| | |
| | | using LB_VisionProcesses.Processes.ScriptTool; |
| | | using OpenCvSharp; |
| | | using System.Collections.Concurrent; |
| | | using System.Windows.Media.Media3D; |
| | | |
| | | namespace LB_SmartVision.ProcessRun |
| | | { |
| | |
| | | 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 |
| | |
| | | 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) |
| | |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | 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); |
| | | |
| | |
| | | [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 |
| | | |
| | | |