Qt中如何使用canon edsdk实现实时预览
发表于:2024-10-19 作者:千家信息网编辑
千家信息网最后更新 2024年10月19日,这篇文章主要介绍"Qt中如何使用canon edsdk实现实时预览",在日常操作中,相信很多人在Qt中如何使用canon edsdk实现实时预览问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作
千家信息网最后更新 2024年10月19日Qt中如何使用canon edsdk实现实时预览
这篇文章主要介绍"Qt中如何使用canon edsdk实现实时预览",在日常操作中,相信很多人在Qt中如何使用canon edsdk实现实时预览问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"Qt中如何使用canon edsdk实现实时预览"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
实时预览步骤
StartLiveView
声明一个变量来标志 m_isLiveView
来标识 liveview 是否开启。
将实时预览输出到 PC 上
device |= kEdsEvfOutputDevice_PC;
// -----------------------------void MainWindow::StartLiveView(){ // Change settings because live view cannot be started // when camera settings are set to "do not perform live view." // 开启 EdsError err = EDS_ERR_OK; uint evfMode = 1; //把 1 写入 enable err = EdsSetPropertyData(m_camera, kEdsPropID_Evf_Mode, 1, sizeof(uint), &evfMode); m_isLiveView = true; // Get the output device for the live view image EdsUInt32 device; err = EdsGetPropertyData(m_camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device); if(err == EDS_ERR_OK) { device |= kEdsEvfOutputDevice_PC; err = EdsSetPropertyData(m_camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device); }}
将预览的图像流转为 QImage 再转为 Mat
QImage img = QImage::fromData(data, length, "JPG");
将图像流转为 QImage
格式,这个是最重要的,在网上搜索了非常久,不知道怎么利用 data 和 length,网上的很多都是用 vb 和 c# 处理的,没有 C++ 的。
// ------------------------------------bool MainWindow::requestLiveViewImage(){ EdsError error = EDS_ERR_OK; EdsStreamRef stream = NULL; EdsEvfImageRef evfImage = NULL; EdsUInt64 length; if (!m_isLiveView) { error = EDS_ERR_INTERNAL_ERROR; qDebug() << "liveView false"; return false; } // 在主机计算机的内存中创建流。 如果写入超出分配的缓冲区大小,则会自动扩展内存。 error = EdsCreateMemoryStream(0, &stream); if (error != EDS_ERR_OK) { qDebug() << ("failed to create memory stream"); return false; } // 创建一个用于获取实时取景图像数据集的对象。 error = EdsCreateEvfImageRef(stream, &evfImage); if (error != EDS_ERR_OK) { qDebug() << ("failed to create Evf image"); return false; } // 下载当前处于实时取景模式的相机的实时取景图像数据集。 error = EdsDownloadEvfImage(m_camera, evfImage); if (error != EDS_ERR_OK) { // 当相机未准备好图像数据集或无法获取图像数据集时 if (error == EDS_ERR_OBJECT_NOTREADY) { qDebug() << ("failed to download Evf image, not ready yet"); } else { qDebug() << ("failed to download Evf image"); } return false; } // 获取图像流的大小 error = EdsGetLength(stream, &length); if (error != EDS_ERR_OK) { qDebug() << ("failed to get Evf image length"); return false; } if (length == 0) { qDebug() << ("failed to get Evf length is zero"); return false; } // 获取图像流的指针 unsigned char* data = NULL; error = EdsGetPointer(stream, (EdsVoid**)&data); if (error != EDS_ERR_OK) { qDebug() << ("failed to get pointer from stream"); return false; } // 将图像流转为 QImage QImage img = QImage::fromData(data, length, "JPG"); // 将 QImage 转为 Mat 格式 m_image = QImageToMat(img); // 释放 if (stream != NULL) { EdsRelease(stream); stream = NULL; } if (evfImage != NULL) { EdsRelease(evfImage); evfImage = NULL; } return true;}// -----------------------------------------cv::Mat MainWindow::QImageToMat(QImage& src){ // 注意这个 CV_8UC4 和你相机拍到的图像格式有关系,如果不符合,图像会损坏,显示出来就有问题 cv::Mat tmp(src.height(),src.width(),CV_8UC4,(uchar*)src.bits(),src.bytesPerLine()); cv::Mat result = tmp.clone(); // 深拷贝 return result;}
在 OpenCv 中显示
// -------------------------void MainWindow::ShowVideo(){ namedWindow("yunhu",WINDOW_NORMAL); while(1) { requestLiveViewImage(); // m_image 就是转换生成的 Mat if(m_image.data != NULL) { imshow("yunhu", m_image); cvWaitKey(50); } }}
到此,关于"Qt中如何使用canon edsdk实现实时预览"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
图像
实时
数据
学习
格式
相机
流转
内存
大小
更多
问题
帮助
实用
重要
接下来
主机
变量
对象
就是
拷贝
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
电信防范5g网络安全风险
win10适合软件开发吗
数据库设计时标准数据采用
车系车款数据库
深圳大微互联网科技有限公司
桓台时时网络技术有限公司
软件开发者自我介绍
清空数据库vb
大华视频服务器初始化
服务器安全狗的使用
中拓互联网科技有限公司
数据库系统 战德臣
打不开年度数据库
网络安全危害处罚
重庆服务器迁移推荐
女生网络安全教育
怎么介绍软件开发这个课程
数据库sql类型设置在哪里
合肥软件开发免费官方版
王某被某软件开发公司录用
数据计算软件开发
工程软件开发技术上机难吗
深圳大微互联网科技有限公司
网络安全洁
四川软件开发公司推荐
企业网络安全对策建议
上海红色文化馆软件开发公司
u点家庭服务器绿灯闪完不亮
网络安全硕士研究生待遇
两会关于网络安全通知