C#+VisionPro取CogBlobTool工具运行结果
在使用Vpro的过程中经常需要用到索引Patmax或者Blob的结果量,下面大概讲讲实现过程.
首先创建DataGridView表头,代码如下:
DataTable blobtable = new DataTable(); blobtable.Columns.Add("ID", Type.GetType("System.String")); blobtable.Columns.Add("面积", Type.GetType("System.String")); blobtable.Columns.Add("CenterMassX", Type.GetType("System.String")); blobtable.Columns.Add("CenterMassY", Type.GetType("System.String")); blobtable.Columns.Add("Acircularity", Type.GetType("System.String")); blobtable.Columns.Add("AcircularityRms", Type.GetType("System.String")); blobtable.Columns.Add("Angle", Type.GetType("System.String")); blobtable.Columns.Add("InertiaMax", Type.GetType("System.String")); blobtable.Columns.Add("InertiaMin", Type.GetType("System.String")); blobtable.Columns.Add("InertiaX", Type.GetType("System.String")); blobtable.Columns.Add("InertiaY", Type.GetType("System.String"));
其次获取Blob的各种结果量,如面积,XY位置,圆度等等结果参数。
CogJobManager mymanger = (CogJobManager)CogSerializer.LoadObjectFromFile(Application.StartupPath+"/111.vpp"); mymanger.Job(0).Run(); CogToolGroup tg = mymanger.Job(0).VisionTool as CogToolGroup;
CogBlobTool cbt = tg.Tools["CogBlobTool1"] as CogBlobTool; for (int i = 0; i < cbt.Results.GetBlobs().Count;i++ ) { DataRow dr = blobtable.NewRow(); dr[0] = cbt.Results.GetBlobs()[i].ID; dr[1] = cbt.Results.GetBlobs()[i].Area; dr[2] = cbt.Results.GetBlobs()[i].CenterOfMassX; dr[3] = cbt.Results.GetBlobs()[i].CenterOfMassY; dr[4] = cbt.Results.GetBlobs()[i].Acircularity; dr[5] = cbt.Results.GetBlobs()[i].AcircularityRms; dr[6] = cbt.Results.GetBlobs()[i].Angle; dr[7] = cbt.Results.GetBlobs()[i].InertiaMax; dr[8] = cbt.Results.GetBlobs()[i].InertiaMin; dr[9] = cbt.Results.GetBlobs()[i].InertiaX; dr[10] = cbt.Results.GetBlobs()[i].InertiaY; blobtable.Rows.Add(dr); } dataGridView2.DataSource = blobtable;
winform界面如下图示:
不要去跟随消逝的虚无