我有一个带有Video
组件/控件的QML QuickControls 2应用程序。我想创建一个C ++回调来处理视频中的每个帧。 C ++回调函数将处理每个帧,即在图像/帧中找到边缘并返回该边缘图像以供UI显示。
如何将所有这些挂钩?即,以某种方式告诉QML在每个帧上调用c ++回调吗?
Video {
id: video
fillMode: VideoOutput.PreserveAspectFit
anchors.fill : parent
source: "file:///D:/cards.mp4"
muted: true
focus: true
Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
Keys.onLeftPressed: video.seek(video.position - 5000)
Keys.onRightPressed: video.seek(video.position + 5000)
}
我的回调类,不确定是否正确:
class ImageProcessor : public QObject
{
Q_OBJECT
public:
explicit ImageProcessor(QObject *parent = nullptr);
Q_INVOKABLE void processImage(QString va);
signals:
public slots:
};
答案 0 :(得分:1)
您可以从视频中创建一个VideoOutput
:
Rectangle {
width: 800
height: 600
color: "black"
MediaPlayer {
id: player
source: "file://video.webm"
autoPlay: true
}
VideoOutput {
id: videoOutput
source: player
anchors.fill: parent
}
}
您可以将过滤器添加到VideoOutput
。例如,这里是faceRecognitionFilter
:
VideoOutput {
...
filters: [ faceRecognitionFilter ]
}
在C++
过滤器的实现中,您可以到达框架:
QVideoFrame FaceRecogFilterRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags)
{
// Convert the input into a suitable OpenCV image format, then run e.g. cv::CascadeClassifier,
// and finally store the list of rectangles into a QObject exposing a 'rects' property.
...
return *input;
}
您可以在此处收集一些信息:
http://doc.qt.io/qt-5/qml-qtmultimedia-videooutput.html
http://blog.qt.io/blog/2015/03/20/introducing-video-filters-in-qt-multimedia/