在
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)
显示效果如下:
本文通过实例演示了如何使用Halcon进行图像处理,包括计算特定形状的数量、选择并定位特定对象,以及解决圆对象未按预期排序的问题。
计数与排序&spm=1001.2101.3001.5002&articleId=9384673&d=1&t=3&u=183864d373884aca8f0185679bad2090)
3257

被折叠的 条评论
为什么被折叠?



