在比较两个指纹图像时抛出错误

发布于 2025-02-05 20:27:26 字数 2034 浏览 0 评论 0原文

我有一个python函数,旨在比较

import os
import cv2


def isIdentical():
    best_score = 0
    filename = None
    image = None
    kp1, kp2, mp = None, None, None

    finger_print_one = cv2.imread("compare/image1.jpg")
    finger_print_two = cv2.imread("compare/image2.jpg")

    resized_1 = cv2.resize(finger_print_one, None, fx=4, fy=4)
    resized_2 = cv2.resize(finger_print_two, None, fx=4, fy=4)

    sift = cv2.SIFT_create()

    keypoints_1, descriptors_1 = sift.detectAndCompute(resized_1, None)
    keypoints_2, descriptors_2 = sift.detectAndCompute(resized_2, None)

    matches = cv2.FlannBasedMatcher({'algorithm': 1, 'trees': 10}, {}).knnMatch(descriptors_1, descriptors_2, k=2)
    match_points = []

    for p, q in matches:
        if p.distance < 0.1 * q.distance:
            match_points.append(p)

    keypoints = 0

    if len(keypoints_1) < len(keypoints_2):
        keypoints = len(keypoints_1)
    else:
        keypoints = len(keypoints_2)

    if len(match_points) / keypoints * 100 > best_score:
        best_score = len(match_points) / keypoints * 100
        image = resized_2
        kp1, kp2, mp = keypoints_1, keypoints_2, match_points

    print("SCORE: " + str(best_score))
    if len(match_points) > 0:
        result = cv2.drawMatches(resized_1, kp1, image, kp2, mp, None)
        result = cv2.resize(result, None, fx=4, fy=4)
        cv2.imshow("Result", result)
        cv2.waitKey(0)
        cv2.destroyAllWindows()


#
# one = ""
isIdentical()

当图像相同时比较这样的两个指纹图像,函数返回a best_score of 100,但是当它们是相同指纹的不同图像时, best_score 是0,match_points数组是

finger_print_one = cv2.imread("compare/image1.jpg")
finger_print_two = cv2.imread("compare/image1.jpg")

代码>

finger_print_one = cv2.imread("compare/image1.jpg")
finger_print_two = cv2.imread("compare/image2.jpg")

best_score0match_points是空的,

我缺少什么吗?

i have a python function that is meant to compare two fingerprint images like this

import os
import cv2


def isIdentical():
    best_score = 0
    filename = None
    image = None
    kp1, kp2, mp = None, None, None

    finger_print_one = cv2.imread("compare/image1.jpg")
    finger_print_two = cv2.imread("compare/image2.jpg")

    resized_1 = cv2.resize(finger_print_one, None, fx=4, fy=4)
    resized_2 = cv2.resize(finger_print_two, None, fx=4, fy=4)

    sift = cv2.SIFT_create()

    keypoints_1, descriptors_1 = sift.detectAndCompute(resized_1, None)
    keypoints_2, descriptors_2 = sift.detectAndCompute(resized_2, None)

    matches = cv2.FlannBasedMatcher({'algorithm': 1, 'trees': 10}, {}).knnMatch(descriptors_1, descriptors_2, k=2)
    match_points = []

    for p, q in matches:
        if p.distance < 0.1 * q.distance:
            match_points.append(p)

    keypoints = 0

    if len(keypoints_1) < len(keypoints_2):
        keypoints = len(keypoints_1)
    else:
        keypoints = len(keypoints_2)

    if len(match_points) / keypoints * 100 > best_score:
        best_score = len(match_points) / keypoints * 100
        image = resized_2
        kp1, kp2, mp = keypoints_1, keypoints_2, match_points

    print("SCORE: " + str(best_score))
    if len(match_points) > 0:
        result = cv2.drawMatches(resized_1, kp1, image, kp2, mp, None)
        result = cv2.resize(result, None, fx=4, fy=4)
        cv2.imshow("Result", result)
        cv2.waitKey(0)
        cv2.destroyAllWindows()


#
# one = ""
isIdentical()

when the images are the same, the functions returns a best_score of 100, but when they are different images of the same fingerprint, the best_score is 0 and the match_points array is empty

for example when the inputs are like this

finger_print_one = cv2.imread("compare/image1.jpg")
finger_print_two = cv2.imread("compare/image1.jpg")

the best_score is 100

but for

finger_print_one = cv2.imread("compare/image1.jpg")
finger_print_two = cv2.imread("compare/image2.jpg")

the best_score is 0 and the match_points is empty

is there anything i am missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文