From 4b3a410a5083970bb2e56d2ab459d860c4fa22d0 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期二, 30 十二月 2025 15:50:42 +0800
Subject: [PATCH] 添加单流程多相机处理功能。
---
LB_SmartVision/ProcessRun/ProcessContext.cs | 107 ++++++++++++++---------------------------------------
1 files changed, 29 insertions(+), 78 deletions(-)
diff --git a/LB_SmartVision/ProcessRun/ProcessContext.cs b/LB_SmartVision/ProcessRun/ProcessContext.cs
index 79d4ada..6f32ad5 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 HImage InputImage, out HImage RecordImage)
+ public bool GetImage(Layout layout, out HObject InputImage, out HObject RecordImage)
{
InputImage = null; RecordImage = null;
try
@@ -329,37 +329,24 @@
IndexValueName = arrOutputs[2];
object o_InputImage = ((IProcess)dicContext[IndexProcessName]).OutputImage;
- if (o_InputImage != null && o_InputImage is HImage ho_image && ho_image.IsInitialized())
- {
- InputImage = ho_image.Clone();
- ho_image.Dispose();
- }
- else if (o_InputImage != null && o_InputImage is Bitmap)
+ if (o_InputImage is HObject ho_image && ho_image.IsInitialized())
+ InputImage = ho_image;
+ else if (o_InputImage is Bitmap)
{
//灏哅at杞崲涓篐Object
- using (HImage ho_RecordImage = TAlgorithm.Bitmap2HImage((Bitmap)o_InputImage))
- {
- if (ho_RecordImage != null && ho_RecordImage.Key != IntPtr.Zero)
- {
- InputImage = ho_RecordImage.Clone();
- }
- }
+ TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage, out HObject ho_RecordImage);
+ InputImage = ho_RecordImage;
}
- else if (o_InputImage != null && o_InputImage is Mat)
+ else if (o_InputImage is Mat)
{
//灏哅at杞崲涓篐Object
- using (HImage ho_RecordImage = TAlgorithm.Mat2HImage((Mat)o_InputImage))
- {
- if (ho_RecordImage != null && ho_RecordImage.Key != IntPtr.Zero)
- {
- InputImage = ho_RecordImage.Clone();
- }
- }
+ TAlgorithm.Mat2HObject((Mat)o_InputImage, out HObject ho_RecordImage);
+ InputImage = ho_RecordImage;
}
- if (InputImage != null && InputImage.Key != IntPtr.Zero && InputImage.IsInitialized())
+ if (InputImage != null && InputImage.IsInitialized())
{
- InputImage.GetImageSize(out ho_ImageWidth, out ho_ImageHeight);
+ HOperatorSet.GetImageSize(InputImage, out ho_ImageWidth, out ho_ImageHeight);
//鍥剧墖灏哄鍙樺寲鎵嶆洿鏂扮獥鍙e昂瀵竅鎻愰珮閫熷害]
if ((ho_ImageWidth.Length > 0 && ho_ImageWidth.TupleInt() != hWindowControl.Size.Width)
@@ -387,13 +374,11 @@
if (dicContext.ContainsKey(IndexProcessName))
{
- using (ObjectRecord objectRecord1 = ((IProcess)dicContext[IndexProcessName]).Record)
+ ObjectRecord objectRecord1 = ((IProcess)dicContext[IndexProcessName]).Record;
+ if (objectRecord1 != null)
{
- if (objectRecord1 != null)
- {
- objectRecord1.Display(hWindowControl.HalconWindow);
- objectRecord1.Dispose();
- }
+ objectRecord1.Display(hWindowControl.HalconWindow);
+ objectRecord1.Dispose();
}
}
}
@@ -407,13 +392,11 @@
if (dicContext.ContainsKey(IndexProcessName))
{
- using (ObjectRecord objectRecord2 = ((IProcess)dicContext[IndexProcessName]).Record)
+ ObjectRecord objectRecord2 = ((IProcess)dicContext[IndexProcessName]).Record;
+ if (objectRecord2 != null)
{
- if (objectRecord2 != null)
- {
- objectRecord2.Display(hWindowControl.HalconWindow);
- objectRecord2.Dispose();
- }
+ objectRecord2.Display(hWindowControl.HalconWindow);
+ objectRecord2.Dispose();
}
}
}
@@ -427,13 +410,11 @@
if (dicContext.ContainsKey(IndexProcessName))
{
- using (ObjectRecord objectRecord3 = ((IProcess)dicContext[IndexProcessName]).Record)
+ ObjectRecord objectRecord3 = ((IProcess)dicContext[IndexProcessName]).Record;
+ if (objectRecord3 != null)
{
- if (objectRecord3 != null)
- {
- objectRecord3.Display(hWindowControl.HalconWindow);
- objectRecord3.Dispose();
- }
+ objectRecord3.Display(hWindowControl.HalconWindow);
+ objectRecord3.Dispose();
}
}
}
@@ -441,13 +422,13 @@
if (Result)
{
Msg = "杩愯鎴愬姛";
- hWindowControl.HalconWindow.SetColor("green");
+ HOperatorSet.SetColor(hWindowControl.HalconWindow, "green");
}
else
- hWindowControl.HalconWindow.SetColor("red");
+ HOperatorSet.SetColor(hWindowControl.HalconWindow, "red");
TAlgorithm.DispMsg(Msg, hWindowControl.HalconWindow, Result ? "green" : "red", 0, 0);
- RecordImage = hWindowControl.HalconWindow.DumpWindowImage();
+ HOperatorSet.DumpWindowImage(out RecordImage, hWindowControl.HalconWindow);
#endregion
return true;
@@ -508,38 +489,7 @@
if (dicContext.TryGetValue(ProcessName, out IProcess obj)
&& obj is IProcess process)
{
- if (process.InputImage != null)
- {
- if (process.InputImage is HObject)
- {
- ((HObject)process.InputImage).Dispose();
- }
- else if (process.InputImage is Mat)
- {
- ((Mat)process.InputImage).Dispose();
- }
- else if (process.InputImage is Bitmap)
- {
- ((Bitmap)process.InputImage).Dispose();
- }
- process.InputImage = null;
- }
- if (process.OutputImage != null)
- {
- if (process.OutputImage is HObject)
- {
- ((HObject)process.OutputImage).Dispose();
- }
- else if (process.OutputImage is Mat)
- {
- ((Mat)process.OutputImage).Dispose();
- }
- else if (process.OutputImage is Bitmap)
- {
- ((Bitmap)process.OutputImage).Dispose();
- }
- process.OutputImage = null;
- }
+ process.InputImage = null;
UpdateInputs(process);
// 涓嶅悓鑺傜偣璺宠繃鐨勬柟寮忎笉鍚�
@@ -589,9 +539,10 @@
[Node("鐩告満鍙栧浘", "鍙栧儚宸ュ叿", "Basic", "鐩告満鍙栧浘")]
public void 鐩告満鍙栧浘(FlowNode node) { RunNodeAsync(node); }
- [Node("Halcon2D鏂戠偣宸ュ叿", "Halcon2D宸ュ叿", "Basic", "Halcon2D鏂戠偣宸ュ叿")]
+ [Node("Halcon2D鏂戠偣宸ュ叿", "Haclon2D宸ュ叿", "Basic", "Halcon2D鏂戠偣宸ュ叿")]
public void Halcon2D鏂戠偣宸ュ叿(FlowNode node) { RunNodeAsync(node); }
+
#endregion
--
Gitblit v1.9.3