jbilcke-hf HF Staff commited on
Commit
c446987
·
verified ·
1 Parent(s): 1c8dc47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -286,11 +286,6 @@ class GPUSatelliteModelGenerator:
286
 
287
  # Detect tree areas and generate tree geometry
288
  tree_mask = cp.all(texture_img_gpu == self.colors['dark_green'], axis=2)
289
-
290
- # Add some debug printing
291
- print(f"Tree mask shape: {tree_mask.shape}")
292
- print(f"Number of trees detected: {cp.sum(tree_mask)}")
293
-
294
  vertices = self.generate_tree_vertices(tree_mask, vertices)
295
 
296
  # Normalize coordinates
@@ -303,9 +298,9 @@ class GPUSatelliteModelGenerator:
303
  faces = self.generate_faces_gpu(height, width)
304
  uvs = self.generate_uvs_gpu(vertices, width, height)
305
 
306
- # Create textured mesh
307
  return self.create_textured_mesh(vertices, faces, uvs, texture_img)
308
-
309
 
310
  @staticmethod
311
  def generate_faces_gpu(height, width):
@@ -332,20 +327,32 @@ class GPUSatelliteModelGenerator:
332
  @staticmethod
333
  def create_textured_mesh(vertices, faces, uvs, texture_img):
334
  """Create textured mesh with proper color conversion"""
335
- if len(texture_img.shape) == 3 and texture_img.shape[2] == 4:
336
- texture_img = cv2.cvtColor(texture_img, cv2.COLOR_BGRA2RGB)
337
- elif len(texture_img.shape) == 3:
338
- texture_img = cv2.cvtColor(texture_img, cv2.COLOR_BGR2RGB)
339
-
340
- return trimesh.Trimesh(
341
- vertices=vertices.get(),
342
- faces=faces.get(),
 
 
 
 
 
 
 
 
 
 
343
  visual=trimesh.visual.TextureVisuals(
344
- uv=uvs.get(),
345
- image=Image.fromarray(texture_img)
346
  )
347
  )
348
 
 
 
349
  def generate_and_process_map(prompt: str) -> tuple[str | None, np.ndarray | None]:
350
  """Generate satellite image from prompt and convert to 3D model using GPU acceleration"""
351
  try:
 
286
 
287
  # Detect tree areas and generate tree geometry
288
  tree_mask = cp.all(texture_img_gpu == self.colors['dark_green'], axis=2)
 
 
 
 
 
289
  vertices = self.generate_tree_vertices(tree_mask, vertices)
290
 
291
  # Normalize coordinates
 
298
  faces = self.generate_faces_gpu(height, width)
299
  uvs = self.generate_uvs_gpu(vertices, width, height)
300
 
301
+ # Create textured mesh using the original texture image
302
  return self.create_textured_mesh(vertices, faces, uvs, texture_img)
303
+
304
 
305
  @staticmethod
306
  def generate_faces_gpu(height, width):
 
327
  @staticmethod
328
  def create_textured_mesh(vertices, faces, uvs, texture_img):
329
  """Create textured mesh with proper color conversion"""
330
+ # Ensure we're working with the original texture image
331
+ if isinstance(texture_img, cp.ndarray):
332
+ texture_img = texture_img.get()
333
+
334
+ # Convert texture image to RGB format for PIL
335
+ if len(texture_img.shape) == 3:
336
+ if texture_img.shape[2] == 4: # BGRA
337
+ texture_img = cv2.cvtColor(texture_img, cv2.COLOR_BGRA2RGB)
338
+ else: # BGR
339
+ texture_img = cv2.cvtColor(texture_img, cv2.COLOR_BGR2RGB)
340
+
341
+ # Create PIL Image from the texture
342
+ texture_pil = Image.fromarray(texture_img)
343
+
344
+ # Create the mesh with texture
345
+ mesh = trimesh.Trimesh(
346
+ vertices=vertices.get() if isinstance(vertices, cp.ndarray) else vertices,
347
+ faces=faces.get() if isinstance(faces, cp.ndarray) else faces,
348
  visual=trimesh.visual.TextureVisuals(
349
+ uv=uvs.get() if isinstance(uvs, cp.ndarray) else uvs,
350
+ image=texture_pil
351
  )
352
  )
353
 
354
+ return mesh
355
+
356
  def generate_and_process_map(prompt: str) -> tuple[str | None, np.ndarray | None]:
357
  """Generate satellite image from prompt and convert to 3D model using GPU acceleration"""
358
  try: