• (C#-VisionPro)用代码方式新建VisionPro视觉文件(.vpp)


    1.方法一:

    引用:

    using Cognex.VisionPro;
    using Cognex.VisionPro.ToolBlock;
    using Cognex.VisionPro.Exceptions;
    using Cognex.VisionPro.PMAlign;
    using Cognex.VisionPro.Display;
    using System.Drawing;
    using Cognex.VisionPro.CalibFix;
    //新增工具
            public void VisionPro_Add()
            {
                //实例化工具
                CogToolBlock CogToolBlock1 = new CogToolBlock();
                CogPMAlignTool CogPMAlignTool1 = new CogPMAlignTool();
                CogFixtureTool CogFixtureTool1 = new CogFixtureTool();
                CogPMAlignTool CogPMAlignTool2 = new CogPMAlignTool();
    
                //将工具单独保存在加载
                CogPMAlignTool CogPMAlignTool3 = new CogPMAlignTool();
                CogPMAlignTool3 = CogSerializer.LoadObjectFromFile(@"E:CogPMAlignTool1.vtt") as CogPMAlignTool;
    
                //给工具命名
                CogToolBlock1.Name = "CogToolBlock1";
                CogPMAlignTool1.Name = "CogPMAlignTool1";
                CogFixtureTool1.Name = "CogFixtureTool1";
                CogPMAlignTool2.Name = "CogPMAlignTool2";
    
                //将工具添加到CogToolBlock工具中再保存CogToolBlock工具
                CogToolBlock1.Tools.Add(CogPMAlignTool1);
                CogToolBlock1.Tools.Add(CogFixtureTool1);
                CogToolBlock1.Tools.Add(CogPMAlignTool2);
                CogSerializer.SaveObjectToFile(CogToolBlock1, @"E:ToolBlock2.vpp");
                MessageBox.Show("保存成功");
            }

    结果:

     方法二:添加工具输出项

    //新增工具
            public void VisionPro_Add()
            {
                //实例化工具
                CogToolBlock CogToolBlock1 = new CogToolBlock();
                CogPMAlignTool CogPMAlignTool1 = new CogPMAlignTool();
                CogFixtureTool CogFixtureTool1 = new CogFixtureTool();
                CogPMAlignTool CogPMAlignTool2 = new CogPMAlignTool();
    
                //将工具单独保存在加载
                CogPMAlignTool CogPMAlignTool3 = new CogPMAlignTool();
                CogPMAlignTool3 = CogSerializer.LoadObjectFromFile(@"E:CogPMAlignTool1.vtt") as CogPMAlignTool;
                
                   
                //给工具命名
                CogToolBlock1.Name = "CogToolBlock1";
                CogPMAlignTool1.Name = "CogPMAlignTool1";
                CogFixtureTool1.Name = "CogFixtureTool1";
                CogPMAlignTool2.Name = "CogPMAlignTool2";
    
                string[] s1 = new string[1];
                string[] s2 = new string[5];
                s1[0] = "|InputImage|InputImage";
                s2[0] = "| Results.Item[0].GetPose() | Results.Item[0].GetPose()";
                s2[1] = "|Results.Item[0].GetPose().TranslationX|Results.Item[0].GetPose().TranslationX";
                s2[2] = "|Results.Item[0].GetPose().TranslationX|Results.Item[0].GetPose().TranslationY";
                s2[3] = "|Results.Item[0].GetPose().Rotation|Results.Item[0].GetPose().Rotation";
                s2[4] = "|Results.Item[0].Score|Results.Item[0].Score";
    
                CogPMAlignTool1.UserData.Add("_ToolInputTerminals", s1);//添加终端-InputImage
                CogPMAlignTool1.UserData.Add("_ToolOutputTerminals", s2);
    
                //将工具添加到CogToolBlock工具中再保存CogToolBlock工具
                CogToolBlock1.Tools.Add(CogPMAlignTool1);
                CogToolBlock1.Tools.Add(CogFixtureTool1);
                CogToolBlock1.Tools.Add(CogPMAlignTool2);
                CogSerializer.SaveObjectToFile(CogToolBlock1, @"E:ToolBlock2.vpp");
                MessageBox.Show("保存成功");
            }

     方法三:单独保存工具再去加载

    系统工具默认地址:

     保存工具模板

    点击右键保存工具模板(.vtt)文件

    //加载系统初始工具
                CogPMAlignTool CogPMAlignTool1 = CogSerializer.LoadObjectFromFile(@"C:Program FilesCognexVisionProinTemplatesToolsC#CogPMAlignTool.vtt") as CogPMAlignTool;
                CogPMAlignTool CogPMAlignTool2 = CogSerializer.LoadObjectFromFile(@"C:Program FilesCognexVisionProinTemplatesToolsC#CogPMAlignTool.vtt") as CogPMAlignTool;
                CogFixtureTool CogFixtureTool1 = CogSerializer.LoadObjectFromFile(@"C:Program FilesCognexVisionProinTemplatesToolsC#CogFixtureTool.vtt") as CogFixtureTool;
                CogToolBlock CogToolBlock1 = CogSerializer.LoadObjectFromFile(@"C:Program FilesCognexVisionProinTemplatesToolsC#CogToolBlock.vtt") as CogToolBlock;
  • 相关阅读:
    游标加标量函数
    将一个Excel文件分隔成多个
    网页抓取的一个小例子
    ajax跨域问题
    ssh连接至Ubuntu服务器时,提示以下错误:REMOTE HOST IDENTIFICATION HAS CHANGED!
    Python 实现汉诺塔问题(递归)
    Ubuntu下环境变量设置
    文件上传 jqueryForm
    Oracle数据库安装完成后相关问题的解决
    Java中16进制与字符串之间的相互转换
  • 原文地址:https://www.cnblogs.com/yangshunwang/p/13163345.html
Copyright © 2020-2023  润新知