codic commited on
Commit
97f7020
·
verified ·
1 Parent(s): 36f3551

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -103,23 +103,15 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=12):
103
  # Normalize depth_image_resized to the range [0, 1]
104
  min_depth = np.min(depth_image_resized)
105
  max_depth = np.max(depth_image_resized)
106
-
107
  if max_depth - min_depth == 0:
108
  raise ValueError("Depth image has no variation; cannot normalize.")
109
 
110
- depth_image_resized = (depth_image_resized - min_depth) / (max_depth - min_depth)
111
- depth_image_resized = np.clip(depth_image_resized, 0, 1) # Ensure values are between 0 and 1
112
-
113
- # Convert the normalized float image to float format
114
- depth_image_float = img_as_float(depth_image_resized)
115
-
116
- # Check the range of the depth image after conversion to float
117
- if np.min(depth_image_float) < -1 or np.max(depth_image_float) > 1:
118
- raise ValueError(f"Depth image values after float conversion must be in the range [-1, 1]: "
119
- f"min={np.min(depth_image_float)}, max={np.max(depth_image_float)}")
120
 
121
- # Convert to 8-bit unsigned integers
122
- depth_image_resized_uint8 = img_as_ubyte(depth_image_float)
123
 
124
  # Create Open3D image from the depth and foreground images
125
  depth_o3d = o3d.geometry.Image(depth_image_resized_uint8)
 
103
  # Normalize depth_image_resized to the range [0, 1]
104
  min_depth = np.min(depth_image_resized)
105
  max_depth = np.max(depth_image_resized)
106
+
107
  if max_depth - min_depth == 0:
108
  raise ValueError("Depth image has no variation; cannot normalize.")
109
 
110
+ depth_image_normalized = (depth_image_resized - min_depth) / (max_depth - min_depth)
111
+ depth_image_normalized = np.clip(depth_image_normalized, 0, 1) # Ensure values are between 0 and 1
 
 
 
 
 
 
 
 
112
 
113
+ # Convert to 8-bit unsigned integers using OpenCV
114
+ depth_image_resized_uint8 = (depth_image_normalized * 255).astype(np.uint8)
115
 
116
  # Create Open3D image from the depth and foreground images
117
  depth_o3d = o3d.geometry.Image(depth_image_resized_uint8)