读入图片、显示与显示相关设置
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 := [‘orange’,‘lemon’]
创建一个GMM分类器,这个函数之前的帖子介绍过
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)
构建可视化空间,即二维坐标系
visualize_2D_feature_space (Cross, Height, Width, WindowHandle, FeaturesArea[0:5], FeaturesCircularity[0:5], ‘dim gray’, 18)
dev_set_color (‘black’)
OriginOfGraph := [Height - 0.1 * Height,0.1 * Width]
画箭头
disp_arrow (WindowID, OriginOfGraph[0], OriginOfGraph[1], OriginOfGraph[0], Width - 0.2 * Width, 2)
disp_arrow (WindowID, OriginOfGraph[0], OriginOfGraph[1], 0.1 * Height, OriginOfGraph[1], 2)
显示横纵坐标的名称
set_tposition (WindowID, OriginOfGraph[0], Width - 0.2 * Width)
write_string (WindowID, ‘Area’)
set_tposition (WindowID, 0.07 * Height, OriginOfGraph[1])
write_string (WindowID, ‘Circularity’)
dev_set_color (ColorFeatureVector)
ExtentOfGraph := Height - 0.3 * Height
RangeC := 0.5
RangeA := 24000
ScaleC := ExtentOfGraph / RangeC
ScaleA := ExtentOfGraph / RangeA
MinC := 0.5
MinA := 20000
NumberFeatureVectors := |FeaturesA|
for i := 0 to NumberFeatureVectors - 1 by 1
DiffC := ScaleC * (FeaturesC[i] - MinC)
DiffA := ScaleA * (FeaturesA[i] - MinA)
RowFeature := OriginOfGraph[0] - DiffC
ColumnFeature := OriginOfGraph[1] + DiffA
画X号
gen_cross_contour_xld (Cross, RowFeature, ColumnFeature, CrossSize, 0.785398)
dev_display (Cross)
endfor
return ()
柠檬的自定义函数
visualize_2D_feature_space (Cross, Height, Width, WindowHandle, FeaturesArea[6:11], FeaturesCircularity[6:11], ‘light gray’, 18)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
训练分类器train_class_gmm(:: 分类器句柄,最大迭代次数,阈值,计算方法,规范单一协方差矩阵:类中心数量,每个类的迭代次数)
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)
清除训练句柄
clear_class_gmm (GMMHandle)
这个例子介绍了GMM分类器的使用方法,步骤是create_class_gmm 、add_sample_class_gmm、train_class_gmm、classify_class_gmm 先创建分类器,为分类器添加样本,训练分类器,使用分类器对进行分类。一个全面介绍GMM分类器使用的一个例子。通过GMM分类器实现了橙子和柠檬 的分类。
大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。