2025-03-16 13:11:08 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using DH.Commons.Enums;
|
|
|
|
|
using HalconDotNet;
|
|
|
|
|
using OpenCvSharp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-21 08:51:20 +08:00
|
|
|
|
namespace DH.Commons.Base
|
2025-03-16 13:11:08 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 视觉处理引擎:1.传统视觉 2.深度学习
|
|
|
|
|
/// CV深度学习 四大领域
|
|
|
|
|
/// Image Classification 图像分类:判别图中物体是什么,比如是猫还是狗;
|
|
|
|
|
/// Semantic Segmentation 语义分割:对图像进行像素级分类,预测每个像素属于的类别,不区分个体;
|
|
|
|
|
/// Object Detection 目标检测:寻找图像中的物体并进行定位;
|
|
|
|
|
/// Instance Segmentation 实例分割:定位图中每个物体,并进行像素级标注,区分不同个体;
|
|
|
|
|
/// </summary>
|
2025-04-01 18:15:30 +08:00
|
|
|
|
public abstract class VisionEngineBase : DeviceBase
|
2025-03-16 13:11:08 +08:00
|
|
|
|
{
|
|
|
|
|
public List<DetectionConfig> DetectionConfigs = new List<DetectionConfig>();
|
|
|
|
|
#region event
|
|
|
|
|
public event Action<string, List<double>> OnCropParamsOutput;
|
|
|
|
|
public event Action<string, Bitmap, List<IShapeElement>> OnDetectionDone;
|
|
|
|
|
public event Action<string> OnDetectionWarningStop;//有无检测 需要报警停机
|
|
|
|
|
#endregion
|
|
|
|
|
//public VisionEngineInitialConfigBase IConfig
|
|
|
|
|
//{
|
|
|
|
|
// get => InitialConfig as VisionEngineInitialConfigBase;
|
|
|
|
|
//}
|
|
|
|
|
// public ImageSaveHelper ImageSaveHelper { get; set; } = new ImageSaveHelper();
|
|
|
|
|
public string BatchNO { get; set; }
|
|
|
|
|
|
|
|
|
|
public HTuple hv_ModelID;
|
|
|
|
|
|
|
|
|
|
public abstract DetectStationResult RunInference(Mat originImgSet, string detectionId = null);
|
|
|
|
|
|
|
|
|
|
//public abstract void SaveDetectResultAsync(DetectStationResult detectResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void DetectionDone(string detectionId, Bitmap image, List<IShapeElement> detectionResults)
|
|
|
|
|
{
|
|
|
|
|
OnDetectionDone?.Invoke(detectionId, image, detectionResults);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void DetectionWarningStop(string detectionDes)
|
|
|
|
|
{
|
|
|
|
|
OnDetectionWarningStop?.Invoke(detectionDes);
|
|
|
|
|
}
|
2025-04-02 18:26:34 +08:00
|
|
|
|
public ImageSaveHelper ImageSaveHelper { get; set; } = new ImageSaveHelper();
|
2025-03-16 13:11:08 +08:00
|
|
|
|
public virtual void SaveImageAsync(string fullname, Bitmap saveMap, ImageFormat imageFormat)
|
|
|
|
|
{
|
|
|
|
|
if (saveMap != null)
|
|
|
|
|
{
|
2025-04-02 18:26:34 +08:00
|
|
|
|
ImageSaveSet imageSaveSet = new ImageSaveSet()
|
|
|
|
|
{
|
|
|
|
|
FullName = fullname,
|
|
|
|
|
SaveImage = saveMap,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ImageSaveHelper.ImageSaveAsync(imageSaveSet);
|
2025-03-16 13:11:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-01 18:15:30 +08:00
|
|
|
|
|
|
|
|
|
|
2025-03-16 13:11:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|