设置和获取Python cv2.VideoCapture对象的属性不起作用

时间:2017-03-07 13:54:28

标签: python python-2.7 opencv camera video-capture

我正在尝试设置来自Imaging Source DFK31AU03 USB 2.0相机的视频流的返回格式。当我使用以下Python2代码获取视频格式时:

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()

此代码打印相机的一些属性。对我来说,问题是许多属性在应该有其他值时打印为-1.0或0.0。我在这个课程中找到的文档非常差,几乎没有解释每个值的含义以及相机属性未被返回的可能原因。我使用的相机并不便宜。

以下是代码运行的示例输出:

enter image description here

我的相机是否无法访问这些属性?这不是便宜的相机,所以这将是令人惊讶的。任何帮助,将不胜感激。

0 个答案:

没有答案