Ver Fonte

20251110001 海康通用算子的用法更新

向羽 孟 há 1 semana atrás
pai
commit
afbb1428d5

+ 74 - 0
MvvmScaffoldFrame48.DLL/ImageAlgorithm/HikVisionAlgorithmRelated.cs

@@ -12,6 +12,12 @@ namespace MvvmScaffoldFrame48.DLL.ImageAlgorithm
 {
     public static class HikVisionAlgorithmRelated
     {
+        /// <summary>
+        /// Bitmap转MVDImage
+        /// </summary>
+        /// <param name="cBitmapImg"></param>
+        /// <param name="cMvdImg"></param>
+        /// <exception cref="MvdException"></exception>
         public static void ConvertBitmap2MVDImage(Bitmap cBitmapImg, CMvdImage cMvdImg)
         {
             // 参数合法性判断
@@ -90,6 +96,12 @@ namespace MvvmScaffoldFrame48.DLL.ImageAlgorithm
             }
         }
 
+        /// <summary>
+        /// MVDImage转Bitmap
+        /// </summary>
+        /// <param name="cMvdImg"></param>
+        /// <param name="cBitmapImg"></param>
+        /// <exception cref="MvdException"></exception>
         public static void ConvertMVDImage2Bitmap(CMvdImage cMvdImg, ref Bitmap cBitmapImg)
         {
             // 参数合法性判断
@@ -199,5 +211,67 @@ namespace MvvmScaffoldFrame48.DLL.ImageAlgorithm
                 throw ex;
             }
         }
+
+        /// <summary>
+        /// 加载图片(从文件)
+        /// </summary>
+        /// <param name="LoadImagePath"></param>
+        public static CMvdImage LoadImage(string LoadImagePath)
+        {
+            CMvdImage m_stInputImage = null;
+            try
+            {
+                if (!string.IsNullOrEmpty(LoadImagePath))
+                {
+                    if (null == m_stInputImage)
+                    {
+                        m_stInputImage = new CMvdImage();
+                    }
+                    m_stInputImage.InitImage(LoadImagePath);
+                    Console.WriteLine("Finish loading image from [" + LoadImagePath + "].");
+                }
+            }
+            catch (MvdException ex)
+            {
+                Console.WriteLine("Fail to load image from [" + LoadImagePath + "]. ErrorCode: 0x" + ex.ErrorCode.ToString("X"));
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine("Fail to load image from [" + LoadImagePath + "]. Error: " + ex.Message);
+            }
+            return m_stInputImage;
+        }
+
+        /// <summary>
+        /// 加载图片(从Bitmap)
+        /// </summary>
+        /// <param name="bitmap"></param>
+        public static CMvdImage LoadImage(Bitmap bitmap)
+        {
+            CMvdImage m_stInputImage = null;
+            try
+            {
+                if (bitmap != null)
+                {
+                    if (null == m_stInputImage)
+                    {
+                        m_stInputImage = new CMvdImage();
+                    }
+                    //m_stInputImage.InitImage(bitmap);
+                    ConvertBitmap2MVDImage(bitmap, m_stInputImage);
+
+                    Console.WriteLine("Finish loading image from [BitMap].");
+                }
+            }
+            catch (MvdException ex)
+            {
+                Console.WriteLine("Fail to load image from [BitMap]. ErrorCode: 0x" + ex.ErrorCode.ToString("X"));
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine("Fail to load image from [BitMap]. Error: " + ex.Message);
+            }
+            return m_stInputImage;
+        }
     }
 }

+ 1 - 0
MvvmScaffoldFrame48.VIEWMODEL/MvvmScaffoldFrame48.ViewModel.csproj

@@ -57,6 +57,7 @@
     <Reference Include="MVDCNNDetect.Net, Version=4.2.1.4, Culture=neutral, PublicKeyToken=f4e2bfa0ac20f5c4" />
     <Reference Include="MVDShape.Net, Version=4.2.1.4, Culture=neutral, PublicKeyToken=a59215ef735587a6" />
     <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Drawing" />

+ 0 - 8
MvvmScaffoldFrame48.VIEWMODEL/ViewModel/MainViewModel.cs

@@ -1,12 +1,4 @@
 // 演示类
-using MvvmScaffoldFrame48.DLL;
-using MvvmScaffoldFrame48.DLL.AuditTrail;
-using MvvmScaffoldFrame48.DLL.WindowsTools;
-using MvvmScaffoldFrame48.Model;
-using MvvmScaffoldFrame48.Model.StorageModel.AuditTrail;
-using System;
-using System.Collections.ObjectModel;
-using System.Windows.Input;
 
 namespace MvvmScaffoldFrame48.ViewModel.ViewModel
 {

+ 11 - 2
MvvmScaffoldFrame48/WPFFroms/MainWindow.xaml

@@ -5,8 +5,17 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:MvvmScaffoldFrame48"
         mc:Ignorable="d"
-        Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
+        Title="MainWindow" Height="450" Width="800">
     <Grid>
-        <Frame x:Name="ShowFrame" Margin="0,0,0,0" NavigationUIVisibility="Hidden"/>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="80"/>
+            <RowDefinition Height="*"/>
+        </Grid.RowDefinitions>
+        <Grid Grid.Row="0">
+            <Button x:Name="Button" Content="目标检测" Margin="10,10,10,10" Width="80" HorizontalAlignment="Left" Click="Button_Click"/>
+        </Grid>
+        <Grid Grid.Row="1">
+            <Frame x:Name="ShowFrame" Margin="0,0,0,0" NavigationUIVisibility="Hidden"/>
+        </Grid>
     </Grid>
 </Window>

+ 1 - 1
MvvmScaffoldFrame48/WPFFroms/MainWindow.xaml.cs

@@ -15,7 +15,7 @@ namespace MvvmScaffoldFrame48
             InitializeComponent();
         }
 
-        private void Window_Loaded(object sender, RoutedEventArgs e)
+        private void Button_Click(object sender, RoutedEventArgs e)
         {
             Uri ShowUri = new Uri("WPFPage\\DeepObjectDetectPage.xaml", UriKind.Relative);
             ShowFrame.Navigate(ShowUri);

+ 0 - 13
MvvmScaffoldFrame48/WPFPage/DeepObjectDetectPage.xaml.cs

@@ -1,18 +1,5 @@
 using MvvmScaffoldFrame48.ViewModel.ViewModel;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace MvvmScaffoldFrame48.WPFPage
 {