Halcon模板匹配并框定检测区域

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

记录一下Halcon的模板匹配的使用


一、创建模板

在这里插入图片描述

二、模板参数优化

在这里插入图片描述

三、保存模板

在这里插入图片描述

四、计算模板的参考坐标

计算得到模板的中心点
RefRow,
RefColumn

read_image (Model_img, 'model.BMP')
read_shape_model('D:/tool_develop/opencvshape/Matching 01.shm',ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
find_shape_model (Model_img, ModelID, rad(0), rad(90), 0.5, 1, 0.5, 'least_squares', [5,1], 0.9, RefRow, RefColumn, Angle, Score)

五、ROI框模式一 ROI transfer

    find_shape_model (Image, ModelID, rad(0), rad(360), 0.3, 1, 0.5, 'least_squares', [5,1], 0.9, Row, Column, Angle, Score)          
    for I := 0 to |Score| - 1 by 1
    hom_mat2d_identity (AlignmentHomMat2D)
    hom_mat2d_translate (AlignmentHomMat2D, -RefRow, -RefColumn, AlignmentHomMat2D)
    hom_mat2d_rotate (AlignmentHomMat2D, Angle[I], 0, 0, AlignmentHomMat2D)
    hom_mat2d_translate (AlignmentHomMat2D, Row[I], Column[I], AlignmentHomMat2D)   
    affine_trans_region(ROI_0, ROI_0_trans, AlignmentHomMat2D, 'nearest_neighbor')
    affine_trans_region(ROI_1, ROI_1_trans, AlignmentHomMat2D, 'nearest_neighbor')   
    endfor

六、ROI框模式二 Image Transfer

    find_shape_model (Image, ModelID, rad(0), rad(360), 0.3, 1, 0.5, 'least_squares', [5,1], 0.9, Row, Column, Angle, Score)          
    for I := 0 to |Score| - 1 by 1
    hom_mat2d_identity (RectificationHomMat2D)
    hom_mat2d_translate (RectificationHomMat2D, RefRow-Row[I], RefColumn-Column[I], RectificationHomMat2D)
    hom_mat2d_rotate (RectificationHomMat2D, -Angle[I], RefRow, RefColumn, RectificationHomMat2D)
    affine_trans_image (Image, RectifiedImage, RectificationHomMat2D, 'constant', 'false')   
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值