Summary of Halcon curve width detection algorithm

In visual inspection, the width of a straight line is easy to detect, that is, the vertical distance between two parallel lines, while the width detection of a curve needs to find another way.

Detect the width of the edge of the curve in the image to judge whether the edge is broken or not. The following five methods are summarized:

1. Image matching judgment

Overview: Establish a standard image reference and compare the detection results.

Core operator:

(1) Reference: align_bead;

(2) Detection: apply_bead_inspection_model;

Refer to the Halcon routine: apply_bead_inspection_model.hdev.

This method is more suitable for glue detection, because it is not easy to obtain the value of the collapse, so it is abandoned, but it has reference value, it is recommended to learn.

2. Distance from point to contour

Overview: Extract the Border (edge) through binarization, extract the lattice of one of the edges, and calculate the distance from all points of the lattice to the other edge.

Core operator:

(1) Get the point matrix on the edge: get_contour_xld(Contour : : : Row, Col);

(2) Calculate the distance from the lattice to the edge: distance_pc(Contour : : Row, Column : DistanceMin, DistanceMax)

Refer to the Halcon routine: distance_pc.hdev.

Reference Code:

*二值化找Border
threshold_sub_pix(ImageReducedM1,Border, 130)
count_obj(Border,Number)
*创建数组,按长度拍排序Border
LengthTuple:=[]
for i:=1 to Number by 1    
select_obj (Border,  ObjectSelected, i)
length_xld(ObjectSelected,length)
LengthTuple:=[LengthTuple,length]
endfor
tuple_sort_index(LengthTuple,Indices)
*找出两条最长的轮廓
if(|Indices|>1)
select_obj(Border,MaxXLD,Indices[|Indices|-1]+1)
select_obj(Border,NextXLD,Indices[|Indices|-1-1]+1)
else
    return()
endif  
*获取最长轮廓的点阵
get_contour_xld(MaxXLD, Rows1, Columns1)
*计算点阵到另一个轮廓的距离
distance_pc(NextXLD,Rows1, Columns1, DistanceMin, DistanceMax)

Note: The operator distance_pc outputs two arrays, which are the minimum distance array and the maximum distance array, and the minimum distance array should be used when taking the value.

3. Distance from contour to contour

Overview: Extract a pair of Contours (contours) through binarization, and calculate the distance between the two contours.

Core operator:

(1) Calculate the distance between contours: distance_contours_xld(ContourFrom, ContourTo : ContourOut : Mode : );

(2) Get the width value set: get_contour_attrib_xld(Contour : : Name : Attrib);

(3) Extract OK/NG segments: segment_contour_attrib_xld(Contour : ContourPart : Attribute, Operation, Min, Max : )

Refer to the Halcon routine:

(1)inspect_frame_width.hdev;

(2)Apply_distance_transform_xld.hdev。

Reference Code:

*测量两条曲线之间的宽度
distance_contours_xld (MaxXLD, NextXLD, ContourOut, 'point_to_segment')
get_contour_attrib_xld (ContourOut, 'distance', Distance)
*提取测量宽度集中合规的部分
segment_contour_attrib_xld (ContourOut, ContourPart, 'distance', 'and', 10, 26)
display_result (MaxXLD, NextXLD, ContourPart)
*取最大值
tuple_max (Distance, WidthMax)
tuple_min (Distance, WidthMin)

4. Extract the skeleton to measure the width

Overview: Extract the central skeleton of the curve, and then measure the width of the curve through the skeleton.

Core operator:

(1) Calculate the input parameters required for the lines_gauss operator: calculate_lines_gauss_parameters( : : MaxLineWidth, Contrast : Sigma, Low, High);

(2) Detect the skeleton and its width: lines_gauss(Image : Lines : Sigma, Low, High, LightDark, ExtractWidth, LineModel, CompleteJunctions : ).

Refer to the Halcon routine:

(1)angio.hdev;

(2)lines_gauss.hdev。

5. Polar coordinate expansion curve image

Overview: Expand the curved image according to polar coordinates, detect the expanded image, and then restore the resulting image to a rectangular coordinate image.

Core operator:

(1) Image to polar coordinates: polar_trans_image;

(2) Image to Cartesian coordinates: polar_trans_region_inv.

Refer to the Halcon routine:

(1)ocr_cd_print_polar_trans.hdev;

(2)vessel.hdev。

Learn from each other and get rich together.

Guess you like

Origin blog.csdn.net/m0_62778855/article/details/125999880