本人在我要自学网里发现一个好的教程,里面有一个案例我跟着做了一遍,也做了些总结。有张图如下:
要求:求矩形块的平均宽度。
涉及知识点:图像采集、blob分析、检测边缘等
直接上代码:
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_update_off ()
*开始时间
count_seconds (T1)
*blob分析挑选出测量区域(形状特征的选择)
read_image (Image1, 'F:/2018~2019大三/图像处理/素材/halcon视频教程素材/6-8/1.bmp')
*判断通道数,若为3通道,则对图像灰度化
count_channels (Image1, Channels)
if (Channels==3)
rgb1_to_gray (Image1, Image1)
endif
threshold (Image1, Region, 128, 255)
connection (Region, ConnectedRegions)
*形状选择
select_shape (ConnectedRegions, SelectedRegions, ['rect2_len1','rect2_len2'], 'and', [100,50], [150,80])
select_shape (SelectedRegions, SelectedRegions1, 'convexity', 'and', 0.8, 1)
count_obj (SelectedRegions1, Number)