[英]How to get fingerprints using cv2 in Python?
What would you recommend me in order to get a better fingerprints extraction?为了获得更好的指纹提取,您会推荐我什么? I doesn't look so well.
我看起来不太好。 Thank you.
谢谢你。 Here's my code:
这是我的代码:
import cv2
import numpy as np
img = cv2.imread("huella.jpg")
img = cv2.resize(img, None, fx=0.7, fy=1.0, interpolation=cv2.INTER_AREA)
w, h = img.shape[:2]
fp = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sharp = np.array([[-1, -1, -1, -1, -1], [-1, 2, 2, 2, -1], [-1, 2, 8, 2, -1], [-1, 2, 2, 2, -1], [-1, -1, -1, -1, -1]]) / 8
fp = cv2.filter2D(fp, -1, sharp)
fp = cv2.Canny(fp, 45, 45)
cv2.imshow("Original", img)
cv2.imshow("Huella", fp)
cv2.waitKey(0)
cv2.destroyAllWindows()
You need to use morphological operation.您需要使用形态学操作。
First.第一的。 Try to use
cv2.dilate()
and then cv2.erode()
.尝试使用
cv2.dilate()
然后cv2.erode()
。 This should remove all small and far object.这应该删除所有小的和远的物体。
You can see full documentation here.您可以在此处查看完整文档。
Morphological Transformations 形态变换
The image will lost the information upon dilate and erode, so here is a script to remove small connected component.图像在膨胀和腐蚀时会丢失信息,所以这里有一个删除小连接组件的脚本。 You should change the minSize as your need.
您应该根据需要更改 minSize。
import cv2
import numpy as np
def remove_small_pixel(img, minSize=50):
nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(img, None, None, None, 8, cv2.CV_32S)
sizes = stats[1:, -1] # get CC_STAT_AREA component
img2 = np.zeros(labels.shape, np.uint8)
for i in range(0, nlabels - 1):
if sizes[i] >= minSize: # filter small dotted regions
img2[labels == i + 1] = 255
return img2
Note: This script only available for grayscale image.注意:此脚本仅适用于灰度图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.