修改瞅瞅

This commit is contained in:
2025-03-10 13:41:12 +08:00
parent 4df6b668bf
commit 0314f4d403
3 changed files with 467 additions and 442 deletions

View File

@ -12,6 +12,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.Xml;
namespace DH.Devices.Vision
@ -171,7 +172,7 @@ namespace DH.Devices.Vision
{
MLResult mlResult = new MLResult();
Mat originMat=new Mat() ;
Mat detectMat;
Mat detectMat= new Mat();
try
{
if (req.mImage == null)
@ -182,7 +183,7 @@ namespace DH.Devices.Vision
}
// resize
detectMat = req.mImage;//1ms
detectMat = req.mImage.Clone();//1ms
@ -200,9 +201,10 @@ namespace DH.Devices.Vision
else if (detectMat.Channels() == 3)
{
// 如果已经是三通道BGR则直接转换为RGB
Cv2.CvtColor( detectMat,originMat, ColorConversionCodes.BGR2RGB);
// Cv2.CvtColor( detectMat,originMat, ColorConversionCodes.BGR2RGB);
// 直接使用原始图像
originMat = detectMat.Clone();
}
//输入数据转化为字节
@ -225,7 +227,7 @@ namespace DH.Devices.Vision
req.confThreshold, req.iouThreshold,
ref outputByte[0],
ref labellist[0]);
//mlResult.IsSuccess = true;
// mlResult.IsSuccess = true;
}
sw.Stop();
@ -257,10 +259,19 @@ namespace DH.Devices.Vision
}
finally
{
req.mImage?.Dispose();
req.mImage = null;
originMat = null;
// 释放 Mat 资源
if (detectMat != null)
{
detectMat.Dispose();
detectMat = null;
}
if (originMat != null)
{
originMat.Dispose();
originMat = null;
}
// GC.Collect();