Halcon Learning Notes: Development Thought of Machine Vision Engineering Application
The application of machine vision engineering can be divided into two parts: hardware and software.
Hardware: The first step in engineering application is hardware selection. Hardware selection is critical because it is the basis for your future work. Mainly the choice of light source, industrial camera and lens.
Software: At present, the main commercial libraries in the industry are Halcon, Cognex, DALSA, evision, NI, etc. Open source libraries include OpenCV. Among them, NI's LabVIEW + vision module.
The basic development ideas of machine vision engineering application are as follows:
First, image acquisition, second, image segmentation, third, morphological processing, fourth, feature extraction, fifth, output results.
These four steps are explained below in Halcon.
1. Image acquisition:
Halcon supports various image acquisition cards and industrial cameras through image acquisition interfaces. These include: analog video signal, digital video signal Camera Link, digital video signal IEEE 1394, digital video signal USB2.0, digital video signal Gigabit Ethernet, etc.
Halcon encapsulates the image acquisition interfaces of the different cameras mentioned above through a unified interface, thus achieving the unification of operators. Different cameras can be changed by changing only a few parameters.
Halcon image acquisition ideas: 1. Open the device, get the handle of the device. 2. Call the acquisition operator to get the image.
1. Open the device and get the handle of the device.
Open_framegrabber ('Daheng CAM', 1, 1, 0, 0, 0, 0,'interlaced', 8,'gray', -1,'false','HV-13xx','1', 1, -1, AcqHandle)// Connect the camera and set relevant parameters.
Parameter
Values
Default
Type
Description
Name
'Daheng CAM'
String
Name of the HALCON interface.
Horizontal Resolution
One
One
1 represents the level of all, 2 is the level of 1/2, representing image interception.
Vertical Resolution
11
Ibid., indicating the vertical direction.
Image Width
<width>
Zero
Integer
The required width of the image section ('0'represents the complete image).
ImageHeight < height > 0 Integer requires the height of the image part (0"is the complete image)
Pixel row coordinates at the top left of the image section required by StartRow < width > 0 integer
Pixel column coordinates at the top left of the image section required by StartColumn < column > 0 integer
Field * Neglect
BitsPerChannel
Channel modes for ColorSpace'default','gray','rgb''gray' string HALCON images
Generic
External Trigger
'false','true'
'false'string external trigger state
Camera Type'HV-13xx','HV-20xx','HV-30xx','HV-31xx','HV-50xx','SV-xxxx''HV-13xx' string is connected to a series of cameras.
Device'1','2','3',...'1'string camera connects the first device number "1" and the second device number "2".
Port * Neglect
LineIn * Neglect
2. Call the acquisition operator to get the image.
Grab_image (Image, AcqHandle) //(Synchronized acquisition) is used to post-process the image and then collect the image. The rate of image acquisition is affected by the processing speed.
Grab_image_async (Image, AcqHandle, MaxDelay)//(Asynchronous acquisition). After one picture is collected, the camera immediately collects the next picture, which is not affected by processing speed. The third parameter is MaxDelay, which indicates the maximum allowable delay in asynchronous acquisition. The time between this acquisition command and the last acquisition command can not exceed MaxDelay, which means re-acquisition.
Other correlation operators for image acquisition:
Grab_image_start, which starts to command the camera for asynchronous acquisition. It can only be used with grab_image_async (asynchronous acquisition).
Example:
* Select a suitable image acquisition interface name AcqName
Open_framegrabber (AcqName, 1, 1, 0, 0, 0,'default', -1,'default', -1.0,'\
'default','default','default','default', -1, -1, AcqHandle)
Grab_image (Image 1, AcqHandle)// for synchronous acquisition
* Start next grab
Grab_image_start (AcqHandle, -1.0)// Command camera to start asynchronous image acquisition
* Process Image 1...
* Finish asynchronous grab + start next grab
Grab_image_async (Image 2, AcqHandle, -1.0)// / Read the asynchronously captured image
* Process Image 2...
Close_framegrabber (AcqHandle)
3. Reading and Writing of Camera Parameters
Read camera parameters:
Info_framegrabber (:: Name, Query: Information, ValueList)
Write camera parameters:
Set_framegrabber_param(:: AcqHandle, Param, Value:)
2. Image segmentation:
Definition of image segmentation:
The so-called image segmentation refers to the segmentation of different regions with special meanings in an image. These regions are not intersected with each other, and each region satisfies the consistency of a particular region.
1. Image Segmentation Based on Threshold
Threshold - The image is segmented using global thresholds.
Format: threshold (Image: Region: MinGray, MaxGray:)
Automatic global threshold segmentation method:
(1) Computing gray histogram
(2) Find the most frequent gray value (maximum value)
(3) The threshold value is a distance from the maximum value in thresholds.
Code:
Gray_histo (Regions, Image, Absolute Histo, Relative Histo)// Calculates the absolute and relative gray value histograms in the image area.
PeakGray: = sort_index (Absolute Histo) [255]// Find the gray value with the most frequency
Threshold (Image, Region, 0, PeakGray-25)
Bin_threshold - Segments an image using an automatically determined threshold.
Format: bin_threshold (Image: Region::)
Dyn_threshold - Segments an image using a local threshold.
Format: dyn_threshold (OrigImage, ThresholdImage: RegionDynThresh: Offset, LightDark:)
Example:
Mean_i
Please the Chinese version for details.