Official V4L2 driver


493 posts   Page 20 of 20   1 ... 16, 17, 18, 19, 20
by nandor65 » Tue Nov 22, 2016 3:38 pm
6by9,
thanks for your reply. I use OpenCV 3.1, I think this is the latest version. OK, so if fps is set AE will never use longer exposure time than 1/fps. Lets say fps=45, then max exposure time is 22msec. (and min exposure time = 1 msec?)

So under darker conditions - to force AE to use longest possible exposure time - below two settings should result similar images on the same scenes?

Setting A :: no AE
v4l2-ctl -p 45
v4l2-ctl -c auto_exposure=1
v4l2-ctl -c exposure_time_absolute=22
Setting B :: AE
v4l2-ctl -p 45
v4l2-ctl -c auto_exposure=0

I do use NoIR sensor and IR illumination for night vision experiments. It is true these experiments are started recently.
Posts: 8
Joined: Tue Nov 22, 2016 10:34 am
by 6by9 » Tue Nov 22, 2016 4:15 pm
nandor65 wrote:6by9,
thanks for your reply. I use OpenCV 3.1, I think this is the latest version. OK, so if fps is set AE will never use longer exposure time than 1/fps. Lets say fps=45, then max exposure time is 22msec. (and min exposure time = 1 msec?)

So under darker conditions - to force AE to use longest possible exposure time - below two settings should result similar images on the same scenes?

Setting A :: no AE
v4l2-ctl -p 45
v4l2-ctl -c auto_exposure=1
v4l2-ctl -c exposure_time_absolute=22
Setting B :: AE
v4l2-ctl -p 45
v4l2-ctl -c auto_exposure=0

I do use NoIR sensor and IR illumination for night vision experiments. It is true these experiments are started recently.

http://hverkuil.home.xs4all.nl/spec/uap ... trols.html again
V4L2_CID_EXPOSURE_ABSOLUTE (integer)
Determines the exposure time of the camera sensor. The exposure time is limited by the frame interval. Drivers should interpret the values as 100 µs units, where the value 1 stands for 1/10000th of a second, 10000 for 1 second and 100000 for 10 seconds.

So you'll want
v4l2-ctl -c exposure_time_absolute=220

Min exposure time is about 50usecs IIRC.
AE will naturally adopt the max permitted exposure time if the scene demands it (at night time it will).
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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4182
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by nandor65 » Tue Nov 22, 2016 5:36 pm
6by9, all right, so when exposure_time_absolute=22 is set this means exposure of 2.2ms and not 22ms. I missed a zero somewhere then.
what I wanted to have is a single set of sensor parameters which works for recognizing moving licence plates during the day as well as during the night. AE looks like a very good choice for daylight conditions, but fails when light amount drops. with IR AE does not look like doing a good job because plates are bleached out. I assume an ideal exposure time should be found.
to me now it looks like a set of parameter needed for the day and another set for the night. and I need some more reading. thanks for your kind support.
Posts: 8
Joined: Tue Nov 22, 2016 10:34 am
by 6by9 » Tue Nov 22, 2016 10:31 pm
AE will be looking at the whole scene rather than small patches.
There are options using V4L2_CID_EXPOSURE_METERING to switch the AE metering mode between average, spot, and centre weighted. I'll refer you again to the V4L2 spec. Spot mode is most likely to give the results you want.
Otherwise feel free to go with manual mode, but you may end up with more issues than you expect due to scene changes.
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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4182
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by nandor65 » Mon Nov 28, 2016 1:05 pm
As I have learned recently: AE uses maximum exposure time of 1/fps. I would like to use AE and keep my fps but I would like to set my maximum exposure time different from 1/fps. Different means much shorter, and never longer exposure times than 1/fps. How is it possible?
Posts: 8
Joined: Tue Nov 22, 2016 10:34 am
by racer993 » Fri Feb 17, 2017 7:01 am
Today I discovered that one of the raspberry pi cameras in my setup was not functioning as expected. It sometimes skipped taking a picture. I looked at dmesg and found a couple of errors which seem to relate to the v4l2 driver.

I've copied some snippets here below. Any idea what might be causing this?

Code: Select all
[688060.901171] bcm2835-v4l2: error 0 waiting for frame completion
[688063.901202] bcm2835_v4l2: error 0 waiting for sync completion
[688066.901228] bcm2835_v4l2: error 0 waiting for sync completion
[688066.901247] bcm2835-v4l2: Failed disabling camera, ret -62
[688066.901255] bcm2835-v4l2: Failed to disable camera
[688066.901263] ------------[ cut here ]------------
[688066.901295] WARNING: CPU: 2 PID: 24933 at drivers/media/v4l2-core/videobuf2-core.c:1670 __vb2_queue_cancel+0xfc/0x160 [videobuf2_core]()
[688066.901303] Modules linked in: bcm2835_v4l2 videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_core v4l2_common videodev media nfsd rpcsec_gss_krb5 snd_bcm2835 snd_pcm snd_timer snd bcm2835_gpiomem bcm2835_wdt uio_pdrv_genirq uio ipv6
[688066.901381] CPU: 2 PID: 24933 Comm: capture Not tainted 4.4.15-v7+ #897
[688066.901388] Hardware name: BCM2709
[688066.901422] [<80018724>] (unwind_backtrace) from [<80014058>] (show_stack+0x20/0x24)
[688066.901442] [<80014058>] (show_stack) from [<80320764>] (dump_stack+0xd4/0x118)
[688066.901463] [<80320764>] (dump_stack) from [<80025300>] (warn_slowpath_common+0x98/0xc8)
[688066.901482] [<80025300>] (warn_slowpath_common) from [<800253ec>] (warn_slowpath_null+0x2c/0x34)
[688066.901504] [<800253ec>] (warn_slowpath_null) from [<7f16928c>] (__vb2_queue_cancel+0xfc/0x160 [videobuf2_core])
[688066.901538] [<7f16928c>] (__vb2_queue_cancel [videobuf2_core]) from [<7f169608>] (vb2_core_queue_release+0x20/0x40 [videobuf2_core])
[688066.901568] [<7f169608>] (vb2_core_queue_release [videobuf2_core]) from [<7f1745f0>] (_vb2_fop_release+0x9c/0xac [videobuf2_v4l2])
[688066.901594] [<7f1745f0>] (_vb2_fop_release [videobuf2_v4l2]) from [<7f174634>] (vb2_fop_release+0x34/0x38 [videobuf2_v4l2])
[688066.901650] [<7f174634>] (vb2_fop_release [videobuf2_v4l2]) from [<7f12e500>] (v4l2_release+0x48/0x84 [videodev])
[688066.901685] [<7f12e500>] (v4l2_release [videodev]) from [<80158be8>] (__fput+0x94/0x1e4)
[688066.901703] [<80158be8>] (__fput) from [<80158da8>] (____fput+0x18/0x1c)
[688066.901723] [<80158da8>] (____fput) from [<8004097c>] (task_work_run+0xa0/0xd4)
[688066.901740] [<8004097c>] (task_work_run) from [<80027968>] (do_exit+0x348/0xab0)
[688066.901755] [<80027968>] (do_exit) from [<80028168>] (do_group_exit+0x4c/0xe4)
[688066.901769] [<80028168>] (do_group_exit) from [<80028220>] (__wake_up_parent+0x0/0x30)
[688066.901785] [<80028220>] (__wake_up_parent) from [<8000fb40>] (ret_fast_syscall+0x0/0x1c)
[688066.901794] ---[ end trace 093d4f1489a09556 ]---
[688070.381263] bcm2835_v4l2: error 0 waiting for sync completion
[688070.384017] bcm2835-v4l2: ==================  END STATUS  ==================
[688151.071855] bcm2835_v4l2: error 0 waiting for sync completion
[688154.071878] bcm2835_v4l2: error 0 waiting for sync completion
[688154.071898] bcm2835-v4l2: vidioc_s_fmt_vid_cap: failed to setup mmal components: -62
[688157.101903] bcm2835_v4l2: error 0 waiting for sync completion
[688160.121922] bcm2835_v4l2: error 0 waiting for sync completion
[688163.141942] bcm2835_v4l2: error 0 waiting for sync completion
[688166.161966] bcm2835_v4l2: error 0 waiting for sync completion
[688169.161986] bcm2835_v4l2: error 0 waiting for sync completion
[688172.162007] bcm2835_v4l2: error 0 waiting for sync completion
[688175.162032] bcm2835_v4l2: error 0 waiting for sync completion
[688175.162049] bcm2835-v4l2: Failed to set fps ret -186
[688178.322059] bcm2835_v4l2: error 0 waiting for sync completion
[688178.322107] bcm2835-v4l2: queue_setup: capture port not configured
[688181.792068] bcm2835_v4l2: error 0 waiting for sync completion
[688181.794473] bcm2835-v4l2: =================  START STATUS  =================

........

[698560.689390] bcm2835-v4l2: ==================  END STATUS  ==================
[698565.476695] bcm2835_v4l2: error 0 waiting for sync completion
[698568.476713] bcm2835_v4l2: error 0 waiting for sync completion
[698568.476733] bcm2835-v4l2: vidioc_s_fmt_vid_cap: failed to setup mmal components: -62
[698571.506735] bcm2835_v4l2: error 0 waiting for sync completion
[698574.526759] bcm2835_v4l2: error 0 waiting for sync completion
[698578.596808] bcm2835_v4l2: error 0 waiting for sync completion
[698581.616837] bcm2835_v4l2: error 0 waiting for sync completion
[698584.616849] bcm2835_v4l2: error 0 waiting for sync completion
[698587.616877] bcm2835_v4l2: error 0 waiting for sync completion
[698590.616896] bcm2835_v4l2: error 0 waiting for sync completion
[698590.616909] bcm2835-v4l2: Failed to set fps ret -186
[698593.766895] bcm2835_v4l2: error 0 waiting for sync completion
[698593.766939] bcm2835-v4l2: queue_setup: capture port not configured
[698597.226937] bcm2835_v4l2: error 0 waiting for sync completion
[698597.229360] bcm2835-v4l2: =================  START STATUS  =================
[698597.229379] bcm2835-v4l2: Saturation: 0
[698597.229395] bcm2835-v4l2: Sharpness: 0
[698597.229405] bcm2835-v4l2: Contrast: 15
[698597.229416] bcm2835-v4l2: Brightness: 50
[698597.229427] bcm2835-v4l2: ISO Sensitivity: 100000
[698597.229438] bcm2835-v4l2: ISO Sensitivity, Auto: Auto
[698597.229450] bcm2835-v4l2: Image Stabilization: false
[698597.229460] bcm2835-v4l2: Auto Exposure: Manual Mode
[698597.229471] bcm2835-v4l2: Exposure Time, Absolute: 125
[698597.229482] bcm2835-v4l2: Auto Exposure, Bias: 0
[698597.229493] bcm2835-v4l2: Exposure, Dynamic Framerate: false
[698597.229503] bcm2835-v4l2: Exposure, Metering Mode: Average
[698597.229514] bcm2835-v4l2: White Balance, Auto & Preset: Manual
[698597.229525] bcm2835-v4l2: Red Balance: 1520
[698597.229535] bcm2835-v4l2: Blue Balance: 1600
[698597.229546] bcm2835-v4l2: Color Effects: None
[698597.229556] bcm2835-v4l2: Color Effects, CbCr: 32896
[698597.229568] bcm2835-v4l2: Rotate: 0
[698597.229578] bcm2835-v4l2: Horizontal Flip: true
[698597.229588] bcm2835-v4l2: Vertical Flip: true
[698597.229599] bcm2835-v4l2: Video Bitrate Mode: Variable Bitrate
[698597.229610] bcm2835-v4l2: Video Bitrate: 10000000
[698597.229620] bcm2835-v4l2: Compression Quality: 30
[698597.229631] bcm2835-v4l2: Power Line Frequency: 50 Hz
[698597.229642] bcm2835-v4l2: Repeat Sequence Header: false
[698597.229652] bcm2835-v4l2: H264 Profile: High
[698597.229663] bcm2835-v4l2: H264 Level: 4
[698597.229673] bcm2835-v4l2: Scene Mode: None
[698597.229684] bcm2835-v4l2: H264 I-Frame Period: 60
[698597.229695] bcm2835-v4l2: ==================  END STATUS  ==================

........

[1275967.519489] INFO: task vcgencmd:29142 blocked for more than 120 seconds.
[1275967.519510]       Tainted: G        W       4.4.15-v7+ #897
[1275967.519518] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[1275967.519527] vcgencmd        D 805b4e4c     0 29142      1 0x00000005
[1275967.519574] [<805b4e4c>] (__schedule) from [<805b53c4>] (schedule+0x50/0xa8)
[1275967.519593] [<805b53c4>] (schedule) from [<805b82b4>] (schedule_timeout+0x1e8/0x270)
[1275967.519611] [<805b82b4>] (schedule_timeout) from [<805b7000>] (__down+0x88/0xc0)
[1275967.519631] [<805b7000>] (__down) from [<800690ac>] (down+0x54/0x68)
[1275967.519652] [<800690ac>] (down) from [<803cf73c>] (vchiq_release+0x12c/0x314)
[1275967.519673] [<803cf73c>] (vchiq_release) from [<80158be8>] (__fput+0x94/0x1e4)
[1275967.519692] [<80158be8>] (__fput) from [<80158da8>] (____fput+0x18/0x1c)
[1275967.519711] [<80158da8>] (____fput) from [<8004097c>] (task_work_run+0xa0/0xd4)
[1275967.519729] [<8004097c>] (task_work_run) from [<80027968>] (do_exit+0x348/0xab0)
[1275967.519745] [<80027968>] (do_exit) from [<80028168>] (do_group_exit+0x4c/0xe4)
[1275967.519762] [<80028168>] (do_group_exit) from [<800332a0>] (get_signal+0x370/0x6dc)
[1275967.519782] [<800332a0>] (get_signal) from [<8001341c>] (do_signal+0xc4/0x3c0)
[1275967.519801] [<8001341c>] (do_signal) from [<80013900>] (do_work_pending+0xb8/0xd0)
[1275967.519819] [<80013900>] (do_work_pending) from [<8000fb68>] (slow_work_pending+0xc/0x20)
(END)
Posts: 42
Joined: Mon Feb 18, 2013 7:27 pm
by zoukimando » Mon Jul 17, 2017 11:11 am
I'm sure I'm just being dumb, but I keep reading that I can just set the scene-mode to night, but I cannot see how. I've Googled it and got no where. I've tried various combinations of example code but nothing I've tried has worked. Like I say, I must be missing something obvious. Anybody give me an example?
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm
by 6by9 » Mon Jul 17, 2017 12:37 pm
zoukimando wrote:I'm sure I'm just being dumb, but I keep reading that I can just set the scene-mode to night, but I cannot see how. I've Googled it and got no where. I've tried various combinations of example code but nothing I've tried has worked. Like I say, I must be missing something obvious. Anybody give me an example?

Code: Select all
v4l2-ctl --set-ctrl=scene_mode=8

or programmatically something like
Code: Select all
struct v4l2_control ctrl;
ctrl.id = V4L2_CID_SCENE_MODE;
ctrl.value = V4L2_SCENE_MODE_NIGHT;
ret = ioctl(fd, VIDIOC_S_CTRL, &ctrl);

(not tested that code, but you can always use "v4l2-ctl --get-ctrl=scene_mode" to read back the value via the command line).
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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4182
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by gordon77 » Mon Jul 17, 2017 12:51 pm
6by6,

Is there a document anywhere detailing all the options?

Gordon77
Posts: 2901
Joined: Sun Aug 05, 2012 3:12 pm
by 6by9 » Mon Jul 17, 2017 1:03 pm
gordon77 wrote:Is there a document anywhere detailing all the options?

Er, the V4L2 API specification - https://linuxtv.org/downloads/v4l-dvb-a ... /v4l2.html Section 1.9 and 1.10 for the user controls, with 1.10.6 for the camera specific ones such as scene mode.

v4l2-ctl is the basic test tool for exercising the V4L2 API. "v4l2-ctl --list-ctrls-menus" is the option to list out all the controls that the driver supports, with the min, max, and current values.
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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4182
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by gordon77 » Mon Jul 17, 2017 1:08 pm
Er, thanks ;)
Posts: 2901
Joined: Sun Aug 05, 2012 3:12 pm
by zoukimando » Tue Jul 18, 2017 2:47 pm
yup, I was being dumb. Serves me right for trying this after a set of night shifts ;-)
Many thanks for the prompt and helpful reply
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm
by zoukimando » Wed Jul 19, 2017 7:32 am
Okay so I have night mode working if I use the v4l-ctl to capture, but I can't seem to get it to work if I use motion. Is there a trick to geting it working with motion?
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm
by 6by9 » Wed Jul 19, 2017 9:43 am
zoukimando wrote:Okay so I have night mode working if I use the v4l-ctl to capture, but I can't seem to get it to work if I use motion. Is there a trick to geting it working with motion?

You should be able to use v4l2-ctl to change controls whilst another client app (ie motion) is running, you just can't ask for images from two clients simultaneously. The value should be retained as well, so you should only need to set the scene mode once per boot.

A quick check of the source for the standard motion package has no reference to scene modes, nor support for controls using anything other than integers or booleans. Scene mode uses a menu, so isn't supported.

Do note that frame rate will limit the exposure time that can be achieved, regardless of scene mode. Frame rate is not controllable based on the motion 3.2.12 source I've just looked at.
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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4182
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by zoukimando » Wed Jul 19, 2017 4:05 pm
Many thanks. Each time you run v4l2-ctl it disconnects Motion from the video stream, and I had Motion starting at boot. So when I made changes it appeared to do nothing. Once I restarted Motion after running the v4l2 commands it works fine. Many thanks
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm
by 6by9 » Thu Jul 20, 2017 8:54 am
zoukimando wrote:Many thanks. Each time you run v4l2-ctl it disconnects Motion from the video stream, and I had Motion starting at boot. So when I made changes it appeared to do nothing. Once I restarted Motion after running the v4l2 commands it works fine. Many thanks

Hmm, it shouldn't cause motion to disconnect.
I don't have motion set up so can't test with that, but having 2 command prompts open I've just run "v4l2-ctl --stream-mmap=3 --stream-count=10000 --stream-to=/dev/null" in one to grab lots of images. In the other terminal I've run commands such as "v4l2-ctl --set-ctrl=scene_mode=8", "v4l2-ctl -p 5" (request 5fps), "v4l2-ctl --set-ctrl=horizontal_flip=1", and they do the expected thing. Run "v4l2-ctl --overlay=1" first and you can see the effect of the commands live.
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.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4182
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by zoukimando » Thu Jul 20, 2017 9:14 am
I've tried multiple times. The live view from motion just freezes. It doesn't error it just stops updating. However I should say that the device I'm testing this on is a rather old pi, in a remote location, still running Wheezy. I'll try it on something a little more current today
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm
by zoukimando » Thu Jul 20, 2017 9:37 am
Just tried it on an upto date Zero W and it works just fine. It's about time I retired that old Pi I guess
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm