【问题标题】:Callback on each QML Video frame每个 QML 视频帧的回调
【发布时间】:2018-11-26 09:13:10
【问题描述】:

我有一个带有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:
};

【问题讨论】:

  • "在每一帧上调用一个 c++ 回调" 你好,你能澄清一下吗?你如何将帧传递给回调函数?另外,QString va 应该代表什么参数?

标签: c++ qt qml


【解决方案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/

【讨论】:

  • 感谢您的好主意。请给我你的想法的完整例子来完成答案。我想用你的想法从连接网络摄像机的 MediaPlayer 录制视频,但仍有很多问题。提前致谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多