HackerShackOfficial / AI-Smart-Mirror

Smart Mirror with a smart AI 🤖
MIT License
537 stars 214 forks source link

OpenCV error : error: (-215) scn == 3 || scn == 4 in function cvtColor (fixed - need confirmation) #36

Closed laststand0810 closed 6 years ago

laststand0810 commented 7 years ago

Hi, couple days ago I have worked with this project and encounter this error below, I did a little tune and the error seems to have disappeared so I think I would like to submit my fix for those who may concerned. Authors please check it for me, thank you in advance (sorry I'm not that good with git =.='):

Issue reproduce:

  1. Set up project as README instructions
  2. Run with low-average webcam or in dark environments for better bug encounter
  3. while webcam is running, occasionally error is thrown on terminal and bot.py is terminated:

Found face I'm listening Found audio Google Speech Recognition could not understand audio OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/opencv-20170224-1869-10nlf6f/opencv-2.4.13.2/modules/imgproc/src/color.cpp, line 3739 Traceback (most recent call last): File "bot.py", line 254, in bot.start() File "bot.py", line 40, in start if self.vision.recognize_face(): File "/Users/macuser/AI-Smart-Mirror/vision.py", line 32, in recognize_face gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.error: /tmp/opencv-20170224-1869-10nlf6f/opencv-2.4.13.2/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor

Suspected cause: while streaming webcam there must be a corrupted frame that have been assigned into cvtColor() and produce error reference: http://www.pyimagesearch.com/2016/12/26/opencv-resolving-nonetype-errors/

Suggest fix: change vision.py line 32 from

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

to:

if ret is True: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) else: continue

YODHAA commented 6 years ago

yeh its working in my project its fix my error.

Roc-J commented 6 years ago

it's cool,thanks

laststand0810 commented 6 years ago

So I've just read through git book, i'll make a push request later on, just that the project seems to be abandoned.

laststand0810 commented 6 years ago

So I've just read through git book, i'll make a push request later on, just that the project seems to be abandoned.

Sachin12s19 commented 6 years ago

if ret is True: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) else: continue

what is ret ?

ghltshubh commented 6 years ago
    _ , frame = cap.read()
    # Convert BGR to HSV
    if _ is True:
        hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    else:
        continue
ghost commented 6 years ago

Trying to replicate on colab.research.google.com but error is not getting resolved

sarabisohrab commented 6 years ago

You can use: if ret is True: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) else: break

This will end video when a frame has problem.

sandeepknit commented 6 years ago

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) its not working

sudhir002 commented 6 years ago

can i use raspberrypi camera in place of webcam image

sudhir002 commented 6 years ago

if yes the n share some idea in detail

vishalkaului commented 6 years ago

I tried the above fix. Not getting the scn error anymore but after giving the command it's stuck not doing anything.

I am executing webcam.py from https://github.com/shantnu/Webcam-Face-Detect . Please note the file was run after doing the fix suggested in the comments above.

Any help would be appreciated, thanks.

santhoshnp commented 5 years ago
gray = cv2.cvtColor(image_frame, cv2.COLOR_BGR2GRAY)

cv2.error: /build/opencv-U1UwfN/opencv-2.4.9.1+dfsg1/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cvtColor (I am facing this problem please help me)

riyam68 commented 4 years ago

You can use: if ret is True: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) else: break

This will end video when a frame has problem.

It works. Thanks a lot!