| | |
| | | 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; |
| | |
| | | [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 |
| | | |