基于Halcon学习的基于相关性模板匹配【一】find_ncc_model_exposure.hdev例程

基于Halcon学习的基于相关性模板匹配【一】find_ncc_model_exposure.hdev例程_第1张图片

* 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.

*此示例程序显示如何使用HALCON的基于相关性的匹配。特别是,它证明了该方法对
*线性照明变化。培训是在具有良好效果的图像中进行的照明。
*匹配应用于曝光时间变化的图像从非常短到非常长的极端

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)
*获得该区域的面积
area_center (Circle, Area, RowRef, ColumnRef)
reduce_domain (Image, Circle, ImageReduced)
*准备一个NCC模型以进行匹配。
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')
    *金字塔层数越多搜索越快  
    *在图像中查找NCC模型的最佳匹配项。
    find_ncc_model (Image, ModelID, 0, 0, 0.5, 1, 0.5, 'true', 0, Row, Column, Angle, Score)
   *所有的仿射变换都是为了显示用的
   *将每一幅图像识别到的目标的行坐标放到Rows这个数组中去
    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)
*清除模型
clear_ncc_model (ModelID)

 

你可能感兴趣的:(Halcon学习笔记,#,模板匹配,图像处理,图像识别,算法)