VisionMaster
1. VM能够做什么
2. 采集
3.模板匹配
4. 查找
5. 斑点分析
6. 边缘查找
7. 矩形检测
8. 位置修正(常用)
9. 平行线、四边形查找
10, 角平分线、中线、中垂线、平行线计算、路径提取
11. 图像处理
二次开发
VisionMaster的TCP通信
Group二次开发
Group模块的使用
OK/NG计数方案搭建
畸变校正和畸变校正的使用
本文档使用 MrDoc 发布
-
+
首页
二次开发
# 显示流程 vmProcedureConfigControl1 # 显示渲染图像 vmRenderControl1 # 通讯模块 vmGlobalToolControl1 # 参数配置(带渲染) vmParamsConfigWithRenderControl1 # 参数配置(不带渲染) vmParamsConfigControl1  ```C# using IMVSHPFeatureMatchModuCs; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using VM.Core; using VM.PlatformSDKCS; using VMControls.Interface; namespace WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { KillProcess("VisionMasterServerApp"); KillProcess("VisionMaster"); KillProcess("VmModuleProxy.exe"); InitializeComponent(); // 注册回调函数,所有流程运行后都会调用 VmSolution.OnWorkStatusEvent += VmSolution_OnWOrkStatusEvent; } private void VmSolution_OnWOrkStatusEvent(ImvsSdkDefine.IMVS_MODULE_WORK_STAUS workStatusInfo) { try { // 为0表示执行完毕,为1表示正在执行,10000表示流程1 if (workStatusInfo.nWorkStatus == 0 && workStatusInfo.nProcessID == 10000) { // 通过流程获取结果 VmProcedure vmProcess1 = VmSolution.Instance["流程1"] as VmProcedure; string rCount = vmProcess1.ModuResult.GetOutputInt("rCount").pIntVal[0].ToString(); string sCount = vmProcess1.ModuResult.GetOutputInt("sCount").pIntVal[0].ToString(); // 在回调里对控件操作需要使用委托 this.BeginInvoke(new Action(() => { vmRenderControl1.ModuleSource = vmProcess1; listBox1.Items.Insert(0, $"箭头个数为{rCount}"); listBox1.Items.Insert(0, $"三角个数为{sCount}"); MessageBox.Show($"{rCount} -- {sCount}"); })); // 通过模块获取结果 IMVSHPFeatureMatchModuTool ivm = VmSolution.Instance["流程1.高精度匹配1"] as IMVSHPFeatureMatchModuTool; string rC = ivm.ModuResult.MatchNum.ToString(); MessageBox.Show($"通过模块获取结果{rC}"); } } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } void KillProcess(string strKillName) { foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) { if (p.ProcessName.Contains(strKillName)) { try { p.Kill(); p.WaitForExit(); } catch(Exception e) { MessageBox.Show("VM Close Error"); } } } } // 打开方案 private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "方案|*.sol"; DialogResult result = ofd.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { textBox1.Text = ofd.FileName; } listBox1.Items.Insert(0, "选择路径成功"); } // 加载方案 private void button2_Click(object sender, EventArgs e) { try { VmSolution.Load(textBox1.Text); listBox1.Items.Insert(0, "方案加载成功"); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 方案执行 private void button4_Click(object sender, EventArgs e) { // 模块的参数配置 vmParamsConfigWithRenderControl1.ModuleSource = VmSolution.Instance["流程1.高精度匹配1"] as IVmModule ; vmParamsConfigControl1.ModuleSource = VmSolution.Instance["流程1.高精度匹配1"] as IVmModule; VmSolution.Instance.SyncRun(); listBox1.Items.Insert(0, "方案执行成功"); //VmProcedure vmProcess1 = (VmProcedure)VmSolution.Instance["流程1"]; //vmRenderControl1.ModuleSource = vmProcess1; //// string s = vmProcess1.ModuResult.GetOutputString("sCount").astStringVal[0].ToString(); //string rCount = vmProcess1.ModuResult.GetOutputInt("rCount").pIntVal[0].ToString(); //listBox1.Items.Insert(0, $"箭头个数为{rCount}"); //string sCount = vmProcess1.ModuResult.GetOutputInt("sCount").pIntVal[0].ToString(); //listBox1.Items.Insert(0, $"三角个数为{sCount}"); //MessageBox.Show($"{rCount} -- {sCount}"); } // 方案保存 private void button3_Click(object sender, EventArgs e) { VmSolution.Save(); listBox1.Items.Insert(0, "方案保存成功"); } // 释放资源 private void Form1_FormClosing(object sender, FormClosingEventArgs e) { VmSolution.Instance.Dispose(); } // 流程下拉框事件 private void comboBox1_DropDown(object sender, EventArgs e) { try { ProcessInfoList vmProcessInfoList = VmSolution.Instance.GetAllProcedureList(); comboBox1.Items.Clear(); for (int item = 0; item < vmProcessInfoList.nNum; item++) { comboBox1.Items.Add(vmProcessInfoList.astProcessInfo[item].strProcessName); } } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 显示单个流程 private void button5_Click(object sender, EventArgs e) { try { vmProcedureConfigControl1.BindSingleProcedure(comboBox1.Text); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 显示多个流程 private void button6_Click(object sender, EventArgs e) { try { vmProcedureConfigControl1.BindMultiProcedure(); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 选择流程 private void button7_Click(object sender, EventArgs e) { try { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "流程|*.prc"; DialogResult result = ofd.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { textBox2.Text = ofd.FileName; } listBox1.Items.Insert(0, "选择流程成功"); } } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 导入流程 private void button11_Click(object sender, EventArgs e) { try { VmSolution.LoadProcedure(textBox2.Text, ""); listBox1.Items.Insert(0, "导入流程成功"); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 导出流程 private void button10_Click(object sender, EventArgs e) { try { VmProcedure vmProcess = VmSolution.Instance[comboBox1.Text] as VmProcedure; vmProcess.SaveAs("测试保存流程.prc"); listBox1.Items.Insert(0, "导出流程成功"); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 删除流程 private void button9_Click(object sender, EventArgs e) { try { VmSolution.Instance.DeleteOneProcedure(comboBox1.Text); listBox1.Items.Insert(0, "删除流程成功"); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } // 运行流程 private void button8_Click(object sender, EventArgs e) { try { VmProcedure vmProcess = VmSolution.Instance[comboBox1.Text] as VmProcedure; vmProcess.Run(); // 流程连续运行 // vmProcess.ContinuousRunEnable = true; listBox1.Items.Insert(0, $"运行一次流程 {comboBox1.Text} 成功"); } catch (VmException ex) { MessageBox.Show(Convert.ToString(ex.errorCode, 16)); } catch (Exception ex) { MessageBox.Show($"Code Error {ex.Message}"); } } } } ```
张泽楠
2025年8月15日 16:39
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码