Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Access webcam without sudo

The code below will only work if I run it with sudo:

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)

while True:
    ret, img = cap.read()
    print(ret)  # False without sudo
    print(img)  # None without sudo

    cv2.imshow('img', img)
        k = cv2.waitKey(30) & 0xff
        if k == 27:
            break

I don't want to run it as sudo for various reasons. Adding my user to the video group on linux doesn't change anything. Do I need to add myself to another group?

Note: I know it's bad to add myself to the video group... I'll create another user when this works!