Can't open camera by index on Raspberry-pi4

Question:

So, i installed the official Raspberry-pi OS "Raspberry pi OS Lite 64" and installed OpenCV.

But when trying to call cv2.VideoCapture(1) an error appears (i have USB camera):

[ WARN:[email protected] ] global /io/opencv/modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index. 

My code:

import cv2

cap = cv2.VideoCapture(0)

while True:
    _, imgOrignal = cap.read(
    cv2.imwrite(rf"photo.jpg", imgOrignal)

I tried changing 0 to 1, -1 and cv2.CAP_V4L2, but nothing worked. It seems to me that this is due to the fact that I installed "Raspberry pi OS Lite 64". I think it just doesn’t have the right drivers, but i didn’t find anything on google 🙁

Asked By: kostya

||

Answers:

Ohh, i just turned off my Raspberry-pi and wait about 30 minutes. Now it works…

Answered By: kostya