[Python] Opencv changing camera resolution with v4l2 backend not working

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I am using opencv 4.10.0 from conda-forge compiled with v4l2 backend on ubuntu.

    It seems I can't set the camera resolution, is there any workaround?

    import cv2 as cv

    cam = cv.VideoCapture(0, cv.CAP_V4L2)
    w, h = 1920, 1080
    cam.set(cv.CAP_PROP_FRAME_WIDTH, w)
    cam.set(cv.CAP_PROP_FRAME_HEIGHT, h)

    actual_width = cam.get(cv.CAP_PROP_FRAME_WIDTH)
    actual_height = cam.get(cv.CAP_PROP_FRAME_HEIGHT)
    print(f"Resolution: {actual_width}x{actual_height}")


    Output:

    Resolution: 640.0x480.0


    PS: the resolution is valid for that camera. When using the cheese app, it defaults to 1920x1080 which is the one I want.

    Continue reading...

Compartilhe esta Página