Webcam DirectShow Properties Page in Python

末鹿安然 提交于 2019-12-06 13:30:20

Since I've worked on this more lately, I can provide a partial answer to my own question for anyone interested:

videoInput library is included in the Direct Show implementation in OpenCV. The videoInput library can be used to open video properties page (gain, exposure, etc.), but not the video settings page (which would have capture format, image size, frame rate, etc.) since there is no code for it. Cython can be used to interface with this library in Python without too much issue.

OpenCV's Python bindings CAN be used to access the Direct Show video properties page. This requires:

  1. Using the Direct Show driver when opening the camera device, by adding the value CV_CAP_DSHOW to the index (no python constant, use value 700).
  2. Calling the window to display using the (undocumented) propID CV_CAP_PROP_SETTINGS in VideoCapture::set(int propID, ...). Again, this constant is not in the Python bindings, so use the value 37 (from highgui_c.h)

(These instructions work as of OpenCV 2.4.6, hopefully more constants will come to the Python bindings)

I had a similar sounding problem. Basically, I accidentally fixed it by wanting to see what I captured.

cap = cv2.VideoCapture(0)
print cap.read()      #once to inialize
print cap.read()      #twice to check that it actually initialized

The first .read() returns (False, None) while the second one actually has the feed. Before I added this I would pass None to cv2.imshow('title',frame) and my program would crash.

I don't know if this solves your problem. Mine is a DinoLite USB microscope and I think I'm just accessing it through DirectX. OpenCV 2.4.8.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!