QML 叠加在摄像头视频上

QML overlay on the camera video

我正在尝试在 Qt/QML 中的相机对象捕获的帧上绘制一些叠加层。相机本身定义为:

Camera {
    id: camera
    captureMode: Camera.CaptureVideo
}
VideoOutput {
    source: camera
    focus : visible 
    anchors.fill: parent
}

现在当我调用 camera.videorecorder.record() 时,摄像机开始录制并且当前帧显示在视频输出 canvas 上。现在,我想做的是在框架上的任意位置绘制一个矩形。

我看到有一些着色器效果示例 (http://doc.qt.io/qt-5/qtmultimedia-multimedia-video-qmlvideofx-example.html),但它们对于我想做的事情来说看起来真的很复杂,而且我不精通 GLSL。

是这样的吗?

Camera {
    id: camera
    captureMode: Camera.CaptureVideo
}

VideoOutput {
    source: camera
    focus : visible
    anchors.fill: parent
    Rectangle {
            color: "red";
            width: parent.width / 2;
            height: parent.height / 2;
            anchors.centerIn: parent;
   }
}

编辑: 这也行得通:

Camera {
    id: camera
    captureMode: Camera.CaptureVideo
}
VideoOutput {
    source: camera
    focus : visible
    anchors.fill: parent
}
Rectangle {
        color: "red";
        width: parent.width / 2;
        height: parent.height / 2;
        anchors.centerIn: parent;
}