python打开摄像头 调节hue_在OpenCV/Python中设置摄像机参数

本文探讨了使用Python的OpenCV库控制USB摄像头参数的问题,特别是尝试改变曝光时间和调节HUE。作者指出,虽然可以成功设置宽度、高度等,但无法调整所有相机参数,如曝光时间。问题提出后,有评论确认了CV_CAP_PROP_EXPOSURE(第15个选项)是用于控制曝光的,并分享了相关经验。
摘要由CSDN通过智能技术生成

我使用Thorlabs(DC1545M)的USB摄像头使用OpenCV(2.4)和Python(2.7.3)。在OpenCV/Python中设置摄像机参数

我正在做一些视频流的图像分析,我希望能够从我的视频流中更改一些相机参数。令人困惑的是我能够改变一些相机的属性,但不是所有的相机属性,我不确定我做错了什么。

下面是代码,在Python使用CV2绑定和我可以证实,它运行:

import cv2

#capture from camera at location 0

cap = cv2.VideoCapture(0)

#set the width and height, and UNSUCCESSFULLY set the exposure time

cap.set(3,1280)

cap.set(4,1024)

cap.set(15, 0.1)

while True:

ret, img = cap.read()

cv2.imshow("input", img)

#cv2.imshow("thresholded", imgray*thresh2)

key = cv2.waitKey(10)

if key == 27:

break

cv2.destroyAllWindows()

cv2.VideoCapture(0).release()

作为参考,在cap.set的第一个参数()命令指相机性能的列举,列举如下:

0. CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.

1. CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.

3. CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file

4. CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.

5. CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.

6. CV_CAP_PROP_FPS Frame rate.

7. CV_CAP_PROP_FOURCC 4-character code of codec.

8. CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.

9. CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .

10. CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.

11. CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).

12. CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).

13. CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).

14. CV_CAP_PROP_HUE Hue of the image (only for cameras).

15. CV_CAP_PROP_GAIN Gain of the image (only for cameras).

16. CV_CAP_PROP_EXPOSURE Exposure (only for cameras).

17. CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.

18. CV_CAP_PROP_WHITE_BALANCE Currently unsupported

19. CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

我的问题是:

是否可以通过python/opencv设置相机曝光时间(或其他相机参数)?

如果不是,我将如何去设置这些参数?

注意:有相机制造商提供的C++代码显示了如何做到这一点,但我不是C++的专家(很长一段时间),并会欣赏任何基于python的解决方案。

在此先感谢!

2012-07-10

Mike

+2

那么什么是第15个选项,即CV_CAP_PROP_EXPOSURE?是不是曝光时间? –

2012-07-11 09:18:59

+3

是的。我所做的一点是,试图修改它会产生任何可衡量的结果。 (这是'cap.set(15,x)',没有'x'的值会产生可测量的变化。) 顺便说一句,感谢您的博客。对于通过python加快opencv的速度,我已经非常有用了。你得到一个赞成:) –

2012-07-11 20:01:36

+0

最后一行:cv2.VideoCapture(0).release()可以简单地是cap.release():) –

2013-10-07 12:54:54

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值