实例介绍
【实例简介】
本例子集成了“MLP”,"SVM","KNN","GMM",分类器算法,可以作为进行物体分类,缺陷检测的参考案例。
【实例截图】
【核心代码】
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
HOperatorSet.GenEmptyObj(out ho_Cross);
try
{
//This example program shows how to apply a general GMM
//classification to distinguish citrus fruits using the
//features 'area' and 'circularity'. Additionally, the
//2D feature space for the extracted fruits is visualized.
hv_FeaturesArea = new HTuple();
hv_FeaturesCircularity = new HTuple();
hv_ClassName = new HTuple();
hv_ClassName[0] = "橘子";
hv_ClassName[1] = "柠檬";
//
//Create a GMM classifier
HOperatorSet.CreateClassGmm(2, 2, 1, "spherical", "normalization", 10, 42, out hv_GMMHandle);
//
//Add training samples
for (hv_i = 1; (int)hv_i <= inspectImgCount; hv_i = (int)hv_i 1)
{
ho_Image.Dispose();
HOperatorSet.ReadImage(out ho_Image, files[hv_i - 1]);
HOperatorSet.GetImagePointer1(ho_Image, out hv_Pointer, out hv_Type, out hv_Width, out hv_Height);
HOperatorSet.SetDraw(hWindowControl1.HalconWindow, "margin");
HOperatorSet.SetLineWidth(hWindowControl1.HalconWindow, 2);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
//'Add Samples'
ho_SelectedRegions.Dispose();
Get_regions(ho_Image, out ho_SelectedRegions);
HOperatorSet.DispObj(ho_SelectedRegions, hWindowControl1.HalconWindow);
HOperatorSet.CountObj(ho_SelectedRegions, out hv_NumberObjects);
HTuple end_val32 = hv_NumberObjects;
HTuple step_val32 = 1;
for (hv_j = 1; hv_j.Continue(end_val32, step_val32); hv_j = hv_j.TupleAdd(step_val32))
{
ho_ObjectSelected.Dispose();
HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, hv_j);
get_features(ho_ObjectSelected, out hv_Circularity, out hv_Area,
out hv_RowRegionCenter, out hv_ColumnRegionCenter);
hv_FeaturesArea = hv_FeaturesArea.TupleConcat(hv_Area);
hv_FeaturesCircularity = hv_FeaturesCircularity.TupleConcat(hv_Circularity);
hv_FeatureVector = ((hv_Circularity.TupleConcat(hv_Area))).TupleReal();
if ((int)(new HTuple(hv_i.TupleLessEqual(2))) != 0)
{
HOperatorSet.AddSampleClassGmm(hv_GMMHandle, hv_FeatureVector, 0, 0);
disp_message(hWindowControl1.HalconWindow, "Add to Class:" (hv_ClassName.TupleSelect(
0)), "window", hv_RowRegionCenter, hv_ColumnRegionCenter - 100, "black",
"true");
}
else
{
HOperatorSet.AddSampleClassGmm(hv_GMMHandle, hv_FeatureVector, 1, 0);
disp_message(hWindowControl1.HalconWindow, "Add to Class:" (hv_ClassName.TupleSelect(
1)), "window", hv_RowRegionCenter, hv_ColumnRegionCenter - 100, "black",
"true");
}
}
// stop(); only in hdevelop
}
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)