1
votes

Long time listener, first time asker. Here is the situation:

I'm trying to read frames from multiple opencv (python) video capture device using the .read() functionality. When using opencv 2.4.11 the following error occurs at random times:

HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV Unable to stop the stream.: Bad file descriptor

This error appears to happen within the .read() call and even wrapping the call in a try/except fails to catch the problem as the .read() call never returns even as an exception.

When trying to update to the newest version of ocv(3.2.0) the .read() fails to return any frames.

Additional information: Machine: Linux Mint 18.1 Camera: https://www.amazon.com/ELP-megapixel-surveillance-machine-monitor/dp/B015FIKTZC Python: 2.7

Update: code:

The following takes place within a videoCamera class which holds a video object made initially from: self.video = cv2.VideoCapture(self.cameraSerialAddress)

Then a getFrame() call is made to this class, within this function is the following: try: retVal,frame = self.video.read()

            if frame is None:
                print("no frame available for camera: "+str(self.cameraSerialAddress) + " Reconnecting to camera")
                self.video.release()
                self.video = None
                self.hasConnection = False
                self.frame = None
                return

            elif frame is not None:                 
                self.frame = frame

Thanks for the help, Kyle

1
More important than the camera, do you have any code? - cs95
Question has been updated! - Russell
Try cv2.VideoCapture(0)? - cs95
Hi Coldspeed, this is what is occurring. The line: self.video = cv2.VideoCapture(self.cameraSerialAddress) is identical to cv2.VideoCapture(0) however the variable self.cameraSerialAddress is an int passed to the videoCamera class. This is done as there are 6 cameras connecting to the computer. - Russell
Anything in system logs regarding the USB devices that would correspond with the times you get those errors? - Dan MaĊĦek

1 Answers

2
votes

To anyone who might come across experiencing something similar we eventually found out the issue was a power problem. The camera in question had a 5m usb cable used to get additional length necessary for the application. Over this length of cable occasionally a bad pixel format would come back yielding the HIGHGUI error. As the camera/computer location couldn't be changed the solution was to wrap the class in another that would catch these errors, kill the stream, then reconnect to the camera. Not a perfect solution by any means but it worked for the purposes at hand.