35.5、仿射变换实例二(几何定位---坐标跟随)
目标:通过定位出实时图像的中心坐标(反射举行中的两个圆形为模板),再利用这个中心坐标来对左上角区域进行仿射变换跟随。
read_image (Image1, 'C:/123/试1.jpg')
dev_set_draw ('margin')
gen_rectangle2 (Rectangle, 267, 285, 0.84587, 99, 35)
reduce_domain (Image1, Rectangle, ImageReduced)
create_shape_model (ImageReduced, 'auto', 0, 0, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
find_shape_model (Image1, ModelID, 0, 0, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle1, Score1)
*把定位模板图片得到的模板中心显示出来
gen_cross_contour_xld (Cross1, Row1, Column1, 20, Angle1)
*显示模板轮廓
dev_display_shape_matching_results123 (Out_countours, ModelID, 'red', Row1, Column1, Angle1, 1, 1, 0)
*绘制要跟随的区域
draw_region (Region, 3600)
* Code generated by Image Acquisition 01
list_files ('C:/123', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
* Do something
find_shape_model (Image, ModelID, 0, 0, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row2, Column2, Angle2, Score2)
*把定位实时图片得到的模板中心显示出来
gen_cross_contour_xld (Cross2, Row2, Column2, 6, Angle2)
*根据模板图像中心和实时图像中心计算仿射变换矩阵
vector_angle_to_rigid (Row1, Column1, Angle1,Row2, Column2, Angle2, HomMat2D)
*根据仿射变换矩阵对模板图像中的矩形区域进行仿射变换跟随
affine_trans_region (Rectangle, RegionAffineTrans, HomMat2D, 'false')
*根据仿射变换矩阵对要跟随的区域进行仿射变换跟随
affine_trans_region (Region,Region11, HomMat2D, 'false')
endfor