*本例子演示了使用变化模板进行打印质量检测,模板用单张图像训练而来。 *在应用检测之前,检测图像被放大或缩小,但是在同样的灰度范围
This example demonstrates the print inspection usinga variation model. The variation model is trainedusing a single model image. Before applying the print inspection,the images are scaled to the same gray value range like the model.*关闭更新 dev_update_off () *关闭窗体 dev_close_window ()
读取模板图像,初始化显示Read model image and init visualization *读取图像 read_image (ModelImage, ‘cap_illumination/cap_illumination_01’) *获取图像尺寸 get_image_size (ModelImage, Width, Height) *打开新窗体 dev_open_window (0, 0, Width / 2, Height / 2, ‘black’, WindowHandle) *设置字体 set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)分割模板区域Segment model region *显示模板图像 dev_display (ModelImage) *获取模板区域 get_model_region (ModelImage, RegionROI, ImageReduced) *求取区域中心和面积 area_center (RegionROI, Area, RowModel, ColumnModel) *设置填充方式 dev_set_draw (‘margin’) *设置显示颜色 dev_set_color (‘green’) *显示区域 dev_display (RegionROI)创建基于形状的模板匹配Create model for shape-based-matching *显示模板生成信息 disp_message (WindowHandle, ‘Model generation…’, ‘window’, 12, 12, ‘black’, ‘true’) *创建可放大缩小的形状模板匹配,范围是0.8-1.2倍都可以。在0-360度范围都可以 create_scaled_shape_model (ImageReduced, ‘auto’, 0, rad(360), ‘auto’, 0.8, 1.2, ‘auto’, ‘auto’, ‘use_polarity’, ‘auto’, ‘auto’, ModelID) *获取模板轮廓 get_shape_model_contours (ModelContours, ModelID, 1)Transform model contours from the original position for visualization hom_mat2d_identity (HomMat2DIdentity) hom_mat2d_translate (HomMat2DIdentity, RowModel, ColumnModel, HomMat2DTranslate) affine_trans_contour_xld (ModelContours, ModelContoursAffineTrans, HomMat2DTranslate)Create variation model for print inspection *创建一个变化模板 create_variation_model (Width, Height, ‘byte’, ‘direct’, VariationID)Generate variation image *创建变化图像 sobel_amp (ModelImage, VarImage, ‘sum_abs’, 5) *准备变化模板,把变化图像和变化模板联系起来 prepare_direct_variation_model (ModelImage, VarImage, VariationID, [20,25], [1.6,1.6])获取变化模板的灰度范围Get gray value range of the variation model get_grayval_range (ModelImage, RegionROI, RegionForeground, RegionBackground, BackgroundGVModel, ForegroundGVModel)执行灰度检测Perform print inspection for I := 1 to 9 by 1 *读取图像 read_image (rImage, ‘cap_illumination/cap_illumination_’ + I$’.2’) *本地函数,检测差异并显示 inspect_cap (rImage, RegionROI, WindowHandle, ModelID, VariationID, RowModel, ColumnModel, BackgroundGVModel, ForegroundGVModel) if (I < 9) disp_continue_message (WindowHandle, ‘black’, ‘true’) stop () endif endfor清除句柄,释放内存 clear_shape_model (ModelID) clear_variation_model (VariationID)