Industrial Camera Image Acquisition Program Design Based on 1394 Bus
2026-04-06 07:22:29··#1
[b]0 Introduction[/b] At present, image acquisition devices based on CCD technology can be divided into two categories: 1) Image acquisition system consisting of CCD camera, image acquisition card and computer, which uses image acquisition card to convert analog image signal from CCD into digital image signal and transmit it to computer for processing; 2) Digital image signal is directly transmitted to computer through port by the digital device built into the CCD camera itself. The former, as a classic image acquisition system, has always been dominant in the application of image acquisition[1]. However, high-performance acquisition cards are expensive, and due to different needs, secondary development of acquisition cards is often required. Most acquisition card manufacturers have encapsulated their own functions and link libraries, so the professional quality requirements of developers are high when secondary development is carried out. In recent years, with the continuous progress of CCD camera technology, the second type of image acquisition device, represented by digital camera, has received widespread attention for its convenience, fast acquisition speed, high resolution and high cost performance, and has been well applied in some fields. For the second type of image acquisition device, since the CCD camera directly provides digital signal, high-quality images can be obtained, but at the same time, it also puts forward high requirements for 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, RS-422 has a relatively low data transmission rate, which cannot meet the requirements of a large amount of image data transmission; while RS-644 requires an external image acquisition card when transmitting data, which increases the cost of the entire system. IEEE1394 can not only provide a high-speed data rate, overcoming the disadvantage of low data transmission rate of RS-422, but also does not require an external image acquisition card when connected to 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 called IEEE1394. The data transmission rate of IEEE1394-1995 in 1995 was 100/200/400Mbps, and the data transmission rate of its improved version IEEE1394b can reach 800Mbps, 1.6Gbps and 3.2Gbps. Therefore, the IEEE 1394 bus is the fastest serial bus to date [3]. The IEEE 1394 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) High 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 digital cameras. At present, the most common application is the programming control of image acquisition cards, while there is little information on the programming methods for image acquisition using second-class image acquisition devices. Therefore, this paper focuses on the programming process of image acquisition using second-class image acquisition devices based on the 1394 interface under the VC++ platform. 1 Hardware composition and development platform of the image acquisition system The hardware composition of image acquisition in this paper is: industrial digital camera, 1394b card and PC. Install the required 1394b card in the spare PCI slot of the PC host, connect the camera to the PC via the 1394 interface and install the driver. This completes the hardware environment required for this system. The system platform used is Windows 2000, and the development environment is Microsoft VC++ 6.0. [b]2 Implementation of Image Acquisition[/b] The main contents of the image acquisition system include: human-computer interaction interface, receiving and saving image signals from the CCD camera, displaying images on the acquisition interface, and controlling the camera. These will be described in detail below. 2.1 Establishing the Acquisition Interface The acquisition interface can be created as a dialog box or a document structure. This paper uses the latter: 1) Generate an MFC AppWizard (exe) multi-document application framework (application name: PictureTest). 2) Connect the camera's dynamic link library (because the camera's library functions are used to control image acquisition). Locate the camera installation directory and add the file path of the include folder to the Project->Setting->C/C++->Preprocessor->Additional include directories edit box; add the file path of the lib folder to the Project->Setting->Link->Input->Additional library path edit box, and also enter pgrflycapture.lib pgrflycapturegui.lib in the …->Input->Object/library modules edit box. 3) Include the header file for the camera control class by adding the following header file to the CPICtureTestDoc.h file in the project: #include #include And define the following public variables: FlyCaptureContext context; // Camera function handle CameraGUIContext m_guicontext; // Graphical user interface (GUI) handle 4) When capturing images with the camera, it is necessary to initialize it first. We hope that this part of the work will be done by the system itself when the application is opened. In the CPICtureTestDoc.cpp file of the project, the camera is initialized: First, the defined function handle is initialized in the constructor: context = NULL; // Camera function handle initialization m_guicontext = NULL; // Image user interface handle initialization Then, the camera is connected and initialized in the OnNewDocument() function: flycaptureCreateContext( &context ); // Connect the camera guierror = pgrcamguiCreateContext( &m_guicontext ); // Create GUI connection flycaptureInitialize( context, _CAMERA_INDEX ); // Camera initialization 2.2 Image Capture In some automated systems, image capture code may be used in multiple places. Therefore, to enhance the readability of the program and reduce the amount of programming code, we write a function to perform the image capture and saving function, so that the function can be called directly when needed. Add the function `PictureGrab()` to the `CPictureTestDoc.cpp` file to implement image capture. Its core code is as follows: `flycaptureStart(context, FLYCAPTURE_VIDEOMODE_ANY, FLYCAPTURE_FRAMERATE_ANY); // Camera starts, the three parameters are: camera handle, video mode, and frame rate. flycaptureGrabImage2(context, &image); // Capture image, image is the memory address of the image. flycaptureConvertImage(context, &image, &imageConverted); // Image format conversion, imageConverted is the memory address of the converted image. flycaptureSaveImage(context, &imageConverted, ("TestPicture.bmp"), SAVE_FORMAT_C); // Save image, TestPicture.bmp is the image save name, SAVE_FORMAT_C is the image save format, i.e., BMP format. flycaptureStop(context, &imageConverted, &imageConverted, &imageConverted, &imageConverted); // Save image, TestPicture.bmp is the image save name, SAVE_FORMAT_C is the image save format, i.e., BMP format. flycaptureStop(context, &imageConverted, &imageConverted, &imageConverted, &imageConverted, &imageConverted); // Save image, TestPicture.bmp is the image save name, SAVE_FORMAT_C is the image save format, i.e., BMP format.` );//Stop the camera from capturing the image captured by the above program and save it in the project folder. In this way, during subsequent image processing, the image file can be accessed directly in the program by file name without adding the path, which simplifies the program code. 2.3 Image display Windows bitmaps are of two types: DDB and DIB. The former depends on the device (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 as a file, i.e., the common BMP file. In Visual C++ 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 developing image processing programs, it is necessary to design a reusable class CDib specifically for handling DIB[4] (readers can refer to relevant bibliographies for CDib, which will not be repeated in this article). In this paper, a CDib-like technique is used for image display to facilitate subsequent image processing. Because in practical applications, continuous image input is often required, this paper directly uses filenames to read images, enabling real-time display of the acquired images. First, define the class CDib and define a public variable in CPICtureTestDoc.h: CDib m_dib; //CDib class object, used for reading and writing bitmap files. Then, add a function PictureRead() in 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; } Then, in the OnDraw(CDC* pDC) function in the CPICtureTestView.cpp file, add the following code: CPictureTestDoc* pDoc = GetDocument(); CDib* pDib = pDoc->GetPDib(); // Returns a pointer to m_dib CSize sizeFileDib = pDib->GetDimensions(); // Gets the size of the DIB pDib->Draw(pDC, CPoint(0, 0), sizeFileDib); // Display DIB In the OnInitialUpdate() function, set the scroll window: CDib *pDib = pDoc->GetPDib(); // Get the pointer to the 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, whose response function is: void CPictureTestView::OnTestStart() { CPictureTestDoc *pDoc = GetDocument(); pDoc->pictureGrab(); // Capture the image pDoc->pictureRead(); // Read the image into memory OnInitialUpdate(); // Set the scroll window } After compilation, click the image acquisition command to acquire the image in real time. [align=center]Fig.1 The example of image acquisition[/align] 2.4 Camera Settings When acquiring images, we often need to set camera parameters such as image format, resolution, and frame rate. Simultaneously, to obtain high-quality images, we also need to adjust the white balance. Of course, these parameter settings can be implemented in code during camera initialization. However, in practical applications, to achieve the best results, we need to debug multiple times. If we use the method of modifying code, the debugging process will be very troublesome. Digital cameras generally have a settings menu. What we need to do is call the camera's settings menu through code. After setting the parameters, the parameters will be automatically saved and loaded. This will make debugging much more convenient. The camera settings menu command is created, and its response function is as follows: void CPictureTestDoc::OnTestCameraset() { pgrcamguiToggleSettingsWindowState( m_guicontext, AfxGetApp()->m_pMainWnd->GetSafeHwnd() );//Camera settings dialog box} [align=center]Fig.2 Camera parameter setting interface Fig.2 Fig. 4.2 Interface for setting the parameter of the camera[/align] 3 Conclusion The image acquisition system implemented in this paper can set the format/mode/frame rate of the digital camera, 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 for highway vehicles and license plates, and the product packaging inspection system in industrial production. It has great practicality. Acknowledgements I would like to thank my supervisor, Associate Professor Xu Zhixiang, for his guidance in the writing of this paper. References [1] Yan Shoucheng, Quan Houde, Li Qing. Research on digital image acquisition technology under Windows environment. Microcomputer Information, 2006, 2(1): 252-254. [2] Bi Meihua, Liu Wenwen. Development of IEEE1394 CCD application based on VC++6.0. Modern Display, 2009, 3: 38-42. [3] Liu Yixian, Song Shenmin, Chen Xinglin, Qiang Wenyi. Implementation of image acquisition and processing system based on IEEE1394 bus. Control Engineering, 2006, 13: 110-115. [4] Chen Jian. Selected Collection of Visual C/C++ Programming - Implementing the device-independent bitmap class CDib in Visual C++. Beijing: Science Press, 2003. Programming of Image Acquisition with Industrial Camera Based on 1394 Bus LI Xiao-feng, XU Zhi-xiang (School of Mechanical Engineering, Dalian University of Technology, Dalian 116024, China) Abstract: Through comparisons of two image acquisition methods at present, the advantages of combining digital camera with PC to grab image are pointed out. Meanwhile, the paper reveals that IEEE1394 bus has superior performances in image acquisition after analyzing the characteristics functions and of IEEE1394 standard. For this, the programming method and skill to grab image by using device with 1394 digital interface are introduced through concrete examples. Key words: IEEE1394; VC++; DIB; image acquisition