File size: 2,699 Bytes
5d257ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test FFmpegFrameReader to match exactly how the pipeline reads frames.
"""

import json
import logging
import sys
from pathlib import Path

# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))

from video.ffmpeg_reader import FFmpegFrameReader
from readers import ReadPlayClock
from setup import DigitTemplateLibrary

logging.basicConfig(level=logging.INFO, format="%(message)s")

# Video path
VIDEO_PATH = "/Users/andytaylor/Documents/Personal/cfb40/full_videos/OSU vs Oregon 01.01.25.mkv"


def load_session_config(config_path: str) -> dict:
    """Load session config."""
    with open(config_path, "r", encoding="utf-8") as f:
        return json.load(f)


def main():
    # Load config
    config = load_session_config("output/OSU_vs_Oregon_01_01_25_config.json")

    # Set up playclock coordinates
    playclock_coords = (
        config["scorebug_x"] + config["playclock_x_offset"],
        config["scorebug_y"] + config["playclock_y_offset"],
        config["playclock_width"],
        config["playclock_height"],
    )
    print(f"Playclock coords: {playclock_coords}")

    # Load templates
    library = DigitTemplateLibrary()
    if not library.load("output/debug/digit_templates"):
        print("ERROR: Could not load templates")
        return

    reader = ReadPlayClock(library, config["playclock_width"], config["playclock_height"])

    # Test timestamps
    timestamps = [
        (4104, 4115, "Known working - plays detected here"),
        (4125, 4145, "Gap around 4136s - missed play"),
        (6640, 6660, "Known working - plays detected here"),
        (6675, 6695, "Gap around 6684s - missed play"),
    ]

    for start, end, desc in timestamps:
        print(f"\n{'=' * 70}")
        print(f"{desc}")
        print(f"Testing {start}s to {end}s using FFmpegFrameReader (matches pipeline)")
        print("=" * 70)

        with FFmpegFrameReader(VIDEO_PATH, start, end, frame_interval=0.5) as reader_ctx:
            count = 0
            detected = 0
            for timestamp, frame in reader_ctx:
                result = reader.read_from_fixed_location(frame, playclock_coords, padding=10)
                status = f"value={result.value}, conf={result.confidence:.2f}" if result.detected else f"NOT DETECTED (conf={result.confidence:.2f})"
                if result.detected:
                    detected += 1
                count += 1
                if count <= 10 or result.detected:  # Show first 10 or any detected
                    print(f"  t={timestamp:.1f}s: {status}")

            print(f"\n  Detection rate: {detected}/{count} ({100*detected/count:.1f}%)")


if __name__ == "__main__":
    main()