(-215:Assertion failed) s >= 0 in function 'cv::setSize'

See original GitHub issue

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'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasmcauscommented, Feb 11, 2021

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.

0reactions
vivekthedevcommented, Feb 13, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - OpenCV Error: Assertion failed (s >= 0) in setSize
There are not enough details to tell, but it seems that one of the images that you are trying to resize is empty....
Read more >
OpenCV Error: Assertion failed (s >= 0) in setSize
Hi everyone, I'm new user and I'm trying to execute my program that uses opencv. It compiles but during the exeution it appears...
Read more >
cv::imshow raises (Assertion failed) s >= 0 in function 'setSize ...
When I was trying to make a minimal program to reproduce the same error, there were two new errors showing up, Assertion failed)...
Read more >
FaceRecognizer - train method throws "Assertion failed"
Hello,I have the same problem like that,but my program is SVM object detect. It always say that"OpenCV Error: Assertion failed (s >= 0)...
Read more >
Assertion failed (size.width>0 && size.height>0) in imshow, file ...
This error means you are passing an empty array to imshow function. Use cout to check if the array is empty or not....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found