eranid / adience_align

This project provides alignment tools for faces, to be used as a preprocessing step before computer vision tasks on face images
MIT License
61 stars 53 forks source link

AttributeError: 'cv2.CascadeClassifier' object has no attribute 'detectMultiScaleWithScores' #2

Open umitanuki opened 9 years ago

umitanuki commented 9 years ago

After installing, I ran test_pipeline.py and failed.

... processing ./resources/pipeline/Fayssal_Mekdad_0002.jpg
E
======================================================================
ERROR: testPipeline (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_pipeline.py", line 30, in testPipeline
    cascade_face_aligner.detect_faces(input_folder, faces_folder)
  File "/usr/local/lib/python2.7/dist-packages/adiencealign/pipeline/CascadeFaceAligner.py", line 55, in detect_faces
    faces_file = self.face_finder.create_faces_file( input_file, is_overwrite = False, target_file = target_faces_file )
  File "/usr/local/lib/python2.7/dist-packages/adiencealign/cascade_detection/cascade_face_finder.py", line 104, in create_faces_file
    faces = self.get_faces_list_in_photo(cv2.imread(fname))
  File "/usr/local/lib/python2.7/dist-packages/adiencealign/cascade_detection/cascade_face_finder.py", line 89, in get_faces_list_in_photo
    haar_faces = self.haar_dtct.detectWithAngles(img, resolve = True)
  File "/usr/local/lib/python2.7/dist-packages/adiencealign/cascade_detection/cascade_detector.py", line 97, in detectWithAngles
    faces = self.detectMultiScaleWithScores(rot_image, scaleFactor = 1.03, minNeighbors = 20, minSize = (15,15), flags = 4)
  File "/usr/local/lib/python2.7/dist-packages/adiencealign/cascade_detection/cascade_detector.py", line 60, in detectMultiScaleWithScores
    return self._cascade_classifier.detectMultiScaleWithScores(img,
AttributeError: 'cv2.CascadeClassifier' object has no attribute 'detectMultiScaleWithScores'

----------------------------------------------------------------------
Ran 1 test in 0.051s

I don't think it has such method ever, but it looks like detectMultiScale (without WithScores)? I changed it accordingly in my local and seems to be working.

ahaque commented 9 years ago

In cascade_detector.py, in the detectWithAngles function, go to around line 100. You will see the function call to self.detectMultiScaleWithScores. Immediately below that, find:

for face in faces:
    xp = face[0][0]
    dx = face[0][2]
    yp = face[0][1]
    dy = face[0][3]
    score = face[1]

and replace it with:

for face in faces:
    xp = face[0]
    dx = face[2]
    yp = face[1]
    dy = face[3]
    score = 1

This fixes the problem because the self._cascade_classifier.detectMultiScale call on line 60 does not return scores. After making this change, test_pipeline.py seems to be working and generates outputs (that look correct?).

mayankgrd commented 9 years ago

Hi there, I faced similar error, and solved things as mentioned. But, it does not seem that the faces are aligned anymore. Specifically, see the Fayssal_Mekdad_0002_face_0.aligned imaged under the aligned folder.

Any update on this? Though, I doubt that this might be causing problem.

Any help will be highly appreciated.

kli-casia commented 9 years ago

I have the same problem

kli-casia commented 9 years ago

@umitanuki @mayankgrd Have you solved this problem?

sirnicolaz commented 7 years ago

I have found the solution: the code is using an outdated version of the method. Just go to line 60 of cascade_detector.py and turn detectMultiScaleWithScores into detectMultiScale

Lokesh3152 commented 4 years ago

i cant find cascade detector. i installed through conda can u help me out