Showing posts with label eos. Show all posts
Showing posts with label eos. Show all posts

Tuesday, January 22, 2008

Programming with the Canon Digital Camera Part 2

I got my Canon EOS Digital Software Development Kit (ED-SDK 2.1) back in December but have not gotten much time to experiment with it. I wrote some quick-and-dirty program today just to test out the different SDK function calls. I opted to test with my Canon EOS 400D instead of the Digital IXUS 400 primarily because the EOS Development Kit (EDK) already came with a C-Sharp wrapper called EDSDK.cs. So I didn't have to download some other 3rd party library wrapper just to integrate with the CD-SDK.

The C Sharp wrapper bundled with the EDK is pretty basic. In fact, I would not really call it a class in the OOP sense. Its more of like a traditional C struct. It enumerates all the different constants and data structures supported by the EDK, which is a big help since I would not want to re-type that. The development library can be either statically linked through the provided EDSDK.lib file, or by dynamic linking by referring to the EDSDK.dll. The C Sharp class file uses the latter method (since I don't think there is any way of linking directly to a .lib file with C#). The EDSDK.cs wrapper file provides the convenient function prototypes already also.

The program flow is very straightforward. You call EdsInitializeSDK() to startup the library and EdsTerminateSDK() to shut it down. Then in-between that's where you do all the neat stuffs -- like query the camera for its properties and settings; modify the settings; take a picture; go through the camera's storage system and retrieve images. The EDK pretty much lets you change all the settings that can be modified -- the ISO speed, AE mode, aperture, shutter speed, JPEG quality/compression level, and so much more. Anything that you can set using the camera's LCD menu, can be programmatically set as well. The EDK provides you with functions to lock the User Interface so that while the application is in control of the camera, it cannot be manually overridden by a human operator.

I think in theory you can connect multiple cameras to a PC via the provided USB cable and control them from a single application (this setup of EOS cameras is pretty amazing). The EDK just mentions some notes about concurrency issues that might cause problems. In any case, I have no plans of attaching more than one camera so that should not be an issue. The SDK does provide you with functions to list the cameras attached, or are available, and lets you select which one you want to work with. Once you've selected your camera, you would open a session with it by calling EdsOpenSession(). Then you would use the EdsSendCommand() mainly to do everything else like doing a remote capture.

I've gotten as far as the following:
  1. Initialize the SDK
  2. Enumerate the cameras attached and select the 1st one (my EOS 400D in this case)
  3. Open a session with the camera
  4. Retrieve its settings and properties
  5. Perform a remote capture (aka. Take a Picture)
  6. Close the camera session
  7. Terminate the SDK

The images taken by step 5 currently remains on the camera. I have to do more experimentation next time on how to do image transfers from the camera to the PC. Of course, the SDK provides all of those functions as well. Its just a matter of figuring out how to use them correctly. I will need to define postback functions for sure. For now, I'm purely doing synchronous programming. However, the programming model that the Canon EDK uses is asynchronous and postback-based.

Friday, December 21, 2007

Programming with the Canon IXUS and EOS Digital Camera

I recently came across a business model which I thought was very interesting. Its essentially a mobile photo studio (or a photo booth) that can be setup easily in events or venues such as birthday parties, event launchings, weddings and many more. They basically charge a fixed fee (anywhere from P10k to P20k) for a finite number of hours (2 to 5 hrs). During that period, the event/party guests can ham it up in front of the camera and they get free souvenir prints.

In the event that I first saw this setup, I took a peek inside the contraption and saw a Canon EOS 20D. Aha! There must be a way to programmatically control a camera from a PC; retrieve the still images that it captures; lay it out in a memory bitmap; then dump it out to a photo printer. Sounds like an interesting project!

So I Googled around to know what tools are out there. First, I found an open-source project in Sourceforge under the GNU General Public License (GPL):

http://canoncam.sourceforge.net/

It seems to be a bunch of command-line utilities which can control a Canon digital camera. However, in order to use it, one has to have the Canon RC SDK. Hmm.... what could that be? Doing more Google searches, I found out that Canon offers the SDK to allow application developers to talk to their camera. Best of all, its for free! One just has to go through the application process:

http://www.canon-asia.com/index.jsp?fuseaction=dev_prog&prod_type=digital_imaging

So I diligently filled up the forms. I figure I would need the standard Canon Digital Camera Software Development Kit (CD-SDK 7.3.0) to support the older Powershot and IXUS lines, and the newer Canon EOS Digital Software Development Kit (ED-SDK 2.1) for the digital SLR lines. My old IXUS 400 (aka Powershot SD400) is supported by the older CD-SDK, while my EOS 400D (aka Digital Rebel XTi) would be supported by the newer ED-SDK.

Based on the website, the libraries are written in Windows C. But some guys seem to have made a C# wrapper around it.

  1. Elias Torres made a C# wrapper around the CD-SDK. But it seems very dated. And for sure, it does not support the newer ED-SDK.
  2. Christian Graus and Benjamin Liedblad came out with a unified version for the CDSDK and PRSDK (a newer version of the CDSDK), but also no mention of the ED-SDK.

Well, my CD from Canon Singapore arrived the other day (after about a 3-week wait). I tried plugging in my old IXUS 400 to my PC. Couldn't seem to get the CD-SDK sample programs to detect it. I wonder if its because I did not really install the entire drivers CD of the IXUS 400. My PC only has the drivers/programs installed from my EOS 400D camera. This will take some more tests.

On the bright side, I found out that the EDSDK came shipped with a C# class file! There's no documentation whatsoever, but it doesn't seem too difficult to figure out since its basically just a class that defines entry points to the EDSDK.DLL. I think I'll focus my development on the EDSDK and forget about the older CDSDK. Of course, this means that whatever application I develop will have to use an EOS Digital Camera and not a lower-end IXUS. Will update this blog more as I find out more also about the EDSDK.