codic commited on
Commit
dc4d996
·
verified ·
1 Parent(s): 7f3085c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -98,15 +98,21 @@ def process_image(image_path, depth_map_path=None):
98
  return [img, gltf_path, gltf_path]
99
 
100
  def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
 
101
  depth_image_resized = np.array(
102
  Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)
103
  )
104
- depth_image_normalized = (depth_image_resized - depth_image_resized.min()) / (
105
- depth_image_resized.max() - depth_image_resized.min()
106
- ) * 255
107
- depth_image_normalized = depth_image_normalized.astype(np.uint8)
108
 
109
- depth_o3d = o3d.geometry.Image(depth_image_normalized)
 
 
 
 
 
 
 
 
 
110
  image_o3d = o3d.geometry.Image(foreground)
111
  rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
112
  image_o3d, depth_o3d, convert_rgb_to_intensity=False
 
98
  return [img, gltf_path, gltf_path]
99
 
100
  def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
101
+ # Resize depth_image to match the size of the foreground
102
  depth_image_resized = np.array(
103
  Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)
104
  )
 
 
 
 
105
 
106
+ # Ensure depth_image_resized is normalized to the [0, 1] range
107
+ depth_image_resized = (depth_image_resized - np.min(depth_image_resized)) / (
108
+ np.max(depth_image_resized) - np.min(depth_image_resized)
109
+ )
110
+
111
+ # Convert the normalized float image to 8-bit unsigned integers
112
+ depth_image_resized = img_as_ubyte(depth_image_resized)
113
+
114
+ # The rest of the function follows
115
+ depth_o3d = o3d.geometry.Image(depth_image_resized)
116
  image_o3d = o3d.geometry.Image(foreground)
117
  rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
118
  image_o3d, depth_o3d, convert_rgb_to_intensity=False