Closed vivekthedev closed 3 years ago
Could you verify that features
and labels
are both Numpy arrays (use type(features)
and type(labels)
) and check that they both have the same number of elements?
Could you verify that
features
andlabels
are both Numpy arrays (usetype(features)
andtype(labels)
) and check that they both have the same number of elements?
My code is here https://github.com/bradtoxic/open-cv-face-detection/blob/main/face-detection.py Line 37 and Line 38 for features and labels
LGTM. However, still, verify the above. Comment out lines 37-47 and add the following:
print(features.shape)
print(type(features))
print(labels.shape)
print(type(labels))
Let me know what you get
LGTM. However, still, verify the above. Comment out lines 37-47 and add the following:
print(features.shape) print(type(features)) print(labels.shape) print(type(labels))
Let me know what you get
Traceback (most recent call last): File "d:\Work\py\opencv\advanced\face_recognize.py", line 36, in <module> print(features.shape) AttributeError: 'list' object has no attribute 'shape'
This error popped up.
Ah yes, my bad. Replace the .shape
with len()
. Like: len(features)
and len(labels
Ah yes, my bad. Replace the
.shape
withlen()
. Like:len(features)
andlen(labels
Ok
24
<class 'list'>
24
<class 'list'>
I have 24 Images (Faces in my faces folder)
Your issue is here: https://github.com/bradtoxic/open-cv-face-detection/blob/7263af8229394674371c28c1a9be8c637714bd4e/face-detection.py#L29
You've written
gray[x:y+h, x:x+w]
instead of
faces_roi = gray[y:y+h, x:x+w]
You're attempting to access a negative index, which is not possible.
At first, I thought it had something to do with a NoneType
return, so hence the above tests.
Your issue is here: https://github.com/bradtoxic/open-cv-face-detection/blob/7263af8229394674371c28c1a9be8c637714bd4e/face-detection.py#L29
You've written
gray[x:y+h, x:x+w]
instead of
faces_roi = gray[y:y+h, x:x+w]
You're attempting to access a negative index, which is not possible.
At first, I thought it had something to do with a
NoneType
return, so hence the above tests.
It's working now. Thank you so much
I was following your Youtube tutorial but got stuck in this particular problem. I searched a lot but couldn't find any solution.
Video with Timestamp - https://youtu.be/oXlwWbU8l2o?t=10728
Traceback (most recent call last): File "face_recognize.py", line 43, in <module> face_recognizer.train(features, labels) cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-8ely825f\opencv\modules\core\src\matrix.cpp:235: error: (-215:Assertion failed) s >= 0 in function 'cv::setSize'