with a glass of water
This commit is contained in:
1 parent
a220035126
commit
31b9e85912
6 files changed
+115
-9
No files matched your search
@@ -82,15 +82,13 @@ def process_logic(input_: Path,
|
||||
np.arange(0.5, 1, 0.05)
|
||||
]
|
||||
|
||||
transformation_matrix = get_court_perspective_transform()
|
||||
|
||||
with get_video_writer(display_video, input_, output_dir / 'video.mov') as video_writer:
|
||||
with create_data_dumper(input_, output_dir / 'data.sqlite', metadata) as data_dumper:
|
||||
tracker = DodgeballTracker(input_,
|
||||
video_writer,
|
||||
data_dumper,
|
||||
detected_box_objects,
|
||||
transformation_matrix)
|
||||
metadata.get_view_perspective_matrix())
|
||||
|
||||
with time_tracker():
|
||||
tracker.main()
|
||||
|
||||
@@ -61,12 +61,14 @@ class SQLiteDataDumper(DataDumper):
|
||||
ymin DOUBLE PRECISION NOT NULL,
|
||||
xmax DOUBLE PRECISION NOT NULL,
|
||||
ymax DOUBLE PRECISION NOT NULL,
|
||||
|
||||
bird_view_x DOUBLE PRECISION,
|
||||
bird_view_y DOUBLE PRECISION,
|
||||
|
||||
score DOUBLE PRECISION NOT NULL,
|
||||
category INTEGER NOT NULL,
|
||||
object_id INTEGER NOT NULL,
|
||||
video_frame_id INTEGER NOT NULL,
|
||||
|
||||
|
||||
FOREIGN KEY(video_frame_id) REFERENCES video_frame(id)
|
||||
);
|
||||
''')
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import logging
|
||||
import torch
|
||||
@@ -70,7 +69,6 @@ class DodgeballTracker:
|
||||
self._data_dumper = data_dumper
|
||||
self.detected_box_objects = sorted(detected_box_objects, reverse=True)
|
||||
self.transformation_matrix = transformation_matrix
|
||||
self.points = []
|
||||
|
||||
|
||||
@pa.check_output(DetectedObject)
|
||||
@@ -94,7 +92,7 @@ class DodgeballTracker:
|
||||
load the pre-trained YOLOv8n model
|
||||
"""
|
||||
my_model = Path(
|
||||
'/home/didier/all-dressed-programming/dodgeball-tracker/dodgeballtracker/runs/detect/train31/weights/best.pt')
|
||||
'/home/didier/all-dressed-programming/dodgeball-tracker/runs/detect/train31/weights/best.pt')
|
||||
return YOLO(my_model, verbose=False)
|
||||
|
||||
@pa.check_io(detected_objs=DetectedObject, out=TrackedDetectedObject)
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
class KnownImagePoint(BaseModel):
|
||||
height: float
|
||||
width: float
|
||||
height: float
|
||||
|
||||
@classmethod
|
||||
def from_vec(cls, vec: tuple[float, float]) -> 'KnownImagePoint':
|
||||
return cls(width=vec[0], height=vec[1])
|
||||
|
||||
|
||||
class BirdViewPoint(BaseModel):
|
||||
x: float
|
||||
y: float
|
||||
|
||||
@classmethod
|
||||
def from_vec(cls, vec: tuple[float, float]) -> 'BirdViewPoint':
|
||||
return cls(x=vec[0], y=vec[1])
|
||||
|
||||
|
||||
class KnownPoint(BaseModel):
|
||||
image: KnownImagePoint
|
||||
@@ -18,3 +31,14 @@ class KnownPoint(BaseModel):
|
||||
class VideoMetadata(BaseModel):
|
||||
knownPoints: list[KnownPoint]
|
||||
|
||||
def get_view_perspective_matrix(self) -> Optional[np.array]:
|
||||
if len(self.knownPoints) < 4:
|
||||
return None
|
||||
|
||||
empirical_source = np.float32(
|
||||
[[k.image.width, k.image.height] for k in self.knownPoints])
|
||||
empirical_target = np.float32(
|
||||
[[k.bird_view.x, k.bird_view.y] for k in self.knownPoints])
|
||||
pixel_per_meter = 100
|
||||
return cv2.getPerspectiveTransform(empirical_source,
|
||||
empirical_target * pixel_per_meter)
|
||||
Reference in new issue
Block a user