using OpenCvSharp; using OS.Spin.Common; using OS.Spin.Modle.BusinessLayer; using System; using System.Collections.Generic; using System.Linq; namespace OS.Spin.Running { public sealed class Cache { private Dictionary> _flawImgs = new Dictionary>(); private Dictionary> _foreResults = new Dictionary>(); private Dictionary> _imgo_Roi = new Dictionary>(); private Dictionary _mats = new Dictionary(); private MGateWidth _gate = new MGateWidth(); private int _cloths_kind = 0; private double _findWall = 0.7; /// /// 检测强调 /// public double FindWall { get { return _findWall; } set { _findWall = value; } } private bool _camerasOk = false; public int ClothWidth { get; set; } public int GetCount = 0; private const int _cameraCount = 3; private int _okCount = 0; private object _objCameraLock = new object(); public bool CamerasOk { get { return _camerasOk; } set { lock (_objCameraLock) { if (!value) { _okCount = 0; } if (value && _okCount < _cameraCount) { _okCount++; return; } _camerasOk = value; } } } private double _mhWall = 0.9; /// /// 检测质量 /// public double MhWall { get { return _mhWall; } set { _mhWall = value; } } private double _jdWall = 0.4; /// /// 检测精度 /// public double JdWall { get { return _jdWall; } set { _jdWall = value; } } public int Cloths_kind { get { return _cloths_kind; } set { _cloths_kind = value; } } private object _lock = new object(); public MGateWidth GateInfo { get { return _gate; } } public Dictionary Mats { get { return _mats; } set { _mats = value; } } private Dictionary _cameraImg = new Dictionary(); private static Cache _cDk; private static readonly object ObjLock = new object(); private int _flawId = 1; private int _cacheImgId = 0; public int CacheImgId { get { return _cacheImgId; } set { _cacheImgId = value; } } public int FlawId { get { return _flawId++; } set { _flawId = value; } } public static Cache GetInstance() { lock (ObjLock) { return _cDk ?? (_cDk = new Cache()); } } private Cache() { } public List GetFore_Result(int cameraId) { try { if (_foreResults.Keys.Contains(cameraId)) { return _foreResults[cameraId]; } return null; } catch (Exception ex) { LogisTrac.WriteLog(string.Format("GetFore_Result:{0}", ex.Message)); return null; } } public void SetFore_Result(int cameraId, List result) { lock (_lock) { _foreResults[cameraId] = result; } } public List GetImgo_Roi(int cameraId) { try { if (_foreResults.Keys.Contains(cameraId)) { return _imgo_Roi[cameraId]; } return null; } catch (Exception ex) { LogisTrac.WriteLog(string.Format("GetImgo_Roi:{0}", ex.Message)); return null; } } public void SetImgo_Roi(int cameraId, List result) { _imgo_Roi[cameraId] = result; } //public List GetCameraImg(int cameraId) //{ // if (_flawImgs.Keys.Contains(cameraId)) // { // return _flawImgs[cameraId]; // } // return null; //} public void ClearFlawImg(int cameraId) { //_flawImgs[cameraId] = new List(); } //public void AddFlawImg(int cameraId, Mat img) //{ // if(!_flawImgs.Keys.Contains(cameraId)) // { // _flawImgs[cameraId] = new List(); // } // var flaw = new Modle.Sdk.StructInfos.DATA_IMAGE(); // flaw.channel = 3; // flaw.data = img.Data; // flaw.width = img.Width; // flaw.height = img.Height; // _flawImgs[cameraId].Add(flaw); //} //private byte _figureId; //public byte FigureId //{ // set // { // if(value != _figureId) // { // ReLoadAlgorithmInfo(value); // } // _figureId = value; // } // get // { // return _figureId; // } //} private double _cMeter = 0; public double CMeter { get { return _cMeter; } set { _cMeter = value; } } private double _speed = 0; public double Speed { get { return _speed; } set { _speed = value; } } private bool _autoFlaw = true; public bool AutoFlaw { get { return _autoFlaw; } set { _autoFlaw = value; } } //private void ReLoadAlgorithmInfo(byte figureId) //{ // // Todo 加载信息 //} //private Modle.Sdk.StructInfos.DATA_IMAGE _algorithmWidth ; //public Modle.Sdk.StructInfos.DATA_IMAGE AlgorithmWidth //{ // get { return _algorithmWidth; } // private set { _algorithmWidth = value; } //} //private Modle.Sdk.StructInfos.DATA_IMAGE _algorithmHeight; //public Modle.Sdk.StructInfos.DATA_IMAGE AlgorithmHeight //{ // get { return _algorithmHeight; } // private set { _algorithmHeight = value; } //} //private Modle.Sdk.StructInfos.DETC_PARAM _detectionParams; //public Modle.Sdk.StructInfos.DETC_PARAM DetectionParams //{ // get { return _detectionParams; } // set { _detectionParams = value; } //} } }