轮胎外观检测添加思谋语义分割模型检测工具
C3204
14 小时以前 b48ac75b89e94e3f70da5a2233e18734aa271682
LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -2,6 +2,7 @@
using LB_SmartVisionCommon;
using LB_VisionProcesses.Cameras.LBCameras;
using MVSDK_Net;
using Sunny.UI;
using System;
using System.Collections;
using System.Collections.Concurrent;
@@ -102,6 +103,57 @@
                                typeof(IMVDefine.IMV_DeviceInfo));
                        string cameraInfo = $"{deviceInfo.cameraName}[{deviceInfo.serialNumber}]";
                        if (!cameraInfo.Contains("L"))
                        {
                            cameraList.Add(cameraInfo);
                        }
                    }
                }
                else
                {
                    // 记录日志或抛出异常
                    //throw new Exception($"枚举设备失败,错误码:{result}");
                    AsyncLogHelper.Error("枚举设备失败!");
                    System.Diagnostics.Debug.WriteLine("枚举设备失败!");
                }
            }
            catch (Exception ex)
            {
                // 记录错误日志
                System.Diagnostics.Debug.WriteLine($"获取相机列表失败:{ex.Message}");
                AsyncLogHelper.Error($"获取相机列表失败:{ex.Message}");
                throw;
            }
            return cameraList;
        }
        /// <summary>
        /// 获取相机SN枚举列表
        /// </summary>
        /// <returns>相机SN列表</returns>
        public  List<string> GetListEnumAll()
        {
            List<string> cameraList = new List<string>();
            try
            {
                // 枚举所有设备
                IMVDefine.IMV_DeviceList deviceList = new IMVDefine.IMV_DeviceList();
                IMVDefine.IMV_EInterfaceType interfaceType = IMVDefine.IMV_EInterfaceType.interfaceTypeAll;
                int result = MyCamera.IMV_EnumDevices(ref deviceList, (uint)interfaceType);
                if (result == IMVDefine.IMV_OK && deviceList.nDevNum > 0)
                {
                    for (int i = 0; i < deviceList.nDevNum; i++)
                    {
                        IMVDefine.IMV_DeviceInfo deviceInfo = (IMVDefine.IMV_DeviceInfo)
                            Marshal.PtrToStructure(
                                deviceList.pDevInfo + Marshal.SizeOf(typeof(IMVDefine.IMV_DeviceInfo)) * i,
                                typeof(IMVDefine.IMV_DeviceInfo));
                        string cameraInfo = $"{deviceInfo.cameraName}[{deviceInfo.serialNumber}]";
                        cameraList.Add(cameraInfo);
                    }
                }
@@ -150,7 +202,7 @@
                }
                // 枚举设备并匹配SN
                List<string> cameraList = GetListEnum();
                List<string> cameraList = GetListEnumAll();
                int cameraIndex = -1;
                for (int i = 0; i < cameraList.Count; i++)
@@ -233,10 +285,9 @@
                    AsyncLogHelper.Warn(SN + "帧转换为Bitmap失败,跳过处理");
                    return;
                }
                AsyncLogHelper.Info(SN + $"图像已加入缓存,当前缓存数量:{CollectedImages[SN].Count}");
                // 3. 获取/创建线程安全队列
                var queue = CollectedImages.GetOrAdd(SN, new ConcurrentQueue<Bitmap>());
                AsyncLogHelper.Info(SN + $"图像已加入缓存,当前缓存数量:{CollectedImages[SN].Count}");
                // 4. 队列限流,防止内存溢出
                if (queue.Count >= MAX_QUEUE_CAPACITY)
                {
@@ -308,6 +359,7 @@
                            {
                                // 触发图像事件
                                ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, clone, true));
                                CallBackImg = (Bitmap)clone.Clone();
                            }
                            // 触发模式判断
@@ -1408,7 +1460,6 @@
        public override bool GetImage(out Bitmap bitmap, int outtime = 3000)
        {
            bitmap = null;
            try
            {
                // 设置超时时间
@@ -1421,12 +1472,12 @@
                        lock (CallBackImg)
                        {
                            // 保存旧 Bitmap 并释放
                            bitmap = CallBackImg.Clone() as Bitmap; // 创建副本
                            bitmap = CallBackImg; // 创建副本
                        }
                        // 释放旧资源
                        CallBackImg.Dispose();
                        CallBackImg = null;
                        //// 释放旧资源
                        //CallBackImg.Dispose();
                        //CallBackImg = null;
                        return true;
                    }
                }