嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
本例子集成了“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
}