Selected project Computer vision
Handy Automator
Gesture-Based Home Automation with Computer Vision
A real-time computer vision pipeline that recognized who was in front of a camera, figured out whose hand was making which gesture, and turned that into a home automation command. I built the entire computer vision component (the "Processing Unit") of this team project.
Tech Python, OpenCV, DeepFace (ArcFace + RetinaFace), MediaPipe Tasks (Pose and Gesture), NumPy, SciPy, pytest
Overview
Most smart-home systems relied on voice commands or a phone app. Handy Automator explored a lower-friction alternative: users could walk into view, get recognized, make a hand gesture, and trigger a user-defined workflow (for example, toggling a light).
The hard part was not detecting a face or a gesture on its own. It was answering "whose hand was that?" when more than one person could be in the frame, while making sure gestures from unrecognized people were ignored. My part of the project was the pipeline that solved this. The rest of the system (a Go REST server, a React Native app, and ESP32 edge devices) was built by teammates and consumed the events my pipeline produced. For more on the technical side of the Go REST API server, visit Caio Cotts's website!
Demo
You're probably looking at me wondering why my eyes are so red and why I look half-asleep. Honestly, this project was huge, and we were grinding right up until the last few minutes before submission. This demo covers one of the use cases and highlights it's functioanlity using ESP32 boards controlling LED
Pipeline Architecture
A single loop captured webcam frames with OpenCV and fed three independent perception
modules. A linking step then combined their outputs into (user, gesture) events.
- Face recognition (
face_recognition.py): found faces, identified them, and tracked them between frames. - Pose estimation (
pose.py): provided a body skeleton that acted as a bridge between a face and a hand. - Gesture recognition (
gesture_recognition.py): detected hands and classified gestures. - Integration (
main.py): ran the spatial verification logic that bound identity to gesture.
Both MediaPipe tasks ran in LIVE_STREAM mode. Each frame was submitted with a millisecond
timestamp, and a non-blocking callback stored the latest result, so the video loop never waited
on inference.
Face Recognition and Identity Tracking
Enrollment
On startup, the system scanned database/auth_users for reference images and
used each filename as that person's identity (User1.png became User1). Each image was converted to an embedding using DeepFace with the ArcFace model. Enrollment used the slower but more accurate RetinaFace detector, since
it only ran once per image.
Live detection and recognition
Running a deep model on every frame made the first version of the Processing Unit very laggy. I split the work into a fast path and a slow path:
- Fast path (every frame): an OpenCV Haar cascade detected face bounding boxes on grayscale frames.
- Slow path (once per second): the face crop was embedded with ArcFace,
using DeepFace's faster
opencvdetector backend and compared against the stored embeddings.
Identities were compared using cosine distance. A face was accepted when the distance to a stored embedding fell below a threshold of 0.6:
Once a face was verified, the user stayed authorized for a 7-second lock window, so a brief detection miss did not immediately revoke access.
Keeping labels stable between recognition checks
Since recognition only ran once per second, the system needed to remember who was who in the frames in between. I implemented a lightweight centroid tracker. For each detected face, it computed the center of the bounding box and compared it to the previous frame's face centers. If a face moved less than 50 pixels, it inherited the same identity:
The detection function returned a list of (bounding_box, name) pairs.
Unrecognized faces were labeled Unknown, which let the system ignore them
later.
Pose and Gesture Recognition
For gestures, I used MediaPipe's GestureRecognizer, configured to track up to
two hands with a minimum detection confidence of 0.7. For each hand, it returned 21
landmarks and a top gesture with a confidence score. I wrote the drawing code in plain
OpenCV rather than using MediaPipe's built-in utilities. It plotted the landmarks, connected
them using a hardcoded hand-connection map, and labeled the gesture above the wrist.
MediaPipe's PoseLandmarker supplied the pieces needed to link a face to a hand:
the nose and the left and right wrists. MediaPipe returned
normalized coordinates, so I converted them to pixel coordinates using the frame size:
How Gestures Were Linked to People
This was the most interesting design problem, and the approach went through three iterations.
- Global session state. Once anyone was authenticated, any gesture was attributed to them. That approach was simple, but another person in the frame could trigger someone else's workflows.
- Nearest-face proximity. Each hand was assigned to the face whose center was closest. It broke down when people stood close together or reached across each other.
- Pose-bridged linking (final). A body skeleton connected the face to the hand, so ownership depended on anatomy rather than just distance.
The final approach was a two-step chain of checks:
- Face to skeleton: if the pose's nose landmark lay inside a face's bounding box, that skeleton belonged to that face's identity.
- Skeleton to hand: if the gesture recognizer's wrist landmark was within 50 pixels of one of the skeleton's wrist landmarks, that hand belonged to the skeleton.
A simplified version of the core logic:
def get_dist(p1, p2):
return math.hypot(p1[0] - p2[0], p1[1] - p2[1])
# 1. Face -> skeleton: checked whether the pose's nose was inside a face box.
nose_x, nose_y = get_nose_coords(pose_result, frame_w, frame_h)
owner = None
for (fx, fy, fw, fh), name in faces:
if fx < nose_x < fx + fw and fy < nose_y < fy + fh:
owner = name
# 2. Skeleton -> hand: matched this hand's wrist against a pose wrist.
for hand in gesture_result.hand_landmarks:
hand_wrist = to_pixels(hand[0], frame_w, frame_h)
if any(get_dist(hand_wrist, w) < 50
for w in get_wrist_coords(pose_result, frame_w, frame_h)):
if owner and owner != "Unknown":
emit(owner, gesture_name) # e.g. ("User1", "Thumb_Up") When both checks passed, the pipeline output a (user, gesture) event and drew NAME + hand above the person's head along with the hand skeleton. Gestures from Unknown faces, and gestures that could not be tied to a recognized skeleton, were discarded.