MarioPrzBasto commited on
Commit
0773ca1
·
verified ·
1 Parent(s): 4c1d7f9

Update similarity.py

Browse files
Files changed (1) hide show
  1. similarity.py +3 -3
similarity.py CHANGED
@@ -60,13 +60,13 @@ def orb_sim(img1, img2):
60
  matches = bf.match(desc_a, desc_b)
61
  similar_regions = [i for i in matches if i.distance < 20]
62
  if len(matches) > 0:
63
- score = len(similar_regions) / len(matches)
64
  if (score > 0):
65
  logging.info(f"Orb score is {score}")
66
  except Exception as e:
67
  logging.error("Erro ao verificar similaridade ORB", exc_info=True)
68
 
69
- return score
70
 
71
  def ssim_sim(img1, img2):
72
  s, _ = ssim(img1, img2, full=True)
@@ -102,7 +102,7 @@ def check_similarity(images: List[RequestModel]):
102
  image = cv2.resize(image, original_image_shape[::-1])
103
 
104
  similarity_score = ssim_sim(original_image, image)
105
- similarity_orb_score = orb_sim(original_image, image) * 100
106
  similarity_mobilenet_score = mobilenet_sim(original_image, image)
107
  except Exception as e:
108
  logging.error(f"Error loading image for resource id {images[i].originId} : {e}")
 
60
  matches = bf.match(desc_a, desc_b)
61
  similar_regions = [i for i in matches if i.distance < 20]
62
  if len(matches) > 0:
63
+ score = (len(similar_regions) / len(matches)) * 100
64
  if (score > 0):
65
  logging.info(f"Orb score is {score}")
66
  except Exception as e:
67
  logging.error("Erro ao verificar similaridade ORB", exc_info=True)
68
 
69
+ return round(score) if 0 < score < 1 else score
70
 
71
  def ssim_sim(img1, img2):
72
  s, _ = ssim(img1, img2, full=True)
 
102
  image = cv2.resize(image, original_image_shape[::-1])
103
 
104
  similarity_score = ssim_sim(original_image, image)
105
+ similarity_orb_score = orb_sim(original_image, image)
106
  similarity_mobilenet_score = mobilenet_sim(original_image, image)
107
  except Exception as e:
108
  logging.error(f"Error loading image for resource id {images[i].originId} : {e}")