内容源自:
*对目标进行排序
*http://www.ihalcon.com/read-15537.html
重点关注:
union1 (SelectedRegions, RegionUnion) ///区域合并
sort_region (RegionAffineTrans, SortedRegions, 'character', 'true', 'row') ///排序
完整的源码:
*对目标进行排序
*http://www.ihalcon.com/read-15537.html
dev_close_window()
dev_update_off()
read_image (Image, '对目标进行排序.bmp')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width/1.5, Height/1.5, 'black', WindowHandle)
dev_display (Image)
threshold (Image, Region, 0, 30)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 200, 600)
union1 (SelectedRegions, RegionUnion) ///区域合并
smallest_rectangle2 (RegionUnion, Row, Column, Phi, Length1, Length2)
gen_rectangle2_contour_xld (Rectangle, Row, Column, Phi, Length1, Length2)
vector_angle_to_rigid (Row, Column, 0, Row, Column, -Phi, HomMat2D)
vector_angle_to_rigid (Row, Column, 0, Row, Column, Phi, HomMat2D1)
affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
affine_trans_region (SelectedRegions, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
sort_region (RegionAffineTrans, SortedRegions, 'character', 'true', 'row') ///排序
affine_trans_region (SortedRegions, RegionAffineTrans1, HomMat2D1, 'nearest_neighbor')
dev_display (Image)
count_obj (RegionAffineTrans1, Number)
for i:=1 to Number by 1
select_obj (RegionAffineTrans1, ObjectSelected, i)
area_center (ObjectSelected, Area, Row1, Column1)
dev_disp_text (i, 'image', Row1, Column1, 'red', 'box', 'false')
endfor