I have been working with my Raspberry Pi 2B for a while now. Testing the Pi cam using raspistill
works great but trying to use OpenCV functions such as VideoCapture.open();
won't work. trying the same command with a USB camera works just fine. I tried different indexes as inputs but nothing works for the pi cam. What am I missing here?

- 1,573
- 8
- 25
- 43
2 Answers
sudo modprobe bcm2835-v4l2
will "enable" the camera for opencv automatically.
make sure you have the camera enabled from the raspberry config, either gui or raspi-config. the above loads the necessary drivers to handle everything automatically, i.e. loads the appropriate interfaces (v4l2 drivers) for the raspberry camera.
works out of the box on raspbian jessie. other releases might include the drivers by default, but the link below contains info on compiling the drivers in your worst case. so you should be able to get this to work with pidora as well.
more info: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=62364

- 807
- 7
- 3
-
This fixed the problem for me on Jessie. Simple and effective. – Josh Davis Jun 16 '16 at 21:41
-
Note: your rpi camera will work right out off the box using the PiCamera library BUT it won't work directly using openCV unless you run the above command provided by ats, thank you – user1988824 Jan 31 '18 at 17:53
-
That did the trick for me. Raspberry Pi 2 Model B + Python 3 + OpenCV 3.1.0 and Raspbian Stretch. Thanks. – Marlon Mar 07 '18 at 16:14
-
Great, activated the camera! – Vishal Kaul Jun 07 '18 at 16:56
I assume your question is about the C++ API, not the python one? As far as I understand the raspberry pi camera is not a usb camera and as such should be approached differently. For python there is is picamera package which works like a charm (with opencv). I never used the C++ interface but a quick google leads to this

- 8,806
- 4
- 41
- 56
-
-
So this actually works but not with `VideoCapture`. According to what I read [here](http://stackoverflow.com/questions/27950013/i-am-trying-make-the-raspberry-pi-camera-work-with-opencv) it is not possible to use OpenCV's `VideoCapture` with raspberry pi cam. – DMEM Apr 15 '15 at 21:49
-
I use openCV with video capture in python, which in the end is just a wrapper around C++ calls. I don't actually use the `VideoCapture` call, but do get each raw frame from the camera, using the instructions [here](http://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/). The trick they use there is to use capture (as opposed to record), but tell it to use the video-port and not the still-port of the camera. No idea if that helps you further along your way... – Claude Apr 15 '15 at 21:55