Esempio n. 1
0
def findsim():
    # GET方法请求
    if request.method == 'GET':
        # 获取参数,从json文件中获取图片
        data = request.args.get('name')
        name = json.loads(data)
        name = name['name']

        # 进行人脸的匹配
        name, ret, sim = compare_feature(name, vgg_net, feature)

        if ret == 2:  # 匹配成功,返回结果
            result = name + ',' + str(sim[0][0])
            print(result)
            return result

        elif ret == 0:  # 人脸识别失败,需要重新上传清晰照片
            return 'pickfail'

        else:  # 数据库中没有找到匹配的人脸
            return 'findfail'
    else:
        data = request.form.get('name')
        name = json.loads(data)
        name = name['name']
        # 进行人脸的匹配
        name, ret, sim = compare_feature(name, vgg_net, feature)
        if ret == 2:  # 匹配成功,返回结果
            result = name + ',' + str(sim[0][0])
            print(result)
            return result
        elif ret == 0:  # 人脸识别失败,需要重新上传清晰照片
            return 'pickfail'
        else:  # 数据库中没有找到匹配的人脸
            return 'findfail'
Esempio n. 2
0
def findsim():
    if request.method == 'POST':
        name = request.form['name']
        name, sim = compare_feature(name, vgg_net, feature)
        result = name + ',' + str(sim[0][0])
        print(result)
        return result
    else:
        return 'method is not right'
Esempio n. 3
0
import socket
from numpy import loadtxt
from face_recognition import compare_feature
import torch
from torch.legacy import nn

VGG_FACE_LOCATION = 'D://vgg.pkl'
FEATURE_LOCATION = 'D:\\feature\\feature.dat'

s = socket.socket()
host = socket.gethostname()
port = 12345
s.bind((host, port))

vgg_net = torch.load(VGG_FACE_LOCATION)
vgg_net.modules[31] = nn.View(1, 25088)
feature = loadtxt(FEATURE_LOCATION)

s.listen(5)
while True:
    c, addr = s.accept()
    fileName = str(c.recv(1024), 'gbk')
    name, sim = compare_feature(fileName, vgg_net, feature)
    result = name + ',' + str(sim[0][0])
    c.send(bytes(result, 'gbk'))
    c.close()
Esempio n. 4
0
from face_recognition import compare_feature, get_image
from sys import argv

if __name__ == '__mian__':
    script, fileName = argv
    name, sim = compare_feature(fileName)
    img = get_image(name)
    print(img, ',', sim[0][0])