Click here to Skip to main content
Click here to Skip to main content

A wrapper for the canon CDSDK and PRSDK for remote capture

By , , 18 May 2007
 

The Canon capture sample app

Introduction

Both Benjamin and I have been working with digital cameras for some time now. Of the few manufacturers that support remote capture, Canon has the best feature set. Unfortunately, the Canon SDK does not contain examples in C#, it is C++ only. Elias Torres is well known for his CDSDK wrapper, which I've used with much success. However, newer cameras are not supported by the CDSDK. Most new Canon cameras use the PRSDK. Our C# library (based on the C++ SDK samples and the Elias Torres wrapper) encapsulates Canon's CDSDK and PRSDK.

THE SAMPLE PROGRAM WILL NOT WORK !!!!!

Having written a number of CP articles, I know that we'll be asked this no matter what, but here goes. This is a wrapper of an existing SDK. It won't work without the SDK, or at least the DLLs that come with the SDK. In fact, there are two SDKs involved, although I hope to add a PRSDK-only mode at some point, given that no cameras on sale today work with the CDSDK. We can't give you the DLLs - Canon requires that you register with them to obtain a license. Elias' forum is full of 'please send me the SDK' requests. Please don't ask. We'd love to help you, but we will not disrespect software copyrights.

Sample program

The sample program simply attempts to connect to a Canon camera, enumerate some settings and allows you to show a preview and take pictures. More than the Canon sample does, and more in line with the feature set I'd imagine most people would be looking for. If you work through the sample, you'll see how to query the camera for it's settings, how to take pictures, etc.

Enumerations

The PRSDK and the CDSDK each define their own enums for settings, but these settings often overlap. In order to make things strongly typed, where the PRSDK contains all the values in the CDSDK, I've used the PRSDK enum as the property to get available settings, and to set a value. I did this as the CDSDK will not change, but the PRSDK may add new values. Where there are values in the CDSDK and not the PRSDK, you can use the enums, but the actual properties just take int, so as to not offer properties that are not available.

PRSDK and shooting modes

One thing I've discovered, neither my A620 or my A640 will change shooting mode with the PRSDK, it accepts the setting and ignores it. I think this is a bug in the SDK, I've written to Canon about it and will update the wrapper if I get a fix. In the meantime, I added an IsPRSDK property on the camera, so if the camera connects via the PRSDK and you need an effect such as grayscale, you can post process the images.

I have got a reply from Canon - the sequence went something like this:

Me: I don't think setting the PhotoEffect works in the PRSDK

Canon: Try reading the manual

Me: Thanks, I did, and I've done what it says, but I can't set grayscale. Does it work for you?

Canon: You can set the camera to grayscale manually, then connect. We've tested, and that works here.

Me: Will the camera remember this setting when powered off?

Canon: No. Thank you for developing software for Canon cameras.

I assume that this means the SDK is definately broken in this regard. I also found that trying to set the PhotoMode meant that when I set ExposureCompensation afterwards, I'd get an AccessDenied error, so I use the IsPRSDK method to make sure I don't try to set this property on a newer camera.

Multi-threading

The background to this wrapper is an interesting story. I wrote a wrapper for the PRSDK only, mainly in C++/CLI (so, no pinvoke, pretty much the opposite of how this wrapper works). I coded it for my specific application, not as broadly as this one is written. I wrote a test app and it worked fine. I integrated the DLL into my app, and it kept throwing a WMI error. It was at this point that I met Benjamin, who had also written a wrapper based on Elias' work.

Benjamin's wrapper used pinvoke and was C# only. Building on his code, I made several improvements - added some properties, fixed a few bugs and made some of the existing properties strongly typed. I wrote the included sample app while improving on the wrapper - everything worked. To my surprise, when I added the wrapper to my program, I immediately got WMI errors! After wrestling with the problem, I found that the SDK doesn't like being run from a thread, but a thread inside the DLL appears to work fine. Due to this limitation, I added the ability to do time-intensive things like camera enumeration, camera connection and image acquisition in another thread within the library. Events provide hooks for tracking when these threads end. This leads to code like this:

public Form1()
{
    InitializeComponent();

    lblPath.Text = Application.StartupPath;

    brightnessValues = new List<int />();
    exposureModesList = new Dictionary<string, int>();

    camera = new Camera();
    camera.Connected += new Camera.ConnectionEventHandler(camera_Connected);
    camera.ReceivedFrame += new Camera.ReceivedFrameEventHandler(
        camera_ReceivedFrame);
    camera.DevicesEnumerated += new Camera.DeviceNamesEnumeratedEvent(
        camera_DevicesEnumerated);
    camera.ImageAcquired += new Camera.ImageAcquiredEventHandler(
        camera_ImageAcquired);
}

private void btnConnect_Click(object sender, EventArgs e)
{
    camera.StartSDK();
    camera.GetDevices();
}

private void camera_DevicesEnumerated(object sender, DeviceListEventArgs e)
{
    cboDevices.DataSource = e.DeviceNames;
}

In this code, the GetDevices call returns right away, and the list of devices connected is passed to the camera_DevicesEnumerated delegate function. Custom event args are provided for connection, recieving of a frame (which is the preview) and acquiring an image.

Points of Interest

Getting this to work with both SDKs was interesting, mostly due to bugs in the newer SDK. I also tested under Vista, and found the PRSDK doesn't work under Vista (at least it didn't for me). The older SDK works with Vista. I have found that a lot of issues I had, were caused by calling APIs that are broken in the PRSDK, which would kill the SDK for other things. However, I couldn't get the PRSDK to connect in Vista, with either my commercial app, or the demo that comes with this sample (the demo was in general more reliable, as it does less, it never breaks the SDK ).

Community involvement

This wrapper has had input from two people (the article authors), and is to be considered a work in progress. I'd love to spend some time making more of the properties typesafe, for example. So, if you use it, and you find that you improve it, let us know so we can keep improving the wrapper for the benefit of all who use it.

History

  • Released version 1.0

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Authors

Christian Graus
Software Developer (Senior)
Australia Australia
Member
Programming computers ( self taught ) since about 1984 when I bought my first Apple ][. Was working on a GUI library to interface Win32 to Python, and writing graphics filters in my spare time, and then building n-tiered apps using asp, atl and asp.net in my job at Dytech. After 4 years there, I've started working from home, at first for Code Project and now for a vet telemedicine company. I owned part of a company that sells client education software in the vet market, but we sold that and now I work for the new owners.

Benjamin Liedblad
Software Developer (Senior)
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionI'm getting an erorr after adding the CDSDK.dll file error: CDStartsSDK C000060 what is that ?memberchocolade2 May '13 - 10:38 
QuestionPRSDK FocusmemberMember 912459425 Oct '12 - 1:25 
AnswerRe: PRSDK FocusmvpChristian Graus25 Oct '12 - 7:43 
GeneralRe: PRSDK FocusmemberMember 912459425 Oct '12 - 22:13 
GeneralRe: PRSDK Focusmemberweltklasse14 Feb '13 - 6:16 
GeneralRe: PRSDK FocusmvpChristian Graus14 Feb '13 - 7:37 
GeneralRe: PRSDK Focusmemberweltklasse14 Feb '13 - 7:53 
QuestionIssue with multiple camerasmemberRyan Emmett20 Aug '12 - 8:08 
AnswerRe: Issue with multiple camerasmvpChristian Graus20 Aug '12 - 8:17 
GeneralRe: Issue with multiple cameras [modified]memberRyan Emmett20 Aug '12 - 9:36 
QuestionWPF Image controlmemberJonatas Simoes29 Aug '11 - 15:20 
AnswerRe: WPF Image controlmvpChristian Graus20 Aug '12 - 8:17 
QuestionUnable to load DLL 'PRSDK.dll'memberGerry Golla8 Aug '11 - 17:45 
AnswerRe: Unable to load DLL 'PRSDK.dll'memberkafloom12 Apr '12 - 3:23 
Questionuse CDSDKmemberJonatas Simoes30 Jun '11 - 15:30 
QuestionUsing Canon SDK to build camera controls in Microsoft Access 2010memberDan Slater27 Jun '11 - 9:41 
QuestionAdvanced settings, for example focus point and exposure compensation [modified]membergalaxc5 Apr '11 - 0:25 
QuestionExplicit License?memberPaul de la Warr12 Jan '11 - 22:24 
QuestionList of available Av Settingsmemberthlibby24 Sep '10 - 5:23 
GeneralCDSDK 7.3memberMember 48506917 Jun '10 - 21:03 
GeneralRe: CDSDK 7.3mvpChristian Graus24 Aug '10 - 23:31 
AnswerRe: CDSDK 7.3memberBenjamin Liedblad25 Aug '10 - 6:05 
GeneralCanon Wrapper on Vista VS 2008memberMember 48506917 Jun '10 - 21:00 
GeneralRe: Canon Wrapper on Vista VS 2008mvpChristian Graus24 Aug '10 - 23:32 
GeneralDelay after requesting releasememberpiusott27 Apr '10 - 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130513.1 | Last Updated 18 May 2007
Article Copyright 2007 by Christian Graus, Benjamin Liedblad
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid