@@ -1339,6 +1339,39 @@ def rear_camera_from(sig, p=PARAMS):
13391339SIDE_CUT = re.compile(rf'(?:camera not facing forward|{SIDE_SHOT}|camera turned to the side \([^)]*\)) (\d+)-(\d+)s')
13401340
13411341
1342+ # a scene off the road edited into a drive (3MCWs0IRUiE 0:46-1:24: a photo shoot on the rocks by the sea, faded in and
1343+ # out between two frames of the same crossing; user, 2026-11-15): where YOLO sees a big person close by and no vehicle
1344+ # ahead (walk_view) for OFF_ROAD_READINGS readings in a row or more, in a drive (a vehicle ahead in OFF_ROAD_AHEAD of
1345+ # all its readings), and CLIP sees OFF_SCENES' first ones in OFF_ROAD_FRAMES frames (middle score OFF_ROAD_AT). Of 30
1346+ # such approved stretches (3 readings or more) sampled, one scored that high: 15 s of a street with a man beside the
1347+ # camera (3DAdCDRzM58), hence 4 readings; the photo shoot scored 1.0
1348+ OFF_SCENES = (['people posing for a photo outdoors', 'a person standing on rocks by the sea', 'people on a beach',
1349+ 'a person walking toward the camera on a path', 'a person taking a selfie outdoors', 'people in a park',
1350+ 'a woman looking at her phone outdoors',
1351+ 'a road ahead seen through a car windshield', 'a city street seen from a driving car',
1352+ 'traffic ahead on a road', 'a motorcyclist ahead on a road seen from a car',
1353+ 'a cyclist ahead on a bike lane', 'pedestrians crossing the street in front of a car',
1354+ 'the inside of a car with the driver', 'a road tunnel', 'a street at night seen from a car'], 7,
1355+ 'a photo of ')
1356+ OFF_ROAD_READINGS, OFF_ROAD_AHEAD, OFF_ROAD_FRAMES, OFF_ROAD_AT, OFF_ROAD_PAD_S = 4, 0.3, 5, 0.9, 5
1357+
1358+
1359+ def off_road_candidates(sig):
1360+ """[(start s, end s)] where a big person is close by and no vehicle ahead OFF_ROAD_READINGS readings in a row or
1361+ more, in a drive (see OFF_SCENES), padded by OFF_ROAD_PAD_S."""
1362+ wv = np.asarray(sig.get('walk_view', np.zeros((0, 2)))).reshape(-1, 2)
1363+ if len(wv) < 20 or wv[:, 1].mean() < OFF_ROAD_AHEAD:
1364+ return []
1365+ end = len(sig.get('motion', [])) / FPS or len(wv) * URBAN_EVERY_S
1366+ return [(max(0, a * URBAN_EVERY_S - OFF_ROAD_PAD_S), min(end, b * URBAN_EVERY_S + OFF_ROAD_PAD_S))
1367+ for a, b in _runs((wv[:, 0] == 1) & (wv[:, 1] == 0)) if b - a >= OFF_ROAD_READINGS]
1368+
1369+
1370+ def off_road_track(path, sig, work_dir):
1371+ """[(start s, end s)] of off_road_candidates CLIP sees as people off the road (see OFF_SCENES)."""
1372+ return _clip_stretches(path, off_road_candidates(sig), work_dir, OFF_SCENES, OFF_ROAD_FRAMES, OFF_ROAD_AT)
1373+
1374+
13421375def side_forward_track(path, sig, work_dir):
13431376 """[(start s, end s)] of the side views propose cuts that CLIP sees as the road ahead (see SIDE_FORWARD)."""
13441377 stretches = [(int(a), int(b)) for a, b in SIDE_CUT.findall('; '.join(propose(sig)[1]))]
@@ -1650,6 +1683,10 @@ def propose(sig, p=PARAMS):
16501683 notes.append(f'{label} {a / FPS:.0f}-{b / FPS:.0f}s')
16511684 for t, x in fast_walkers(sig): # see walk_cadence
16521685 notes.append(f'people walk at {x:.1f} steps a second at {int(t) // 60}:{int(t) % 60:02d}: sped up? check')
1686+ for a, b in np.asarray(sig.get('off_road', np.zeros((0, 2)))).reshape(-1, 2): # see OFF_SCENES
1687+ keep[int(a * FPS):int(b * FPS)] = False
1688+ notes.append(f'not the drive: people off the road (CLIP) {int(a) // 60}:{int(a) % 60:02d}-'
1689+ f'{int(b) // 60}:{int(b) % 60:02d}')
16531690 for a, b in np.asarray(sig.get('rear', np.zeros((0, 2)))).reshape(-1, 2): # see rear_camera
16541691 keep[int(a * FPS):int(b * FPS)] = False
16551692 notes.append(f'rear camera {int(a) // 60}:{int(a) % 60:02d}-{int(b) // 60}:{int(b) % 60:02d}')
@@ -4485,6 +4522,7 @@ def analyse_video(video_id, out_dir, meta=None, signs=False, keep=False):
44854522 sig['stamp'] = np.array(stamp, float)
44864523 sig['on_bus'] = np.array(title_vehicle(title_text(meta.get('title') or '')) == 1)
44874524 sig['side_forward'] = np.array(side_forward_track(path, sig, work_dir), float).reshape(-1, 2)
4525+ sig['off_road'] = np.array(off_road_track(path, sig, work_dir), float).reshape(-1, 2)
44884526 contact_sheet(path, meta['duration'] or len(sig['motion']) / FPS,
44894527 os.path.join(out_dir, f'{video_id}.jpg'))
44904528 finally:
0 commit comments