在比较两个指纹图像时抛出错误
我有一个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_score
是0
,match_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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论