andreaschiavinato / python_grabber

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

"set_format" raises COMError #5

Open Toussaic opened 4 years ago

Toussaic commented 4 years ago

Hi,

I tried to use the "set_format" function (of the class "VideoInput" in "graph_dshow.py") when the grabber is running and a COMError is raised.

in current_format self.grabber.get_input_device().set_format(index)

File "...\pygrabber\dshow_graph.py", line 160, in set_format stream_config.SetFormat(media_type)

COMError: (-2147220953, None, (None, None, None, 0, None))

When calling FilterGraph.stop() before "set_format", I have another Error.

in current_format self.grabber.get_input_device().set_format(index)

File "...\pygrabber\dshow_graph.py", line 160, in set_format stream_config.SetFormat(media_type)

COMError: (-2147220992, None, (None, None, None, 0, None))

package_list.txt

jongra commented 2 years ago

I've the same problem. Did you found a solution for this?

I'm using the grabber for capturing images of generic UVC devices and I'm getting the exact same error.

PrimusSPS commented 1 year ago

For me, this error was showing when I tried to add a device using the below statement when no device was connected to the system.

FilterGraph().add_video_input_device(index)

I handled it using

from comtypes import COMError

try:
        FilterGraph().add_video_input_device(index)

except (COMError):
        # your statements

Update: ComError shows when a device shows in the list computed using FilterGraph().get_devices() but isn't actually connected to the system. I found this when I observed that add_video_input_device(another_index) throws an "Assertion error" for same for other indices after successfully adding the first index successfully.