Getting raw viewfinder frame data from the camera in Qt5.5
-
I am trying to get raw viewfinder frame data (RGB or YUV) in Qt 5.5 in Android; I am using a Galaxy Nexus running Android 4.3. I have tried different ways to achieve this but I was not successful. The only way that it did work was back in the day of necessitas and Bogdan Vatra, when I used pure java to access the frame data in Java and pass it to Qt using JNI.
Presently I tried numerous ways, just to list a few keywords:
-
QCamera with custom QAbstractVideoSurface class as the viewfinder: this method works on Windows 7 PC, but when I ran the same example on Android there is no error reported but no callbacks from the custom QAbstractVideoSurface class are getting called; just nothing happens after the slot XXXXX::onCameraStateChanged(): state= QCamera::ActiveState
-
QVideoProbe->setSource(QCamera) or QVideoProbe->setSource(QMediaRecorder) and QMediaRecorder instantiated using QCamera;
-
the new QAbstractVideoBuffer class; this try is detailed here: https://forum.qt.io/topic/55810/qt-5-5-android-qvideoframe-problem-with-mapping-memory-from-camera/4
-
I even tried the old way of getting the video frame data in Android java and passing the data to Qt using JNI; this did not work either but this time on the Java side; it seems in newer versions of Android one cannot get viewfinder data without a visible video surface on screen, which can not be the case because I want the actual UI to be in Qt/QML and not in Java.
I am at a loss; does anyone out there managed to achieve this pinnacle of basic camera API functionality??? The only thing from the Qt 5.x examples related to camera that works on an actual Android device is the QML camera example but this one is utterly useless because that does not provide access to the frame data in C++.
Thanks,
Ionut Dediu -
-
Hi. I was going through the exact same problem and thanks to your post I could solve it. I'm posting here the solution for future reference. The 4th item of your list gave me an idea.
I even tried the old way of getting the video frame data in Android java and passing the data to Qt using JNI; this did not work either but this time on the Java side; it seems in newer versions of Android one cannot get viewfinder data without a visible video surface on screen, which can not be the case because I want the actual UI to be in Qt/QML and not in Java.
I was implementing a QRCode reader. Here's what I've done. My qml file:
Camera { id: camera } CodeScanner { source: camera onCodeDetected: { // do the thing } } VideoOutput { anchors.fill: parent source: camera }
My class (simplified code):
void CodeScanner::setSource(QObject *value){ QVariant mediaObject = value->property("mediaObject"); if(mediaObject.isValid()){ m_camera = mediaObject.value<QCamera*>(); if(m_camera && m_camera->availability() == QMultimedia::Available){ m_probe = new QVideoProbe(this); if(m_probe->setSource(m_camera)){ connect(m_probe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(videoFrameProbed(QVideoFrame))); } } } }
For Windows, setting a custom QAbstractVideoSurface as the camera's viewfinder is the way to go. For Android, the solution above works like a charm.
Thank you.