V4L2 absolute exposure setting has (almost) not effect
Asked Answered
S

1

9

I am trying to manually control the exposure of my camera, but the setting is only briefly active, but then apparently still an auto mode seems to be active, as I can see on the camera images.

My camera has the following controls:

v4l2-ctl --list-ctrls-menus
                     brightness 0x00980900 (int)    : min=-127 max=128 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=30 step=1 default=15 value=15
                     saturation 0x00980902 (int)    : min=0 max=127 step=1 default=54 value=54
                            hue 0x00980903 (int)    : min=-180 max=180 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=20 max=250 step=1 default=88 value=88
                           gain 0x00980913 (int)    : min=0 max=10 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1
                0: Disabled
                1: 50 Hz
                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2500 max=7000 step=1 default=6000 value=6000 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=60 step=1 default=10 value=10
         backlight_compensation 0x0098091c (int)    : min=0 max=2 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=1
                1: Manual Mode
                3: Aperture Priority Mode
              exposure_absolute 0x009a0902 (int)    : min=78 max=1250 step=1 default=312 value=1250
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=0

I set and verify, while watching the image through a basic opencv viewer, which doesn't do any controlling:

# Verify initial setting
$ v4l2-ctl -C exposure_auto
exposure_auto: 3

# Set auto-exposure to "Manual exposure time, manual iris."
$ v4l2-ctl -c exposure_auto=1

# Verify that manual setting is active
$ v4l2-ctl -C exposure_auto
exposure_auto: 1

# Set an absolute exposure value
$ v4l2-ctl -c exposure_absolute=1000

# Verify set absolute exposure
$ v4l2-ctl -C exposure_absolute
exposure_absolute: 1000

I also play with the exposure_auto_priority setting.

However, when I change the exposure, I can see the effect very quickly on the images from the camera, which then immediately seems to go back to the "auto" mode. I.e. the camera is adjusting it's brightness automatically.

The same effect I'm observing when I use guvcview, which basically gives me a slider for each of the above controls. When I change the exposure, it briefly applies, but then seems to apply auto-exposure. Although the setting itself can be confirmed to be as set (using v4l2-ctl -C ...).

Disabling white_balance_temperature_auto works, and I also tried to fiddle with any other value, but I couldn't find any dependency to the exposure.

What could it be that is overruling the manual exposure settings?

Update

Some system information:

Kernel:

$ uname -r
5.3.0-51-generic
cat /proc/version
Linux version 5.3.0-51-generic (buildd@lgw01-amd64-034) (gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)) #44-Ubuntu SMP Wed Apr 22 21:09:44 UTC 2020

Media:

$ media-ctl -p
Failed to enumerate /dev/media0 (-13)

$ ls /dev/media* 
/dev/media0  /dev/media1  /dev/media2

V4L2:

$ v4l2-ctl --all
Driver Info:
    Driver name      : uvcvideo
    Card type        : HBV HD CAMERA: HBV HD CAMERA
    Bus info         : usb-0000:05:00.3-1.1
    Driver version   : 5.3.18
    Capabilities     : 0x84a00001
        Video Capture
        Metadata Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps      : 0x04200001
        Video Capture
        Streaming
        Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height      : 1920/1080
    Pixel Format      : 'MJPG' (Motion-JPEG)
    Field             : None
    Bytes per Line    : 0
    Size Image        : 4147200
    Colorspace        : sRGB
    Transfer Function : Default (maps to sRGB)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Full Range)
    Flags             : 
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 1920, Height 1080
    Default     : Left 0, Top 0, Width 1920, Height 1080
    Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Selection: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Streaming Parameters Video Capture:
    Capabilities     : timeperframe
    Frames per second: 30.000 (30/1)
    Read buffers     : 0
                     brightness 0x00980900 (int)    : min=-127 max=128 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=30 step=1 default=15 value=15
                     saturation 0x00980902 (int)    : min=0 max=127 step=1 default=54 value=54
                            hue 0x00980903 (int)    : min=-180 max=180 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=20 max=250 step=1 default=88 value=88
                           gain 0x00980913 (int)    : min=0 max=10 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1
      white_balance_temperature 0x0098091a (int)    : min=2500 max=7000 step=1 default=6000 value=6000 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=60 step=1 default=10 value=10
         backlight_compensation 0x0098091c (int)    : min=0 max=2 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
              exposure_absolute 0x009a0902 (int)    : min=78 max=1250 step=1 default=312 value=312 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=1
Solley answered 3/5, 2020 at 20:24 Comment(2)
can you give the kernel version and the output of v4l2-ctl --all and media-ctl -p?Hoggard
Thanks @dafnahaktana, totally forgot about some system info - I added the info to the updated description.Solley
A
9

Take a look at Exposure Time (Absolute) Control in the UVC class specification, which you can find from usb.org. I'm quoting from spec version 1.5 below.

Note that the manual exposure control is further limited by the frame interval, which always has higher precedence. If the frame interval is changed to a value below the current value of the Exposure Control, the Exposure Control value will automatically be changed. The default Exposure Control value will be the current frame interval until an explicit exposure value is chosen.

So, this explains what you are seeing. Absolute Exposure Time is expressed in 100µs units. Your default value is 312, which is 31200µs, and this gives a frame rate of ~32.

exposure_absolute 0x009a0902 (int)    : min=78 max=1250 step=1 default=312 value=312 flags=inactive

Frames per second: 30.000 (30/1)

You are setting the Absolute exposure time to 1000, which is 100000µs. This takes effect, but then the frame interval (31200µs) takes precedence and it falls back to 31200µs.

Articular answered 5/5, 2020 at 16:6 Comment(9)
That's very useful information, thanks a lot for the hints. Unfortunately, it isn't that. Also when I set absolute exposure to lower values, the camera shortly applies them, but then changes back to an auto setting. That means, the image shortly gets brighter or darker, but then goes back. I just tried my settings with another camera I have, and everything is working fine there. So perhaps just a buggy implementation on the device side? Are there any more chances to debug this?Solley
@Solley Examining usb traces might help. Maybe you can take traces from both cams and compare. Sometimes, the camera firmware may not fully adhere to the spec, and as you said, could be buggy.Articular
@Articular does this mean that manual exposure never persists forever? only for a given time? I have a similar issue, but I want the manual exposure setting to remainVinna
@Vinna I'm a bit rusty on this topic right now, but, by forever, if you mean even after a power reset, then you will have to check with the camera vendor to see if they provide such feature to save a certain configuration as the default via an extension unit.Articular
@Articular no sorry I mean once it has been set and while remains powered. I understood your explanation above that the desired exposure level only persisted for X number of frames? Then essentially returned to auto?Vinna
@Vinna No. It's not that it persists for some number of frames. It persists as long as it satisfies the requirement in quotes.Articular
@Articular what are the requirements and what causes it to kick back to auto?Vinna
by @dhanushka's explanation, you basically can't set the exposure to something higher than the duration of a frame.Solley
@Articular I have asked my own question here #65595880Vinna

© 2022 - 2024 — McMap. All rights reserved.