简体   繁体   English

从Windows C#Canon SDK与PTP或MTP对齐图片

[英]Snapping pictures from Windows C# Canon SDK vs PTP or MTP

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. 我有一个数码单反相机(佳能EOS 50D),需要编写一个应用程序,告诉相机拍照。 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#). 我的环境将是Windows(XP Pro或Vista Enterprise)和.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. 我找到并从佳能下载了一个SDK,它提供了很多这方面的功能。 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. 我查看了SDK,虽然它很广泛并且用C语言编写,但它确实有C#包装器,可以加快开发速度。

Another option I've found is called Windows Portable Devices. 我发现的另一个选项叫做Windows便携设备。 Apparently, it is an API that will talk to devices that implement PTP and MTP standards. 显然,它是一个API,可以与实现PTP和MTP标准的设备进行通信。 It is COM based and as far as I can tell it has no .Net wrappers. 它是基于COM的,据我所知,它没有.Net包装器。 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. 我可以P / Invoke我需要的功能或编写托管C ++ DLL在我的应用程序中使用与摄像头通信。

I am looking for anyone with experience with WPD to give me pointers. 我正在寻找有WPD经验的人给我指点。 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. 但是,我没有看到提取照片,获取预览图像或说焦点/自动对焦的命令。

The WPD api provides the command WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE WPD api提供命令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. 如果你可以从驱动程序开发工具包中获取“wpdinfo”工具并在连接相机的情况下启动它,那么发送一个WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS命令并查看它是否支持静止图像捕获命令。 IF so then you could give that a try. 如果那么你可以尝试一下。

PTP and MTP are both protocols for transferring files from a digital still camera (DSC). PTP和MTP都是用于从数码相机(DSC)传输文件的协议。 The protocols provide no functionality for triggering new images, or setting exposure control. 协议不提供触发新图像或设置曝光控制的功能。 You will be stuck using the camera specific SDK. 你将被困在使用相机专用SDK。 If you want multiple vendor support Nikon has an SDK that provides similar support as the Canon SDK for their cameras. 如果您需要多个供应商支持,尼康有一个SDK,可以为其相机提供与Canon SDK类似的支持。

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 有关PTP和MTP的更多信息,请访问: http//en.wikipedia.org/wiki/Picture_Transfer_Protocolhttp://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. 我忘了提到WIA可能对你有意思,假设你的相机的驱动程序提供了一个WIA界面。

The comment from TallGanglyGuy is incorrect. TallGanglyGuy的评论不正确。 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允许您触发新图像并更改曝光等。某些相机的固件仅显示某些ptp命令。

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. PTP支持常见的设备控制,例如拍照,这样用户可以再次以新的和不同的方式利用PC /相机组合,而无需额外的软件。

try my Eos Framework: https://github.com/esskar/Canon.Eos.Framework 试试我的Eos框架: https//github.com/esskar/Canon.Eos.Framework

IMHO it's a better alternative then the .cs file that comes with the SDK. 恕我直言,它是一个比SDK附带的.cs文件更好的选择。

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. 我不得不编写一个应用程序,它使用来自两个不同供应商的两个不同条形码扫描器,使用不同的SDK。 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. 如果采用相同的方法,则不会完全依赖于一个SDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM