Monday, 27 November 2023

Incorrect image matching results despite differences (human fingerprints)

I want to use python to compared two images to check whether they are the same or not, I want to use this for fingerprint functionality in django app to validate whether the provided fingerprint is matches the one stored in the database. I have decided to use OpenCV for this purpose, utilizing ORB_create with detectAndCompute and providing the provided fingerprint to the BFMatcher. However, with the code below, when attempting to match the images, it consistently return True, while the provided images are not the same, along with the print statment "Images are the same".

def compared_fingerprint(image1, image2):

    finger1 = cv2.imread(image1, cv2.IMREAD_GRAYSCALE)
    finger2 = cv2.imread(image2, cv2.IMREAD_GRAYSCALE)

    orb = cv2.ORB_create()

    keypoints1, descriptors1 = orb.detectAndCompute(finger1, None)
    keypoints2, descriptors2 = orb.detectAndCompute(finger2, None)

    bf = cv2.BFMatcher()
    matches = bf.match(descriptors1, descriptors2)
    threshold = 0.7

    similar = len(matches) > threshold * len(keypoints1)

    if similar:
        print('Images are the same')
        return similar
    else:
        print('Images are not the same')
        return similar

result = compared_fingerprint('c.jpg', 'a.jpg')
print(result)

With the provided images, the function supposed to return the second statement, since, they are not the same, I thought, it was the threshold assign to 0.7, and when I increase the threshold to 1.7, it return the second statement saying: "Images are not the same" False, but when I try to make the images to be the same, I mean: result = compared_fingerprint('a.jpg', 'a.jpg'), it's still return "Images are not the same" False.

a.jpg

this is an a image

c.jpg

this is an c image



from Incorrect image matching results despite differences (human fingerprints)

No comments:

Post a Comment