基于模板匹配,将模板映射到目标物上

思路:当模板匹配定位到目标后获取此模板的轮廓,因为轮廓是一个图元对象可以通过仿射变换将其映射到目标物上。

演示:

创建模板用图:

匹配用图:

halcon代码:

dev_set_line_width (6)
read_image (Image, 'D:/Halcon-WorkSpaces/Test/图像匹配,将模板轮廓映射到检测图像/test1.png')
threshold_sub_pix (Image, Border, 128)
*创建模板
create_shape_model_xld (Border, 'auto', rad(-180), rad(180), 'auto', 'auto', 'ignore_local_polarity', 5, ModelID)
*匹配模板
read_image (Image1,  'D:/Halcon-WorkSpaces/Test/图像匹配,将模板轮廓映射到检测图像/test2.png')
find_shape_model (Image1, ModelID, rad(-180), rad(180), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
*获取模板轮廓
get_shape_model_contours (ModelContours, ModelID, 1)
dev_clear_window ()
dev_display (Image1)
*使用仿射变换将模板映射到目标物
vector_angle_to_rigid (0, 0, 0, Row, Column, Angle, HomMat2D)
affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2D)

效果:(红色的轮廓就是模板轮廓)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值