Skip to content

Commit d022e29

Browse files
committed
Additional ghost train found
1 parent 175210b commit d022e29

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

lib/train_detector.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ def _detect_symbols(self, hsv, h, w, gray):
862862
candidate_mask = cv2.bitwise_and(candidate_mask, cv2.bitwise_not(cyan_mask))
863863
candidate_mask = cv2.bitwise_and(candidate_mask, cv2.bitwise_not(red_mask))
864864

865-
# Morphology
865+
# Morphology — keep pre-close mask to verify symbol solidity
866+
pre_close_mask = candidate_mask.copy()
866867
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
867868
candidate_mask = cv2.morphologyEx(candidate_mask, cv2.MORPH_CLOSE, kernel)
868869

@@ -887,6 +888,14 @@ def _detect_symbols(self, hsv, h, w, gray):
887888
if aspect < 1.5 or aspect > 3.5:
888889
continue
889890

891+
# Reject noise connected by morphological closing: real train symbols
892+
# are solidly colored (fill ≥ 0.7 before closing), while noise from
893+
# scattered pixels has much lower fill (~0.3-0.4).
894+
pre_pixels = cv2.countNonZero(pre_close_mask[y:y+ch, x:x+cw])
895+
fill_ratio = pre_pixels / max(cw * ch, 1)
896+
if fill_ratio < 0.7:
897+
continue
898+
890899
cx, cy = x + cw // 2, y + ch // 2
891900
track = 'upper' if cy < upper_track_y else 'lower'
892901

scripts/review-archive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,7 @@ def main():
504504
print(f'No images directory found at {image_dir}')
505505
sys.exit(1)
506506

507-
filter_reason = effective_reason if args.skip_download else None
508-
entries = collect_images(image_dir, reason_filter=filter_reason)
507+
entries = collect_images(image_dir, reason_filter=effective_reason)
509508
if not entries:
510509
print('No archive images found.')
511510
sys.exit(0)

tests/baseline_delay_summaries.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@
121121
"Eastbound service not running between Montgomery and Embarcadero",
122122
"Eastbound backup at Civic Center (4 trains)"
123123
]
124+
},
125+
"muni_snapshot_20260224_082751.jpg": {
126+
"status": "red",
127+
"delay_summaries": []
124128
}
125129
}
126130
}

tests/baseline_trains.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
"train_free_images": {
218218
"muni_snapshot_20260124_015604.jpg": {"max_false_positives": 10},
219219
"muni_snapshot_20260124_041839.jpg": {"max_false_positives": 20},
220-
"muni_snapshot_20260219_closed.jpg": {"max_false_positives": 1}
220+
"muni_snapshot_20260219_closed.jpg": {"max_false_positives": 1},
221+
"muni_snapshot_20260224_082751.jpg": {"max_false_positives": 0}
221222
}
222223
}
89.4 KB
Loading

tests/test_system_status.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
("muni_snapshot_20251212_002351.jpg", "red", "Maintenance display - only non-revenue trains detected"),
5151
("muni_snapshot_20260124_020104.jpg", "red", "Not operating - overnight"),
5252
("muni_snapshot_20260218_013611.jpg", "red", "Overnight - non-revenue train 2206X, red track segments"),
53+
("muni_snapshot_20260224_082751.jpg", "red", "Overnight 12:27am - no revenue trains, false positive at YBR area"),
5354
]
5455

5556

0 commit comments

Comments
 (0)