Тестовые запросы¶
Перед тем как приступить к программированию и использованию распознавания лиц в своем приложении, убедитесь, что компоненты Сервера FindFace работают надлежащим образом. Для этого выполните по порядку приведенные ниже тестовые запросы. Для того чтобы структурировать текст ответов на запросы, используйте обработчик JSON jq.
Примечание
Сообщения запросов приведены в качестве примера. Вам потребуется заменить токен авторизации в запросах на актуальный.
Совет
Вы можете найти примеры кода на C#, PHP, Java и Python на нашем ресурсе GitHub.
In this section:
Структурирование ответов на запросы¶
Use jq to parse JSON data in responses. To install jq, execute:
sudo apt-get install jq
Получение списка галерей¶
Данный запрос возвращает имя единственной на данный момент галереи (создана по умолчанию). Соответствующий метод REST API: /galleries GET.
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" http://localhost:8000/v0/galleries | jq
Ответ
{
"results": [
"default"
]
}
Создание галереи¶
Данный запрос создает новую галерею testgal
. Соответствующий метод REST API: /galleries/new POST.
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -X POST http://localhost:8000/v0/galleries/testgal | jq
Ответ
{
"name": "testgal"
}
Обнаружение лица на фотографии¶
Данный запрос обнаруживает лицо на тестовом изображении, размещенном в сети Интернет, и возвращает координаты рамки вокруг лица (bbox). Соответствующий метод REST API: /detect POST.
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F "photo=http://static.findface.pro/sample.jpg" http://localhost:8000/v0/detect | jq
Ответ
{
"faces": [
{
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
],
"orientation": 1
}
Добавление лица в галерею¶
This request processes the same sample image as in the previous request, detects a face and adds the detected face to the default gallery with a unique meta tag. Relevant REST API method: /face POST.
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F "photo=http://static.findface.pro/sample.jpg" -F "meta=Sam Berry" http://localhost:8000/v0/face | jq
Ответ
{
"results": [
{
"friend": false,
"galleries": [
"default"
],
"id": 3827229391220303,
"meta": "Sam Berry",
"normalized": "http://192.168.113.88:3333/uploads//20170517/1495011480937809.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170517/14950114809306293.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170517/149501148093593.jpeg",
"timestamp": "2017-05-17T08:58:00.930572",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
]
}
The following request also adds a face to a gallery but this time the face is extracted from a local image, and the gallery is custom (‘testgal’).
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F "photo=@sample.jpg" -F "meta=sample" -F "galleries=testgal" http://localhost:8000/v0/face | jq
Ответ
{
"results": [
{
"friend": false,
"galleries": [
"default",
"testgal"
],
"id": 3827229578000564,
"meta": "sample",
"normalized": "http://192.168.113.88:3333/uploads//20170517/14950115538997407.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170517/14950115538939695.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170517/14950115538985784.jpeg",
"timestamp": "2017-05-17T08:59:13.893921",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
]
}
Поиск лица в галерее¶
The following 2 requests process an image on the Internet (#1) and a local image (#2), detect a face and compare it with those from the default gallery. Return data of most similar faces and their similarity index. Relevant REST API method: /identify POST.
Запрос №1
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F "photo=http://static.findface.pro/sample2.jpg" http://localhost:8000/v0/identify | jq
Ответ
{
"results": {
"[515, 121, 821, 427]": [
{
"confidence": 0.9373,
"face": {
"age": 26.0483455657959,
"emotions": [
"neutral",
"sad"
],
"friend": false,
"galleries": [
"default"
],
"gender": "female",
"id": 3827062458772442,
"meta": "Sam Berry",
"normalized": "http://192.168.113.88:3333/uploads//20170516/1494946272949371.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170516/14949462729435823.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170516/14949462729480093.jpeg",
"timestamp": "2017-05-16T14:51:12.943000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
}
]
}
}
Запрос №2
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F "photo=@Pictures/sample.jpg" http://localhost:8000/v0/identify | jq
Ответ
{
"results": {
"[595, 127, 812, 344]": [
{
"confidence": 0.9999,
"face": {
"age": 26.0483455657959,
"emotions": [
"neutral",
"sad"
],
"friend": false,
"galleries": [
"default"
],
"gender": "female",
"id": 3827062458772442,
"meta": "Sam Berry",
"normalized": "http://192.168.113.88:3333/uploads//20170516/1494946272949371.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170516/14949462729435823.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170516/14949462729480093.jpeg",
"timestamp": "2017-05-16T14:51:12.943000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
}
]
}
}
Сравнение двух лиц¶
This request compares a face in a local image and that on the Internet. Relevant REST API method: /verify POST.
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F "photo1=@Pictures/sample.jpg" -F "photo2=http://static.findface.pro/sample2.jpg" http://localhost:8000/v0/verify | jq
Ответ
{
"results": [
{
"bbox1": {
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
},
"bbox2": {
"x1": 515,
"x2": 821,
"y1": 121,
"y2": 427
},
"confidence": 0.9373794198036194,
"verified": true
}
],
"verified": true
}
Получение списка лиц в галереях¶
The following requests return the list of all faces stored in galleries, both default and custom (#1), and only custom (#2). Relevant REST API method: /faces GET.
Запрос №1
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" http://localhost:8000/v0/faces | jq
Ответ
{
"next_page": "/v0/faces?max_id=3827058103081960",
"prev_page": null,
"results": [
{
"friend": false,
"galleries": [
"default",
"testgal"
],
"id": 3827229578000564,
"meta": "sample",
"normalized": "http://192.168.113.88:3333/uploads//20170517/14950115538997407.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170517/14950115538939695.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170517/14950115538985784.jpeg",
"timestamp": "2017-05-17T08:59:13.893000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
},
{
"friend": false,
"galleries": [
"default"
],
"id": 3827229391220303,
"meta": "Sam Berry",
"normalized": "http://192.168.113.88:3333/uploads//20170517/1495011480937809.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170517/14950114809306293.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170517/149501148093593.jpeg",
"timestamp": "2017-05-17T08:58:00.930000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
},
{
"age": 26.0483455657959,
"emotions": [
"neutral",
"sad"
],
"friend": false,
"galleries": [
"default"
],
"gender": "female",
"id": 3827227793957831,
"meta": "Sam Berry",
"normalized": "http://192.168.113.88:3333/uploads//20170517/14950108570078573.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170517/14950108570022256.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170517/14950108570066717.jpeg",
"timestamp": "2017-05-17T08:47:37.002000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
]
}
Запрос №2
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" http://localhost:8000/v0/faces/gallery/testgal | jq
Ответ
{
"next_page": "/v0/faces/gallery/testgal?max_id=3827059994026334",
"prev_page": null,
"results": [
{
"friend": false,
"galleries": [
"default",
"testgal"
],
"id": 3827229578000564,
"meta": "sample",
"normalized": "http://192.168.113.88:3333/uploads//20170517/14950115538997407.jpeg",
"person_id": 5,
"photo": "http://192.168.113.88:3333/uploads//20170517/14950115538939695.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://192.168.113.88:3333/uploads//20170517/14950115538985784.jpeg",
"timestamp": "2017-05-17T08:59:13.893000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
},
{
"galleries": [
"default",
"testgal"
],
"id": 3827059994026334,
"meta": "sample",
"normalized": "http://127.0.0.1:3333/uploads//20170516/14949453101653092.jpeg",
"photo": "http://127.0.0.1:3333/uploads//20170516/14949453101581762.jpeg",
"photo_hash": "53477c4a72f52c6efc951d9c7ece42bc",
"thumbnail": "http://127.0.0.1:3333/uploads//20170516/14949453101640306.jpeg",
"timestamp": "2017-05-16T14:35:10.158000",
"x1": 595,
"x2": 812,
"y1": 127,
"y2": 344
}
]
}
Распознавание пола, возраста и эмоций¶
This request detects faces in a sample image on the internet and returns coordinates of the rectangle around a detected face (bbox) along with gender, age and emotions information. Relevant REST API method: /detect POST. API version: v1.
Примечание
First, you need to configure gender, age and emotions recognition.
Запрос
curl -H "Authorization: Token t3WGNhZbyaE_GFyQaywYllFoR2QkHXi-" -F 'photo=https://static.findface.pro/sample2.jpg' -F 'gender=true' -F 'emotions=true' -F 'age=true' http://localhost:8000/v1/detect | jq
Ответ
{
"faces": [
{
"age": 29.057680130004883,
"emotions": [
"neutral",
"happy"
],
"gender": "female",
"x1": 515,
"x2": 821,
"y1": 121,
"y2": 427
}
],
"orientation": 1
}