轮胎外观检测添加思谋语义分割模型检测工具
LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
@@ -39,8 +39,8 @@
        // 采集回调
        private AcquisitionCallbackZA _acquisitionCallback;
        private AcquisitionCompletedCallback _acquisitionCompletedCallback;
        private bool _isConnected = false;
        public bool _isConnected = false;
        private int _frameCount = 0; // 采集帧计数
        // 图像缓冲
@@ -98,11 +98,11 @@
                {
                    byte[] moduleTypeBytes = new byte[64];
                    byte[] serialNumberBytes = new byte[64];
                    if (PHM6000Profiler.GetCameraInformation(tempHandle, i, moduleTypeBytes, serialNumberBytes) == 0)
                    {
                        string currentSn = Encoding.UTF8.GetString(serialNumberBytes).TrimEnd('\0');
                        // 匹配SN或IP
                        if (currentSn == sn || sn.Contains(currentSn))
                        {
@@ -127,7 +127,7 @@
                    if (System.Net.IPAddress.TryParse(sn, out _))
                    {
                        targetIp = sn;
                        targetPort = 5577;
                        targetPort = 5577;
                    }
                    else
                    {
@@ -142,7 +142,7 @@
                var addr = Encoding.ASCII.GetBytes(targetIp);
                int result = PHM6000Profiler.ConnectToCamera(_cameraHandle, addr, targetPort);
                if (result == 0)
                {
                    _isConnected = true;
@@ -169,8 +169,8 @@
                    AsyncLogHelper.Error($"LBCamera[{SN}]: ConnectToCamera failed, result={result}");
                }
            }
            catch (Exception ex)
            {
            catch (Exception ex)
            {
                AsyncLogHelper.Error($"LBCamera: InitDevice异常 - {ex.Message}");
                if (tempHandle != IntPtr.Zero) PHM6000Profiler.DestroyCameraEntry(tempHandle);
            }
@@ -207,7 +207,7 @@
                        if (PHM6000Profiler.GetCameraInformation(tempHandle, i, moduleTypeBytes, serialNumberBytes) == 0)
                        {
                            string sn = Encoding.UTF8.GetString(serialNumberBytes).TrimEnd('\0');
                            if (!string.IsNullOrEmpty(sn))
                            if (!string.IsNullOrEmpty(sn) && sn.Contains("L"))
                            {
                                cameraList.Add(sn);
                            }
@@ -249,7 +249,7 @@
        public bool StartSingleGrab()
        {
            if (!_isConnected) return false;
            _isContinuous = false;
            InitBuffer();
            AsyncLogHelper.Info($"LBCamera[{SN}]: 开始单次采集");
@@ -291,7 +291,7 @@
            _isContinuous = false;
            if (!_isConnected) return true;
            PHM6000Profiler.StopAcquisition(_cameraHandle);
            // 停止时如果有未显示的缓存数据,将其显示出来(支持显示不完整的帧)
            lock (_bufferLock)
            {
@@ -302,7 +302,7 @@
                    _currentLineCount = 0;
                }
            }
            isGrabbing = false;
            return true;
        }
@@ -357,11 +357,11 @@
        public override void SetCamConfig(CameraConfig config) { }
        public override void GetCamConfig(out CameraConfig config) { config = new CameraConfig(null); }
        public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; return false; }
        public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000)
        public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000)
        {
            // 简单实现:软触发等待
            bitmap = null;
            if(!_isConnected) return false;
            if (!_isConnected) return false;
            // 计算理论最小耗时 (仅当使用固定频率触发时)
            int minTime = 0;
@@ -379,18 +379,20 @@
                actualTimeout = minTime + 3000; // 预留3秒余量
                AsyncLogHelper.Warn($"LBCamera: Provided timeout {outtime}ms is too short for {minTime}ms scan. Extended to {actualTimeout}ms.");
            }
            using (AutoResetEvent waitHandle = new AutoResetEvent(false))
            {
                Bitmap res = null;
                EventHandler<CameraEventArgs> handler = (s, e) => {
                    if(e.Bitmap != null) {
                         res = e.Bitmap.Clone() as Bitmap;
                         waitHandle.Set();
                EventHandler<CameraEventArgs> handler = (s, e) =>
                {
                    if (e.Bitmap != null)
                    {
                        res = e.Bitmap.Clone() as Bitmap;
                        waitHandle.Set();
                    }
                };
                ImageGrabbed += handler;
                if (StartSingleGrab())
                {
                    if (!waitHandle.WaitOne(actualTimeout))
@@ -404,10 +406,10 @@
                }
                ImageGrabbed -= handler;
                // 确保停止采集
                StopGrabbing();
                bitmap = res;
                return bitmap != null;
            }
@@ -495,7 +497,7 @@
        }
        #endregion
        #endregion
        #region Callbacks
@@ -530,7 +532,7 @@
                // 提取灰度(Intensity/Alpha)数据填充到 _rawPixelBuffer
                // LBPointZA结构: float(4) + res(3) + alpha(1). Alpha在偏移7
                int bufferOffset = _currentLineCount * _currentBitmapWidth;
                for (int i = 0; i < points; i++)
                {
                    if (bufferOffset + i < _rawPixelBuffer.Length)
@@ -545,7 +547,7 @@
                if (_currentLineCount >= _currentBitmapHeight)
                {
                    CreateAndFireBitmap();
                    // 重置,准备下一帧 (如果是连续采集)
                    _currentLineCount = 0;
                    // _rawPixelBuffer 可以复用,不需要置空
@@ -564,7 +566,7 @@
                {
                    // 如果在连续模式下收到结束信号,尝试自动重启采集
                    AsyncLogHelper.Info($"LBCamera[{SN}]: Continuous mode frame ended, restarting...");
                    Task.Run(() =>
                    Task.Run(() =>
                    {
                        if (_isContinuous && _isConnected)
                        {
@@ -773,7 +775,7 @@
                        int intValue = 0;
                        double doubleValue = 0;
                        int enumValue = 0;
                        if (PHM6000Profiler.GetProfilerParameter(_cameraHandle, (int)nameId, ref intValue, ref doubleValue, ref enumValue) == 0)
                        {
                            if (p.PropertyType == typeof(int))