Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from SuperGluePretrainedNetwork.models.matching import Matching
|
|
12 |
from SuperGluePretrainedNetwork.models.utils import read_image
|
13 |
import matplotlib.pyplot as plt
|
14 |
import matplotlib.cm as cm
|
|
|
15 |
|
16 |
# Set device
|
17 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
@@ -61,22 +62,27 @@ def stitch_images(images):
|
|
61 |
return composite
|
62 |
|
63 |
def unified_matching_plot2(image0, image1, kpts0, kpts1, mkpts0, mkpts1, color, text, path=None, show_keypoints=False, fast_viz=False, opencv_display=False, opencv_title='matches', small_text=[]):
|
|
|
|
|
|
|
|
|
|
|
64 |
plt.figure(figsize=(15, 15))
|
65 |
plt.subplot(1, 2, 1)
|
66 |
-
plt.imshow(
|
67 |
plt.scatter(kpts0[:, 0], kpts0[:, 1], color='r', s=1)
|
68 |
plt.axis('off')
|
69 |
|
70 |
plt.subplot(1, 2, 2)
|
71 |
-
plt.imshow(
|
72 |
plt.scatter(kpts1[:, 0], kpts1[:, 1], color='r', s=1)
|
73 |
plt.axis('off')
|
74 |
|
75 |
fig, ax = plt.subplots(figsize=(20, 20))
|
76 |
-
plt.plot([mkpts0[:, 0], mkpts1[:, 0] +
|
77 |
plt.scatter(mkpts0[:, 0], mkpts0[:, 1], s=2, marker='o', color='b')
|
78 |
-
plt.scatter(mkpts1[:, 0] +
|
79 |
-
plt.imshow(np.hstack([
|
80 |
|
81 |
plt.suptitle('\n'.join(text), fontsize=20, fontweight='bold')
|
82 |
plt.tight_layout()
|
|
|
12 |
from SuperGluePretrainedNetwork.models.utils import read_image
|
13 |
import matplotlib.pyplot as plt
|
14 |
import matplotlib.cm as cm
|
15 |
+
from io import BytesIO
|
16 |
|
17 |
# Set device
|
18 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
62 |
return composite
|
63 |
|
64 |
def unified_matching_plot2(image0, image1, kpts0, kpts1, mkpts0, mkpts1, color, text, path=None, show_keypoints=False, fast_viz=False, opencv_display=False, opencv_title='matches', small_text=[]):
|
65 |
+
# Resize images to have the same height
|
66 |
+
height = min(image0.shape[0], image1.shape[0])
|
67 |
+
image0_resized = cv2.resize(image0, (int(image0.shape[1] * height / image0.shape[0]), height))
|
68 |
+
image1_resized = cv2.resize(image1, (int(image1.shape[1] * height / image1.shape[0]), height))
|
69 |
+
|
70 |
plt.figure(figsize=(15, 15))
|
71 |
plt.subplot(1, 2, 1)
|
72 |
+
plt.imshow(image0_resized)
|
73 |
plt.scatter(kpts0[:, 0], kpts0[:, 1], color='r', s=1)
|
74 |
plt.axis('off')
|
75 |
|
76 |
plt.subplot(1, 2, 2)
|
77 |
+
plt.imshow(image1_resized)
|
78 |
plt.scatter(kpts1[:, 0], kpts1[:, 1], color='r', s=1)
|
79 |
plt.axis('off')
|
80 |
|
81 |
fig, ax = plt.subplots(figsize=(20, 20))
|
82 |
+
plt.plot([mkpts0[:, 0], mkpts1[:, 0] + image0_resized.shape[1]], [mkpts0[:, 1], mkpts1[:, 1]], 'r', lw=0.5)
|
83 |
plt.scatter(mkpts0[:, 0], mkpts0[:, 1], s=2, marker='o', color='b')
|
84 |
+
plt.scatter(mkpts1[:, 0] + image0_resized.shape[1], mkpts1[:, 1], s=2, marker='o', color='g')
|
85 |
+
plt.imshow(np.hstack([image0_resized, image1_resized]), aspect='auto')
|
86 |
|
87 |
plt.suptitle('\n'.join(text), fontsize=20, fontweight='bold')
|
88 |
plt.tight_layout()
|