Halcon例程分析14:模板匹配(基於相關性)

打開halcon,按下ctrl+e打開halcon自帶例程。方法->模板匹配(基於相關性)->find_ncc_model_exposure.hdev

ncc模板匹配算法的一個重要特性是光照不敏感

* This example program shows how to use HALCON's correlation-based
* matching. In particular it demonstrates the robustness of this method against
* linear illumination changes.  The training is performed in an image with good
* illumination.  The matching is applied in images where the exposure time varies
* extremely from very short to very long.
read_image (Image, 'cap_exposure/cap_exposure_03')
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_update_off ()
*生成一個圓形ROI區域
gen_circle (Circle, 246, 336, 150)
*圓形ROI的中心座標
area_center (Circle, Area, RowRef, ColumnRef)
*裁剪圖像,保留ROI區域
reduce_domain (Image, Circle, ImageReduced)
*創建模型
*第一個參數輸入圖像
*第二個參數金字塔層數
*第三個參數起始角度
*第四個參數旋轉的角度
*第五個參數角度步長值
*第六個參數極性選擇
create_ncc_model (ImageReduced, 'auto', 0, 0, 'auto', 'use_polarity', ModelID)

dev_set_draw ('margin')
dev_display (Image)
dev_set_color ('yellow')
dev_display (Circle)
disp_message (WindowHandle, 'Trained NCC model', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
Rows := []
Cols := []
for J := 1 to 10 by 1
    read_image (Image, 'cap_exposure/cap_exposure_' + J$'02')
    *查找模板
    find_ncc_model (Image, ModelID, 0, 0, 0.5, 1, 0.5, 'true', 0, Row, Column, Angle, Score)
    Rows := [Rows,Row]
    Cols := [Cols,Column]
    dev_display (Image)
    dev_display_ncc_matching_results (ModelID, 'green', Row, Column, Angle, 0)
    disp_message (WindowHandle, 'Found NCC model', 'window', 12, 12, 'black', 'true')
    if (J < 10)
        disp_continue_message (WindowHandle, 'black', 'true')
    endif
    stop ()
endfor
* Compute the standard deviation of the found positions.  If the individual
* positions in Rows and Cols are examined, it can be seen that the standard
* deviation is caused mainly by the last four images, which are severely
* overexposed.
StdDevRows := deviation(Rows)
StdDevCols := deviation(Cols)

測試模板圖像

 

查找模板圖像

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