camp
camp copied to clipboard
Assertion Failed on OPENCV cvtColor
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.
Nope, tried three different power sources for the PI, not the problem. Tested the camera on my PC, worked.
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?
And for my problem, I'll try a clean install of raspbian and see what happens.
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.