The following python code which generates a soccer field homography of a soccer video…
- User
The following python code which generates a soccer field homography of a soccer video using a trained yolo model. Please analyse the code to see how the homography can be made smoother with less jitter, given the fact the camera panning is smooth.
import cv2 import numpy as np import time from ultralytics import YOLO
--- Complete mapping with reference coordinates ---
CLASS_TO_KPT = { "cul": 0, "pbl1": 1, "gl1": 2, "gl2": 3, "pbl2": 4, "cll": 5, "gl4": 6, "gl3": 7, "pl": 8, "pbl6": 9, "pbl5": 10, "pbl4": 11, "pbl3": 12, "hlu": 13, "cu": 14, "cd": 15, "hll": 16, "pbr6": 17, "pbr5": 18, "pbr4": 19, "pbr3": 20, "pr": 21, "gr4": 22, "gr3": 23, "cur": 24, "pbr1": 25, "gr1": 26, "gr2": 27, "pbr2": 28, "clr": 29, "cl": 30, "cr": 31, }
Punten die extra zwaar mee moeten tellen
IMPORTANT_KPTS = { 13: 4, # hlu 14: 8, # cu 15: 8, # cd 30: 8, # cl 31: 8, # cr 16: 4, # hll 17: 3, # pbr6 18: 3, # pbr5 23: 3, # gr3 }
MIN_CONFIDENCE = 0.5
-------------------------------------------
FIFA standard pitch model (105 x 68 m)
-------------------------------------------
PITCH_POINTS = { "cul": (0, 68), "cll": (0, 0), "cur": (105, 68), "clr": (105, 0), "cl": (43.35, 34), # <--- CORRECTED "cr": (61.65, 34), # <--- CORRECTED "cu": (52.5, 34 + 9.15), "cd": (52.5, 34 - 9.15), "pl": (11, 34), "pr": (94, 34), "pbl6": (16.5, 54.15), "pbl5": (16.5, 13.85), "pbl1": (0, 13.85), "pbl2": (0, 54.15), "pbr6": (88.5, 54.15), "pbr5": (88.5, 13.85), "pbr1": (105, 13.85), "pbr2": (105, 54.15), "gl1": (0, 24.84), "gl2": (0, 43.16), "gl3": (5.5, 24.84), "gl4": (5.5, 43.16), "gr1": (105, 24.84), "gr2": (105, 43.16), "gr3": (99.5, 24.84), "gr4": (99.5, 43.16), }
PITCH_LINES = [ [(0,0), (105,0), (105,68), (0,68), (0,0)], [(52.5,0), (52.5,68)], [(52.5 + 9.15np.cos(a), 34 + 9.15np.sin(a)) for a in np.linspace(0, 2*np.pi, 40)], [(0, 13.85), (16.5, 13.85), (16.5, 54.15), (0, 54.15)], [(105, 13.85), (88.5, 13.85), (88.5, 54.15), (105, 54.15)], [(0, 24.84), (5.5, 24.84), (5.5, 43.16), (0, 43.16)], [(105, 24.84), (99.5, 24.84), (99.5, 43.16), (105, 43.16)], ]
class HomographySmoother: """ Applies an Exponential Moving Average to stabilize the homography matrix over time. """ def init(self, alpha=0.5): """ Initializes the smoother. :param alpha: The smoothing factor, a value between 0 and 1. A smaller alpha results in more smoothing (and more latency). A larger alpha results in less smoothing (and more responsiveness). """ self.alpha = alpha self.smoothed_H = None
code Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.