轮胎外观检测添加思谋语义分割模型检测工具
C3204
9 小时以前 b48ac75b89e94e3f70da5a2233e18734aa271682
LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -129,6 +129,54 @@
        }
        /// <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);
                    }
                }
                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>
        /// 初始化相机设备
        /// </summary>
        /// <param name="SN">相机序列号</param>
@@ -154,7 +202,7 @@
                }
                // 枚举设备并匹配SN
                List<string> cameraList = GetListEnum();
                List<string> cameraList = GetListEnumAll();
                int cameraIndex = -1;
                for (int i = 0; i < cameraList.Count; i++)
@@ -1412,7 +1460,6 @@
        public override bool GetImage(out Bitmap bitmap, int outtime = 3000)
        {
            bitmap = null;
            try
            {
                // 设置超时时间
@@ -1425,12 +1472,12 @@
                        lock (CallBackImg)
                        {
                            // 保存旧 Bitmap 并释放
                            bitmap = CallBackImg.Clone() as Bitmap; // 创建副本
                            bitmap = CallBackImg; // 创建副本
                        }
                        // 释放旧资源
                        CallBackImg.Dispose();
                        CallBackImg = null;
                        //// 释放旧资源
                        //CallBackImg.Dispose();
                        //CallBackImg = null;
                        return true;
                    }
                }