假设某视觉业务场景需实现如下需求:
需求 |
描述 |
---|---|
需求1 |
方案中包含2个流程:流程1和流程2,其中流程1中包含快速匹配模块。 |
需求2 |
2个流程批量同时执行时,自动将流程1中快速匹配模块的最大匹配个数设置为10。 |
需求3 |
2个流程批量同时执行时,获取流程1中快速匹配模块结果中的匹配个数和匹配点。 |
基于上述业务需求,方案搭建的思路框架如下:
基于上述思路,需搭建流程并自行开发全局脚本。
本节仅对本应用示例的流程的核心操作做简要呈现,具体流程中调用的模块不作赘述。
本节仅对全局脚本中的核心接口调用作简要介绍。其中SDK相关的类、方法和属性的详情,请参见VM的SDK开发指南(.NET)。
上述步骤的完整示例代码如下:
using System; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Collections; using VM.GlobalScript.Methods; using iMVS_6000PlatformSDKCS; using VM.Core; using VM.PlatformSDKCS; using ImageSourceModuleCs; using IMVSFastFeatureMatchModuCs; using System.Collections.Generic; /***************************************** * Example explanation:Example of multi process control operation * Logic Control:Single run, each flow execute once * Continuous run:continuous run, each flow execute continuous * 示例说明: 获取流程对象,模块对象,设置参数,运行,获取结果 * ***************************************/ public class UserGlobalScript : UserGlobalMethods, IScriptMethods { /// <summary> /// Init /// </summary> /// <returns>Success:return 0</returns> public int Init() { //SDK init return InitSDK(); } /// <summary> /// execute function /// Single run:the function execute once /// Continuous run:Repeat the function at regular intervals /// 运行函数 /// 单次执行:该函数执行一次 /// 连续执行:以一定时间间隔重复执行该函数 /// </summary> /// <returns>Success:return 0</returns> public int Process() { //m_operateHandle SDK handle if (m_operateHandle == IntPtr.Zero) { return ImvsSdkPFDefine.IMVS_EC_NULL_PTR; } //All processes are executed by default //If execute in your own define logic,please remove the function :DefaultExecuteProcess, Create your own logic function. //默认执行全部流程, //如果自定义流程执行逻辑,请移除DefaultExecuteProcess方法,编写自定义流程执行逻辑代码 int nRet = 0; IMVSFastFeatureMatchModuTool fastFeatureTool = (IMVSFastFeatureMatchModuTool)VmSolution.Instance["流程1.快速匹配1"]; VmProcedure pro1 = (VmProcedure)VmSolution.Instance["流程1"]; if (fastFeatureTool != null) { FastFeatureMatchParam matchParam = fastFeatureTool.ModuParams; if (matchParam != null) { //设置快速匹配模块运行参数 matchParam.MaxMatchNum = 10; } } if (pro1 != null) { pro1.Run(); //获取快速匹配模块的运行结果 FastFeatureMatchResult matchResult = fastFeatureTool.ModuResult; if (matchResult != null) { //获取匹配个数 int matchnum = matchResult.MatchNum; //获取匹配点 List<PointF> matchpoint = matchResult.MatchPoint; int a = 0; } } return nRet; } }
完成该方案的搭建后,可在VM软件上测试方案效果。
如以下视频所示,流程1的快速匹配模块的最大匹配个数在流程1执行前的初始值为5。流程1和流程2批量执行后,该参数的值自动设置为10。
可在全局脚本中调用MessageBox.Show方法打印全局脚本获取的模块结果,验证全局脚本是否已成功获取。如果弹窗中显示了模块结果的值,则说明全局脚本获取模块结果成功。
如下视频仅以打印匹配个数为例进行说明。