Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get camera supported resolutions using Qt5?
Forum Updated to NodeBB v4.3 + New Features

How to get camera supported resolutions using Qt5?

Scheduled Pinned Locked Moved General and Desktop
23 Posts 5 Posters 17.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andreyc
    wrote on last edited by
    #7

    I looked into Qt multimedia sources and I've found that supportedResolutions() call depends on a multimedia backend plugin of OS.

    The code bellow (you can put it to the end of your main.cpp from sample.zip) shows how the call imageCapture->supportedResolutions(); is executed. It is not full trace of course, only part that is relevant to supportedResolutions.

    @
    QMediaObject* mediaObject = imageCapture->mediaObject();
    qDebug() << "mediaObject" << mediaObject;
    if (mediaObject) {
    QMediaService* service = mediaObject->service();
    qDebug() << "media service" << service;
    if (service) {
    QImageEncoderControl* encoderControl = qobject_cast<QImageEncoderControl*>(service->requestControl(QImageEncoderControl_iid));
    qDebug() << "encoderControl" << encoderControl;
    if (encoderControl) {
    QImageEncoderSettings settings;
    bool continuous = false;
    qDebug() << "settings null" << settings.isNull();
    QList<QSize> resolutions = encoderControl->supportedResolutions(settings, &continuous);
    qDebug() << "Camera resolution list size: " << resolutions.size();
    qDebug() << "settings null" << settings.isNull();
    qDebug() << "continuous" << continuous;
    }
    }
    }
    @

    For MacOS X 10.9 it shows QImageEncoderControl is null, which means that it is not implemented.
    For GNU/Linux (Ubuntu 14.04) it shows QImageEncoderControl but the list of the resolutions is still empty.

    The systems that have plugins and may support QImageEncoderControl::supportedResolutions are android, qnx (BlackBerry uses it too), directshow (Windows), gstreamer (GNU/Linux)

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xtingray
      wrote on last edited by
      #8

      Just for your information... the output of my test from Windows 7 using your code. Same result, no resolutions:

      Starting C:\tupi\build-sample-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\camera.exe...
      Camera description: "Webcam C170"
      Camera status: QCamera::UnavailableStatus
      Camera resolution list size: 0
      mediaObject QCamera(0x59e820)
      media service DSCameraService(0x59a970)
      encoderControl QObject(0x0)
      C:\tupi\build-sample-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\camera.exe exited with code 0


      Qt Developer

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xtingray
        wrote on last edited by
        #9

        Today I was running some tests from my Linux system (Ubuntu 14.04 x64). This is my report:

        1. List of gstreamer dependencies installed:
          http://www.maefloresta.com/tmp/gstreamer-dependencies.txt

        2. Using Qt 4.8 and the package qtmobility-dev the piece of code of my first post works perfectly.
          @
          QList<QSize> resolutions = imageCapture->supportedResolutions();
          @
          I got the list of resolutions for three different cameras I'm using with accurate values.

        Note: The dependencies required by the package "qtmobility-dev" are:
        libqtconnectivity1 libqtcontacts1 libqtfeedback1 libqtgallery1 libqtlocation1 libqtmultimediakit1 libqtorganizer1 libqtpublishsubscribe1 libqtsensors1 libqtserviceframework1 libqtsysteminfo1 libqtversit1 libqtversitorganizer1 servicefw

        1. Using either Qt 5.2.1 or Qt 5.3.0 and removing the package qtmobility-dev the function QCameraImageCapture::supportedResolutions() doesn't work any more.
          Note: I tried two options: the Qt Ubuntu packages and the Qt online installer.

        2. I was checking the source code of the package qtmobility-dev running: apt-get source qtmobility-dev and comparing the structure and classes against the Qt 5.2.1/5.3.0 and I got the same code:
          @
          QList<QSize> QCameraImageCapture::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const
          {
          if (continuous)
          *continuous = false;

          return d_func()->encoderControl ?
          d_func()->encoderControl->supportedResolutions(settings, continuous) : QList<QSize>();
          }
          @

        All the Qt versions I checked have the module "plugins/multimedia/gstreamer" included, so the problem shouldn't be there.

        I tried the same test from MS Windows installing all the directshow compounds and the result is the same: an empty list.

        So, what happened between Qt 4.8.x and Qt 5.2.x with this feature? Is this feature already working for someone using Qt 5.x?


        Qt Developer

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xtingray
          wrote on last edited by
          #10

          Today I had the chance to test my sample from OSX and I got the same result, the method QCameraImageCapture::supportedResolutions() doesn't work here neither:

          $ uname -a
          Darwin MacBook-Pro.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64

          $ qmake -version
          QMake version 3.0
          Using Qt version 5.3.0 in /Users/test/Qt5.3.0/5.3/clang_64/lib

          $ ./camera.app/Contents/MacOS/camera
          Camera description: "Cámara FaceTime HD (integrada)"
          Camera status: QCamera::LoadedStatus
          Camera resolution list size: 0


          Qt Developer

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xtingray
            wrote on last edited by
            #11

            Testing the same example but this time using Qt 5.3.1 from Linux, same result:

            $ ./camera
            Camera description: "USB2.0 UVC WebCam"
            Camera status: QCamera::LoadedStatus
            CameraBinImageEncoder::supportedResolutions()
            Camera resolution list size: 0

            The method supportedResolutions() always returns an empty list :(


            Qt Developer

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tr3w
              wrote on last edited by
              #12

              Surprisingly I couldn't find a bug report about this (for linux)...
              Now here it is:
              https://bugreports.qt-project.org/browse/QTBUG-40545

              Follow, upvote, comment. Make some noise!

              (There is a bug report for windows, but there it is just not supported...
              https://bugreports.qt-project.org/browse/QTBUG-32743 )

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xtingray
                wrote on last edited by
                #13

                Thanks for the hint... I already voted for it! :)


                Qt Developer

                1 Reply Last reply
                0
                • yeckelY Offline
                  yeckelY Offline
                  yeckel
                  wrote on last edited by
                  #14

                  It looks like that gstreamer on Linux is not returing any value in: camerabinsession.cpp

                  @ GstCaps *supportedCaps = 0;
                  g_object_get(G_OBJECT(m_camerabin),
                  (mode == QCamera::CaptureStillImage) ?
                  SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY : SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY,
                  &supportedCaps, NULL);
                  if (!supportedCaps)
                  return res;@

                  I was trying calling gstreamer out of QT and was getting NULL as well. Is it a bug in GStreamer?

                  1 Reply Last reply
                  0
                  • yeckelY Offline
                    yeckelY Offline
                    yeckel
                    wrote on last edited by
                    #15

                    It looks like that gstreamer on Linux is not returing any value in: camerabinsession.cpp

                    @ GstCaps *supportedCaps = 0;
                    g_object_get(G_OBJECT(m_camerabin),
                    (mode == QCamera::CaptureStillImage) ?
                    SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY : SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY,
                    &supportedCaps, NULL);
                    if (!supportedCaps)
                    return res;@

                    I was trying calling gstreamer out of QT and was getting NULL as well. Is it a bug in GStreamer?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      Hi,

                      Either that or the device doesn't return the information. Do you have any other way to retrieve that information on your system ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        Hi,

                        Either that or the device doesn't return the information. Do you have any other way to retrieve that information on your system ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • yeckelY Offline
                          yeckelY Offline
                          yeckel
                          wrote on last edited by
                          #18

                          Well, v4l2 is returning:

                          @$ v4l2-ctl --list-formats-ext
                          ioctl: VIDIOC_ENUM_FMT
                          Index : 0
                          Type : Video Capture
                          Pixel Format: 'YUYV'
                          Name : YUV 4:2:2 (YUYV)
                          Size: Discrete 640x480
                          Interval: Discrete 0.033s (30.000 fps)
                          Interval: Discrete 0.067s (15.000 fps)
                          Size: Discrete 640x360
                          Interval: Discrete 0.033s (30.000 fps)
                          Interval: Discrete 0.067s (15.000 fps)
                          ...@

                          The structure GstCaps *supportedCaps from previous code, has 0 length, but it's valid but @gst_caps_is_any(supportedCaps) == true@

                          1 Reply Last reply
                          0
                          • yeckelY Offline
                            yeckelY Offline
                            yeckel
                            wrote on last edited by
                            #19

                            Well, v4l2 is returning:

                            @$ v4l2-ctl --list-formats-ext
                            ioctl: VIDIOC_ENUM_FMT
                            Index : 0
                            Type : Video Capture
                            Pixel Format: 'YUYV'
                            Name : YUV 4:2:2 (YUYV)
                            Size: Discrete 640x480
                            Interval: Discrete 0.033s (30.000 fps)
                            Interval: Discrete 0.067s (15.000 fps)
                            Size: Discrete 640x360
                            Interval: Discrete 0.033s (30.000 fps)
                            Interval: Discrete 0.067s (15.000 fps)
                            ...@

                            The structure GstCaps *supportedCaps from previous code, has 0 length, but it's valid but @gst_caps_is_any(supportedCaps) == true@

                            1 Reply Last reply
                            0
                            • yeckelY Offline
                              yeckelY Offline
                              yeckel
                              wrote on last edited by
                              #20

                              I've digged deeper into GStreamer plugin gstcamerabin2.c, here it's querying for pad capabilities @pad = gst_element_get_static_pad (element, padname);

                              caps = gst_pad_query_caps (pad, NULL);@ and then the query failing "GstPAd.html":http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html

                              ...gst_pad_query_caps returns all possible caps a pad can operate with, using the pad's CAPS query function, If the query fails, this function will return filter , if not NULL, otherwise ANY.

                              And this ANY is what's returned into QT and then returned as empty QList. I thing we should use another gstreamer input element aka v4l2src which is stable. Camerabin2 is marked as unstable and under development.

                              1 Reply Last reply
                              0
                              • yeckelY Offline
                                yeckelY Offline
                                yeckel
                                wrote on last edited by
                                #21

                                I've digged deeper into GStreamer plugin gstcamerabin2.c, here it's querying for pad capabilities @pad = gst_element_get_static_pad (element, padname);

                                caps = gst_pad_query_caps (pad, NULL);@ and then the query failing "GstPAd.html":http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html

                                ...gst_pad_query_caps returns all possible caps a pad can operate with, using the pad's CAPS query function, If the query fails, this function will return filter , if not NULL, otherwise ANY.

                                And this ANY is what's returned into QT and then returned as empty QList. I thing we should use another gstreamer input element aka v4l2src which is stable. Camerabin2 is marked as unstable and under development.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #22

                                  Thanks for sharing your findings !

                                  Do you have that with gstreamer0.1 ? Did you check gstreamer 1 ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #23

                                    Thanks for sharing your findings !

                                    Do you have that with gstreamer0.1 ? Did you check gstreamer 1 ?

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved