35.6、仿射变换实例三(Blob定位---坐标跟随)
目标:Blob定位圆形,并让矩形实时跟随圆形(矩形和圆形的相对位置不变)
read_image (Image1, 'C:/ͼƬ/4.bmp')
*阈值分割并连通性操作
threshold (Image1, Regions, 218, 255)
connection (Regions, ConnectedRegions)
*通过圆度和面积筛选出中心大圆
select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [105394,0.9315], [228945,1])
* select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 96267.4, 228945)
*填充孔洞
fill_up (SelectedRegions, RegionFillUp)
*计算大圆中心
area_center (RegionFillUp, Area1, Row1, Column1)
dev_set_draw ('margin')
* draw_rectangle1 (3600, Row11, Column11, Row2, Column2)
*绘制要仿射变换跟随的区域
gen_rectangle1 (Rectangle, 817, 344, 926, 753)
* Code generated by Image Acquisition 01
list_files ('C:/ͼƬ', ['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
*对实时图像进行阈值分割并连通性操作
threshold (Image, Regions, 218, 255)
connection (Regions, ConnectedRegions)
*通过圆度和面积筛选出中心大圆
select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [105394,0.9315], [228945,1])
*填充孔洞
fill_up (SelectedRegions, RegionFillUp)
*计算实时图像大圆中心
area_center (RegionFillUp, Area2, Row2, Column2)
*根据实时图像中心和原图像中心来计算仿射变换矩阵
vector_angle_to_rigid (Row1, Column1, 0, Row2, Column2, 0, HomMat2D)
*根据仿射变换矩阵对要进行仿射变换的矩阵区域进行仿射变换
affine_trans_region (Rectangle, RegionAffineTrans, HomMat2D, 'false')
endfor