-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
Detailed description
I was using the landmark_demo.py as a reference for a personal project of mine and I kept running into the below error:
cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\core\src\matrix.cpp:1193: error: (-15:Bad number of channels) The total width is not divisible by the new number of channels in function 'cv::Mat::reshape'
It turned out that when CascadeClassifier.detectMultiScale does not detect any faces in the input image it returns an empty tuple which Facemark.fit is unable to handle. the demo does not have any indication that this would be the behavior and the exception that gets raised is pretty obtuse making it difficult to diagnose this problem.
This isn't really a bug I don't think but it is pretty confusing. Some possible suggestions:
- the demo should indicate this behavior for clarity if this is the intended behavior
- change the return of
CascadeClassifier.detectMultiScalewhen no faces are detected so that it's compatible withFacemark.fit()function - raise a more description exception in
Facemark.fit()whenfacesare empty so that it's easier to diagnose the problem.
Steps to reproduce
Replace lena.jpg image in the landmark_demo.py with an image without any faces. And run the script.