Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Split-view of cam feeds QML
Qt 6.11 is out! See what's new in the release blog

Split-view of cam feeds QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 3 Posters 1.6k 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.
  • A Offline
    A Offline
    Animesh452
    wrote on last edited by
    #1

    Re: Multiple cameras QML

    I want to see two camera feeds, or rather, multiple camera feeds, like a CCTV hub, on a single screen. I used the codes given in the Qt forum query titled: Multiple cameras QML. The code runs error-free but I'm not getting the feeds in split form instead they are getting overlapped. I am using Qt 5.15 on a Windows 10 64-bit machine and I have tried building using both minGW and MSVC2015 getting the same results.
    The two codes are below:
    CamCam.qml

    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
        }
    
    }
    

    main.qml

    import QtQuick 2.12
    import QtMultimedia 5.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.15
    
    Window {
    visible: true
    width: 1900
    height: 1080
    title: qsTr("CamHub")
    
    Item{
            id: cameraLeft
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.right: cameraRight.left
            anchors.bottom: parent.bottom
            clip: true
                    CamCam{
                        theID: QtMultimedia.availableCameras[0].deviceId
                        backgroundColor: "red"
                    }
            }
    
    Item{
            id: cameraRight
            anchors.right: parent.right
            anchors.top: parent.top
            anchors.left: cameraLeft.right
            anchors.bottom: parent.bottom
            CamCam{
                theID: QtMultimedia.availableCameras[1].deviceId
                backgroundColor: "blue"
    
            }
        }
    }
    
    

    How I knew they are overlapping?
    There are 2 images below. The first image is when I normally run it. The 2nd image is when I made a mistake in the 2nd half of the code (the one with blue background). Since the red background comes 1st in order hence it is always coming below the blue background. I might be wrong and hence any help would be great.
    182fef30-e2ad-4ceb-ba57-629c4f7b50c1-image.png
    f25faed6-7535-47f5-8815-7a45ec4492d8-image.png

    (I know there is no cam feed on the red background but trust me even when i connected the camera the same thing happens)

    Thank you!

    johngodJ 1 Reply Last reply
    0
    • A Animesh452

      Re: Multiple cameras QML

      I want to see two camera feeds, or rather, multiple camera feeds, like a CCTV hub, on a single screen. I used the codes given in the Qt forum query titled: Multiple cameras QML. The code runs error-free but I'm not getting the feeds in split form instead they are getting overlapped. I am using Qt 5.15 on a Windows 10 64-bit machine and I have tried building using both minGW and MSVC2015 getting the same results.
      The two codes are below:
      CamCam.qml

      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
          }
      
      }
      

      main.qml

      import QtQuick 2.12
      import QtMultimedia 5.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.15
      
      Window {
      visible: true
      width: 1900
      height: 1080
      title: qsTr("CamHub")
      
      Item{
              id: cameraLeft
              anchors.left: parent.left
              anchors.top: parent.top
              anchors.right: cameraRight.left
              anchors.bottom: parent.bottom
              clip: true
                      CamCam{
                          theID: QtMultimedia.availableCameras[0].deviceId
                          backgroundColor: "red"
                      }
              }
      
      Item{
              id: cameraRight
              anchors.right: parent.right
              anchors.top: parent.top
              anchors.left: cameraLeft.right
              anchors.bottom: parent.bottom
              CamCam{
                  theID: QtMultimedia.availableCameras[1].deviceId
                  backgroundColor: "blue"
      
              }
          }
      }
      
      

      How I knew they are overlapping?
      There are 2 images below. The first image is when I normally run it. The 2nd image is when I made a mistake in the 2nd half of the code (the one with blue background). Since the red background comes 1st in order hence it is always coming below the blue background. I might be wrong and hence any help would be great.
      182fef30-e2ad-4ceb-ba57-629c4f7b50c1-image.png
      f25faed6-7535-47f5-8815-7a45ec4492d8-image.png

      (I know there is no cam feed on the red background but trust me even when i connected the camera the same thing happens)

      Thank you!

      johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2

      @Animesh452 Hi

      Try adding a width and height to both cameras

      width: parent.width * 0.5
      height: parent.height
      
      A 1 Reply Last reply
      1
      • johngodJ johngod

        @Animesh452 Hi

        Try adding a width and height to both cameras

        width: parent.width * 0.5
        height: parent.height
        
        A Offline
        A Offline
        Animesh452
        wrote on last edited by
        #3

        @johngod Hi mate Thanks for the reply.
        I tried adding your snippet both inside and outside the CamCam class in main.qml but still got the same results. If I did anything wrong, please correct me. I am a beginner in Qt.

        Thanks!

        johngodJ 1 Reply Last reply
        0
        • A Animesh452

          @johngod Hi mate Thanks for the reply.
          I tried adding your snippet both inside and outside the CamCam class in main.qml but still got the same results. If I did anything wrong, please correct me. I am a beginner in Qt.

          Thanks!

          johngodJ Offline
          johngodJ Offline
          johngod
          wrote on last edited by
          #4

          @Animesh452 Hi

          Like this should work, I got the red and blue rectangle properly aligned

          Window {
              visible: true
              width: 1900
              height: 1080
              title: qsTr("CamHub")
          
              Item{
                  id: cameraLeft
                  width: parent.width * 0.5
                  height: parent.height
                  anchors.left: parent.left
                  clip: true
                  CamCam{
                      //  theID: QtMultimedia.availableCameras[0].deviceId    
                      backgroundColor: "red"
                      
                  }
              }
          
              Item{
                  id: cameraRight
                  width: parent.width * 0.5
                  height: parent.height
                  anchors.right: parent.right
                  CamCam{
                      backgroundColor: "blue"
          
                  }   
              }
          }
          
          A 1 Reply Last reply
          2
          • johngodJ johngod

            @Animesh452 Hi

            Like this should work, I got the red and blue rectangle properly aligned

            Window {
                visible: true
                width: 1900
                height: 1080
                title: qsTr("CamHub")
            
                Item{
                    id: cameraLeft
                    width: parent.width * 0.5
                    height: parent.height
                    anchors.left: parent.left
                    clip: true
                    CamCam{
                        //  theID: QtMultimedia.availableCameras[0].deviceId    
                        backgroundColor: "red"
                        
                    }
                }
            
                Item{
                    id: cameraRight
                    width: parent.width * 0.5
                    height: parent.height
                    anchors.right: parent.right
                    CamCam{
                        backgroundColor: "blue"
            
                    }   
                }
            }
            
            A Offline
            A Offline
            Animesh452
            wrote on last edited by
            #5

            @johngod A huge thanks buddy its works. I tried it with a USB cam and it works as intended.
            Screenshot (33).png
            Here is a ss after I connected another camera.
            Thanks a lot man!!!!

            I had another doubt like they aren't of the same size. So, can I resize the feeds using width and height or it depends on the camera I am using? Currently, one is an integrated laptop webcam while the other is a USB cam.

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

              Hi,

              The image aspect ratio usually depends on the camera you use. Some are 4:3 others 16:9. Some may even have several formats from which you can select one.

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

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                The image aspect ratio usually depends on the camera you use. Some are 4:3 others 16:9. Some may even have several formats from which you can select one.

                A Offline
                A Offline
                Animesh452
                wrote on last edited by
                #7

                @SGaist Hello. How would I know if my camera has multiple formats I can select from? If you could mention the related functions and how they are used, that would be great.

                Thanks!!

                SGaistS 1 Reply Last reply
                0
                • A Animesh452

                  @SGaist Hello. How would I know if my camera has multiple formats I can select from? If you could mention the related functions and how they are used, that would be great.

                  Thanks!!

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Animesh452 you have to read the camera documentation.

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

                  A 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @Animesh452 you have to read the camera documentation.

                    A Offline
                    A Offline
                    Animesh452
                    wrote on last edited by
                    #9

                    @SGaist Okay will do that thanks.
                    I also wanted to know if this can be done on Qt6. I tried but the problem I faced was the VideoOutput method in Qt6 didn't have a member called source, which was there in Qt5.15. So is there any way to do this split thing in Qt6?

                    SGaistS 1 Reply Last reply
                    0
                    • A Animesh452

                      @SGaist Okay will do that thanks.
                      I also wanted to know if this can be done on Qt6. I tried but the problem I faced was the VideoOutput method in Qt6 didn't have a member called source, which was there in Qt5.15. So is there any way to do this split thing in Qt6?

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      It's the other way around. You declare the output and then set it on the camera.

                      See the Camera QML type documentation.

                      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
                      • A Animesh452 has marked this topic as solved on

                      • Login

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