halcon模板匹配干扰边缘消除办法

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

使用自定义区域去消除吧,因为轮廓长,边缘干扰距离近,操作起来不方便;
使用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创建模板

在这里插入图片描述

查找模板

在这里插入图片描述

转载自:

https://blog.csdn.net/cashmood/article/details/108378041


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864