2

I am trying to use the raspberry pi camera module as the live video feed in my opencv code(c++). However, the pi camera module does not work the same as the USB camera. eg: for USB webcam:

VideoCapture cam(0);
cam >> captured_frame;

will simply return me the new frame which I can perform algorithms on.

I found some libraries/tutorials online, but most of them are for either C or python based program.

5
  • 1
    Using V4L2 driver for raspberry camera sudo modprobe bcm2835-v4l2, you could access it like USB camera.
    – mpromonet
    Mar 8, 2015 at 22:39
  • Thanks @mpromonet, I got the V4L2 driver working and i am using it as a USB camera now. However, it does not perform as well as i expected: there is a 2 seconds lag in the video feed, and i am not able to change the resolution of the video. Mar 9, 2015 at 6:08
  • Whilst my knowledge of OpenCV in C++ is minimal, I do know that beneath the covers, OpenCV uses ffmpeg for video decoding. If the camera is configured for H.264 output you may find that ffmpeg is introducing (or at least contributing to) the lag, in which case using an unencoded pixel format like BGR3 or YU12 may be preferable.
    – Dave Jones
    Mar 9, 2015 at 16:10
  • Thanks @DaveJones for the clarification. I tried to set the video pixel format to RGR3/YU12, but it did not really make a difference. There is still a lag in the video feed. Is there any possible solution? Mar 9, 2015 at 23:52
  • I'm afraid I'm out of ideas at this point; I suspect any solution would involve digging into OpenCV to figure out exactly how it's calling ffmpeg (which I suspect is the culprit of the lag). That said I'm rather surprised you didn't see the same lag with a USB webcam, so I may well be wrong about my assumption!
    – Dave Jones
    Mar 16, 2015 at 18:35

1 Answer 1

0

You can use this link as a base : https://thinkrpi.wordpress.com/2013/05/22/opencv-and-camera-board-csi/ for your dev.

It's a little bit old, but it's a good point of entry for openCV and RPi camera.

1
  • Yes, i have tried that library. The image quality is really an issue and it is for C, not c++. But thanks for the help Mar 9, 2015 at 6:10

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