图片下载
链接:https://pan.baidu.com/s/188kLS5w2bw0OeYeYeRkNEA
提取码:p4eh
代码
* 1.加载图片 ***************************************************
dev_close_window ()
read_image (Image, './pads')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_colored (12)
dev_set_draw ('margin')
dev_display (Image)
* 2.XLD检测与合并 ***************************************************
Border := 35
rectangle1_domain (Image, ImageReduced, Border, Border, 576 - Border, 768 - Border)
* 边缘检测
* edges_sub_pix (ImageReduced, Edges, 'lanser2', 0.16, 3, 5)
edges_sub_pix (ImageReduced, Edges, 'canny', 5, 3, 5)
* 边缘分割
segment_contours_xld (Edges, ContoursSplit, 'lines', 5, 4, 2)
* 边缘筛选
select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 20, Width / 2, -0.5, 0.5)
* 边缘 直线连接(合并)
union_collinear_contours_xld (SelectedContours, UnionContours, 10, 1, 8, 0.4, 'attr_keep')
* 二次筛选
select_contours_xld (UnionContours, SelectedContours1, 'contour_length', 50, 10000, -0.5, 0.5)
* 显示边缘
dev_display (Image)
dev_display (SelectedContours1)
stop ()
* 3.拟合成 外接矩形 ***************************************************
* 四角链接
union_adjacent_contours_xld (SelectedContours1, UnionContours1, 20, 1, 'attr_keep')
* 最小外接矩形
smallest_rectangle2_xld (UnionContours1, Row, Column, Phi, Length1, Length2)
* 生成矩形
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
* 显示结果
dev_display (Image)
dev_display (Rectangle)
stop ()
* 4.拟合成直线xld ***************************************************
dev_display (Image)
* 拟合成直线
fit_line_contour_xld (SelectedContours1, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
for i := 0 to |RowBegin| - 1 by 1
* 生成直线
gen_contour_polygon_xld (Contour, [RowBegin[i],RowEnd[i]], [ColBegin[i],ColEnd[i]])
* 显示xld
dev_display (Contour)
endfor