• VM4.3 二次开发02 方案加载、执行及显示


    效果

    这是二次开发的第二个文章,所以不重复说明环境配置相关的内容。如果不懂的可以看本专栏的上一个文章。

    海康视觉算法平台VisionMaster 4.3.0 C# 二次开发01 加载方案并获取结果-CSDN博客

    界面代码

    1. <Window x:Class="VmTestWpf.App.MainWindow"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    6. xmlns:vm="clr-namespace:VMControls.WPF.Release;assembly=VMControls.WPF.Release"
    7. xmlns:local="clr-namespace:VmTestWpf.App"
    8. mc:Ignorable="d"
    9. Title="MainWindow" Height="450" Width="900">
    10. <Grid>
    11. <Grid.RowDefinitions>
    12. <RowDefinition/>
    13. <RowDefinition Height="45"/>
    14. </Grid.RowDefinitions>
    15. <Grid.ColumnDefinitions>
    16. <ColumnDefinition/>
    17. <ColumnDefinition Width="300"/>
    18. </Grid.ColumnDefinitions>
    19. <!--显示方案执行结果-->
    20. <vm:VmRenderControl Grid.Row="0" Grid.Column="0"
    21. x:Name="vrcRender" />
    22. <!--操作按钮-->
    23. <WrapPanel Grid.Row="1" Grid.Column="0" >
    24. <Button x:Name="btnLoad" Click="btnLoad_Click"
    25. Content="加载方案" Width="100" Height="35" HorizontalAlignment="Left"/>
    26. <Button Grid.Row="1" Grid.Column="1" Name="btnRun" Click="btnRun_Click"
    27. Content="运行" Width="80" Height="35" HorizontalAlignment="Left"
    28. Margin="5"/>
    29. </WrapPanel>
    30. <!--消息显示-->
    31. <ListBox Grid.Row="1" Grid.Column="1" x:Name="lbRunResult">
    32. </ListBox>
    33. </Grid>
    34. </Window>

    按钮代码

    注意命名空间的引用

    using VM.Core;
    using VM.PlatformSDKCS;
    using VMControls.Interface;

    using IMVSCircleFindModuCs;

    1. using IMVSCircleFindModuCs;
    2. using System;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5. using System.Reflection;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. using System.Windows;
    9. using System.Windows.Controls;
    10. using System.Windows.Data;
    11. using System.Windows.Documents;
    12. using System.Windows.Input;
    13. using System.Windows.Media;
    14. using System.Windows.Media.Imaging;
    15. using System.Windows.Navigation;
    16. using System.Windows.Shapes;
    17. using VM.Core;
    18. using VM.PlatformSDKCS;
    19. using VMControls.Interface;
    20. namespace VmTestWpf.App
    21. {
    22. /// <summary>
    23. /// MainWindow.xaml 的交互逻辑
    24. /// </summary>
    25. public partial class MainWindow : Window
    26. {
    27. public MainWindow()
    28. {
    29. InitializeComponent();
    30. Loaded += MainWindow_Loaded;
    31. }
    32. /// <summary>
    33. /// 流程对象
    34. /// </summary>
    35. VmProcedure _vmProcedure;
    36. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    37. {
    38. }
    39. /// <summary>
    40. /// 加载方案
    41. /// </summary>
    42. /// <param name="sender"></param>
    43. /// <param name="e"></param>
    44. private void btnLoad_Click(object sender, RoutedEventArgs e)
    45. {
    46. //加载方案
    47. VmSolution.Load("F:/二期VM视觉学习/标定相机找圆心20240614.sol", string.Empty);
    48. //使用流程名称获取流程对象
    49. _vmProcedure = (VmProcedure)VmSolution.Instance["流程1"];
    50. var msg = "方案加载成功";
    51. lbRunResult.Items.Insert(0, msg);
    52. }
    53. /// <summary>
    54. /// 获取方案结果
    55. /// </summary>
    56. /// <param name="sender"></param>
    57. /// <param name="e"></param>
    58. private void btnGetResult_Click(object sender, RoutedEventArgs e)
    59. {
    60. // 获取应用程序的执行目录
    61. //string appDirectory = Assembly.GetExecutingAssembly().Location;
    62. //appDirectory = appDirectory.Substring(0, appDirectory.LastIndexOf("\\") + 1);
    63. //string imagePathRelative = "TestProCess/01/12345.sol";
    64. //加载方案
    65. VmSolution.Load("F:/二期VM视觉学习/标定相机找圆心20240614.sol", string.Empty);
    66. //使用流程名称获取流程对象
    67. VmProcedure vmProcedure = (VmProcedure)VmSolution.Instance["流程1"];
    68. //运行一次流程才能拿到结果
    69. vmProcedure.SyncRun();
    70. IMVSCircleFindModuTool circleFitResult = (IMVSCircleFindModuTool)VmSolution.Instance["流程1.圆查找1"];
    71. if (circleFitResult != null)
    72. {
    73. MessageBox.Show("获取到的圆心坐标:X:" + circleFitResult.ModuResult.OutputCircle.CenterPoint.X.ToString("0.0000") + ",Y:" + circleFitResult.ModuResult.OutputCircle.CenterPoint.Y.ToString("0.0000"));
    74. }
    75. else
    76. {
    77. MessageBox.Show("失败");
    78. }
    79. }
    80. /// <summary>
    81. /// 运行
    82. /// </summary>
    83. /// <param name="sender"></param>
    84. /// <param name="e"></param>
    85. private void btnRun_Click(object sender, RoutedEventArgs e)
    86. {
    87. if (_vmProcedure != null)
    88. {
    89. //使用流程名称获取流程对象
    90. _vmProcedure = (VmProcedure)VmSolution.Instance["流程1"];
    91. //运行一次流程才能拿到结果
    92. //_vmProcedure.SyncRun();
    93. _vmProcedure.Run();
    94. //获取 圆查找1 结果
    95. IMVSCircleFindModuTool circleFitResult = (IMVSCircleFindModuTool)VmSolution.Instance["流程1.圆查找1"];
    96. if (circleFitResult != null)
    97. {
    98. vrcRender.ModuleSource = circleFitResult;
    99. var msg = "获取到的圆心坐标:X:" + circleFitResult.ModuResult.OutputCircle.CenterPoint.X.ToString("0.0000") + ",Y:" + circleFitResult.ModuResult.OutputCircle.CenterPoint.Y.ToString("0.0000");
    100. lbRunResult.Items.Insert(0, msg);
    101. //MessageBox.Show("获取到的圆心坐标:X:" + circleFitResult.ModuResult.OutputCircle.CenterPoint.X.ToString("0.0000") + ",Y:" + circleFitResult.ModuResult.OutputCircle.CenterPoint.Y.ToString("0.0000"));
    102. }
    103. else
    104. {
    105. MessageBox.Show("失败");
    106. }
    107. }
    108. else
    109. {
    110. MessageBox.Show("流程加载失败");
    111. }
    112. }
    113. }
    114. }

  • 相关阅读:
    目标检测论文解读复现之十五:基于YOLOv5的光学遥感图像舰船 目标检测算法
    电脑桌面图标不见了?三招教你轻松找回
    广州华锐互动:VR技术应用到工程项目施工安全培训的好处
    程序化交易的关键是进场策略和操作纪律
    LCR 034.验证外星语词典
    Redis命令集合
    LeetCode 1503. 所有蚂蚁掉下来前的最后一刻【脑筋急转弯】1618
    创邻科技入选Gartner全球《图数据库管理系统市场指南》代表厂商
    第63篇:美国NSA量子注入攻击的流量特征及检测方法
    MySQL之内存表
  • 原文地址:https://blog.csdn.net/cjh16606260986/article/details/139754684