Blog

Dogoozx explains for you: How do USB cameras complete shooting?

Cameras are divided into two categories: digital cameras and analog cameras. Digital cameras can convert analog video signals generated by video acquisition devices into digital signals, and then store them in computers. The video signals captured by analog cameras must be converted into digital modes by a specific video capture card, and then compressed before they can be converted to computers for use. Digital cameras can directly capture images and then transmit them to computers through serial, parallel or USB interfaces. Currently, the cameras on the computer market are mainly digital cameras, and the digital cameras are mainly USB digital cameras that use new data transmission interfaces. Most of the products currently available on the market are of this type. In addition, there is a product that works with video capture cards, but it is not yet mainstream. Due to the rapid popularization of personal computers and the high overall cost of analog cameras, the transmission speed of the USB interface is much higher than that of the serial and parallel ports. Therefore, the current market hotspot is mainly digital cameras with USB interfaces. The following mainly refers to digital cameras with USB interfaces.

The main structure and components of the camera module:

1. Lens (LENS)

Lens structure, composed of several lenses, plastic lens (plastic) or glass lens (glass).

2. Image sensor (SENSOR)

It can be divided into two categories:

CCD: Charge coupled device

CMOS: Complementary metal oxide semiconductor

Camera

3. Digital signal processing chip (DSP)

There are many DSP manufacturers, and the more popular ones on the market are: VIMICRO (VIS) 301P/L, SONIX (Songhan) 102/120/128, ST (Logitech LOGITECH’s DSP provider), SUNPLUS (SUN+ focuses on the development of single-chip CIF and VGA, but the image quality is average), PIXART (Original Phase) PAC207 single-chip CIF, SQ (Yiqiang) SQ930C, etc.

4. Power supply

The camera requires two operating voltages: 3.3V and 2.5V, and the latest process chips use 1.8V.

Technical indicators:

1. Image resolution/resolution

●SXGA (1280×1024) is also known as 1.3 million pixels
●XGA (1024×768) is also known as 800,000 pixels
●SVGA (800×600) is also known as 500,000 pixels
●VGA (640×480) is also known as 300,000 pixels (350,000 refers to 648X488)
●CIF (352×288) is also known as 100,000 pixels
●SIF/QVGA (320×240)
●QCIF (176×144)
●QSIF/QQVGA (160×120)

2. Image format (imageFormat/Colorspace)

RGB24, 420 are the two most commonly used image formats at present.
●RGB24: Indicates 8 bits for each of the three colors R, G, and B, which can represent up to 256 levels of light and dark, thus reproducing 256*256*256 colors.

●I420: One of the YUV formats.

●Other formats include: RGB565, RGB444, YUV4:2:2, etc.

3. Automatic white balance adjustment (AWB)

Definition: It is required that the image on the screen should also be white when a white object is illuminated under different color temperature environments. Color temperature indicates the spectral components and the color of light. Low color temperature indicates more long-wave light components. When the color temperature changes, the ratio of the three primary colors (red, green, and blue) in the light source will change. The ratio of the three primary colors needs to be adjusted to achieve color balance. This is the actual white balance adjustment.

4. Image compression method

JPEG: (joint photography expert group) static image compression method. A lossy image compression method. The larger the compression ratio, the worse the image quality. This format can be selected when the image accuracy requirement is not high and the storage space is limited. At present, most digital cameras use JPEG format.

5. Color depth (color bit number)

Reflects the ability to recognize colors and the ability to express colors in images. It is actually the quantization accuracy of the A/D converter, which refers to how many levels the signal is divided into. It is usually expressed in color bit numbers (bit). The higher the color depth, the more vivid and moving the image color will be. Cameras on the market now have reached 24 bits, and some even 32 bits

6. Image noise

Refers to the noise interference in the image. It is manifested as fixed color noise in the image.

7. Viewing angle

It is a complementary principle with the imaging of human eyes. Simply put, it is the imaging range.

8. Output/input interface

Serial interface (RS232/422): slow transmission rate, 115kbit/s

Parallel interface (PP): the rate can reach 1Mbit/s

Infrared interface (IrDA): the rate is also 115kbit/s, and general laptops have this interface

Universal serial bus USB: plug-and-play interface standard, supports hot plugging. USB1.1 can reach 12Mbit/s, USB2.0 can reach 480Mbit/s

IEEE1394 (FireWire) interface (also known as ilink): its transmission rate can reach 100M~400Mbit/s

As a common camera interface, what are the advantages of USB interface?

USB interface (Universal Serial Bus) is a standard interface for connecting computers and other electronic devices. Since its first introduction in 1996, USB interface has become the preferred connection method between many devices, including computers, mobile phones, digital cameras, printers and other devices. This interface has the characteristics of high speed, reliability, simplicity and strong compatibility, making it the preferred connection method between modern electronic devices.

The main advantages of USB interface are its versatility and portability. Through the USB interface, users can easily connect various devices to the computer, and also transfer data between different devices. In addition, the USB interface can also provide power to the device, so that the device can work normally without a separate external power supply.

There are many versions of USB interface, including USB 1.0, USB 2.0, USB 3.0 and USB 3.1. As technology develops, the speed and functionality of USB interfaces are also constantly improving. For example, the USB 3.1 interface can provide faster data transmission speeds, thus meeting users’ needs for high-speed data transmission.

How do USB cameras work?

USB cameras contain an image sensor inside, usually of CMOS or CCD type, whose main function is to convert the captured light into electrical signals. Before these electrical signals are further processed, they need to go through the analog-to-digital conversion (A/D conversion) process to convert them from analog signals to digital signals. After the conversion is completed, these digital signals are transmitted to the computer through the USB interface.

On the computer side, the corresponding driver is responsible for receiving these digital signals and parsing them. The parsed data will be converted into an image format and then displayed on the screen. This conversion process allows users to view the images captured by the camera in real time.

In addition, USB cameras have a variety of resolution and frame rate options, which users can adjust according to their needs. The resolution determines the clarity of the image, while the frame rate determines the smoothness of the image. By adjusting these parameters, users can get better performance while ensuring image quality.

Image acquisition using VC++:

There are many ways to perform image acquisition in VC++, the most common of which is to use Windows API functions or third-party libraries. This article will take the DirectShow library as an example to describe in detail how to use VC++ to implement image acquisition of USB cameras.
First, we need to create a DirectShow capture filter GraphBuilder, which is an important component in the DirectShow library for building and processing filter graphs for multimedia streams. In GraphBuilder, we can add various filters, such as video capture devices (USB cameras) and a frame rate control filter. These filters are connected by connecting lines to form a complete filter graph.
Next, we need to add the video capture device (USB camera) as a capture filter. In GraphBuilder, we can use ICreateDevEnum and IMoniker interfaces to find and select a suitable video capture device. After finding the device, we need to create an ICaptureGraphBuilder2 interface instance and call its AddSourceFilter method to add the selected video capture device to the filter graph.
In addition to the video capture device, we also need to add a frame rate control filter. In GraphBuilder, we can use the IFileLoader interface to load the frame rate control filter. Then, we need to create an instance of the IMediaControl interface and call its Run method to start the video stream. At runtime, we can extract image data from the captured frame.

In the process of implementing image acquisition, we also need to set capture parameters, such as resolution, frame rate, etc. These parameters can be set through the SetProperties method of the IMediaControl interface. When setting parameters, we need to ensure that the selected parameters are compatible to avoid errors.

Using VC++ and DirectShow library to implement image acquisition of USB cameras is a relatively complex process, but through the above steps, we can successfully implement image acquisition and subsequent processing. In actual operation, we also need to pay attention to handling various abnormal situations to ensure the stable operation of the program.

Photo function implementation:

To implement the photo function of the USB camera, we need to save a frame of image data as a picture file after obtaining it. In VC++, the GDI+ library can be used to complete this task. Convert the captured image data into a GDI+ compatible data format, then create a Bitmap object and load the image data into the Bitmap. Call the Save method of Bitmap, specify the saved file path and format (such as JPEG, PNG, etc.), and the image can be saved to the hard disk.

Implementation process of the camera function:

We need to implement the camera function of the USB camera, which requires saving a frame of image data as a picture file after obtaining it. In VC++, the GDI+ library can be used to complete this task. The specific implementation process is as follows:
1. Convert the captured image data into a GDI+ compatible data format, which ensures that the image data can be correctly processed by the GDI+ library.
2. Create a Bitmap object and load the converted image data into the Bitmap. The Bitmap class is a core class in the GDI+ library for processing bitmap images.
3. Call the Save method of Bitmap, specify the saved file path and format (such as JPEG, PNG, etc.), and the image can be saved to the hard disk. In the Save method, you can set parameters such as image quality and compression ratio to meet different needs.
Through the above steps, we can implement the camera function of the USB camera. The GDI+ library can easily process image data, and at the same time provides a wealth of image processing functions to meet different camera needs. In the implementation process, you need to pay attention to the conversion and saving process of image data to ensure the stability and reliability of the camera function.

Video Saving:

Video saving is a process involving continuous frame capture and encoding. In VC++, we can use the Media Foundation SDK to implement this function. First, we need to create a Media Foundation Transform (MFT) filter, which is responsible for encoding the original image data into a video stream. Next, we need to configure a file output filter, such as ASF Writer, to write the encoded video stream to a file.

When each frame is captured, we first encode it and then pass the encoded data to the ASF Writer. When the preset recording time is reached or the user manually stops recording, we close the output file, and the video saving is completed.

To describe this process in more detail, we can divide it into the following steps:

1. Create and initialize the Media Foundation Transform (MFT) filter: This step involves registering the MFT, creating an MFT instance, and linking it to the corresponding ports of the source and output devices.

2. Configure the file output filter, such as ASF Writer: This step includes creating an ASF Writer instance, setting the path and format of the output file, and allocating storage space for the video stream.

3. Capture each frame and encode it: In this process, we need to capture each frame of the image on the source device, and then use the MFT filter to encode it to get the encoded video stream.

4. Pass the encoded video stream to ASF Writer: After obtaining the encoded video stream, we pass it to the ASF Writer output filter to write it to the file.

5. Close the output file and complete the video saving: When the preset recording time is reached or the user manually stops recording, we close the output file, and the video saving is completed.

Through the above introduction, you will be able to understand the basic working principle of the USB camera and master the skills of image acquisition, photo taking and video saving using VC++. This will not only help you develop your own multimedia applications, but also deepen your understanding of multimedia processing and computer vision technology. In practice, you can also combine other libraries and frameworks, such as OpenCV, to further enhance the ability of image processing and analysis.

 

Leave a Reply

Your email address will not be published. Required fields are marked *