佳能EDSDK如何获得实时取景图像的宽度和高度? [英] Canon EDSDK How can I get width and height of live view images?

查看:134
本文介绍了佳能EDSDK如何获得实时取景图像的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了C ++代码以在监视器上显示实时取景图像.我提到了一些关于stackoverflow的代码.最后,我完成了代码,但是有一些问题.

I written C++ code to display live view image on monitor. I referred to some code on stackoverflow. Finally, I complete my code, but there are some problem.

我想使用opencv显示实时取景图像,但是我不知道宽度&实时取景图像的高度. (也许是通过EDSDK函数检索的.)

I want display live view image using opencv, but I don't know to get the width & height of live view image. (maybe it is retrieved by EDSDK function..)

请为我回答.

(我附上了我的代码,我想为我的代码提供合适的答案)

(I attached my code, I want suitable answer for my code)

(看看"//libjpegTurbo...//,有手册_width& height.我想使用函数进行检索)

(look at "//libjpegTurbo...//, there are manual _width & height. I want to retrieve using function)

// 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;
} 

推荐答案

如果有evfImage,则可以使用EdsGetPropertyData请求其kEdsPropID_Evf_CoordinateSystem(类型为EdsSize).该值包含最后捕获的帧的实时视图的宽度和高度.

If you have an evfImage you can use EdsGetPropertyData to request its kEdsPropID_Evf_CoordinateSystem (type EdsSize). This value contains the width and height of the liveview of last captured frame.

这篇关于佳能EDSDK如何获得实时取景图像的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆