From eb3e5c90006ab2b1b485000e7622941ff11a2b51 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期四, 25 十二月 2025 16:07:17 +0800
Subject: [PATCH] ”修复log显示以及文件大小问题。“

---
 LB_VisionProcesses/Alogrithms/Halcon/2D/HFindMultiModelTool/HFindMultiModelTool.cs |   22 +
 LB_SmartVision/VisionForm.cs                                                       |    2 
 LB_VisionProcesses/Alogrithms/OpenCvSharp/BlobTool/BlobToolEdit.cs                 |   72 ++-
 LB_VisionProcesses/Alogrithms/Halcon/2D/HFindCode2dTool/HFindCode2dTool.cs         |   22 +
 LB_VisionProcesses/Alogrithms/OpenCvSharp/FindLineTool/FindLineToolEdit.cs         |  228 ++++++------
 LB_VisionProcesses/Alogrithms/Halcon/2D/HFindLineTool/HFindLineTool.cs             |   29 +
 LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithmEdit.cs                      |   19 
 LB_SmartVision/ProcessRun/ProcessRunBll.cs                                         |    4 
 LB_VisionProcesses/Alogrithms/Halcon/2D/HFindModelTool/HFindModelTool.cs           |   22 +
 LB_VisionProcesses/Alogrithms/BaseAlgorithm/TestTool/TestToolEdit.cs               |   18 
 LB_VisionProcesses/Alogrithms/Halcon/2D/HBlobTool/HBlobTool.cs                     |    5 
 LB_VisionProcesses/Alogrithms/OpenCvSharp/FindModelTool/FindModelToolEdit.cs       |  391 +++++++++++----------
 LB_SmartVision/ProcessRun/ProcessContext.cs                                        |   16 
 LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs                          |  181 ++++++----
 14 files changed, 605 insertions(+), 426 deletions(-)

diff --git a/LB_SmartVision/ProcessRun/ProcessContext.cs b/LB_SmartVision/ProcessRun/ProcessContext.cs
index 0604acf..313c6cb 100644
--- a/LB_SmartVision/ProcessRun/ProcessContext.cs
+++ b/LB_SmartVision/ProcessRun/ProcessContext.cs
@@ -301,7 +301,7 @@
             return res;
         }
 
-        public bool GetImage(Layout layout, out HObject InputImage, out HObject RecordImage)
+        public bool GetImage(Layout layout, out HImage InputImage, out HObject RecordImage)
         {
             InputImage = null; RecordImage = null;
             try
@@ -329,19 +329,23 @@
                     IndexValueName = arrOutputs[2];
 
                     object o_InputImage = ((IProcess)dicContext[IndexProcessName]).OutputImage;
-                    if (o_InputImage is HObject ho_image && ho_image.IsInitialized())
+                    if (o_InputImage is HImage ho_image && ho_image.IsInitialized())
                         InputImage = ho_image;
                     else if (o_InputImage is Bitmap)
                     {
                         //灏哅at杞崲涓篐Object
-                        TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage, out HObject ho_RecordImage);
-                        InputImage = ho_RecordImage;
+                        using (HImage ho_RecordImage = TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage))
+                        {
+                            InputImage = ho_RecordImage.Clone();
+                        }
                     }
                     else if (o_InputImage is Mat)
                     {
                         //灏哅at杞崲涓篐Object
-                        TAlgorithm.Mat2HObject((Mat)o_InputImage, out HObject ho_RecordImage);
-                        InputImage = ho_RecordImage;
+                        using (HImage ho_RecordImage = TAlgorithm.Mat2HObject((Mat)o_InputImage))
+                        {
+                            InputImage = ho_RecordImage.Clone();
+                        }
                     }
 
                     if (InputImage != null && InputImage.IsInitialized())
diff --git a/LB_SmartVision/ProcessRun/ProcessRunBll.cs b/LB_SmartVision/ProcessRun/ProcessRunBll.cs
index ddd7a6c..547af4d 100644
--- a/LB_SmartVision/ProcessRun/ProcessRunBll.cs
+++ b/LB_SmartVision/ProcessRun/ProcessRunBll.cs
@@ -121,12 +121,12 @@
         /// </summary>
         public double RunTime = 0;
 
-        public bool GetImage(Forms.Pages.SettingPage.Layout layout, out HObject InputImage, out HObject RecordImage)
+        public bool GetImage(Forms.Pages.SettingPage.Layout layout, out HImage InputImage, out HObject RecordImage)
         {
             return ProcessContext.GetImage(layout, out InputImage, out RecordImage);
         }
 
-        public bool GetImage(out HObject InputImage, out HObject RecordImage)
+        public bool GetImage(out HImage InputImage, out HObject RecordImage)
         {
             InputImage = null;
             RecordImage = null;
diff --git a/LB_SmartVision/VisionForm.cs b/LB_SmartVision/VisionForm.cs
index 37fd869..53a775f 100644
--- a/LB_SmartVision/VisionForm.cs
+++ b/LB_SmartVision/VisionForm.cs
@@ -1437,7 +1437,7 @@
                         catch { }
                     }
                     // 鐢熸垚鍥剧墖骞舵樉绀哄埌鎺т欢涓�
-                    HObject InputImage = null;
+                    HImage InputImage = null;
                     HObject RecordImage = null;
 
                     foreach (var layout in GlobalVar.dicLayout.Values
diff --git a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs
index 0c95831..830932e 100644
--- a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs
+++ b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs
@@ -64,7 +64,7 @@
                 {
                     if (InputImage is Bitmap)
                     {
-                        TAlgorithm.Bitmap2Mat((Bitmap)InputImage, out Mat src);
+                        Bitmap2Mat((Bitmap)InputImage, out Mat src);
 
                         if (Params.Fixture == null)
                             Params.Fixture = new Fixture();
@@ -96,7 +96,7 @@
 
                                 // 4. 鍒涘缓涓庡師鍥惧ぇ灏忕浉鍚岀殑Mat锛屽苟鍒濆鍖栨棤鏁堝��
                                 image = new Mat(src.Size(), src.Type());
-                                ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
+                                ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
 
                                 // 5. 鍒涘缓閬僵锛氬湪result涓婄粯鍒舵棆杞煩褰紙鐧借壊濉厖锛�
                                 using (Mat cropped = new Mat(src, boundingRect))
@@ -113,7 +113,7 @@
 
                                 // 2. 鍒涘缓涓庡師鍥惧ぇ灏忕浉鍚岀殑Mat锛屽苟鍒濆鍖栨棤鏁堝��
                                 image = new Mat(src.Size(), src.Type());
-                                ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
+                                ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
 
                                 // 3. 鍒涘缓鍦嗗舰閬僵
                                 using (Mat mask = Mat.Zeros(src.Rows, src.Cols, MatType.CV_8UC1))
@@ -127,7 +127,7 @@
                                 image = ((Bitmap)InputImage)?.Clone();
                                 return true;
                         }
-                        TAlgorithm.Mat2Bitmap((Mat)image, out Bitmap bmp);
+                        Mat2Bitmap((Mat)image, out Bitmap bmp);
                         image = bmp;
                         return true;
                     }
@@ -193,7 +193,7 @@
 
                                 // 4. 鍒涘缓涓庡師鍥惧ぇ灏忕浉鍚岀殑Mat锛屽苟鍒濆鍖栨棤鏁堝��
                                 image = new Mat(src.Size(), src.Type());
-                                ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
+                                ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
 
                                 // 5. 鍒涘缓閬僵锛氬湪result涓婄粯鍒舵棆杞煩褰紙鐧借壊濉厖锛�
                                 using (Mat cropped = new Mat(src, boundingRect))
@@ -210,7 +210,7 @@
 
                                 // 2. 鍒涘缓涓庡師鍥惧ぇ灏忕浉鍚岀殑Mat锛屽苟鍒濆鍖栨棤鏁堝��
                                 image = new Mat(src.Size(), src.Type());
-                                ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
+                                ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 鍏ㄩ儴鍒濆鍖栦负鏃犳晥鍊�
 
                                 // 3. 鍒涘缓鍦嗗舰閬僵
                                 using (Mat mask = Mat.Zeros(src.Rows, src.Cols, MatType.CV_8UC1))
@@ -249,27 +249,36 @@
             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;
             }
-
             if (Record != null)
             {
                 Record.Dispose();
@@ -287,13 +296,18 @@
                 if (InputImage != null)
                 {
                     if (InputImage is HObject ho_image && ho_image.IsInitialized())
+                    {
                         obj.InputImage = ho_image.CopyObj(1, -1);
+                    }
                     else if (InputImage is Mat mat && !mat.Empty())
+                    {
                         obj.InputImage = mat.Clone();
+                    }
                     else if (InputImage is Bitmap bitmap)
+                    {
                         obj.InputImage = bitmap.Clone();
+                    }
                 }
-
                 return obj;
             }
             catch { return (TAlgorithm)MemberwiseClone(); }
@@ -303,17 +317,32 @@
         {
             Result = true;
             bCompleted = false;
-            Msg = "";
-            OutputImage = null;
-
+            Msg = string.Empty;
+            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 (Record != null)
+            {
                 Record.Dispose();
+            }
         }
 
         public override bool Run()
         {
             DateTime StartTime = DateTime.Now;
-
             InitRunParams();
             HOperatorSet.GenEmptyObj(out HObject EmptyObj);
             OutputImage = EmptyObj;
@@ -331,7 +360,6 @@
 
                 Thread.Sleep(30);
             }
-
             Msg = "杩愯瓒呮椂";
             Result = false;
             RunTime = (DateTime.Now - StartTime).TotalMilliseconds;
@@ -357,8 +385,9 @@
             try
             {
                 if (string.IsNullOrEmpty(fullPath))
+                {
                     return false;
-
+                }
                 if (!fullPath.Contains(".json"))
                 {
                     Debug.WriteLine("鏂囦欢璺緞涓嶅畬鏁�");
@@ -369,7 +398,6 @@
                     Debug.WriteLine("鏂囦欢璺緞涓嶅畬鏁�");
                     return false;
                 }
-
                 // 鑾峰彇涓嶅甫鏂囦欢鍚嶇殑鐩綍璺緞
                 string directoryPath = Path.GetDirectoryName(fullPath);
                 strProcessName = Path.GetFileNameWithoutExtension(fullPath);
@@ -380,7 +408,6 @@
                     Save(directoryPath);
                     return true;
                 }
-
                 string strJson = string.Empty;
                 using (StreamReader streamReader = new StreamReader(fullPath, Encoding.UTF8))
                 {
@@ -389,8 +416,9 @@
                 }
                 Params = JsonConvert.DeserializeObject<ProcessParams>(strJson);
                 if (Params == null)
+                {
                     return false;
-
+                }
                 Params.FixDeserializedData();
                 return true;
             }
@@ -453,20 +481,21 @@
                 return value;
         }
 
-        public static void Bitmap2HObject(Bitmap bmp, out HObject image)
+        public static HImage Bitmap2HObject(Bitmap bmp)
         {
             BitmapData srcBmpData;
-
+            HImage image = null;
             try
             {
                 if (bmp == null || bmp.Width == 0 || bmp.Height == 0)
                 {
                     image = null;
-                    return;
+                    return image;
                 }
 
                 lock (bmp)
                 {
+                    image = new HImage();
                     switch (bmp.PixelFormat)
                     {
                         case PixelFormat.Format24bppRgb:
@@ -475,35 +504,41 @@
                             int width = bmp.Width;
                             int height = bmp.Height;
                             int stride = srcBmpData.Stride;
-
                             if (stride == width * 3)
-                                HOperatorSet.GenImageInterleaved(out image, srcBmpData.Scan0, "bgr", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0);
+                            {
+                                image.GenImageInterleaved(srcBmpData.Scan0, "bgr", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0);
+                            }
                             else
+                            {
                                 image = HandleStrideAlignmentBest(srcBmpData.Scan0, width, height, stride);
-
+                            }
                             bmp.UnlockBits(srcBmpData);
                             break;
                         default:
                             srcBmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
-                            HOperatorSet.GenImage1(out image, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0);
+                            image.GenImage1("byte", bmp.Width, bmp.Height, srcBmpData.Scan0);
                             bmp.UnlockBits(srcBmpData);
                             break;
                     }
                 }
-                return;
+                return image;
             }
             catch
             {
+                if (image != null)
+                {
+                    image.Dispose();
+                }
                 image = null;
-                return;
+                return image;
             }
         }
 
-        private static HObject HandleStrideAlignmentBest(IntPtr scan0, int width, int height, int stride)
+        private static HImage HandleStrideAlignmentBest(IntPtr scan0, int width, int height, int stride)
         {
             int expectedStride = width * 3;
             byte[] alignedData = new byte[width * height * 3];
-
+            HImage image = new HImage();
             unsafe
             {
                 byte* srcPtr = (byte*)scan0;
@@ -521,31 +556,31 @@
                             expectedStride
                         );
                     }
-                    HOperatorSet.GenImageInterleaved(out HObject ho_img, new IntPtr(dstPtr), "bgr", width, height, 0, "byte", width, height, 0, 0, -1, 0);
-                    return ho_img;
+                    image.GenImageInterleaved(new IntPtr(dstPtr), "bgr", width, height, 0, "byte", width, height, 0, 0, -1, 0);
+                    return image;
                 }
             }
         }
 
-        public static unsafe void HObject2Bitmap(HObject hObject, out Bitmap bmp)
+        public static unsafe void HObject2Bitmap(HImage hImage, out Bitmap bmp)
         {
             try
             {
-                if (hObject == null || !hObject.IsInitialized())
+                if (hImage == null || !hImage.IsInitialized())
                 {
                     bmp = null;
                     return;
                 }
 
                 // 鑾峰彇鍥惧儚淇℃伅
-                HOperatorSet.GetImageSize(hObject, out HTuple width, out HTuple height);
-                HOperatorSet.CountChannels(hObject, out HTuple channels);
+                hImage.GetImageSize(out HTuple width, out HTuple height);
+                HTuple channels = hImage.CountChannels();
 
                 if (channels.I == 1)
                 {
                     // 鐏板害鍥惧鐞�
                     HTuple ptr, type;
-                    HOperatorSet.GetImagePointer1(hObject, out ptr, out type, out width, out height);
+                    ptr = hImage.GetImagePointer1(out type, out width, out height);
 
                     bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
 
@@ -574,7 +609,7 @@
                 {
                     // 褰╄壊鍥惧鐞嗭紙BGR椤哄簭锛�
                     HTuple ptrR, ptrG, ptrB, type;
-                    HOperatorSet.GetImagePointer3(hObject, out ptrR, out ptrG, out ptrB, out type, out width, out height);
+                    hImage.GetImagePointer3(out ptrR, out ptrG, out ptrB, out type, out width, out height);
 
                     bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                     BitmapData bmpData = bmp.LockBits(
@@ -611,20 +646,20 @@
             }
         }
 
-        public static void Mat2HObject(Mat mat, out HObject image)
+        public static HImage Mat2HObject(Mat mat)
         {
+            HImage image = null;
             try
             {
                 if (mat == null || mat.Empty())
                 {
-                    image = null;
-                    return;
+                    return image;
                 }
 
                 if (mat.Type() == MatType.CV_8UC3) // 褰╄壊鍥惧儚 (BGR)
                 {
-                    HOperatorSet.GenImageInterleaved(
-                        out image,
+                    image = new HImage();
+                    image.GenImageInterleaved(
                         mat.Data,
                         "bgr",
                         mat.Width,
@@ -635,8 +670,8 @@
                 }
                 else if (mat.Type() == MatType.CV_8UC1) // 鐏板害鍥惧儚
                 {
-                    HOperatorSet.GenImage1(
-                        out image,
+                    image = new HImage();
+                    image.GenImage1(
                         "byte",
                         mat.Width,
                         mat.Height,
@@ -646,12 +681,12 @@
                 {
                     throw new ArgumentException($"Mat2HObject涓嶆敮鎸佺殑鍥惧儚鏍煎紡锛歿mat.Type()}");
                 }
-                return;
+                return image;
             }
             catch
             {
                 image = null;
-                return;
+                return image;
             }
         }
 
@@ -1251,7 +1286,7 @@
         /// <param name="startPoint"></param>
         /// <param name="endPoint"></param>
         /// <returns></returns>
-        public static double GetDistanceP2P(HPoint startPoint, HPoint endPoint)
+        public double GetDistanceP2P(HPoint startPoint, HPoint endPoint)
         {
             try
             {
@@ -1260,12 +1295,12 @@
             catch { return 9994; }
         }
 
-        public static double GetDistanceP2P(Point startPoint, Point endPoint)
+        public double GetDistanceP2P(Point startPoint, Point endPoint)
         {
             return GetDistanceP2P(new HPoint(startPoint), new HPoint(endPoint));
         }
 
-        public static double DistanceP2P(double startX, double startY, double endX, double endY)
+        public double DistanceP2P(double startX, double startY, double endX, double endY)
         {
             return GetDistanceP2P(new HPoint(startX, startY), new HPoint(endX, endY));
         }
@@ -1276,17 +1311,17 @@
         /// <param name="startPoint"></param>
         /// <param name="endPoint"></param>
         /// <returns></returns>
-        public static HPoint GetMidPoint(HPoint startPoint, HPoint endPoint)
+        public HPoint GetMidPoint(HPoint startPoint, HPoint endPoint)
         {
             return new HPoint((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
         }
 
-        public static Point GetMidPoint(Point startPoint, Point endPoint)
+        public Point GetMidPoint(Point startPoint, Point endPoint)
         {
             return new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
         }
 
-        public static System.Drawing.Point GetMidPoint(System.Drawing.Point startPoint, System.Drawing.Point endPoint)
+        public System.Drawing.Point GetMidPoint(System.Drawing.Point startPoint, System.Drawing.Point endPoint)
         {
             return new System.Drawing.Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
         }
@@ -1297,7 +1332,7 @@
         /// <param name="point"></param>
         /// <param name="segment"></param>
         /// <returns></returns>
-        public static bool IsPointOnSegment(HPoint pt, HSegment segment, double tolerance = 1e-3)
+        public bool IsPointOnSegment(HPoint pt, HSegment segment, double tolerance = 1e-3)
         {
             // 璁$畻鐩寸嚎鏂圭▼鐨勭郴鏁�
             double A = segment.EndY - segment.StartX;
@@ -1320,7 +1355,7 @@
             return false;
         }
 
-        public static bool IsPointOnSegment(double px, double py, double x1, double y1, double x2, double y2)
+        public bool IsPointOnSegment(double px, double py, double x1, double y1, double x2, double y2)
         {
             return IsPointOnSegment(new HPoint(px, py), new HSegment(x1, y1, x2, y2));
         }
@@ -1345,7 +1380,7 @@
             catch { return false; }
         }
 
-        public static bool IsPointNearRectangleSilde(HPoint pt, HRectangle2 rect, double tolerance = 100)
+        public bool IsPointNearRectangleSilde(HPoint pt, HRectangle2 rect, double tolerance = 100)
         {
             return IsPointNearRectangleSilde(new System.Drawing.Point((int)pt.X, (int)pt.Y), new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), tolerance);
         }
@@ -1357,21 +1392,21 @@
         /// <param name="pt2"></param>
         /// <param name="tolerance"></param>
         /// <returns></returns>
-        public static bool IsPointNearPoint(HPoint pt1, HPoint pt2, double tolerance = 100)
+        public bool IsPointNearPoint(HPoint pt1, HPoint pt2, double tolerance = 100)
         {
             if (GetDistanceP2P(pt1, pt2) <= tolerance)
                 return true;
             return false;
         }
 
-        public static bool IsPointNearPoint(Point pt1, Point pt2, double tolerance = 100)
+        public bool IsPointNearPoint(Point pt1, Point pt2, double tolerance = 100)
         {
             if (GetDistanceP2P(pt1, pt2) <= tolerance)
                 return true;
             return false;
         }
 
-        public static bool IsPointNearPoint(double x1, double y1, double x2, double y2, int tolerance = 100)
+        public bool IsPointNearPoint(double x1, double y1, double x2, double y2, int tolerance = 100)
         {
             return IsPointNearPoint(new HPoint(x1, y1), new HPoint(x2, y2), tolerance);
         }
@@ -1384,7 +1419,7 @@
         /// <param name="corner"></param>
         /// <param name="tolerance"></param>
         /// <returns></returns>
-        public static bool IsPointNearRectangleCorner(Point pt, Rectangle rect, out string corner, double tolerance = 10)
+        public bool IsPointNearRectangleCorner(Point pt, Rectangle rect, out string corner, double tolerance = 10)
         {
             try
             {
@@ -1423,7 +1458,7 @@
             catch { corner = ""; return false; }
         }
 
-        public static bool IsPointNearRectangleCorner(HPoint pt, HRectangle2 rect, out string corner, double tolerance = 10)
+        public bool IsPointNearRectangleCorner(HPoint pt, HRectangle2 rect, out string corner, double tolerance = 10)
         {
             try
             {
@@ -1471,7 +1506,7 @@
         /// <param name="p3">绾�2璧峰鐐�</param>
         /// <param name="p4"></param>
         /// <returns></returns>
-        public static Point2d? GetLineIntersection(Point2d p1, Point2d p2, Point2d p3, Point2d p4, bool bOnSegment = false)
+        public Point2d? GetLineIntersection(Point2d p1, Point2d p2, Point2d p3, Point2d p4, bool bOnSegment = false)
         {
             // 鐩寸嚎1鐨勫悜閲�
             double x1 = p1.X, y1 = p1.Y;
@@ -1508,7 +1543,7 @@
         #region Halcon
         // Chapter: Graphics / Output
         // Short Description: Display 3D object models 
-        public static void visualize_object_model_3d(HTuple hv_WindowHandle, HTuple hv_ObjectModel3D,
+        public void visualize_object_model_3d(HTuple hv_WindowHandle, HTuple hv_ObjectModel3D,
             HTuple hv_CamParam, HTuple hv_PoseIn, HTuple hv_GenParamName, HTuple hv_GenParamValue,
             HTuple hv_Title, HTuple hv_Label, HTuple hv_Information, out HTuple hv_PoseOut)
         {
@@ -3236,7 +3271,7 @@
 
         // Chapter: Calibration / Camera Parameters
         // Short Description: Set the value of a specified camera parameter in the camera parameter tuple. 
-        public static void set_cam_par_data(HTuple hv_CameraParamIn, HTuple hv_ParamName, HTuple hv_ParamValue,
+        public void set_cam_par_data(HTuple hv_CameraParamIn, HTuple hv_ParamName, HTuple hv_ParamValue,
             out HTuple hv_CameraParamOut)
         {
             // Local iconic variables 
@@ -3340,7 +3375,7 @@
             }
         }
 
-        public static void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1,
+        public void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1,
             HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth)
         {
             // Stack for temporary objects 
@@ -3514,7 +3549,7 @@
             }
         }
 
-        public static void get_rect2_vertex(HTuple hv_Row, HTuple hv_Column, HTuple hv_Phi, HTuple hv_Length1,
+        public void get_rect2_vertex(HTuple hv_Row, HTuple hv_Column, HTuple hv_Phi, HTuple hv_Length1,
             HTuple hv_Length2, out HTuple hv_TopLeft_Row, out HTuple hv_TopLeft_Col, out HTuple hv_TopRight_Row,
             out HTuple hv_TopRight_Col, out HTuple hv_LowLeft_Row, out HTuple hv_LowLeft_Col,
             out HTuple hv_LowRight_Row, out HTuple hv_LowRight_Col)
@@ -3721,7 +3756,7 @@
             }
         }
 
-        public static void pts_to_best_line(out HObject ho_LineXld, HTuple hv_Rows, HTuple hv_Columns,
+        public void pts_to_best_line(out HObject ho_LineXld, HTuple hv_Rows, HTuple hv_Columns,
             HTuple hv_IgnoreNum, out HTuple hv_Row1, out HTuple hv_Column1, out HTuple hv_Row2,
             out HTuple hv_Column2)
         {
@@ -3807,7 +3842,7 @@
             }
         }
 
-        public static (double, double) CalculateTailValues(HTuple minValue, HTuple maxValue, HTuple mean, HTuple deviation, double tailPercentage = 0.3)
+        public (double, double) CalculateTailValues(HTuple minValue, HTuple maxValue, HTuple mean, HTuple deviation, double tailPercentage = 0.3)
         {
             // 璁$畻浣庡熬鐏板害鍊�
             double lowTailValue = minValue.TupleReal() + (mean.TupleReal() - minValue.TupleReal()) * tailPercentage;
@@ -3840,7 +3875,7 @@
         /// <param name="hv_Column2">缁撴潫妯潗鏍�</param>
         /// <param name="hv_ResultRow">缁撴灉鐐归泦鍚堢旱鍧愭爣</param>
         /// <param name="hv_ResultColumn">缁撴灉鐐归泦鍚堟í鍧愭爣</param>
-        public static void Rake(HObject ho_Image, out HObject ho_Regions, HTuple hv_Elements,
+        public void Rake(HObject ho_Image, out HObject ho_Regions, HTuple hv_Elements,
             HTuple hv_DetectHeight, HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold,
             HTuple hv_Transition, HTuple hv_Select, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2,
             HTuple hv_Column2, out HTuple hv_ResultRow, out HTuple hv_ResultColumn)
@@ -5036,7 +5071,7 @@
             catch { }
         }
 
-        public static void scale_gray_map(HObject ho_Image, out HObject ho_Image1, HTuple hv_Min, HTuple hv_Max)
+        public void scale_gray_map(HObject ho_Image, out HObject ho_Image1, HTuple hv_Min, HTuple hv_Max)
         {
             HTuple hv_Mult = new HTuple(), hv_Add = new HTuple();
             HOperatorSet.GenEmptyObj(out ho_Image1);
@@ -5123,7 +5158,7 @@
 
         #region OpenCVSharp
         // 鏍规嵁Mat绫诲瀷杩斿洖瀵瑰簲鐨勬棤鏁堝��
-        public static Scalar GetInvalidValueForMat(Mat mat)
+        public Scalar GetInvalidValueForMat(Mat mat)
         {
             MatType type = mat.Type();
             if (type == MatType.CV_8UC1 || type == MatType.CV_8UC3)
@@ -5136,7 +5171,7 @@
                 return new Scalar(0); // 瀵逛簬8浣嶆棤绗﹀彿绫诲瀷锛�0鏄畨鍏ㄧ殑鏃犳晥鍊�
         }
 
-        public static void RGB2XYZ(double sR, double sG, double sB, out double X, out double Y, out double Z)
+        public void RGB2XYZ(double sR, double sG, double sB, out double X, out double Y, out double Z)
         {
             // 杈撳叆鐨勯鑹插�� (sR, sG, sB) 搴斾负 0 鍒� 255 涔嬮棿鐨勫��
 
@@ -5167,7 +5202,7 @@
             Z = Math.Round(var_Z / (var_X + var_Y + var_Z), 3);
         }
 
-        public static void ExtractFrames(string videoPath, string outputDir)
+        public void ExtractFrames(string videoPath, string outputDir)
         {
             // 妫�鏌ヨ棰戞枃浠舵槸鍚﹀瓨鍦�
             if (!File.Exists(videoPath))
diff --git a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithmEdit.cs b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithmEdit.cs
index b3701a6..70d13aa 100644
--- a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithmEdit.cs
+++ b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithmEdit.cs
@@ -53,27 +53,36 @@
             get
             {
                 if (Subject == null)
+                {
                     return null;
+                }
                 return Subject.InputImage;
             }
             set
             {
                 Subject.InputImage = value;
-
                 if (InputImage == null)
+                {
                     return;
+                }
 
                 if (InputImage is HObject)
+                {
                     inputImageHSmartWindowControl.ShowHoImage((HObject)value);
+                }
                 else if (InputImage is Bitmap)
                 {
-                    TAlgorithm.Bitmap2HObject((Bitmap)value, out HObject image);
-                    inputImageHSmartWindowControl.ShowHoImage(image);
+                    using (HImage image = TAlgorithm.Bitmap2HObject((Bitmap)value))
+                    {
+                        inputImageHSmartWindowControl.ShowHoImage(image);
+                    }
                 }
                 else if (InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)value, out HObject image);
-                    inputImageHSmartWindowControl.ShowHoImage(image);
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)value))
+                    {
+                        inputImageHSmartWindowControl.ShowHoImage(image);
+                    }
                 }
             }
         }
diff --git a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TestTool/TestToolEdit.cs b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TestTool/TestToolEdit.cs
index 23027d1..5038929 100644
--- a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TestTool/TestToolEdit.cs
+++ b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TestTool/TestToolEdit.cs
@@ -179,18 +179,23 @@
                 {
                     if (Subject.OutputImage is Mat)
                     {
-                        TAlgorithm.Mat2HObject((Mat)Subject.OutputImage, out HObject image);
-                        recordImageHSmartWindowControl.ShowHoImage(image);
+                        using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.OutputImage))
+                        {
+                            recordImageHSmartWindowControl.ShowHoImage(image);
+                        }
                     }
                     else if (Subject.OutputImage is Bitmap)
                     {
-                        TAlgorithm.Bitmap2HObject((Bitmap)Subject.OutputImage, out HObject image);
-                        recordImageHSmartWindowControl.ShowHoImage(image);
+                        using (HImage image = TAlgorithm.Bitmap2HObject((Bitmap)Subject.OutputImage))
+                        {
+                            recordImageHSmartWindowControl.ShowHoImage(image);
+                        }
                     }
                     else if (Subject.OutputImage is HObject)
+                    {
                         recordImageHSmartWindowControl.ShowHoImage((HObject)Subject.OutputImage);
+                    }
                 }
-
                 //鍏堝垽鏂瓙绫诲啀鍒ゆ柇鐖剁被
                 if (Subject.Record != null && Subject.Record is MsgRecord msgRecord)
                 {
@@ -198,15 +203,16 @@
                     recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false);
 
                     for (int i = 0; i < msgRecord.Msg.Length; i++)
+                    {
                         recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i]
                             , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]);
+                    }
                 }
                 else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord)
                 {
                     recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true);
                     recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false);
                 }
-
                 GC.Collect();
             }));
         }
diff --git a/LB_VisionProcesses/Alogrithms/Halcon/2D/HBlobTool/HBlobTool.cs b/LB_VisionProcesses/Alogrithms/Halcon/2D/HBlobTool/HBlobTool.cs
index 4999754..49df5d4 100644
--- a/LB_VisionProcesses/Alogrithms/Halcon/2D/HBlobTool/HBlobTool.cs
+++ b/LB_VisionProcesses/Alogrithms/Halcon/2D/HBlobTool/HBlobTool.cs
@@ -89,12 +89,15 @@
                             BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
                             hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0);
                             ((Bitmap)InputImage).UnlockBits(srcBmpData);
-                            InputImage = null;
+                            ((Bitmap)InputImage).Dispose();
                             InputImage = hImage.Clone();
                         }
                     }
                     catch (Exception ex)
                     {
+                        Msg = "杞浘鍑洪敊锛�" + ex.Message;
+                        Result = false;
+                        return;
                     }
                 }
                 if (!(InputImage is HObject))
diff --git a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindCode2dTool/HFindCode2dTool.cs b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindCode2dTool/HFindCode2dTool.cs
index fcf47ec..879f915 100644
--- a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindCode2dTool/HFindCode2dTool.cs
+++ b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindCode2dTool/HFindCode2dTool.cs
@@ -2,6 +2,7 @@
 using System;
 using System.Collections.Generic;
 using System.Drawing;
+using System.Drawing.Imaging;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -64,6 +65,27 @@
                         Result = false;
                         return;
                     }
+                    if (InputImage is Bitmap)
+                    {
+                        try
+                        {
+                            using (HImage hImage = new HImage())
+                            {
+                                Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height);
+                                BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
+                                hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0);
+                                ((Bitmap)InputImage).UnlockBits(srcBmpData);
+                                ((Bitmap)InputImage).Dispose();
+                                InputImage = hImage.Clone();
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            Msg = "杞浘鍑洪敊锛�" + ex.Message;
+                            Result = false;
+                            return;
+                        }
+                    }
                     if (!(InputImage is HObject))
                     {
                         Msg = "杈撳叆鍥剧墖鏍煎紡涓嶄负Mat";
diff --git a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindLineTool/HFindLineTool.cs b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindLineTool/HFindLineTool.cs
index 533a89c..2ced791 100644
--- a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindLineTool/HFindLineTool.cs
+++ b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindLineTool/HFindLineTool.cs
@@ -3,6 +3,7 @@
 using LB_VisionProcesses.Alogrithms.Halcon;
 using System;
 using System.Collections.Generic;
+using System.Drawing.Imaging;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -61,7 +62,33 @@
                     Result = false;
                     return;
                 }
-
+                if (InputImage is Bitmap)
+                {
+                    try
+                    {
+                        using (HImage hImage = new HImage())
+                        {
+                            Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height);
+                            BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
+                            hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0);
+                            ((Bitmap)InputImage).UnlockBits(srcBmpData);
+                            ((Bitmap)InputImage).Dispose();
+                            InputImage = hImage.Clone();
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        Msg = "杞浘鍑洪敊锛�" + ex.Message;
+                        Result = false;
+                        return;
+                    }
+                }
+                if (!(InputImage is HObject))
+                {
+                    Msg = "杈撳叆鍥剧墖鏍煎紡涓嶄负Mat";
+                    Result = false;
+                    return;
+                }
                 #region 瑁佸壀鍖哄煙
                 if (!(Params.ROI is HSegment))
                 {
diff --git a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindModelTool/HFindModelTool.cs b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindModelTool/HFindModelTool.cs
index 4ca9695..2bd95aa 100644
--- a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindModelTool/HFindModelTool.cs
+++ b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindModelTool/HFindModelTool.cs
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Drawing.Imaging;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -93,6 +94,27 @@
                         Result = false;
                         return;
                     }
+                    if (InputImage is Bitmap)
+                    {
+                        try
+                        {
+                            using (HImage hImage = new HImage())
+                            {
+                                Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height);
+                                BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
+                                hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0);
+                                ((Bitmap)InputImage).UnlockBits(srcBmpData);
+                                ((Bitmap)InputImage).Dispose();
+                                InputImage = hImage.Clone();
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            Msg = "杞浘鍑洪敊锛�" + ex.Message;
+                            Result = false;
+                            return;
+                        }
+                    }
                     if (!(InputImage is HObject))
                     {
                         Msg = "杈撳叆鍥剧墖鏍煎紡涓嶄负HObject";
diff --git a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindMultiModelTool/HFindMultiModelTool.cs b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindMultiModelTool/HFindMultiModelTool.cs
index ee6b699..1ca8acb 100644
--- a/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindMultiModelTool/HFindMultiModelTool.cs
+++ b/LB_VisionProcesses/Alogrithms/Halcon/2D/HFindMultiModelTool/HFindMultiModelTool.cs
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Drawing.Imaging;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -88,6 +89,27 @@
                         Result = false;
                         return;
                     }
+                    if (InputImage is Bitmap)
+                    {
+                        try
+                        {
+                            using (HImage hImage = new HImage())
+                            {
+                                Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height);
+                                BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
+                                hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0);
+                                ((Bitmap)InputImage).UnlockBits(srcBmpData);
+                                ((Bitmap)InputImage).Dispose();
+                                InputImage = hImage.Clone();
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            Msg = "杞浘鍑洪敊锛�"+ ex.Message;
+                            Result = false;
+                            return;
+                        }
+                    }
                     if (!(InputImage is HObject))
                     {
                         Msg = "杈撳叆鍥剧墖鏍煎紡涓嶄负Mat";
diff --git a/LB_VisionProcesses/Alogrithms/OpenCvSharp/BlobTool/BlobToolEdit.cs b/LB_VisionProcesses/Alogrithms/OpenCvSharp/BlobTool/BlobToolEdit.cs
index 5395562..cfe7641 100644
--- a/LB_VisionProcesses/Alogrithms/OpenCvSharp/BlobTool/BlobToolEdit.cs
+++ b/LB_VisionProcesses/Alogrithms/OpenCvSharp/BlobTool/BlobToolEdit.cs
@@ -120,10 +120,11 @@
 
                 if (Subject.InputImage != null && Subject.InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
-                    inputImageHSmartWindowControl.ShowHoImage(image);
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
+                    {
+                        inputImageHSmartWindowControl.ShowHoImage(image);
+                    }
                 }
-
                 Type type = Subject.Params.ROI?.GetType();
                 if (Subject.Params.ROI != null)
                 {
@@ -215,9 +216,11 @@
 
                 if (Subject.InputImage != null && Subject.InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
-                    HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
-                    recordImageHSmartWindowControl.ShowHoImage(image);
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
+                    {
+                        HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
+                        recordImageHSmartWindowControl.ShowHoImage(image);
+                    }
                 }
 
                 //鍏堝垽鏂瓙绫诲啀鍒ゆ柇鐖剁被
@@ -225,10 +228,11 @@
                 {
                     recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_OK, true);
                     recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false);
-
                     for (int i = 0; i < msgRecord.Msg.Length; i++)
+                    {
                         recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i]
                             , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]);
+                    }
                 }
                 else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord)
                 {
@@ -302,32 +306,34 @@
                     HTuple hv_imageHeight = 0;
                     if (InputImage != null && InputImage is Mat)
                     {
-                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image);
-                        HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight);
-                    }
-                    switch (type)
-                    {
-                        case RoiType.Rectangle2:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, 0
-                                , hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
-                            break;
-                        case RoiType.Circle:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HCircle(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, hv_imageWidth.TupleReal() / 4);
-                            break;
-                        //case RoiType.Ellipse:
-                        //    inputImageHSmartWindowControl.oRoi
-                        //        = new HEllipse(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2,0, hv_imageHeight.TupleReal() / 4, hv_imageWidth.TupleReal() / 4);
-                        //    break;
-                        //case RoiType.Segment:
-                        //    inputImageHSmartWindowControl.oRoi
-                        //        = new HSegment(0, 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
-                        //    break;
-                        case RoiType.None:
-                        default:
-                            inputImageHSmartWindowControl.oRoi = null;
-                            break;
+                        using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage))
+                        {
+                            image.GetImageSize(out hv_imageWidth, out hv_imageHeight);
+                            switch (type)
+                            {
+                                case RoiType.Rectangle2:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, 0
+                                        , hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                                    break;
+                                case RoiType.Circle:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HCircle(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, hv_imageWidth.TupleReal() / 4);
+                                    break;
+                                //case RoiType.Ellipse:
+                                //    inputImageHSmartWindowControl.oRoi
+                                //        = new HEllipse(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2,0, hv_imageHeight.TupleReal() / 4, hv_imageWidth.TupleReal() / 4);
+                                //    break;
+                                //case RoiType.Segment:
+                                //    inputImageHSmartWindowControl.oRoi
+                                //        = new HSegment(0, 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                                //    break;
+                                case RoiType.None:
+                                default:
+                                    inputImageHSmartWindowControl.oRoi = null;
+                                    break;
+                            }
+                        }
                     }
                 }
             }
diff --git a/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindLineTool/FindLineToolEdit.cs b/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindLineTool/FindLineToolEdit.cs
index bcfa800..d84fcbd 100644
--- a/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindLineTool/FindLineToolEdit.cs
+++ b/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindLineTool/FindLineToolEdit.cs
@@ -144,61 +144,62 @@
 
                 if (Subject.InputImage != null && Subject.InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
-                    inputImageHSmartWindowControl.ShowHoImage(image);
-                }
-
-                Type type = Subject.Params.ROI?.GetType();
-                if (Subject.Params.ROI != null)
-                {
-                    switch (type)
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
                     {
-                        case Type t when t == typeof(HRectangle2):
-                            cmbTypeRoi.Text = RoiType.Rectangle2.ToString();
-                            break;
-                        case Type t when t == typeof(HCircle):
-                            cmbTypeRoi.Text = RoiType.Circle.ToString();
-                            break;
-                        case Type t when t == typeof(HSegment):
-                            cmbTypeRoi.Text = RoiType.Segment.ToString();
-                            break;
-                        default:
-                            cmbTypeRoi.Text = RoiType.None.ToString();
-                            break;
+                        inputImageHSmartWindowControl.ShowHoImage(image);
+                        Type type = Subject.Params.ROI?.GetType();
+                        if (Subject.Params.ROI != null)
+                        {
+                            switch (type)
+                            {
+                                case Type t when t == typeof(HRectangle2):
+                                    cmbTypeRoi.Text = RoiType.Rectangle2.ToString();
+                                    break;
+                                case Type t when t == typeof(HCircle):
+                                    cmbTypeRoi.Text = RoiType.Circle.ToString();
+                                    break;
+                                case Type t when t == typeof(HSegment):
+                                    cmbTypeRoi.Text = RoiType.Segment.ToString();
+                                    break;
+                                default:
+                                    cmbTypeRoi.Text = RoiType.None.ToString();
+                                    break;
+                            }
+                            if (cmbTypeRoi.Text.ToString() != "None")
+                                ckbDrawRoi.Checked = true;
+                            else
+                                ckbDrawRoi.Checked = false;
+
+                            inputImageHSmartWindowControl.oRoi = Subject.Params.ROI;
+                        }
+
+                        if (Subject.Params.Fixture != null)
+                            cmbFixture.Text = Subject.Params.Fixture.strName;
+                        else
+                            cmbFixture.Text = "";
+
+                        switch (type)
+                        {
+                            case Type t when t == typeof(HRectangle2):
+                                inputImageHSmartWindowControl.oRoi
+                                     = new HRectangle2(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
+                                     , Subject.Params.ROI.Phi + Subject.Params.Fixture.Phi, ((HRectangle2)Subject.Params.ROI).Width, ((HRectangle2)Subject.Params.ROI).Height);
+                                break;
+                            case Type t when t == typeof(HCircle):
+                                inputImageHSmartWindowControl.oRoi
+                                = new HCircle(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
+                                , ((HCircle)Subject.Params.ROI).Radius);
+                                break;
+                            case Type t when t == typeof(HSegment):
+                                inputImageHSmartWindowControl.oRoi
+                                = new HSegment(((HSegment)Subject.Params.ROI).StartX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).StartY + Subject.Params.Fixture.Y
+                                , ((HSegment)Subject.Params.ROI).EndX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).EndY + Subject.Params.Fixture.Y);
+                                break;
+                            default:
+                                inputImageHSmartWindowControl.oRoi = null;
+                                break;
+                        }
                     }
-                    if (cmbTypeRoi.Text.ToString() != "None")
-                        ckbDrawRoi.Checked = true;
-                    else
-                        ckbDrawRoi.Checked = false;
-
-                    inputImageHSmartWindowControl.oRoi = Subject.Params.ROI;
-                }
-
-                if (Subject.Params.Fixture != null)
-                    cmbFixture.Text = Subject.Params.Fixture.strName;
-                else
-                    cmbFixture.Text = "";
-
-                switch (type)
-                {
-                    case Type t when t == typeof(HRectangle2):
-                        inputImageHSmartWindowControl.oRoi
-                             = new HRectangle2(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
-                             , Subject.Params.ROI.Phi + Subject.Params.Fixture.Phi, ((HRectangle2)Subject.Params.ROI).Width, ((HRectangle2)Subject.Params.ROI).Height);
-                        break;
-                    case Type t when t == typeof(HCircle):
-                        inputImageHSmartWindowControl.oRoi
-                        = new HCircle(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
-                        , ((HCircle)Subject.Params.ROI).Radius);
-                        break;
-                    case Type t when t == typeof(HSegment):
-                        inputImageHSmartWindowControl.oRoi
-                        = new HSegment(((HSegment)Subject.Params.ROI).StartX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).StartY + Subject.Params.Fixture.Y
-                        , ((HSegment)Subject.Params.ROI).EndX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).EndY + Subject.Params.Fixture.Y);
-                        break;
-                    default:
-                        inputImageHSmartWindowControl.oRoi = null;
-                        break;
                 }
             }));
         }
@@ -258,27 +259,27 @@
 
                 if (Subject.InputImage != null && Subject.InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
-                    HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
-                    recordImageHSmartWindowControl.ShowHoImage(image);
-                }
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
+                    {
+                        image.GetImageSize(out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
+                        recordImageHSmartWindowControl.ShowHoImage(image);
+                        //鍏堝垽鏂瓙绫诲啀鍒ゆ柇鐖剁被
+                        if (Subject.Record != null && Subject.Record is MsgRecord msgRecord)
+                        {
+                            recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_OK, true);
+                            recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false);
 
-                //鍏堝垽鏂瓙绫诲啀鍒ゆ柇鐖剁被
-                if (Subject.Record != null && Subject.Record is MsgRecord msgRecord)
-                {
-                    recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_OK, true);
-                    recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false);
-
-                    for (int i = 0; i < msgRecord.Msg.Length; i++)
-                        recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i]
-                            , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]);
+                            for (int i = 0; i < msgRecord.Msg.Length; i++)
+                                recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i]
+                                    , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]);
+                        }
+                        else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord)
+                        {
+                            recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true);
+                            recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false);
+                        }
+                    }
                 }
-                else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord)
-                {
-                    recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true);
-                    recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false);
-                }
-
                 GC.Collect();
             }));
         }
@@ -345,28 +346,30 @@
                     HTuple hv_imageHeight = 0;
                     if (InputImage != null && InputImage is Mat)
                     {
-                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image);
-                        HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight);
-                    }
-                    switch (type)
-                    {
-                        case RoiType.Rectangle2:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, 0
-                                , hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
-                            break;
-                        case RoiType.Circle:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HCircle(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, hv_imageWidth.TupleReal() / 4);
-                            break;
-                        case RoiType.Segment:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HSegment(0, 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
-                            break;
-                        case RoiType.None:
-                        default:
-                            inputImageHSmartWindowControl.oRoi = null;
-                            break;
+                        using (HImage image=TAlgorithm.Mat2HObject((Mat)InputImage))
+                        {
+                            image.GetImageSize(out hv_imageWidth, out hv_imageHeight);
+                            switch (type)
+                            {
+                                case RoiType.Rectangle2:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, 0
+                                        , hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                                    break;
+                                case RoiType.Circle:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HCircle(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, hv_imageWidth.TupleReal() / 4);
+                                    break;
+                                case RoiType.Segment:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HSegment(0, 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                                    break;
+                                case RoiType.None:
+                                default:
+                                    inputImageHSmartWindowControl.oRoi = null;
+                                    break;
+                            }
+                        }
                     }
                 }
             }
@@ -397,25 +400,26 @@
 
                     if (InputImage != null && InputImage is Mat)
                     {
-                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image);
-                        inputImageHSmartWindowControl.ShowHoImage(image);
+                        using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage))
+                        {
+                            inputImageHSmartWindowControl.ShowHoImage(image);
+                            int hv_Elements = Convert.ToInt16(itxtCaliperCount.Text);
+                            double hv_DetectHeight = Convert.ToDouble(dtxtCaliperHeight.Text);
+                            double hv_DetectWidth = Convert.ToDouble(dtxtCaliperWidth.Text);
+
+                            double hv_Row1 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).BeginRow + Subject.Params.Fixture.Row);
+                            double hv_Column1 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).BeginColumn + Subject.Params.Fixture.Column);
+                            double hv_Row2 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).EndRow + Subject.Params.Fixture.Row);
+                            double hv_Column2 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).EndColumn + Subject.Params.Fixture.Column);
+
+                            TAlgorithm.GetRakeRegions(null, out HObject ho_Regions, hv_Elements, hv_DetectHeight, hv_DetectWidth
+                                , new HTuple(), new HTuple(), new HTuple(), new HTuple()
+                                , hv_Row1, hv_Column1, hv_Row2, hv_Column2
+                                , out HTuple hv_ResultRow, out HTuple hv_ResultColumn);
+
+                            inputImageHSmartWindowControl.DispObj(ho_Regions);
+                        }
                     }
-
-                    int hv_Elements = Convert.ToInt16(itxtCaliperCount.Text);
-                    double hv_DetectHeight = Convert.ToDouble(dtxtCaliperHeight.Text);
-                    double hv_DetectWidth = Convert.ToDouble(dtxtCaliperWidth.Text);
-
-                    double hv_Row1 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).BeginRow + Subject.Params.Fixture.Row);
-                    double hv_Column1 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).BeginColumn + Subject.Params.Fixture.Column);
-                    double hv_Row2 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).EndRow + Subject.Params.Fixture.Row);
-                    double hv_Column2 = Convert.ToDouble(((HSegment)inputImageHSmartWindowControl.oRoi).EndColumn + Subject.Params.Fixture.Column);
-
-                    TAlgorithm.GetRakeRegions(null, out HObject ho_Regions, hv_Elements, hv_DetectHeight, hv_DetectWidth
-                        , new HTuple(), new HTuple(), new HTuple(), new HTuple()
-                        , hv_Row1, hv_Column1, hv_Row2, hv_Column2
-                        , out HTuple hv_ResultRow, out HTuple hv_ResultColumn);
-
-                    inputImageHSmartWindowControl.DispObj(ho_Regions);
                 }
                 catch { }
             }));
diff --git a/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindModelTool/FindModelToolEdit.cs b/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindModelTool/FindModelToolEdit.cs
index 392ee61..5e2e2df 100644
--- a/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindModelTool/FindModelToolEdit.cs
+++ b/LB_VisionProcesses/Alogrithms/OpenCvSharp/FindModelTool/FindModelToolEdit.cs
@@ -241,64 +241,66 @@
 
                 if (Subject.InputImage != null && Subject.InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
-                    inputImageHSmartWindowControl.ShowHoImage(image);
-                }
-
-                Type type = Subject.Params.ROI?.GetType();
-                if (Subject.Params.ROI != null)
-                {
-                    switch (type)
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
                     {
-                        case Type t when t == typeof(HRectangle2):
-                            cmbTypeRoi.Text = RoiType.Rectangle2.ToString();
-                            break;
-                        case Type t when t == typeof(HCircle):
-                            cmbTypeRoi.Text = RoiType.Circle.ToString();
-                            break;
-                        case Type t when t == typeof(HSegment):
-                            cmbTypeRoi.Text = RoiType.Segment.ToString();
-                            break;
-                        default:
-                            cmbTypeRoi.Text = RoiType.None.ToString();
-                            break;
+                        inputImageHSmartWindowControl.ShowHoImage(image);
+                        Type type = Subject.Params.ROI?.GetType();
+                        if (Subject.Params.ROI != null)
+                        {
+                            switch (type)
+                            {
+                                case Type t when t == typeof(HRectangle2):
+                                    cmbTypeRoi.Text = RoiType.Rectangle2.ToString();
+                                    break;
+                                case Type t when t == typeof(HCircle):
+                                    cmbTypeRoi.Text = RoiType.Circle.ToString();
+                                    break;
+                                case Type t when t == typeof(HSegment):
+                                    cmbTypeRoi.Text = RoiType.Segment.ToString();
+                                    break;
+                                default:
+                                    cmbTypeRoi.Text = RoiType.None.ToString();
+                                    break;
+                            }
+                            if (cmbTypeRoi.Text.ToString() != "None")
+                                ckbDrawRoi.Checked = true;
+                            else
+                                ckbDrawRoi.Checked = false;
+
+                            inputImageHSmartWindowControl.oRoi = Subject.Params.ROI;
+                        }
+
+                        if (Subject.Params.Fixture != null)
+                            cmbFixture.Text = Subject.Params.Fixture.strName;
+                        else
+                            cmbFixture.Text = "";
+
+                        switch (type)
+                        {
+                            case Type t when t == typeof(HRectangle2):
+                                inputImageHSmartWindowControl.oRoi
+                                     = new HRectangle2(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
+                                     , Subject.Params.ROI.Phi + Subject.Params.Fixture.Phi, ((HRectangle2)Subject.Params.ROI).Width, ((HRectangle2)Subject.Params.ROI).Height);
+                                break;
+                            case Type t when t == typeof(HCircle):
+                                inputImageHSmartWindowControl.oRoi
+                                = new HCircle(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
+                                , ((HCircle)Subject.Params.ROI).Radius);
+                                break;
+                            case Type t when t == typeof(HSegment):
+                                inputImageHSmartWindowControl.oRoi
+                                = new HSegment(((HSegment)Subject.Params.ROI).StartX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).StartY + Subject.Params.Fixture.Y
+                                , ((HSegment)Subject.Params.ROI).EndX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).EndY + Subject.Params.Fixture.Y);
+                                break;
+                            default:
+                                inputImageHSmartWindowControl.oRoi = null;
+                                break;
+                        }
+
+                        ShowModel(((FindModelTool)Subject).ModelID);
+
                     }
-                    if (cmbTypeRoi.Text.ToString() != "None")
-                        ckbDrawRoi.Checked = true;
-                    else
-                        ckbDrawRoi.Checked = false;
-
-                    inputImageHSmartWindowControl.oRoi = Subject.Params.ROI;
                 }
-
-                if (Subject.Params.Fixture != null)
-                    cmbFixture.Text = Subject.Params.Fixture.strName;
-                else
-                    cmbFixture.Text = "";
-
-                switch (type)
-                {
-                    case Type t when t == typeof(HRectangle2):
-                        inputImageHSmartWindowControl.oRoi
-                             = new HRectangle2(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
-                             , Subject.Params.ROI.Phi + Subject.Params.Fixture.Phi, ((HRectangle2)Subject.Params.ROI).Width, ((HRectangle2)Subject.Params.ROI).Height);
-                        break;
-                    case Type t when t == typeof(HCircle):
-                        inputImageHSmartWindowControl.oRoi
-                        = new HCircle(Subject.Params.ROI.X + Subject.Params.Fixture.X, Subject.Params.ROI.Y + Subject.Params.Fixture.Y
-                        , ((HCircle)Subject.Params.ROI).Radius);
-                        break;
-                    case Type t when t == typeof(HSegment):
-                        inputImageHSmartWindowControl.oRoi
-                        = new HSegment(((HSegment)Subject.Params.ROI).StartX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).StartY + Subject.Params.Fixture.Y
-                        , ((HSegment)Subject.Params.ROI).EndX + Subject.Params.Fixture.X, ((HSegment)Subject.Params.ROI).EndY + Subject.Params.Fixture.Y);
-                        break;
-                    default:
-                        inputImageHSmartWindowControl.oRoi = null;
-                        break;
-                }
-
-                ShowModel(((FindModelTool)Subject).ModelID);
             }));
         }
 
@@ -357,25 +359,27 @@
 
                 if (Subject.InputImage != null && Subject.InputImage is Mat)
                 {
-                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
-                    HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
-                    recordImageHSmartWindowControl.ShowHoImage(image);
-                }
+                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
+                    {
+                        image.GetImageSize(out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
+                        recordImageHSmartWindowControl.ShowHoImage(image);
+                        //鍏堝垽鏂瓙绫诲啀鍒ゆ柇鐖剁被
+                        if (Subject.Record != null && Subject.Record is MsgRecord msgRecord)
+                        {
+                            recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_OK, true);
+                            recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false);
 
-                //鍏堝垽鏂瓙绫诲啀鍒ゆ柇鐖剁被
-                if (Subject.Record != null && Subject.Record is MsgRecord msgRecord)
-                {
-                    recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_OK, true);
-                    recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false);
+                            for (int i = 0; i < msgRecord.Msg.Length; i++)
+                                recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i]
+                                    , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]);
+                        }
+                        else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord)
+                        {
+                            recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true);
+                            recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false);
+                        }
 
-                    for (int i = 0; i < msgRecord.Msg.Length; i++)
-                        recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i]
-                            , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]);
-                }
-                else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord)
-                {
-                    recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true);
-                    recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false);
+                    }
                 }
 
                 GC.Collect();
@@ -498,28 +502,30 @@
                     HTuple hv_imageHeight = 0;
                     if (InputImage != null && InputImage is Mat)
                     {
-                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image);
-                        HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight);
-                    }
-                    switch (type)
-                    {
-                        case RoiType.Rectangle2:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, 0
-                                , hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
-                            break;
-                        case RoiType.Circle:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HCircle(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, hv_imageWidth.TupleReal() / 4);
-                            break;
-                        case RoiType.Segment:
-                            inputImageHSmartWindowControl.oRoi
-                                = new HSegment(0, 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
-                            break;
-                        case RoiType.None:
-                        default:
-                            inputImageHSmartWindowControl.oRoi = null;
-                            break;
+                        using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage))
+                        {
+                            HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight);
+                            switch (type)
+                            {
+                                case RoiType.Rectangle2:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, 0
+                                        , hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                                    break;
+                                case RoiType.Circle:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HCircle(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2, hv_imageWidth.TupleReal() / 4);
+                                    break;
+                                case RoiType.Segment:
+                                    inputImageHSmartWindowControl.oRoi
+                                        = new HSegment(0, 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                                    break;
+                                case RoiType.None:
+                                default:
+                                    inputImageHSmartWindowControl.oRoi = null;
+                                    break;
+                            }
+                        }
                     }
                 }
             }
@@ -1096,13 +1102,14 @@
             if (InputImage != null && InputImage is Mat)
             {
                 imgTabControl.SelectedTab = tabPageModelImage;
-                TAlgorithm.Mat2HObject((Mat)InputImage, out HObject hoDomainImage);
-
-                HOperatorSet.GetImageSize(hoDomainImage, out HTuple hv_imageWidth, out HTuple hv_imageHeight);
-                createModelImageHSmartWindowControl.ShowHoImage((HObject)hoDomainImage);
-                createModelImageHSmartWindowControl.bAollowDraw = true;
-                createModelImageHSmartWindowControl.oRoi = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2
-                    , 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                using (HImage hoDomainImage = TAlgorithm.Mat2HObject((Mat)InputImage))
+                {
+                    HOperatorSet.GetImageSize(hoDomainImage, out HTuple hv_imageWidth, out HTuple hv_imageHeight);
+                    createModelImageHSmartWindowControl.ShowHoImage((HObject)hoDomainImage);
+                    createModelImageHSmartWindowControl.bAollowDraw = true;
+                    createModelImageHSmartWindowControl.oRoi = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2
+                        , 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
+                }
             }
         }
 
@@ -1113,7 +1120,6 @@
                 if (InputImage != null && InputImage is Mat)
                 {
                     double result = 0;
-
                     if (Enum.TryParse(cmbModelType.Text, out ModelType modelType))
                     {
                         string NumLevels = this.dtxtModelParam1.Text;
@@ -1131,75 +1137,83 @@
                         string Contrast = this.dtxtModelParam11.Text;
                         int MinContrast = Convert.ToInt16(this.dtxtModelParam12.Text);
                         HRectangle2 ROI = (HRectangle2)createModelImageHSmartWindowControl.oRoi;
-
-                        HOperatorSet.GenRectangle2(out HObject hRectangle, ROI.Row, ROI.Column, ROI.Phi, ROI.SemiLength1, ROI.SemiLength2);
-                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject hoDomainImage);
-                        HTuple hv_Channels = new HTuple();
-                        //鍒ゆ柇鏄惁涓虹伆搴﹀浘
-                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
+                        using (HRegion hRectangle = new HRegion())
                         {
-                            try
+                            hRectangle.GenRectangle2(ROI.Row, ROI.Column, ROI.Phi, ROI.SemiLength1, ROI.SemiLength2);
+                            using (HImage hoDomainImage = TAlgorithm.Mat2HObject((Mat)InputImage))
                             {
-                                HOperatorSet.CountChannels(hoDomainImage, out hv_Channels);
-                                if (hv_Channels.TupleInt() != 1)
-                                    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
+                                HTuple hv_Channels = new HTuple();
+                                //鍒ゆ柇鏄惁涓虹伆搴﹀浘
+                                using (HDevDisposeHelper dh = new HDevDisposeHelper())
+                                {
+                                    try
+                                    {
+                                        //hv_Channels = hoDomainImage.CountChannels();
+                                        //if (hv_Channels.TupleInt() != 1)
+                                        //    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
 
-                                //杞崲鍚庡啀娆℃鏌ユ槸鍚︿负鐏板害鍥�
-                                HOperatorSet.CountChannels(hoDomainImage, out hv_Channels);
-                                if (hv_Channels.TupleInt() != 1)
-                                    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
+                                        ////杞崲鍚庡啀娆℃鏌ユ槸鍚︿负鐏板害鍥�
+                                        //HOperatorSet.CountChannels(hoDomainImage, out hv_Channels);
+                                        //if (hv_Channels.TupleInt() != 1)
+                                        //    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
+                                    }
+                                    catch { }
+                                }
+                                HObject hoImageReduced = hoDomainImage.Rgb1ToGray().ReduceDomain(hRectangle);
+                                HOperatorSet.CropDomain(hoImageReduced, out hoImageReduced);
+                                TAlgorithm.HObject2Mat(hoImageReduced, out Mat hoModelImage);
+                                bool bCreateModel = false;
+
+                                switch (modelType)
+                                {
+                                    case ModelType.鐏板害鍖归厤:
+                                        bCreateModel = ((FindModelTool)Subject).CreateModel
+                                            (hoModelImage, modelType, NumLevels
+                                            , AngleStart, AngleExtent, AngleStep
+                                            , ScaleRMin, ScaleRMax, "auto"
+                                            , ScaleCMin, ScaleCMax, "auto"
+                                            , Optimization, Metric, Contrast, MinContrast);
+                                        break;
+                                    default:
+                                        bCreateModel = ((FindModelTool)Subject).CreateModel
+                                            (hoModelImage, modelType, NumLevels
+                                            , AngleStart, AngleExtent, AngleStep
+                                            , ScaleRMin, ScaleRMax, "auto"
+                                            , ScaleCMin, ScaleCMax, "auto"
+                                            , Optimization, Metric, Contrast, MinContrast);
+                                        break;
+                                }
+
+                                if (bCreateModel)
+                                {
+                                    using (HObject ho_ModelContours = new HObject())
+                                    {
+                                        //switch (((FindModelTool)Subject).ModelID.Type)
+                                        //{
+                                        //    case ModelType.灞�閮ㄥ彉褰㈡ā鏉�:
+                                        //        HOperatorSet.GetDeformableModelContours(out ho_ModelContours, ((HFindModelTool)Subject).ModelID.hvModel, 1);
+                                        //        break;
+                                        //    case ModelType.鍚勫悜寮傚舰妯℃澘:
+                                        //    default:
+                                        //        HOperatorSet.GetShapeModelContours(out ho_ModelContours, ((HFindModelTool)Subject).ModelID.hvModel, 1);
+                                        //        break;
+                                        //}
+                                        //HOperatorSet.GetImageSize(((HFindModelTool)Subject).ModelID.hoImage, out HTuple hv_Width, out HTuple hv_Height);
+                                        //HOperatorSet.VectorAngleToRigid(-hv_Height / 2, -hv_Width / 2, 0, 0, 0, 0, out HTuple hv_HomMat2D);
+                                        //HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ModelContours, hv_HomMat2D);
+
+                                        //寤烘ā鎴愬姛瀵艰埅鍒板瓙椤�
+                                        parasTabControl.SelectedTab = tabPageRunParas;
+                                        //modelImageHSmartWindowControl.ShowHoImage(((HFindModelTool)Subject).ModelID.hoImage);
+                                        using (HImage modelImage = TAlgorithm.Mat2HObject(((FindModelTool)Subject).ModelID.hoImage))
+                                        {
+                                            modelImageHSmartWindowControl.ShowHoImage(modelImage);
+                                            modelImageHSmartWindowControl.DispObj(ho_ModelContours, false);
+                                            modelImageHSmartWindowControl.ShowMsg("鍒涘缓妯℃澘鎴愬姛", true);
+                                        }
+                                    }
+                                }
                             }
-                            catch { }
-                        }
-                        HOperatorSet.ReduceDomain(hoDomainImage, hRectangle, out HObject hoImageReduced);
-                        HOperatorSet.CropDomain(hoImageReduced, out hoImageReduced);
-                        TAlgorithm.HObject2Mat(hoImageReduced, out Mat hoModelImage);
-                        bool bCreateModel = false;
-
-                        switch (modelType)
-                        {
-                            case ModelType.鐏板害鍖归厤:
-                                bCreateModel = ((FindModelTool)Subject).CreateModel
-                                    (hoModelImage, modelType, NumLevels
-                                    , AngleStart, AngleExtent, AngleStep
-                                    , ScaleRMin, ScaleRMax, "auto"
-                                    , ScaleCMin, ScaleCMax, "auto"
-                                    , Optimization, Metric, Contrast, MinContrast);
-                                break;
-                            default:
-                                bCreateModel = ((FindModelTool)Subject).CreateModel
-                                    (hoModelImage, modelType, NumLevels
-                                    , AngleStart, AngleExtent, AngleStep
-                                    , ScaleRMin, ScaleRMax, "auto"
-                                    , ScaleCMin, ScaleCMax, "auto"
-                                    , Optimization, Metric, Contrast, MinContrast);
-                                break;
-                        }
-
-                        if (bCreateModel)
-                        {
-                            HObject ho_ModelContours = new HObject();
-                            //switch (((FindModelTool)Subject).ModelID.Type)
-                            //{
-                            //    case ModelType.灞�閮ㄥ彉褰㈡ā鏉�:
-                            //        HOperatorSet.GetDeformableModelContours(out ho_ModelContours, ((HFindModelTool)Subject).ModelID.hvModel, 1);
-                            //        break;
-                            //    case ModelType.鍚勫悜寮傚舰妯℃澘:
-                            //    default:
-                            //        HOperatorSet.GetShapeModelContours(out ho_ModelContours, ((HFindModelTool)Subject).ModelID.hvModel, 1);
-                            //        break;
-                            //}
-                            //HOperatorSet.GetImageSize(((HFindModelTool)Subject).ModelID.hoImage, out HTuple hv_Width, out HTuple hv_Height);
-                            //HOperatorSet.VectorAngleToRigid(-hv_Height / 2, -hv_Width / 2, 0, 0, 0, 0, out HTuple hv_HomMat2D);
-                            //HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ModelContours, hv_HomMat2D);
-
-                            //寤烘ā鎴愬姛瀵艰埅鍒板瓙椤�
-                            parasTabControl.SelectedTab = tabPageRunParas;
-                            //modelImageHSmartWindowControl.ShowHoImage(((HFindModelTool)Subject).ModelID.hoImage);
-                            TAlgorithm.Mat2HObject(((FindModelTool)Subject).ModelID.hoImage, out HObject modelImage);
-                            modelImageHSmartWindowControl.ShowHoImage(modelImage);
-                            modelImageHSmartWindowControl.DispObj(ho_ModelContours, false);
-                            modelImageHSmartWindowControl.ShowMsg("鍒涘缓妯℃澘鎴愬姛", true);
                         }
                     }
                 }
@@ -1215,27 +1229,32 @@
 
                 if (ModelID != null && ModelID.Width > 0)
                 {
-                    HOperatorSet.GenEmptyObj(out HObject ho_ModelContours);
-                    //switch (ModelID.Type)
-                    //{
-                    //    case ModelType.鍚勫悜寮傚舰妯℃澘:
-                    //        HOperatorSet.GetDeformableModelContours(out ho_ModelContours, ModelID.hvModel, 1);
-                    //        break;
-                    //    default:
-                    //        HOperatorSet.GetShapeModelContours(out ho_ModelContours, ModelID.hvModel, 1);
-                    //        break;
-                    //}
+                    //HOperatorSet.GenEmptyObj(out HObject ho_ModelContours);
+                    using (HRegion ho_ModelContours = new HRegion())
+                    {
+                        //switch (ModelID.Type)
+                        //{
+                        //    case ModelType.鍚勫悜寮傚舰妯℃澘:
+                        //        HOperatorSet.GetDeformableModelContours(out ho_ModelContours, ModelID.hvModel, 1);
+                        //        break;
+                        //    default:
+                        //        HOperatorSet.GetShapeModelContours(out ho_ModelContours, ModelID.hvModel, 1);
+                        //        break;
+                        //}
 
-                    //HOperatorSet.GetImageSize(ModelID.hoImage, out HTuple hv_Width, out HTuple hv_Height);
-                    //HOperatorSet.VectorAngleToRigid(-hv_Height / 2, -hv_Width / 2, 0, 0, 0, 0, out HTuple hv_HomMat2D);
-                    //HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ModelContours, hv_HomMat2D);
+                        //HOperatorSet.GetImageSize(ModelID.hoImage, out HTuple hv_Width, out HTuple hv_Height);
+                        //HOperatorSet.VectorAngleToRigid(-hv_Height / 2, -hv_Width / 2, 0, 0, 0, 0, out HTuple hv_HomMat2D);
+                        //HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ModelContours, hv_HomMat2D);
 
-                    modelImageHSmartWindowControl.ClearObj();
-                    TAlgorithm.Mat2HObject(ModelID.hoImage, out HObject hoImage);
-                    //modelImageHSmartWindowControl.ShowHoImage(ModelID.hoImage);
-                    modelImageHSmartWindowControl.ShowHoImage(hoImage);
-                    modelImageHSmartWindowControl.DispObj(ho_ModelContours, false);
-                    modelImageHSmartWindowControl.ShowMsg("鍒涘缓妯℃澘鎴愬姛", true);
+                        modelImageHSmartWindowControl.ClearObj();
+                        using (HImage hoImage = TAlgorithm.Mat2HObject(ModelID.hoImage))
+                        {
+                            //modelImageHSmartWindowControl.ShowHoImage(ModelID.hoImage);
+                            modelImageHSmartWindowControl.ShowHoImage(hoImage);
+                            modelImageHSmartWindowControl.DispObj(ho_ModelContours, false);
+                            modelImageHSmartWindowControl.ShowMsg("鍒涘缓妯℃澘鎴愬姛", true);
+                        }
+                    }
                 }
             }
             catch { }

--
Gitblit v1.9.3