codic commited on
Commit
babed9f
·
verified ·
1 Parent(s): ba4f35f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -110,15 +110,12 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
110
  depth_image_resized.max() - depth_image_resized.min()
111
  )
112
 
113
- # Debugging: Check normalization results
114
- print(f"Depth Image Min: {depth_image_resized.min()}, Max: {depth_image_resized.max()}")
115
-
116
- depth_image_normalized = depth_image_normalized.astype(np.float32)
117
-
118
  # Ensure depth image is valid
119
  if np.all(depth_image_normalized == 0):
120
  raise RuntimeError("Depth image normalization resulted in all zeros.")
121
 
 
 
122
  # Create flat background depth with a small gap for empty space
123
  background_depth = np.zeros_like(depth_image_normalized) + 1.5
124
 
@@ -131,19 +128,22 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
131
  image_o3d, depth_o3d, convert_rgb_to_intensity=False
132
  )
133
 
 
 
 
 
134
  # Check if the depth and foreground sizes are compatible
135
- w, h = foreground.shape[1], foreground.shape[0]
136
- if rgbd_image.color.shape[1] != w or rgbd_image.color.shape[0] != h:
137
  raise RuntimeError("RGBD image dimensions do not match foreground dimensions.")
138
 
139
  # Camera intrinsic setup
140
  camera_intrinsic = o3d.camera.PinholeCameraIntrinsic()
141
- camera_intrinsic.set_intrinsics(w, h, 1500, 1500, w / 2, h / 2)
142
 
143
  # Create the point cloud
144
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
145
 
146
- # Debugging: Print point cloud size
147
  print(f"Point Cloud Size: {len(pcd.points)}")
148
  if len(pcd.points) < 100:
149
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
 
110
  depth_image_resized.max() - depth_image_resized.min()
111
  )
112
 
 
 
 
 
 
113
  # Ensure depth image is valid
114
  if np.all(depth_image_normalized == 0):
115
  raise RuntimeError("Depth image normalization resulted in all zeros.")
116
 
117
+ depth_image_normalized = depth_image_normalized.astype(np.float32)
118
+
119
  # Create flat background depth with a small gap for empty space
120
  background_depth = np.zeros_like(depth_image_normalized) + 1.5
121
 
 
128
  image_o3d, depth_o3d, convert_rgb_to_intensity=False
129
  )
130
 
131
+ # Get dimensions of the rgbd_image
132
+ rgbd_width = rgbd_image.color.get_width()
133
+ rgbd_height = rgbd_image.color.get_height()
134
+
135
  # Check if the depth and foreground sizes are compatible
136
+ if rgbd_width != foreground.shape[1] or rgbd_height != foreground.shape[0]:
 
137
  raise RuntimeError("RGBD image dimensions do not match foreground dimensions.")
138
 
139
  # Camera intrinsic setup
140
  camera_intrinsic = o3d.camera.PinholeCameraIntrinsic()
141
+ camera_intrinsic.set_intrinsics(rgbd_width, rgbd_height, 1500, 1500, rgbd_width / 2, rgbd_height / 2)
142
 
143
  # Create the point cloud
144
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
145
 
146
+ # Check if the point cloud is valid
147
  print(f"Point Cloud Size: {len(pcd.points)}")
148
  if len(pcd.points) < 100:
149
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")