自动选择最佳特征进行分类-SVM (Halcon)
HALCON12里的example,classify_pills_auto_select_features.hdev.
执行流程:
1.选取相关特征(本例选取color和region组的所有特征)
(本例用get_feature_names( : : GroupNames : Names),根据特征组名得到一系列特征
2.创建训练数据,添加样本的相关特征至训练数据结构中。
(本例用calculate_features(Region, Image : : FeatureNames : Features)),根据特征名计算特征
3.自动选择最适合特征
(本例用select_feature_set_svm( : : ClassTrainDataHandle, SelectionMethod, GenParamNames, GenParamValues : SVMHandle,SelectedFeatureIndices, Score)
4.用分类器对测试图片进行分类
* This example shows how to use the calculate_feature_set
* procedure library together with the automatic feature selection
* to classify different pill types using a SVM classifier.
* 该示例演示如何从calculate_feature得到的特征,进行自动最佳特征选择,
* 并使用SVM分类器对各类型的pill进行分类。
* First, the pills are segmented in some training images.
* Then, a list of color and region features are calculated
* for each pill and stored in a classifier training data structure.
* After that, the best features are automatically selected
* with the operator select_feature_set_svm, and finally
* the resulting classifier is applied on a number of test
* images.
* 首先,对包含有pills的训练图片进行分割。
* 计算color和region组相关的特征。
* 每1个pill的相关特征添加至分类器训练数据结构里。
* 所有的训练数据添加完毕,用select_feature_set_svm
* 也可以用其他的分类器类型选择比如(select_feature_set_knn(mlp,gmm))
* 自动选择最佳特征,最后应用分类器对测试图像分类。
* Init visualization
dev_close_window ()
dev_update_off ()
read_image (Image, 'color/pills_class_01')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_draw ('margin')
dev_set_line_width (2)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_colored (12)
*
PillNames := ['big_round_red','round_green','small_round_red','yellow_trans','brown','brown_green']
PillNames := [PillNames,'brown_grain','purple','turquese','pink']
PillColors := ['#D08080','#ADC691','#FFB0A1','#D5C398','#B59C87','#BCB3B8','#B7ACA1','#908E99','#97B9BC','#C0ABA9']
*
* Check, which features and feature groups are available
query_feature_group_names (AvailableGroupNames)
query_feature_names_by_group (AvailableGroupNames, AvailableFeatureNames, AvailableCorrespondingGroups)
*
* Generate list of color and region features using the
* calculate_feature_set library procedures.
* 获取相关特征组的对应的特征名称(1个特征组包含许多特征),比如region组,有area,width,height,phi,ra,rb等。
* 获取相关特征的特征向量长度,比如rgb_mean特征,特征向量长度为3(每个通道对应1个值),area特征向量长度为1。
FeatureGroups := ['region','color']
get_feature_names (FeatureGroups, FeatureNames)
get_feature_lengths (FeatureNames, FeatureLengths)
*
* Create and prepare classifier training data structure
* 创建和准备分类训练数据结构
create_class_train_data (sum(FeatureLengths), ClassTrainDataHandle)
set_feature_lengths_class_train_data (ClassTrainDataHandle, FeatureLengths, FeatureNames)
*
* Training loop 循环训练
*
for I := 1 to 10 by 1
* Segment pills in training image
read_image (Image, 'color/pills_class_' + I$'.2d')
segment_pills (Image, Pills)
* Display segmentation result
dev_display (Image)
dev_set_color ('white')
dev_display (Pills)
disp_message (WindowHandle, 'Collecting ' + PillNames[I - 1] + ' samples', 'window', 12, 12, 'black', 'true')
*
* Calculate features for all segmented pills and store
* them in the training data structure
count_obj (Pills, Number)
calculate_features (Pills, Image, FeatureNames, Features)
add_sample_class_train_data (ClassTrainDataHandle, 'feature_column', Features, I - 1)
* 以上注意第二参数'feature_column'的选择,此例中由于Number的数大于1,以特征列做为顺序。
* Visualize processed pills
dev_set_color (PillColors[I - 1])
dev_display (Pills)
GroupList := sum('\'' + FeatureGroups + '\', ')
tuple_str_first_n (GroupList, strlen(GroupList) - 3, GroupList)
Message := 'Calculate ' + |FeatureNames| + ' features from following feature groups:'
disp_message (WindowHandle, [Message,GroupList], 'window', 40, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
*
* Automatically select suitable features from the training data
* 自动选择训练数据的最合适的特征
disp_message (WindowHandle, 'Selecting optimal features...', 'window', 90, 12, 'black', 'true')
select_feature_set_svm (ClassTrainDataHandle, 'greedy', [], [], SVMHandle, SelectedFeatures, Score)
disp_message (WindowHandle, ['Selected:',SelectedFeatures], 'window', 120, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Free memory, because the training data is no longer used
clear_class_train_data (ClassTrainDataHandle)
*
* Classify pills in test images
* using the automatically trained classifier with the
* automatically selected features
* 用分类器对测试图片进行测试,使用训练分类器和自动选择的最佳特征。
dev_set_line_width (4)
dev_set_colored (12)
for I := 1 to 3 by 1
* Segment pills in test image
read_image (Image, 'color/pills_test_' + I$'.2d')
dev_display (Image)
segment_pills (Image, Pills)
* For all pills, calculate selected features
* using the calculate_features procedure from the
* calculate_feature_set library and classify them.
PillsIDs := []
count_obj (Pills, NPills)
for P := 1 to NPills by 1
select_obj (Pills, PillSelected, P)
calculate_features (PillSelected, Image, SelectedFeatures, Features)
classify_class_svm (SVMHandle, real(Features), 1, Class)
* Display results
PillsIDs := [PillsIDs,Class]
dev_set_color (PillColors[Class])
dev_display (PillSelected)
area_center (PillSelected, Area, Row, Column)
disp_message (WindowHandle, Class + 1, 'image', Row, Column - 10, 'black', 'true')
endfor
disp_message (WindowHandle, 'Classify image ' + I + ' of 3 using following features:', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, SelectedFeatures, 'window', 40, 12, 'black', 'true')
if (I < 3)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
* Clean up memory
* 清除内存
clear_class_svm (SVMHandle)
自动选择最佳特征进行分类-SVM (Halcon)的更多相关文章
- SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)
1.概念:SpringCloudConfig 基础配置 2.具体内容 通过名词就可以发现,SpringCloudConfig 核心作用一定就在于进行配置文件的管理上.也就是说为了更好的进行所有微服务的 ...
- Debian初识(选择最佳镜像发布站点加入source.list文件)
选择最佳镜像发布站点加入source.list文件:netselect,netselect-apt “该将哪个Debian镜像发布站点加入source.list文件?”.有很多方法来选择镜像发布站点, ...
- 如何为应用选择最佳的FPGA(下)
如何为应用选择最佳的FPGA(下) How to select an FPGA board? FPGA板的选择在很大程度上受FPGA本身的影响,也受整个板的特性和性能的影响.们已经在上面的章节中讨论了 ...
- js单击自动选择文本
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- [大牛翻译系列]Hadoop(4)MapReduce 连接:选择最佳连接策略
4.1.4 为你的数据选择最佳连接策略 已介绍的每个连接策略都有不同的优点和缺点.那么,怎么来判断哪个最适合待处理的数据? 图4.11给出了一个决策树.这个决策树是于论文<A Compariso ...
- ECshop网点程序优化-后台添加类目自动选择上次父类目并计算Sort Order
如果在ECshop后台批量添加过大量类目的人都能体会到是多么的不方便(这点还是要说一下ECshop的产品经理,细节上还是要多注意),每次添加都需要在几百个类目里面找到要添加的父类目也是一个麻烦事,比如 ...
- Android自定义垂直滚动自动选择日期控件
------------------本博客如未明正声明转载,皆为原创,转载请注明出处!------------------ 项目中需要一个日期选择控件,该日期选择控件是垂直滚动,停止滚动时需要校正日期 ...
- 【百度地图API】——如何让标注自动呈现在最佳视野内
原文:[百度地图API]--如何让标注自动呈现在最佳视野内 摘要: “我有一堆标注,不规则的散落在地图的各个地方,我想把它们展示在一个最佳视野中,怎么办呢?”一位API爱好者咨询道. -------- ...
- C#自动选择出系统中最合适的IP地址
写这个是因为很长时间以来,碰到过很多次这个问题,但都没当回事,这次又碰到了这个老问题,无奈百度了一圈儿未果,身边又没有大牛可以请教,就自己先“总结”了一套方法,一来给自己记录,二来如果碰巧能有朋友看到 ...
随机推荐
- Spring Cloud Netflix项目进入维护模式
任何项目都有其生命周期,Spring Could Netflix也不例外,官宣已进入维护模式,如果在新项目开始考虑技术选型时要考虑到这点风险,并考虑绕道的可能性. 原创: itmuch IT牧场 这 ...
- RAC8——scan ip的理解
SCAN概念 先介绍一下什么叫SCAN,SCAN(Single Client Access Name)是Oracle从11g R2开始推出的,客户端可以通过SCAN特性负载均衡地连接到RAC数据库.S ...
- 从工程文化和运维理念理解Netflix
http://www.infoq.com/cn/news/2018/01/netflix-engineering-culture 在技术圈儿,Netflix 是一家非常有特色的互联网公司.他们信奉“自 ...
- php中__get()和__set的用法
php版本5.6 一般来说,总是把类的属性定义为private,这更符合现实的逻辑.但是,对属性的读取和赋值操作是非常频繁的,因此在PHP5中,预定义了两个函数“__get()”和“__set()”来 ...
- linux ping报错Name or service not known
ubuntu设置静态ip以后忘记设置dns,ping的时候报错:Name or service not known 添加dns即可 vi /etc/resolv.conf nameserver 8.8 ...
- AppBox中main树节点单击事件JS(还有叶子的节点的页面链接)
AppBox中main.aspx.csif (menu.IsTreeLeaf) { node.Leaf = true; ...
- JZ2440 裸机驱动 第9章 中断体系结构
本章目标: 了解ARM体系CPU的7种工作模式 了解S3C2410/S3C2440中断体系结构 掌握S3C2410/S3C2440的中断服务程序的编写方法 9.1 S3C241 ...
- MySQL数据库服务器整体规划(go)
我们在搭建MySQL数据库服务器的开始阶段就合理的规划,可以避免以后的很多问题的产生,大大节省我们的时间和精力,在一定幅度上降低成本.当然,这会涉及很多方面.比如机器的选型.业务评估和系统规划等. 所 ...
- 微信JSSDK分享朋友圈微信自定义分享接口
服务项目 新手技术咨询 企业技术咨询 定制开发 服务说明 QQ有问必答 QQ.微信.电话 微信开发.php开发,网站开发,系统定制,小程序开发 价格说明 200元/月 1000/月 商议 ...
- bzoj4419 发微博
Description 刚开通的SH微博共有n个用户(1..n标号),在短短一个月的时间内,用户们活动频繁,共有m条按时间顺序的记录: ! x 表示用户x发了一条微博: + x y 表示用户x和用 ...