PyImageSearch / imutils

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
MIT License
4.51k stars 1.03k forks source link

wrong datatype for eyesCenter in facealiner #254

Open andvikt opened 2 years ago

andvikt commented 2 years ago
>       M = cv2.getRotationMatrix2D(eyesCenter, angle, scale)
E    TypeError: Can't parse 'center'. Sequence item with index 0 has a wrong type

the actual shape of eyesCenter is (np.int64, np.int64), but must be (int, int) it can be easyly fixed by [int(x) for x in eyesCenter]

I will provide PR fixing that

Wingscape commented 2 years ago

Wow that's something why i can't fix this bug whenever i search on google. I think im gonna use haar cascade if this issue doesn't solve yet

ariG23498 commented 2 years ago

Hey folks,

Thanks for the issue. Could you give us a reproducible bug to check? A colab notebook with the bug would do! TIA šŸ˜„

AKSoapy29 commented 2 years ago

I can confirm that this is still an issue. I was following the face align tutorial, and kept running into this exact issue. I eventually added all of the facealigner.py code into my code and got the same error. Adding int() to the tuple fixed it:

eyesCenter = (int((leftEyeCenter[0] + rightEyeCenter[0]) // 2),
        int((leftEyeCenter[1] + rightEyeCenter[1]) // 2))

Maybe I'm using a bad version? This is what my pip reports:

Package               Version
--------------------- --------
cmake                 3.22.3
dlib                  19.23.1
imutils               0.5.4
numpy                 1.22.3
opencv-contrib-python 4.5.5.64
vikaskookna commented 1 year ago

Hi @ariG23498 this is still an issue as I got a ticket from a customer today about this

ariG23498 commented 1 year ago

Tagging @abhishekthanki and @ritwikraha to this issue!

ariskoutris commented 1 year ago

I had this issue too with opencv-python 4.6.0.66 and numpy 1.19.5. Thanks @AKSoapy29 for the easy fix.

BilalAlsharif commented 1 year ago

det = dlib.get_frontal_face_detector() pred = dlib.shape_predictor(r'...\shape_predictor_68_face_landmarks.dat') alg = FaceAligner(pred, desiredFaceWidth = 256) This tries to do face-normalisation

This makes this error 'Can't parse 'Center''

frame = cv2.imread('img.jpg') gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) rect = detector(gray,1)[0] faceAligned = aligner.align(frame, gray, rect)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\imutils\face_utils\facealigner.py:68, in FaceAligner.align(self, image, gray, rect) 64 eyesCenter = ((leftEyeCenter[0] + rightEyeCenter[0]) // 2, 65 (leftEyeCenter[1] + rightEyeCenter[1]) // 2) 67 # grab the rotation matrix for rotating and scaling the face ---> 68 M = cv2.getRotationMatrix2D(eyesCenter, angle, scale) 70 # update the translation component of the matrix 71 tX = self.desiredFaceWidth * 0.5

TypeError: Can't parse 'center'. Sequence item with index 0 has a wrong type

dunland commented 1 year ago

For me, casting the eyesCenter from <class 'numpy.int64> to type <class 'int'> instead of fixed it:

in faceAligner.py:64 I did:

eyesCenter = (int((leftEyeCenter[0] + rightEyeCenter[0]) // 2),
        int((leftEyeCenter[1] + rightEyeCenter[1]) // 2))
eze1376 commented 1 month ago

For me, casting the eyesCenter from <class 'numpy.int64> to type <class 'int'> instead of fixed it:

in faceAligner.py:64 I did:

eyesCenter = (int((leftEyeCenter[0] + rightEyeCenter[0]) // 2),
      int((leftEyeCenter[1] + rightEyeCenter[1]) // 2))

This works for me! Thanks @dunland

abhishekthanki commented 1 month ago

Hi Pyimagesearch/imutils,

We know how annoying auto-reply and email confirmation responses are, but we wanted to send you a quick reply and let you know that your email has safely landed in our inbox. Hooray!

We try to respond to emails within 72 hours, Monday-Friday.

In the meantime, hereā€™s a few quick tips to help you out:

  1. We prioritize customer emails. Full transparency, we receive tens of thousands of emails a year, and we prioritize customer support emails. If youā€™d like to become a customer, you can see our full catalog of books and courses here https://www.pyimagesearch.com/books-and-courses/ .
  2. Not sure which of our books/courses is right for you? Need a personalized recommendation from us? No problem, we can get you unblocked and moving forward in < 13.84 seconds (seriously, weā€™ve tested it!) To start, take this short multiple choice survey https://www.pyimagesearch.com/survey/ ā€” it will compile your answers and recommend our book/course best suited for you and your needs.
  3. If you are not a customer and not interested in becoming a customer, you probably wonā€™t get a response. We do our best to respond to all emails we receive, but thereā€™s only so much time in the day to offer free help and support and we continue to get more and more emails. Therefore, we have elected to ā€œdo the most goodā€ with our limited resources and serve the computer vision and deep learning community at large by publishing weekly, high-quality (and did we mention free) tutorials. We hope these give you everything you need to be successful with your project or research.
  4. If you are a customer, we can only help with questions directly related to my books, courses, and blog posts. If you have a question related to a topic covered in our books/courses, or have an issue with code errorā€™ing out, weā€™ll be more than happy to help. Otherwise, if you need targeted 1:1 help with your specific project, we've partnered with Dr. Tim Oates, who offers office hours and consulting on behalf of PyImageSearch. Hereā€™s a quick survey https://www.pyimagesearch.com/consulting/ you can fill out to start the office hours/consulting request with Tim.

We really appreciate your understanding, we hope this email didnā€™t let you down. See you at pyimagesearch.com!

PyImageSearch Team {#HS:2604959745-309633#}