jiten6555 commited on
Commit
f9b9c98
·
verified ·
1 Parent(s): 1c3feda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -37
app.py CHANGED
@@ -99,44 +99,38 @@ class RobustDepthTo3DConverter:
99
  print(f"Depth estimation error: {e}")
100
  return None
101
 
102
- def create_point_cloud(self, image, depth_map):
103
- """
104
- Create point cloud with enhanced error handling
105
- """
106
- if depth_map is None:
107
- return None
108
-
109
- try:
110
- img_array = np.array(image)
111
- height, width = img_array.shape[:2]
112
-
113
- # More adaptive sampling
114
- step = max(1, min(height, width) // 300)
115
-
116
- points = []
117
- colors = []
118
-
119
- for y in range(0, height, step):
120
- for x in range(0, width, step):
121
- z = depth_map[y, x] / 255.0 * 10 # Extended depth scaling
122
- points.append([x, y, z])
123
-
124
- # Safer color extraction
125
- try:
126
- color = img_array[y, x][:3] / 255.0
127
- except IndexError:
128
- color = [0.5, 0.5, 0.5]
129
- colors.append(color)
130
-
131
- pcd = o3d.geometry.PointCloud()
132
- pcd.points = o3d.utility.Vector3dVector(points)
133
- pcd.colors = o3d.utility.Vector3dVector(colors)
134
-
135
- return pcd
136
 
137
- except Exception as e:
138
- print(f"Point cloud creation error: {e}")
139
- return None
140
 
141
  def convert_to_mesh(self, point_cloud):
142
  """
 
99
  print(f"Depth estimation error: {e}")
100
  return None
101
 
102
+ def create_point_cloud(self, image, depth_map):
103
+ """
104
+ Create point cloud with error handling and dimension checks
105
+ """
106
+ if depth_map is None:
107
+ return None
108
+
109
+ try:
110
+ img_array = np.array(image)
111
+ depth_map_resized = cv2.resize(depth_map, (img_array.shape[1], img_array.shape[0]), interpolation=cv2.INTER_LINEAR)
112
+ height, width = img_array.shape[:2]
113
+
114
+ step = max(1, min(height, width) // 200)
115
+ points, colors = [], []
116
+
117
+ for y in range(0, height, step):
118
+ for x in range(0, width, step):
119
+ z = depth_map_resized[y, x] / 255.0 * 5 # Scaled depth
120
+ points.append([x, y, z])
121
+ color = img_array[y, x][:3] / 255.0 if len(img_array[y, x]) >= 3 else [0.5, 0.5, 0.5]
122
+ colors.append(color)
123
+
124
+ pcd = o3d.geometry.PointCloud()
125
+ pcd.points = o3d.utility.Vector3dVector(points)
126
+ pcd.colors = o3d.utility.Vector3dVector(colors)
127
+
128
+ return pcd
129
+
130
+ except Exception as e:
131
+ print(f"Point cloud creation error: {e}")
132
+ return None
 
 
 
133
 
 
 
 
134
 
135
  def convert_to_mesh(self, point_cloud):
136
  """