Candle commited on
Commit ·
3830a3f
1
Parent(s): 07ee382
code
Browse files- detect_scene.py +7 -11
detect_scene.py
CHANGED
|
@@ -56,7 +56,7 @@ def load_original_frames(filepath):
|
|
| 56 |
pass
|
| 57 |
return frames
|
| 58 |
|
| 59 |
-
def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_radius=2, title=None):
|
| 60 |
"""
|
| 61 |
Save a timeline JPG with thumbnails every `interval` frames and every frame near scene changes.
|
| 62 |
Scene change regions are highlighted. Each thumbnail is annotated with its frame index.
|
|
@@ -97,14 +97,6 @@ def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_ra
|
|
| 97 |
first_frames = set(idx + 1 for idx in scene_change_indices if idx + 1 < len(frames))
|
| 98 |
|
| 99 |
# Draw thumbnails and annotate
|
| 100 |
-
# Optionally, get single_frame_pred if passed as a kwarg
|
| 101 |
-
single_frame_pred = None
|
| 102 |
-
import inspect
|
| 103 |
-
if 'single_frame_pred' in inspect.signature(save_timeline_jpg).parameters:
|
| 104 |
-
single_frame_pred = locals().get('single_frame_pred', None)
|
| 105 |
-
|
| 106 |
-
# But better: pass single_frame_pred as an argument (see below for main loop update)
|
| 107 |
-
|
| 108 |
for i, fidx in enumerate(frames_to_render):
|
| 109 |
thumb = frames[fidx].resize((32, 32))
|
| 110 |
imagebox = OffsetImage(np.array(thumb), zoom=0.7)
|
|
@@ -126,8 +118,11 @@ def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_ra
|
|
| 126 |
# Draw frame index
|
| 127 |
ax.text(x_positions[i], 0.32, str(fidx), ha='center', va='center', fontsize=9, color='black', bbox=dict(facecolor='white', edgecolor='none', alpha=0.8, boxstyle='round,pad=0.2'))
|
| 128 |
# Draw prediction value below frame index
|
| 129 |
-
if
|
| 130 |
pred_val = single_frame_pred[fidx]
|
|
|
|
|
|
|
|
|
|
| 131 |
ax.text(x_positions[i], 0.18, f"{pred_val:.2f}", ha='center', va='center', fontsize=8, color='blue', bbox=dict(facecolor='white', edgecolor='none', alpha=0.7, boxstyle='round,pad=0.2'))
|
| 132 |
|
| 133 |
if title:
|
|
@@ -193,7 +188,8 @@ if __name__ == "__main__":
|
|
| 193 |
filename=timeline_filename,
|
| 194 |
interval=5,
|
| 195 |
roi_radius=2,
|
| 196 |
-
title=f"Timeline: {file.name}"
|
|
|
|
| 197 |
)
|
| 198 |
# Save prediction plot with thumbnails
|
| 199 |
save_prediction_plot(
|
|
|
|
| 56 |
pass
|
| 57 |
return frames
|
| 58 |
|
| 59 |
+
def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_radius=2, title=None, single_frame_pred=None):
|
| 60 |
"""
|
| 61 |
Save a timeline JPG with thumbnails every `interval` frames and every frame near scene changes.
|
| 62 |
Scene change regions are highlighted. Each thumbnail is annotated with its frame index.
|
|
|
|
| 97 |
first_frames = set(idx + 1 for idx in scene_change_indices if idx + 1 < len(frames))
|
| 98 |
|
| 99 |
# Draw thumbnails and annotate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
for i, fidx in enumerate(frames_to_render):
|
| 101 |
thumb = frames[fidx].resize((32, 32))
|
| 102 |
imagebox = OffsetImage(np.array(thumb), zoom=0.7)
|
|
|
|
| 118 |
# Draw frame index
|
| 119 |
ax.text(x_positions[i], 0.32, str(fidx), ha='center', va='center', fontsize=9, color='black', bbox=dict(facecolor='white', edgecolor='none', alpha=0.8, boxstyle='round,pad=0.2'))
|
| 120 |
# Draw prediction value below frame index
|
| 121 |
+
if single_frame_pred is not None:
|
| 122 |
pred_val = single_frame_pred[fidx]
|
| 123 |
+
# Ensure pred_val is a scalar float for formatting
|
| 124 |
+
if isinstance(pred_val, np.ndarray):
|
| 125 |
+
pred_val = float(pred_val.squeeze())
|
| 126 |
ax.text(x_positions[i], 0.18, f"{pred_val:.2f}", ha='center', va='center', fontsize=8, color='blue', bbox=dict(facecolor='white', edgecolor='none', alpha=0.7, boxstyle='round,pad=0.2'))
|
| 127 |
|
| 128 |
if title:
|
|
|
|
| 188 |
filename=timeline_filename,
|
| 189 |
interval=5,
|
| 190 |
roi_radius=2,
|
| 191 |
+
title=f"Timeline: {file.name}",
|
| 192 |
+
single_frame_pred=result["single_frame_pred"]
|
| 193 |
)
|
| 194 |
# Save prediction plot with thumbnails
|
| 195 |
save_prediction_plot(
|