Amazon Rekognition
links:
- python api for rekognition https://boto3.readthedocs.io/en/latest/reference/services/rekognition.html#client
- api reference general http://docs.aws.amazon.com/rekognition/latest/dg/API_ListFaces.html
- command line http://docs.aws.amazon.com/cli/latest/reference/rekognition/index.html#cli-aws-rekognition
- cli and java sdk examples http://docs.aws.amazon.com/rekognition/latest/dg/get-started-exercise-compare-faces.html
a nice project with raspberry pi and iot
https://softwaremill.com/access-control-system-with-rfid-and-amazon-rekognition/
Concepts
Access control
In Amazon Rekognition, the primary resource is a collection. In a policy, you use an Amazon Resource Name (ARN) to identify the resource that the policy applies to.
arn:aws:rekognition:region:account-id:collection/collection-id
- In this page http://docs.aws.amazon.com/rekognition/latest/dg/using-identity-based-policies.html you can find read only or read write or full access permission for rekognition
- in this page the list of api and permissions necessary to use them http://docs.aws.amazon.com/rekognition/latest/dg/api-permissions-reference.html
CLI
A working examples of face rekognition steps:
- Upgrade the cli because if you installed before 13 december 2016 you don't have the necessary permissions
- upload some different pictures on a S3 bucket
- Create a collection and list to see if exist
- load some images in the collection with the index faces command , if it detect a face you will have back "FaceId", "Confidence", "ImageId". It is possible have more faces in the same image. You need to store at least the faceid in your database so you have a corrispondence between faceid and name of the person
- load a new image with a face that you don't know the name, run the search-faces action in your collection to find the association in your database
probably you need to upgrade the cli
pip install --upgrade --user awscli
actions
aws rekognition list-collections
{
"CollectionIds": []
}
aws rekognition --region eu-west-1 create-collection --collection-id test123bla
{
"CollectionArn": "aws:rekognition:eu-west-1:accountid:collection/test123bla",
"StatusCode": 200
}
aws rekognition list-collections --region eu-west-1
{
"CollectionIds": [
"test123bla"
]
}
failed and working face image indexing
#failed
aws rekognition --region eu-west-1 index-faces --collection-id test123bla --image '{"S3Object":{"Bucket":"testreko","Name":"database/10268467_10205511436048230_7814163286698537495_n.jpg"}}'
{
"FaceRecords": [],
"OrientationCorrection": "ROTATE_0"
}
#working , it found two faces
aws rekognition --region eu-west-1 index-faces --collection-id test123bla --image '{"S3Object":{"Bucket":"testreko","Name":"database/10352329_10205082867050562_2000141568158191576_n.jpg"}}'
{
"FaceRecords": [
{
"FaceDetail": {
"BoundingBox": {
"Width": 0.42820513248443604,
"Top": 0.18803419172763824,
"Left": 0.4435897469520569,
"Height": 0.5709401965141296
},
"Landmarks": [
{
"Y": 0.4098227918148041,
"X": 0.5927227139472961,
"Type": "eyeLeft"
},
{
"Y": 0.42729148268699646,
"X": 0.7383217215538025,
"Type": "eyeRight"
},
{
"Y": 0.5350412130355835,
"X": 0.6591365337371826,
"Type": "nose"
},
{
"Y": 0.5856460332870483,
"X": 0.5787419080734253,
"Type": "mouthLeft"
},
{
"Y": 0.6144521832466125,
"X": 0.718766450881958,
"Type": "mouthRight"
}
],
"Pose": {
"Yaw": 3.8756542205810547,
"Roll": 4.612514019012451,
"Pitch": -6.215380668640137
},
"Quality": {
"Sharpness": 99.99671173095703,
"Brightness": 54.21664047241211
},
"Confidence": 99.99958801269531
},
"Face": {
"BoundingBox": {
"Width": 0.42820513248443604,
"Top": 0.18803419172763824,
"Left": 0.4435897469520569,
"Height": 0.5709401965141296
},
"FaceId": "d8beeb37-209b-5d6e-9a54-329c4d06dc3e",
"Confidence": 99.99958801269531,
"ImageId": "6182cf1b-adbd-5056-a1cf-05d800f48766"
}
},
{
"FaceDetail": {
"BoundingBox": {
"Width": 0.3717948794364929,
"Top": 0.11965811997652054,
"Left": 0.17179487645626068,
"Height": 0.49572649598121643
},
"Landmarks": [
{
"Y": 0.3520870506763458,
"X": 0.271046906709671,
"Type": "eyeLeft"
},
{
"Y": 0.27331531047821045,
"X": 0.3906380534172058,
"Type": "eyeRight"
},
{
"Y": 0.4130267798900604,
"X": 0.3769768476486206,
"Type": "nose"
},
{
"Y": 0.5067362189292908,
"X": 0.33903148770332336,
"Type": "mouthLeft"
},
{
"Y": 0.4303989112377167,
"X": 0.45189225673675537,
"Type": "mouthRight"
}
],
"Pose": {
"Yaw": 3.106931686401367,
"Roll": -27.121381759643555,
"Pitch": -1.3480712175369263
},
"Quality": {
"Sharpness": 99.9945297241211,
"Brightness": 40.77513122558594
},
"Confidence": 99.99991607666016
},
"Face": {
"BoundingBox": {
"Width": 0.3717948794364929,
"Top": 0.11965811997652054,
"Left": 0.17179487645626068,
"Height": 0.49572649598121643
},
"FaceId": "f58b49ee-e457-579c-abbf-6a12233661a8",
"Confidence": 99.99991607666016,
"ImageId": "6182cf1b-adbd-5056-a1cf-05d800f48766"
}
}
],
"OrientationCorrection": "ROTATE_0"
}
aws rekognition --region eu-west-1 search-faces --collection-id test123bla --face-id "8e658cd2-e180-5576-9360-aab4c3a8384a"
{
"SearchedFaceId": "8e658cd2-e180-5576-9360-aab4c3a8384a",
"FaceMatches": [
{
"Face": {
"BoundingBox": {
"Width": 0.37179499864578247,
"Top": 0.11965800076723099,
"Left": 0.17179499566555023,
"Height": 0.49572598934173584
},
"FaceId": "f58b49ee-e457-579c-abbf-6a12233661a8",
"Confidence": 99.9999008178711,
"ImageId": "6182cf1b-adbd-5056-a1cf-05d800f48766"
},
"Similarity": 94.75210571289062
}
]
}
Compare faces without collection
aws rekognition compare-faces --source-image '{"S3Object":{"Bucket":"testreko","Name":"reko/ritagliogoogle.png"}}' --target-image '{"S3Object":{"Bucket":"testreko","Name":"database/429133_3469569657208_1127214741_n(1).jpg"}}' --region eu-west-1
{
"FaceMatches": [
{
"Face": {
"BoundingBox": {
"Width": 0.7692307829856873,
"Top": 0.19711539149284363,
"Left": 0.17307692766189575,
"Height": 0.7692307829856873
},
"Confidence": 99.99598693847656
},
"Similarity": 86.0
}
],
"SourceImageFace": {
"BoundingBox": {
"Width": 0.8674304485321045,
"Top": 0.1717352420091629,
"Left": 0.09819967299699783,
"Height": 0.7549194693565369
},
"Confidence": 100.0
}
}
versione della pagina: 8, ultima modifica: 16 Jun 2017 21:05