shape_trans_xld(XLD : XLDTrans : Type : )
shape_trans根据参数Type 转换输入轮廓或l输入的多边形:
convex 凸包
ellipse与输入轮廓或多边形具有相同力矩和面积的椭圆。
封闭的输入轮廓或多边形不能与自身相交,
否则生成的椭圆没有意义
(输入轮廓或多边形是否与自身相交可用test_self_intersection_xld确定)。
outer_circle 最小外接圆
rectangle1 最小外接平行矩形
rectangle2 最小外接旋转矩形
例程
*当前这个例程演示调用shape_trans_xld将轮廓转换成凸包,椭圆,圆,矩形
dev_close_window ()
read_image (Letters, 'letters')
crop_part (Letters, ImagePart, 631, 4, 200, 310)
get_image_size (ImagePart, Width, Height)
dev_open_window (0, 0, Width * 2, Height * 2, 'black', WindowHandle)
dev_display (ImagePart)
dev_set_line_width (2)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
Color := ['yellow','forest green']
for Column := 0 to 4 by 1
dev_set_color (Color[0])
gen_rectangle1 (Rectangle, 1, 2 + 40 * Column, 295, 32 + 40 * Column)
reduce_domain (ImagePart, Rectangle, ImageReduced)
threshold_sub_pix (ImageReduced, Border, 100)
dev_set_color (Color[1])
set_tposition (WindowHandle, 290, 5 + 40 * Column)
if (Column == 0)
*将第一列字母转轮廓换成凸包
shape_trans_xld (Border, XLDConvex, 'convex')
dev_display (XLDConvex)
Message := 'convex\nhull'
endif
if (Column == 1)
* ellipse with the same moments and area as the input contour
shape_trans_xld (Border, XLDEllipse, 'ellipse')
dev_display (XLDEllipse)
Message := 'ellipse'
endif
if (Column == 2)
*将第二列字母轮廓转换成圆
shape_trans_xld (Border, XLDOuterCircle, 'outer_circle')
dev_display (XLDOuterCircle)
Message := 'outer\ncircle'
endif
if (Column == 3)
*将第三列字母转换成平行矩形
shape_trans_xld (Border, XLDRectangle1, 'rectangle1')
dev_display (XLDRectangle1)
Message := 'rect1'
endif
if (Column == 4)
*将第四列字母轮廓转换成旋转矩形
shape_trans_xld (Border, XLDRectangle2, 'rectangle2')
dev_display (XLDRectangle2)
Message := 'rect2'
endif
disp_message (WindowHandle, Message, 'image', 290, 5 + 40 * Column, Color[1], 'false')
endfor
|