Halcon形状模板匹配

在使用Halcon进行模板匹配的时候,我们使用find_shape_model、find_scaled_shape_model等算子找到模板后返回的是实例,得到的数据是模板中心的行列坐标、角度和缩放比例等数据,不是具体的区域,下面介绍怎么得到具体区域。

解决思路:
一:先获取模板的轮廓,此时获取的轮廓位置在(0,0)的位置;

二:求出模板到匹配实例的旋转矩阵;

三:利用仿射变换得到匹配实例的轮廓;

四:将轮廓转成区域;
————————————————
 

read_image (Image,'green-dot')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
*draw_circle (WindowHandle, Row, Column, Radius)
* gen_circle (Circle, 274.5, 280.5, 95)

*获取模板区域
* reduce_domain (Image, Circle, ImageReduced)

*创建模板
* create_scaled_shape_model (ImageReduced, 'auto', rad(-45), rad(90), 'auto', 0.9, 1.1, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)

*保存模板
* write_shape_model (ModelID, 'D:/Demo/Model.shm')

*读取模板
read_shape_model ('D:/Demo/Model.shm', ModelID1)

read_image (Image1, 'green-dots')
dev_display (Image1)

*获取初始模板轮廓
get_shape_model_contours (ModelContours, ModelID1, 1)

find_scaled_shape_model (Image1, ModelID1,rad(-45), rad(90),  0.9, 1.1, 0.5, 0, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle, Scale, Score)
for i:= 0 to |Score|-1 by 1

        *显示找到的模板轮廓
    *dev_display_shape_matching_results (ModelID1, 'red', Row1[i], Column1[i], Angle[i], 1, 1, 0)

  *求出初始模板到实例中间的旋转矩阵--注:初始模板的行列坐标和角度都是0
    vector_angle_to_rigid (0, 0, 0, Row1[i], Column1[i], Angle[i], HomMat2D)

*给旋转矩阵添加缩放信息
    hom_mat2d_scale (HomMat2D, Scale[i], Scale[i],  Row1[i], Column1[i], HomMat2DScale)

*通过初始模板和旋转矩阵运算得到模板实例的轮廓
    affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2DScale)

*轮廓转区域
    gen_region_contour_xld (ContoursAffinTrans, Region, 'margin')
    
     if(Score[i] > 0.8)

*用十字显示中心点
        *disp_cross (WindowHandle, Row1[i], Column1[i], 20, Angle[i])
    endif
endfor

  • 2
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值