From 87a51c004242323d6bc80c470115ef69117bcb1b Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期五, 26 十二月 2025 09:52:47 +0800
Subject: [PATCH] ”修复一部分工具图像转换问题以及内存释放问题。“
---
LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs | 137 +++++++++++++++++++++++++++++----------------
1 files changed, 88 insertions(+), 49 deletions(-)
diff --git a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs
index 830932e..919f3bd 100644
--- a/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs
+++ b/LB_VisionProcesses/Alogrithms/BaseAlgorithm/TAlgorithm.cs
@@ -131,37 +131,6 @@
image = bmp;
return true;
}
- else if (InputImage is HObject ho_image)
- {
- if (!ho_image.IsInitialized())
- return false;
-
- if (Params.Fixture == null)
- Params.Fixture = new Fixture();
-
- HObject hoDomainImage = null;
-
- switch (Params.ROI?.GetType().Name)
- {
- case "HRectangle2":
- HOperatorSet.GenRectangle2(out HObject hRectangle2, (HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column)
- , (HTuple)(Params.ROI.Phi + Params.Fixture.Phi), (HTuple)((HRectangle2)Params.ROI).SemiLength1, (HTuple)((HRectangle2)Params.ROI).SemiLength2);
- HOperatorSet.ReduceDomain(ho_image, hRectangle2, out hoDomainImage);
- break;
- case "HCircle":
- HOperatorSet.GenCircle(out HObject hCircle, (HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column)
- , (HTuple)((HCircle)Params.ROI).Radius);
- HOperatorSet.ReduceDomain(ho_image, hCircle, out hoDomainImage);
- break;
- case "ROI":
- default:
- image = ho_image.CopyObj(1, -1);
- return true;
- }
-
- image = hoDomainImage;
- return true;
- }
else if (InputImage is Mat)
{
Mat src = ((Mat)InputImage);
@@ -244,6 +213,77 @@
}
}
+ public virtual bool ReduceDomainImage(object InputImage, ref HImage image)
+ {
+ image = null;
+ if (InputImage == null)
+ {
+ image = null;
+ Msg = "杈撳叆鍥剧墖涓虹┖";
+ Result = false;
+ return false;
+ }
+
+ lock (InputImage)
+ {
+ try
+ {
+ if (InputImage is HImage ho_image)
+ {
+ if (!ho_image.IsInitialized())
+ return false;
+
+ if (Params.Fixture == null)
+ Params.Fixture = new Fixture();
+
+ HImage hoDomainImage = null;
+
+ switch (Params.ROI?.GetType().Name)
+ {
+ case "HRectangle2":
+ using (HRegion hRectangle2 = new HRegion())
+ {
+ hRectangle2.GenRectangle2((HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column)
+ , (HTuple)(Params.ROI.Phi + Params.Fixture.Phi), (HTuple)((HRectangle2)Params.ROI).SemiLength1, (HTuple)((HRectangle2)Params.ROI).SemiLength2);
+ hoDomainImage = ho_image.ReduceDomain(hRectangle2);
+ }
+ break;
+ case "HCircle":
+ using (HRegion hCircle = new HRegion())
+ {
+ hCircle.GenCircle((HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column)
+ , (HTuple)((HCircle)Params.ROI).Radius);
+ hoDomainImage = ho_image.ReduceDomain(hCircle);
+ }
+ break;
+ case "ROI":
+ default:
+ image = ho_image.CopyObj(1, -1);
+ return true;
+ }
+
+ image = hoDomainImage;
+ return true;
+ }
+ else
+ {
+ image = null;
+ Msg = $"杈撳叆鏍煎紡涓嶆纭畕InputImage.GetType()}";
+ Result = false;
+ return false;
+ }
+ }
+ catch (Exception ex)
+ {
+ image = null;
+ Msg = $"瑁佸壀鍖哄煙澶辫触,鍘熷洜鏄�:{ex.ToString()}";
+ Result = false;
+ return false;
+ }
+ }
+ }
+
+
public override void Dispose()
{
if (InputImage != null)
@@ -318,22 +358,22 @@
Result = true;
bCompleted = false;
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 (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();
@@ -487,12 +527,11 @@
HImage image = null;
try
{
- if (bmp == null || bmp.Width == 0 || bmp.Height == 0)
+ if (bmp.Tag != null && bmp == null || bmp.Width == 0 || bmp.Height == 0)
{
image = null;
return image;
}
-
lock (bmp)
{
image = new HImage();
--
Gitblit v1.9.3