佳能EDSDK如何获得实时视图图像的宽度和高度
Canon EDSDK How can I get width and height of live view images?
我编写了c++代码在监视器上显示实时视图图像。我在stackoverflow上引用了一些代码。最后,我完成了我的代码,但是有一些问题。
我想使用opencv显示实时视图图像,但我不知道如何获得宽度&实时图像的高度。(可能是EDSDK函数检索…)
请回答我。
(我附上了我的代码,我想要合适的回答我的代码)
(看"//libjpegTurbo…//,有手动_width &高度。我想检索使用函数)
// Functions_body
bool LiveViewStart()
{
EdsError err = EDS_ERR_OK;
EdsCameraListRef cameraList = NULL;
EdsCameraRef camera = NULL;
EdsUInt32 count = 0;
bool isSDKLoaded = false;
// Initialize SDK
err = EdsInitializeSDK();
if(err == EDS_ERR_OK)
{
isSDKLoaded = true;
}
// Acquisition of camera list
if(err == EDS_ERR_OK)
{
err = EdsGetCameraList(&cameraList);
}
// Acquisition of number of Cameras
if(err == EDS_ERR_OK)
{
err = EdsGetChildCount(cameraList, &count);
if(count == 0)
{
err = EDS_ERR_DEVICE_NOT_FOUND;
}
}
// Acquisition of camera at the head of the list
if(err == EDS_ERR_OK)
{
err = EdsGetChildAtIndex(cameraList , 0 , &camera);
}
// Acquisition of camera information
EdsDeviceInfo deviceInfo;
if(err == EDS_ERR_OK)
{
err = EdsGetDeviceInfo(camera , &deviceInfo);
if(err == EDS_ERR_OK && camera == NULL)
{
err = EDS_ERR_DEVICE_NOT_FOUND;
}
}
// Release camera list
if(cameraList != NULL)
{
EdsRelease(cameraList);
}
if(err != EDS_ERR_OK)
{
::MessageBox(NULL,"Cannot detect camera",NULL,MB_OK);
exit(1);
}
// Open session with camera
if(err == EDS_ERR_OK)
{
err = EdsOpenSession(camera);
}
// Start Live view
// Get the output device for the live view image
EdsUInt32 device;
err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
// PC live view starts by setting the PC as the output device for the live view image.
if(err == EDS_ERR_OK)
{
device |= kEdsEvfOutputDevice_PC;
err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device);
}
Sleep(2000);
// Download EvfData
EdsEvfImageRef evfImage = NULL;
EdsStreamRef stream = NULL;
unsigned char* data = NULL;
unsigned long size = 0;
// Create memory stream
err = EdsCreateMemoryStream(0, &stream);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsCreateMemoryStream: " << err << "n";
return false;
}
// Create EvfImageRef.
err = EdsCreateEvfImageRef(stream, &evfImage);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsCreateEvfImageRef: " << err << "n";
return false;
}
// Download live view image data.
err = EdsDownloadEvfImage(camera, evfImage);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsDownloadEvfImage: " << err << "n";
return false;
}
//Sleep(1000);
// Get Pointer of evfStream
err = EdsGetPointer(stream, (EdsVoid**)& data);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsGetPointer: " << err << "n";
return false;
}
// Get Length of evfStream
err = EdsGetLength(stream, &size);
if (err != EDS_ERR_OK) {
cout << "Download Live View Image Error in Function EdsGetLength: " << err << "n";
return false;
}
// libjpegTurbo(data, size);
int JPEG_QUALITY = 75;
int COLOR_COMPONENTS = 3;
int _width = 1920;
int _height = 1080;
long unsigned int _jpegSize = 0;
unsigned char *_compressedImage = NULL;
unsigned char *buffer = new unsigned char [_width * _height * COLOR_COMPONENTS];
tjhandle _jpegCompressor = tjInitCompress();
tjCompress2(_jpegCompressor, buffer, _width, 0, _height, TJPF_RGB, &_compressedImage, &_jpegSize, TJSAMP_444, JPEG_QUALITY, TJFLAG_FASTDCT);
tjDestroy(_jpegCompressor);
// display RGB image in opencv
// Release stream
if (stream != NULL) {
EdsRelease(stream);
stream = NULL;
}
// Release evfImage
if (evfImage != NULL) {
EdsRelease(evfImage);
evfImage = NULL;
}
data = NULL;
// End Live view.
// Get the output device for the live view image
err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
// PC live view ends if the PC is disconneccted from the live view output device.
if(err == EDS_ERR_OK)
{
device &= ~kEdsEvfOutputDevice_PC;
err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
}
// Close session with camera
if(err == EDS_ERR_OK)
{
err = EdsCloseSession(camera);
}
// Release camera
if(camera != NULL)
{
EdsRelease(camera);
}
// Terminate SDK
if(isSDKLoaded)
{
EdsTerminateSDK();
}
return true;
}
佳能SDK不提供任何函数来获取实时视图图像的大小。你在代码中面临的问题是,你试图压缩图像,但你需要解压。我建议你仔细阅读一下libjpg turbo的用法。他们提供了很好的文档示例:http://www.libjpeg-turbo.org/Documentation/Documentation
旁注:这是你真正的代码还是只是为了展示?因为实时图像下载必须在循环中反复调用,否则您将只下载一个图像并关闭所有内容。
亲切的问候
如果你有一个evfImage,你可以使用EdsGetPropertyData请求它的kedspropid_evf_coordinatessystem(类型EdsSize)。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- 免费图像零宽度和高度
- Q::比例高度变换模式返回空图像
- 图像部分的开口高度/宽度
- 使用逐位运算符查找bmp图像的宽度和高度
- 如何使用opengl或dx从网格中生成深度(高度)图像
- 如何在OpenCV中获得图像宽度和高度
- 用c++实现图像的高度和宽度
- 如何加载具有负高度的图像
- 复制图像后,断言失败(大小>宽度0 &&&大小.高度>0)
- 抛出了一个奇怪的异常:在SFML中获取精灵图像的高度
- 从标题(宽度、高度等)获取图像信息,而无需打开它
- 佳能EDSDK如何获得实时视图图像的宽度和高度