Spaces:
Sleeping
Sleeping
Download utils/visualization.py from shin0624/Factory_Layout_Simulator: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/spaces/shin0624/Factory_Layout_Simulator/resolve/main/utils/visualization.py
- Command line
-
hf download hf://spaces/shin0624/Factory_Layout_Simulator/utils/visualization.py
-
curl -L -o visualization.py https://huggingface.co/spaces/shin0624/Factory_Layout_Simulator/resolve/main/utils/visualization.py
2.33 kB
| # utils/visualization.py | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from mpl_toolkits.mplot3d import Axes3D | |
| class FactoryVisualizer: | |
| def plot_3d_pointcloud(points, save_path=None): | |
| """3D ํฌ์ธํธ ํด๋ผ์ฐ๋ ์๊ฐํ""" | |
| fig = plt.figure(figsize=(12, 8)) | |
| ax = fig.add_subplot(111, projection='3d') | |
| ax.scatter( | |
| points[:,0], | |
| points[:,1], | |
| points[:,2], | |
| c=points[:,2], | |
| cmap='viridis', | |
| s=20, | |
| alpha=0.7 | |
| ) | |
| ax.set_xlabel('X Axis') | |
| ax.set_ylabel('Y Axis') | |
| ax.set_zlabel('Frame Sequence (Z)') | |
| ax.set_title('3D Factory Point Cloud') | |
| if save_path: | |
| plt.savefig(save_path, dpi=120, bbox_inches='tight') | |
| plt.close() | |
| else: | |
| plt.show() | |
| def create_top_down_view(points, save_path): | |
| """ํ๋ทฐ 2D ํ๋ก์ ์ ์์ฑ""" | |
| plt.figure(figsize=(10, 8)) | |
| plt.scatter(points[:,0], points[:,1], | |
| c=points[:,2], cmap='plasma', | |
| alpha=0.5, s=15) | |
| plt.colorbar(label='Frame Sequence') | |
| plt.xlabel('X Position') | |
| plt.ylabel('Y Position') | |
| plt.title('Top-Down View') | |
| plt.grid(True) | |
| plt.savefig(save_path, dpi=100) | |
| plt.close() | |
| def plot_class_distribution(detections, save_path): | |
| """๊ฐ์ฒด ๋ถํฌ ์๊ฐํ""" | |
| # ์์ : ์๋ณธ์ list of detections๋ฅผ ๊ธฐ๋ํ์ง๋ง, ์ค์ ์ ๋ ฅ์ class: count ๋์ ๋๋ฆฌ | |
| classes = list(detections.keys()) | |
| counts = list(detections.values()) | |
| plt.figure(figsize=(10, 6)) | |
| colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFA726'] | |
| bars = plt.bar(classes, counts, color=colors[:len(classes)]) | |
| plt.ylabel('Detection Count') | |
| plt.title('Object Distribution') | |
| plt.xticks(rotation=45) | |
| for bar in bars: | |
| height = bar.get_height() | |
| plt.text(bar.get_x() + bar.get_width()/2., height, | |
| f'{height}', | |
| ha='center', va='bottom') | |
| plt.tight_layout() | |
| plt.savefig(save_path, bbox_inches='tight') | |
| plt.close() |