Spaces:
Sleeping
Sleeping
File size: 3,282 Bytes
c67582c c0cb016 c67582c 58b4ac9 c67582c bdcadd4 c67582c f10a28a c67582c f10a28a c67582c c0cb016 c67582c c0cb016 f10a28a c0cb016 c67582c c0cb016 c67582c bdcadd4 c67582c bdcadd4 c0cb016 bdcadd4 c67582c c0cb016 c67582c c0cb016 f10a28a c67582c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | import gradio as gr
import tempfile
import os
import numpy as np
from detector.frame_sampler import extract_keyframes
from detector.yolo_pipeline import YOLO3DReconstructor
from exporters.webgl_exporter import export_to_webgl
from utils.visualization import FactoryVisualizer
def process_video(video):
with tempfile.TemporaryDirectory() as tmpdir:
print(f"์์ ๋๋ ํ ๋ฆฌ ์์ฑ: {tmpdir}") # ๊ฒฝ๋ก ํ์ธ
# 1. ํคํ๋ ์ ์ถ์ถ
frames_dir = os.path.join(tmpdir, "frames")
os.makedirs(frames_dir, exist_ok=True)
frame_paths = extract_keyframes(video, frames_dir)
if not frame_paths:
raise gr.Error("๋น๋์ค ํ์ผ์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค!")
# 2. 3D ํฌ์ธํธ ํด๋ผ์ฐ๋ ์์ฑ
reconstructor = YOLO3DReconstructor()
result = reconstructor.process_frames(frame_paths)
if result is None:
raise gr.Error("์์์์ ๊ฐ์ง ๊ฐ๋ฅํ ๊ฐ์ฒด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค!")
pointcloud, detections = result
# 3. ์๊ฐํ ๊ฒฐ๊ณผ ์์ฑ
vis_dir = os.path.join(tmpdir, "visualizations")
os.makedirs(vis_dir, exist_ok=True)
# 3D ํฌ์ธํธ ํด๋ผ์ฐ๋ ์๊ฐํ
pc_points = np.array([point[:3] for point in pointcloud.vertices])
FactoryVisualizer.plot_3d_pointcloud(
pc_points,
save_path=os.path.join(vis_dir, "3d_view.png")
)
# ํ๋ทฐ ์๊ฐํ
FactoryVisualizer.create_top_down_view(
pc_points,
save_path=os.path.join(vis_dir, "top_view.png")
)
# ํด๋์ค ๋ถํฌ ์๊ฐํ
FactoryVisualizer.plot_class_distribution(
detections,
save_path=os.path.join(vis_dir, "distribution.png")
)
# 4. ๋ชจ๋ธ ๋ฐ ๊ฒฐ๊ณผ ํ์ผ ์ ์ฅ
obj_path = os.path.join(tmpdir, "factory.obj")
if len(pc_points) < 3: # ์ต์ 3๊ฐ ํฌ์ธํธ ํ์
raise gr.Error("ํฌ์ธํธ ํด๋ผ์ฐ๋ ์์ฑ ์คํจ: ์ถฉ๋ถํ ๋ฐ์ดํฐ ์์")
pointcloud.export(obj_path)
html_path = export_to_webgl(obj_path, tmpdir)
print("์์ฑ๋ ํ์ผ ๋ชฉ๋ก:", os.listdir(tmpdir)) # ํ์ผ ์กด์ฌ ์ฌ๋ถ ํ์ธ
return (
obj_path,
html_path,
os.path.join(vis_dir, "3d_view.png"),
os.path.join(vis_dir, "top_view.png"),
os.path.join(vis_dir, "distribution.png")
)
iface = gr.Interface(
fn=process_video,
inputs=gr.Video(label="๊ณต์ฅ ์์ ์
๋ก๋ (MP4/AVI)"),
outputs=[
gr.Model3D(label="3D ํฌ์ธํธ ํด๋ผ์ฐ๋ ๋ชจ๋ธ"),
gr.File(label="WebGL ์ธํฐ๋ํฐ๋ธ ๋ทฐ์ด"),
gr.Image(label="3D ๊ณต์ฅ ๊ตฌ์กฐ", type="filepath"),
gr.Image(label="ํ๋ทฐ ๊ตฌ์กฐ๋งต", type="filepath"),
gr.Image(label="๊ฐ์ฒด ๋ถํฌ ๋ถ์", type="filepath")
],
title="๐ญ AI ๊ณต์ฅ ๊ตฌ์กฐ ๋ถ์ ์์คํ
",
description="์
๋ก๋๋ ๊ณต์ฅ ์์์์ 3D ๊ตฌ์กฐ๋งต๊ณผ ๋ถ์ ๋ฆฌํฌํธ๋ฅผ ์๋ ์์ฑํฉ๋๋ค",
allow_flagging="never",
examples=[], # ์์ ์ถ๊ฐ ๊ฐ๋ฅ
)
if __name__ == "__main__":
iface.launch(debug=True) |