Unable to control camera aperture on Raspberry Pi
-
Hi everyone,
I have exactly the same problem described in https://forum.qt.io/topic/75441/qcameraexposure-not-possible-to-get-or-set-attributes-camera-example. Supported apertures, ISO sensitivities or shutter speeds lists are empty, neither auto nor manual exposure mode is supported, and current aperture, ISO and shutter speed is returned as -1.
Qt Camera example also is unable to control the exposure.
My system is Raspberry Pi 4 running Raspbian based on Debian 12.9, according to
lsusb
my camera isBus 001 Device 006: ID 0c45:6366 Microdia Webcam Vitade AF
. The Qt version is 5.15.8.v4l2-ctl --list-devices
shows this camera asArducam USB Camera: Arducam USB (usb-0000:01:00.0-1.1): /dev/video0 /dev/video1 /dev/video2 /dev/video3 /dev/media4
v4l2-ctl --list-ctrls
givesUser Controls brightness 0x00980900 (int) : min=-64 max=64 step=1 default=0 value=0 contrast 0x00980901 (int) : min=0 max=64 step=1 default=32 value=32 saturation 0x00980902 (int) : min=0 max=128 step=1 default=64 value=64 hue 0x00980903 (int) : min=-40 max=40 step=1 default=0 value=0 white_balance_automatic 0x0098090c (bool) : default=1 value=1 gamma 0x00980910 (int) : min=72 max=500 step=1 default=100 value=100 gain 0x00980913 (int) : min=0 max=100 step=1 default=0 value=0 power_line_frequency 0x00980918 (menu) : min=0 max=2 default=1 value=1 (50 Hz) white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive sharpness 0x0098091b (int) : min=0 max=6 step=1 default=2 value=2 backlight_compensation 0x0098091c (int) : min=0 max=2 step=1 default=1 value=1 Camera Controls auto_exposure 0x009a0901 (menu) : min=0 max=3 default=3 value=3 (Aperture Priority Mode) exposure_time_absolute 0x009a0902 (int) : min=1 max=5000 step=1 default=156 value=5000 flags=inactive exposure_dynamic_framerate 0x009a0903 (bool) : default=0 value=1
I can get images from the cam just fine, and I can control the exposure time from the command line with something like
v4l2-ctl -d /dev/video0 --set-ctrl=exposure_time_absolute=2000
. This command will affect the image I get in my app, making it lighter or darker. I can also save an image to the SD card withv4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=MJPG --stream-mmap --stream-to=frame.jpg --stream-count=1
.The command
gst-launch-1.0 v4l2src extra-controls="c,auto_exposure=1,exposure_time_absolute=5000" ! jpegdec ! xvimagesink
also works and opens a window with video feed from the camera with the requested exposure time.But nothing in QCameraExposure class works. Here's the relevant part of my code:
const QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); for(const auto& camera : cameras) { qDebug() << "Camera:" << camera.deviceName(); } // Use the first available camera camera = std::make_unique<QCamera>(cameras.first(), this); // Print everything QCameraExposure supports camera->load(); QCameraExposure* exposure = camera->exposure(); qDebug() << "Is available:" << camera->isAvailable(); qDebug() << "Is auto exposure supported:" << exposure->isExposureModeSupported(QCameraExposure::ExposureAuto); qDebug() << "Is manual exposure supported:" << exposure->isExposureModeSupported(QCameraExposure::ExposureManual); qDebug() << "Exposure compensation:" << exposure->exposureCompensation(); qDebug() << "Exposure mode:" << exposure->exposureMode(); qDebug() << "Supported aperture list:" << exposure->supportedApertures(); qDebug() << "Supported ISO list:" << exposure->supportedIsoSensitivities(); qDebug() << "Supported shutter speed list:" << exposure->supportedShutterSpeeds(); qDebug() << "Current aperture:" << exposure->aperture(); qDebug() << "Current ISO:" << exposure->isoSensitivity(); qDebug() << "Current shutter speed:" << exposure->shutterSpeed();
And here's the output:
Camera: "/dev/video0" Camera: "/dev/video2" Is available: true Is auto exposure supported: false Is manual exposure supported: false Exposure compensation: 0 Exposure mode: QCameraExposure::ExposureAuto Supported aperture list: () Supported ISO list: () Supported shutter speed list: () Current aperture: -1 Current ISO: -1 Current shutter speed: -1
I have a hunch that the camera works through libQt5MultimediaGstTools plugin and maybe it doesn't implement the exposure control for V4L2 devices, at least in Qt 5.
I tried to run my application with
Q_DEBUG_PLUGINS=1 ./myapp
, as suggested in the topic I referred to, but got no additional output. -
According to https://github.com/torvalds/linux/blob/master/include/uapi/linux/v4l2-controls.h, Qt Multimedia sources and my v4l2 output, Qt tries to control V4L2_CID_AUTO_EXPOSURE_BIAS parameter, and my camera supports V4L2_CID_EXPOSURE_ABSOLUTE, which is a different parameter.
But that's just my guess. -
Hi,
In that case, one possibility would be to rebuild the backed modified to suite your need (just the backend)
-
@SGaist could you please explain the Qt Multimedia architecture in greater detail? Or point me to its description. Quick search through Qt classes didn't yield useful results for me.
I understand there are different backends (plugins?) that are loaded on different systems to implement the platform-specific features, but where is the code which decides the backend to load? I would like to know which backend should I modify. -
Since you are using Q5, it's the GStreemer plugin that you should check.