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 QML
Forum Updated to NodeBB v4.3 + New Features

Multiple cameras QML

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

    Hello everyone,

    I have a problem with setting up 2 camera windows in QML.

    The error I get is: [0x800705aa] Failed to start (Insufficient system resources exist to complete the requested service.)
    When I start the program only the last camera window is showing the camera capture. If I start 2 instances of the application then each of the application shows one camera but the image on one is frozen and on the other one it is working OK.
    alt text

    If I start the application once with only camera 1 and second time only with camera 2 then both cameras are working simultaneously:
    alt text

    The code for camera:

    Item{
            id:cameraWindow1
            anchors.left: parent.left
            anchors.right: swipeView.left
            height: parent.height
            signal closed
    
            Rectangle{
                anchors.fill: parent
                color: "red"
            }
    
            Camera{
                id:camera1
            }
        }
    
        VideoOutput{
            id:vo1
            z:99
            source: camera1
            anchors.fill: cameraWindow1
            //focus: visible
            //orientation: 270
        }
    
    Item{
            id:cameraWindow2
            anchors.left: swipeView.right
            anchors.right: parent.right
            height: parent.height
            signal closed
    
            Rectangle{
                anchors.fill: parent
                color: "blue"
            }
    
            Camera{
                id:camera2
            }
        }
    
        VideoOutput{
            id:vo2
            z:99
            source: camera2
            anchors.fill: cameraWindow2
            //focus: visible
            //orientation: 270
        }
    

    Code to specify the camera source:

    Component.onCompleted: {
            var myL = QtMultimedia.availableCameras;
            console.log("Loaded", myL.length);
            camera1.deviceId = myL[0].deviceId;
            camera2.deviceId = myL[1].deviceId;
        }
    

    The console returns "qml: Loaded 2" for myL.length

    Does anyone have more experience with creating new instances of the same object in QML? Especially cameras.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NiLe
      wrote on last edited by NiLe
      #6

      Hello community,

      After a few days, I think I solved the problem with the cameras.
      I made myself a QML file named "CamCam.qml" with the following code:

      import QtQuick 2.14
      import QtMultimedia 5.12
      
      Item{
          id:cameraWindow
          anchors.fill: parent
          signal closed
          property alias theID: camera.deviceId
          property alias backgroundColor: background.color
          property alias orientation: vo.orientation
      
          Rectangle{
              id: background
              anchors.fill: parent
              color: "blue"
          }
      
          Camera{
              id:camera
          }
      
          VideoOutput{
              id: vo
              z:99
              source: camera
              anchors.fill: parent
          }
      
      }
      

      And then I use it in the "main.qml":

      Item{
              id: cameraLeft
              anchors.left: parent.left
              anchors.top: parent.top
              anchors.right: swipeView.left
              anchors.bottom: parent.bottom
              
              CamCam{
                  theID: QtMultimedia.availableCameras[0].deviceId
                  backgroundColor: "red"
              }
          }
          
      Item{
              id: cameraRight
              anchors.right: parent.right
              anchors.top: parent.top
              anchors.left: swipeView.right
              anchors.bottom: parent.bottom
              
              CamCam{
                  theID: QtMultimedia.availableCameras[1].deviceId
                  backgroundColor: "blue"
              }
          }
      

      It is important to set the deviceId as soon as possible. As I did here "theID: QtMultimedia.availableCameras[x].deviceId"

      Now it works perfectly:
      alt text

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

        Hi and welcome to devnet,

        Since you have a resource error, please give more details about the machine/device you are using for development.

        You should as well add the Qt version you are using as well as platform your are working and targeting.

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

          Thank you for the warm welcome,

          Oh yes, sorry about that.
          The computer is this:
          alt text

          Qt:
          Qt Creator 4.11.1
          Based on Qt 5.14.1 (MSVC 2017, 32 bit)
          Built on Feb 5 2020 10:36:21
          From revision b2ddeacfb5

          My target is windows application:
          alt text

          Thank you!

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

            What are these two cameras ?

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

              They are USB cameras, not web cameras.
              5a9e5980-6569-41b6-ba47-bfa6d6871839-image.png

              https://i.imgur.com/x71om5B.jpg

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NiLe
                wrote on last edited by NiLe
                #6

                Hello community,

                After a few days, I think I solved the problem with the cameras.
                I made myself a QML file named "CamCam.qml" with the following code:

                import QtQuick 2.14
                import QtMultimedia 5.12
                
                Item{
                    id:cameraWindow
                    anchors.fill: parent
                    signal closed
                    property alias theID: camera.deviceId
                    property alias backgroundColor: background.color
                    property alias orientation: vo.orientation
                
                    Rectangle{
                        id: background
                        anchors.fill: parent
                        color: "blue"
                    }
                
                    Camera{
                        id:camera
                    }
                
                    VideoOutput{
                        id: vo
                        z:99
                        source: camera
                        anchors.fill: parent
                    }
                
                }
                

                And then I use it in the "main.qml":

                Item{
                        id: cameraLeft
                        anchors.left: parent.left
                        anchors.top: parent.top
                        anchors.right: swipeView.left
                        anchors.bottom: parent.bottom
                        
                        CamCam{
                            theID: QtMultimedia.availableCameras[0].deviceId
                            backgroundColor: "red"
                        }
                    }
                    
                Item{
                        id: cameraRight
                        anchors.right: parent.right
                        anchors.top: parent.top
                        anchors.left: swipeView.right
                        anchors.bottom: parent.bottom
                        
                        CamCam{
                            theID: QtMultimedia.availableCameras[1].deviceId
                            backgroundColor: "blue"
                        }
                    }
                

                It is important to set the deviceId as soon as possible. As I did here "theID: QtMultimedia.availableCameras[x].deviceId"

                Now it works perfectly:
                alt text

                1 Reply Last reply
                2
                • L Offline
                  L Offline
                  lxy12345
                  wrote on last edited by
                  #7

                  Hi NiLe, I am very new to qml ,could you please post your code?

                  jsulmJ 1 Reply Last reply
                  0
                  • L lxy12345

                    Hi NiLe, I am very new to qml ,could you please post your code?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @lxy12345 Isn't the code just above in the last post from @NiLe ?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    L 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @lxy12345 Isn't the code just above in the last post from @NiLe ?

                      L Offline
                      L Offline
                      lxy12345
                      wrote on last edited by
                      #9

                      @jsulm When I tried the code, the error occured.
                      Here is my code:
                      main.qml
                      import QtQuick 2.12
                      import QtMultimedia 5.12
                      import QtQuick.Window 2.12

                      Window {
                      visible: true
                      width: 1200
                      height: 500
                      title: qsTr("Hello World")
                      Item{
                      id: cameraLeft
                      anchors.left: parent.left
                      anchors.top: parent.top
                      anchors.right: swipeView.left
                      anchors.bottom: parent.bottom

                              CamCam{
                                  theID: QtMultimedia.availableCameras[0].deviceId
                                  backgroundColor: "red"
                              }
                          }
                      
                      Item{
                              id: cameraRight
                              anchors.right: parent.right
                              anchors.top: parent.top
                              anchors.left: swipeView.right
                              anchors.bottom: parent.bottom
                      
                              CamCam{
                                  theID: QtMultimedia.availableCameras[1].deviceId
                                  backgroundColor: "blue"
                              }
                          }
                      

                      }

                      CamCam.qml:
                      import QtQuick 2.12
                      import QtMultimedia 5.12

                      Item{
                      id:cameraWindow
                      anchors.fill: parent
                      signal closed
                      property alias theID: camera.deviceId
                      property alias backgroundColor: background.color
                      property alias orientation: vo.orientation

                      Rectangle{
                          id: background
                          anchors.fill: parent
                          color: "blue"
                      }
                      
                      Camera{
                          id:camera
                      }
                      
                      VideoOutput{
                          id: vo
                          z:99
                          source: camera
                          anchors.fill: parent
                      }
                      

                      }

                      The errors:
                      qrc:/main.qml:15: ReferenceError: swipeView is not defined
                      qrc:/main.qml:32: TypeError: Cannot read property 'deviceId' of undefined
                      qrc:/main.qml:28: ReferenceError: swipeView is not defined
                      libv4l2: error setting pixformat: Device or resource busy
                      CameraBin error: "Device '/dev/video0' is busy"

                      The environment is ubuntu16.04(virtual machine), qt5.12.9. The camera is USB camera

                      jsulmJ 1 Reply Last reply
                      0
                      • L lxy12345

                        @jsulm When I tried the code, the error occured.
                        Here is my code:
                        main.qml
                        import QtQuick 2.12
                        import QtMultimedia 5.12
                        import QtQuick.Window 2.12

                        Window {
                        visible: true
                        width: 1200
                        height: 500
                        title: qsTr("Hello World")
                        Item{
                        id: cameraLeft
                        anchors.left: parent.left
                        anchors.top: parent.top
                        anchors.right: swipeView.left
                        anchors.bottom: parent.bottom

                                CamCam{
                                    theID: QtMultimedia.availableCameras[0].deviceId
                                    backgroundColor: "red"
                                }
                            }
                        
                        Item{
                                id: cameraRight
                                anchors.right: parent.right
                                anchors.top: parent.top
                                anchors.left: swipeView.right
                                anchors.bottom: parent.bottom
                        
                                CamCam{
                                    theID: QtMultimedia.availableCameras[1].deviceId
                                    backgroundColor: "blue"
                                }
                            }
                        

                        }

                        CamCam.qml:
                        import QtQuick 2.12
                        import QtMultimedia 5.12

                        Item{
                        id:cameraWindow
                        anchors.fill: parent
                        signal closed
                        property alias theID: camera.deviceId
                        property alias backgroundColor: background.color
                        property alias orientation: vo.orientation

                        Rectangle{
                            id: background
                            anchors.fill: parent
                            color: "blue"
                        }
                        
                        Camera{
                            id:camera
                        }
                        
                        VideoOutput{
                            id: vo
                            z:99
                            source: camera
                            anchors.fill: parent
                        }
                        

                        }

                        The errors:
                        qrc:/main.qml:15: ReferenceError: swipeView is not defined
                        qrc:/main.qml:32: TypeError: Cannot read property 'deviceId' of undefined
                        qrc:/main.qml:28: ReferenceError: swipeView is not defined
                        libv4l2: error setting pixformat: Device or resource busy
                        CameraBin error: "Device '/dev/video0' is busy"

                        The environment is ubuntu16.04(virtual machine), qt5.12.9. The camera is USB camera

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @lxy12345 said in Multiple cameras QML:

                        anchors.right: swipeView.left

                        Since you don't have swipeView replace it with parent.

                        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