Update app.py
Browse files
app.py
CHANGED
|
@@ -73,12 +73,18 @@ def process_image(image_path, depth_map_path=None):
|
|
| 73 |
raise Exception("Error reconstructing 3D model")
|
| 74 |
|
| 75 |
def create_3d_obj(rgb_image, depth_image, image_path, depth=12):
|
| 76 |
-
# Resize
|
| 77 |
depth_image_resized = np.array(
|
| 78 |
Image.fromarray(depth_image).resize(rgb_image.shape[:2][::-1], Image.NEAREST)
|
| 79 |
)
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
image_o3d = o3d.geometry.Image(rgb_image)
|
| 83 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 84 |
image_o3d, depth_o3d, convert_rgb_to_intensity=False
|
|
|
|
| 73 |
raise Exception("Error reconstructing 3D model")
|
| 74 |
|
| 75 |
def create_3d_obj(rgb_image, depth_image, image_path, depth=12):
|
| 76 |
+
# Resize and normalize the depth image if needed
|
| 77 |
depth_image_resized = np.array(
|
| 78 |
Image.fromarray(depth_image).resize(rgb_image.shape[:2][::-1], Image.NEAREST)
|
| 79 |
)
|
| 80 |
+
# Invert depth values (make closer objects lighter)
|
| 81 |
+
depth_image_normalized = (depth_image_resized - depth_image_resized.min()) / (
|
| 82 |
+
depth_image_resized.max() - depth_image_resized.min()
|
| 83 |
+
)
|
| 84 |
+
depth_image_inverted = (1 - depth_image_normalized) * 255
|
| 85 |
+
depth_image_inverted = depth_image_inverted.astype(np.uint8)
|
| 86 |
+
|
| 87 |
+
depth_o3d = o3d.geometry.Image(depth_image_inverted)
|
| 88 |
image_o3d = o3d.geometry.Image(rgb_image)
|
| 89 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 90 |
image_o3d, depth_o3d, convert_rgb_to_intensity=False
|