Spaces:
Sleeping
Sleeping
Delete utils.py
Browse files
utils.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
import trimesh
|
| 2 |
-
import numpy as np
|
| 3 |
-
import os
|
| 4 |
-
import tempfile
|
| 5 |
-
import cv2
|
| 6 |
-
|
| 7 |
-
# ํคํ๋ ์ ์ถ์ถ ํจ์ (์์์์ ํน์ ํ๋ ์์ ์ถ์ถ)
|
| 8 |
-
def extract_keyframes(video_path, frame_interval=30):
|
| 9 |
-
"""
|
| 10 |
-
Extract keyframes from a video at a given interval.
|
| 11 |
-
|
| 12 |
-
:param video_path: Path to the input video file
|
| 13 |
-
:param frame_interval: Interval (in frames) between keyframes
|
| 14 |
-
:return: List of keyframes (as numpy arrays)
|
| 15 |
-
"""
|
| 16 |
-
# Open the video file
|
| 17 |
-
cap = cv2.VideoCapture(video_path)
|
| 18 |
-
|
| 19 |
-
# Get the total number of frames
|
| 20 |
-
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 21 |
-
|
| 22 |
-
keyframes = []
|
| 23 |
-
|
| 24 |
-
# Extract frames at the given interval
|
| 25 |
-
for i in range(0, total_frames, frame_interval):
|
| 26 |
-
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
| 27 |
-
ret, frame = cap.read()
|
| 28 |
-
if ret:
|
| 29 |
-
keyframes.append(frame)
|
| 30 |
-
|
| 31 |
-
cap.release()
|
| 32 |
-
return keyframes
|
| 33 |
-
|
| 34 |
-
# 3D Reconstruction (using trimesh to create simple 3D model)
|
| 35 |
-
def reconstruct_3d(keyframes):
|
| 36 |
-
"""
|
| 37 |
-
Reconstruct 3D point cloud or mesh from keyframes using simple feature matching.
|
| 38 |
-
|
| 39 |
-
:param keyframes: List of keyframes (as numpy arrays)
|
| 40 |
-
:return: 3D model (trimesh object)
|
| 41 |
-
"""
|
| 42 |
-
# Example: Create a simple mesh using trimesh (placeholder logic)
|
| 43 |
-
# For simplicity, we generate a cube mesh. In practice, 3D reconstruction would use feature matching
|
| 44 |
-
# and triangulation for actual 3D modeling.
|
| 45 |
-
mesh = trimesh.creation.box(extents=[1, 1, 1])
|
| 46 |
-
|
| 47 |
-
return mesh
|
| 48 |
-
|
| 49 |
-
# Save 3D mesh to WebGL HTML file
|
| 50 |
-
def save_3d_to_webgl(mesh, output_path="output_model.html"):
|
| 51 |
-
"""
|
| 52 |
-
Save a 3D mesh to a WebGL-compatible HTML file using trimesh's built-in method.
|
| 53 |
-
|
| 54 |
-
:param mesh: 3D mesh object (trimesh)
|
| 55 |
-
:param output_path: Path to save the HTML file
|
| 56 |
-
"""
|
| 57 |
-
# Export mesh as WebGL (HTML format)
|
| 58 |
-
mesh.export(output_path, file_type='html')
|
| 59 |
-
print(f"3D model saved to {output_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|