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

Assertion Failed on OPENCV cvtColor #2

Open
diogobernini opened this issue May 18, 2015 · 4 comments
Open

Assertion Failed on OPENCV cvtColor #2

diogobernini opened this issue May 18, 2015 · 4 comments

Comments

@diogobernini
Copy link

So, I had a problem here with my camera (it broke) and I bought a new one, same model, same brand. Plugged it in and got an error. Tried again on your code, same error. Not sure if it's a driver problem, since I'm using the exact same camera. Maybe the power is not being enough? I'll check on that on my side.

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /usr/src/packages/BUILD/opencv-2.4.1+dfsg/modules/imgproc/src/color.cpp, line 3149
ERROR:tornado.application:Exception in callback <bound method WebSocket.loop of <__main__.WebSocket object at 0x284e5b0>>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 1020, in _run
    return self.callback()
  File "server.py", line 94, in loop
    img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
error: /usr/src/packages/BUILD/opencv-2.4.1+dfsg/modules/imgproc/src/color.cpp:3149: error: (-215) scn == 3 || scn == 4 in function cvtColor

I looked it up online and it was saying as if the frame is empty and then there is no conversion. So I feel like it could be a driver issue.

@diogobernini
Copy link
Author

Nope, tried three different power sources for the PI, not the problem. Tested the camera on my PC, worked.

@diogobernini
Copy link
Author

The following snippet is printing ten times "cannot read image", so it is definitely a driver problem on my side:

import cv2
from PIL import Image
camera = cv2.VideoCapture(0)
for i in range (10):
    ret, img = camera.read()
    if ret:
        break
    else:
        print ("cannot read img");

Maybe we should add an if and read the first value on the tuple returned by camera.read() (line 7x on your code I think), printing an understandable error to the developer. What's your opinion?

@diogobernini
Copy link
Author

And for my problem, I'll try a clean install of raspbian and see what happens.

@patrickfuller
Copy link
Owner

Maybe we should add an if and read the first value on the tuple returned by camera.read() (line 7x on your code I think), printing an understandable error to the developer. What's your opinion?

I think that's a good idea. Send over a pull request and I'll accept it.

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