|
|
@@ -2,6 +2,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
+using System.Drawing.Imaging;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
@@ -42,18 +43,27 @@ namespace MvvmScaffoldFrame48.ViewModel.ViewModel
|
|
|
#region 绑定用Action方法
|
|
|
public void Test(object obj)
|
|
|
{
|
|
|
+ List<Bitmap> bitmaps = new List<Bitmap>();
|
|
|
// 创建一个 Bitmap 对象
|
|
|
Bitmap bitmap = new Bitmap("D:\\work\\MvvmScaffoldFrame48\\MvvmScaffoldFrame48\\MvvmScaffoldFrame48\\testfile\\testimage\\2025-08-04-13-28-45-807.jpg");
|
|
|
|
|
|
cPUDeepObject.LoadImage(bitmap);
|
|
|
cPUDeepObject.LoadDeepModel("D:\\work\\MvvmScaffoldFrame48\\MvvmScaffoldFrame48\\MvvmScaffoldFrame48\\testfile\\model\\Detect_20250818T1328175385.bin");
|
|
|
var result = cPUDeepObject.RunDetect();
|
|
|
+ foreach (var item in result)
|
|
|
+ {
|
|
|
+ if (item.LabelName == "A好药")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Rectangle rectangle = new Rectangle(Convert.ToInt32(item.Box.CenterX - (item.Box.Width / 2)), Convert.ToInt32(item.Box.CenterY - (item.Box.Height / 2)), Convert.ToInt32(item.Box.Width), Convert.ToInt32(item.Box.Height));
|
|
|
+ bitmaps.Add(ImageAlgorithmTools.CropBitmap(bitmap, rectangle));
|
|
|
+ }
|
|
|
PrintRectToBitmap(result, ref bitmap);
|
|
|
// 将 Bitmap 转换为 BitmapImage
|
|
|
- BitmapImage bitmapImage = ConvertToBitmapImage(bitmap);
|
|
|
+ BitmapImage bitmapImage = ImageAlgorithmTools.ConvertToBitmapImage(bitmap);
|
|
|
|
|
|
ShowImage = bitmapImage;
|
|
|
-
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -75,23 +85,7 @@ namespace MvvmScaffoldFrame48.ViewModel.ViewModel
|
|
|
TestCommand = new RelayCommand(Test, CanTrue);
|
|
|
}
|
|
|
|
|
|
- // Bitmap 转 BitmapImage 的辅助方法
|
|
|
- private BitmapImage ConvertToBitmapImage(Bitmap bitmap)
|
|
|
- {
|
|
|
- using (MemoryStream memory = new MemoryStream())
|
|
|
- {
|
|
|
- bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
- memory.Position = 0;
|
|
|
- var bitmapImage = new BitmapImage();
|
|
|
- bitmapImage.BeginInit();
|
|
|
- bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
- bitmapImage.DecodePixelWidth = 1440; // 设置目标分辨率宽度
|
|
|
- bitmapImage.DecodePixelHeight = 1080; // 保持宽高比
|
|
|
- bitmapImage.StreamSource = memory;
|
|
|
- bitmapImage.EndInit();
|
|
|
- return bitmapImage;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
public void PrintRectToBitmap(List<CNNDetectPredInfo> RectData , ref Bitmap bitmap)
|
|
|
{
|
|
|
@@ -108,6 +102,8 @@ namespace MvvmScaffoldFrame48.ViewModel.ViewModel
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
#endregion
|
|
|
}
|
|
|
}
|