Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update similarity.py
Browse files- similarity.py +16 -9
similarity.py
CHANGED
@@ -12,16 +12,23 @@ import logging
|
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
14 |
def orb_sim(img1, img2):
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
|
20 |
-
matches = bf.match(desc_a, desc_b)
|
21 |
-
similar_regions = [i for i in matches if i.distance < 20]
|
22 |
-
if len(matches) == 0:
|
23 |
-
return 0
|
24 |
-
return len(similar_regions) / len(matches)
|
25 |
|
26 |
def load_image_url(source):
|
27 |
Image.MAX_IMAGE_PIXELS = None
|
|
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
14 |
def orb_sim(img1, img2):
|
15 |
+
score = 0
|
16 |
+
|
17 |
+
try:
|
18 |
+
orb = cv2.ORB_create()
|
19 |
+
kp_a, desc_a = orb.detectAndCompute(img1, None)
|
20 |
+
kp_b, desc_b = orb.detectAndCompute(img2, None)
|
21 |
+
|
22 |
+
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
|
23 |
+
matches = bf.match(desc_a, desc_b)
|
24 |
+
similar_regions = [i for i in matches if i.distance < 20]
|
25 |
+
if len(matches) > 0:
|
26 |
+
score = len(similar_regions) / len(matches)
|
27 |
+
except Exception as e:
|
28 |
+
logging.error("Erro ao verificar similaridade ORB", exc_info=True)
|
29 |
+
|
30 |
+
return score
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def load_image_url(source):
|
34 |
Image.MAX_IMAGE_PIXELS = None
|