using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using DH.Commons.Enums;
using DH.Commons.Helper;
using HalconDotNet;
using OpenCvSharp;



namespace DH.Commons.Base
{
    /// <summary>
    /// 视觉处理引擎:1.传统视觉 2.深度学习
    /// CV深度学习 四大领域
    /// Image  Classification 图像分类:判别图中物体是什么,比如是猫还是狗;
    /// Semantic Segmentation 语义分割:对图像进行像素级分类,预测每个像素属于的类别,不区分个体;
    /// Object Detection 目标检测:寻找图像中的物体并进行定位;
    /// Instance Segmentation 实例分割:定位图中每个物体,并进行像素级标注,区分不同个体;
    /// </summary>
    public abstract class VisionEngineBase : DeviceBase
    {
        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(MatSet 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);
        }
        public ImageSaveHelper ImageSaveHelper { get; set; } = new ImageSaveHelper();
        public virtual void SaveImageAsync(string fullname, Bitmap saveMap, ImageFormat imageFormat)
        {
            if (saveMap != null)
            {
                ImageSaveSet imageSaveSet = new ImageSaveSet()
                {
                    FullName = fullname,
                    SaveImage = saveMap.CopyBitmap(),
                    ImageFormat = imageFormat.DeepSerializeClone()

                };

                ImageSaveHelper.ImageSaveAsync(imageSaveSet);
            }
        }
    }
    
  
}