rectangle2


* 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

  • 13
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值