0 Introduction
At present, image acquisition devices with CCD technology as the core can be divided into two categories:
1) An image acquisition system consisting of a CCD camera, an image acquisition card and a computer. The image acquisition card is used to convert the analog image signal from the CCD into a digital image signal and transmit it to the computer for processing;
2) The digitization device of the CCD camera itself directly transmits the digital image signal to the computer through the port.
The former, as a classic image acquisition system, has always been in a dominant position in image acquisition applications [1]. However, acquisition cards with better performance are expensive. At the same time, due to different requirements, acquisition cards often need to be redeveloped. Most acquisition card manufacturers encapsulate their own functions and link libraries, so the secondary development requires high professional quality of developers. In recent years, with the continuous advancement of CCD camera technology, the second type of image acquisition devices represented by digital cameras have attracted widespread attention for their convenience, fast acquisition speed, high resolution, and high cost performance, and have been well applied in some fields.
For the second type of image acquisition devices, since the CCD camera directly provides digital signals, high-quality images can be obtained, but at the same time, higher requirements are placed on the transmission rate of image data. Generally, CCD output can follow digital output interface standards such as RS-422, RS-644 and IEEE1394. Among them, the data transmission rate of RS-422 is relatively low and cannot meet the requirements of large-scale image data transmission; and when RS-644 is transmitting data, an image acquisition card must be added, which increases the cost of the entire system. IEEE1394 can not only provide a high-speed data rate to overcome the disadvantage of the low data transmission rate of RS-422, but also does not require an external image acquisition card when connected to the CCD [2].
IEEE1394, also known as FireWire, is a high-speed serial bus standard released by Apple in 1987. The standard was adopted by the Institute of Electrical and Electronics Engineers (IEEE) in 1995 and was called IEEE1394. The data transmission rate of IEEE1394-1995 in 1995 was 100/200/400Mbps. Later, its improved version IEEE1394b had a data transmission rate of 800Mbps, 1.6Gbps and 3.2Gbps. Therefore, the IEEE1394 bus is the fastest serial bus to date [3]. The IEEE1394 bus has the following characteristics: (1) Digital interface: data is transmitted in digital form without the need for digital-to-analog conversion, thereby reducing the complexity of the device and ensuring the quality of the signal; (2) Plug and play; (3) Fast speed, supporting both synchronous and asynchronous data transmission modes; (4) Small physical size, low manufacturing cost, and easy installation; (5) Low price. Based on these characteristics, 1394 is widely used in the multimedia field, especially in digital cameras.
At present, the most common subject is the programming control of image acquisition cards, while there is little introduction to the programming methods of using the second type of image acquisition devices for image acquisition. Therefore, this article focuses on the programming process of using the second type of image acquisition devices based on the 1394 interface for image acquisition under the VC++ platform.
1 Hardware composition and development platform of image acquisition system
The hardware components of the image acquisition in this article are: industrial digital camera, 1394b card and PC. Install the 1394b card required by the system in the empty PCI slot of the PC host, connect the camera to the PC through the 1394 interface and install the driver, so that the hardware environment required by this system is completed.
The system platform used is Windows 2000, and the development environment is Microsoft VC++6.0.
2 Implementation of Image Acquisition
The writing of the image acquisition system mainly includes: human-computer interaction interface, receiving and saving image signals from the CCD camera, displaying the image on the acquisition interface, and controlling the camera. The following will explain them one by one.
2.1 Establishing the collection interface
For the collection interface, it can be created in the form of a dialog box or in a document structure. This article uses the latter:
1) Generate an MFC AppWizard (exe) multi-document application framework (application name: PictureTest).
2) Connect the dynamic link library of the camera (because you need to control the camera to capture images, you will use the camera's library functions). Find the directory file where the camera is installed, add the file path of the include folder to the edit box of Project->Setting->C/C++->;preprocessor->Additional include directories; add the file path of the lib folder to the edit box of Project->Setting->Link->Input->Additional library path, and enter pgrflycapture.lib pgrflycapturegui.lib in the edit box of ...->Input->Object/library modules.
3) Include the header file of the camera control class and add the header file to the CPictureTestDoc.h file in the project:
#include
#include
And define the shared variables:
FlyCaptureContext context; //Camera function
handleCameraGUIContext m_guicontext; //Graphical user interface (GUI) handle
4) When using the camera to capture images, it must first be initialized. We hope that this part of the work will be completed by the system itself when the application is opened. Initialize the camera in the CPictureTestDoc.cpp file in the project:
First, initialize the defined function handle in the constructor:
context=NULL; //Initialize camera function handle
m_guicontext=NULL; //Initialize image user interface handle
Then, connect and initialize the camera in the OnNewDocument() function:
flycaptureCreateContext( &context ); //Connect camera
guierror=pgrcamguiCreateContext( &m_guicontext ); //Create GUI connection
flycaptureInitialize( context, _CAMERA_INDEX ); //Camera initialization
2.2 Image Capture
In some automation systems, the capture code may be used in many places. Therefore, in order to enhance the readability of the program and reduce the programming code, we write a function to complete the capture and save functions, so that when needed, we can directly call the function. Add the function PictureGrab() in the CPictureTestDoc.cpp file to implement image capture. The core code is as follows:
flycaptureStart( context,
FLYCAPTURE_VIDEOMODE_ANY,
FLYCAPTURE_FRAMERATE_ANY ); //Start the camera. The three parameters are: camera function handle, video mode, frame
rateflycaptureGrabImage2( context, &image ); //Grab the image. image is the address of the image in the
memoryflycaptureConvertImage( context, &image, &imageConverted ); //Image format conversion. imageConverted is the address of the converted image in the memoryflycaptureSaveImage
( context, &imageConverted, ("TestPicture.bmp"), SAVE_FORMAT_C ); //Save the image. TestPicture.bmp is the name of the image. SAVE_FORMAT_C is the image saving format, i.e. BMP
formatflycaptureStop( context ); //Stop the camera
The images captured by the above program are saved in the project folder. In this way, in subsequent image processing, the image files can be accessed directly through the file name in the program without adding a path, which simplifies the program code.
2.3 Image Display
There are two types of Windows bitmaps: DDB and DIB. The former is device-dependent (Device Dependent Bitmap), corresponding to the CBitmap class in MFC 6.0. Their structure and location in memory depend on the device driver that manages them. DIB is a "format" that can be stored in memory or stored as a file, that is, a common BMP file. In Visual C++'s MFC, the CBitmap class represents DDB images, which greatly facilitates programmers' use of DDB. However, usually no one will store DDB images as files, so we use DIB more often. Unfortunately, MFC has almost no support for DIB. Therefore, when compiling image processing programs, it is necessary to design a reusable class CDib specifically for processing DIB[4] (For CDib, readers can refer to relevant books, and this article will not repeat it). In this article, in order to facilitate subsequent image processing, the CDib class technology is used when displaying images. Because in actual applications, we often need to read images continuously, this article directly uses the file name to read the image, so that the acquired image can be displayed in real time.
First, define the class CDib and define the common variables in CPictureTestDoc.h:
CDib m_dib; //CDib class object, used for reading and writing bitmap files
Then, add the function PictureRead() to the CPictureTestDoc.cpp file and add the following code:
CString strPathName;
strPathName = _T("TestPicture.bmp");
if (m_dib.Read(strPathName) == TRUE)
{
SetModifiedFlag(FALSE); // start off with unmodified
return ;
}
And add the following code to the OnDraw (CDC * pDC) function in the CPictureTestView.cpp file:
CPictureTestDoc* pDoc = GetDocument();
CDib* pDib = pDoc->GetPDib(); //Return the pointer of m_dib
CSize sizeFileDib = pDib->GetDimensions(); //Get the size of DIB
pDib->Draw(pDC, CPoint(0, 0), sizeFileDib); //Display DIB
Set the scroll window in the OnInitialUpdate() function:
CDib* pDib = pDoc->GetPDib(); //Get the pointer of DIB
if (pDib!=NULL)
SetScrollSizes(MM_TEXT, pDib->GetDimensions()); //Set the window size according to the DIB size
Finally, add the image acquisition command menu, and its response function is:
void CPictureTestView::OnTestStart()
{
CPictureTestDoc * pDoc = GetDocument();
pDoc->pictureGrab(); //grab
the picture pDoc->pictureRead(); //read the image into memory
OnInitialUpdate(); //set the scroll window
}
After the compilation is successful, click the image acquisition command to obtain the image in real time.
The example of image acquisition
2.4 Camera Settings
When acquiring images, we often need to set the camera's parameters such as image format, resolution, frame rate, etc. At the same time, in order to obtain high-quality images, we also need to adjust the white balance. Of course, we can set these parameters by code when the camera is initialized. However, in actual applications, in order to achieve the best results, we need to debug multiple times to achieve it. If we use the method of modifying the code, the debugging process will be very troublesome. Digital cameras generally have a setting menu. What we have to do is to call the camera's setting menu through code. After setting the parameters, the parameters will be automatically saved and loaded. In this way, debugging will be much more convenient. Create a camera setting menu command, and its response function is as follows:
void CPictureTestDoc::OnTestCameraset()
{
pgrcamguiToggleSettingsWindowState(
m_guicontext, AfxGetApp()->m_pMainWnd->GetSafeHwnd()); //Camera settings dialog box
}
Fig. 4.2 Interface for setting the parameter of the camera
3 Conclusion
The image acquisition system implemented in this paper can set the format/mode/frame rate of the digital machine, set the optical parameters, and display the acquired image in real time through the 1394 interface. It can also automatically control the camera. The system is stable and reliable. It can be used to complete the real-time continuous image acquisition process in some complex projects, such as the automatic recognition management system of highway vehicles and license plates, the product outer packaging inspection system in industrial production, etc., and has great practicality.
Previous article:North China Industrial Control Rail Transit Centralized Dispatching System CTC Solution
Next article:Voltage space vector research and Matlab simulation
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Analog Electronics Tong Shibai 223 pages Frequency Response
- EEWORLD University Hall----Live Replay: Infineon BMS solutions protect electric vehicles and energy storage systems!
- Explore TE's PCB Subsystem Solutions
- Things to note when selecting Keithley desktop power supply
- Application of operational amplifier in active filtering
- Solution to EK200-6Q7C stuck during operation
- Goodbye February, hello March
- Embedded protocol selection issues
- [ST NUCLEO-H743ZI Review] (5) ADC conversion speed and accuracy test
- uPySteppers, a wirelessly controlled rotating platform using the ESP32