milap edgarriba commited on
Commit
1787e0d
1 Parent(s): aa6f5b3

use kornia.io to load image and preprocess (#2)

Browse files

- use kornia.io to load image and preprocess (4f612641d683f1a7919689893da48cc33b3c7cd4)


Co-authored-by: Edgar Riba <edgarriba@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -8,20 +8,17 @@ from kornia_moons.feature import *
8
  import gradio as gr
9
 
10
  def load_torch_image(fname):
11
- img = K.image_to_tensor(fname, False).float() /255.
12
- img = K.color.bgr_to_rgb(img)
 
13
  return img
 
14
  def inference(file1,file2):
15
  fname1 = file1.name
16
- fname2 = file2.name
17
- im1 = cv2.imread(fname1)
18
- im1re = cv2.resize(im1, (700, 700))
19
- im2 = cv2.imread(fname2)
20
- im2re = cv2.resize(im2, (700, 700))
21
  img1 = load_torch_image(im1re)
22
  img2 = load_torch_image(im2re)
23
 
24
-
25
  matcher = KF.LoFTR(pretrained='outdoor')
26
 
27
  input_dict = {"image0": K.color.rgb_to_grayscale(img1), # LofTR works on grayscale images only
 
8
  import gradio as gr
9
 
10
  def load_torch_image(fname):
11
+ img: Tensor = K.io.load_image(fname, K.io.ImageLoadType.RGB32)
12
+ img = img[None] # 1xCxHxW / fp32 / [0, 1]
13
+ img = K.geometry.resize(img, (700, 700))
14
  return img
15
+
16
  def inference(file1,file2):
17
  fname1 = file1.name
18
+ fname2 = file2.name
 
 
 
 
19
  img1 = load_torch_image(im1re)
20
  img2 = load_torch_image(im2re)
21
 
 
22
  matcher = KF.LoFTR(pretrained='outdoor')
23
 
24
  input_dict = {"image0": K.color.rgb_to_grayscale(img1), # LofTR works on grayscale images only