我使用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的解決方案。
在此先感謝!
那麼什麼是第15個選項,即CV_CAP_PROP_EXPOSURE?是不是曝光時間? – 2012-07-11 09:18:59
是的。我所做的一點是,試圖修改它會產生任何可衡量的結果。 (這是'cap.set(15,x)',沒有'x'的值會產生可測量的變化。) 順便說一句,感謝您的博客。對於通過python加快opencv的速度,我已經非常有用了。你得到一個贊成:) – Mike 2012-07-11 20:01:36
最後一行:cv2.VideoCapture(0).release()可以簡單地是cap.release():) – otterb 2013-10-07 12:54:54