drawFaces

warning

The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.

What is drawFaces component ?#

drawFaces component is used to draw face data(detected faces information) on face image.

  • Description : drawFaces() takes an input a json string with base64 image, and detected faces information(bounding boxes, probability and 5 landmarks) and returns base64 string with drawn values on image. Check Input and output parameters for details.
  • Parameters :
    • Input(Via STDIN) : A JSON String with following contents:
      • Input1: For each detected face
        • Bounding box co-ordinates
        • Probability being face
        • 5 Landmarks co-ordinates values
      • Input2: Original image in base64 string format
    • Output(Via STDOUT) : A JSON string with following contents
      • Base64 image string with drawn landmarks, bounding boxes and probability
      • int responseID

List of drawFaces features in shunya stack#

  1. Get Image with drawn face detections

Using drawFaces#

Requirements to use drawFaces#

  1. Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices)
  2. Shunya AI installed in Shunya OS.

Steps to use drawFaces#

  1. Give face data JSON as an input.
  2. Get Image with drawn face detections
note

Run the steps given below inside Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices) terminals.

Lets take an example use case: Say we need to

  1. Give detected faces information as as input in JSON format
  2. Get JSON output of all the detected faces drawn on image.

Steps are

1. Give face data JSON as an input.#

  1. Start with an ready to use template for drawing faces on image.

    git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git
    cd shunya-ai-examples/indiv-components
  2. Open the examples in a text editor and modify as per your usecase.

    • For CPP you will find the examples in the folder cpp-examples/face-detection/drawFaces
    • Open the file draw_faces.cpp
    • Modify the line to set the input json string
    /* Replace detectFacesOut with your json string and give as an input to drawFaces component */
    drawFaces.stdin() << detectFacesOut << std::endl;
    • For Python you will find the examples in the folder python-examples/face-detection/drawFaces
    • Open the file draw_faces.py
    • Modify the line to set the input json string
    # Replace detectFacesOut with your json string and give as an input to drawFaces component
    drawFacesOut = drawFaces.communicate(input=detectFacesOut)[0]

2. Get Image with drawn face detections#

  1. Once you are done editing, save and run the code, by running

    mkdir build && cd build
    cmake ../
    make
    ./drawFacesCpp
    python3 draw_faces.py
  2. Running the codes will print the JSON output on the terminal (to STDOUT).

    For Example:

    • Lets say the input image is

      Oops!, No Image to display.
    • Input JSON containing face data is

      {
      "DetectedFacesJSON": [
      {
      "Face0": {
      "Rect": {
      "x": 124.75111389160156,
      "y": 124.99150848388672,
      "height": 71.9333267211914,
      "width": 59.7119140625
      },
      "Landmarks": {
      "x0": 140.8402099609375,
      "y0": 149.54171752929688,
      "x1": 167.64346313476563,
      "y1": 150.42926025390626,
      "x2": 153.3344268798828,
      "y2": 161.6752471923828,
      "x3": 141.37945556640626,
      "y3": 174.49305725097657,
      "x4": 164.75201416015626,
      "y4": 175.1620635986328
      },
      "Prob": 0.9994495511054993
      }
      },
      {
      "responseID": 1600262891
      }
      ],
      "Image": "/e98239u9r93ynm9rfumu02398r8umc9ejmrc8ew0r374y8uhmcwe,=="
      }
    • Then the JSON output is

      {
      "DetectedFacesJSON": {
      "ResponseID": 1606896528,
      "Image": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wB=="
      }
      }

Understand this component with an example (ready to use code)#

  • This is an example for face-detection and here we will be using 2 components: detectFaces and drawFaces

  • Check this ready to use example in c++ and python

  • Download the code

    git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git
    cd shunya-ai-examples/cpp-examples/face-detection
    ```shell git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git cd shunya-ai-examples/python-examples/face-detection ```
  • In this folder there is a file, face_detect.cpp or face_detect.py

  • detectFaces Components used

    subprocess::popen detectFaces("/usr/bin/detectFaces", {});
    ```shell detectFaces = Popen(['/usr/bin/detectFaces'], stdout=PIPE, stdin=PIPE) ```
  • drawFaces component used

    subprocess::popen drawFaces("/usr/bin/drawFaces", {});
    ```shell drawFaces = Popen(['/usr/bin/drawFaces'], stdout=PIPE, stdin=PIPE) ```
  • Run code by yourself

    mkdir build && cd build
    cmake .. && make
    ./faceDetectCpp
    ```shell python3 face_detect.py ```
    - You will get a new image stored in system.Oops!, No Image to display.

Facing errors with the component?#