*传入第一张图片做模板 read_image (Image, 'C:/Users/Maxwell/Desktop/模板匹配testimage/1.jpg') rgb1_to_gray (Image, GrayImage) dev_open_window (0, 0, 512, 512, 'black', WindowHandle) dev_display (GrayImage) dev_set_draw ('margin') *draw_rectangle2 (WindowHandle, Row1, Column1, Phi, Length1, Length2) gen_rectangle2 (Rectangle, 2258.64, 893.313, -0.0, 228.375, 179.435) reduce_domain (GrayImage, Rectangle, ImageReduced) create_shape_model (ImageReduced, 'auto', rad(0),rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID) row1:=2468 col1:=1396 row2:=2517 col2:=2918 gen_region_line (RegionLines, row1, col1, row2, col2) * Image Acquisition 01: Code generated by Image Acquisition 01 list_files ('C:/Users/Maxwell/Desktop/模板匹配testimage', ['files','follow_links'], ImageFiles) tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles) for Index := 0 to |ImageFiles| - 1 by 1 dev_set_color ('green') dev_set_line_width (3) read_image (Image_t, ImageFiles[Index]) rgb1_to_gray (Image_t, GrayImage_t) find_shape_model (GrayImage_t, ModelID, rad(0), rad(360), 0.1, 1, 0.5, 'least_squares', 0, 0.5, Row, Column, Angle, Score) vector_angle_to_rigid (2258.64, 893.313, 0, Row, Column, Angle, HomMat2D) affine_trans_region (Rectangle, RegionAffineTrans, HomMat2D, 'nearest_neighbor') * 卡尺找直线 affine_trans_point_2d (HomMat2D, row1, col1, row1_t, col1_t) affine_trans_point_2d (HomMat2D, row2, col2, row2_t, col2_t) Lineparam:=[row1_t, col1_t, row2_t, col2_t] gen_region_line (RegionLines, row1_t, col1_t, row2_t, col2_t) * 创建测量句柄 create_metrology_model (MetrologyHandle) * 设置计量模型图像大小 get_image_size (GrayImage, Width, Height) set_metrology_model_image_size (MetrologyHandle, Width, Height) * 卡尺高 卡尺宽 sigma 阈值 add_metrology_object_generic (MetrologyHandle, 'line', Lineparam, 150, 3, 1, 10, \ 'measure_transition', 'positive', Index1) * 执行测量,获取边缘点集 apply_metrology_model (GrayImage, MetrologyHandle) get_metrology_object_measures (Contours1, MetrologyHandle, 'all', 'all', Row1, Column1) *获取找到的点位 gen_cross_contour_xld (Cross1, Row1, Column1, 6, 0.785398) * 获取最终测量数据和轮廓线 *获取结果 get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter) *划线 get_metrology_object_result_contour (ContourOut1, MetrologyHandle, 'all', 'all', 1.5) *将轮廓拟合成线 fit_line_contour_xld (ContourOut1, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist) * 释放测量句柄 clear_metrology_object (MetrologyHandle, 'all') dev_set_color ('blue') dev_display (GrayImage_t) dev_display (RegionAffineTrans) dev_display (ContourOut1) endfor