-
-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathrun.py
More file actions
86 lines (70 loc) · 2.29 KB
/
Copy pathrun.py
File metadata and controls
86 lines (70 loc) · 2.29 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
from __future__ import annotations
from ultralytics import YOLO
import torch
import supervision as sv
from trackers import ByteTrackTracker
from logic.config_watcher import cfg
from logic.checks import run_checks
from logic.logger import logger
@torch.inference_mode()
def perform_detection(model, image, tracker: ByteTrackTracker | None = None):
ai_device = str(cfg.AI_device).lower()
kwargs = dict(
source=image,
imgsz=cfg.ai_model_image_size,
conf=cfg.AI_conf,
iou=0.50,
device=cfg.AI_device,
half="cpu" not in ai_device,
max_det=20,
agnostic_nms=False,
augment=False,
vid_stride=1,
visualize=False,
verbose=False,
show_boxes=False,
show_labels=False,
show_conf=False,
save=False,
show=False,
stream=True
)
kwargs["cfg"] = "logic/tracker.yaml" if tracker else "logic/game.yaml"
results = model.predict(**kwargs)
if tracker:
for res in results:
det = sv.Detections.from_ultralytics(res)
return tracker.update(det)
else:
return next(results, None)
def init():
run_checks()
from logic.capture import capture
from logic.visual import visuals
from logic.frame_parser import frameParser
from logic.hotkeys_watcher import hotkeys_watcher
from logic.shooting import shooting
tracker = ByteTrackTracker() if not cfg.disable_tracker else None
try:
model = YOLO(f"models/{cfg.AI_model_name}", task="detect")
except Exception as e:
logger.error(f"An error occurred when loading the AI model:\n{e}")
raise SystemExit(0)
while True:
image = capture.get_new_frame()
if image is None:
continue
if cfg.circle_capture:
image = capture.convert_to_circle(image)
if hotkeys_watcher.app_pause != 0:
visuals.clear()
shooting.shoot(False, False)
if cfg.show_window or cfg.show_overlay:
visuals.submit_frame(image)
continue
result = perform_detection(model, image, tracker)
frameParser.parse(result)
if cfg.show_window or cfg.show_overlay:
visuals.submit_frame(image)
if __name__ == "__main__":
init()