Important: Please read the Qt Code of Conduct -

QCamera (auto) exposure/focus settings

  • Hi!
    Some time ago I made a basic but functional implementation of a Stopmotion interface using the QCamera class. In fact, everything works pretty well, except for one thing: the auto exposure/focus settings are enabled all the time, generating a constant "blink" effect with a lot of horizontal lines moving around on my display.
    Here is a short example of my problem:

    So, my question is: how can I set the exposure/focus parameters of my webcam using Qt to avoid this behaviour? I noticed that there is a class called QCameraExposure and other called QCameraFocus, but the lack of documentation don't let me find the hint I need.

    Any suggestion?

  • Lifetime Qt Champion


    AFAIK, you can get these directly from the QCamera instance and then modify them to change the camera settings.

  • Lifetime Qt Champion

  • Just guessing, I tried this code:

        QCamera *camera = new QCamera();
        QCameraExposure *exposure = camera->exposure();
        QCameraFocus *focus = camera->focus();

    But the result is exactly the same, the webcam keeps trying to calculate exposure and focus values every second. I am using a webcam FaceCam 320X. Suggestions?

  • Lifetime Qt Champion

    Does this webcam support manual exposure and focus?

  • @jsulm It is a very basic webcam model, so I really doubt it. To me, this has been a slow learning process about dealing with cameras using Qt.

    Now, I wonder if the right path to solve my issue (if there is a solution for this) is to look for some "Webcam system settings" in the operating system context and try to deal with the auto-exposure/focus from there.

    Should I give up to manage webcams for doing stopmotion and focus on DSRL devices? Should I get used to the annoying blinking horizontal lines if I decide to work with webcams? ->

    I would like to understand the technical boundaries of working with webcams, how far can I take my expectations?

    Comments are very welcome! :)

  • Lifetime Qt Champion

    Something surprises me here, isn't that camera focus handling manual ?

    Do you have the same phenomenon if you use QML ?

  • @SGaist said:

    Something surprises me here, isn't that camera focus handling manual ?

    In fact, you are right. The focus doesn't change when the finger appears. But, what about the exposure? why the camera view is blinking all the time? I tried setting focus and exposure values as Auto and Manual with the same result.

    Do you have the same phenomenon if you use QML ?

    I was trying to learn QML but I must confess that I couldn't deal with it, different paradigm, just difficult to me. My apologies to QML developers.

  • Lifetime Qt Champion

    It is just for the sake of testing, not trying to convince you to change your code base.

    Just create a default QtQuick application and put

    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtMultimedia 5.0
    Window {
        visible: true
        Camera {
            id: camera
        VideoOutput {
            source: camera
            anchors.fill: parent
            focus : visible // to receive focus and capture key events when visible

    in the main.qml file.

    It will show you the first camera it finds.

  • This morning I was testing the QML code you shared with me and I compared it with my own implementation. Here is the result:

    What I wonder most is how the blink effect disappears when the natural light is strong. I mean, I used to run my tests at night and as you could see, the blinking effect was exaggerated, but in this latest test is almost imperceptible. I made a comparison with the FaceTime app and definitely there is a big difference when you work either with night or day light.

    About the QML vs QWidget implementation, I must say that in my opinion, the "quality" result is the same. My most important learning about this issue is that natural light matters when you are going to work with webcams, at least from Mac operating systems. I guess for some of you this could sound "really obvious", but please, count on I am a newbie in this topic ;)

    I ran some night tests from my laptop with Ubuntu using the same webcam and the same Qt code, and the auto exposure effect was not so intense as in my Mac.

    After all my tests, I consider that this issue is far beyond the software itself, environment light matters. Maybe with DSLR devices is a different story.

  • Lifetime Qt Champion

    Do you know whether that camera provides a RGB or YUV stream ?

  • @SGaist Not sure how to answer your question, but this is all the info I could get from the manufacturer:

  • Lifetime Qt Champion

    Do you mind building a custom QtMultimedia with two patches to test that ?

  • @SGaist Not at all. If you can give me the building instructions to follow I can do it :)

  • Lifetime Qt Champion

    You can clone QtMultimedia from here and checkout the branch matching your current Qt.

    git fetch refs/changes/04/156204/5 && git format-patch -1 --stdout FETCH_HEAD > yuv422.patch
    git fetch refs/changes/45/156845/2 && git format-patch -1 --stdout FETCH_HEAD > yuv422_avcamera.patch

    That will give you two patches that you can apply with:
    patch -p1 -i yuv422.patch and patch -p1 -i yuv422_avcamera.patch.

    If you have trouble compiling QtMultimedia from git, you can also grab the sources from the installer and just apply the two patches on them. It shouldn't be problematic.

  • @SGaist Hi, following your instructions I downloaded the git branch corresponding to my Qt version (5.6), applied the patches and finally, compiled the whole source code with no issues (qmake and then make).

    Now, what should I do with the content of this "qtmultimedia" folder?

    PS: I am running my tests on a Mac system.

  • Lifetime Qt Champion

    You need to call make install, that will replace your current QtMultimedia. Then you only have to re-build your application, it should use the new available format if possible (just double check that's indeed the case)

  • @SGaist Just one question before continuing: Should I make a backup copy of some directory of my current Qt (official) installation? I don't want to break something :S

  • Lifetime Qt Champion

    It shouldn't break anything but you can copy your QtMultimedia.framework as well as the mediaservices plugin folder.

  • @SGaist Sorry for my delay. I was busy working on my latest release.

    Now that I had some time to run the test, I must say that I couldn't detect any difference in my camera behavior after installing the new version of the QtMultimedia module. The blinking effect remains.

    Initially, I was expecting to run my tests on my Mac system. Unfortunately, I couldn't work with the Qt 4.6 version due to some qmake bug I found when I was trying to compile my project, so I decided to try the whole thing from my Linux box.

    This is the output I got before compiling:

    # qmake
    Checking for openal... no
    Checking for alsa... yes
    Checking for pulseaudio... yes
    Checking for gstreamer... yes
    Checking for gstreamer_photography... no
    Checking for gstreamer_encodingprofiles... yes
    Checking for gstreamer_appsrc... yes
    Checking for linux_v4l... yes
    Checking for resourcepolicy... no
    Checking for gpu_vivante... no

    Not sure if this test doesn't have any sense in Linux. Please, let me know if there are another tests related to the webcam management I could run.

  • Lifetime Qt Champion

    From a quick look at the gstreamer plugin sources, I can't tell if you'll be using that format. You have to check that.

    At least since GStreamer 1.0 the format is available (see the qgstutils.cpp file)

Log in to reply