InferenceNetworkInputImage.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. namespace YOLODetectProcessLib
  3. {
  4. public class InferenceNetworkInputImage : IDisposable
  5. {
  6. #region properties
  7. /// <summary>
  8. /// 图像
  9. /// </summary>
  10. public IImage Image { get; protected set; }
  11. /// <summary>
  12. /// 感兴趣的区域
  13. /// </summary>
  14. public Rect ROI { get; protected set; }
  15. /// <summary>
  16. /// 划定该ROI的置信度
  17. /// </summary>
  18. public float Confidence { get; protected set; }
  19. /// <summary>
  20. /// 判断图像是否需要裁图
  21. /// </summary>
  22. public bool IsCrop { get; protected set; }
  23. /// <summary>
  24. /// 额外的边界框
  25. /// 有些模型在检测病灶时,可能需要除了感兴趣轮廓以外的图像作为补充信息
  26. /// 如,肝脏弥漫性病灶分类模型,需要肝脏以外的其他器官作为对比,以便判断脂肪肝等疾病
  27. /// 因此这里添加一个额外的边界框,供模型选择使用
  28. /// </summary>
  29. public Rect ExtraBoundingBox { get; protected set; }
  30. #endregion
  31. #region constructor
  32. public InferenceNetworkInputImage(IImage image, Rect roi, float confidence = 1.0f)
  33. {
  34. Image = image;
  35. ROI = roi;
  36. Confidence = confidence;
  37. ExtraBoundingBox = Rect.Empty;
  38. }
  39. public InferenceNetworkInputImage(IImage image, bool iscrop = true, float confidence = 1.0f)
  40. {
  41. Image = image;
  42. Confidence = confidence;
  43. IsCrop = iscrop;
  44. ExtraBoundingBox = Rect.Empty;
  45. }
  46. #endregion
  47. #region dispose
  48. /// <summary>
  49. /// 析构函数
  50. /// </summary>
  51. ~InferenceNetworkInputImage()
  52. {
  53. DoDispose();
  54. LogHelper.InfoLog("InferenceNetworkInputImage.Disposed by destructor.");
  55. }
  56. /// <summary>
  57. /// 主动销毁
  58. /// </summary>
  59. public void Dispose()
  60. {
  61. DoDispose();
  62. GC.SuppressFinalize(this);
  63. LogHelper.InfoLog("InferenceNetworkInputImage.Disposed manually.");
  64. }
  65. /// <summary>
  66. /// 销毁
  67. /// </summary>
  68. public void DoDispose()
  69. {
  70. Image?.Dispose();
  71. Image = null;
  72. }
  73. #endregion
  74. }
  75. }