Failed to find faces (face detection) in django project (using python-opencv project)

This block of code (in views.py) is launched using a URL. No problem importing cv2. (The same as using virtualenvwrapper, it shows the same result (after adding all the necessary libraries). Initializing the camera and ....

def caminit(request): cam.open(0) img=cam.read() cv2.imwrite("snap"+".jpg",img[1]) cam.release() #takes the instant pic faceCascade =cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') 

When checking for print type(faceCascade) , <type 'cv2.CascadeClassifier'> . Object created.

moving on in the same caminit

 image = cv2.imread("snap.jpg") # when checked with image.dtype it shows correct uint8 also image.shape shows correct data {Eg: (480, 640, 3)} gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Detect faces in the image faces = faceCascade.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags = cv2.cv.CV_HAAR_SCALE_IMAGE ) 

Now the important part of โ€œFace Searchโ€

 print "Found {0} faces!".format(len(faces)) 

EXIT IN TERMINAL:

 Found 0 faces! 

Why is this happening?

I tried debugging by typing in terminal. I mentioned them in the comments. The camera used is my laptop (HP envy), which gives a snap with a resolution of 640x480.

I suspect that something needs to be changed in the faceCascade.detectMultiScale(..) block. (Options). I tried with scalefactor = 1.000001 and minNeighbors = 3 no avail.

+7
django opencv haar-classifier
source share
1 answer

In my experience, the classifier that predicts the best is: haarcascade_frontalface_alt2.xml, you can try with it.

This is the code that works for me:

 min_face_size=30 max_face_size=100 face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml") faces = face_cascade.detectMultiScale(img_gray, 1.05,1,0| cv2.cv.CV_HAAR_SCALE_IMAGE,(min_face_size,min_face_size),(max_face_size,max_face_size)) 

In addition to trying this, you must make sure that you are loading a real image. It may happen that you upload a black image, then it may return something like what you said (480, 640, 3).

0
source share