python opencv 摄像头亮度_Python 下opencv 应用: 摄像头参数设置

本文介绍了如何使用Python的OpenCV库来设置和读取摄像头参数,包括宽度、高度、曝光等。通过示例代码展示了如何设置参数,并通过遍历所有可能的参数编号来检查哪些参数可以被摄像头支持。还提到了使用其他软件来核实参数范围的重要性。
摘要由CSDN通过智能技术生成

为了取得好的图片效果,我们需要设置摄像头的参数。

假如摄像流为 cap, 那么设置参数是cap.set(参数编号,参数)

获取参数值的函数是  cap.get(参数编号)

看一段摄像头参数设置读取的例子吧,代码里先设置3个参数,然后再读取这3个参数。

import cv2

#选择摄像头号,一般从 0 开始

cap = cv2.VideoCapture(0)

#先设置参数,然后读取参数

cap.set(3,1280)

cap.set(4,1024)

cap.set(15, 0.1)

print("width={}".format(cap.get(3)))

print("height={}".format(cap.get(4)))

print("exposure={}".format(cap.get(15)))

while True:

ret, img = cap.read()

cv2.imshow("input", img)

# 按 ESC 键退出

key = cv2.waitKey(10)

if key == 27:

break

cv2.destroyAllWindows()

cv2.VideoCapture(0).release()

我的程序运行结果是:

width=1280.0

height=720.0

exposure=-1.0

宽,高,设置有效,而曝光量设置返回无效。

摄像头有哪些参数可以设置呢?参数编号的对应关系怎么样,请看下面列表。

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.

2. CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file

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

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

5. CV_CAP_PROP_FPS Frame rate.

6. CV_CAP_PROP_FOURCC 4-character code of codec.

7. CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.

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

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

10. CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值