bunkahle / pygrabber

Python tool to capture photo from camera and for doing simple image processing using DirectShow and OpenCV
MIT License
17 stars 5 forks source link

OS Error when trying to open video capture device settings dialog #6

Open tfranzen opened 2 months ago

tfranzen commented 2 months ago

With pygrabber I've finally found a way to talk to my See3CAM_CU135M camera from python. However I'd like to modify exposure settings (or show a dialog to do so). The set_properties() method looks like it should do that, but keeps throwing an error for me.

code snippet:

    graph          = FilterGraph()
    devices        = graph.get_input_devices()
    print(f"Connecting to device {devices[CAMERA_INDEX]}")
    graph.add_video_input_device(CAMERA_INDEX)
    graph.get_input_device().set_properties()

The error:

Traceback (most recent call last):
  File "C:\Users\pggs76\Documents\github\webcamtest\seecampygrabber.py", line 46, in <module>
    formats = graph.get_input_device().set_properties()
  File "C:\Users\pggs76\Anaconda3\envs\e39\lib\site-packages\pygrabber\dshow_graph.py", line 113, in set_properties
    show_properties(self.instance)
  File "C:\Users\pggs76\Anaconda3\envs\e39\lib\site-packages\pygrabber\dshow_graph.py", line 644, in show_properties
    OleCreatePropertyFrame(
  File "_ctypes/callproc.c", line 997, in GetResult
OSError: [WinError -2147467259] Unspecified error

Am I doing this right?

Thanks, Tobias

bunkahle commented 2 months ago

Please check you webcam functionality if you have an OSError. If you are on Windows you use tools like AMCAP - part of the library stored in https://videocapture.sourceforge.net/ under VideoCapture-0.9-5.zip https://videocapture.sourceforge.net/VideoCapture-0.9-5.zip

tfranzen commented 2 months ago

Thanks and sorry for the delayed response. AMCAP brings up the properties dialog no problem (it does seem to struggle rendering the Y8 or Y16 data though), so I assume the dialog is implemented correctly in the webcam driver. Can't find a fault with the code in pygrabber though.

I have now managed to use the IAMCameraControl to set the exposure, which essentially fulfills my need. If that's of interest I'll try to find some time to put together a proper integration into pygrabber and a pull request. Let me know if you have any thoughts on how the interface should look like (I'm thinking have a cameracontrols member on the input device with methods for get/set/get_range)