第一步 ??創建支持向量機分類器
create_class_svm (7, 'rbf', KernelParam, Nu, |ClassNames|, 'one-versus-one', 'principal_components', 5, SVMHandle)
第二步 ?添加樣本到分類器里
for ClassNumber := 0 to |ClassNames| - 1 by 1
????*列出目錄下的所有文件
????list_files (ReadPath + ClassNames[ClassNumber], 'files', Files)
????*獲取后綴為PNG的所有文件
????Selection := regexp_select(Files,'.*[.]png')
????for Index := 0 to |Selection| - 1 by 1
????????*讀取圖像
????????read_image (Image, Selection[Index])
????????dev_display (Image)
????????* 'Add Samples...', -1
????????*圖像閾值,獲取黑色區域
????????threshold (Image, Region, 0, 40)
* ??????calculate_features_define (Region, Features)
????????calculate_features_define (Region, Features)
????????add_sample_class_svm (SVMHandle, Features, ClassNumber)
????endfor
endfor
* add_samples_to_svm_define(ClassNames, SVMHandle, WindowHandle, ReadPath)
* 關閉窗口
dev_clear_window ()
*第三步 ?訓練支持向量機分類器
disp_message (WindowHandle, 'Training...', 'window', -1, -1, 'black', 'true')
train_class_svm (SVMHandle, 0.001, 'default')
disp_message (WindowHandle, 'Training completed', 'window', -1, -1, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*第四步 用SVM分類器進行分類
????*讀取圖像
????read_image (Image, Selection[Index])
????*對圖像閾值
????threshold (Image, Region, 0, 40)
????*計算區域的特征值
????calculate_features_define (Region, Features)
????*用SVM分類器進行分類
????classify_class_svm (SVMHandle, Features, 1, Class)
第五步 ?顯示和輸出結果
????dev_display (Region)
????disp_message (WindowHandle, 'Classified as:' + ClassNames[Class], 'window', -1, -1, 'black', 'true')
????disp_continue_message (WindowHandle, 'black', 'true')