• VisionPro 各控件的C#中类库 (CogToolBlock类)像函数设计一样。


    1.先了解其控件使用

    编辑增加控件步骤1-2-3-4。我们把他当做一个整体进行封装,可以可以看成一个函数设计(增加输入类型几个,添加输出类型几个)

    2.进行CogToolBlock控件功能设计(进行函数功能设计--即功能调试)

    3.进行添加功能控件,进行配置把要输入和输出的项目设定好测试OK后进行保存。

    4.下部分进行C#进行调用--先进行反序列化成为对象。

    CogToolBlock Block= CogSerializer.LoadObjectFromFile(@"D:AVITool1.vpp") as CogToolBlock;

    5.基本应用

     1 private void button4_Click(object sender, EventArgs e)//测试应用CogToolBlock
     2 {
     3             this.cogRecordDisplay2.StaticGraphics.Clear();
     4             tool1 = CogSerializer.LoadObjectFromFile(@"D:AVITool1.vpp") as CogToolBlock;
     5             Bitmap A1 = (Bitmap)Bitmap.FromFile(@"D:AVI13.JPG");
     6             CogImage24PlanarColor ima3 = new CogImage24PlanarColor(A1);
     7             tool1.Inputs[0].Value = ima3;//输入图片
     8             tool1.Run();//运行
     9             CogTransform2DLinear aline = tool1.Outputs[0].Value as CogTransform2DLinear;
    10             label1.Text = string.Format("数据:角度:{0},
     X:{1},Y:
    {2}", aline.Rotation, aline.TranslationX, aline.TranslationY);
    11 
    12             cogRecordDisplay2.Record = tool1.CreateLastRunRecord().SubRecords[1];
    13 
    14 }

    源码:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 using Cognex.VisionPro;
    10 using Cognex.VisionPro.ToolBlock;
    11 using Cognex.VisionPro.ImageFile;
    12 using System.IO;
    13 using Cognex.VisionPro.OCRMax;
    14 using Cognex.VisionPro.ID;
    15 using System.Diagnostics;
    16 using Cognex.VisionPro.PMAlign;
    17 using Cognex.VisionPro.Blob;
    18 
    19 namespace qj
    20 {
    21     public partial class Form1 : Form
    22     {
    23         public Form1()
    24         {
    25             InitializeComponent();
    26             chushua();
    27         }
    28         CogAcqFifoTool camtool = null;
    29         ICogFrameGrabber cam1 = null;
    30         ICogAcqFifo cam = null;
    31        // CogImageFile file = null;
    32         CogImageFileTool file1 = null;
    33         CogImageConvert covet1 = null;
    34         CogToolBlock tool1 = null;
    35         CogPMAlignTool tool2 = null;
    36         ICogImage tu = null;
    37         private void chushua()
    38         {
    39            // camtool = new CogAcqFifoTool();
    40            // cam = camtool.Operator;
    41           //  covet1 = new CogImageConvert();
    42             file1 = (CogImageFileTool)CogSerializer.LoadObjectFromFile(@"D:AVIimg.vpp");
    43             tool2 = CogSerializer.LoadObjectFromFile(@"D:AVIpm1.vpp") as CogPMAlignTool;
    44             file1.Run();
    45            // cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
    46           cogRecordDisplay2.Image = file1.OutputImage;
    47 
    48 
    49         }
    50 
    51         private void button1_Click(object sender, EventArgs e)
    52         {
    53            // file1.Run();
    54             
    55             cogRecordDisplay2.Image =tu = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
    56         }
    57 
    58         private void button1_Click_1(object sender, EventArgs e) //定位测试
    59         {
    60             Bitmap A1 = (Bitmap)Bitmap.FromFile(@"D:AVI13.JPG");
    61             CogImage8Grey ima1 = new CogImage8Grey(A1);
    62             
    63             tool2 = CogSerializer.LoadObjectFromFile(@"D:AVIpm1.vpp") as CogPMAlignTool;
    64             tool2.InputImage = ima1;
    65             tool2.Run();
    66             cogRecordDisplay2.Record = tool2.CreateLastRunRecord().SubRecords[0];
    67           CogTransform2DLinear aline=  tool2.Results[0].GetPose();
    68           label1.Text = string.Format("数据:角度:{0},
     X:{1},Y:
    {2},
    得分{3}", aline.Rotation, aline.TranslationX, aline.TranslationY, tool2.Results[0].Score * 100);
    69         }
    70 
    71         private void button2_Click(object sender, EventArgs e)
    72         {
    73       
    74         }
    75 
    76         private void button3_Click(object sender, EventArgs e) //CogPMAlignTool mark编辑
    77         {
    78             Form2 gi = new Form2();
    79             gi.ShowDialog();
    80         }
    81 
    82         private void button4_Click(object sender, EventArgs e)//测试应用CogToolBlock
    83         {
    84             this.cogRecordDisplay2.StaticGraphics.Clear();
    85             tool1 = CogSerializer.LoadObjectFromFile(@"D:AVITool1.vpp") as CogToolBlock;
    86             Bitmap A1 = new Bitmap(@"D:AVI13.JPG");
    87             CogImage24PlanarColor ima3 = new CogImage24PlanarColor(A1);
    88             tool1.Inputs[0].Value = ima3;//输入图片
    89             tool1.Run();//运行
    90             CogTransform2DLinear aline = tool1.Outputs[0].Value as CogTransform2DLinear;
    91             label1.Text = string.Format("数据:角度:{0},
     X:{1},Y:
    {2}", aline.Rotation, aline.TranslationX, aline.TranslationY);
    92 
    93             cogRecordDisplay2.Record = tool1.CreateLastRunRecord().SubRecords[1];
    94             A1.Dispose();
    95             tool1.Dispose();
    96 
    97         }
    98     }
    99 }

     

  • 相关阅读:
    LLVM 3.0 — LinuxTOY
    Fabric Engine 1.0
    tmux:GNU screen 替代品 — LinuxTOY
    LuoYun 开源云计算平台软件 0.2 Beta 版本发布 — LinuxTOY
    迅雷离线下载脚本 — LinuxTOY
    Vim 状态栏是 Powerline 插件。
    LuoYun 云计算平台 0.4 版本 liveCD 发布
    webOS Isis 开源 — LinuxTOY
    Impress.js — LinuxTOY
    从 screen 切换到 tmux — LinuxTOY
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/14281380.html
Copyright © 2020-2023  润新知