using OpenCvSharp;
using System.IO;
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
{
///
/// 获取From文件Handler
///
public class GetFromFileHandler : IVisionFlowHandler
{
///
/// 类型
///
public VisionFlowType Type => VisionFlowType.从文件获取图片;
///
/// 执行
///
/// 视觉功能
/// 变量项
/// 返回布尔值
public bool Execute(VisionFunction func, VisionFlow item)
{
if (item.StringParams.TryGetValue("Path", out string filePath))
{
if (File.Exists(filePath))
{
func.Src = Cv2.ImRead(filePath);
return true;
}
else
{
throw new Exception($"文件路径不存在: {filePath}");
}
}
return false;
}
}
}