Ask Your Question
3

Face-detection/recognition + segmenting + tracking Difficulty

asked 2012-09-20 18:00:03 -0600

peon1990 gravatar image

updated 2012-09-20 18:00:21 -0600

Hello there,

I have basic-intermediate programming skills and extensive statistical/data-mining skills. I would like to design software that uses a strategically placed camera and weak processor (~ 1 GHz single core) to: -detect faces -recognize face if return person, save if new - add counter to all that apply: male, female, child, young, middle aged, old, caucasian, black, hispanic, east asian

I have not downloaded OpenCV yet, but would be coding in Python on my Mac. Could someone please indicate the difficulty of doing this? I realize this is a vague question, but any comments would be greatly appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
6

answered 2012-09-21 12:26:30 -0600

updated 2012-09-21 13:21:02 -0600

Good choice to do it in Python, as it is easy to see some results pretty quick.

For the face detection part you can use the CascadeClassifier in OpenCV. A whole program to do face detection from a webcam video (for example) is nothing more than a tiny script. Since you said you are planning to work on a weak device, you should go for the LBP cascades as they should eat up much less resources.

The following sample uses the classes video (samples/python2/video.py) and common (samples/python2/common.py), which are helper classes from the samples/python2 folder. The cascades are located in the data folder of your OpenCV download, so you'll probably need to adjust cascade_fn to make it work:

import cv2
from video import create_capture
from common import clock, draw_str

# You probably need to adjust some of these:
video_src = 0
cascade_fn = "haarcascades/haarcascade_frontalface_default.xml"
# Create a new CascadeClassifier from given cascade file:
cascade = cv2.CascadeClassifier(cascade_fn)
cam = create_capture(video_src)

while True:
  ret, img = cam.read()
  # Do a little preprocessing:
  img_copy = cv2.resize(img, (img.shape[1]/2, img.shape[0]/2))
  gray = cv2.cvtColor(img_copy, cv2.COLOR_BGR2GRAY)
  gray = cv2.equalizeHist(gray)
  # Detect the faces (probably research for the options!):
  rects = cascade.detectMultiScale(gray)
  # Make a copy as we don't want to draw on the original image:
  for x, y, width, height in rects:
    cv2.rectangle(img_copy, (x, y), (x+width, y+height), (255,0,0), 2)
  cv2.imshow('facedetect', img_copy)
  if cv2.waitKey(20) == 27:
    break

As for the recognition part. This tutorial shows how to perform gender classification with OpenCV:

It will work the same for any other classification problem. But please note, that this works very good on well-aligned images and sufficient image data (in terms of the number of training samples). You probably need to apply some pre-processing to make it work in real life settings.

Because you said you want to work with Python, you could also have a look at how to it in Python:

So how difficult is it to write a program for your use case? The above probably makes you feel it is a simple task. It is not. Getting computer vision algorithms to work robust in non-constrained scenarios is hard. In case of face detection and face recognition you have to combat things like head pose or illumination to mention only two tough problems. You can spend years of research on any of these problems.

So my advice is: limit yourself to realistic goals. Don't try to aim for face.com recognition rates. And validate your algorithms as early as possible in the project, so you have figures to rely on and work with:

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-09-20 18:00:03 -0600

Seen: 4,365 times

Last updated: Sep 21 '12