我是AWS的新手,我正在尝试使用Rekognition识别人群中的某些人。我目前正在尝试索引单独个人的图像,但在尝试创建集合时遇到了障碍。当我尝试使用Amazon.Rekognition.Model.S3Object()时,似乎存在数据类型兼容性问题。我提供了以下代码。有没有人有解决方案或更好的方法?谢谢你的时间!
private static void TryIndexFaces()
{
S3Client = new AmazonS3Client();
RekognitionClient = new AmazonRekognitionClient();
IndexFacesRequest indexRequest = new IndexFacesRequest();
Amazon.Rekognition.Model.Image img = new Amazon.Rekognition.Model.Image();
ListObjectsV2Request req = new ListObjectsV2Request();
req.BucketName = "wem0020";
ListObjectsV2Response listObjectsResponse = S3Client.ListObjectsV2(req);
CreateCollectionRequest ccr = new CreateCollectionRequest();
ccr.CollectionId = "TestFaces";
//RekognitionClient.CreateCollection(ccr);
ListVersionsResponse lvr = S3Client.ListVersions(req.BucketName);
string version = lvr.Versions[0].VersionId;
foreach(Amazon.S3.Model.S3Object s3o in listObjectsResponse.S3Objects)
{
Console.WriteLine(s3o.Key);
try
{
if (s3o.Key.EndsWith(".jpg"))
{
Amazon.Rekognition.Model.S3Object reks3o = new Amazon.Rekognition.Model.S3Object();
reks3o.Bucket = req.BucketName;
reks3o.Name = s3o.Key;
Console.WriteLine(version);
reks3o.Version = version;
img.S3Object = reks3o;
indexRequest.Image = img;
indexRequest.CollectionId = ccr.CollectionId;
RekognitionClient.IndexFaces(indexRequest);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
答案 0 :(得分:0)
要索引面部,请使用从aws rekognition返回的边界框值。我已经用完python
widtho = 717 #width of the given image
heighto = 562 #height of the given image
counter = 0
facecount = 1
s3 = boto3.resource('s3')
bucket = s3.Bucket('rek')
if __name__ == "__main__":
#Choosing the file in s3 bucket
photo = 'sl.jpg'
bucket = 'rek'
#Intilization of rekognition and performing detect_faces
client = boto3.client('rekognition', region_name='eu-west-1')
response = client.detect_faces(
Image={'S3Object': {'Bucket': bucket, 'Name': photo}}, Attributes=['ALL'])
print('Detected faces for ' + photo)
print('The faces are detected and labled from left to right')
for faceDetail in response['FaceDetails']:
print('Face Detected= ', i)
#To mark a bounding box of the image using coordinates
print('Bounding Box')
bboxlen = len(faceDetail['BoundingBox'])
print(bboxlen)
width = faceDetail['BoundingBox'].get('Width')
height = faceDetail['BoundingBox'].get('Height')
left = faceDetail['BoundingBox'].get('Left')
top = faceDetail['BoundingBox'].get('Top')
w = int(width * widtho)
h = int(height * heighto)
x = int(left * widtho)
y = int(top * heighto)
cv2.rectangle(imagere, (x, y), (x + w, y + h), (255, 0, 0), 2)
此循环将在单个帧中一张一张地索引脸