在
1、count_obj
2、assign
例:
区别
在众多区域中选择输出的算子是
select_obj
在halcon学习(三)种加入select_obj算子,并显示第三个焊接点所在的圆的位置。这里我们发现一个问题。圆不是按坐标位置排列的。可以考虑算子
程序如下:
reduce_domain(Die, ROI, DieROI)
threshold(DieROI, RawSegmentation,0,50)
fill_up_shape(RawSegmentation, Wires, 'area', 1, 100)
opening_circle(Wires, BallRegion, 15.5)
connection(BallRegion, Balls)
select_shape(Balls, FinalBalls, 'circularity', 'and', 0.85, 1.0)
count_obj(FinalBalls,NumBalls)
select_obj (FinalBalls, ObjectSelected,3)
smallest_circle(ObjectSelected, Row, Column, Radius)
meanRadius := sum(Radius)/|Radius|
area_center(FinalBalls, Area, RowCenter, Colcenter)
minArea := min(Area)
disp_circle (WindowID, Row, Column, Radius)
这里我们发现一个问题。圆不是按坐标位置排列的。我们想显示的是第3个圆,可是显示的是第5个圆。可以考虑算子
sort_region(Regions : SortedRegions : SortMode, Order, RowOrCol : )
根据他们的位置关系进行排序
修改程序如下:
dev_close_window ()
dev_open_window(0, 0, -1, -1, 'black', WindowID)
read_image(Die, 'E:/halcon图像/die_03.png')
dev_display(Die)
threshold(Die, Brightregion,100,255)
shape_trans(Brightregion, ROI, 'rectangle2')
reduce_domain(Die, ROI, DieROI)
threshold(DieROI, RawSegmentation,0,50)
fill_up_shape(RawSegmentation, Wires, 'area', 1, 100)
opening_circle(Wires, BallRegion, 15.5)
connection(BallRegion, Balls)
select_shape(Balls, FinalBalls, 'circularity', 'and', 0.85, 1.0)
sort_region (FinalBalls, SortedRegions, 'upper_left', 'true', 'column')
count_obj(SortedRegions,NumBalls)
select_obj (SortedRegions, ObjectSelected,3)
smallest_circle(ObjectSelected, Row, Column, Radius)
meanRadius := sum(Radius)/|Radius|
area_center(SortedRegions, Area, RowCenter, Colcenter)
minArea := min(Area)
disp_circle (WindowID, Row, Column, Radius)
显示效果如下: