Wednesday, 12 April 2023

python select camera programatically

My programm should select three cameras and take pictures with each of it.

I have the following code at the moment:

def getCamera(camera):
    graph = FilterGraph()
    print("Camera List: ")
    print(graph.get_input_devices())

    #tbd get right Camera

    try:
        device = graph.get_input_devices().index("HD Pro Webcam C920")
    except ValueError as e:
        device = graph.get_input_devices().index("Integrated Webcam")
    return device

The code above worked fine. But I have three similar cameras with the same name.

Output of

    graph = FilterGraph()
    print("Camera List: ")
    print(graph.get_input_devices())

is a list with 3 Cameras all the same name. I thought they are in an array and I can select them with

device = graph.get_input_devices().index(0) 

Like any other Array

But I only can access with the Name. like in the first code example.

How can I access the cameras with index?

Thanks in advance



from python select camera programatically

No comments:

Post a Comment