我为这篇长文提前道歉。
我对亚马逊网络服务的Rekognition和Lambda非常陌生,但我承担了一个项目,使用亚马逊网络服务的S3,Rekognition和Lambda来构建一个面部识别系统。我设法使用AWS JavaScript SDK Documentation中提供的一些Rekognition API获得了一个有效的解决方案,但它只在输入图像中有一张脸时才起作用。我开始尝试处理具有多个面孔的图像,但它没有给出我想要的响应。在做了研究之后,我把我的问题缩小到了以下几个方面:
我需要能够使用indexFaces应用程序接口指定要在具有多个面孔的图像中索引哪些面孔。
注意:我使用的是JavaScript。
对于图像中的单个人脸,我的逻辑是使用allFaces API,然后首先查看是否已将过去的人1的脸索引为‘SearchFacesByImage’。如果我有,那么我不需要再次索引Person 1的面部到'allFaces',但如果我没有,那么我需要首先做这件事。
到目前为止,当我使用只有一张脸的图像作为输入时,一切都很好。(参见下面的代码示例)
问题来了,当我有一个包含多个人脸的图像,包括人1的脸,它会索引图像中的所有脸,包括人1的脸,并将其添加到'allFaces‘集合中,但我想要实现的是系统在哪里拾取人1在过去已经被索引,所以它不应该再次索引人1,而是索引图像中的所有其他人。
这就是我如何改进我的问题,以便能够在包含多个面孔的图像中指定我想要索引的面孔,因为如果我可以做到这一点,那么我可以说Person 1已经被索引,所以继续Person 2。
在indexFaces接口中,您可以指定MaxFaces和QualityFilter参数。我已经看过了,但我不相信它能解决我的解决方案,所以我会远离它,除非它100%地解决了我的问题。
我也不确定我的逻辑是否有问题,或者我的逻辑是否正常,但我对JavaScript知识的缺乏是阻碍我的原因。
这是我到目前为止为图像中的单个人脸所做的工作:
const AWS = require('aws-sdk');
const s3 = new AWS.S3({apiVersion: "2006-03-01"});
const rekognition = new AWS.Rekognition();
//-----------------------------Exports Function-----------------------
exports.handler = function(event, context) {
bucket = event.Records[0].s3.bucket.name;
key = event.Records[0].s3.object.key;
console.log(bucket);
console.log(key);
searchingFacesByImage(bucket, key);
};
//--------------------------------------------------------------------
// Search for a face in an input image
function searchingFacesByImage(bucket, key) {
let params = {
CollectionId: "allFaces",
FaceMatchThreshold: 95,
Image: {
S3Object: {
Bucket: bucket,
Name: key
}
},
MaxFaces: 5
};
const searchingFace = rekognition.searchFacesByImage(params, function(err, searchdata) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
// console.log(JSON.stringify(searchdata, null, '\t'));
// if data.FaceMatches > 0 : There that face in the image exists in the collection
if (searchdata.FaceMatches.length > 0) {
console.log("Face is a match");
// Continue
} else {
console.log("Face is not a match");
console.log("Start indexing face to 'allFaces'");
indexToAllFaces(bucket, key);
}
}
});
return searchingFace;
}
//--------------------------------------------------------------------
// If face is not a match in 'allFaces', index face to 'allFaces' collection
function indexToAllFaces(bucket, key) {
let params = {
CollectionId: "allFaces",
DetectionAttributes: ['ALL'],
Image: {
S3Object: {
Bucket: bucket,
Name: key
}
}
};
const indexFace = rekognition.indexFaces(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
console.log("INDEXING TO 'allFaces'");
console.log(JSON.stringify(data, null, '\t'));
}
});
return indexFace;
}
//--------------------------------------------------------------------就像我说的,当使用只有一张脸的图像时,这很好用,所以这就是为什么我希望添加一些逻辑来过滤具有多张脸的图像中的脸,并且无论谁的脸在过去被索引过,都不应该再被索引。
提前感谢您的反馈。
发布于 2019-08-28 09:12:13
您将需要使用DetectFaces()来获取图像中检测到的所有人脸的列表。
对于返回的每个面:
BoundingBox复制和裁剪图像,因此它只显示给定的Face SearchFacesByImage()确定它是否已经在Face IndexImages()将其添加到Face Collection中。它会将单个面孔添加到集合中。根据经验,将ExternalImageId与添加的每个图像相关联也是一个好主意。这可以包含你自己对脸部的引用,并可以在数据库中使用来存储关于脸部的额外信息(例如id、姓名或他们来自哪个图片)。当在图像中检测到人脸时,会通过cetain调用返回ExternalImageId。
https://stackoverflow.com/questions/57675212
复制相似问题