天天看點

Halcon區域region的周遊,合并,旋轉與排序

内容源自:

*對目标進行排序

*http://www.ihalcon.com/read-15537.html

Halcon區域region的周遊,合并,旋轉與排序

重點關注:

union1 (SelectedRegions, RegionUnion) ///區域合并

sort_region (RegionAffineTrans, SortedRegions, 'character', 'true', 'row') ///排序

完整的源碼:

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)

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')

affine_trans_region (SortedRegions, RegionAffineTrans1, HomMat2D1, 'nearest_neighbor')

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

---

引申閱讀:

Halcon學習(6)計數與排序

http://www.skcircle.com/?id=91

sort_contours_xld算子的幾種排序方式研究

https://www.cnblogs.com/xh6300/p/6536467.html

繼續閱讀