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()
. This should remove all small and far object.
You can see full documentation here.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.