Week 04 ‐ OpenCV Cascade Classifiers - AkinduID/EyeRiz GitHub Wiki

Goals

  • Study basic of opencv cascade classifiers
  • prepare presentation for the knowledge sharing session on cascade classifiers
  • start with option 1 (using an exsisting webcam)
  • Interface servo motors with arduino

Components

  • 720p Webcam
  • Arduino Uno R3
  • SG90 Servo Motor x2

Libraries and Models

  • OpenCV
  • Haar Cascade Files

After testing options 4 and 5, I concluded that option 1 is the best for my purpose. I purchased a low-cost 720p webcam, removed the casing, and discovered that it fits perfectly on the servo bracket. I conducted separate tests for the servos and the facial recognition system.

Face Recognition using Haar Cascade Classifiers

import cv2
import imutils
detector = cv2.CascadeClassifier("cascades/haarcascade_frontalface_default.xml")
cap = cv2.VideoCapture(1)

while True:
    ret,frame = cap.read()
    if not ret:
        break
    frame = imutils.resize(frame, width=500)
    grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faceRects = detector.detectMultiScale(grey, scaleFactor=1.05, minNeighbors=5, minSize=(30, 30), flags=cv2.CASCADE_SCALE_IMAGE)
    for (x, y, w, h) in faceRects:
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
    cv2.imshow("Faces", frame)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break
cap.release()
cv2.destroyAllWindows()

Interfacing Servo Motor with arduino

#include <Servo.h>

Servo pan; 
Servo tilt;

int pos = 0;    // variable to store the servo position

void setup() {
  pan.attach(9);
  pan.attach(10); 
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { 
    pan.write(pos);              
    delay(15);                       
  }
  for (pos = 0; pos <= 180; pos += 1) { 
    tilt.write(pos);              
    delay(15);                       
  }
  for (pos = 180; pos >= 0; pos -= 1) { 
    pan.write(pos);              
    delay(15);                      
  }
  for (pos = 0; pos <= 180; pos += 1) { 
    tilt.write(pos);              
    delay(15);                       
  }
}

Conclusions

  • High False Positive Rate: The Haar Cascade Classifier has a relatively high false positive rate. I will explore more advanced facial detection methods, such as YOLO, for improved accuracy.
  • Servo Motor Optimization: The servo movements may need further optimization to improve tracking precision.
  • Noise Interference: The noise generated by the servo motors can interfere with the webcam’s audio. I will explore noise-reduction techniques to minimize this issue.

Next Steps

  • Integrate the facial detection system with servo motor control for real-time face tracking.
  • Test face detection using other models to compare accuracy and performance against Haar Cascade Classifiers.
  • Evaluate which model offers the best balance between speed and accuracy for the project’s requirements.
⚠️ **GitHub.com Fallback** ⚠️