从 Windows C# Canon SDK 拍摄图片与 PTP 或 MTP
我希望获得一些关于实现看似简单的目标的一般指导。我有一台 DSLR 相机(Canon EOS 50D),需要编写一个应用程序来告诉相机拍照。我还需要将照片传输到计算机,并可能将其从相机的存储中删除。一个好处是可以在我的应用程序中从相机获得实时预览。我的环境是 Windows(XP Pro 或 Vista Enterprise)和 .Net 3.5 (C#)。
我做了一些研究并找到了几个选择。我知道一个可以用,但限制我将来只能使用佳能相机。我从 Canon 找到并下载了一个 SDK,它提供了很多此类功能。我查看了 SDK,虽然它内容广泛并且是用 C 语言编写的,但它确实具有 C# 包装器,可以稍微加快开发速度。
我发现的另一个选项称为“Windows 便携式设备”。显然,它是一个可以与实现 PTP 和 MTP 标准的设备通信的 API。它是基于 COM 的,据我所知它没有 .Net 包装器。然而,这并不是一个阻碍。我可以 P/Invoke 我需要的功能,或者编写一个托管 C++ DLL 以在我的应用程序中使用来与相机对话。
我正在寻找有 WPD 经验的人给我指点。我仔细阅读了文档并看到了有关传输图像和删除图像的参考。然而,我还没有看到提及拍照、获取预览图像或对焦/自动对焦的命令。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
WPD api 提供命令 WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE
我不确定您的相机是否支持它,但它应该足够简单才能找到。如果您可以从驱动程序开发套件中获取“wpdinfo”工具并在连接相机的情况下启动它,然后向其发送 WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS 命令并查看它是否支持静态图像捕获命令。如果是的话你可以尝试一下。
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.
TallGanglyGuy 的评论不正确。 ptp 确实允许您触发新图像并更改曝光等。某些相机的固件仅公开某些 ptp 命令。
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.
尝试我的 Eos 框架:https://github.com/esskar/Canon.Eos.Framework
恕我直言,它是比 SDK 附带的 .cs 文件更好的替代方案。
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.
PTP 和 MTP 都是用于从数码相机 (DSC) 传输文件的协议。这些协议不提供触发新图像或设置曝光控制的功能。您将无法使用相机特定的 SDK。如果您需要多个供应商支持,尼康有一个 SDK,可以为其相机提供与佳能 SDK 类似的支持。
有关 PTP 和 MTP 的更多信息可在此处找到:
http://en.wikipedia.org/wiki/Picture_Transfer_Protocol
和
http://en.wikipedia.org/wiki/Media_Transfer_Protocol
编辑
我忘了提及 WIA 可能是您可能会感兴趣,假设您的相机驱动程序提供了 WIA 接口。
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.
这确实很通用,但可能会有所帮助。
我必须编写一个应用程序,使用来自两个不同供应商的两个不同的条形码扫描仪和不同的 SDK。我创建了一个接口,定义了我想要为其编码的方法和事件,然后编写了实现我的接口的适配器类。
这对我来说效果很好,从一种到另一种的切换非常无缝。如果您采用相同的方法,您就不会完全依赖一个 SDK。
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.