Vision Pro低级脚本 熟悉终端


一、低级脚本

1、添加所需终端

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、编写低级脚本

#region namespace imports 引用程序集
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.Blob;
using Cognex.VisionPro.CalibFix;
#endregion

public class CogToolBlockSimpleScript : CogToolBlockAdvancedScript
{
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  List<double> rectangleAffine = null; //矩形
  
  public override bool GroupRun(ref string message, ref CogToolResultConstants result)
  {
    //获取该组的Outputs中的Output
    this.Outputs.Output = "";
    this.Outputs.Text = "";
    this.Outputs.OutputXYText = "";
    
    
    double CenterX = (this.Inputs.CenterOfMassX1 + this.Inputs.CenterOfMassX2) / 2;
    double CenterY = (this.Inputs.CenterOfMassY1 + this.Inputs.CenterOfMassY3) / 2;
    double LengthX = this.Inputs.CenterOfMassX1 - this.Inputs.CenterOfMassX2;
    double LengthY = this.Inputs.CenterOfMassY1 - this.Inputs.CenterOfMassY3;
    double X = CenterX + LengthX;
    double Y = CenterY + LengthY;
    
    
    this.Outputs.LengthX = LengthX;
    this.Outputs.LengthY = LengthY;
    
    //CogFixtureTool坐标需要通过CogTransform2DLinear转化
    //将x,y,Rotation赋给CogFixtureTool2
    CogTransform2DLinear ct = new CogTransform2DLinear();
    ct.TranslationX = X;
    ct.TranslationY = Y;
    ct.Rotation = this.Inputs.Result_GetLine_Rotation;
    this.Tools.CogFixtureTool2.RunParams.UnfixturedFromFixturedTransform = ct;
    this.Tools.CogFixtureTool2.Run();
    
    double originX = 0.847365 + this.Inputs.X;
    double originY = 7.70912 + this.Inputs.Y;
    double lX = 198.194 + this.Inputs.LX;
    double lY = 317.618 + this.Inputs.LY;
    double rotation = 0 + this.Inputs.Rotation;
    double skew = 0 + this.Inputs.Skew;
    CogRectangleAffine cra = new CogRectangleAffine();
    
    this.Outputs.X = originX;
    this.Outputs.Y = originY;
    this.Outputs.LX = lX;
    this.Outputs.LY = lY;
    this.Outputs.Rotation = rotation;
    this.Outputs.Skew = skew;
    
    //循环
    for(int j = 0;j <= 5;j++)
    {
      for(int i = 0;i <= 12;i++)
      {
        cra.SetCenterLengthsRotationSkew(originX - (i * LengthX), originY - (j * LengthY), lX, lY, rotation, skew);  //使用CogRectangleAffine的方法
        
        //向集合列表中加入数据
        rectangleAffine.Add(originX - (i * LengthX));
        rectangleAffine.Add(originY - (j * LengthY));   
        rectangleAffine.Add(lX);
        rectangleAffine.Add(lY);
        rectangleAffine.Add(rotation);
        rectangleAffine.Add(skew);
        
        this.Tools.CogBlobTool1.Region = cra;
        this.Tools.CogBlobTool1.Run();
        if(this.Tools.CogBlobTool1.Results.GetBlobs().Count.Equals(4))    //判断是否有4个结果
        {
          this.Outputs.OutputXYText = this.Outputs.OutputXYText + (originX - (i * LengthX)).ToString() + "," + (originY - (j * LengthY)).ToString() + "," + "OK";
        }else{
          this.Outputs.OutputXYText = this.Outputs.OutputXYText + (originX - (i * LengthX)).ToString() + "," + (originY - (j * LengthY)).ToString() + "," + "NG";
        }
        
        if(i.Equals(12))
        {
          this.Outputs.Text = this.Outputs.Text + this.Tools.CogBlobTool1.Results.GetBlobs().Count.ToString();
          this.Outputs.Output = this.Outputs.Output + this.Tools.CogBlobTool1.Results.GetBlobs().Count.ToString() + ";";
        }else
        {
          this.Outputs.Text = this.Outputs.Text + this.Tools.CogBlobTool1.Results.GetBlobs().Count.ToString();
          this.Outputs.Output = this.Outputs.Output+ this.Tools.CogBlobTool1.Results.GetBlobs().Count.ToString() + ",";
        }
       
      }
    }  
    return false;
  }
}

注意:添加一次终端的在脚本里点击检查界面终端在这里插入图片描述

二、总结

在低级脚本中只需要

this.工具名.终端名  来获取终端的数据

注意:终端中一般找所需的数据只用(Results:结果、InputImage:输入图片)中找就行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值