我有一行包含Oracle中的人的姓名和照片,如何进行人脸识别,使其只能通过相机拍照来识别姓名??我可以使用哪些技术?
发布于 2020-09-16 20:11:48
首先,不要将原始图像存储在blob列中。你应该存储原始图像的向量表示。下面的python代码块将找到人脸图像的向量表示。
#!pip install deepface
from deepface.basemodels import VGGFace, Facenet
model = VGGFace.loadModel() #you can use google facenet instead of vgg
target_size = model.layers[0].input_shape
#preprocess detects facial area and aligns it
img = functions.preprocess_face(img="img.jpg", target_size=target_size)
representation = model.predict(img)[0,:]
在这里,您可以传递精确的图像路径,如img.jpg,也可以将3D数组传递给preprocess_face的img参数。这样,您就可以将矢量表示存储在oracle数据库的blob列中。
当你有一个新的人脸图像,并且想要在数据库中找到它的身份时,再次找到它的表示。
#preprocess detects facial area and aligns it
target_img = functions.preprocess_face(img="target.jpg", target_size=target_size)
target_representation = model.predict(target_img )[0,:]
现在,您有了目标图像的向量表示和数据库图像的向量表示。您需要找到目标图像表示和数据库表示的每个实例的相似度得分。
欧几里德距离是比较向量的最简单方法。
def findEuclideanDistance(source_representation, test_representation):
euclidean_distance = source_representation - test_representation
euclidean_distance = np.sum(np.multiply(euclidean_distance, euclidean_distance))
euclidean_distance = np.sqrt(euclidean_distance)
return euclidean_distance
我们将每个数据库实例与目标进行比较。假设数据库实例的表示存储在表示对象中。
distances = []
for i in range(0, len(representations)):
source_representation = representations[i]
#find the distance between target_representation and source_representation
distance = findEuclideanDistance(source_representation, target_representation )
distances.append(distance)
距离列表存储数据库中每个项目到目标的距离。我们需要找到最短的距离。
import numpy as np
idx = np.argmax(distances)
Idx是数据库中目标镜像的id。
https://stackoverflow.com/questions/63903017
复制相似问题