一、概述
想要使用 canon 的 sdk 进行实时的一个预览,即 LiveView 功能。
二、前期准备
前期的一些相机的连接,可以参考我之前写的文章 QT 使用 canon sdk 拍照并保存到本机
三、实时预览步骤
3.1 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);
}
}
3.2 将预览的图像流转为 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;