search
.Net tips for playing SLRMar 12, 2017 pm 02:04 PM
.net

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,
    }


## Generally, USB disk devices are Removable, but SLR cameras are PortableDevices, and this type cannot be obtained using the GetDrives method. Windows systems32 provides a series of

api methods for portable devices. Interested students can try

.Net 玩单反的技巧

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.

Second for PC to discover new camera devices

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

.Net 玩单反的技巧

Program controlled camera to take pictures

.Net 玩单反的技巧

Load in-camera photo data

.Net 玩单反的技巧


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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to use char array in C languageHow to use char array in C languageApr 03, 2025 pm 03:24 PM

The char array stores character sequences in C language and is declared as char array_name[size]. The access element is passed through the subscript operator, and the element ends with the null terminator '\0', which represents the end point of the string. The C language provides a variety of string manipulation functions, such as strlen(), strcpy(), strcat() and strcmp().

How to use various symbols in C languageHow to use various symbols in C languageApr 03, 2025 pm 04:48 PM

The usage methods of symbols in C language cover arithmetic, assignment, conditions, logic, bit operators, etc. Arithmetic operators are used for basic mathematical operations, assignment operators are used for assignment and addition, subtraction, multiplication and division assignment, condition operators are used for different operations according to conditions, logical operators are used for logical operations, bit operators are used for bit-level operations, and special constants are used to represent null pointers, end-of-file markers, and non-numeric values.

What is the role of char in C stringsWhat is the role of char in C stringsApr 03, 2025 pm 03:15 PM

In C, the char type is used in strings: 1. Store a single character; 2. Use an array to represent a string and end with a null terminator; 3. Operate through a string operation function; 4. Read or output a string from the keyboard.

How to handle special characters in C languageHow to handle special characters in C languageApr 03, 2025 pm 03:18 PM

In C language, special characters are processed through escape sequences, such as: \n represents line breaks. \t means tab character. Use escape sequences or character constants to represent special characters, such as char c = '\n'. Note that the backslash needs to be escaped twice. Different platforms and compilers may have different escape sequences, please consult the documentation.

How to convert char in C languageHow to convert char in C languageApr 03, 2025 pm 03:21 PM

In C language, char type conversion can be directly converted to another type by: casting: using casting characters. Automatic type conversion: When one type of data can accommodate another type of value, the compiler automatically converts it.

Avoid errors caused by default in C switch statementsAvoid errors caused by default in C switch statementsApr 03, 2025 pm 03:45 PM

A strategy to avoid errors caused by default in C switch statements: use enums instead of constants, limiting the value of the case statement to a valid member of the enum. Use fallthrough in the last case statement to let the program continue to execute the following code. For switch statements without fallthrough, always add a default statement for error handling or provide default behavior.

What is the function of C language sum?What is the function of C language sum?Apr 03, 2025 pm 02:21 PM

There is no built-in sum function in C language, so it needs to be written by yourself. Sum can be achieved by traversing the array and accumulating elements: Loop version: Sum is calculated using for loop and array length. Pointer version: Use pointers to point to array elements, and efficient summing is achieved through self-increment pointers. Dynamically allocate array version: Dynamically allocate arrays and manage memory yourself, ensuring that allocated memory is freed to prevent memory leaks.

The difference between multithreading and asynchronous c#The difference between multithreading and asynchronous c#Apr 03, 2025 pm 02:57 PM

The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.