44 lines
2.1 KiB
C#
44 lines
2.1 KiB
C#
namespace Heimdall.Application.DTOs;
|
|
|
|
/// <summary>Version 1 supports COCO object detection and a normalized pixel motion gate.</summary>
|
|
public sealed record DetectionProfileDto
|
|
{
|
|
public int Version { get; init; } = 1;
|
|
public int IdleIntervalMs { get; init; } = 1000;
|
|
public int MotionIntervalMs { get; init; } = 500;
|
|
public int ActiveIntervalMs { get; init; } = 200;
|
|
public float MinConfidence { get; init; } = .4f;
|
|
public bool DetectPerson { get; init; } = true;
|
|
public bool DetectVehicle { get; init; } = true;
|
|
public bool DetectAnimal { get; init; }
|
|
public bool DetectPackage { get; init; }
|
|
public bool DetectMotion { get; init; } = true;
|
|
public bool RequireMotionForAI { get; init; } = true;
|
|
public double MotionThreshold { get; init; } = .3;
|
|
public double MotionPixelThreshold { get; init; } = .08;
|
|
public double ZoneX { get; init; }
|
|
public double ZoneY { get; init; }
|
|
public double ZoneWidth { get; init; } = 1;
|
|
public double ZoneHeight { get; init; } = 1;
|
|
public string YoloModel { get; init; } = "yolov8n";
|
|
|
|
public void Validate()
|
|
{
|
|
if (IdleIntervalMs is < 50 or > 60000 || MotionIntervalMs is < 50 or > 60000 || ActiveIntervalMs is < 50 or > 60000 || Version != 1 || !float.IsFinite(MinConfidence) || MinConfidence is < 0 or > 1 ||
|
|
!double.IsFinite(MotionThreshold) || MotionThreshold is < 0 or > 1 ||
|
|
!double.IsFinite(MotionPixelThreshold) || MotionPixelThreshold is <= 0 or > 1 ||
|
|
!double.IsFinite(ZoneX + ZoneY + ZoneWidth + ZoneHeight) || ZoneX < 0 || ZoneY < 0 ||
|
|
ZoneWidth <= 0 || ZoneHeight <= 0 || ZoneX + ZoneWidth > 1 || ZoneY + ZoneHeight > 1 ||
|
|
YoloModel != "yolov8n" || DetectPackage)
|
|
throw new ArgumentException("Unsupported or invalid detection profile; only COCO yolov8n is available (package detection requires another model)");
|
|
}
|
|
|
|
public bool AllowsClass(int? index) => index switch
|
|
{
|
|
0 => DetectPerson,
|
|
1 or 2 or 3 or 5 or 7 => DetectVehicle,
|
|
>= 14 and <= 23 => DetectAnimal,
|
|
_ => false
|
|
};
|
|
}
|