一、电路检测
算子解释
dyn_threshold
*dyn_threshold 利用局部阈值分割图像*OrigImage (input_object):原始图像*ThresholdImage (input_object):处理后图像(一般采用滤波处理)*RegionDynThresh (output_object):分割后区域*Offset (input_control):灰度值偏移量。*LightDark (input_control):提取区域类型( ‘dark’, ‘equal’, ‘light’, ‘not_equal’)
dyn_threshold (ImageOpening, ImageClosing, RegionDynThresh, 75, 'not_equal')
原理介绍
halcon 源码
* 电路检测方案
read_image (Image, 'pcb')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
* 开闭图像做减法 得到不同的区域gray_opening_shape (Image, ImageOpening, 7, 7, 'octagon')
gray_closing_shape (Image, ImageClosing, 7, 7, 'octagon')*dyn_threshold 局部区域阈值*OrigImage (input_object):原始图像*ThresholdImage (input_object):处理后图像(一般采用滤波处理)*RegionDynThresh (output_object):分割后区域*Offset (input_control):灰度值偏移量。*LightDark (input_control):提取区域类型( ‘dark’, ‘equal’, ‘light’, ‘not_equal’)
dyn_threshold (ImageOpening, ImageClosing, RegionDynThresh, 75, 'not_equal')
dev_display (Image)
dev_set_color ('red')
dev_set_draw ('margin')
dev_display (RegionDynThresh)
二、毛刺检测
算子解释
*用二进制阈值来分割图像。*Image:需要进行阈值的图像*Region:处理后的区域 输出*Method:分割方法('max_separability':最大限度的可分性, 'smooth_histo':直方图平滑)*LightDark:提取的是黑色部分还是白色部分*当LightDark=light,max_separability选的区域比smooth_histo少一点*当LightDark=dark,max_separability选的区域比smooth_histo多一点*UsedThreshold:自动阈值使用的阈值binary_threshold (Fin, Background, 'max_separability', 'light', UsedThreshold)
halcon 源码
* 毛刺检测案例
*思路:通过二值化将图像分开,然后消除减小区域 ,最后做区域的减法 显示
dev_update_window ('off')
read_image (Fins, 'fin' + [1:3])
get_image_size (Fins, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width[0], Height[0], 'black', WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
for I := 1 to 3 by 1select_obj (Fins, Fin, I)dev_display (Fin)*用二进制阈值来分割图像。*Image:需要进行阈值的图像*Region:处理后的区域 输出*Method:分割方法('max_separability':最大限度的可分性, 'smooth_histo':直方图平滑)*LightDark:提取的是黑色部分还是白色部分*当LightDark=light,max_separability选的区域比smooth_histo少一点*当LightDark=dark,max_separability选的区域比smooth_histo多一点*UsedThreshold:自动阈值使用的阈值binary_threshold (Fin, Background, 'max_separability', 'light', UsedThreshold)dev_set_color ('blue')dev_set_draw ('margin')dev_set_line_width (4)dev_display (Background)disp_continue_message (WindowID, 'black', 'true')stop ()*用圆形区域进行闭运算,能达到保留圆弧边,消除毛刺效果closing_circle (Background, ClosedBackground, 250)dev_set_color ('green')dev_display (ClosedBackground)disp_continue_message (WindowID, 'black', 'true')stop ()*背景差分,得出不同点difference (ClosedBackground, Background, RegionDifference)*用矩形开操作去除小点,保留真正的差异点opening_rectangle1 (RegionDifference, FinRegion, 5, 5)dev_display (Fin)dev_set_color ('red')dev_display (FinRegion)*得到真正差异点的面积和中心点area_center (FinRegion, FinArea, Row, Column)if (I < 3)disp_continue_message (WindowID, 'black', 'true')stop ()endif
endfor