Halcon programming-texture-based Mara detection

Source: Internet
Author: User

Surface defect Detection is a very important application in the field of machine vision. Machine Vision is a new technology in the three fields of optics, electromechanical and computer science. But the current surface flaw detection in the academic field is mainly computer professional or control professional aiming at the image processing direction in doing, and the visual optics system this piece is mainly optical engineering major in doing. Few researchers have combined these three pieces well, and the domestic machine vision (note that machine vision is not computer vision) is basically a small company.

Software This piece will not say, the overall software environment in the country is not good. As far as I know, Japan, Germany and the United States have a lot of relatively mature software in machine vision. Professor Chen Bingxi of China Agricultural University, who has worked on many robot-vision agricultural robots during his stay, has also written a book on visual image processing, followed by an addendum to their own master software. The German software is the Halcon to be introduced below. Mention Halcon is necessary and open source OpenCV contrast, OpenCV in the image processing is also small, but its image module function is not much, and because it is open source, and does not specialize in a variety of image processing areas of the detection needs to expand, or that sentence, after all, is open source.

Halcon is a commercial software, the main domestic companies in the agency, in the image processing, in particular, the detection and measurement has many advantages. Below I take an example to introduce the HALCON image algorithm development process.

start the software, ctrl+e pop-up routines, select Detect_mura_defects_texture in the surface detection. This is the Mura damage on the LCD panel. An image of the damage in the appendix

The black area that appears on a cluttered texture is damage. How to detect it?

The code is as follows:

* This example shows how to detect Mura defects

* In highly textured images
*
Dev_close_window ()
Dev_update_off ()
Path: = ' lcd/mura_defects_texture_ '
Read_image (image, path+ ' 01 ')
Get_image_size (image, Width, Height)
Dev_open_window (0, 0, 640, 480, ' black ', windowhandle)
Set_display_font (WindowHandle, +, ' courier ', ' true ', ' false ')
Dev_set_draw (' margin ')
Dev_set_line_width (3)
Dev_set_color (' Red ')
For f: = 1 to 2 by 1
Read_image (image, path+f$ '. 2i ')
DECOMPOSE3 (Image, R, G, B)
* Defects is characterized by dark patches. Hence, by substracting the
* Estimated background illumination from the original image the
* Defects become more apparent
Estimate_background_illumination (B, ImageFFT1)
Sub_image (B, ImageFFT1, Imagesub, 2, 100)
* Median filter smooths out the fine texture, simplifying the following
* Segmentation and final detection of defects
Median_image (Imagesub, Imagemedian, ' Circle ', 9, ' mirrored ')
Watersheds_threshold (Imagemedian, basins, 20)
* Dark patches corresponding to defects has a very low energy
Cooc_feature_image (Basins, Imagemedian, 6, 0, energy, Correlation, homogeneity, contrast)
Tuple_find (SGN (Energy-0.05),-1, Indices)
Select_obj (Basins, Defects, indices+1)
*
Dev_display (Image)
Dev_display (Defects)
Count_obj (Defects, ndefects)
Disp_message (WindowHandle, ndefects+ ' mura\ ' defects detected ', ' window ',-1,-1, ' Red ', ' true ')
if (F < 2)
Disp_continue_message (WindowHandle, ' black ', ' true ')
Stop ()
endif
ENDfor

1 The color image is decomposed by R G B, and B is selected as the subsequent image. The reason for this is that the black spot and the background difference in the B image are the most important to be treated by experiments.

2 Generate the background template, the image Fourier transform into the frequency domain, through the Gaussian filter, and then the Fourier inverse transformation back, the resulting image is the background template

3 background differential. Use the following function to enhance the difference of two images

Sub_image (Imageminuend, ImageSubtrahend:ImageSub:Mult, ADD:)

imagesub= (imageminuend-imagesubtrahend) *mult+add

4 Watershed algorithm segmentation, using median filter before segmentation to suppress small spots or thin lines. After the watershed, the image is segmented into multiple outlines (region).

5 calculates the grayscale information for multiple contours region, including energy. Correlation degree, the same degree, the contrast, through the gray level symbiosis matrix. The previous two parameters are gray level and direction, gray level is 2^, direction is gray-scale symbiosis matrix direction.

6 The region is filtered according to the Energy information, and the filtered region is the test result.

Halcon::tuple_find ((Energy-0.05). SGN (),-1, &indices);
Image_opencv_test=m_ip->himagetoiplimage (M_hoimage);
int Number=indices.num ();
for (int i=0;i<number;i++)
{
Halcon::htuple new_indices;
New_indices[0]=indices[i]. I () +1;
Halcon::select_obj (Basins, &defects, new_indices);
Hlong X1,x2,y1,y2;
Halcon::smallest_rectangle1 (DEFECTS,&Y1,&X1,&Y2,&X2);
Cvrectangle (Image_opencv_test,cvpoint (x1,y1), Cvpoint (X2,y2), Cvscalar (0,0,255), 2,8,0);
}

Determine whether the energy is greater than 0.05, through the SGN function will be greater than 0.05 of the 1, less than the set-1. Through the Find

In (Energy-0.05). Find out where in Sgn () 1 appears, note that this position is starting from 0. It seems that this is a sort of man-made, so indices is the first three 0 1 2
    Select_obj (Basins, &defects, new_indices) is the region where the sequence number basins is extracted from new_indices. Why redefine a htuple because htuple are actually arrays.
The Select_obj parameter must be htuple, which is the array, so it can only be redefined, and the sequence number starts at 1, so add 1 to get the value in the array plus 1.
The code obtained is new_indices[0]=indices[i]. I () +1; This means that the values in the array can be accessed directly and then converted to the desired type.
This is my stupid method, directly through the Halcon conversion C + + code, only one sentence. I think it's more reliable to take it out individually.

Put a test result on it:




Halcon programming-texture-based Mara detection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.