Snapping pictures from Windows C# Canon SDK vs PTP or MTP
Asked Answered
L

5

8

I am hoping to receive some general guidance on accomplishing a seemingly simple goal. I have a DSLR camera (Canon EOS 50D) and need to write an application that will tell the camera to take a picture. I also need to transfer the picture to the computer and possibly delete it from the camera's storage. A bonus would be to get a live preview from the camera in my application. My environment will be Windows (either XP Pro or Vista Enterprise) and .Net 3.5 (C#).

I have done some research and found a couple of options. One I know will work, but limits me to using only Canon cameras in the future. I have found and downloaded an SDK from Canon that provides a lot of this functionality. I've looked over the SDK and while it's extensive and written in C it does have C# wrappers that will speed up development a bit.

Another option I've found is called Windows Portable Devices. Apparently, it is an API that will talk to devices that implement PTP and MTP standards. It is COM based and as far as I can tell it has no .Net wrappers. This is not however a show stopper. I could P/Invoke the functionality I need or write a Managed C++ DLL to use in my application to talk to the camera.

I am looking for anyone with experience with WPD to give me pointers. I've perused the documentation and seen references to transferring images and deleting images. I have not, however, seen mention of commands to take a picture, get a preview image, or say focus/auto-focus.

Lederman answered 10/11, 2009 at 18:59 Comment(4)
I'm interested in seeing the answer to this question. Personally, if I'm just writing the app for myself, I'd try out the Canon SDK first. Besides, if you already have a set of Canon lenses, you'll probably be sticking with Canon in the future :-).Covariance
This sounds like it would be a great CodePlex project. I've got a Rebel XTi and this sounds like a fun concept to work on. If you decide to start a CodePlex project, definitely let me know!Covariance
Work continues on a C++/CLI wrapper for the Canon SDK. It has been a real challenge. I do not think I would be able to release a CodePlex project because I will not have rights to the code. Sorry. I'd love to have more latitude in this regard.Lederman
Wish I could. It's been a long time and that code is wrapped up in my former employers Intellectual Property. I ended up using the Canon SDK and wrapping the C code with C# P/Invoke classes. It was fairly challenging. The Canon SDK was pretty cryptic and IMO far too tied directly to MTP. What I really wanted was a library to just say, "take a picture" or "give me the live screen preview". At the time that was hard to come by. Since then, I've learned there is a library on Linux that will do that, alas I haven't worked with it and don't know it's name.Lederman
H
3

The WPD api provides the command WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE

I am not sure whether your camera supports it but it should be simple enough to find out. If you can get the "wpdinfo" tool from the driver development kit and start it with your camera connected then send it a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS command and see if it supports the still image capture command. IF so then you could give that a try.

Henton answered 22/1, 2010 at 12:7 Comment(2)
Thanks! This is exactly what I was looking for. Haven't tried it yet, but will once I get the chance. Currently I'm using the Canon SDK. It has its issues, not to mention it only works with Canon EOS cameras...Lederman
I ended up trying this out. Unfortunately it wasn't supported by my EOS 50D. If I ever have another camera to try it out with I will. I've emailed microsoft WPD devs (using the WPD blog) for a list of manufacturers that support various WPD commands, but they don't have such a list. They were, however very helpful in figuring out how I should use WPD.Lederman
M
3

The comment from TallGanglyGuy is incorrect. ptp does allow you to trigger new images and change exposure, etc. Some cameras have firmware that only exposes some of the ptp commands.

PTP supports common device controls, such as taking a picture, so that the user could take advantage of the PC/camera combination in new and different ways again, without requiring additional software.

Maclay answered 15/8, 2011 at 22:37 Comment(0)
C
2

try my Eos Framework: https://github.com/esskar/Canon.Eos.Framework

IMHO it's a better alternative then the .cs file that comes with the SDK.

Colorimeter answered 6/2, 2012 at 20:52 Comment(0)
S
1

PTP and MTP are both protocols for transferring files from a digital still camera (DSC). The protocols provide no functionality for triggering new images, or setting exposure control. You will be stuck using the camera specific SDK. If you want multiple vendor support Nikon has an SDK that provides similar support as the Canon SDK for their cameras.

More info on PTP and MTP can be found here: http://en.wikipedia.org/wiki/Picture_Transfer_Protocol and http://en.wikipedia.org/wiki/Media_Transfer_Protocol

EDIT

I forgot to mention that WIA may be interesting to you, assuming your camera's driver provides a WIA interface.

Supersedure answered 10/11, 2009 at 23:24 Comment(1)
I looked at WIA, which has been superseded by Windows Portable Devices. While I'm not sure if PTP or MTP includes this functionality (taking pictures), I did see information in WPD that alludes that it may. At any rate, WPD is supposed to (see below), which is what I was considering using with this app. I've since decided to use the SDK and possibly explore WPD at a later time. "Applications that are built on WPD can explore a device, send and receive content, and even control the device, for example, take a picture..." msdn.microsoft.com/en-us/library/dd388998%28VS.85%29.aspxLederman
T
0

This is really generic, but it may help.

I had to write an application that used two different bar code scanners from two different vendors with different SDK's. I created an interface that defined the methods and events that I wanted to code for, and then wrote adapter classes that implemented my interface.

This worked well in my case, and switching from one to the other was pretty seamless. If you took the same approach, you wouldn't be totally dependent upon one SDK.

Theology answered 13/11, 2009 at 2:15 Comment(1)
Yes, an interface is a given. I can easily create a base class or interface with generic methods and implemented as needed. While this is useful, having a single SDK for many camera brands would take less work. Thanks.Lederman

© 2022 - 2024 — McMap. All rights reserved.