The question is a bit similar to this question.

The main difference is that I'm using a different camera (the Raspberry Pi camera board). I've spend a few days exploring Python and OpenCV. I'm writing a script on my Windows laptop that I want to run on my Raspberry Pi.

My Raspberry Pi has OpenCV 2.3.1 installed. I could make images using PiCamera, or I could write:

import os, sys
os.system('raspistill -o /var/www/images/image.jpg')

However, I want to use cv2.VideoCapture(int device). The documentation says:


  • filename – name of the opened video file
  • device – id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0.

cv2.CreateCapture(0) works perfectly fine on my laptop. On the Raspberry Pi however, it's unable to open the camera. I'm not experienced with Raspbian, so I'm not sure if 0 is the correct device ID.

Any help will be greatly appreciated.

  • I’ve had a similar issue an found that adding a 500 ms wait to allow the window to initialize works. Jul 31, 2021 at 19:50

1 Answer 1


Until recently this wasn't possible - it requires a V4L2 driver for the camera which was previously absent. This is now available, just follow the instructions here to set up the driver and cv2 videocapture should work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.