一次完成VisionMaster 9点标定

本文介绍了一种在点胶项目中,利用VisionMaster视觉软件进行9点标定的创新方法。通过编写脚本工具,一次性读取9个点的像素坐标和机械手发送的世界坐标,实现了一次性完成标定的流程。具体步骤包括读取图像、获取圆点坐标、配置TCP服务器接收坐标数据,并通过脚本将数据写入标定工具中,最后设置标定文件保存路径以完成整个过程。

场景

点胶项目,由于每次换针后有装配误差,所以需要CCD拍照,使用VisionMaster视觉软件计算换针前后点坐标差,补偿到机械手上。

问题

VisionMaster的N点标定有两种模式,一种是触发模式,一种是手动模式,触发模式就是每拍一次照,记录一条数据,拍满9次开始标定,手动模式就是手动输入所有坐标数据,手动执行标定。
在这里插入图片描述
点胶项目标定一般是先点9个点,一次拍照完成标定,显然VisionMaster的现有方式都不适用。

思路

有没有办法一次完成9点标定呢?
答案是可以的,我们可以使用脚本工具,一次写入9条标定数据即可

实战

先看一下整体结构
在这里插入图片描述
首先读入一个图片,如下在这里插入图片描述
然后使用圆查找工具获取9点像素坐标,输入点集工具中。
在这里插入图片描述
然后配置一个tcp服务器,来接受机械手发来的世界坐标,坐标以字符串形式被接受工具获取,字符串内容如下:

CC,0,0,5,0,10,0,0,5,5,5,10,5,0,10,5,10,10,10

其中开头的CC表示此命令为calibration命令,VisionMaster会根据命令执行9点标定流程;

在这里插入图片描述
我们用脚本工具处理这些标定数据,将他们写入到N点标定工具中;
在这里插入图片描述
N点标定代码如下:

using System;
using System.Text;
using System.Windows.Forms;
using Script.Methods;
class UserScript:ScriptMethods,IProcessMethods
{
    //the count of process
	//执行次数计数
    int processCount ;  

    /// <summary>
    /// Initialize the field's value when compiling
	/// 预编译时变量初始化
    /// </summary>
    public void Init()
    {
        //You can add other global fields here
		//变量初始化,其余变量可在该函数中添加
        processCount = 0;
       
    }

    /// <summary>
    /// Enter the process function when running code once
	/// 流程执行一次进入Process函数
    /// </summary>
    /// <returns></returns>
    public bool Process()
    {
        //You can add your codes here, for realizing your desired function
        //每次执行将进入该函数,此处添加所需的逻辑流程处理
        //MessageBox.Show("Process Success");
        string cmd="";
        GetStringValue("CmdStr", ref cmd);
        
        float[] Px = new float[255];
        float[] Py = new float[255];
        int arrayCount = 0;
        GetFloatArrayValue("Px", ref Px, out arrayCount);
        GetFloatArrayValue("Py", ref Py, out arrayCount);

        string moduleName ="";
        GetStringValue("Name",ref moduleName);
        //清空旧数据
        CurrentProcess.GetModule(moduleName).SetValue("Clear", "0");
        //设置模块参数
        CurrentProcess.GetModule(moduleName).SetValue("CalibPointGet","1");
        CurrentProcess.GetModule(moduleName).SetValue("CalibPointTotalNum", arrayCount.ToString());
        CurrentProcess.GetModule(moduleName).SetValue("RotPointTotalNum", "0");
        CurrentProcess.GetModule(moduleName).SetValue("RefreshFileEnable", "True");
        CurrentProcess.GetModule(moduleName).SetValue("CameraMode", "1");
        CurrentProcess.GetModule(moduleName).SetValue("HomoFreedom", "Affine");
        //设置标定数据
        string[] WorldPoints = cmd.Split(',');
        for (int i = 0; i < arrayCount; i++)
        {
            CurrentProcess.GetModule(moduleName).SetValue("ImagePointX" + i, Px[i].ToString());
            CurrentProcess.GetModule(moduleName).SetValue("ImagePointY" + i, Py[i].ToString());
            CurrentProcess.GetModule(moduleName).SetValue("WorldPointX" + i, WorldPoints[i * 2 + 1].ToString());
            CurrentProcess.GetModule(moduleName).SetValue("WorldPointY" + i, WorldPoints[i * 2 + 2].ToString());
        }
        return true;
    }
}
                            

另外,在执行前,记得设置标定文件保存路径即可,其他参数皆在脚本中完成设置。
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值