轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-04-02 3c837a3be1548e296d6ed1afb32ebe418b69db25
LB_VisionProcesses/Cameras/BaseCamera.cs
@@ -1,8 +1,10 @@
using HalconDotNet;
using MvCameraControl;
using LB_SmartVisionCommon;
using LB_VisionProcesses;
using LB_VisionProcesses.Cameras;
using MvCameraControl;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
@@ -36,22 +38,44 @@
        protected Bitmap CallBackImg { get; set; }
        public Bitmap Bitmap;
        private Dictionary<string, List<Bitmap>> _collectedImages;
        public Dictionary<string, List<Bitmap>> CollectedImages
        {
            get => _collectedImages;
            set
            {
                _collectedImages = value;
            }
        }
        //private ConcurrentDictionary<string, ConcurrentQueue<Bitmap>> _collectedImages;
        public ConcurrentDictionary<string, ConcurrentQueue<Bitmap>> CollectedImages = new ConcurrentDictionary<string, ConcurrentQueue<Bitmap>>();
        //{
        //    get => _collectedImages;
        //    set
        //    {
        //        _collectedImages = value;
        //    }
        //}
        /// <summary>
        /// 队列上限,防止内存爆炸
        /// </summary>
        public int MAX_QUEUE_CAPACITY = 30;
        #endregion
        #region  operate
        /// <summary>
        /// 相机销毁时:清空所有缓存,释放全部内存
        /// </summary>
        public virtual void ClearAllImages()
        {
            if (CollectedImages.TryRemove(SN, out var queue))
            {
                while (queue.TryDequeue(out Bitmap bmp))
                {
                    bmp.Dispose();
                }
            }
            AsyncLogHelper.Info($"LBCamera[{SN}]: 已清空所有图像缓存");
        }
        public virtual void Dispose()
        {
            try
            {
                ClearAllImages();
                CloseDevice();
            }
            catch { }