提取,比较和匹配指纹细节的有效方法

时间:2019-06-17 07:14:31

标签: python-3.x image-processing fingerprint

我目前正在开发一个程序,该程序可以检测和匹配指纹,并将其作为指纹传感器的一部分。处理完图像后,我使用哈里斯角点检测获取关键点。然后,使用ORB特征提取器,获得数组形式的描述符。

问题是同一指纹的两个不同图像获得的关键点数量不同。因此,获得的描述符数组的大小也不同。

现在,我已经使用汉明距离来测量两个图像的描述符数组之间的差异,从而测量了指纹本身之间的差异。但是,由于阵列大小不同,我发现很难为所有指纹设置阈值。

def get_descriptors(img):
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
img = clahe.apply(img)
img = image_enhance.image_enhance(img) #for image-processing
img = numpy.array(img, dtype=numpy.uint8)

# Threshold
ret, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
# Normalize to 0 and 1 range
img[img == 255] = 1

#Thinning
skeleton = skeletonize(img)
skeleton = numpy.array(skeleton, dtype=numpy.uint8)
skeleton = removedot(skeleton)
# Harris corners
harris_corners = cv2.cornerHarris(img, 3, 3, 0.04)
harris_normalized = cv2.normalize(harris_corners, 0, 255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32FC1)
threshold_harris = 125
# Extract keypoints
keypoints = []
for x in range(0, harris_normalized.shape[0]):
    for y in range(0, harris_normalized.shape[1]):
        if harris_normalized[x][y] > threshold_harris:
            keypoints.append(cv2.KeyPoint(y, x, 1))
# Define descriptor
orb = cv2.ORB_create()
# Compute descriptors
_, des = orb.compute(img, keypoints)

return (keypoints, des);

def main():

img1 = cv2.imread("C:/Users/Nimesh Shahdadpuri/Desktop/DMRC Intern/database/106_1.tif" , cv2.IMREAD_GRAYSCALE)

kp1, des1 = get_descriptors(img1)

#print (des1)   
#print (des1.shape)
img2 = cv2.imread("C:/Users/Nimesh Shahdadpuri/Desktop/DMRC Intern/database/106_2.tif" , cv2.IMREAD_GRAYSCALE)
kp2, des2 = get_descriptors(img2)
#print (des2)

# Matching between descriptors
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches= bf.match(des1,des2)
matches = sorted(matches, key= lambda match:match.distance)
#print (len(matches))
# Plot keypoints
img4 = cv2.drawKeypoints(img1, kp1, outImage=None)
img5 = cv2.drawKeypoints(img2, kp2, outImage=None)
#f, axarr = plt.subplots(1,2)
print ("First Fingerprint")
#axarr[0].imshow(img4) 
plt.imshow(img4)
plt.show()
print ("Second Fingerprint")
#axarr[1].imshow(img5)
plt.imshow(img5)
plt.show()
# Plot matches
img3 = cv2.drawMatches(img1, kp1, img2, kp2, matches, flags=2, outImg=None)
print ("All the matching points and the corresponding distances")
plt.imshow(img3)
plt.show()

# Calculate score
score = 0
for match in matches:
    score += match.distance
score_threshold = 40
matchper= score/len(matches)
print(matchper)     

if  matchper < score_threshold:
    print("Fingerprint matches.")
else:
    print("Fingerprint does not match.")

我希望为所有指纹定义通用阈值的有效方法。我还想提出一种替代方法来定义和匹配关键点。

0 个答案:

没有答案
相关问题