本文主要是介绍halcon 使用svm分类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
计算特征
1.选取特征
2.添加数据
3.训练
4.预测
NumFeatures:=200
DataPath:='G:/pj/test/train'
ValPath:='G:/pj/test/val'
list_files(DataPath, 'directories', Dirs)
NumClasses:=|Dirs|
NumData:=10create_class_svm (NumFeatures, 'rbf', 0.01, 0.01, NumClasses,\'one-versus-all', 'normalization', NumFeatures,\SVMHandle)for Index := 1 to NumClasses by 1classPath:=Dirs[Index-1]list_image_files(classPath, 'default', [], ImageFiles)for Index1 := 1 to |ImageFiles| by 1read_image(Image, ImageFiles[Index1-1])scale_image_range(Image, ImageScaled, 20, 200)get_domain (Image, Domain)calc_feature_gray_proj(Domain, ImageScaled, 'hor', NumFeatures, Feature)add_sample_class_svm(SVMHandle, Feature, Index-1)endfor
endfor* Train the SVM
train_class_svm (SVMHandle, 0.001, 'default')list_files(ValPath, 'directories', DirsVal)
NumVal:=|DirsVal|for Index := 1 to NumVal by 1classPath:=DirsVal[Index-1]list_image_files(classPath, 'default', [], ImageFilesVal)for Index1 := 1 to |ImageFilesVal| by 1read_image(Image, ImageFilesVal[Index1-1])scale_image_range(Image, ImageScaled, 20, 200)get_domain (Image, Domain)calc_feature_gray_proj(Domain, ImageScaled, 'hor', NumFeatures, Feature)classify_class_svm(SVMHandle, Feature, 1, Class)stop()endfor
endfor
这篇关于halcon 使用svm分类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!