-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkyNet.cs
74 lines (57 loc) · 2.16 KB
/
SkyNet.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using SkyNet.Vision.Objects;
using Compunet.YoloV8;
using Compunet.YoloV8.Data;
using SixLabors.ImageSharp;
using SkyNet.Vision;
namespace SkyNet;
public static class SkyNet
{
public static XdgSessionType SessionType;
public static List<VisionObject> VisionObjects = [];
private static YoloPredictor _yoloPredictor;
public static void Init()
{
SessionType = GetSessionType();
LoadYoloPredictor(Config.PathToOnnxModel);
Start();
}
private static void LoadYoloPredictor(string modelPath)
{
var x = new YoloPredictorOptions
{
UseCuda = false,
// SessionOptions = SessionOptions.MakeSessionOptionWithRocmProvider() // AMD GPU
};
_yoloPredictor = new YoloPredictor(modelPath, x);
Console.WriteLine("YoloPredictor ready!");
}
private static void Start()
{
if(SessionType == XdgSessionType.Wayland)
WaylandScreenshot.Init();
}
public static void DetectAndDraw(Image image)
{
// _yoloPredictor.DetectAndSaveAsync("/home/daniliammo/RiderProjects/SkyNet/SkyNet/test2.jpg", "/home/daniliammo/RiderProjects/SkyNet/SkyNet/out.png");
DrawAllObjects(_yoloPredictor!.Detect(image));
}
private static void DrawAllObjects(YoloResult<Detection> visionObjects)
{
// Clear the list
// VisionObjects = [];
foreach (var visionObject in visionObjects)
VisionObjects.Add(new VisionObject(ObjectType.Ally, visionObject.Bounds, visionObject.Confidence));
Console.WriteLine($"Объектов: {VisionObjects.Count}");
WindowController.DrawAllObjects();
}
private static XdgSessionType GetSessionType()
{
var sessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE");
return sessionType switch
{
"wayland" or "x11" => XdgSessionType.Wayland,
_ => throw new ArgumentOutOfRangeException(
$"Неизвестный тип XDGSessionType. Environment.GetEnvironmentVariable(\"XDG_SESSION_TYPE\") вернул значение: {sessionType}")
};
}
}