注意:此文未设置vip免费功能,如若显示,为csdn自动设置,是挺烦人的。
自己画一蟹线段:
opening_rectangle1之所以能获取网格中的竖线,是因为开运算具有“保持与结构元素同向特征,滤除异向特征”的特性。
参考:27.1、形态学---开运算、闭运算原理 - ihh2021 - 博客园
代码:
*读取一张图像 read_image (Image, 'D:/程序/Halcon程序/找线段交叉点/test.jpg') *获取图像大小 get_image_size (Image, Width, Height) *关闭已经打开的窗口 dev_close_window () *打开新窗口 dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle) *对图像均值滤波,滤波核大小3*3 mean_image(Image, ImageMean, 3, 3) *对图像均值滤波,滤波核大小12*12 mean_image(Image, ImageMean2, 12, 12) *通过局部阈值分割出网格区域 dyn_threshold(ImageMean, ImageMean2, RegionDynThresh, 5, 'dark') *对网格区域进行连通处理 connection(RegionDynThresh, ConnectedRegions) *过滤出网格区域 select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 150, 50000) *开运算,获取网格竖线 opening_rectangle1(SelectedRegions, RegionOpening1, 1, 10) *开运算,获取网格横线 opening_rectangle1(SelectedRegions, RegionOpening2, 10, 1) *交集运算,获取横线和竖线的交点 intersection(RegionOpening1, RegionOpening2, RegionIntersection) *对交点区域进行连通处理 connection(RegionIntersection, ConnectedRegions1) *获取交点的坐标位置:行,列坐标 area_center (ConnectedRegions1, Area, Row, Column) *显示图像 dev_display (Image) *显示网格交点 dev_display (ConnectedRegions1)引用:【愚公系列】2023年04月 Halcon机器视觉-15种常用缺陷检测实例_halcon例子-CSDN博客
效果: