mischeiwiller commited on
Commit
b368542
1 Parent(s): bc3919a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -6,26 +6,30 @@ import kornia.feature as KF
6
  import torch
7
  import numpy as np
8
 
9
- def inference(img_1, img_2):
10
- # Convert numpy arrays to Tensors and ensure correct shape
11
- img_1: Tensor = K.image_to_tensor(img_1, keepdim=False).float() / 255.0
12
- img_2: Tensor = K.image_to_tensor(img_2, keepdim=False).float() / 255.0
13
 
14
- # Ensure 3D tensors (C, H, W)
15
- if img_1.ndim == 2:
16
- img_1 = img_1.unsqueeze(0)
17
- if img_2.ndim == 2:
18
- img_2 = img_2.unsqueeze(0)
19
 
20
- # Ensure 3 channel images
21
- if img_1.shape[0] == 1:
22
- img_1 = img_1.repeat(3, 1, 1)
23
- if img_2.shape[0] == 1:
24
- img_2 = img_2.repeat(3, 1, 1)
25
 
26
  # Add batch dimension
27
- img_1 = img_1.unsqueeze(0)
28
- img_2 = img_2.unsqueeze(0)
 
 
 
 
 
 
29
 
30
  IS = ImageStitcher(KF.LoFTR(pretrained='outdoor'), estimator='ransac')
31
  with torch.no_grad():
 
6
  import torch
7
  import numpy as np
8
 
9
+ def preprocess_image(img):
10
+ # Convert numpy array to Tensor and ensure correct shape
11
+ if isinstance(img, np.ndarray):
12
+ img = K.image_to_tensor(img, keepdim=False).float() / 255.0
13
 
14
+ # Ensure 3D tensor (C, H, W)
15
+ if img.ndim == 2:
16
+ img = img.unsqueeze(0)
 
 
17
 
18
+ # Ensure 3 channel image
19
+ if img.shape[0] == 1:
20
+ img = img.repeat(3, 1, 1)
21
+ elif img.shape[0] > 3:
22
+ img = img[:3] # Take only the first 3 channels if more than 3
23
 
24
  # Add batch dimension
25
+ img = img.unsqueeze(0)
26
+
27
+ return img
28
+
29
+ def inference(img_1, img_2):
30
+ # Preprocess images
31
+ img_1 = preprocess_image(img_1)
32
+ img_2 = preprocess_image(img_2)
33
 
34
  IS = ImageStitcher(KF.LoFTR(pretrained='outdoor'), estimator='ransac')
35
  with torch.no_grad():