Demo entry 6697596

ЫВ

   

Submitted by anonymous on Jan 24, 2018 at 18:25
Language: Python. Code size: 1.7 kB.

import dlib
import os
from skimage import io
from scipy.spatial import distance
import cv

i=0

sp = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
facerec = dlib.face_recognition_model_v1('dlib_face_recognition_resnet_model_v1.dat')
detector = dlib.get_frontal_face_detector()

#Input foto

capture = cv.CaptureFromCAM(0)
frame = cv.QueryFrame(capture)
cv.SaveImage("input_foto/input.jpg", frame)

input_img = io.imread('input_foto/input.jpg')

win1 = dlib.image_window()
win1.clear_overlay()
win1.set_image(input_img)

dets = detector(input_img, 1)

for k, d in enumerate(dets):
	shape = sp(input_img, d)
	win1.clear_overlay()
    	win1.add_overlay(d)
    	win1.add_overlay(shape)

face_descriptor1 = facerec.compute_face_descriptor(input_img, shape)


#For all foto in users
while True:
	i=i+1;
	img = io.imread('users/user'+str(i)+'.jpg')
	
	win1 = dlib.image_window()
	win1.clear_overlay()
	win1.set_image(img)

	dets = detector(img, 1)

	for k, d in enumerate(dets):
	    shape = sp(img, d)
	    win1.clear_overlay()
	    win1.add_overlay(d)
	    win1.add_overlay(shape)

	face_descriptor2 = facerec.compute_face_descriptor(img, shape)

	a = distance.euclidean(face_descriptor1, face_descriptor2)
	if a<0.6:
		f = open('users_inf/user'+str(i)+'.txt')
		print('=====================')
		print('= Access is allowed =')
		print('=====================')
		print('')
		for line in f:
			print(line)
		print('=====================')
		f.close()
		break;
	if i>4:
		if a>0.6:
			print('=====================')
			print('=== Access denied ===')
			print('=====================')
        	break

os.remove("input_foto/input.jpg")

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).