A19grey commited on
Commit
5784c10
1 Parent(s): 755366f

Added type checking

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -69,6 +69,10 @@ def generate_3d_model(depth, image_path, focallength_px):
69
  # Load the RGB image and convert to a NumPy array
70
  image = np.array(Image.open(image_path))
71
 
 
 
 
 
72
  # Resize depth to match image dimensions if necessary
73
  if depth.shape != image.shape[:2]:
74
  depth = cv2.resize(depth, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_LINEAR)
@@ -79,7 +83,7 @@ def generate_3d_model(depth, image_path, focallength_px):
79
  print(f"3D model generation - Image shape: {image.shape}")
80
 
81
  # Compute camera intrinsic parameters
82
- fx = fy = focallength_px # Assuming square pixels and fx = fy
83
  cx, cy = width / 2, height / 2 # Principal point at the image center
84
 
85
  # Create a grid of (u, v) pixel coordinates
 
69
  # Load the RGB image and convert to a NumPy array
70
  image = np.array(Image.open(image_path))
71
 
72
+ # Ensure depth is a NumPy array
73
+ if isinstance(depth, torch.Tensor):
74
+ depth = depth.cpu().numpy()
75
+
76
  # Resize depth to match image dimensions if necessary
77
  if depth.shape != image.shape[:2]:
78
  depth = cv2.resize(depth, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_LINEAR)
 
83
  print(f"3D model generation - Image shape: {image.shape}")
84
 
85
  # Compute camera intrinsic parameters
86
+ fx = fy = float(focallength_px) # Ensure focallength_px is a float
87
  cx, cy = width / 2, height / 2 # Principal point at the image center
88
 
89
  # Create a grid of (u, v) pixel coordinates