Initial commit: Synthetic Defect Factory digital twin & automated AOI pipeline
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
blender/stitch_videos.py
|
||||
|
||||
Stitches rendered animation frames into high-quality MP4 videos at 24 FPS.
|
||||
"""
|
||||
|
||||
import os
|
||||
import glob
|
||||
import cv2
|
||||
|
||||
|
||||
def stitch_folder(frames_dir, out_mp4, fps=24.0, res_x=640, res_y=640):
|
||||
pattern = os.path.join(frames_dir, "frame_*.png")
|
||||
frames = sorted(glob.glob(pattern))
|
||||
if not frames:
|
||||
print(f"No frames found matching {pattern}")
|
||||
return False
|
||||
|
||||
os.makedirs(os.path.dirname(out_mp4), exist_ok=True)
|
||||
first_img = cv2.imread(frames[0])
|
||||
h, w = first_img.shape[:2]
|
||||
|
||||
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
||||
out = cv2.VideoWriter(out_mp4, fourcc, fps, (w, h))
|
||||
|
||||
for f in frames:
|
||||
img = cv2.imread(f)
|
||||
if img is not None:
|
||||
out.write(img)
|
||||
|
||||
out.release()
|
||||
size_mb = os.path.getsize(out_mp4) / (1024 * 1024)
|
||||
print(f"Saved: {out_mp4} ({len(frames)} frames, {w}x{h}, {size_mb:.2f} MB)")
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 1. Station Camera Inspection Video (Top-Down Machine Vision POV)
|
||||
stitch_folder(
|
||||
"renders/animation/frames_station_cam",
|
||||
"renders/animation/station_camera_inspection.mp4",
|
||||
fps=24.0
|
||||
)
|
||||
|
||||
# 2. 3D Overview Conveyor Simulation Video (Perspective Factory POV)
|
||||
stitch_folder(
|
||||
"renders/animation/frames_overview",
|
||||
"renders/animation/station_overview_inspection.mp4",
|
||||
fps=24.0
|
||||
)
|
||||
Reference in New Issue
Block a user