基于灰度的模板匹配(带旋转角度)

原图

选择模板

旋转180度进行识别

继续旋转 ,依然可以识别

代码:

* Searching the best matching of a template in an image (with rotation).
* 
dev_close_window ()
read_image (For6, 'for6')
get_image_size (For6, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
* Interpolate 2 video half images
fill_interlace (For6, ImageFilled, 'odd')
* gen_rectangle1 (Rectangle, 266, 390, 348, 435)
gen_rectangle1 (Rectangle, 78, 292, 129, 402)
* gen_rectangle1 (Rectangle, 258, 214, 296, 258)
area_center (Rectangle, Area, Row, Column)
reduce_domain (ImageFilled, Rectangle, ImageReduced)
pi := acos(0.0) * 2
* Preparing a pattern for template matching with rotation
create_template_rot (ImageReduced, 4, -pi, 2 * pi, pi / 45, 'sort', 'original', TemplateID)
dev_set_color ('red')
SumError := 0.0
Count := 0
for Phi := -180 to 180 by 5.0
    hom_mat2d_identity (HomMat2DIdentity)
    hom_mat2d_rotate (HomMat2DIdentity, rad(Phi), 256, 256, HomMat2DRotate)
    affine_trans_image (ImageFilled, ImageAffinTrans, HomMat2DRotate, 'constant', 'false')
*     add_noise_white (ImageAffinTrans, ImageAffinTrans, 30)
    best_match_rot_mg (ImageAffinTrans, TemplateID, -pi, 2 * pi, 40, 'true', 4, Row, Column, Angle, Error)
    disp_arrow (WindowID, Row, Column, Row - cos(Angle) * 50, Column - sin(Angle) * 50, 1)
    AngleDeg := deg(Angle)
    DiffAngle := abs(AngleDeg - Phi)
    if (DiffAngle > 360)
        DiffAngle := abs(360 - DiffAngle)
    endif
    SumError := SumError + DiffAngle
    Count := Count + 1
endfor
TotalError := SumError / Count
clear_template (TemplateID)

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值