(C#-VisionPro)⽤代码⽅式新建VisionPro视觉⽂件(.vpp)1.⽅法⼀:
引⽤:
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro.Exceptions;
image pro plususing 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 Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogPMAlignTool.vtt") as CogPMAlignTool;            CogPMAlignTool CogPMAlignTool2 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogPMAlignTool.vtt") as CogPMAlignTool;            CogFixtureTool CogFixtureTool1 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogFixtureTool.vtt") as CogFixtureTool;
CogToolBlock CogToolBlock1 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogToolBlock.vtt") as CogToolBlock;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。