因为太多的博客并没有深入理解,本文是自己学习后加入自己深入理解的总结记录,方便自己以后查看
Halcon模板匹配、阈值分割、仿射变换的运用
学习前言
一起来学习Halcon做实战项目---螺丝检测
参考链接:无
一、检测出下图中螺丝的有无
。
二、算法流程思路
- BGRToGrey
- 做高斯变换算法平滑(效果不理想)
- 像素特征提取映射(0-20,20-255)
- 整个物体特征轮廓提取做精定位确定每个孔位置(图片不完善)
- 模板匹配卷积平滑匹配无螺丝时候的孔特征,得到无螺丝匹配分数
- 模板匹配卷积平滑匹配有螺丝时候的十字特征,得到有螺丝匹配分数
- 确定螺丝孔直径20piex内的像素平均值,低像素比例值
- 通过设置无螺丝匹配分数范围,有螺丝匹配分数范围,像素平均值范围,低像素比例值范围确定有无螺丝结果
- 结果显示仿射变换
注意点:
1、如果上线后图片阈值波动较大,换成使用检测区域平均像素来做直方图分割
1.创建模板代码
dev_close_window ()
dev_update_off ()
********创建模型**********
read_image (Image, 'D:/AllLargeProject/找螺丝项目/InputImage/1.jpg')
rgb1_to_gray (Image, Image)
get_image_size (Image, Width, Height)
threshold (Image, Region1, 1, 20)
*binary_threshold (Image, Region1, 'max_separability', 'dark', UsedThreshold)
*region_to_mean (Region1, Image, Region1)
region_to_bin (Region1, Image, 255, 0, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
*选取模型区域(模型效果不好时可以自己画出模型特征图后再建)
draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (Image, Rectangle, ImageReduced)
threshold (ImageReduced, Region, 0, 30)
connection (Region, ConnectedRegions)
area_center (ConnectedRegions, Area, Row3, Column3)
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
dilation_circle (SelectedRegions, RegionDilation, 5.5)
fill_up (RegionDilation, RegionFillUp)
reduce_domain (ImageReduced, RegionFillUp, ImageReduced2)
ImageReduced:=ImageReduced2
inspect_shape_model (ImageReduced, ModelImages, ModelRegions, 8, 30)
*创建模型
create_scaled_shape_model (Ima

本文详细介绍了如何使用Halcon进行螺丝检测,包括图像预处理、模板匹配、特征提取和仿射变换,以确定螺丝的存在并定位孔的位置。
最低0.47元/天 解锁文章
6812

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



