Download tools/dump_frames.py from AK51/MoonFlash: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/spaces/AK51/MoonFlash/resolve/main/tools/dump_frames.py
- Command line
-
hf download hf://spaces/AK51/MoonFlash/tools/dump_frames.py
-
curl -L -o dump_frames.py https://huggingface.co/spaces/AK51/MoonFlash/resolve/main/tools/dump_frames.py
1.82 kB
| """ | |
| Decode selected frame ranges of the test video, downscale to the detector's | |
| analysis resolution, and write raw RGBA frames + timing so the ACTUAL | |
| detector.js can be run in Node against real data. | |
| Binary format: | |
| header: <iiii aw, ah, fps_int, count | |
| then per frame: <i frameIndex, then aw*ah*4 bytes RGBA | |
| """ | |
| import cv2, numpy as np, struct | |
| PATH = r"E:\test\Kiro_flash_detection\Video\0921 (1)_flash.mp4" | |
| OUT = r"E:\test\Kiro_flash_detection\tools\frames.bin" | |
| ANALYSIS_W = 480 | |
| # Include >=15 lead-in frames before each window for the rolling background. | |
| WINDOWS = [ | |
| (2580, 2660), # the real flash at 2612 (must still be detected) | |
| (2330, 2380), # the reported false positive at 2353-2358 / peak 2355 | |
| (2510, 2560), # prior false-positive cluster ~2535 | |
| (2080, 2160), # prior false-positive cluster ~2105 | |
| ] | |
| cap = cv2.VideoCapture(PATH) | |
| fps = cap.get(cv2.CAP_PROP_FPS) or 30.0 | |
| W = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)); H = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
| scale = W/ANALYSIS_W if W > ANALYSIS_W else 1.0 | |
| aw = max(1, round(W/scale)); ah = max(1, round(H/scale)) | |
| want, seen = [], set() | |
| for a, b in WINDOWS: | |
| for i in range(a, b+1): | |
| if i not in seen: | |
| seen.add(i); want.append(i) | |
| want.sort() | |
| records = [] | |
| for idx in want: | |
| cap.set(cv2.CAP_PROP_POS_FRAMES, idx) | |
| ok, f = cap.read() | |
| if not ok: continue | |
| s = cv2.resize(f, (aw, ah), interpolation=cv2.INTER_AREA) | |
| rgba = cv2.cvtColor(s, cv2.COLOR_BGR2RGBA) | |
| records.append((idx, rgba.tobytes())) | |
| cap.release() | |
| with open(OUT, "wb") as fo: | |
| fo.write(struct.pack("<iiii", aw, ah, int(round(fps)), len(records))) | |
| for idx, buf in records: | |
| fo.write(struct.pack("<i", idx)) | |
| fo.write(buf) | |
| print(f"wrote {len(records)} frames {aw}x{ah} fps~{fps} scale={scale:.3f} to {OUT}") | |