Multiple cameras QML
-
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.
If I start the application once with only camera 1 and second time only with camera 2 then both cameras are working simultaneously:
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.
-
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:
-
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.
-
What are these two cameras ?
-
They are USB cameras, not web cameras.
-
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:
-
@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.12Window {
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.bottomCamCam{ 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.12Item{
id:cameraWindow
anchors.fill: parent
signal closed
property alias theID: camera.deviceId
property alias backgroundColor: background.color
property alias orientation: vo.orientationRectangle{ 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
-
@lxy12345 said in Multiple cameras QML:
anchors.right: swipeView.left
Since you don't have swipeView replace it with parent.