修改保存相机原图和保存结果图命名一致
This commit is contained in:
parent
f9d472295b
commit
428896dbf8
@ -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; }
|
public virtual bool CameraConnect() { return false; }
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace DH.Commons.Base
|
|||||||
|
|
||||||
public HTuple hv_ModelID;
|
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);
|
//public abstract void SaveDetectResultAsync(DetectStationResult detectResult);
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@ -372,7 +373,9 @@ namespace DH.Devices.Camera
|
|||||||
|
|
||||||
};
|
};
|
||||||
InitialImageSet(imageSet);
|
InitialImageSet(imageSet);
|
||||||
OnHImageOutput?.Invoke(DateTime.Now, this, smat);
|
|
||||||
|
var outImgSet = CopyImageSet(imageSet);
|
||||||
|
OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||||
|
|
||||||
//存图
|
//存图
|
||||||
DisplayAndSaveOriginImage(imageSet.Id,SnapshotCount);
|
DisplayAndSaveOriginImage(imageSet.Id,SnapshotCount);
|
||||||
|
@ -368,7 +368,7 @@ namespace DH.Devices.Camera
|
|||||||
throw new NotSupportedException($"Unsupported pixel type: {pFrameInfo.enPixelType}");
|
throw new NotSupportedException($"Unsupported pixel type: {pFrameInfo.enPixelType}");
|
||||||
}
|
}
|
||||||
|
|
||||||
OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
|
//OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -58,7 +58,7 @@ namespace DH.Devices.Vision
|
|||||||
//{
|
//{
|
||||||
// LogAsync(new LogMsg(dt, LogLevel.Error, msg));
|
// 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();
|
DetectStationResult detectResult = new DetectStationResult();
|
||||||
DetectionConfig detectConfig = null;
|
DetectionConfig detectConfig = null;
|
||||||
@ -78,19 +78,20 @@ namespace DH.Devices.Vision
|
|||||||
//未能获得检测配置
|
//未能获得检测配置
|
||||||
return detectResult;
|
return detectResult;
|
||||||
}
|
}
|
||||||
|
detectResult.Id = originImgSet.Id;
|
||||||
detectResult.DetectName = detectConfig.Name;
|
detectResult.DetectName = detectConfig.Name;
|
||||||
detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory;
|
detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory;
|
||||||
detectResult.SaveNGDetect=detectConfig.SaveNGDetect;
|
detectResult.SaveNGDetect=detectConfig.SaveNGDetect;
|
||||||
detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal;
|
detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal;
|
||||||
detectResult.SaveOKDetect=detectConfig.SaveOKDetect;
|
detectResult.SaveOKDetect=detectConfig.SaveOKDetect;
|
||||||
detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal;
|
detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal;
|
||||||
Mat OriginImage = originImgSet.Clone();
|
Mat OriginImage = originImgSet._mat.Clone();
|
||||||
detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap());
|
detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap());
|
||||||
//detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap();
|
//detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap();
|
||||||
Stopwatch sw = new Stopwatch();
|
Stopwatch sw = new Stopwatch();
|
||||||
#region 1.预处理
|
#region 1.预处理
|
||||||
sw.Start();
|
sw.Start();
|
||||||
using (Mat PreTMat = originImgSet.Clone())
|
using (Mat PreTMat = originImgSet._mat.Clone())
|
||||||
{
|
{
|
||||||
PreTreated(detectConfig, detectResult, PreTMat);
|
PreTreated(detectConfig, detectResult, PreTMat);
|
||||||
PreTreated2(detectConfig, detectResult, PreTMat);
|
PreTreated2(detectConfig, detectResult, PreTMat);
|
||||||
@ -142,7 +143,7 @@ namespace DH.Devices.Vision
|
|||||||
req.ResizeHeight = (int)detectConfig.ModelHeight;
|
req.ResizeHeight = (int)detectConfig.ModelHeight;
|
||||||
// req.LabelNames = detectConfig.GetLabelNames();
|
// req.LabelNames = detectConfig.GetLabelNames();
|
||||||
// req.Score = IIConfig.Score;
|
// req.Score = IIConfig.Score;
|
||||||
req.mImage = originImgSet.Clone();
|
req.mImage = originImgSet._mat.Clone();
|
||||||
|
|
||||||
req.in_lable_path = detectConfig.In_lable_path;
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ namespace DHSoftware
|
|||||||
cam.IsEnabled = cameraBase.IsEnabled;
|
cam.IsEnabled = cameraBase.IsEnabled;
|
||||||
HKCameras.Add(cam);
|
HKCameras.Add(cam);
|
||||||
// cam.CameraConnect();
|
// cam.CameraConnect();
|
||||||
cam.OnHImageOutput += OnCameraHImageOutput;
|
//cam.OnHImageOutput += OnCameraHImageOutput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1199,7 +1199,7 @@ namespace DHSoftware
|
|||||||
/// <param name="dt"></param>
|
/// <param name="dt"></param>
|
||||||
/// <param name="camera"></param>
|
/// <param name="camera"></param>
|
||||||
/// <param name="imageSet"></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))
|
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
|
||||||
//{
|
//{
|
||||||
@ -1215,7 +1215,7 @@ namespace DHSoftware
|
|||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
using (Mat localImageSet = imageSet.Clone()) // 复制 Mat 避免并发问题
|
//using (Mat localImageSet = imageSet._mat.Clone()) // 复制 Mat 避免并发问题
|
||||||
{
|
{
|
||||||
// imageSet?.Dispose();
|
// imageSet?.Dispose();
|
||||||
// 拍照计数与物件编号一致,查找对应的产品
|
// 拍照计数与物件编号一致,查找对应的产品
|
||||||
@ -1254,7 +1254,7 @@ namespace DHSoftware
|
|||||||
}
|
}
|
||||||
|
|
||||||
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
|
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
|
||||||
localImageSet.Dispose();
|
imageSet.Dispose();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1263,7 +1263,7 @@ namespace DHSoftware
|
|||||||
|
|
||||||
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
|
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
|
||||||
{
|
{
|
||||||
localImageSet.Dispose();
|
imageSet.Dispose();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1280,11 +1280,11 @@ namespace DHSoftware
|
|||||||
for (int i = 0; i < detectionDict.Count; i++)
|
for (int i = 0; i < detectionDict.Count; i++)
|
||||||
{
|
{
|
||||||
string detectionId = detectionDict[i];
|
string detectionId = detectionDict[i];
|
||||||
|
var tmpImgSet = camera.CopyImageSet(imageSet as MatSet);
|
||||||
|
//imageSet
|
||||||
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
|
// using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
|
||||||
{
|
{
|
||||||
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId);
|
DetectStationResult temp1 = _visionEngine.RunInference(tmpImgSet, detectionId);
|
||||||
|
|
||||||
resultStates.Add(temp1.ResultState);
|
resultStates.Add(temp1.ResultState);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user