修改保存相机原图和保存结果图命名一致

This commit is contained in:
xhm\HP 2025-04-11 11:09:55 +08:00
parent f9d472295b
commit 428896dbf8
6 changed files with 33 additions and 18 deletions

View File

@ -343,7 +343,18 @@ namespace DH.Commons.Base
}
// 其他方法保持原有逻辑
public Action<DateTime, CameraBase, Mat> OnHImageOutput { get; set; }
public MatSet CopyImageSet(MatSet srcSet)
{
MatSet imageSet = new MatSet
{
Id = srcSet.Id,
_mat = srcSet._mat.Clone(),
// ImageSaveOption = srcSet.ImageSaveOption.Copy(),
ImageTime = srcSet.ImageTime
};
return imageSet;
}
public Action<DateTime, CameraBase, MatSet> OnHImageOutput { get; set; }
public virtual bool CameraConnect() { return false; }

View File

@ -36,7 +36,7 @@ namespace DH.Commons.Base
public HTuple hv_ModelID;
public abstract DetectStationResult RunInference(Mat originImgSet, string detectionId = null);
public abstract DetectStationResult RunInference(MatSet originImgSet, string detectionId = null);
//public abstract void SaveDetectResultAsync(DetectStationResult detectResult);

View File

@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Xml.Linq;
@ -372,7 +373,9 @@ namespace DH.Devices.Camera
};
InitialImageSet(imageSet);
OnHImageOutput?.Invoke(DateTime.Now, this, smat);
var outImgSet = CopyImageSet(imageSet);
OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
//存图
DisplayAndSaveOriginImage(imageSet.Id,SnapshotCount);

View File

@ -368,7 +368,7 @@ namespace DH.Devices.Camera
throw new NotSupportedException($"Unsupported pixel type: {pFrameInfo.enPixelType}");
}
OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
//OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
}
catch (Exception ex)

View File

@ -58,7 +58,7 @@ namespace DH.Devices.Vision
//{
// LogAsync(new LogMsg(dt, LogLevel.Error, msg));
//}
public override DetectStationResult RunInference(Mat originImgSet, string detectionId = null)
public override DetectStationResult RunInference(MatSet originImgSet, string detectionId = null)
{
DetectStationResult detectResult = new DetectStationResult();
DetectionConfig detectConfig = null;
@ -78,19 +78,20 @@ namespace DH.Devices.Vision
//未能获得检测配置
return detectResult;
}
detectResult.Id = originImgSet.Id;
detectResult.DetectName = detectConfig.Name;
detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory;
detectResult.SaveNGDetect=detectConfig.SaveNGDetect;
detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal;
detectResult.SaveOKDetect=detectConfig.SaveOKDetect;
detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal;
Mat OriginImage = originImgSet.Clone();
Mat OriginImage = originImgSet._mat.Clone();
detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap());
//detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap();
Stopwatch sw = new Stopwatch();
#region 1.
sw.Start();
using (Mat PreTMat = originImgSet.Clone())
using (Mat PreTMat = originImgSet._mat.Clone())
{
PreTreated(detectConfig, detectResult, PreTMat);
PreTreated2(detectConfig, detectResult, PreTMat);
@ -142,7 +143,7 @@ namespace DH.Devices.Vision
req.ResizeHeight = (int)detectConfig.ModelHeight;
// req.LabelNames = detectConfig.GetLabelNames();
// req.Score = IIConfig.Score;
req.mImage = originImgSet.Clone();
req.mImage = originImgSet._mat.Clone();
req.in_lable_path = detectConfig.In_lable_path;
@ -308,7 +309,7 @@ namespace DH.Devices.Vision
DisplayDetectionResult(detectResult, originImgSet.Clone(), detectionId);
DisplayDetectionResult(detectResult, originImgSet._mat.Clone(), detectionId);

View File

@ -610,7 +610,7 @@ namespace DHSoftware
cam.IsEnabled = cameraBase.IsEnabled;
HKCameras.Add(cam);
// cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput;
//cam.OnHImageOutput += OnCameraHImageOutput;
}
}
}
@ -1199,7 +1199,7 @@ namespace DHSoftware
/// <param name="dt"></param>
/// <param name="camera"></param>
/// <param name="imageSet"></param>
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, Mat imageSet)
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, MatSet imageSet)
{
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
//{
@ -1215,7 +1215,7 @@ namespace DHSoftware
Task.Run(async () =>
{
using (Mat localImageSet = imageSet.Clone()) // 复制 Mat 避免并发问题
//using (Mat localImageSet = imageSet._mat.Clone()) // 复制 Mat 避免并发问题
{
// imageSet?.Dispose();
// 拍照计数与物件编号一致,查找对应的产品
@ -1254,7 +1254,7 @@ namespace DHSoftware
}
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose();
imageSet.Dispose();
return;
}
@ -1263,7 +1263,7 @@ namespace DHSoftware
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
localImageSet.Dispose();
imageSet.Dispose();
@ -1280,11 +1280,11 @@ namespace DHSoftware
for (int i = 0; i < detectionDict.Count; i++)
{
string detectionId = detectionDict[i];
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
var tmpImgSet = camera.CopyImageSet(imageSet as MatSet);
//imageSet
// using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
{
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId);
DetectStationResult temp1 = _visionEngine.RunInference(tmpImgSet, detectionId);
resultStates.Add(temp1.ResultState);