From 5db7bcda71242d7f0695e7d3771eecbbf7649fbc Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Fri, 15 Nov 2024 15:49:15 +1100 Subject: [PATCH] bus_analyzer: use last frame of segment, not first --- bus_analyzer/bus_analyzer/extract.py | 4 ++-- bus_analyzer/bus_analyzer/main.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bus_analyzer/bus_analyzer/extract.py b/bus_analyzer/bus_analyzer/extract.py index ce68637..73e2fcc 100644 --- a/bus_analyzer/bus_analyzer/extract.py +++ b/bus_analyzer/bus_analyzer/extract.py @@ -344,10 +344,10 @@ def recognize_time_of_day(frame): return best, distance -def extract_segment(prototypes, segment): +def extract_segment(prototypes, segment, time): ODO_SCORE_THRESHOLD = 0.01 CLOCK_SCORE_THRESHOLD = 0.01 - frame_data = b"".join(extract_frame([segment], segment.start)) + frame_data = b"".join(extract_frame([segment], time)) frame = Image.open(BytesIO(frame_data)) odometer, score, _ = recognize_odometer(prototypes, frame) if score < ODO_SCORE_THRESHOLD: diff --git a/bus_analyzer/bus_analyzer/main.py b/bus_analyzer/bus_analyzer/main.py index a53ef86..f57e1aa 100644 --- a/bus_analyzer/bus_analyzer/main.py +++ b/bus_analyzer/bus_analyzer/main.py @@ -26,7 +26,7 @@ def do_extract_segment(*segment_paths, prototypes_path="./prototypes"): prototypes = load_prototypes(prototypes_path) for segment_path in segment_paths: segment_info = parse_segment_path(segment_path) - odometer, clock, tod = extract_segment(prototypes, segment_info) + odometer, clock, tod = extract_segment(prototypes, segment_info, segment_info.end) print(f"{segment_path} {odometer} {clock} {tod}") @@ -76,7 +76,7 @@ def compare_segments(dbconnect, base_dir='.', prototypes_path="./prototypes", si for old_odometer, (segment, old_clock, old_tod) in selected: path = os.path.join(base_dir, segment) segment_info = parse_segment_path(path) - odometer, clock, tod = extract_segment(prototypes, segment_info) + odometer, clock, tod = extract_segment(prototypes, segment_info, segment_info.end) results.append((segment, { "odo": (old_odometer, odometer), "clock": (old_clock, clock), @@ -118,8 +118,10 @@ def analyze_segment(db_manager, prototypes, segment_path, check_segment_name=Non if check_segment_name is not None: assert segment_name == check_segment_name + timestamp = segment_info.end + try: - odometer, clock, tod = extract_segment(prototypes, segment_info) + odometer, clock, tod = extract_segment(prototypes, segment_info, timestamp) except Exception: logging.warning(f"Failed to extract segment {segment_path!r}", exc_info=True) odometer = None @@ -143,7 +145,7 @@ def analyze_segment(db_manager, prototypes, segment_path, check_segment_name=Non timeofday = %(timeofday)s """, channel=segment_info.channel, - timestamp=segment_info.start, + timestamp=timestamp, segment=segment_name, error=error, odometer=odometer,