Design of image acquisition program for industrial camera based on 1394 bus

Publisher:limm20032003Latest update time:2009-12-16 Source: 中国传动网 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Fig.1
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. 2
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.

Reference address:Design of image acquisition program for industrial camera based on 1394 bus

Previous article:North China Industrial Control Rail Transit Centralized Dispatching System CTC Solution
Next article:Voltage space vector research and Matlab simulation

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号