import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
import picamera
import picamera.array
import cv2
import numpy as np
# Initialize the camera
with picamera.PiCamera() as camera:
camera.resolution = (320, 240)
# Capture a single frame from the camera
with picamera.array.PiRGBArray(camera) as output:
camera.capture(output, format='rgb')
frame = output.array
# Convert the frame to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
# Apply Gaussian blur to reduce noise
gray = cv2.GaussianBlur(gray, (15, 15), 0)
# Threshold the image to create a binary mask
_, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
# Find contours in the binary image
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Draw the contours on the original frame
cv2.drawContours(frame, contours, -1, (0, 255, 0), 2)
# Display the frame with contours
cv2.imshow('Hand Gesture Detection', frame)
cv2.waitKey(0)
cv2.destroyAllWindows()