*
* This example program demonstrates the use of union_collinear_contours_xld for connecting
* collinear line segments. This is the new and recommended operator for this task.
* In addition, the program shows how to use the old operator union_straight_contours_xld for
* connecting contours that are not collinear but have neighboring end points.
*
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)
*
* Remove border
*
Border := 35
rectangle1_domain (Image, ImageReduced, Border, Border, 576 - Border, 768 - Border)
*
* Extract edges in the image and detect straight line segments
* Unify collinear line segments and keep only the long ones
*
* 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 ()
*
* Further processing (1): connect neighboring contours and get the surrounding box
*
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)
stop ()
*
*
* Further processing (2): fit lines into the collinear contours
*
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]])
dev_display (Contour)
endfor
QML--Rectangle
2024-03-30 09:46:02 30 阅读