sajjjadayobi / FaceLib

Face Analysis: Detection, Age Gender Estimation & Recognition
MIT License
294 stars 52 forks source link

OpenCV gives an error after a few seconds of opening the window #25

Open sheikhartin opened 2 years ago

sheikhartin commented 2 years ago

I wanted to try FaceLib with the emotion detector from my webcam, but I got an error after a few seconds when a frame opens!

Code (from the README file):

from facelib import WebcamEmotionDetector

detector = WebcamEmotionDetector()
detector.run()

Error message:

loading ...
from EmotionDetector: weights loaded
type q for exit
Traceback (most recent call last):
  File "/home/sheikhartin/w/.tmp/facelib_demo.py", line 15, in <module>
    detector.run()
  File "/home/sheikhartin/.local/lib/python3.10/site-packages/facelib/FacialExpression/from_camera.py", line 27, in run
    special_draw(frame, b, landmarks[i], name=emotions[i], score=emo_probs[i])
  File "/home/sheikhartin/.local/lib/python3.10/site-packages/facelib/InsightFace/models/utils.py", line 117, in special_draw
    cv2.rectangle(img, c1, c2, color, thickness=tl)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
>  - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
>  - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
>  - argument for rectangle() given by name ('thickness') and position (4)
>  - argument for rectangle() given by name ('thickness') and position (4)
rokopi-byte commented 1 year ago

It's a late response, but maybe can help future readers. This is due to OpenCV version. With OpenCV > 4.X.X coordinate argument for function cv.rectangle must be tuple of integer. So in utils.py enclose them in int(). For example in line 115 it becomes:

c1, c2 = (int(box[0]), int(box[1])), (int(box[2]), int(box[3]))
# draw bounding box
cv2.rectangle(img, c1, c2, color, thickness=tl)