Spaces:
Sleeping
Sleeping
TakashiKAWAMOTO-TTS commited on
Commit ·
0f772ca
1
Parent(s): 20a4b72
add application file
Browse files- app.py +45 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import open3d as o3d
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import tempfile
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
def process_point_cloud(file_obj):
|
| 9 |
+
# Save uploaded file temporarily
|
| 10 |
+
temp_path = os.path.join(tempfile.gettempdir(), file_obj.name)
|
| 11 |
+
with open(temp_path, "wb") as f:
|
| 12 |
+
f.write(file_obj.read())
|
| 13 |
+
|
| 14 |
+
# Load point cloud using Open3D
|
| 15 |
+
pcd = o3d.io.read_point_cloud(temp_path)
|
| 16 |
+
|
| 17 |
+
# Process: voxel downsampling
|
| 18 |
+
downsampled = pcd.voxel_down_sample(voxel_size=0.01)
|
| 19 |
+
|
| 20 |
+
# Estimate normals for visualization
|
| 21 |
+
downsampled.estimate_normals()
|
| 22 |
+
|
| 23 |
+
# Visualize to image
|
| 24 |
+
vis = o3d.visualization.Visualizer()
|
| 25 |
+
vis.create_window(visible=False)
|
| 26 |
+
vis.add_geometry(downsampled)
|
| 27 |
+
vis.poll_events()
|
| 28 |
+
vis.update_renderer()
|
| 29 |
+
img = vis.capture_screen_float_buffer(True)
|
| 30 |
+
vis.destroy_window()
|
| 31 |
+
|
| 32 |
+
# Convert image to numpy and return
|
| 33 |
+
img_np = (255 * np.asarray(img)).astype(np.uint8)
|
| 34 |
+
return img_np
|
| 35 |
+
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=process_point_cloud,
|
| 38 |
+
inputs=gr.File(file_types=[".ply", ".pcd", ".xyz"], label="Upload Point Cloud"),
|
| 39 |
+
outputs=gr.Image(type="numpy", label="Rendered Point Cloud"),
|
| 40 |
+
title="Point Cloud Viewer",
|
| 41 |
+
description="Upload a .ply, .pcd, or .xyz file. The app will downsample and render it."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
open3d
|
| 3 |
+
matplotlib
|
| 4 |
+
numpy
|