结果图
通过斑点工具中非圆性找取圆特征
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;using Cognex.VisionPro.ImageFile;
using Cognex.VisionPro;
using Cognex.VisionPro.Blob;
using Cognex.VisionPro.Exceptions;namespace myapp4
{public partial class Form1 : Form{//成员声明CogBlobTool mTool;CogImageFileTool mImageFileTool;public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){mTool = new CogBlobTool();mImageFileTool = new CogImageFileTool();mImageFileTool.Operator.Open("bracket_std.idb", CogImageFileModeConstants.Read);mImageFileTool.Run();CogDisplay1.Image = mImageFileTool.OutputImage;//设置输出图像CogDisplay1.Fit();}private void button1_Click(object sender, EventArgs e){CogDisplay1.StaticGraphics.Clear();//清空静态图形//运行blob工具mTool.InputImage = mImageFileTool.OutputImage;mTool.Run();//获取斑点的轮廓 并显示CogDisplay1.Image = mImageFileTool.OutputImage;int r;for (r = 0; (r<= (mTool.Results.GetBlobs().Count - 1)); r++){if (optCircular.Checked)//如果选取圆性{// display circular objects hereif (((mTool.Results.GetBlobs()[r].Acircularity > 0.9)&& (mTool.Results.GetBlobs()[r].Acircularity < 1.1))){CogDisplay1.StaticGraphics.Add(mTool.Results.GetBlobs()[r].CreateResultGraphics(CogBlobResultGraphicConstants.Boundary), "test");}}else//非圆性{// display non-circular objects hereif (((mTool.Results.GetBlobs()[r].Acircularity <= 0.9)|| (mTool.Results.GetBlobs()[r].Acircularity >= 1.1))){CogDisplay1.StaticGraphics.Add(mTool.Results.GetBlobs()[r].CreateResultGraphics(CogBlobResultGraphicConstants.Boundary), "test");}}}}}
}