From 5ddadba291ea2d9dba78259973594a4664b94f57 Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期四, 08 一月 2026 16:45:35 +0800
Subject: [PATCH] 简化相机逻辑,支持手动数据处理

---
 LB_VisionProcesses/Cameras/2DCameraForm.cs |  127 +++++++++++-------------------------------
 1 files changed, 33 insertions(+), 94 deletions(-)

diff --git a/LB_VisionProcesses/Cameras/2DCameraForm.cs b/LB_VisionProcesses/Cameras/2DCameraForm.cs
index adccb8b..ec8d41b 100644
--- a/LB_VisionProcesses/Cameras/2DCameraForm.cs
+++ b/LB_VisionProcesses/Cameras/2DCameraForm.cs
@@ -253,15 +253,7 @@
                 }
 
                 IntPtr displayHandle = onlinePictureBox.Handle;
-                if (brand == CameraBrand.LBCamera)
-                {
-                    onlinePictureBox.Visible = false;
-                    displayHandle = this.panel_Picture.Handle;
-                }
-                else
-                {
-                    onlinePictureBox.Visible = true;
-                }
+                onlinePictureBox.Visible = true;
 
                 if (cmbSN.Items.Count > 0 && camera.InitDevice(cmbSN.Text.ToString(), displayHandle))
                 {
@@ -402,18 +394,7 @@
         /// <param name="image"></param>
         private void GetImageBllComplete(object sender, CameraEventArgs e)
         {
-            // 瀵逛簬LBCamera锛圫DK鑷姩鏄剧ず妯″紡锛夛紝Bitmap涓簄ull锛屾垜浠彧闇�瑕佺粺璁�
-            if (camera.Brand == CameraBrand.LBCamera)
-            {
-                if (e is LBCameraEventArgs args && args.IsComplete)
-                {
-                    total.iImageCount++;
-                    // 涓嶉渶瑕佹洿鏂皁nlinePictureBox.Image锛孲DK浼氳嚜鍔ㄦ樉绀�
-                }
-                return;
-            }
-
-            // 瀵逛簬2D鐩告満锛堟墜鍔ㄥ鐞嗘ā寮忥級
+            // 瀵逛簬2D鐩告満锛堟墜鍔ㄥ鐞嗘ā寮忥級鍜岀幇鍦ㄧ殑LBCamera锛堟墜鍔ㄥ鐞嗘ā寮忥級
             if (e.Bitmap == null)
                 return;
 
@@ -466,89 +447,47 @@
 
                 if (success)
                 {
-                    // 瀵逛簬LBCamera锛圫DK鑷姩鏄剧ず妯″紡锛夛紝绛夊緟閲囬泦瀹屾垚鍗冲彲
-                    // 瀵逛簬2D鐩告満锛岀瓑寰匓itmap浜嬩欢
-                    if (camera.Brand == CameraBrand.LBCamera)
+                    // 绛夊緟鍥惧儚鏁版嵁
+                    using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                     {
-                        // SDK鑷姩鏄剧ず妯″紡涓嬶紝绛夊緟閲囬泦瀹屾垚
-                        using (AutoResetEvent waitHandle = new AutoResetEvent(false))
+                        Bitmap captured = null;
+                        EventHandler<CameraEventArgs> handler = (s, evt) =>
                         {
-                            bool captured = false;
-                            EventHandler<CameraEventArgs> handler = (s, evt) =>
+                            if (evt.Bitmap != null)
                             {
-                                if (evt is LBCameraEventArgs args && args.IsComplete)
-                                {
-                                    captured = true;
-                                    waitHandle.Set();
-                                }
-                            };
-
-                            camera.ImageGrabbed += handler;
-                            try
-                            {
-                                // 绛夊緟5绉掕秴鏃�
-                                if (waitHandle.WaitOne(5000))
-                                {
-                                    // SDK鑷姩鏄剧ず妯″紡锛屼笉杩斿洖Bitmap
-                                    // 浣嗛噰闆嗗凡瀹屾垚
-                                }
-                                this.BeginInvoke(new Action(() =>
-                                {
-                                    this.lblCapTime.Text = $"{(DateTime.Now - StartTime).TotalMilliseconds}ms";
-                                }));
+                                captured = evt.Bitmap.Clone() as Bitmap;
+                                waitHandle.Set();
                             }
-                            finally
+                        };
+
+                        camera.ImageGrabbed += handler;
+                        try
+                        {
+                            // 绛夊緟5绉掕秴鏃�
+                            if (waitHandle.WaitOne(5000))
                             {
-                                camera.ImageGrabbed -= handler;
-                                camera.StopGrabbing();
+                                bitmap = captured;
                             }
                         }
-                    }
-                    else
-                    {
-                        // 瀵逛簬2D鐩告満锛岀瓑寰呭浘鍍忔暟鎹�
-                        using (AutoResetEvent waitHandle = new AutoResetEvent(false))
+                        finally
                         {
-                            Bitmap captured = null;
-                            EventHandler<CameraEventArgs> handler = (s, evt) =>
-                            {
-                                // 瀵逛簬2D鐩告満锛岀洿鎺ユ帴鏀跺浘鍍�
-                                if (!(evt is LBCameraEventArgs) && evt.Bitmap != null)
-                                {
-                                    captured = evt.Bitmap.Clone() as Bitmap;
-                                    waitHandle.Set();
-                                }
-                            };
-
-                            camera.ImageGrabbed += handler;
-                            try
-                            {
-                                // 绛夊緟5绉掕秴鏃�
-                                if (waitHandle.WaitOne(5000))
-                                {
-                                    bitmap = captured;
-                                }
-                            }
-                            finally
-                            {
-                                camera.ImageGrabbed -= handler;
-                                camera.StopGrabbing();
-                            }
+                            camera.ImageGrabbed -= handler;
+                            camera.StopGrabbing();
                         }
-
-                        this.BeginInvoke(new Action(() =>
-                        {
-                            if (bitmap != null)
-                            {
-                                this.lblCapTime.Text = $"{(DateTime.Now - StartTime).TotalMilliseconds}ms";
-                                onlinePictureBox.Image = bitmap;
-                            }
-                            else
-                            {
-                                this.lblCapTime.Text = "-1ms";
-                            }
-                        }));
                     }
+
+                    this.BeginInvoke(new Action(() =>
+                    {
+                        if (bitmap != null)
+                        {
+                            this.lblCapTime.Text = $"{(DateTime.Now - StartTime).TotalMilliseconds}ms";
+                            onlinePictureBox.Image = bitmap;
+                        }
+                        else
+                        {
+                            this.lblCapTime.Text = "-1ms";
+                        }
+                    }));
                 }
                 else
                 {

--
Gitblit v1.9.3