Ask Your Question
0

Face detection not working on specific image

asked 2017-06-29 09:48:58 -0500

skanga gravatar image

updated 2017-06-29 10:19:46 -0500

berak gravatar image

I am using the haarcascade_frontalface_default.xml classifier to detect faces in python 3 on Windows 7 with OpenCV 3.1.0 using the following code:

import cv2
import sys

classifier = cv2.CascadeClassifier ("haarcascade_frontalface_default.xml")
image = cv2.imread (sys.argv[1])                  # Read image from first command line param
gray = cv2.cvtColor (image, cv2.COLOR_BGR2GRAY)   # Convert the image to grey scale

# Detect faces on image
faces = classifier.detectMultiScale (gray, scaleFactor = 1.1, minNeighbors = 5, minSize = (30, 30), flags = cv2.CASCADE_SCALE_IMAGE)
print ("Found {0} faces!".format (len (faces)))

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
  cv2.rectangle (image, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow ("Faces found", image)
cv2.waitKey (0)
cv2.destroyAllWindows ()

This code works fine for most face images I have. However it does not work for this specific image. C:\fakepath\1a.jpg Any idea why?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-18 20:52:41 -0500

supra56 gravatar image

updated 2017-08-18 20:54:59 -0500

That is wrong argument in cv2.imread.

imagePath = sys.argv[1]
classifier = cv2.CascadeClassifier ("haarcascade_frontalface_default.xml")
image = cv2.imread(imagePath)

Change scaleFactor=1.1 to scaleFactor=1.2

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-29 09:43:12 -0500

Seen: 493 times

Last updated: Aug 18 '17