Markus H
Posts: 1
Joined: Mon Feb 08, 2016 4:35 pm

OpenCV C++ camera module

Mon Feb 08, 2016 5:40 pm

Hello,

I am working on a project in which I use a raspberry pi 2 with a raspberry pi camera model and OpenCV C++ for gesture recognition. It already works quite nice, but I searched the web for hours in order to find information on how to achieve the best performance in terms of fps and, even more important, delay. But most articles and discussions I found are from 2013, so I think they are outdated.

At first, I used raspicam_cv for grabbing frames, now I use v4l2. I read a lot about hardware acceleration, Y-channel extraction, mmal and so on and so forth. But I am not that experienced in programming and before I wast too much time, I thought that someone could possibly steer me into the right direction.

What I need: My algorithm starts with a small (<640x480) grey-scale image which is then converted into a binary image. So my questions are:

1.) How do I get a grey-scale image from the camera module into OpenCV C++ most efficiently? Do I somehow need to extract the Y-channel from a YUV-format? Or is there even a much faster approach which uses a different format? And how do I get OpenCV to accept YUV- or other formats? I have figured out that OpenCV overrides all the settings that I previously set by using v4l2-ctl in the command line. So if I set a certain format with v4l2, and I run my program, afterwards the "Format Video Capture" is set back to 'BGR3' (checked with v4l2-ctl --all). Also, "set(CV_CAP_PROP_CONVERT_RGB , false)" seems not to be supported as I get a "HIGHGUI ERROR: V4L: Property <unknown property string>(16) not supported by device" error.

2.) I figured out that, even though the v4l2-ctl settings are overridden, I am able to set the frame’s width and height using OpenCV’s functions Capture.set() . In terms of best performance, are there certain resolutions which are „faster/better“ than others? By using v4l2-ctl -list-formats-ext I can see that the native resolution of the sensor is 2592x1944 pixels. So in theory, it should be faster to compute a resolution of 259x194 than 320x240. Is that correct?

3) In this http://www.pyimagesearch.com/2015/12/28 ... nd-opencv/ blog, I read about increasing raspberry pi fps and decreasing I/O latency with Python and OpenCV by using a separate thread for grabbing frames from the camera module, so that the video processing pipeline is never blocked. Has anyone ever tried something similar with C++ and OpenCV?

4) I want to be able to set some parameters (especially the exposure time, ISO etc.) myself manually. How can I do that? Do I need to change these settings in OpenCV or in v4l2-ctl?

I am asking all this because I know that the raspberry camera module is capable of capturing 90 frames per second. Even though I know that this frame-rate is not achievable together with video processing, I am pretty sure that I might get closer to it.

Any help is appreciated! Thank you very much in advance! :-)

luballe
Posts: 1
Joined: Tue Jun 11, 2013 7:18 pm

Re: OpenCV C++ camera module

Wed Apr 06, 2016 5:07 pm

Hello,

This is an approach to your first question:

Back in end-2014 I wrote an algorithm in Python that used the PiCamera API Witten by Dave Jones (https://github.com/waveform80/picamera). Although, your target language is C++ (Probably you'll get much better performance) the encoder pipeline is the same:

1. The camera sensor Omnivision OV5647 (http://cdn.sparkfun.com/datasheets/Dev/ ... 7_full.pdf) yields raw bayern data at full resolution (2592x1944) organized in a BGGR pattern (http://en.wikipedia.org/wiki/Bayer_filter).
2. Then, after GPU processing you can get RGB or YUV420 encoded image.
3. After another processing you will get JPEG, PNG or other formats.

So, you might think that working with the encoded image data (Bayer) will get the best performance. However, the image processing (reducing the image size and getting the grayscale) will be probably done in the CPU (Unless you will program the RPI's GPU which is a herculean task).

From my experience, working with the YUV420 images is a good choice. You can get the grayscale image (luminance) without losing resolution and no significant delay. Even from array YUV420 data you can extract the Y channel pretty easy: https://en.wikipedia.org/wiki/YUV#Y.27U ... conversion

Dave Jones and his python API has a way to get the Y,U and V channels very easily:
http://picamera.readthedocs.org/en/rele ... yuv-format

I'm pretty sure that there should be a C++ counterpart. Probably this links can help you:

http://www.uco.es/investiga/grupos/ava/node/40 and https://sourceforge.net/projects/raspicam/files/
http://robotblogging.blogspot.com.co/20 ... i-for.html

sampro
Posts: 3
Joined: Tue Jun 28, 2016 5:38 am

Re: OpenCV C++ camera module

Mon Jul 18, 2016 12:20 pm

2.) I figured out that, even though the v4l2-ctl settings are overridden, I am able to set the frame’s width and height using OpenCV’s functions Capture.set() .
I have the same problem, getting HIGHGUI error when setting camera attributes, how you do that?

Return to “Graphics programming”