http://www.ihalcon.com/read-2246.html
請問(wèn)如何檢測兩個(gè)圖案間的最大、最小、平均距離
這個(gè)方法比較準確,但是耗時(shí)較長(cháng)。
首先要準確的提取所需要的兩條邊,這里我用的是最簡(jiǎn)單的方法,為的是給你提供一個(gè)思路,
實(shí)際項目中不要用這種方法。核心是,第一條線(xiàn)段所有的點(diǎn)到第二條線(xiàn)上的射影,就是做切線(xiàn)。
read_image (Image, 'C:/Users/Desktop/13_3760_ae9968191005f06.jpg')
decompose3(Image, Image1, Image2, Image3)
threshold_sub_pix(Image3, Border, 90)
segment_contours_xld(Border, ContoursSplit, 'lines_circles', 5, 10, 10)
select_shape_xld(ContoursSplit, SelectedXLD, 'contlength', 'and', 500, 800)
sort_contours_xld(SelectedXLD, SortedContours, 'upper_left', 'true', 'row')
select_obj(SortedContours, ObjectSelected2, 2)
fit_line_contour_xld(ObjectSelected2, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
gen_region_line(RegionLine2, RowBegin, ColBegin, RowEnd, ColEnd)
get_contour_xld(ObjectSelected2, Row, Col)
select_obj(SortedContours, ObjectSelected3, 3)
fit_line_contour_xld(ObjectSelected3, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr1, Nc1, Dist1)
gen_region_line(RegionLine3, RowBegin1, ColBegin1, RowEnd1, ColEnd1)
Distance := []
for I := 0 to |Row|-1 by 1
projection_pl(Row[I], Col[I],RowBegin1, ColBegin1, RowEnd1, ColEnd1, RowProj, ColProj)
gen_region_line(RegionLines,Row[I], Col[I], RowProj, ColProj)
distance_pp(Row[I], Col[I], RowProj, ColProj, DistanceTemp)
Distance[I] := DistanceTemp
dev_display(RegionLines)
endfor
tuple_max(Distance, Max)
tuple_min(Distance, Min)
tuple_length(Distance, Length)
tuple_sum(Distance, Sum)
Avg := Sum/Length
dev_display(Image)
dev_display(RegionLine2)
dev_display(RegionLine3)
disp_message(3600, '最大距離:'+Max, 'image', 30, 30, 'green', 'false')
disp_message(3600, '最小距離:'+Min, 'image', 60, 30, 'green', 'false')
disp_message(3600, '平均距離:'+Avg, 'image', 90, 30, 'green', 'false')