Russell
Russell

Reputation: 71

OpenCV Failing to read from Video Capture Device

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

Upvotes: 1

Views: 2239

Answers (1)

Russell
Russell

Reputation: 71

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.

Upvotes: 2

Related Questions