首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用blob oracle进行人脸识别

如何使用blob oracle进行人脸识别
EN

Stack Overflow用户
提问于 2020-09-15 21:33:26
回答 1查看 147关注 0票数 0

我有一行包含Oracle中的人的姓名和照片,如何进行人脸识别,使其只能通过相机拍照来识别姓名??我可以使用哪些技术?

EN

回答 1

Stack Overflow用户

发布于 2020-09-16 20:11:48

首先,不要将原始图像存储在blob列中。你应该存储原始图像的向量表示。下面的python代码块将找到人脸图像的向量表示。

代码语言:javascript
运行
复制
#!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列中。

当你有一个新的人脸图像,并且想要在数据库中找到它的身份时,再次找到它的表示。

代码语言:javascript
运行
复制
#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,:]

现在,您有了目标图像的向量表示和数据库图像的向量表示。您需要找到目标图像表示和数据库表示的每个实例的相似度得分。

欧几里德距离是比较向量的最简单方法。

代码语言:javascript
运行
复制
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

我们将每个数据库实例与目标进行比较。假设数据库实例的表示存储在表示对象中。

代码语言:javascript
运行
复制
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)

距离列表存储数据库中每个项目到目标的距离。我们需要找到最短的距离。

代码语言:javascript
运行
复制
import numpy as np
idx = np.argmax(distances)

Idx是数据库中目标镜像的id。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63903017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档