Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sample C code for Canon EDSDK Liveview?

Tags:

c

sample

edsdk

Is there anyone with a working piece of sample C code that implements LiveView using the Canon EDSDK? The sample code in the documentation looks great until you get to this bit:

// 
// Display image 
// 

Yup, that's it. They don't show how to BLT an image to a window using the data retrieved from the camera. They just say, "Display image." Thanks, Canon.

I have hunted the Internet (including this forum), but I have yet to find a C code sample that shows how to do this. I'm looking to avoid MFC, VB, managed code, or C#. Surely it's possible to do this in vanilla C, right? Vanilla C++ is fine as well.

Thanks, FredP

like image 985
FredP Avatar asked Jul 10 '10 00:07

FredP


1 Answers

There are two functions that they don't tell you about:
1) EdsGetPointer
2) EdsGetLength

This will give you a pointer to the beginning of the JPEG stream and the size respectively.

Once you have this use LibJPEG Turbo to decompress, Libjpeg just isn't fast enough.

Once you decompress, you can show the image using opencv.

bool CanonCamera::downloadLiveViewImage()
{
    EdsError err = EDS_ERR_OK;
    EdsEvfImageRef image = NULL;
    EdsStreamRef stream = NULL;
    unsigned char* data = NULL;
    unsigned long size = 0;

    err = EdsCreateMemoryStream(0, &stream);

    if (err != EDS_ERR_OK) {
        cout << "Download Live View Image Error in Function EdsCreateMemoryStream: " << err << "\n";
        return false;
    }

    err = EdsCreateEvfImageRef(stream, &image);

    if (err != EDS_ERR_OK) {
        cout << "Download Live View Image Error in Function EdsCreateEvfImageRef: " << err << "\n";
        return false;

    }

    err = EdsDownloadEvfImage(cameraRef, image);

    if (err != EDS_ERR_OK) {
        cout << "Download Live View Image Error in Function EdsDownloadEvfImage: " << err << "\n";
        return false;
    }

    err = EdsGetPointer(stream, (EdsVoid**)& data);

    if (err != EDS_ERR_OK) {
        cout << "Download Live View Image Error in Function EdsGetPointer: " << err << "\n";
        return false;
    }

    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);
    // display RGB image in opencv

    if (stream != NULL) {
        EdsRelease(stream);
        stream = NULL;
    }

    if (image != NULL) {            
        EdsRelease(image);
        image = NULL;
    }

    data = NULL;
    return true;
}
like image 152
rossb83 Avatar answered Sep 20 '22 06:09

rossb83