C3032
2026-03-18 e90b36a0fb76d9319390b5984a21a83e4748a3b3
LB_SmartVision/ProcessRun/ProcessContext.cs
@@ -9,6 +9,7 @@
using LB_VisionProcesses.Processes.ScriptTool;
using OpenCvSharp;
using System.Collections.Concurrent;
using System.Windows.Media.Media3D;
namespace LB_SmartVision.ProcessRun
{
@@ -301,7 +302,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 +330,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)
                    {
                        //将Mat转换为HObject
                        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)
                    {
                        //将Mat转换为HObject
                        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);
                        //图片尺寸变化才更新窗口尺寸[提高速度]
                        if ((ho_ImageWidth.Length > 0 && ho_ImageWidth.TupleInt() != hWindowControl.Size.Width)
@@ -387,13 +375,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 +393,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 +411,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 +423,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,37 +490,36 @@
                if (dicContext.TryGetValue(ProcessName, out IProcess obj)
                    && obj is IProcess process)
                {
                    //process.InputImage = null;
                    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;
                    }
                    if (process.Record != null)
                    {
                        process.Record.Dispose();
                        process.Record = null;
                    }
                    UpdateInputs(process);
@@ -589,9 +570,23 @@
        [Node("相机取图", "取像工具", "Basic", "相机取图")]
        public void 相机取图(FlowNode node) { RunNodeAsync(node); }
        [Node("读码工具", "取像工具", "Basic", "读码工具")]
        public void 读码工具(FlowNode node) { RunNodeAsync(node); }
        [Node("Halcon2D斑点工具", "Halcon2D工具", "Basic", "Halcon2D斑点工具")]
        public void Halcon2D斑点工具(FlowNode node) { RunNodeAsync(node); }
        [Node("通讯模块", "通讯工具", "Basic", "通讯模块")]
        public void 通讯模块(FlowNode node) { RunNodeAsync(node); }
        [Node("Halcon2D图像增强", "Halcon2D工具", "Basic", "Halcon2D图像增强")]
        public void Halcon2D图像增强(FlowNode node) { RunNodeAsync(node); }
        [Node("Halcon2D图像滤波", "Halcon2D工具", "Basic", "Halcon2D图像滤波")]
        public void Halcon2D图像滤波(FlowNode node) { RunNodeAsync(node); }
        #endregion