I'm pretty sure I have the general theme correct, but I'm not finding any faces. My code reads from c=cv2.VideoCapture(0)
, i.e. the computer's videocamera. I then have the following set up to yield where the faces are. As you can see, I'm looping through different scaleFactors and minNeighbors but rects always comes back empty. I've also tried each of the four different haarcascade xml files included in the opencv/data/haarcascades package.
Any tips?
while(1):
ret, frame = c.read()
rects = find_face_from_img(frame)
def detect(img, cascade):
for scale in [float(i)/10 for i in range(11, 15)]:
for neighbors in range(2,5):
rects = cascade.detectMultiScale(img, scaleFactor=scale, minNeighbors=neighbors,
minSize=(20, 20), flags=cv2.cv.CV_HAAR_SCALE_IMAGE)
print 'scale: %s, neighbors: %s, len rects: %d' % (scale, neighbors, len(rects))
def find_face_from_img(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
rects = detect(gray, cascade)