MarioPrzBasto commited on
Commit
a76e8fd
·
verified ·
1 Parent(s): 3fd4dfd

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -0
main.py CHANGED
@@ -27,6 +27,21 @@ BASE_DIR = "/tmp/data"
27
  app = FastAPI()
28
  mobilenet = MobileNetV2(weights="imagenet", include_top=False, pooling='avg')
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def orb_sim(img1, img2):
31
  # ORB
32
  orb = cv2.ORB_create()
 
27
  app = FastAPI()
28
  mobilenet = MobileNetV2(weights="imagenet", include_top=False, pooling='avg')
29
 
30
+ def orb_sim(img1, img2):
31
+ score = 0
32
+
33
+ orb = cv2.ORB_create()
34
+ kp_a, desc_a = orb.detectAndCompute(img1, None)
35
+ kp_b, desc_b = orb.detectAndCompute(img2, None)
36
+
37
+ bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
38
+ matches = bf.match(desc_a, desc_b)
39
+ similar_regions = [i for i in matches if i.distance < 20]
40
+ if len(matches) > 0:
41
+ score = (len(similar_regions) / len(matches)) * 100
42
+
43
+ return 1 if 0 < score < 1 else score
44
+
45
  def orb_sim(img1, img2):
46
  # ORB
47
  orb = cv2.ORB_create()