def autenticacao(request): if request.method == "POST": try: uploaded_file = request.FILES['biometry'] fs = FileSystemStorage() fs.save("fingerprint.png", uploaded_file) except: return redirect('home/') global username username = request.POST['username'] try: Users.objects.filter(username=username).first().username print("Username cadastrado no BD") try: print('Analisando o fingerprint recebido') img = cv2.imread('./upload/fingerprint.png', 0) # read input image out = fingerprint_enhancer.enhance_Fingerprint( img) # enhance the fingerprint image print('Analisando o fingerprint cadastrado no BD') img2 = cv2.imread('./upload/' + Users.objects.filter( username=username).first().biometry.name, 0) # read input image out2 = fingerprint_enhancer.enhance_Fingerprint( img2) # enhance the fingerprint image result = out == out2 try: global autenticado if result.all() == True: autenticado = True print("Autenticado!") fs.delete("fingerprint.png") return redirect('home/') except: if result == False: autenticado = False print("Falha na autenticação!") fs.delete("fingerprint.png") return redirect('home/') except: print("Obtivemos um erro ao analisarmos a fingerprint recebida. Por favor, verifique se a fingerprint está no formato JPEG, JPG ou PNG.") fs.delete("fingerprint.png") return redirect('home/') except: print("Usuario não cadastrado no BD") fs.delete("fingerprint.png") return redirect('home/') return render(request, 'auth/src/auth.html')
def get_descriptors(img): clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) img = clahe.apply(img) img = fingerprint_enhancer.enhance_Fingerprint(img) img = numpy.array(img, dtype=numpy.uint8) # Threshold (identify the white black pixel by near method and convert in white or black absolute) ret, img = cv2.threshold( img, 127, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU) # Normalize to 0 and 1 range img[img == 255] = 1 # 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 = _FRONTIER # 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 T_generator(img): X = [] Y = [] R = [] T = [] enhanced_img = enh.enhance_Fingerprint(img) features_terminations, features_bifurcations = ext.extract_minutiae_features( enhanced_img, showResult=False) for termination in features_terminations: X.append(termination.locX) Y.append(termination.locY) for bifurcation in features_bifurcations: X.append(bifurcation.locX) Y.append(bifurcation.locY) n = len(Y) for i in range(0, 64): R.append(randint(0, 2 * (n - 1))) for r in R: if r < n: T.append((X[r] % 256) - 128) else: T.append((Y[r - n] % 256) - 128) return T
import cv2 import fingerprint_enhancer import os import tqdm images = os.listdir('./data/light_data/dataset/train_data') i = False for image_name in tqdm.tqdm(images): img = cv2.imread('./data/light_data/dataset/train_data/' + image_name, 0) try: out = fingerprint_enhancer.enhance_Fingerprint(img) cv2.imwrite('./data/enhanced/light_data_enhanced/' + image_name, out) except: pass
def enhance_and_binarize(img): enhanced_img = fingerprint_enhancer.enhance_Fingerprint(img) _, binarized_enhanced_img = cv2.threshold( enhanced_img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) return binarized_enhanced_img