程序调用十张不同光照下的图片,尝试找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 () gen_circle (Circle, 246, 336, 150) area_center (Circle, Area, RowRef, ColumnRef) 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) *(1) * 仿射变换,变换圆的位置 vector_angle_to_rigid(RowRef, ColumnRef, Angle, Row, Column, 0, HomMat2D) affine_trans_region(Circle, RegionAffineTrans, HomMat2D, 'nearest_neighbor') Rows := [Rows,Row] Cols := [Cols,Column] dev_display (Image) dev_display(RegionAffineTrans) *(2) * 下面这句被注释掉的和(1)的两句功能都是一样的,启用前请先把(1)的两句注释掉 *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 *计算十张图找ncc模板后的坐标位置的标准差 StdDevRows := deviation(Rows) StdDevCols := deviation(Cols)
结果如下:
这个差别是相当的小,最大差别0.087个像素。
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


