Ivanrs commited on
Commit
7cf7dd1
โ€ข
1 Parent(s): 744024b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +71 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from cProfile import label
2
+ import gradio as gr
3
+ import cv2
4
+ import matplotlib.pyplot as plt
5
+ from scipy import ndimage
6
+ from scipy.ndimage.filters import convolve
7
+ import numpy as np
8
+
9
+
10
+ def sift(img1, img2):
11
+ sift = cv2.SIFT_create()
12
+
13
+ keypoints_1, descriptors_1 = sift.detectAndCompute(img1,None)
14
+ keypoints_2, descriptors_2 = sift.detectAndCompute(img2,None)
15
+
16
+ bf = cv2.BFMatcher(cv2.NORM_L1, crossCheck=True)
17
+
18
+ matches = bf.match(descriptors_1,descriptors_2)
19
+ matches = sorted(matches, key = lambda x:x.distance)
20
+
21
+ img3 = cv2.drawMatches(img1, keypoints_1, img2, keypoints_2, matches[:50], img2, flags=2)
22
+ return img3
23
+
24
+ def orb(img1, img2):
25
+ orb = cv2.ORB_create()
26
+
27
+ keypoints_1, descriptors_1 = orb.detectAndCompute(img1,None)
28
+ keypoints_2, descriptors_2 = orb.detectAndCompute(img2,None)
29
+
30
+ bf = cv2.BFMatcher(cv2.NORM_L1, crossCheck=True)
31
+
32
+ matches = bf.match(descriptors_1,descriptors_2)
33
+ matches = sorted(matches, key = lambda x:x.distance)
34
+
35
+ img3 = cv2.drawMatches(img1, keypoints_1, img2, keypoints_2, matches[:50], img2, flags=2)
36
+ return img3
37
+
38
+ def match(img1, img2):
39
+
40
+ img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
41
+ img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
42
+
43
+ sift_res = sift(img1, img2)
44
+ orb_res = orb(img1, img2)
45
+
46
+ return [sift_res, orb_res]
47
+
48
+
49
+ interface = gr.Interface(
50
+ title = "SIFT and ORB Image Matching ๐Ÿ–ผ ๐Ÿ‘‰ ๐Ÿ–ผ",
51
+ description = "<h3>Scale Invariant Feature Transform (SIFT) & Oriented FAST and Rotated BRIEF (ORB) </h3> <br> <b>Select training and query images ๐Ÿ–ผ</b>",
52
+ article='~ Ivanrs',
53
+ allow_flagging = "never",
54
+ fn = match,
55
+ inputs = [
56
+ gr.Image(label = "Train Image", shape = [300, 200]),
57
+ gr.Image(label = "Query Image", shape = [300, 200]),
58
+ ],
59
+ outputs = [
60
+ gr.Image(label = "SIFT Output"),
61
+ gr.Image(label = "ORB Output"),
62
+ ],
63
+ examples = [
64
+ ["images/img1.jpg", "images/img2.jpg"],
65
+ ["images/img3.jpg", "images/img4.jpg"],
66
+ ["images/img5.jpg", "images/img6.png"],
67
+ ["images/img7.jpeg", "images/img8.jpeg"]
68
+ ]
69
+ )
70
+
71
+ interface.launch(share = False)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ opencv-python
2
+ matplotlib
3
+ scipy
4
+ numpy