基於形狀的模板匹配的一個實例

按照上篇講的套路,我們再來實現一個例子

這裏有如下原圖

找出所有的格子

一、選取區域

二、創建模板

創建後,模板的座標爲(0,0),即左上角

三、尋找模板

 

代碼:

* Many dies are typically etched on a wafer. Before the single
* dies can be picked by a die bonder and placed onto a lead
* frame, they must be diced from the wafer. Mirror dies are
* used to determine the parameters of the dicing process.
* Here, the positions of the mirror dies are determined using
* shape-based matching.
* 
dev_update_off ()
dev_close_window ()
read_image (Image, 'wafer/wafer_mirror_dies_01')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_display (Image)
disp_message (WindowHandle, 'Determine the position of mirror dies on the wafer', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Create a shape model of the mirror dies
gen_rectangle1 (Rectangle, 362, 212, 414, 262)
reduce_domain (Image, Rectangle, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(0), rad(1), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
* 
* Read the images and process them
for Index := 1 to 4 by 1
    read_image (Image, 'wafer/wafer_mirror_dies_' + Index$'02')
    * 
    * Determine the position of the mirror dies and
    * calculate the runtime needed to find the positions
    count_seconds (S1)
    find_shape_model (Image, ModelID, rad(0), rad(1), 0.5, 0, 0.0, 'least_squares', 2, 0.5, Row, Column, Angle, Score)
    count_seconds (S2)
    Runtime := (S2 - S1) * 1000
    * 
    * Display the results
    gen_cross_contour_xld (Cross, Row, Column, 6, rad(45))
    dev_display (Image)
    dev_display_shape_matching_results (ModelID, 'lime green', Row, Column, Angle, 1, 1, 0)
    dev_set_color ('orange')
    dev_display (Cross)
    disp_message (WindowHandle, |Score| + ' mirror dies located in ' + Runtime$'.1f' + ' ms', 'window', 12, 12, 'black', 'true')
    if (Index != 4)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
* 
* Clear the model
clear_shape_model (ModelID)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章