halcon模板匹配干扰边缘消除办法(最硬核方式)

tech2022-10-29  129

目录

halcon手绘形状匹配模板手绘形状匹配模板主要算子解析draw_nurbs 绘制平滑曲线参数解释 create_shape_model_xld 使用XLD轮廓创建模板参数解释 实例演示与解析实例代码展示与解析运行过程与处理展示读入图像绘制模板使用绘制的XLD创建模板查找模板

博主写作不容易,还是需要您鼓励 万水千山总是情 , 先点个赞行不行

最近做了个项目,遇到一个问题,就是在创建形状匹配模板时候,干扰太多,像麻绳一样。

使用自定义区域去消除吧,因为轮廓长,边缘干扰距离近,操作起来不方便; 使用CAD图形创建模板吧,又因为产品随意性比较强,每次换产品都要从新画模板。

最终决定使用手绘模板的方式解决这个问题。

halcon手绘形状匹配模板

手绘形状匹配模板

为了避免大家产生理解歧义,这里对手绘形状匹配模板做一个解释。 所谓手绘形状匹配模板,就是在图像上画XLD轮廓,将这个XLD轮廓作为形状匹配模板。这样模板就由我们手绘而成,我们想让模板长什么样,就把模板画成什么样。

主要算子解析

draw_nurbs 绘制平滑曲线

draw_nurbs — 界面交互式绘制平滑曲线

draw_nurbs( : ContOut : WindowHandle, Rotate, Move, Scale, KeepRatio, Degree : Rows, Cols, Weights)

我们一般使用时参数设置如下: draw_nurbs (ContOut1, WindowHandle, ‘true’, ‘true’, ‘true’, ‘true’, 3, Rows, Cols, Weights)

参数解释

ContOut(output_object)xld_cont→对象 与手绘轮廓近似的NURBS曲线。 WindowHandle(input_control)窗口→(整数) 窗口句柄。 Rotate(input_control)字符串→(string) 旋转使能,轮廓交互时可以旋转 默认值:“ true” 值列表:“ false”,“ true” Move (input_control)字符串→(string) 移动使能,轮廓交互时可以使能 默认值:“ true” 值列表:“ false”,“ true” Scale(input_control)字符串→(string) 缩放使能,轮廓交互时可以缩放 默认值:“ true” 值列表:“ false”,“ true” KeepRatio(input_control)字符串→(string) 缩放时是否保持比例,是否等比例缩放 默认值:“ true” 值列表:“ false”,“ true” Degree(input_control)整数→(整数) NURBS曲线的曲度。合理的值是3到25。 默认值:3 建议值:2、3、4、5 限制:Degree> = 2 Rows(output_control)坐标.y数组→(真实) 控件多边形的行坐标。 Cols(output_control)坐标.x数组→(实数) 控件多边形的列坐标。 Weights (output_control)实数数组→(实数) 权重向量。

create_shape_model_xld 使用XLD轮廓创建模板

create_shape_model_xld — 使用XLD轮廓创建模板

create_shape_model_xld(Contours : : NumLevels, AngleStart, AngleExtent, AngleStep, Optimization, Metric, MinContrast : ModelID)

我们一般使用时参数设置如下: create_shape_model_xld (Contours , ‘auto’,-rad(180), rad(360), ‘auto’, ‘auto’, ‘ignore_local_polarity’, 10, ModelID)

参数解释

Contours (input_object)xld_cont(-array)→对象 输入将用于创建模型的轮廓。 NumLevels(input_control)整数→(整数/字符串) 金字塔等级的最大数量。 默认值:“自动” 值列表:1、2、3、4、5、6、7、8、9、10,“自动” AngleStart(input_control)angle.rad→(实数) 模板的起始角度。 默认值:-0.39 建议值:-3.14,-1.57,-0.79,-0.39,-0.20、0.0 AngleExtent(input_control)angle.rad→(实数) 模板旋转角度的范围。 默认值:0.79 建议值:6.29、3.14、1.57、0.79、0.39 限制:AngleExtent> = 0 AngleStep(input_control)angle.rad→(真实/字符串) 旋转角度的步长(分辨率)。 默认值:“自动” 建议值:“自动”,0.0175、0.0349、0.0524、0.0698、0.0873 限制:(AngleStep> 0)&&(AngleStep <=(pi / 16)) Optimization(input_control)字符串(-array)→(string) 一种优化,以及用于生成模型的可选方法。 默认值:“自动” 值列表:“ auto”,“ no_pregeneration”,“ none”,“ point_reduction_high”,“ point_reduction_low”,“ point_reduction_medium”,“ pregeneration” Metric(input_control)字符串→(string) 匹配指标。 默认值:‘ignore_local_polarity’ 值列表:‘ignore_color_polarity’,‘ignore_global_polarity’,‘ignore_local_polarity’,‘use_polarity’ MinContrast(input_control)编号→(整数) 搜索图像中对象的最小对比度。 默认值:5 建议值:1、2、3、5、7、10、20、30、40 ModelID(输出控制)shape_model→(整数) 模板的句柄。

实例演示与解析

实例代码展示与解析

*读入图片进行显示 read_image (Image, 'C:/Users/22967/Desktop/ZL2KB/1.bmp') dev_close_window () dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) dev_display (Image) *手绘模板 draw_nurbs (ContOut1, WindowHandle, 'true', 'true', 'true', 'true', 3, Rows, Cols, Weights) *使用XLD轮廓创建模板 create_shape_model_xld (ContOut1, 'auto',-rad(180), rad(360), 'auto', 'auto', 'ignore_local_polarity', 10, ModelID) *得到模板轮廓 get_shape_model_contours (ModelContours, ModelID, 1) *查找模板 find_shape_model (Image, ModelID, 0, 0, 0.8, 0, 0.5, 'least_squares', 0, 0.1, Row, Column, Angle, Score) *显示查找结果 if(|Row|==0) dev_clear_window() dev_display(Image) set_tposition (WindowHandle, 300, 300) write_string (WindowHandle, 'Not Find') stop() else gen_cross_contour_xld (CrossFind, Row, Column, 200, Angle) endif

运行过程与处理展示

读入图像

绘制模板

使用绘制的XLD创建模板

查找模板

博主简介:工业自动化上位机软件工程师、机器视觉算法工程师、运动控制算法工程师。目前从业于智能制造自动化行业。 博主邮箱:2296776525@qq.com 帮忙点个赞吧。哈哈。
最新回复(0)