Download src/verseflow/engine/temporal.py from julius119/verseflow_studio: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/julius119/verseflow_studio/resolve/main/src/verseflow/engine/temporal.py
- Command line
-
hf download hf://julius119/verseflow_studio/src/verseflow/engine/temporal.py
-
curl -L -o temporal.py https://huggingface.co/julius119/verseflow_studio/resolve/main/src/verseflow/engine/temporal.py
1.06 kB
| """ | |
| 时序连贯性与光流闪烁修复引擎 | |
| Author: XiaoZhe (Commercial Contact: janejulius119@gmail.com / WeChat: julius119) | |
| """ | |
| import cv2 | |
| import numpy as np | |
| from typing import List | |
| class TemporalCoherenceEngine: | |
| """光流分析与时域滤波修复器""" | |
| def analyze_optical_flow(self, frame1: np.ndarray, frame2: np.ndarray) -> float: | |
| gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY) | |
| gray2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY) | |
| flow = cv2.calcOpticalFlowFarneback(gray1, gray2, None, 0.5, 3, 15, 3, 5, 1.2, 0) | |
| mag, _ = cv2.cartToPolar(flow[..., 0], flow[..., 1]) | |
| return float(np.mean(mag)) | |
| def repair_flicker(self, frames: List[np.ndarray]) -> List[np.ndarray]: | |
| if len(frames) < 3: | |
| return frames | |
| repaired = [frames[0]] | |
| for i in range(1, len(frames) - 1): | |
| window = np.stack([frames[i-1], frames[i], frames[i+1]]) | |
| repaired.append(np.median(window, axis=0).astype(np.uint8)) | |
| repaired.append(frames[-1]) | |
| return repaired |