我是靠谱客的博主 勤劳楼房,这篇文章主要介绍人脸识别后处理流程代码人脸注册人脸加载人脸比对人脸识别应用,现在分享给大家,希望可以做个参考。

文章目录

  • 人脸注册
  • 人脸加载
  • 人脸比对
  • 人脸识别
  • 应用

人脸注册

tom = [...]  # (1, 128)
jack = [...]  # (1, 128)

np.savez('faces.npz', tom=tom, jack=jack)

人脸加载

def load_embeddings(path):
    arrs = np.load(path)
    names, embeddings = [], []
    for name, embedding in arrs.items():
        names.append(name)
        embeddings.append(embedding)
    embeddings = np.vstack(embeddings)
    return np.array(names), embeddings

人脸比对

def compare(embedding, embeddings):  # face: (1, 128), embeddings: (None, 128)
	# Euclidean distance
    return np.sqrt(np.sum(((embeddings - embedding) ** 2), axis=1))

人脸识别

def recognize(embedding, embeddings, names):
    result = compare(embedding, embeddings)
    index = np.argsort(result)[::-1]
    score = result[index][0]
    if  score < 1.1:
        return names[index][0], score
    else:
        return 'unknown', score

应用

names, embeddings = load_embeddings('faces.npz')
while 1:
	faces = [...]
	for face in faces:
		embedding = [...]
		name = recognize(embedding, embeddings, names)

最后

以上就是勤劳楼房最近收集整理的关于人脸识别后处理流程代码人脸注册人脸加载人脸比对人脸识别应用的全部内容,更多相关人脸识别后处理流程代码人脸注册人脸加载人脸比对人脸识别应用内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(596)

评论列表共有 0 条评论

立即
投稿
返回
顶部