Update app.py
Browse files
app.py
CHANGED
|
@@ -38,41 +38,20 @@ def normalize_depth_image(depth_image):
|
|
| 38 |
# Function to inpaint the background
|
| 39 |
|
| 40 |
def inpaint_background(image, mask):
|
| 41 |
-
"""
|
| 42 |
-
Inpaint the background of the image using the given mask.
|
| 43 |
-
|
| 44 |
-
Args:
|
| 45 |
-
image (np.ndarray): The input image.
|
| 46 |
-
mask (np.ndarray): The mask indicating the area to inpaint.
|
| 47 |
-
|
| 48 |
-
Returns:
|
| 49 |
-
np.ndarray: The inpainted image.
|
| 50 |
-
"""
|
| 51 |
# Ensure the mask is binary (0 and 255)
|
| 52 |
mask_binary = (mask * 255).astype(np.uint8)
|
| 53 |
-
|
| 54 |
-
# Debugging: Check dimensions before resizing
|
| 55 |
-
print(f"Original Image shape: {image.shape}")
|
| 56 |
-
print(f"Original Mask shape: {mask_binary.shape}")
|
| 57 |
-
|
| 58 |
# Resize the mask to match the dimensions of the image if necessary
|
| 59 |
if image.shape[:2] != mask_binary.shape[:2]:
|
| 60 |
mask_binary_resized = cv2.resize(mask_binary, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
|
| 61 |
else:
|
| 62 |
mask_binary_resized = mask_binary
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
print(f"Resized Mask shape: {mask_binary_resized.shape}")
|
| 66 |
-
|
| 67 |
-
# Assert that the dimensions match
|
| 68 |
-
assert image.shape[:2] == mask_binary_resized.shape[:2], "Image and mask dimensions do not match!"
|
| 69 |
-
|
| 70 |
-
# Convert the image to uint8 if necessary
|
| 71 |
-
if image.dtype != np.uint8:
|
| 72 |
-
image = cv2.normalize(image, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)
|
| 73 |
|
| 74 |
# Inpaint the image using the resized mask
|
| 75 |
-
inpainted_image = cv2.inpaint(image, mask_binary_resized, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
|
| 76 |
|
| 77 |
return inpainted_image
|
| 78 |
|
|
@@ -183,6 +162,7 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
|
| 183 |
# Create the point cloud from the RGBD image
|
| 184 |
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
|
| 185 |
|
|
|
|
| 186 |
if len(pcd.points) < 100:
|
| 187 |
raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
|
| 188 |
|
|
|
|
| 38 |
# Function to inpaint the background
|
| 39 |
|
| 40 |
def inpaint_background(image, mask):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Ensure the mask is binary (0 and 255)
|
| 42 |
mask_binary = (mask * 255).astype(np.uint8)
|
| 43 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# Resize the mask to match the dimensions of the image if necessary
|
| 45 |
if image.shape[:2] != mask_binary.shape[:2]:
|
| 46 |
mask_binary_resized = cv2.resize(mask_binary, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
|
| 47 |
else:
|
| 48 |
mask_binary_resized = mask_binary
|
| 49 |
|
| 50 |
+
# Check dimensions before inpainting
|
| 51 |
+
print(f"Image shape: {image.shape}, Resized Mask shape: {mask_binary_resized.shape}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Inpaint the image using the resized mask
|
| 54 |
+
inpainted_image = cv2.inpaint(image.astype(np.uint8), mask_binary_resized, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
|
| 55 |
|
| 56 |
return inpainted_image
|
| 57 |
|
|
|
|
| 162 |
# Create the point cloud from the RGBD image
|
| 163 |
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
|
| 164 |
|
| 165 |
+
# Check if there are enough points in the point cloud
|
| 166 |
if len(pcd.points) < 100:
|
| 167 |
raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
|
| 168 |
|