halcon 基于轮廓的模板匹配

1.运行结果

 

 2.代码

*读取参考图像
read_image(Image, 'F:/Halcon_workstation/data/m3')
*根据要匹配的目标,围绕目标创建一个矩形,获取ROI区域
gen_rectangle1 (Rectangle, 34, 250, 200, 400)
*对ROI区域进行裁剪,得到模板图像
reduce_domain (Image, Rectangle, ImageReduced)
*测试金字塔的层级参数
inspect_shape_model (ImageReduced, ModelImages, ModelRegions, 4, 30)
*设置显示图像、绘制线条的线宽等窗口参数
dev_set_draw ('margin')
dev_set_line_width(3)
dev_display(Image)
dev_display(Rectangle)
*根据剪裁的模板图像创建基于形状的模板,返回模板句柄ShapeModelID
*create_shape_model (ImageReduced, 5, rad(-10), rad(20), 'auto', 'none', 'use_polarity', *20, 1, 	ShapeModelID)
*edges_image (ImageReduced, ImaAmp, ImaDir, 'canny', 1, 'nms', 20, 40)
edges_sub_pix (ImageReduced, Edges, 'canny', 1.7, 40, 120)
create_shape_model_xld(Edges, 'auto', rad(0), rad(360), 'auto', 'auto', 'ignore_local_polarity', 5, ModelID)
stop()
*读取用于测试的图像
read_image(SearchImage, 'F:/Halcon_workstation/data/m5')
 
*dev_open_window_fit_image(SearchImage, 0, 0, -1, -1, WindowHandle)
get_image_size(Image, Width, Height)
*打开指定窗口的大小
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*使用匹配算子进行形状模板匹配
find_scaled_shape_models (SearchImage, ModelID, rad(-180), rad(180), 0.9, 1.1, 0.50, 6, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Scale, Score1, Model)
gen_cross_contour_xld (Cross, Row, Column, 15, Angle)
disp_cross (WindowHandle, Row, Column, 15, 0)
*disp_rectangle1 (WindowHandle, 0, 0, 100, 100)
*gen_rectangle1 (Rectangle1, Row, Column, Row, Column)
dev_display (SearchImage)
clear_shape_model (ModelID)

 

  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值