63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.Linq;
 | ||
| using System.Text;
 | ||
| using System.Threading.Tasks;
 | ||
| 
 | ||
| namespace Check.Main.Infer
 | ||
| {
 | ||
|     public interface IDetector : IDisposable
 | ||
|     {
 | ||
|         /// <summary>
 | ||
|         /// 初始化检测器。
 | ||
|         /// </summary>
 | ||
|         /// <param name="modelPath">模型文件路径(对于传统算法可能是模板目录)</param>
 | ||
|         /// <param name="detectionSettings">特定于检测器的设置对象(可选,可以用于传递阈值等)</param>
 | ||
|         void Initialize(string modelPath, object detectionSettings = null);
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 执行图像检测。
 | ||
|         /// </summary>
 | ||
|         /// <param name="image">待检测的图像。</param>
 | ||
|         /// <returns>包含检测结果(如OK/NG,得分,边界框等)的统一对象。</returns>
 | ||
|         DetectionResult Detect(Bitmap image);
 | ||
|     }
 | ||
| 
 | ||
|     /// <summary>
 | ||
|     /// 统一的检测结果类。
 | ||
|     /// </summary>
 | ||
|     public class DetectionResult
 | ||
|     {
 | ||
|         public bool IsOk { get; set; }
 | ||
|         public string Message { get; set; }
 | ||
|         public double Score { get; set; }
 | ||
|         public List<RectangleF> BoundingBoxes { get; set; } // 深度学习可能返回多个目标框
 | ||
| 
 | ||
|         // 如果需要,可以添加带有绘制结果的图像
 | ||
|         public Bitmap ResultImage { get; set; }
 | ||
| 
 | ||
|         public DetectionResult(bool isOk, string message = "Unknown", double score = 0.0, List<RectangleF> boundingBoxes = null, Bitmap resultImage = null)
 | ||
|         {
 | ||
|             IsOk = isOk;
 | ||
|             Message = message;
 | ||
|             Score = score;
 | ||
|             BoundingBoxes = boundingBoxes ?? new List<RectangleF>();
 | ||
|             ResultImage = resultImage;
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     //// 辅助设置类,用于传递给 HalconTemplateDetector
 | ||
|     //public class HalconDetectionSettings
 | ||
|     //{
 | ||
|     //    public double ScoreThreshold { get; set; } = 0.5;
 | ||
|     //}
 | ||
| 
 | ||
|     // 辅助设置类,用于传递给 YoloDetector
 | ||
|     public class YoloDetectionSettings
 | ||
|     {
 | ||
|         public float ConfidenceThreshold { get; set; } = 0.25f;
 | ||
|         public float NmsThreshold { get; set; } = 0.45f;
 | ||
|     }
 | ||
| 
 | ||
| }
 |