Display the QML screen on Ui :: MainWindow
-
Hi everybody!
I'm new bie, I use QLM to display the camera, and I want this display frame to be bring to front on ui.form in Ui :: MainWindow
but at present when
win.show ();
the QML screen will be hidden (cannot see the camera screen)int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow win; Window* window = new Window(); PropertyList* propertyList = window->getPropertyList(); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty(QStringLiteral("propertyList"), propertyList); engine.load(QUrl(QStringLiteral("qrc:/motlan.qml"))); if (engine.rootObjects().isEmpty()) { return -1; } win.show(); return a.exec(); }
Thanks!
-
You're mixing two technologies, but is it really what you want to do?
If you just want the QML, then just drop the widget stuff altogether (as in the QML examples). If you indeed want to mix the two there's the QQuickWidget wrapper. -
@kshegunov said in Display the QML screen on Ui :: MainWindow:
ou're mixing two technologies, but is it really what you want to do?
If you just want the QML, then just drop the widget stuff altogether (as in the QML examples). If you indeed want to mix the two there's the QQuickWidget wrapper.Thanks !
In qml I receive video from camera, then pass it to C ++ to display on the label, but the received data is blank.
.qmlCamera { id: camera objectName: "set_camera" imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash exposure { exposureCompensation: -1.0 exposureMode: Camera.ExposurePortrait } focus { focusMode: Camera.FocusContinuous focusPointMode: Camera.FocusPointCenter } flash.mode: Camera.FlashRedEyeReduction // giảm hiệu ứng mắt đỏ flash imageCapture { onImageCaptured: { photoPreview.source = preview // Show the preview in an Image } } } VideoOutput { orientation: 270 // xoay khung camera source: camera anchors.fill: parent focus : false // to receive focus and capture key events when visible }
.cpp
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/motlan.qml"))); QObject *qmlCamera = engine.rootObjects().at(0)->findChild<QObject*>("set_camera"); ui->inform->setText(qmlCamera->objectName()); // I test show is fine ! QCamera *camera1 = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject")); probe_.setSource(camera1); connect(&probe_,SIGNAL(videoFrameProbed(const QVideoFrame &)), this, SLOT(present(const QVideoFrame &)));
Now, I do not receive SIGNAL of probe, the received data is not a QVideoFrame ?
Regards !
-
Hi,
What OS are you on ?
-
Why are you trying to get the output from a QML video output when there's already a QML item to do exactly that ?
-
@SGaist said in Display the QML screen on Ui :: MainWindow:
Why are you trying to get the output from a QML video output when there's already a QML item to do exactly that ?
Because I am using opencv for android on c ++, but for c ++, I can't get real time video of camera (I tried different ways but to no avail)
Error displaying video from the camera, Please help me in this section
https://forum.qt.io/topic/126213/error-displaying-video-from-the-camera/10Many thanks!
-
What do you want to do with OpenCV ?
Depending on that it does not make sens to grab the images from Qt to process them with OpenCV, just use OpenCV directly for that and Qt only at the end.
-
@SGaist said in Display the QML screen on Ui :: MainWindow:
What do you want to do with OpenCV ?
Depending on that it does not make sens to grab the images from Qt to process them with OpenCV, just use OpenCV directly for that and Qt only at the endThanks !
I simply need to get the video camera as Mat, to process the image information, but in Qt C ++ Mainwindow, it doesn't seem to support to get the image directly from the camera.
For example I use this case for Android 11, Qt5.15, arm64-v8afor (const QCameraInfo &cameraInfo : cameras) { if (cameraInfo.deviceName() == "back") { qDebug() <<"video start"; camera = new QCamera(cameraInfo); viewfinder = new QCameraViewfinder(); viewfinder->showMaximized(); camera->setCaptureMode(QCamera::CaptureViewfinder); camera->setViewfinder(viewfinder); viewfinder->show(); camera->start(); qDebug() <<"video finish"; } }
and get an error message
W libuntitled_arm64-v8a.so: The video surface is not compatible with any format
I spent a lot of time dealing with this but still to no avail
Regards ! -
As I already wrote: use OpenCV directly to get the data from the camera.
-
@SGaist said in Display the QML screen on Ui :: MainWindow:
As I already wrote: use OpenCV directly to get the data from the camera.
As I tried the Qt Android does not support OpenCv open directly from the camera, for example the following function always returns false
capture.open(0); // mở camera 0 if(!capture.isOpened()) { qDebug() << "Could not open camera" << 0; return; }
There are many places on the forum that also talk about this
https://forum.qt.io/topic/41961/accessing-the-android-camera-in-qt/16
and
https://github.com/opencv/opencv/issues/11952Thanks!
-
Which version of OpenCV are you using ?
This merge request implemented the Androïd support.
-
@SGaist said in Display the QML screen on Ui :: MainWindow:
Which version of OpenCV are you using ?
This merge request implemented the Androïd support.I use Qt5.15, OpenCV4.5.2, I hope you can show me how to use it
with this Opencv + Qt, I am still using its features normally, except for taking video directly from the cameraRegards!
-
Did you check that you are using the API level 24 as indicated in the patch ?
-
@SGaist said in Display the QML screen on Ui :: MainWindow:
Did you check that you are using the API level 24 as indicated in the patch ?
Hi !
I am using API30, but the integration of this suite is relatively complicated, because my English is limited, so I have not done this yet, I hope that next time there will be an easier approach. Thank you very much! -
Tutorial of what ?
-
@SGaist
Is there any tutorial with Qt C ++? I want detailed tutorial on reading realtime camera using opencv on android, as you said, there is this merge request implemented the Android support,
I also tried using QVideoProbe, but the camera video format is still wrong, I'm stuckvoid MainWindow::handleFrame(QVideoFrame frame) { tien++; qDebug() << tien; auto input_w = frame.width(); auto input_h = frame.height(); auto cam_data = frame.bits(); Mat yuyv(input_h+input_h/2, input_w,CV_8UC1, &cam_data); Mat rgb (input_h, input_w,CV_8UC4); cvtColor(yuyv, rgb, cv::COLOR_YUV2BGRA_NV21); QImage img= QImage((const unsigned char*)(yuyv.data), yuyv.cols,yuyv.rows, QImage::Format_BGR888); }
Thanks!
@SGaist said in Display the QML screen on Ui :: MainWindow:
Which version of OpenCV are you using ?
This merge request implemented the Androïd support.
-
You did not check the type of video frame you get. From memory, on Androïd it's an OpenGL texture.
No, I do not have a tutorial at hand however there are already many applications running OpenCV in conjunction with Qt. Use the search feature of this forum. There are already been several question related to that subject.
-
@SGaist said in Display the QML screen on Ui :: MainWindow:
You did not check the type of video frame you get. From memory, on Androïd it's an OpenGL texture.
No, I do not have a tutorial at hand however there are already many applications running OpenCV in conjunction with Qt. Use the search feature of this forum. There are already been several question related to that subject.
Hello!
I am also using openecv with Qt android, everything is very good, except getting realtime data of the camera, i have also spent a lot of time searching the forum, but haven't found anyone who can do it real time from camera, thank you!