QQ登录

只需一步,快速开始

halcon crop_contours_xld函数介绍

[ 复制链接 ]
crop_contours_xld(Contours : CroppedContours : Row1, Col1, Row2, Col2, CloseContours : )
crop_contours_xld裁剪所有的XLD Contours
即,在输出时只返回由Row1、Col1、Row2和Col2给出的矩形中包含的轮廓段。
而在clip_contours_xld中,所有与边缘线相交的轮廓线段都被省略,
在这里它们被裁剪到与裁剪矩形的相交点。
如有必要,将轮廓线分割并生成几个新的轮廓线。
然而,闭合轮廓可以使用CloseContours参数再次闭合。
如果将其设置为“true”,则将一个闭合轮廓转换为一个或多个轮廓,
这些轮廓通过剪切矩形上的段进行闭合。
如果它是'false',所有的轮廓结束点设为他们离开裁剪矩形的点。
结果保存在CroppedContours 。

下面是halcon自带的例程,
演示了在不同情况下,此函数的执行结果。
例程中带有中文注释,可单步运行,查看效果。
* 例程演示如何使用函数crop_contours_xld.
*读取一图片,打开新窗口
dev_close_window ()
read_image (Angio, 'angio-part')
get_image_size (Angio, Width, Height)
dev_open_window (0, 0, 3 * Width / 2, 3 * Height / 2, 'black', WindowID)
dev_set_part (0, 0, Height - 1, Width - 1)
* 从图片中提取XLD类型轮廓Lines并显示结果
lines_gauss (Angio, Lines, 2.3, 0.0, 0.7, 'dark', 'true', 'parabolic', 'true')
dev_display (Angio)
dev_set_color ('yellow')
dev_display (Lines)
stop ()
*(原始的轮廓显示为灰色),要注意在矩形的四边扩大0.5个像素,
*以便被剪切轮廓在每个像素边缘上。
Top := 200
Left := 100
Bottom := 300
Right := 200
gen_rectangle1 (Rectangle, Top, Left, Bottom, Right)
reduce_domain (Angio, Rectangle, AngioReduced)
crop_contours_xld (Lines, LinesCropped, Top - 0.5, Left - 0.5, Bottom + 0.5, Right + 0.5, 'false')
dev_clear_window ()
dev_display (AngioReduced)
dev_set_color ('dim gray')
dev_display (Lines)
dev_set_color ('yellow')
dev_display (LinesCropped)
stop ()
*
dev_set_color ('white')
disp_arrow (WindowID, 198, 130, 153, 175, 1)
dev_open_window (25, 275, 300, 300, 'black', ZoomWindow)
dev_set_part (198, 126, 202, 130)
dev_display (AngioReduced)
dev_set_color ('dim gray')
dev_display (Lines)
dev_set_color ('yellow')
dev_display (LinesCropped)
stop ()
*
dev_set_window (ZoomWindow)
dev_close_window ()
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*输入轮廓是闭合的,当参数CloseContours设置为true时,输出轮廓也是闭合的。
*被剪切轮廓段被剪切矩形的边连接。
*这里设置crop_contours_xld的参数CloseContours为true,false查看效果
gen_rectangle1 (Rectangles, 200, 110, 300, 190)
gen_rectangle1 (Rectangle2, 200, 310, 300, 390)
union2 (Rectangles, Rectangle2, Rectangles)
gen_contour_polygon_xld (Contours, [170,330,330,170,170], [70,230,70,230,70])
gen_contour_polygon_xld (Contour2, [170,330,330,170,170], [270,430,270,430,270])
concat_obj (Contours, Contour2, Contours)
crop_contours_xld (Contours, CroppedContour1, 199.5, 109.5, 300.5, 190.5, 'false')
crop_contours_xld (Contours, CroppedContour2, 199.5, 309.5, 300.5, 390.5, 'true')
concat_obj (CroppedContour1, CroppedContour2, CroppedContours)
dev_clear_window ()
dev_set_color ('dim gray')
dev_display (Contours)
dev_display (Rectangles)
dev_set_color ('yellow')
dev_display (CroppedContours)
stop ()
* 但参数参数CloseContours仅绝无仅有闭合的轮廓
gen_contour_polygon_xld (Contours, [170,330,330,170], [70,230,70,230])
gen_contour_polygon_xld (Contour2, [170,330,330,170], [270,430,270,430])
concat_obj (Contours, Contour2, Contours)
crop_contours_xld (Contours, CroppedContour1, 199.5, 109.5, 300.5, 190.5, 'false')
crop_contours_xld (Contours, CroppedContour2, 199.5, 309.5, 300.5, 390.5, 'true')
concat_obj (CroppedContour1, CroppedContour2, CroppedContours)
dev_clear_window ()
dev_set_color ('dim gray')
dev_display (Contours)
dev_display (Rectangles)
dev_set_color ('yellow')
dev_display (CroppedContours)

  

halcon从自学到接项目视频教程,另外再赠送全网最全资源  

  

欢迎围观我录制的一套halcon自学视频教程(进入)


回复

使用道具 举报

快速回复 返回列表 客服中心 搜索