Halcon例程分析5:芯片測量

打開halcon,按下ctrl+e打開halcon自帶例程。工業領域->半導體業->measure_pin.hdev

* Pin Measurement: Example for the application of the measure package
* including a lot of visualization operators
* 
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 ()
* draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
*定義變量
Row := 47
Column := 485
Phi := 0
Length1 := 420
Length2 := 10
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
*畫矩形ROI,可以通過圖片窗口上的繪製ROI->繪製軸平行矩形->插入代碼進行繪製
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*應用上面繪製的矩形ROI區域生成測量矩形
*前五個參數爲上面繪製的矩形ROI的數值,
*第六第七個參數爲圖像的寬高
*第八個參數是數據插值方法,這裏採用最近鄰插值方式
*第九個參數是測試句柄,後面通過這個句柄引用這個矩形測量
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_update_pc ('off')
dev_update_var ('off')
n := 100
*計算算法耗時
count_seconds (Seconds1)
*下面這個循環不知道是什麼意思,去掉這個循環(只測一次)同樣可以測量出結果來
for i := 1 to n by 1
    *下面這個函數是提取與測試矩形垂直方向上的的邊緣對,想象一下在矩形長軸方向上做灰度差分,得到的曲線應該是每個一段距離出現一個上尖角與一個下尖角
    *第一個上尖角的X座標RowEdgeFirst,第一個上尖角的Y座標ColumnEdgeFirst
    *第一個下尖角的X座標RowEdgeSecond,第一個下尖角的Y座標ColumnEdgeSecond
    
    *第一個參數輸入圖像
    *第二個參數測量矩形的句柄
    *第三個參數(1.5)是高斯平滑sigma值
    *第四個參數(30)是最低閾值,對應上述尖角的高度值
    *第五個參數('negative')是上述差分值的黑白方向,爲negative時是白到黑爲第一點,如果是爲positive時爲黑到白爲第一點
    *第六個參數是('all')是返回所有的測量到的值,即返回所有的尖角位置
    *第九個參數(AmplitudeFirst)是第一個尖角的大小
    *(PinwWidth)是上尖角與下尖角之間的距離
    *(PinDistance)是下尖角與上尖角之間的距離
    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)
*所有Pin腳寬度取平均值,間距取平均值
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 ()
* draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
Row1 := 0
Column1 := 600
Row2 := 100
Column2 := 700
dev_set_color ('blue')
*下面是爲放大顯示用的,畫一個矩形,把矩形框內的區域放大顯示方便查看
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 ()
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_pair差不多的,同樣是得到像素差分的曲線
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')
dev_set_draw ('fill')
dev_set_line_width (1)

待測試芯片原圖

測試引腳寬度與間距圖像

測試芯片引腳高度效果圖

發佈了60 篇原創文章 · 獲贊 8 · 訪問量 9689
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章