Обратный вызов на каждый кадр QML Video - PullRequest
0 голосов
/ 26 ноября 2018

У меня есть приложение QML QuickControls 2 с компонентом / элементом управления Video.Я хочу создать обратный вызов C ++ для обработки каждого кадра в видео.Функция обратного вызова C ++ будет обрабатывать каждый кадр, то есть находить края в изображении / кадре и возвращать это изображение края для отображения пользовательского интерфейса.

Как я могу подключить все это?То есть как-то сказать 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:
};

1 Ответ

0 голосов
/ 26 ноября 2018

Вы можете создать 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/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...