Sample C code for Canon EDSDK Liveview?
Asked Answered
K

1

7

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

Kellen answered 10/7, 2010 at 0:54 Comment(5)
Do you have MFC, VB, managed code, or C# examples? If so, including or linking to that code here might help to figure out a C equivalent.Brendin
Sure. Here's a V example on Stack Overflow: #895765 It's a big, gnarly thing that uses a VB specific GUI element to display into. I'm trying to BLT into a plain old HDC. This C# one... tech.groups.yahoo.com/group/CanonSDK/message/1155 ...is way simpler, but uses a "CImage" at a critical point in the code.Kellen
Gurgh, what a mess. If I had a compatible camera I might take a whack at it. Good luck, but you might have to drink the Microsoft Kool-Aid.Brendin
Brock, Gurgh, indeed! I guess I'll just keep hacking away at it...Kellen
Hi FredP, Did you were able to program the C code to get the liveView? if so, can you give me a clue? I'm just starting to program in C and I want to control my DR Xsi while learning it. ThanksCharmine
N
4

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;
}
Nathalie answered 22/3, 2011 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.