I have very a simply application written in QT in which I want to display a movie by using QMediaPlayer
, but before I will display any frame I would like to detect on it some objects and mark them by drawing a rectangle over it.
I've read in http://doc.qt.io/qt-5/videooverview.html that I can access each frame by subclassing QAbstractVideoSurface
and so I dit it.
class VideoSurface : public QAbstractVideoSurface {
Q_OBJECT
bool present(const QVideoFrame &frame) override {
if (surfaceFormat().pixelFormat() != frame.pixelFormat()
|| surfaceFormat().frameSize() != frame.size()) {
setError(IncorrectFormatError);
stop();
return false;
} else {
currentFrame = frame;
return true;
}
}
...
}
Now, I am receiving in this member function frames that I want to modify by drawing on it rectangles in places where I detected objects and then I would like to display them on the screen (preferably on some widget).
How can I do this?
Should my
VideoSurface
class containQWidget
as a member? or should I subclassQWidget
which will containVideoSurface
?In both cases, how can I display this frame? Should I first convert it to
QImage
and then display (it would be convinien for me, because my detection system is working withQImage
, but would it be efficient)? I know that I can't paint from outside a paint event, so I can't paint inpresent
function, so where exactly should be this painting function and how I can call it?Where should I detect those object and modify frame? In
present
function, or in drawing function?