From ebcc1d53f14112363bbf539bcaf0202aadcdc9d7 Mon Sep 17 00:00:00 2001
From: C3032 <1057644574@qq.com>
Date: 星期一, 13 四月 2026 12:58:58 +0800
Subject: [PATCH] 2D取图计数功能完成

---
 LB_VisionProcesses/Cameras/CameraConfig.cs |   61 ++++++++++++++++++++++++++++--
 1 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/LB_VisionProcesses/Cameras/CameraConfig.cs b/LB_VisionProcesses/Cameras/CameraConfig.cs
index 66303bd..3b619c9 100644
--- a/LB_VisionProcesses/Cameras/CameraConfig.cs
+++ b/LB_VisionProcesses/Cameras/CameraConfig.cs
@@ -1,6 +1,9 @@
-锘縰sing Newtonsoft.Json;
+锘縰sing HalconDotNet;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
 using OpenCvSharp;
+using OpenCvSharp.Extensions;
+using System;
 using System.Collections.Concurrent;
 using System.Diagnostics;
 using System.Text;
@@ -39,6 +42,11 @@
 
             Params.Inputs.Add("瓒呮椂鏃堕棿", 1000);
             Params.Inputs.Add("鏄惁澶辫触閲嶆柊鍙栧浘", false);
+
+            // 2D杞儙璁℃暟閰嶇疆锛堥粯璁や负1锛岃〃绀�3D妯″紡锛�2D鐩告満璁剧疆涓簄锛�
+            Params.Inputs.Add("ImagesPerTyre", 1);
+            Params.Inputs.Add("褰撳墠杞儙ID", 1);
+            Params.Inputs.Add("褰撳墠鍥惧儚搴忓彿", 0);
         }
 
         /// <summary>
@@ -190,7 +198,7 @@
 
                             Mat src = Cv2.ImRead(SN);
                             if (src != null && !src.Empty())
-                                OutputImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);
+                                OutputImage = src.ToBitmap();
                         }
                     }
                 }
@@ -256,12 +264,17 @@
                     {
                         times--;
                         if (TriggerSource == TriggerSource.Software)
+                        {
                             Camera.GetImageWithSoftTrigger(out bitmap, timeout);
+                        }
                         else
+                        {
                             Camera.GetImage(out bitmap, timeout);
-
+                        }
                         if (bitmap != null)
+                        {
                             break;
+                        }
                         else if (isRegrab)
                         {
                             Debug.WriteLine($"鍙栧浘澶辫触,閲嶆柊鍙栧浘,鍓╀綑娆℃暟:{times}");
@@ -269,8 +282,9 @@
                     } while (times > 0 && isRegrab);
 
                     if (isUpParams)
+                    {
                         Camera.SetCamConfig(oriConfig);
-
+                    }
                     OutputImage = bitmap;
                 }
 
@@ -293,14 +307,49 @@
         {
             Result = true;
             Msg = "";
-            OutputImage = null;
+            if (OutputImage != null)
+            {
+                if (OutputImage is HObject)
+                    ((HObject)OutputImage).Dispose();
+                else if (OutputImage is Mat)
+                    ((Mat)OutputImage).Dispose();
+                else if (OutputImage is Bitmap)
+                    ((Bitmap)OutputImage).Dispose();
 
+                OutputImage = null;
+            }
             if (Record != null)
+            {
                 Record.Dispose();
+                Record = null;
+            }
         }
 
         public override void Dispose()
         {
+            if (InputImage != null)
+            {
+                if (InputImage is HObject)
+                    ((HObject)InputImage).Dispose();
+                else if (InputImage is Mat)
+                    ((Mat)InputImage).Dispose();
+                else if (InputImage is Bitmap)
+                    ((Bitmap)InputImage).Dispose();
+
+                InputImage = null;
+            }
+
+            if (OutputImage != null)
+            {
+                if (OutputImage is HObject)
+                    ((HObject)OutputImage).Dispose();
+                else if (OutputImage is Mat)
+                    ((Mat)OutputImage).Dispose();
+                else if (OutputImage is Bitmap)
+                    ((Bitmap)OutputImage).Dispose();
+
+                OutputImage = null;
+            }
             return;
         }
 
@@ -314,7 +363,9 @@
                 if (OutputImage != null)
                 {
                     if (OutputImage is Bitmap)
+                    {
                         obj.OutputImage = ((Bitmap)OutputImage).Clone();
+                    }
                 }
 
                 return obj;

--
Gitblit v1.9.3