提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
记录一下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')