This article shares the use of .Net to play SLR
Background
I haven’t visited the garden for more than a year. I changed the industry circle and felt that I was too busy. Yes, but it is also rewarding to be exposed to different R&D cultures, such as the technical flow in the gaming circle, the business flow in the e-commerce circle, the artistic flow in the media circle, etc.
The background of this application is to automate SLR cameras. The boss himself wants to do programming for the usb interface, but it is too low-level technology to usec#It’s not very appropriate to do it. After haggling for a while, let’s do it for the SLR.
Assume a scenario where we need N SLR devices to aim at a flower, take a photo every 30 seconds and automatically post it to Weibo.
Technical Points
Canon SDK
WIA Standard
Canon SDK provides dll. NET developers quoted that Canon's corresponding camera models can be easily accessed by calling the SDK, but the .NET version of the SDK does not provide access to the data in the camera. So how to obtain the data in the SLR camera becomes a problem. Some students may be confused. If the SLR camera is connected to the USB port of the computer, a drive letter will be generated. Can't it be enough to directly use DriveInfo.GetDrives() to obtain the drive letter traversal? Let me educate you first. The classification of USB slave devices can be obtained from the bInterfaceClass byte corresponding to the USB device interface descriptor. Typical codes for bInterfaceClass are 1, 2, 3, 6, 7, 8, 9, 10, 11, 255. The respective meanings are 1-audio: indicating an audio device. 2-communication device: communication equipment, such as telephone, moden, etc. 3-HID: Human-computer interaction device, such as keyboard, mouse, etc. 6-image imaging equipment, such as scanners, cameras, etc. Sometimes digital cameras can also be classified into this category. 7-Printer class. Such as one-way, two-way printers, etc. 8-mass storage mass storage class. Everything with certain storage capabilities can be classified into this category. For example, most digital cameras fall into this category. 9-hub class. 11-chip card/smart card. 255-vendor specific. Manufacturer’s custom class, mainly used for some special equipment. Such as interface adapter card, etc.
The device types that our driveinfo can capture are
public enum DriveType { // Summary: // The type of drive is unknown. Unknown = 0, // // Summary: // The drive does not have a root directory. NoRootDirectory = 1, // // Summary: // The drive is a removable storage device, such as a floppy disk drive or a // USB flash drive. Removable = 2, // // Summary: // The drive is a fixed disk. Fixed = 3, // // Summary: // The drive is a network drive. Network = 4, // // Summary: // The drive is an optical disc device, such as a CD or DVD-ROM. CDRom = 5, // // Summary: // The drive is a RAM disk. Ram = 6, }
api methods for portable devices. Interested students can try
Here I choose wia interface programming. WIA is the abbreviation of Windows Image Acquisition. The currently available version is WIA 1.0, which is a digital image acquisition service provided in Windows Millennium Edition (Windows Me) or higher versions of Windows systems. It can also be used For managing digital imaging equipment. WIA is a COM component implemented using out-of-process services. Unlike most out-of-process service programs, WIA avoids performance loss during image data transfer by providing its own data transfer mechanism (IWiaDataTransfer interface). . The high-performance IWiaDataTransfer interface uses shared memory to transfer data to client programs.WIA has three main components: Device Manager, Minidriver Service Library and Device Minidriver. ◆Device Manager: Enumerate image devices, obtain device attributes, create events
and create device
objects for the device; ◆Minidriver Service Library: Execute all device-independent functions Service; ◆Device Minidriver Explanation Mapping: WIA Attributes
and commands to specific devices.
Through the information in DeviceManagerClass().DeviceInfos, we can collect the device information belonging to CameraDeviceType in the SLR. As for
video and other types, there are other similar methods.
public void DownJpgFromAllCamera() { int i = 1; foreach (IDeviceInfo DevInfo in new DeviceManagerClass().DeviceInfos) { if (DevInfo.Type == WiaDeviceType.CameraDeviceType) { string DeviceID = DevInfo.DeviceID; Device wDevice = DevInfo.Connect(); Devparam dev = new Devparam {wiaDevice=wDevice, DeviceID = DeviceID, index = i }; new Thread((Camera) => { DownJpg(((Devparam)Camera).wiaDevice, ((Devparam)Camera).DeviceID, ((Devparam)Camera).index); } ).Start(dev); i++; } } }
Let’s talk about the SDK. Canon sdk .net version provides 5 types of handle delegation
public delegate uint EdsProgressCallback( uint inPercent, IntPtr inContext, ref bool outCancel); public delegate uint EdsCameraAddedHandler(IntPtr inContext); public delegate uint EdsPropertyEventHandler(uint inEvent, uint inPropertyId, uint inParam, IntPtr inContext); public delegate uint EdsObjectEventHandler( uint inEvent, IntPtr inRef, IntPtr inContext); public delegate uint EdsStateEventHandler( uint inEvent, uint inParameter, IntPtr inContext);
The first one is used for data processing such as data copying, picture saving, etc.
The third one is used for notification of changes in the status of attributes such as data streams in the camera, such as a series of changes caused by taking pictures
The fourth one is used for file operations such as file creation, deletion, etc.
The fifth one is used for the status time of the camera itself, such as abnormal power on and off, etc.
Please refer to the demo program for various application scenarios. Although the load method turns on multi-threading, the hard disk IO itself is serial. Here is just It says that you don’t need to take it seriously
Rendering
Newly added camera equipment
Program controlled camera to take pictures
Load in-camera photo data
The above is the detailed content of .Net tips for playing SLR. For more information, please follow other related articles on the PHP Chinese website!