* In this example five different color fuses are segmented with * a look-up table classifier (LUT) based on a Gaussian Mixture * Model (GMM). *基于高斯混合模型查找表分类器,用于颜色分割匹配 * dev_update_off () dev_close_window () dev_open_window (0, 0, 800, 600, 'white', WindowHandle) dev_set_draw ('margin') ImageRootName := 'color/color_fuses_0' *保险丝类型 橘色5A 红色10A 蓝色15A 黄色20A 绿色30A FuseTypes := [5,10,15,20,30] *保险丝颜色 FuseColors := ['橘色','红色','蓝色','黄色','绿色'] FuseHighlight := ['orange','red','blue','goldenrod','forest green'] DisplayTextShift := [85,65,75,85,85] dev_set_color ('white') dev_set_line_width (2) read_image (Image, ImageRootName + '0') dev_display (Image) * * Define ROIs for the training data of the classifier *获取(标记)分类器训练数据区域 set_display_font (WindowHandle, 14, 'mono', 'true', 'false') gen_rectangle1 (FuseOrange, 195, 90, 230, 120) dev_display (FuseOrange) disp_message (WindowHandle, '橘色保险丝', 'image', 160, 90 - 65, 'black', 'false') gen_rectangle1 (FuseRed, 191, 280, 226, 310) dev_display (FuseRed) disp_message (WindowHandle, '红色保险丝', 'image', 160, 280 - 55, 'black', 'false') gen_rectangle1 (FuseBlue, 190, 470, 225, 500) dev_display (FuseBlue) disp_message (WindowHandle, '蓝色保险丝', 'image', 160, 470 - 60, 'black', 'false') gen_rectangle1 (FuseYellow, 192, 672, 227, 702) dev_display (FuseYellow) disp_message (WindowHandle, '黄色保险丝', 'image', 160, 672 - 70, 'black', 'false') gen_rectangle1 (FuseGreen, 197, 880, 232, 910) dev_display (FuseGreen) disp_message (WindowHandle, '绿色保险丝', 'image', 160, 880 - 65, 'black', 'false') *创建分类器中类别 gen_empty_obj (Classes) concat_obj (FuseOrange, FuseRed, Classes) concat_obj (Classes, FuseBlue, Classes) concat_obj (Classes, FuseYellow, Classes) concat_obj (Classes, FuseGreen, Classes) disp_message (WindowHandle, '训练数据标记完成', 'window', 12, 12, 'orange', 'false') disp_continue_message (WindowHandle, 'black', 'false') stop () * * Create the GMM classifier, add the samples, and train it *创建高斯混合模型,添加训练样本以及训练 *创建含5个类的高斯混合模型分类器 create_class_gmm (3, 5, 1, 'full', 'none', 3, 42, GMMHandle) add_samples_image_class_gmm (Image, Classes, GMMHandle, 0) disp_message (WindowHandle, 'GMM分类器训练中……', 'window', 48, 12, 'black', 'true') train_class_gmm (GMMHandle, 100, 0.001, 'training', 0.001, Centers, Iter) * * 创建基于高斯混合模型的查找表分类器 disp_message (WindowHandle, '创建基于高斯混合模型的查找表分类器...', 'window', 84, 12, 'black', 'true') create_class_lut_gmm (GMMHandle, ['bit_depth','rejection_threshold'], [6,0.03], ClassLUTHandle) * * Segment images with LUT classifier *基于GMM查找表分类器分割图像 for Img := 0 to 3 by 1 read_image (Image, ImageRootName + Img) count_seconds (T1) classify_image_class_lut (Image, ClassRegions, ClassLUTHandle) count_seconds (T2) TimeToClassify := (T2 - T1) * 1000 dev_display (Image) dev_set_line_width (3) for Fuse := 1 to 5 by 1 * * Perform post-processing on returned classes *返回结果进行后处理 copy_obj (ClassRegions, ObjectsSelected, Fuse, 1) closing_circle (ObjectsSelected, RegionClosing, 3.5) connection (RegionClosing, ConnectedRegions) select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 2500, 99999) fill_up (SelectedRegions, RegionFillUp) area_center (RegionFillUp, Area, Row, Column) shape_trans (RegionFillUp, RegionTrans, 'convex') dev_set_color (FuseHighlight[Fuse - 1]) dev_display (RegionTrans) * disp_message (WindowHandle, FuseColors[Fuse - 1] + ' ' + FuseTypes[Fuse - 1] + ' A', 'image', Row - 10, Column - DisplayTextShift[Fuse - 1], FuseHighlight[Fuse - 1], 'white') endfor disp_message (WindowHandle,'用时'+TimeToClassify$'.1f' + ' ms', 'window', 12, 12, 'black', 'false') if (Img < 3) disp_continue_message (WindowHandle, 'black', 'false') stop () endif endfor * disp_message (WindowHandle, '执行完成', 'window', 50, 12, 'black', 'false')
1.样本标注
2.高斯混合模型训练
3.创建基于GMM的查找表分类器
4.分类结果
标签:disp,保险丝,WindowHandle,dev,分类器,查找,black,message From: https://www.cnblogs.com/echo-efun/p/18060288