Ask Your Question

SirAlfredNobel's profile - activity

2014-01-28 14:36:47 -0500 asked a question Most basic FaceDetection possible

I am trying to find the most basic way of detecting if a face is present in a video stream from a webcam. However I am new to OpenCV and am struggling to get it working in an embeded project I am building.

Due to lack of serious processing power, I don't want to display the image at all. No drawn boxes, no x,y of faces, just a count of the number of faces, output to a file.

I'm having trouble trying to figure out the minimum amount of code I can use to detect when a face is present and then simply return the number of faces back to the command line into a file.

It seems like I could take the facedetect.cpp line: 'void detectAndDraw' and change it to 'int detectAndDraw' and have it return that int but since I'm trying to write it in python instead of c++ I'm having trouble figuring out what I do and do not need from the example. This is what I have so far, based on some older code I found. where (path) will be /dev/video1

import cv2

def detect(path):
    img = cv2.imread(path)
    cascade = cv2.CascadeClassifier("/galileo/opencv/haarcascade_frontalface_alt.xml")
    rects = cascade.detectMultiScale(img, 1.3, 4,, (20,20))

    if len(rects) == 0:
        return [], img
    rects[:, 2:] += rects[:, :2]
    return rects

I think I messed this up though since I just want to return a count of the faces, not the contents of the rects object. Any helpful pointers or if there is already a minimalist example of face counting in python someplace I missed would be greatly appreciated.