I'm working in a Python app with opencv and a USB camera. Sometimes the camera driver throws an exception:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp, line 3650
or a Segmentation Fault.
I think it's because of the camera driver. The camera stops working after that (though the camera light remains on) and I need to disconnect and reconnect it.
Is there a way to unmount and then remount that Camera with Python? Or is there an alternative way to fix this?
(I've searched on /media and /mnt, and I could not find the camera there).
This is my code:
self.cap = cv2.VideoCapture(0) self.cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, camerapicshowwidth) self.cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, camerapicshowheight) while updateCamera: _, frame = self.cap.read() frame = cv2.flip(frame, 1) cv2image = cv2.cvtColor(frame,cv2.COLOR_BGR2RGBA) img = Image.fromarray(cv2image) img.thumbnail((showpicsmallwidth, showpicsmallheight),Image.BILINEAR); imgtk = ImageTk.PhotoImage(image=img) self.cameraLabel.imgtk = imgtk self.cameraLabel.configure(image=imgtk)