Unsolved Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface
-
@DomTheDuck you may want to take a look at this OpenCV wrapper for QML just in case, either to use it directly or to check what/how they're doing things there.
-
Out of curiosity, what is the problem with the Camera qml type ?
-
@SGaist None at all, I just want to do a lot of backend (c++) work, and with using the QML camera I would need to get that feed to the backend, do some processing and then send it back to the QML front end. It seems inefficient to therefore use QML Camera.
-
What processing do you need ?
-
@domtheduck
Hi, were you ever able to make this work?I'm trying to use the zxing library to read some Qr codes, and this is done by using this library as part of a QAbstractVideoFilter applied in qml on the camera's video output.
I might be wrong but to me this type of processing definitely doesn't belong in QML, where I just want to describe the user interface, but definitely don't want to describe any processing (I know the filter will run in C, but still I don't see why the controls, Qr code results etc.. would have to go back and forth between the QML and C++ world, all this should stay in C++. The filter scheme being used here not to modify what the user sees, but to analyze frames).So there you go, were you able to figure it out? I can get something on my display, but the video doesn't show what's being captured (just flickering blank frames).
I have defined this class:
class PxQCameraAsSource : public QCamera { Q_OBJECT Q_PROPERTY(QAbstractVideoSurface* videoSurface READ getVideoSurface WRITE setVideoSurface ) public: explicit PxQCameraAsSource(QCamera::Position position, QObject *parent); public slots: void setVideoSurface(QAbstractVideoSurface* surface); QAbstractVideoSurface* getVideoSurface(); private: QAbstractVideoSurface* _surface; };
And for my .cpp:
PxQCameraAsSource::PxQCameraAsSource(QCamera::Position position, QObject *parent) : QCamera (position, parent) { } void PxQCameraAsSource::setVideoSurface(QAbstractVideoSurface* newSurface) { _surface = newSurface; setViewfinder(_surface); } QAbstractVideoSurface* PxQCameraAsSource::getVideoSurface() { return _surface; }
I guess I must be missing initialization steps, or some property/calls, but I have no idea which ones :-)
-
@gomgom
Can you use libraries that already do that?Like https://github.com/ftylitak/qzxing/ or https://github.com/swex/QZXingNu
-
@grecko Hi, these libs operate in the QML world (the filter is implemented there), which is what I am trying to avoid. For now I'm using QZXingNu, it works but I'm not happy with it from an architecture point of view.
I'd really like to limit the QML's role to displaying the camera viewfinder, but not to handle the Qr code reader result etc (even if it just passes the result on to the C++ side, it doesn't seem to make any sense to me)... -
@gomgom said in Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface:
these libs operate in the QML world (the filter is implemented there)
I guess the thing is perhaps there's a compelling reason (which I don't know) why the Qt developers provided an easy way to implement video filtering in QML but that same capability is not (or at least not easily) accessible to the C++ part...
-
Hi,
Are you looking for QAbstractVideoFilter ?
-
@sgaist
Hi,
Not really, no. The QZXingNu already provides a class based on QAbstractVideoFilter. But it then exposes this to the QML side, and examples create a camera, video output and connect the filter all in QML.
What I'm trying to do is to instantiate a QCamera and filter un C++, and somehow connect this to a QML VideoOutput. I am missing the glue in between :-)