6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Fri Mar 28, 2014 9:18 pm

BerryPicker wrote:@6by9 Thank you for quickly answering my post. Sorry to have taken you back over old ground; it was due to my lack of knowledge. Following the link you gave has helped me understand where v4l2 is developed. I dared to do an rpi-update and was pleased to find that with it the colours are now true. I find that the pixel format chosen by cv2.VideoCapture is now RGB3, and learned that RGB24 and RGB3 are equivalent.
No problem, but an rpi-update should really be your first port of call. Doing so will also have given you access to things like the full field of view for preview, and the 90fps at VGA mode.
The V4L2 driver is just part of the kernel (linux/drivers/media/platform/bcm2835/), so you can see all the changes by looking at the history of that directory in github. If you felt like it, there's nothing stopping you (or anyone else) adding extra features and making pull requests - that's one of the positives of open source that everyone keeps on banging on about! I won't hold my breath for it though.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Fri Apr 04, 2014 5:15 pm

Just a quick post to update this official thread. There have been a couple of extra features added following requests from other threads.

- Manual white balance control using V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE = V4L2_WHITE_BALANCE_MANUAL, and then V4L2_CID_RED_BALANCE and V4L2_CID_BLUE_BALANCE. (In v4l2-ctl terms, "v4l2-ctl --set-ctrl=white_balance_auto_preset=0", "v4l2-ctl --set-ctrl=red_balance=XXXX", "v4l2-ctl --set-ctrl=blue_balance=XXXX"). Value is the gain *1000.
- New pixel formats added. After a little head scratching, I've found a reasonable way to do BGR3. It's still more processing on the GPU than RGB3, but it does work. I've also added YV12 (YVU420) and NV21 (YVU420SP) as they were simple to do. (This should be in a release happening RSN - Dom is intending it to be tonight)
- The changes to remove the extra padding are still in the progress. It's all written, but needs some thorough testing. If folks want to be my beta-testers then I could post the V4L2 patch required. (The GPU changes should again be released tonight).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5106
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Official V4L2 driver

Fri Apr 04, 2014 7:34 pm

The updates should be in rpi-update now.

Mark_PH
Posts: 5
Joined: Sun Mar 09, 2014 2:21 pm

Re: Official V4L2 driver

Mon Apr 07, 2014 4:20 am

Hello,
I want to use two modes for my project: Daylight settings with auto exposure and night settings with maximum exposure time and ISO. I have a function to calculate the sun altitude and want to change from day to night settings after twilight. But the images I get during night via the V4L2 driver are very dark.

What v4l2-ctl calls have to be used to set the camera to 1s exposure time and maximum ISO?

I currently use this sequence of commands:
- v4l2-ctl --set-ctrl=exposure_dynamic_framerate=1
- v4l2-ctl --set-ctrl=auto_exposure=1
- v4l2-ctl --set-ctrl=exposure_time_absolute=10000
- v4l2-ctl -p 1

But the output image is very dark. I doubt it is 1s.

What are the v4l2-ctl calls to switch back to auto exposure and auto ISO?

Can I change the exposure settings during the video recording or do I have to stop recording first? I capture 1fps in YUV mode (1280x960) with a modified version of uvccapture.

Best regards,
Mark

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Mon Apr 07, 2014 5:41 am

I have been happy for my night video with the following settings:
v4l2-ctl --set-ctrl=exposure_dynamic_framerate=1
v4l2-ctl --set-ctrl=scene_mode=8

Works also during the day, so I do not switch modes anymore.

My only issue is that raspberry hangs after some days. My record is 6 days only. mjpg_streamer just stops working and only reboot gets it going.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Mon Apr 07, 2014 2:51 pm

I have a patch ready that should allow V4L2 to produce YUV and RGB images that have no padding (multiple of 32 width and 16 on height). The patch also means that the rounding on JPEG, H264 and MJPEG formats is removed. The image does still need to be a multiple of 2 for both width & height as we're dealing with YUV420 under the bonnet.

Can I ask if there are a couple of people on this thread that would be happy to give it a bit more testing than I have the time for at the moment?

If you could PM me and I'll send the patch over. You will need to be able to recompile the kernel and V4L2 driver with the patch applied, although I can look into dropping a copy of bcm2835-v4l2.so (based on top of tree) somewhere useful if necessary.

Thanks.

(I've just noticed that there are a couple of formats not handled in the GPU at the moment. At the moment V4L2_PIX_FMT_YUV420 and V4L2_PIX_FMT_RGB24 should be good though, and it's another easy GPU mod for the others.)
edit: Looked at the wrong branch :oops: All 4 of the YUYV formats are handled too, as is YVU420. It's only V4L2_PIX_FMT_NV21, V4L2_PIX_FMT_NV12, and V4L2_PIX_FMT_BGR24 that aren't.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Mark_PH
Posts: 5
Joined: Sun Mar 09, 2014 2:21 pm

Re: Official V4L2 driver

Tue Apr 08, 2014 5:04 am

I have been happy for my night video with the following settings:
v4l2-ctl --set-ctrl=exposure_dynamic_framerate=1
v4l2-ctl --set-ctrl=scene_mode=8
It's not working for me. The image is underexposed and almost black. What program are you using to capture the images?

Mark

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Tue Apr 08, 2014 6:03 am

After thos settings I start:

Code: Select all

nohup mjpg_streamer -i "/usr/local/lib/input_uvc.so -n -f 10 -r 1296x972" -o "/usr/local/lib/output_http.so -p 10088 -w /usr/local/www"&

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Tue Apr 08, 2014 4:04 pm

6by9 wrote:Can I ask if there are a couple of people on this thread that would be happy to give it a bit more testing than I have the time for at the moment?
Tumbleweed blowing across the savannah.
So after all the shouting early on, I guess no one cares now. It'll go back on the back burner for now.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Tue Apr 08, 2014 5:31 pm

We care, but compiling the kernel is quite an obstackle for us mere mortals.

M_P
Posts: 43
Joined: Sun Jan 06, 2013 5:40 pm

Re: Official V4L2 driver

Wed Apr 09, 2014 12:53 am

6by9 wrote:
6by9 wrote:Can I ask if there are a couple of people on this thread that would be happy to give it a bit more testing than I have the time for at the moment?
Tumbleweed blowing across the savannah.
So after all the shouting early on, I guess no one cares now. It'll go back on the back burner for now.
Sorry, work's been crazy - I don't get on the forum as much as I'd like.

I've never done anything like that on Debian, and it's been years since I compiled a kernel in Slackware, but I'm certainly willing to give it a try!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Wed Apr 09, 2014 8:34 am

OK, I'll sort out somewhere that I can dump a firmware image and prebuilt bcm2835-v4l2.so for people to test - saves people having to rebuild the kernel.
Having found qv4l2 as a graphical version of v4l2-ctl, my testing has been quite a lot easier and seems to be good (other than limitations on the formats it supports). I'd still like others to test it with their use cases.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Wed Apr 09, 2014 3:14 pm

If people want to test the new V4L2 update for removing the padding from the images, then please I've started from a clean 2014-01-07-wheezy-raspbian install, but NOOBS should work just as well as long as it is updated first.

So this should mean that any resolution that is a multiple of 2 for width and height should be selectable.
If the resolution is a multiple of 16 or 32 (dependent on format) on width, and a multiple of 16 on height, then the GPU has to do less work, but any multiple of 2 from 16x16 up to 2592x1944 should work.
The buffer size reported by v4l2-ctl -V will always include the padding, but the buffers delivered back will report the correct size for the active pixel data.

I do have a modified qv4l2 that supports all the formats that the RaspberryPi V4L2 driver does (except H264). I'll sort that out and push it to github too, as well as finding the maintainers and pushing it upstream properly.

Could people pleaselet me know if they do test it, and what results they get? I'm fairly happy that this is all good, but has the potential to all blow up! I'm not going to release it until I have heard from at least a couple of other people who haven't found anything bad with it.

(The really keen eyed among you may notice that the driver now claims to support V4L2_PIX_FMT_BGR32. The firmware update for that one hasn't been released yet, so I expect that one to fail.)
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Thu Apr 10, 2014 7:58 am

It does not work for me.

sudo modprobe bcm2835-v4l2
ERROR: could not insert 'bcm2835_v4l2': Exec format error

the module is very small. Do I have it corectly copied:
-rw-r--r-- 1 root root 25034 Apr 10 10:40 bcm2835-v4l2.ko
-rw-r--r-- 1 root root 54983 Apr 10 10:36 bcm2835-v4l2.ko.orig

$ sum /lib/modules/3.10.36+/kernel/drivers/media/platform/bcm2835/*
26766 25 /lib/modules/3.10.36+/kernel/drivers/media/platform/bcm2835/bcm2835-v4l2.ko
05450 54 /lib/modules/3.10.36+/kernel/drivers/media/platform/bcm2835/bcm2835-v4l2.ko.orig

ethanol100
Posts: 475
Joined: Wed Oct 02, 2013 12:28 pm

Re: Official V4L2 driver

Thu Apr 10, 2014 8:34 am

The module has a size of 54KB. Your download seems damaged. You can try to download it using wget:

Code: Select all

wget https://github.com/6by9/RPiTest/raw/master/v4l2_padding/bcm2835-v4l2.ko
You can use md5sum to check your file. For my downloaded module which can be loaded fine it is:

Code: Select all

md5sum bcm2835-v4l2.ko
105925eb2c80ceb6fdc75aa3bb1a3606  bcm2835-v4l2.ko

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Thu Apr 10, 2014 10:51 am

Thanks!
Got it running. So far so good. And indeed it now obeys the requested resolution.

I just started testing.

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Fri Apr 11, 2014 6:59 am

Passed all my tests. It run over night and I tried about 10 different resolutions.
The only failure was with 2592x1944 @10fps, but I guess I run out of gpu memory or my local network throughput. I did not check that more. It is too much for my systems anyway.
It also gave nice message when I made an error and worked:

Code: Select all

$ /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -n -f 10 -r 12800x720" -o "/usr/local/lib/output_http.so -p 10088 -w /usr/local/www"
MJPG Streamer Version: svn rev: 3:172
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 12800 x 720
 i: Frames Per Second.: 10
 i: Format............: MJPEG
i: The format asked unavailable, so the width 2592 height 720 
 o: www-folder-path...: /usr/local/www/
 o: HTTP TCP port.....: 10088
 o: username:password.: disabled
 o: commands..........: enabled
I also got once
[72419.125061] bcm2835-v4l2: error 0 waiting for frame completion
But the camera did not hang. Previously after this error I had to reboot tthe RPi, but now it kept on going.

Excellent work; seems to work better that the previous version. Many thanks for this major improvment!

I switch my security cameras to this now with 1280x960 @10fps (I used to run 1296x972 @10fps.)

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Fri Apr 11, 2014 8:07 am

shuckle wrote:Passed all my tests. It run over night and I tried about 10 different resolutions.
The only failure was with 2592x1944 @10fps, but I guess I run out of gpu memory or my local network throughput. I did not check that more. It is too much for my systems anyway.
Which pixelformat were you trying for 2592x1944? If it was MJPEG or H264 then I would expect it to fail as the driver expects a max of 1080P for video encode or preview.
shuckle wrote:It also gave nice message when I made an error and worked:

Code: Select all

$ /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -n -f 10 -r 12800x720" -o "/usr/local/lib/output_http.so -p 10088 -w /usr/local/www"
MJPG Streamer Version: svn rev: 3:172
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 12800 x 720
 i: Frames Per Second.: 10
 i: Format............: MJPEG
i: The format asked unavailable, so the width 2592 height 720 
 o: www-folder-path...: /usr/local/www/
 o: HTTP TCP port.....: 10088
 o: username:password.: disabled
 o: commands..........: enabled
That's just the way V4L2 works as long as the application does things correctly. The call is "try-video-fmt" which will clip the requested resolution to the closest supported resolution. Going for 12800x720 would be very optimistic!
Have you only be testing with mjpg_streamer? All the pixelformats need to be checked at some point.
shuckle wrote:I also got once
[72419.125061] bcm2835-v4l2: error 0 waiting for frame completion
But the camera did not hang. Previously after this error I had to reboot tthe RPi, but now it kept on going.
I ought to look again at that message. On shutdown the driver waits for completion of the current frame, but if the signal is sent to the GPU when there isn't a request in progress, then there isn't one.
shuckle wrote:Excellent work; seems to work better that the previous version. Many thanks for this major improvment!
Glad it's working for you, and thank you for your efforts in testing it. A bit more testing and I'll get it pushed officially.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Official V4L2 driver

Fri Apr 11, 2014 8:17 am

6by9 wrote:
shuckle wrote:Passed all my tests. It run over night and I tried about 10 different resolutions.
The only failure was with 2592x1944 @10fps, but I guess I run out of gpu memory or my local network throughput. I did not check that more. It is too much for my systems anyway.
Which pixelformat were you trying for 2592x1944? If it was MJPEG or H264 then I would expect it to fail as the driver expects a max of 1080P for video encode or preview.
Yes, I was using the same mjpg_streamer (=mjpeg).
6by9 wrote:Have you only be testing with mjpg_streamer? All the pixelformats need to be checked at some point.
Yes, I have only tested with mjpg_streamer as that is what I use in zoneminder and have the test system ready and I know how it works now.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Mon May 19, 2014 3:00 pm

This has been on my list of things to do for so long I'd almost forgotten it.

I've finally found a couple of hours to test out removing the padding from the images produced by the V4L2 driver with all the possible YUV and RGB output formats (compressed formats should just work anyway).
After ironing out a couple of little bugs that were still present in the firmware, it is all looking good. No more width a multiple of 32, or height a multiple of 16 restrictions! :D

I've pushed the firmware changes internally, and made the pull request for the kernel changes, so it's now down to Dom to pick it up and make a release when he has the time.
As a bonus, you also gain support for V4L2_PIX_FMT_BGR32 as a new pixel format, and V4L2_CID_MPEG_VIDEO_H264_I_PERIOD as a new parameter (the equivalent of the -g option in raspivid).

Enjoy!
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

kandrea
Posts: 4
Joined: Mon May 19, 2014 10:07 pm

Re: Official V4L2 driver

Mon May 19, 2014 10:51 pm

pondruska wrote:When I try to load the camera in OpenCV I get an error:
HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP
The image is eventually fetched but in 'BGR3' format and is cropped (compared to raspistill output). Moreover when I try to change resolution I get the same error and the resolution stays at 640x480 all the time.
I just started looking at the V4L2 drivers for use with OpenCV and hit the same wall that you have, pondruska, with respect to the message and resolution.

I pulled cap_v4l.cpp source of highgui from OpenCV 2.4.9 and stepped through the execution. The VIDIOC_CROPCAP error is just on a check to ascertain whether or not the camera supports that ioctl; the error simply indicates that the device does not support it and that it skipped setting the crop type. It doesn't affect the image capturing, however, it does attempt to run on every call to icvSetVideoSize, which ultimately is the base for calls to VideoCapture::set for changing the CV_CAP_PROP_FRAME_HEIGHT or WIDTH, which is why that error always appears in conjunction with attempts at changing the resolution.

The problem with the fixed 640x480 resolution was the following ioctl call that sets the capture width and height. On the first run, which is called from VideoCapture's constructor on camera initialization, uses some defaults to call icvSetVideoSize, which initializes the camera to 640x480. Future calls, however, through VideoCapture::set, result in the ioctl failing, with a return code of 16, EBUSY (device is busy). I couldn't find any means of getting a resolution change to pass after initialization, it always returns EBUSY.

My fix to get this to operate for my robots was to hack a new constructor into VideoCapture that allowed me to specify an initial resolution, and then to use that instead of the defaults. It allowed us to change the resolution on camera initialization within OpenCV, which is better than the alternatives of being stuck with the older userland/robidouille camera code. This works for all resolutions from minimum up to 720P. I am capturing still images at 1280x720, without the framerate cap, using BGR3, at 28.3 FPS. 1024x720 is coming in at 34.12 FPS.

Now, I'm not an OpenCV user or a vision guy. I've just been trying to build up a new system for use with our robots that would increase framerate, and this does accomplish that marvelously. My problem now is in trying to exceed a height of 720. I'm only concerned with still images, but every attempt I've made withing OpenCV to exceed a height of 720 results in a frame rate drop to 8 and a corrupted output image that renders all black.

I realize that OpenCV is a smaller audience for this camera and driver, and that the problem here is likely contained within OpenCV itself; I was just wondering if anyone had any inclinations as to why I might be limited to a height of 720. Naturally raspistill performs beautifully at far exceeding resolutions.

Additionally, if anyone has any idea about what might have changed within OpenCV from 2.4.6, where we were able to change the resolution on the fly, to the current post-patch (2.4.8) version that returns EBUSY on each call following camera initialization, I would be most interested to find what may be causing this to fail.

Thanks,
Kevin

magnatag
Posts: 33
Joined: Tue Mar 04, 2014 8:39 pm

Re: Official V4L2 driver

Tue May 20, 2014 4:22 pm

Hi Kevin,

Any chance you can share your modified opencv code/constructor and your procedures? I am building an opencv project using RPI cam and I am definitely running into the super low framerate issue.

Thanks!

kandrea
Posts: 4
Joined: Mon May 19, 2014 10:07 pm

Re: Official V4L2 driver

Tue May 20, 2014 9:24 pm

magnatag wrote:Hi Kevin,

Any chance you can share your modified opencv code/constructor and your procedures? I am building an opencv project using RPI cam and I am definitely running into the super low framerate issue.

Thanks!
Greetings,

I have no problems sharing the code snippets. My only condition is that you agree that this is not a particularly acceptable solution; it's just a means of bypassing the problem for the moment. For this build I used the sourceforge repository to get the OpenCV 2.4.9 source, created a release directory off of the main folder, then ran 'cmake ..' from there. I then made the modifications, returned to my release directory and then ran 'make;sudo make install'

modules/highgui/src/cap_v4l.c: added two lines after 246

Code: Select all

245: #define DEFAULT_V4L_WIDTH  1920
246: #define DEFAULT_V4L_HEIGHT 1080
<added>: static int default_resolution_width = DEFAULT_V4L_WIDTH;
<added>: static int default_resolution_height = DEFAULT_V4L_HEIGHT;
modules/highgui/src/cap_v4l.c: lines 425-426 modified

Code: Select all

425 original: capture->form.fmt.pix.width = DEFAULT_V4L_WIDTH;
426 original: capture->form.fmt.pix.height = DEFAULT_V4L_HEIGHT;
425 new:  capture->form.fmt.pix.width = default_resolution_width;
426 new:  capture->form.fmt.pix.height = default_resolution_height;
modules/highgui/src/cap_v4l.c: line 874 modified

Code: Select all

874 original: icvSetVideoSize(capture, DEFAULT_V4L_WIDTH, DEFAULT_V4L_HEIGHT);
874 new: icvSetVideoSize(capture, default_resolution_width, default_resolution_height);
modules/highgui/src/cap_v4l.c added to end of file, just above #endif

Code: Select all

int cvCameraDefaultResolution_V4L( int w, int h )
{
    default_resolution_width = w;
    default_resolution_height = h;
    return 0;
}
modules/highgui/src/precomp.hpp added the following line

Code: Select all

int cvCameraDefaultResolution_V4L( int w, int h );
modules/highgui/src/cap.cpp added

Code: Select all

VideoCapture::VideoCapture(int device, int w, int h)
{
    cvCameraDefaultResolution_V4L( w, h );
    open(device);
}
modules/highgui/include/opencv2/highgui.hpp: Added after line 209

Code: Select all

    CV_WRAP VideoCapture(int device, int w, int h);
Additionally, I used the following modifications to view the error returned from the ioctl on setting the resolution.
modules/highgui/src/cap_v4l.cpp

Code: Select all

2505: int rtn = ioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form);
<added on next line> fprintf(stderr, "Setting video size to (%dx%d).  Return: %d, Errno: %d\n", w, h, rtn, errno);
The FPS cap exists on both the v4l2 side and the OpenCV side. To lift the OpenCV cap, change it on this line. The default is 30.
modules/highgui/src/cap_v4l.cpp

Code: Select all

2512: setfps.parm.capture.timeperframe.denominator = 30;
With respect to my local vision code, I use the following v4l2 settings to get the advertised frame rates.

Code: Select all

system("sudo modprobe bcm2835-v4l2");
char command[255] = {0};
sprintf(command, "v4l2-ctl --set-fmt-video=width=%d,height=%d,pixelformat=%d\n", width, height, mode);
system(command);
system("v4l2-ctl --set-ctrl horizontal_flip=1,vertical_flip=1");
system("v4l2-ctl --set-ctrl white_balance_auto_preset=0");
system("v4l2-ctl -p 40");
Note that OpenCV will not use width or height whatsoever from the v4l2 controls, but the rest of it works as advertised within that environment.

Sorry to the moderators about the length of these messages. Just hope that it's of some help; again, with the understanding that this is a hack to workaround an OpenCV issue, not a fix. It's just what I modified to get us running in OpenCV with v4l2. The current issue with resolution is that it's locked to 720P. Exceeding 1280x720 will cause the capture to fail within OpenCV. I still don't have anything to go off of on this issue.

Kevin

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4536
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Official V4L2 driver

Wed May 21, 2014 7:42 am

kandrea wrote:The current issue with resolution is that it's locked to 720P. Exceeding 1280x720 will cause the capture to fail within OpenCV. I still don't have anything to go off of on this issue.
Seeing as several people are hitting this (eg http://www.raspberrypi.org/forums/viewt ... 3c#p553628), I've made a change that allows you to specify the point where the GPU switches from video to stills mode.
V4L2 driver change is at https://github.com/6by9/linux/commit/44 ... 6d5c77885f
A prebuilt copy of the V4L2 driver (based on 3.12.20+ tree - you MUST do a rpi-update to ensure things match on this) is available at https://github.com/6by9/RPiTest/blob/ma ... 35-v4l2.ko (Please be aware that the firmware change for part of this hasn't been pushed yet, so PLEASE stick with the width being a multiple of 32, and the height a multiple of 16 for now. NB 1080 is NOT a multiple of 16)

With that you should be able to specify the limit as you load the driver with

Code: Select all

sudo modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944
or whatever resolution you fancy. I've had it running via v4l2-ctl streaming 5Mpix YU12/I420 to dev/null at 15fps (ie full framerate for 5MPix)

I'll make a pull request on this change today, but I don't know when Dom is next doing a release.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

kandrea
Posts: 4
Joined: Mon May 19, 2014 10:07 pm

Re: Official V4L2 driver

Wed May 21, 2014 11:01 pm

6by9 wrote:With that you should be able to specify the limit as you load the driver with

Code: Select all

sudo modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944
or whatever resolution you fancy.
Thank you very much for this update to the driver. I just ran a test in OpenCV at 1280x1024 with 18.62 FPS, and 2592x1936 with 3.78 FPS, averaged over 600 still image captures each, and the images look beautiful. One of my researchers is going to be very happy.

Kevin

Return to “Camera board”

Who is online

Users browsing this forum: No registered users and 11 guests