Skip to content

Instantly share code, notes, and snippets.

@smith0022
Created July 10, 2023 18:21
Show Gist options
  • Save smith0022/8891dea9e360e14d5de6d42e30227246 to your computer and use it in GitHub Desktop.
Save smith0022/8891dea9e360e14d5de6d42e30227246 to your computer and use it in GitHub Desktop.
import cv2
from picamera2 import Picamera2
# Grab images as numpy arrays and leave everything else to OpenCV.
face_detector = cv2.CascadeClassifier("/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml")
cv2.startWindowThread()
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
picam2.start()
while True:
im = picam2.capture_array()
grey = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
faces = face_detector.detectMultiScale(grey, 1.1, 5)
for (x, y, w, h) in faces:
print("i can see you:")
cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0))
cv2.waitKey(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment