bus_analyzer: use last frame of segment, not first

master
Mike Lang 1 week ago
parent 941050aea9
commit 5db7bcda71

@ -344,10 +344,10 @@ def recognize_time_of_day(frame):
return best, distance return best, distance
def extract_segment(prototypes, segment): def extract_segment(prototypes, segment, time):
ODO_SCORE_THRESHOLD = 0.01 ODO_SCORE_THRESHOLD = 0.01
CLOCK_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)) frame = Image.open(BytesIO(frame_data))
odometer, score, _ = recognize_odometer(prototypes, frame) odometer, score, _ = recognize_odometer(prototypes, frame)
if score < ODO_SCORE_THRESHOLD: if score < ODO_SCORE_THRESHOLD:

@ -26,7 +26,7 @@ def do_extract_segment(*segment_paths, prototypes_path="./prototypes"):
prototypes = load_prototypes(prototypes_path) prototypes = load_prototypes(prototypes_path)
for segment_path in segment_paths: for segment_path in segment_paths:
segment_info = parse_segment_path(segment_path) 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}") 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: for old_odometer, (segment, old_clock, old_tod) in selected:
path = os.path.join(base_dir, segment) path = os.path.join(base_dir, segment)
segment_info = parse_segment_path(path) 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, { results.append((segment, {
"odo": (old_odometer, odometer), "odo": (old_odometer, odometer),
"clock": (old_clock, clock), "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: if check_segment_name is not None:
assert segment_name == check_segment_name assert segment_name == check_segment_name
timestamp = segment_info.end
try: try:
odometer, clock, tod = extract_segment(prototypes, segment_info) odometer, clock, tod = extract_segment(prototypes, segment_info, timestamp)
except Exception: except Exception:
logging.warning(f"Failed to extract segment {segment_path!r}", exc_info=True) logging.warning(f"Failed to extract segment {segment_path!r}", exc_info=True)
odometer = None odometer = None
@ -143,7 +145,7 @@ def analyze_segment(db_manager, prototypes, segment_path, check_segment_name=Non
timeofday = %(timeofday)s timeofday = %(timeofday)s
""", """,
channel=segment_info.channel, channel=segment_info.channel,
timestamp=segment_info.start, timestamp=timestamp,
segment=segment_name, segment=segment_name,
error=error, error=error,
odometer=odometer, odometer=odometer,

Loading…
Cancel
Save