Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Multiple cameras [solved]
QtWS25 Last Chance

Multiple cameras [solved]

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 4 Posters 7.9k Views
  • 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.
  • D Offline
    D Offline
    dvb0222
    wrote on last edited by
    #1

    I am new at the QtMultimedia 5.x QML interface, but I tried this super simple QCamera demo below and it worked perfectly. It sees the camera and displays the viewfinder for me. This is the basis for an app I am developing.

    However my system has two cameras. I am wondering if there is an API for selecting which physical camera to use. I see the availableDevices() method on the C++ object but I have to admin I am not connecting this to any selection mechanism.

    I don't need a chooser, I can hard code an index into a list of available cameras for a demo....

    Thanks in advance!!
    @
    import QtQuick 2.0
    import QtMultimedia 5.0

    Item {
    width: 640
    height: 360

    Camera {
        id: camera
    
        imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
    
        exposure {
            exposureCompensation: -1.0
            exposureMode: Camera.ExposurePortrait
        }
    
        flash.mode: Camera.FlashRedEyeReduction
    
        imageCapture {
            onImageCaptured: {
                photoPreview.source = preview  // Show the preview in an Image
            }
        }
    }
    
    VideoOutput {
        source: camera
        anchors.fill: parent
        focus : visible // to receive focus and capture key events when visible
    }
    
    Image {
        id: photoPreview
    }
    

    }
    @


    David Van Beveren
    Oak Park Technology Corp.
    Malibu, California
    vbdavid@gmail.com

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

      Hi,

      availableDevices returns all the camera it can find so you can make a simple loop to create a camera + view finder for each entries returned.

      Something like this:
      @foreach (const QByteArray &device, QCamera::availableDevices()) {
      QCamera *camera = new QCamera(device, this);
      QCameraViewfinder *viewFinder = new QCameraViewfinder;
      camera->setViewfinder(viewFinder);
      // rest of logic to setup widgets or anything else
      }
      @

      You can retrieve the camera name with QCamera::deviceDescription with these two function you can build your selection mechanism.

      Hope it helps

      PS: please enclose your code with coding tags to make it readable

      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
      • D Offline
        D Offline
        dvb0222
        wrote on last edited by
        #3

        Thanks, I understood how to do it on the C++ side.

        So when I find the camera I am interested in, all I do is export it:

        @QCamera *selectedCamera = new QCamera(selectedDevice, this);
        QQuickView view;
        view.rootContext()->setContextProperty("selectedCamera", selectedCamera);@

        and set the QML Camera's mediaObject property to that exported object?

        @Camera {
        id: myCamera
        mediaObject: selectedCamera
        }@

        Or do I share the &QByteArray returned from availableDevices() as a contextProperty? Either way, if it's that easy I'll be very happy.


        David Van Beveren
        Oak Park Technology Corp.
        Malibu, California
        vbdavid@gmail.com

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

          Sorry, QML is currently outside my competence... You'll have to test or maybe ask on the mailing list (there you'll find Qt developers/maintainers this forum is more user oriented)

          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
          • D Offline
            D Offline
            dvb0222
            wrote on last edited by
            #5

            Yes this works exactly as expected. put the C++ QCamera object into the root context by name, then you can use that name as the value in the mediaobject: field for the QML Camera and the correct camera will be used. If you do not do this and you have multiple cameras, then the camera at array index 0 of the availableDevices() returned list will be used by default.


            David Van Beveren
            Oak Park Technology Corp.
            Malibu, California
            vbdavid@gmail.com

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

              Great !

              I also saw something about it in the "Qt Contributor Summit page":http://qt-project.org/wiki/Qt_Multimedia about QtMultimedia.

              You might be interested

              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
              • D Offline
                D Offline
                danspelt
                wrote on last edited by
                #7

                I'm trying to set the "mediaObject" property of my camera object in qml i am running Windows 7 64bit Qt 5.2 and wondering if this is a Windows problem? Here's the error i get : Cannot assign to non-existent property "mediaObject"

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dvb0222
                  wrote on last edited by
                  #8

                  Hi,

                  It sounds like maybe something changed in 5.2 which I have not used yet. The code as posted worked in 5.1.1

                  David


                  David Van Beveren
                  Oak Park Technology Corp.
                  Malibu, California
                  vbdavid@gmail.com

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    conny
                    wrote on last edited by
                    #9

                    The relevant bug seems to be this: https://bugreports.qt-project.org/browse/QTBUG-23770

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      conny
                      wrote on last edited by
                      #10

                      Here is a solution that works for me: http://lists.qt-project.org/pipermail/interest/2014-January/010475.html

                      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