Image Similarity

I am using this function to calculate the similarity between two images.

from skimage.metrics import structural_similarity
import cv2

#Works well with images of different dimensions
def orb_sim(img1, img2):
  # SIFT is no longer available in cv2 so using ORB
  orb = cv2.ORB_create()

  # detect keypoints and descriptors
  kp_a, desc_a = orb.detectAndCompute(img1, None)
  kp_b, desc_b = orb.detectAndCompute(img2, None)

  # define the bruteforce matcher object
  bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
  #perform matches. 
  matches = bf.match(desc_a, desc_b)
  #Look for similar regions with distance < 75. Goes from 0 to 100 so pick a number between.
  similar_regions = [i for i in matches if i.distance < 50]  
  if len(matches) == 0:
    return 0
  return len(similar_regions) / len(matches)

orb_similarity = orb_sim(img00, img01)  #1.0 means identical. Lower = not similar
print("Similarity using ORB is: ", orb_similarity)

I am somehow getting an orb of 0.0 (no correlation). Anyone know what I’m doing wrong?



the whole idea is proven not to work.
feature matching is to find a homography between different views of the same scene, not to find “similarity” between different images.

that statement is questionable.

that’s a distance in feature space. that’s a high-dimensional space of whatever the descriptors are made of. neither the dimension nor absolute scales have much meaning there.

a random number such as 50, 75, or 100 is bound to be meaningless.

so, @Tito_Rod – how many bits does an ORB descriptor hold ?