Qt--windows平台上如何获取qml中Camera的数据
2016-09-20 15:54
351 查看
曾经写了一个博客:
我们为什么不习惯使用qml? 最后有一个悬念,到底如何在C++代码中获取qml中camera的数据呢?
QAbstractVideoFilter
The QAbstractVideoFilter class represents a filter that is applied to the video frames received by a VideoOutput type.
https://doc-snapshots.qt.io/qt5-dev/qabstractvideofilter.html#details
QVideoFilterRunnable
The QVideoFilterRunnable class represents the implementation of a filter that owns all graphics and computational resources, and performs the actual filtering or calculations.
上面两个类自己去看官方文档吧,翻译不好。
开始撸代码!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
写一个自己的类叫CameraFilter吧:
camerafilter.h
camerafilter.cc
不要骂娘,上面的代码很简单的,其实官方的文档中也有类似的代码片段,不懂的自己看奥。
是通过:
我们自己写一个slot,然后对Frame进行相应的处理!
接下来才是高潮!!!!
第一步、让qml中理解我们自己的类CameraFilter(Defining QML Types from C++) :
在C++中注册:
在qml中导入:
第二步、在qml中干点大事儿:
我们为什么不习惯使用qml? 最后有一个悬念,到底如何在C++代码中获取qml中camera的数据呢?
QAbstractVideoFilter
The QAbstractVideoFilter class represents a filter that is applied to the video frames received by a VideoOutput type.
https://doc-snapshots.qt.io/qt5-dev/qabstractvideofilter.html#details
QVideoFilterRunnable
The QVideoFilterRunnable class represents the implementation of a filter that owns all graphics and computational resources, and performs the actual filtering or calculations.
上面两个类自己去看官方文档吧,翻译不好。
开始撸代码!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
写一个自己的类叫CameraFilter吧:
camerafilter.h
#ifndef CAMERAFILTER #define CAMERAFILTER #include <QVideoFilterRunnable> class CameraFilter : public QAbstractVideoFilter { Q_OBJECT public: CameraFilter(); ~CameraFilter(); QVideoFilterRunnable *createFilterRunnable(); private: signals: void finished(QObject *result); void cameraFrameSignal(QVideoFrame); public slots: }; class CameraFilterRunnable : public QVideoFilterRunnable { public: CameraFilterRunnable(CameraFilter* filter = NULL); ~CameraFilterRunnable(); QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags); private: CameraFilter *m_filter; }; #endif // CAMERAFILTER
camerafilter.cc
#include "camerafilter.h" #include "qdebug.h" CameraFilter::CameraFilter() { } CameraFilter::~CameraFilter() { } QVideoFilterRunnable *CameraFilter::createFilterRunnable() { return new CameraFilterRunnable(this); } CameraFilterRunnable::CameraFilterRunnable(CameraFilter* filter) { m_filter = filter; } CameraFilterRunnable::~CameraFilterRunnable() { } QVideoFrame CameraFilterRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) { QVideoFrame cloneFrame(*input); emit m_filter->cameraFrameSignal(cloneFrame); return cloneFrame; }
不要骂娘,上面的代码很简单的,其实官方的文档中也有类似的代码片段,不懂的自己看奥。
是通过:
emit m_filter->cameraFrameSignal(cloneFrame);
我们自己写一个slot,然后对Frame进行相应的处理!
接下来才是高潮!!!!
第一步、让qml中理解我们自己的类CameraFilter(Defining QML Types from C++) :
在C++中注册:
qmlRegisterType<CameraFilter>("CameraFilter", 1, 0, "CameraFilter");
在qml中导入:
import CameraFilter 1.0
第二步、在qml中干点大事儿:
Camera { objectName: "CameraObject" id: camera imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash exposure { exposureCompensation: -1.0 exposureMode: Camera.ExposurePortrait } captureMode: Camera.CaptureVideo flash.mode: Camera.FlashRedEyeReduction } VideoOutput { width: 160 height: 90 id: video_output objectName: "VidelOutputObject" source: camera anchors.fill: parent focus : visible // to receive focus and capture key events when visible visible: false filters: [filter] fillMode: VideoOutput.PreserveAspectFit } CameraFilter { objectName: "cameraFilterObject" id: filter }
相关文章推荐
- Qt--windows平台上如何获取qml中Camera的数据
- Qt用QCameraInfo获取摄像头个数
- NSIS + QT 做安装卸载程序
- Qt用DirectShow获取摄像头个数示例
- 在Qt中利用window下的DirectShow获取摄像头名称示例
- Qt、Opencv、QML实现摄像头简单对比
- QTP 学习 - 参数化
- QTP 学习 - 检查点
- Qt之QScintilla(源代码编辑器)
- Qt之操作数据库(SQLite)
- 初识---Qt解析XML文件(QDomDocument)
- Qt环境搭建(Qt Creator)+Visual Studio
- qt信号signal和槽slot机制
- win10+vs2013+Qt5.4 安装方法
- qt windows 导入导出xls
- Qt OpenGL教程
- QTP测试实验
- Qt学习笔记:QDir
- WIN7下Qt4.8.6静态编译
- Qt for Windows:Qt 5.4.0 MinGW 静态编译版本制作