| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- // ImageProcessingAlgorithmFactory.cs 识别算法工厂,用于注册算法实现
- using MvvmScaffoldFrame48.DLL.ImageAlgorithm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MvvmScaffoldFrame48.DLL.ThreadManager
- {
- public static class ImageProcessingAlgorithmHikVisionFactory
- {
- #region 变量与实例
- // 存储所有算法实现类型的字典
- private static readonly Dictionary<string, Type> _algorithmTypes = new Dictionary<string, Type>();
- #endregion
- #region 构造方法
- /// <summary>
- /// 静态构造函数,在类加载时注册所有可用的算法实现
- /// </summary>
- static ImageProcessingAlgorithmHikVisionFactory()
- {
- // 注册所有可用的算法实现
- RegisterAlgorithm<ProcessingAlgorithm>("ProcessingAlgorithm");
- RegisterAlgorithm<ProcessingAlgorithm_CCDShuLi>("ProcessingAlgorithm_CCDShuLi");
- // 可以继续注册更多算法...
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 注册算法实现
- /// </summary>
- /// <typeparam name="T">算法实现类型</typeparam>
- /// <param name="algorithmName">算法名称</param>
- private static void RegisterAlgorithm<T>(string algorithmName) where T : IImageProcessingAlgorithmHikVision, new()
- {
- _algorithmTypes[algorithmName] = typeof(T);
- }
- #endregion
- #region 公有方法
- /// <summary>
- /// 根据算法名称创建算法实例
- /// </summary>
- /// <param name="algorithmName">算法名称</param>
- /// <returns>算法实例</returns>
- public static IImageProcessingAlgorithmHikVision CreateAlgorithm(string algorithmName)
- {
- if (_algorithmTypes.ContainsKey(algorithmName))
- {
- return (IImageProcessingAlgorithmHikVision)Activator.CreateInstance(_algorithmTypes[algorithmName]);
- }
- else
- {
- Console.WriteLine($"未找到名为 '{algorithmName}' 的算法实现");
- return null;
- }
- }
- /// <summary>
- /// 获取所有已注册的算法名称
- /// </summary>
- /// <returns>算法名称列表</returns>
- public static List<string> GetAvailableAlgorithms()
- {
- return _algorithmTypes.Keys.ToList();
- }
- /// <summary>
- /// 检查算法是否存在
- /// </summary>
- /// <param name="algorithmName">算法名称</param>
- /// <returns>是否存在</returns>
- public static bool AlgorithmExists(string algorithmName)
- {
- return _algorithmTypes.ContainsKey(algorithmName);
- }
- #endregion
- }
- }
|