当前位置:
首页
文章
前端
详情

Halcon区域region的合并,旋转与排序

内容源自:

*对目标进行排序
*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

免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。