【发布时间】:2018-03-25 18:50:50
【问题描述】:
我已经在 S3 上使用 php 上传了图像,现在我想比较/匹配我的 S3 集合中的给定图像,我用谷歌搜索但没有得到答案,如果可以使用 AWS 面部识别使用 PHP 在 S3 集合中搜索。
【问题讨论】:
标签: amazon-s3 amazon-ec2 aws-sdk aws-php-sdk
我已经在 S3 上使用 php 上传了图像,现在我想比较/匹配我的 S3 集合中的给定图像,我用谷歌搜索但没有得到答案,如果可以使用 AWS 面部识别使用 PHP 在 S3 集合中搜索。
【问题讨论】:
标签: amazon-s3 amazon-ec2 aws-sdk aws-php-sdk
@Madhukar 的回答是正确的,但是您需要多一步来搜索 s3 存储桶。您需要像这样索引桶中的人脸:
$result = $rekog->indexFaces([
'CollectionId' => '<string>', // REQUIRED
'ExternalImageId' => <string>, //This is important to know what image the face is in (I use the s3 key)
'Image' => [
'S3Object' => [
'Bucket' => '<string>',
'Name' => <string>,
],
],
]);
您需要对集合中的每张图片执行此操作
【讨论】:
使用compareFaces APi 比较存储在 S3 中的两个图像中的人脸。 保留一张图像作为源图像并在迭代中传递目标图像。
API:
<?php
require 'vendor/autoload.php';
use Aws\Rekognition\RekognitionClient;
$options = [
'region' => 'us-east-1',
'version' => '2016-06-27',
];
$client = new RekognitionClient($options);
$result = $client->compareFaces([
'SimilarityThreshold' => <float>,
'SourceImage' => [
'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
'S3Object' => [
'Bucket' => '<string>',
'Name' => '<string>',
'Version' => '<string>',
],
],
'TargetImage' => [
'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
'S3Object' => [
'Bucket' => '<string>',
'Name' => '<string>',
'Version' => '<string>',
],
],
]);
?>
如果你想在一个集合中搜索(假设你已经使用 CreateCollection API 创建了一个并且已经在其中索引了人脸),那么你可以使用searchFacesByImage API。只需提供目标 collection-id(其中索引了多个图像)以及 源图像的 s3 位置。响应将包含所有匹配的人脸,按相似度得分排序。
API:
$result = $client->searchFacesByImage([
'CollectionId' => '<string>',
'FaceMatchThreshold' => <float>,
'Image' => [
'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
'S3Object' => [
'Bucket' => '<string>',
'Name' => '<string>',
'Version' => '<string>',
],
],
'MaxFaces' => <integer>,
]);
【讨论】:
$response = $s3->putObject(array( 'CollectionId' => 'visitor-collection', 'Bucket' => 's3-visitor', 'Key' => 'visitors/'.$input[' imageId'], 'SourceFile' => public_path('images/attachments/').$input['imageId'], )); $s3Id = $response['ObjectURL'];返回 $s3Id;
感谢@Madhukar,您的建议对我比较 S3 中的 2 张图像很有用,而要在集合中搜索,我必须添加 Chris 的建议。谢谢@克里斯。只有我的问题是我在 laravel 中做,所以我必须以 Laravel 风格做,但核心是你的所有建议。再次感谢你们俩。如果有人想要 laravel 编码,请告诉我,如果我能提供帮助。
【讨论】: