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

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
FredP
  • 71
  • 1
  • 2
  • 1
    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. – Brock Adams Jul 10 '10 at 01:00
  • Sure. Here's a V example on Stack Overflow: http://stackoverflow.com/questions/895265/live-view-with-canon-edsdk-2-5-2-vb-net 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... http://tech.groups.yahoo.com/group/CanonSDK/message/1155 ...is way simpler, but uses a "CImage" at a critical point in the code. – FredP Jul 10 '10 at 04:25
  • 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. – Brock Adams Jul 10 '10 at 04:57
  • Brock, Gurgh, indeed! I guess I'll just keep hacking away at it... – FredP Jul 15 '10 at 00:36
  • 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. Thanks – user643019 Mar 03 '11 at 13:08

1 Answers1

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;
}
Nikson Kanti Paul
  • 3,394
  • 1
  • 35
  • 51
rossb83
  • 1,694
  • 4
  • 21
  • 40