【问题标题】:How to access camera in QML QVideoFilterRunnable?如何在 QML QVideoFilterRunnable 中访问相机?
【发布时间】:2016-01-27 19:13:40
【问题描述】:

https://blog.qt.io/blog/2015/03/20/introducing-video-filters-in-qt-multimedia 的博客之后,我设法让我的 C++ 过滤器与 QML 定义的相机一起使用。我遇到的问题是我的过滤器接收到的图像不考虑我的屏幕方向。 Qt 文档http://doc.qt.io/qt-5/cameraoverview.html 展示了如何根据相机和屏幕方向旋转图像。不清楚的是如何从过滤器中获取相机实例。这是我的 QML 文件中的相关 sn-p:

Camera {
    id: camera
    captureMode: Camera.CaptureStillImage
    ...
}

MyFilter {
    id: filter
}

VideoOutput {
    id: viewfinder
    source: camera
    filters: [ filter ]
    ...
}

如何从我的 QVideoFilterRunnable 实例访问 QCamera 实例?问候。

【问题讨论】:

  • 你不能直接访问camera对象,因为runnable是在QCamera之外的另一个线程中调用的,并且QCamera不是线程安全的。您需要将所需的信息传递给您的过滤器(作为属性)并让可运行对象从过滤器中获取它们。 (并确保访问是线程安全的。

标签: qt qml


【解决方案1】:

回答您关于旋转的具体问题,我的最佳答案是将方向从 VideoOutput 组件传递到您的自定义组件,即

Camera {
    id: camera
    captureMode: Camera.CaptureStillImage
    ...
}

MyFilter {
    id: filter
    orientation: videofinder.orientation
}

VideoOutput {
    id: viewfinder
    source: camera
    autoOrientation: true
    filters: [ filter ]
    ...
}

这样,您的自定义过滤器将知道最终用户如何看待您的图片。另一个问题是在某些设备上图像也会翻转:

#ifdef Q_OS_ANDROID
bool flip = true;
#else
bool flip = surfaceFormat.scanLineDirection() == QVideoSurfaceFormat::BottomToTop;
#endif

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2016-07-20
    • 2021-11-17
    • 2017-12-29
    • 2022-01-01
    相关资源
    最近更新 更多