| | |
| | | using LB_VisionProcesses.Alogrithms; |
| | | using LB_VisionProcesses.Cameras; |
| | | using LB_VisionProcesses.Communicators; |
| | | using LB_VisionProcesses.Processes; |
| | | 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 HObject 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 is HImage ho_image && ho_image.IsInitialized()) |
| | | 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.Bitmap2HObject((Bitmap)o_InputImage)) |
| | | { |
| | | InputImage = ho_RecordImage.Clone(); |
| | | } |
| | | TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage, out HObject ho_RecordImage); |
| | | InputImage = ho_RecordImage; |
| | | } |
| | | else if (o_InputImage is Mat) |
| | | { |
| | | //将Mat转换为HObject |
| | | using (HImage ho_RecordImage = TAlgorithm.Mat2HObject((Mat)o_InputImage)) |
| | | { |
| | | InputImage = ho_RecordImage.Clone(); |
| | | } |
| | | TAlgorithm.Mat2HObject((Mat)o_InputImage, out HObject ho_RecordImage); |
| | | InputImage = ho_RecordImage; |
| | | } |
| | | |
| | | if (InputImage != null && InputImage.IsInitialized()) |
| | |
| | | if (dicContext.TryGetValue(ProcessName, out IProcess obj) |
| | | && obj is IProcess process) |
| | | { |
| | | process.InputImage = null; |
| | | //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); } |
| | | |
| | | [Node("轮胎计数", "控制", "Logic", "轮胎计数节点")] |
| | | public void 轮胎计数(FlowNode node) |
| | | { |
| | | string ProcessName = node.Text; |
| | | try |
| | | { |
| | | if (dicContext.TryGetValue(ProcessName, out IProcess obj) |
| | | && obj is TyreCounterProcess counter) |
| | | { |
| | | UpdateInputs(counter); |
| | | |
| | | if (node.Break) |
| | | { |
| | | node.BranchIndex = "0"; |
| | | node.Result = true; |
| | | counter.Result = true; |
| | | counter.Msg = "轮胎计数节点已跳过"; |
| | | return; |
| | | } |
| | | |
| | | // 从前置节点获取检测结果(通过输入映射) |
| | | bool imageResult = GetPreviousResult(node); |
| | | |
| | | // 设置输入结果 |
| | | counter.InputImage = imageResult; |
| | | |
| | | // 运行轮胎计数 |
| | | if (!counter.Run()) |
| | | { |
| | | node.Result = false; |
| | | Result &= false; |
| | | Msg += $"[{ProcessName}]{counter.Msg}"; |
| | | } |
| | | else |
| | | { |
| | | node.Result = true; |
| | | |
| | | // 如果完成一个轮胎,输出完成信号 |
| | | if (counter.IsTyreComplete) |
| | | { |
| | | Msg += $"[{ProcessName}]完成轮胎 #{counter.CurrentTyreID - 1},结果: {(counter.TyreResult ? "OK" : "NG")}"; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | node.Result = false; |
| | | Result &= false; |
| | | Msg += $"[{ProcessName}]未找到轮胎计数工具实例"; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | node.Result = false; |
| | | Result &= false; |
| | | Msg += $"[{ProcessName}]运行发生意外,{ex.Message}"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取前置节点的检测结果 |
| | | /// </summary> |
| | | private bool GetPreviousResult(FlowNode node) |
| | | { |
| | | try |
| | | { |
| | | // 查找前置节点 |
| | | var prevNode = dicContext.Values |
| | | .OfType<IProcess>() |
| | | .FirstOrDefault(p => p.Result == true || p.Result == false); |
| | | |
| | | if (prevNode != null) |
| | | { |
| | | return prevNode.Result; |
| | | } |
| | | } |
| | | catch { } |
| | | |
| | | return true; // 默认返回OK |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |