Setting and getting properties of Python cv2.VideoCapture object does not work

666
March 08, 2017, at 00:48 AM

I am trying to set the return format for a video stream from an Imaging Source DFK31AU03 USB 2.0 camera. When I get the video format using the following Python2 code:

import cv2
# Get a handle to the camera
cam = cv2.VideoCapture(0)
# Print various camera properties
print "CV_CAP_PROP_FORMAT: " + str(cam.get(cv2.cv.CV_CAP_PROP_FORMAT))
print "CV_CAP_PROP_MODE: " + str(cam.get(cv2.cv.CV_CAP_PROP_MODE))
print "CV_CAP_PROP_FPS: " + str(cam.get(cv2.cv.CV_CAP_PROP_FPS))
print "CV_CAP_PROP_CONTRAST: " + str(cam.get(cv2.cv.CV_CAP_PROP_CONTRAST))
print "CV_CAP_PROP_GAIN: " + str(cam.get(cv2.cv.CV_CAP_PROP_GAIN))
print "CV_CAP_PROP_FRAME_WIDTH: " + str(cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
print "CV_CAP_PROP_FRAME_HEIGHT: " + str(int(cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))
print "CV_CAP_PROP_POS_FRAMES: " + str(cam.get(cv2.cv.CV_CAP_PROP_POS_FRAMES))
print "CV_CAP_PROP_EXPOSURE: " + str(cam.get(cv2.cv.CV_CAP_PROP_EXPOSURE))
# Edit a troublesome property and print again
cam.set(cv2.cv.CV_CAP_PROP_MODE, cv2.cv.CV_8UC1);
# Print the "MODE" property again
print "\n-- This is one of the problem variables --"
print "The \"MODE\" property should be set to: " + str(cv2.cv.CV_8UC1)
print "CV_CAP_PROP_MODE: " + str(cam.get(cv2.cv.CV_CAP_PROP_MODE))
# Release the handle to the camera
cam.release()

This code prints some of the properties of the camera. For me, the problem is that many of the properties print as -1.0 or 0.0 when they should have other values. The documentation that I have found for this class is quite poor and there is little explanation as to what each value means and possible reasons for the properties of the camera not being returned. The camera I am using is not cheap.

Here is a sample output of the code as it runs for me:

Is it the case that my camera does not have access to these properties? It is not cheap camera so this would be surprising. Any help would be appreciated.

READ ALSO
matplotlib Event Listeners Not Funcitoning In PyQT Widget

matplotlib Event Listeners Not Funcitoning In PyQT Widget

I have a library of draggable matplotlib objects that I'm trying to utilize with a PyQt5 GUIThe objects' event listeners function correctly in a standalone matplotlib figure window but do not function when the figure is embedded in a QT widget

544
How to get the symmetric difference of two dictionaries

How to get the symmetric difference of two dictionaries

I was looking for a solution to finding the symmetric difference between two dictionaries in Python

487
Sampling rows from numpy array efficiently

Sampling rows from numpy array efficiently

I am wondering how to sample rows efficiently from high dimensional numpy arrays

419
Training a dense layer from bottleneck features vs. freezing all layers but the last - should be the same, but they behave differently

Training a dense layer from bottleneck features vs. freezing all layers but the last - should be the same, but they behave differently

As a "sanity check" I tried two ways to use transfer learning that I expected to behave the same, if not in running time than at least in the results

341