Создайте REST API для распознавания лиц за 1 минуту

Установка

Приложение для распознавания лиц было протестировано в Ubuntu 16.04 с python 3.5. Вот ссылка на код. Хотя он может работать в других средах с небольшими изменениями или без них. Нажмите ниже команды в терминале, чтобы установить приложение.

git clone https://github.com/neerajshukla1911/face-detection-app.git
cd face-detection-app
pip install -r requirements.txt
git clone https://github.com/davisking/dlib.git
cd dlib
python setup.py install --yes USE_AVX_INSTRUCTIONS
cd ..

Запустить сервер

Команда ниже запустит сервер обнаружения лиц на порту 8882. Порт можно изменить в файле app.py.

python app.py

Детали REST API

Ниже приведены сведения об API REST для распознавания лиц.

- Request Type: form-data
    - Request method: post
    - API:          http://localhost:8882/face-detection
    - Request Parameter:
        - file: file object (Required)
        - return_predicted_image: Return base64 string of image with detected faces bounding boxes. Value of parameter can true/false (optional)
    - Response: Returns list of coordinates of detected faces. Below is sample response.
        {
            "predictions": [
                {
                    "box": {
                        "xmax": 394,
                        "xmin": 305,
                        "ymax": 166,
                        "ymin": 76
                    }
                }
            ]
        }
- Request Type: application/json
    - Request method: post
    - API:          http://localhost:8882/face-detection
    - Request Parameter:
        - image_url: "image url of image" (Required)
        - return_predicted_image: Return base64 string of image with detected faces bounding boxes. Value of parameter can true/false (optional)
    - Response: Returns list of coordinates of detected faces. Below is sample response.
        {
            "predictions": [
                {
                    "box": {
                        "xmax": 394,
                        "xmin": 305,
                        "ymax": 166,
                        "ymin": 76
                    }
                }
            ]
        }

использование

Вы можете использовать любой http-клиент (например, почтальон) для отправки почтового запроса на http: // localhost: 8882 / face-detection. Ниже приведены примеры запросов curl. Измените путь к файлу на путь к файлу изображения.

curl \
  -F "file=@/home/neeraj/2.jpg" \
  localhost:8882/face-detection
curl \
  -F "file=@/home/neeraj/2.jpg" \
  -F "return_predicted_image=true" \
  localhost:8882/face-detection
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"image_url":"https://d2zv4gzhlr4ud6.cloudfront.net/media/pictures/tagged_items/540x0/119_CFM04BL976/1.jpg"}' \
  localhost:8882/face-detection
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"image_url":"https://d2zv4gzhlr4ud6.cloudfront.net/media/pictures/tagged_items/540x0/119_CFM04BL976/1.jpg", "return_predicted_image": true}' \
  localhost:8882/face-detection

Пожалуйста, пометьте репозиторий github, если вы найдете этот пост в блоге полезным.