* 此示例程序演示如何应用通用 GMM * 使用“面积”和“圆度”特征区分柑橘类水果的分类。此外,还对提取的水果的 2D 特征空间进行了可视化。 * read_image (Image, 'color/citrus_fruits_01') get_image_pointer1 (Image, Pointer, Type, Width, Height) dev_close_window () dev_open_window (0, 0, Width, Height, 'white', WindowHandle) set_display_font (WindowHandle, 12, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (2) dev_display (Image) dev_update_window ('off') dev_update_pc ('off') dev_update_var ('off') * FeaturesArea := [] FeaturesCircularity := [] ClassName := ['橘子','柠檬'] * * 创建一个高斯混合模型分类器 create_class_gmm (2, 2, 1, 'spherical', 'normalization', 10, 42, GMMHandle) * * 增加训练样本 for I := 1 to 4 by 1 read_image (Image, 'color/citrus_fruits_' + I$'.2d') dev_display (Image) * 获取样本区域 get_regions (Image, SelectedRegions) dev_display (SelectedRegions) count_obj (SelectedRegions, NumberObjects) for J := 1 to NumberObjects by 1 select_obj (SelectedRegions, ObjectSelected, J) get_features (ObjectSelected, WindowHandle, Circularity, Area, RowRegionCenter, ColumnRegionCenter) FeaturesArea := [FeaturesArea,Area] FeaturesCircularity := [FeaturesCircularity,Circularity] *样本圆度和面积特征用于,训练GMM模型 FeatureVector := real([Circularity,Area]) if (I <= 2) *前两张图像为橘子的样本 add_sample_class_gmm (GMMHandle, FeatureVector, 0, 0) disp_message (WindowHandle, '至样本增加:' + ClassName[0], 'window', RowRegionCenter, ColumnRegionCenter - 100, 'white', 'false') else *从第三张图像为柠檬的样本 add_sample_class_gmm (GMMHandle, FeatureVector, 1, 0) disp_message (WindowHandle, '至样本增加:' + ClassName[1], 'window', RowRegionCenter, ColumnRegionCenter - 100, 'white', 'false') endif endfor disp_continue_message (WindowHandle, 'white', 'false') stop () endfor dev_clear_window () * *可视化样本特征空间 visualize_2D_feature_space (Cross, Height, Width, WindowHandle, FeaturesArea[0:5], FeaturesCircularity[0:5], 'orange', 18) * 'oranges', 40, 440 visualize_2D_feature_space (Cross, Height, Width, WindowHandle, FeaturesArea[6:11], FeaturesCircularity[6:11], 'green', 18) * 'lemons', 70, 440 disp_continue_message (WindowHandle, 'white', 'false') stop () * * 训练分类器 train_class_gmm (GMMHandle, 100, 0.001, 'training', 0.0001, Centers, Iter) * * 开始分类 for I := 1 to 15 by 1 read_image (Image, 'color/citrus_fruits_' + I$'.2d') dev_display (Image) * 'Classify Image', 10, 10 get_regions (Image, SelectedRegions) dev_display (SelectedRegions) count_obj (SelectedRegions, NumberObjects) for J := 1 to NumberObjects by 1 select_obj (SelectedRegions, ObjectSelected, J) get_features (ObjectSelected, WindowHandle, Circularity, Area, RowRegionCenter, ColumnRegionCenter) FeaturesArea := [FeaturesArea,Area] FeaturesCircularity := [FeaturesCircularity,Circularity] FeatureVector := real([Circularity,Area]) classify_class_gmm (GMMHandle, FeatureVector, 1, ClassID, ClassProb, Density, KSigmaProb) disp_message (WindowHandle, '得分最高类: ' + ClassName[ClassID], 'window', RowRegionCenter, ColumnRegionCenter - 100,'white', 'false') disp_message (WindowHandle, '得分: ' + KSigmaProb, 'window', RowRegionCenter + 30, ColumnRegionCenter - 100, 'white', 'false') endfor if (I != 15) disp_continue_message (WindowHandle,'white', 'false') endif stop () endfor * * 释放分类器内存 clear_class_gmm (GMMHandle)
1.样本训练
2.样本空间特征统计
3.分类结果
标签:水果,高斯,Image,SelectedRegions,dev,分类器,window,display From: https://www.cnblogs.com/echo-efun/p/18058962