Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sheikhartin opened this issue Jul 2, 2022 · 1 comment
Open

Comments

@sheikhartin
Copy link

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
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants