Masks detection

FREEMIUM
Verified
By API 4 AI | Updated 8 days ago | Visual Recognition
Popularity

8.3 / 10

Latency

702ms

Service Level

100%

Health Check

100%

Followers: 1
Resources:
Product Website
API Creator:
Rapid account: API 4 AI
API 4 AI
api4ai
Log In to Rate API
Rating: 5 - Votes: 1

README

Overview

Service for medical mask detection.

The service allows to perform people detection and classify if the found person has a medical mask.

Detection

People bounding box represented by 4 float numbers: x and y position of the left top corner, width
and height of the box. Numbers are normalized relative to the image size.

Endpoints

METHOD URL DESCRIPTION
GET https://masks-detection.p.rapidapi.com/v1/version Get service version.
GET https://masks-detection.p.rapidapi.com/v1/warmup Warmup service to speedup future analysis.
POST https://masks-detection.p.rapidapi.com/v1/results Perform image analysis and get results.

Get version

Returns an actual version of the service in format vX.Y.Z where X is the
version of API.

PROPERTY DESCRIPTION
Endpoint https://masks-detection.p.rapidapi.com/v1/version
Method GET
Query parameters
POST parameters

Examples

Request:

$ curl -X 'GET' 'https://masks-detection.p.rapidapi.com/v1/version'

Response:

v1.5.0

Analyse image and return results

Performs actual image analysis and responds with results.

PROPERTY DESCRIPTION
Endpoint https://masks-detection.p.rapidapi.com/v1/results
Method POST
Query parameters detection
POST parameters image, url

Query parameter: detection

The detection query parameter allows client to enable/disable people detection.

  • If client passes True value then the service will perform detection. In this case the response may contain multiple boxes in output.
    Each detection will contain:
    • Bounding box: box.
    • Medical mask classification entity med-mask with mask, nomask classes and their probabilities.
    • Classification entity people-detector for detected bounding box which has only person class and the confidence.
  • Otherwise if client passes False value then the image will be treated as a cropped person-only image and service will skip detection.
    In this case box is also appears in the response, but coordinates are always [0.0, 0.0, 1.0, 1.0].

Detection is enabled by default.

Response schema

For responses with 200 HTTP code, the type of response is JSON object with the
following schema:

{
  "results": [
    {
      "status": {
        "code": "ok",
        "message": "Success"
      },
      "name": "curry.jpg",
      "md5": "11170166a6e894e74ff360ff3d01d6ef",
      "page": ...,
      "width": ...,
      "height": ...,
      "entities": [
        {
          "kind": "objects",
          "name": "med-mask-detector",
          "objects": [
            {
              "box": ...,
              "entities": [
                {
                  "kind": "classes",
                  "name": "people-detector",
                  "classes": {
                    "person": ...
                  }
                },
                {
                  "kind": "classes",
                  "name": "med-mask",
                  "classes": {
                    "mask": ...,
                    "nomask": ...
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Primary fields:

Name Type Description
results[].status.code string Status code of image processing: ok or failure.
results[].status.message string Human readable explanation for status of image processing.
results[].name string Original image name passed in request (e.g. my_image.jpg).
results[].md5 string MD5 sum of original image passed in request.
results[].page int Optinal page number (presented for multipage inputs only).
results[].width int Optinal image width (presented for valid inputs only).
results[].height int Optinal image height (presented for valid inputs only).
results[].entities[].objects array Array of detected people.
results[].entities[].objects[].box array Person bounding box defined by 4 float values.
results[].entities[].objects[].entities[name=people-detector].classes.person float Person detection confidence.
results[].entities[].objects[].entities[name=med-mask].classes.mask float Probability that the person has a medical mask.
results[].entities[].objects[].entities[name=med-mask].classes.nomask float Probability that the person doesn’t have a medical mask.

Other fields that are not described above always have the same values.

Passing image

Image can be passed by posting regular “multipart form data” in two alternative ways:

  • as binary file in image field
  • as URL to some public resource in url field

Image must be a regular JPEG or PNG image (with or without transparency) or PDF file.
Usually such images have extensions: .jpg, .jpeg, .png, .pdf. In case of PDF
each page will be converted to PNG image and processed separately.
The service checks input file by MIME type and accepts the following types:

  • image/jpeg
  • image/png
  • application/pdf

The size of image file must be less than 16Mb.

Examples

Request:

curl -X 'POST' 'https://masks-detection.p.rapidapi.com/v1/results' -F 'image=@person.jpg'

Response:

{
  "results": [
    {
      "status": {
        "code": "ok",
        "message": "Success"
      },
      "name": "person.jpg",
      "md5": "11170166a6e894e74ff360ff3d01d6ef",
      "width": 1024,
      "height": 768,
      "entities": [
        {
          "kind": "objects",
          "name": "med-mask-detector",
          "objects": [
            {
              "box": [
                0.02378430962562561,
                0.025364607572555542,
                0.9789055287837982,
                0.974009782075882
              ],
              "entities": [
                {
                  "kind": "classes",
                  "name": "people-detector",
                  "classes": {
                    "person": 0.9750556349754333
                  }
                },
                {
                  "kind": "classes",
                  "name": "med-mask",
                  "classes": {
                    "mask": 4.6584673896177264e-7,
                    "nomask": 0.9999995231628418
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Possible errors

The service can not process an image

When client sends an image that can not be processed for some reason(s), the service responds with 200 code and returns JSON object in the same format as the format for successful analysis. In this case, the results[].status.code will have failure value and results[].status.message will contain relevant explanation.

Example of possible reasons for the issue:

  • Unsupported file MIME type
  • Corrupted image
  • File passed as URL is too big or non downloadable

Example response for corrupted image:

{
  "results": [
    {
      "status": {
        "code": "failure",
        "message": "Can not load image."
      },
      "name": "file.jpg",
      "md5": "d41d8cd98f00b204e9800998ecf8427e",
      "entities": []
    }
  ]
}

Request size is too big

Request size is limited by approximately 32Mb.
When client sends request that exceeds this limit, the service responds with 413 code.

The typical reason for exceeding this limit is overly large image.
Taking into account additional HTTP overhead, we strongly recommend to not pass image files of size more than 16Mb.

Example response for too big request:

Error: Request Entity Too Large

Your client issued a request that was too large.

Missing image or url

When client sends a request without an image and url, the service responds with 422 code and returns JSON object.

Example response for request without image or url:

{"detail": "Missing image or url field."}