此例程为测量芯片引脚的数量、平均宽度以及引脚高度
1、读取图片
dev_close_window ()
read_image (Image, 'ic_pin')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
2、画出一个测量矩形
Row := 47
Column := 485
Phi := 0
Length1 := 420
Length2 := 10
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
*Length1 Length2为半宽半高
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*形成一个测量矩形
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
3、开始测量----显示结果
*更新PC为off状态
dev_update_pc ('off')
*更新变量为off状态
dev_update_var ('off')
n := 100
*计算开始时间
count_seconds (Seconds1)
*这个循环是对每一个引脚进行测量
for i := 1 to n by 1
*得出测量结果
measure_pairs (Image, MeasureHandle, 1.5, 30, 'negative', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, PinWidth, PinDistance)
endfor
count_seconds (Seconds2)
Time := Seconds2 - Seconds1
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_set_color ('red')
*为了把检测到的引脚的边缘对用直线都画出来
disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond)
*求引脚平均宽度
avgPinWidth := sum(PinWidth) / |PinWidth|
*求引脚边缘对的平均距离
avgPinDistance := sum(PinDistance) / |PinDistance|
*求得引脚边缘对的数量
numPins := |PinWidth|
dev_set_color ('yellow')
disp_message (WindowHandle, 'Number of pins: ' + numPins, 'image', 200, 100, 'yellow', 'false')
disp_message (WindowHandle, 'Average Pin Width: ' + avgPinWidth, 'image', 260, 100, 'yellow', 'false')
disp_message (WindowHandle, 'Average Pin Distance: ' + avgPinDistance, 'image', 320, 100, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\pins_result')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
4、放大部分区域
*绘制这个矩形就是想放大这部分引脚图像
disp_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
stop ()
dev_set_part (Row1, Column1, Row2, Column2)
dev_display (Image)
dev_set_color ('green')
dev_display (Rectangle)
dev_set_color ('red')
disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
close_measure (MeasureHandle)
5、 进行引脚的高度测量
dev_set_part (0, 0, Height - 1, Width - 1)
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_set_color ('green')
* draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
Row := 508
Column := 200
Phi := -1.5708
Length1 := 482
Length2 := 35
*形成一个矩形区域 进行引脚高度测量
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*形成一个测量矩形
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
stop ()
*测量边缘间的距离
measure_pos (Image, MeasureHandle, 1.5, 30, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
*上面引脚的高度
PinHeight1 := RowEdge[1] - RowEdge[0]
*下面引脚的高度
PinHeight2 := RowEdge[3] - RowEdge[2]
dev_set_color ('red')
*绘制直线
disp_line (WindowHandle, RowEdge, ColumnEdge - Length2, RowEdge, ColumnEdge + Length2)
disp_message (WindowHandle, 'Pin Height: ' + PinHeight1, 'image', RowEdge[1] + 40, ColumnEdge[1] + 100, 'yellow', 'false')
disp_message (WindowHandle, 'Pin Height: ' + PinHeight2, 'image', RowEdge[3] - 120, ColumnEdge[3] + 100, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\pins_height_result')
close_measure (MeasureHandle)
dev_set_draw ('fill')
dev_set_line_width (1)
生成测量矩形
gen_measure_rectangle2( : : Row, Column, Phi, Length1, Length2, Width, Height, Interpolation : MeasureHandle)Row, Column,Phi:测量矩形中心的行列坐标和角度;
Length1, Length2:测量矩形的板宽和半高;
Width, Height:测量矩形所在的图像的宽和高;
Interpolation:插值算法
MeasureHandle:测量矩形的句柄
不带边缘对查找
measure_pos(Image : : MeasureHandle, Sigma, Threshold, Transition, Select : RowEdge, ColumnEdge, Amplitude, Distance)MeasureHandle:测量矩形的句柄;
Sigma:高斯平滑系数;
Threshold:最小边缘幅度;
Transition:过度,亮到暗’negative’, 暗到亮’positive’,两种都要’all’
Select :如果设置为’all’,则返回所有边缘点。 如果将其设置为’ first’,则仅返回提取的边缘点中的第一个,而将其设置为’last’时,仅返回最后一个。
RowEdge, ColumnEdge:边缘点行列坐标
Amplitude:返回边缘幅度
Distance:返回连续边之间的距离