网站刷链接怎么做的,自己做网站需要什么软件下载,网站如何加入百度网盟,网络规划设计师证书图片使用 PMAlign和Fixture固定Blob工具检测孔
这个示例演示了如何使用 PMAlign 工具和 Fixture 工具来夹持一个 Blob 工具。示例代码将检测支架右上角孔的存在。当点击运行按钮时#xff0c;将读取新图像。PMAlign 工具运行并生成一个 POSE 作为输出。POSE 是一个六自由度的变换…使用 PMAlign和Fixture固定Blob工具检测孔
这个示例演示了如何使用 PMAlign 工具和 Fixture 工具来夹持一个 Blob 工具。示例代码将检测支架右上角孔的存在。当点击运行按钮时将读取新图像。PMAlign 工具运行并生成一个 POSE 作为输出。POSE 是一个六自由度的变换描述了从运行时坐标空间到训练时坐标空间的转换。一个 POSE 由 TranslationX、TranslationY、旋转、缩放、ScalingX 和 ScalingY 组成。 PMAlign 工具的输出 POSE 随后被传递给 Fixture 工具。Fixture 工具从 PMAlign 工具获取 POSE 信息以及新图像并创建一个新的输出图像。Fixture 工具的输出图像随后被传递给 Blob 工具。
这三个工具是在此应用程序外部创建的并在初始化时加载Form_Load。PMAlign 工具被训练使用整个支架作为训练图像。在 PMAlign 工具运行后生成的 POSE 被传递给 Fixture 工具。Fixture 工具从 PMAlign 获取 POSE 信息并从图像文件工具获取图像创建一个新图像然后传递给 Blob 工具。Fixture 工具生成的新图像已经针对支架的新位置进行了校正。Blob 工具的感兴趣区域围绕左侧的孔。当 Blob 工具运行时结果会被检查以查看是否检测到 blob
1. 创建vpp文件
打开VisionPro QuickBuild,新建CogJob1,打开ImageSouce,选择文件C:\Program Files\Cognex\VisionPro\Images\bracket_std.idb作为输入图像源 依次添加CogPMAlignTool,CogFixtureTool,CogBlobTool工具,并连线 PMAlign 工具被训练使用整个支架作为训练图像 抓取训练图像框选整个支架点击训练区域与原点Tab下的中心原点点击运行参数Tab 角度从标称值转为设置上下限45度点击训练参数Tab 训练按钮训练图像运行工具 在 PMAlign 工具运行后生成的 POSE 被传递给 Fixture 工具。Fixture 工具从 PMAlign 获取 POSE 信息并从图像文件工具获取图像创建一个新图像,Fixture 工具生成的新图像已经针对支架的新位置进行了校正 运行整个工具后,结果会被检查以查看是否检测到 blob 确认无误后,分别保存CogPMAlign,CogFixture,CogBlob工具的vpp到本地供后续程序开发使用 2. 添加引用
using Cognex.VisionPro;
using Cognex.VisionPro.Blob;
using Cognex.VisionPro.CalibFix;
using Cognex.VisionPro.Exceptions;
using Cognex.VisionPro.ImageFile;
using Cognex.VisionPro.PMAlign;3. 界面设计
添加CogDisplay控件和Button按钮. 4. 声明变量 private CogImageFileTool imageFileTool;private CogPMAlignTool pMAlignTool;private CogFixtureTool fixtureTool;private CogBlobTool blobTool;5. 加载工具 private void InitializeCogTool(){string ImageFileName Images\bracket_std.idb;string strBaseDir Environment.GetEnvironmentVariable(VPRO_ROOT);if (string.IsNullOrEmpty(strBaseDir)){throw new Exception(环境变量VPRO_ROOT未设置.);}imageFileTool new CogImageFileTool();//调用 CogImageFileTool 的 Operator 属性来打开指定路径的图像文件。CogImageFileModeConstants.Read 参数指定以读取模式打开文件imageFileTool.Operator.Open(Path.Combine(strBaseDir,ImageFileName),CogImageFileModeConstants.Read);string VPPFiles G:/VisonProStudy/UsingQB/vpp/;//将文件内容反序列化为相应的工具对象pMAlignTool (CogPMAlignTool)CogSerializer.LoadObjectFromFile(VPPFiles pmalign_tool.vpp);fixtureTool (CogFixtureTool)CogSerializer.LoadObjectFromFile(VPPFilesfixture_tool.vpp);blobTool (CogBlobTool)CogSerializer.LoadObjectFromFile(VPPFilesblob_tool.vpp);}private void DisplayErrorAndExit(string ErrorMsg){MessageBox.Show(ErrorMsg\nPress OK to exit.);Application.Exit();}private void Form11_Load(object sender, EventArgs e){try{InitializeCogTool();}catch (CogException ex){DisplayErrorAndExit(Tool Load Error: ex.Message);}catch (Exception ex) {DisplayErrorAndExit(Tool Load Error:ex.Message);}}6. 处理按钮点击事件 private void BtnRun_Click(object sender, EventArgs e){try{//清空 cogDisplay1 控件中的静态图形以便在后续处理中显示新的结果cogDisplay1.StaticGraphics.Clear();imageFileTool.Run();pMAlignTool.InputImage (CogImage8Grey)imageFileTool.OutputImage;pMAlignTool.Run();if (pMAlignTool.RunStatus.Result ! CogToolResultConstants.Accept){throw pMAlignTool.RunStatus.Exception;}if (pMAlignTool.Results.Count 0){throw new Exception(PMAlgin工具没找到结果.);}fixtureTool.InputImage imageFileTool.OutputImage;fixtureTool.RunParams.UnfixturedFromFixturedTransform pMAlignTool.Results[0].GetPose();fixtureTool.Run();if (fixtureTool.RunStatus.Result ! CogToolResultConstants.Accept){throw fixtureTool.RunStatus.Exception;}blobTool.InputImage (CogImage8Grey)fixtureTool.OutputImage;blobTool.Run();if (blobTool.RunStatus.Result ! CogToolResultConstants.Accept){throw blobTool.RunStatus.Exception;}if (blobTool.Results.GetBlobs().Count 0){throw new Exception(Blob工具没找到结果.);}cogDisplay1.Image imageFileTool.OutputImage;//使用 Blob 工具的第一个结果创建图形边界和质心并添加到显示区域。//使用 PMAlign 工具的第一个结果创建坐标轴图形并添加到显示区域。cogDisplay1.StaticGraphics.Add(blobTool.Results.GetBlobs()[0].CreateResultGraphics(CogBlobResultGraphicConstants.Boundary | CogBlobResultGraphicConstants.CenterOfMass), );cogDisplay1.StaticGraphics.Add(pMAlignTool.Results[0].CreateResultGraphics(CogPMAlignResultGraphicConstants.CoordinateAxes), );}catch (CogException ex){DisplayErrorAndExit(Tool Load Error: ex.Message);}catch (Exception ex) {DisplayErrorAndExit(Tool Load Error: ex.Message);}}7. 界面效果 8. 项目示例
整理了包含本文章的11个使用C#进行Cognex VisionPro二次开发学习笔记的示例源码涵盖了从创建基于QuickBuild的应用程序到使用PMAlign和Caliper工具进行图像处理的多种实践案例,欢迎学习和指正 视觉领域 计算机视觉 Cognex VisionPro C#二次开发示例