Live face detection — computer vision in the browser
Real-time face detection: OpenCV’s Haar cascade scans each webcam frame for face-like light/dark patterns and boxes them — the classic computer-vision detector, now on your live feed. Runs client-side (nothing uploaded); the cascade XML is bundled with TinkerCV. Press Run and allow the camera.
Example code (Python / OpenCV)
"""
Live face detection
Real-time face detection: OpenCV’s Haar cascade scans each webcam frame for face-like light/dark patterns and boxes them — the classic computer-vision detector, now on your live feed. Runs client-side (nothing uploaded); the cascade XML is bundled with TinkerCV. Press Run and allow the camera.
"""
import cv2
# The camera starts automatically on Run — allow access when prompted.
cap = cv2.VideoCapture(0)
face = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") # bundled with TinkerCV
while True:
ret, frame = cap.read()
if not ret:
print("No camera frame — allow camera access when prompted.")
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
for (x, y, w, h) in face.detectMultiScale(gray, 1.2, 5):
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)
cv2.imshow("faces", frame)
if cv2.waitKey(1) == 27: # Esc / Stop
break