原图
选择模板
旋转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)