下载 | 基恩士中国官方网站 (keyence.com.cn)
打开LJ-X Navigator ,选择设定——PC通信设定,弹出下面对话框:现在的IP地址是192.168.0.1,需要把电脑对应的端口IP设置在同一个字段。
点击实时设定弹出对话框
分三步走:
一. 触发设定,设置采样周期,触发间距,批处理点数;
二. 拍摄设定,测量范围包括X方向和Z方向,相当于感兴趣区域,尽量把轮廓线调整到中间位置。需要注意的是,点击图像连续更新才会实时采集图像。
Z方向范围和曝光模式都会影响采样频率,LJ-X的测量速度是60mm/s。这些都设置完成后点击完成。
需要注意的是,这个软件只能打开.lhix文件,但是保存的文件格式有多种,如果halcon可以处理TIFF文件,选择这个格式会保存两张图像,一张是高度图,而另一张是亮度图。
*圆周焊方法1
detect_col:=1068
detect_row:=100
detect_phi:=0
detect_length1:=2
detect_length2:=2
detect_offset:=-96
std1_col:=100
std1_row:=100
std1_phi:=0
std1_length1:=2
std1_length2:=2
std1_offset:=-105
std2_col:=100
std2_row:=100
std2_phi:=0
std2_length1:=2
std2_length2:=2
std2_offset:=-80
set_display_font (3600, 26, 'mono', 'true', 'false')
dev_update_off ()
for Index1 := 1 to 38 by 1
*读取高度图
read_image (Image1,'漏焊'+Index1)
*读取亮度图
read_image (Image1ngLuminance, '漏焊'+Index1+'_luminance')
*分割电池区域图像
threshold (Image1, Regions, 2756, 65535)
fill_up (Regions, RegionFillUp)
reduce_domain (Image1, RegionFillUp, ImageReduced)
*得到电池边缘区域
boundary (RegionFillUp, RegionBorder, 'inner')
*电池区域的最小外接矩形
smallest_rectangle1 (RegionBorder, Row1, Column1, Row2, Column2)
*区域差集得到电池上盖板边缘区域
gen_rectangle1 (Rectangle1, Row1-1, Column1-1, Row1+1, Column2+1)
gen_rectangle1 (Rectangle2, Row2-1, Column1-1, Row2+1, Column2+1)
difference (RegionBorder, Rectangle1, RegionDifference)
difference (RegionDifference, Rectangle2, RegionDifference2)
connection (RegionDifference2, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'column', 'and', 14.4, 500)
*获取上盖板边缘区域中所有点坐标
get_region_points (SelectedRegions, Rows, Columns)
*对高度图做一次均值滤波,可以屏蔽
mean_image (Image1, ImageMean, 1, 1)
get_image_size (Image1, Width, Height)
meanDetect:=[]
meanStd1:=[]
meanStd2:=[]
meanDifference:=[]
deviation_detect:=[]
gen_empty_obj (detect_rect) //测量矩形
gen_empty_obj (std1_rect) //基准1矩形
gen_empty_obj (std2_rect) //基准2矩形
for I := 0 to |Columns|-1 by 1
*创建测量矩形
gen_rectangle2 (Rect_dectect, detect_row+I*1,Columns[I]+detect_offset, detect_phi,detect_length1, detect_length2)
*计算测量矩形内所有点平均高度值
intensity (Rect_dectect, ImageMean, Mean_dectect, Deviation1)
*创建基准1矩形
gen_rectangle2 (Rect_std1, std1_row+I*1,Columns[I]+std1_offset, std1_phi,std1_length1, std1_length2)
*计算测量矩形内所有点平均高度值
intensity (Rect_std1, ImageMean, Mean_std1, Deviation2)
*创建基准2矩形
gen_rectangle2 (Rect_std2, std2_row+I*1,Columns[I]+std2_offset, std2_phi,std2_length1, std2_length2)
*计算测量矩形内所有点平均高度值
intensity (Rect_std2, ImageMean, Mean_std2, Deviation2)
*判断是否漏焊
if ((Mean_std1 + Mean_std2)/2 > Mean_dectect + 20)
concat_obj (Rect_dectect, detect_rect, detect_rect)
concat_obj (Rect_std1, std1_rect, std1_rect)
concat_obj (Rect_std2, std2_rect, std2_rect)
endif
endfor
union1 (detect_rect, RegionUnion)
dilation_rectangle1 (RegionUnion, RegionDilation, 1, 1)
*显示亮度图是为了便于观察
dev_display (Image1ngLuminance)
dev_display (RegionDilation)
dev_set_draw ('fill')
dev_display (RegionDilation)
disp_message (3600, Index1, 'window', 12, 12, 'black', 'true')
stop()
endfor
dev_update_on ()
包括图像资源,代码资源。
https://download.csdn.net/download/weixin_38566632/24413279