Skip to main content

drawPoses

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 drawPoses component ?

drawPoses component is used to draw the detected points(pose) on image.

  • Description : drawPoses() takes an input a json string with base64 image, and detected poses information(detected points with probability) 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 parameters:
      • Parameter1: For each detected pose
        • detected point
        • Probability for each point
      • Parameter2: Original image in base64 string format
    • Output(Via STDOUT) : A JSON string with following contents
      • Base64 image string with drawn pose
      • int responseID

List of drawPoses features in shunya stack

  1. Get Image with drawn pose detections

Using drawPoses

Requirements to use drawPoses

  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 drawPoses

  1. Give pose data JSON as an input.
  2. Get Image with drawn pose 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 poses information as as input in JSON format
  2. Get JSON output of all the detected poses drawn on image.

Steps are

1. Give pose data JSON as an input.

  1. Start with an ready to use template for drawing poses 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/pose-estimation/drawPoses
    • Open the file draw_poses.cpp
    • Modify the line to set the input json string
    /* Replace detectPosesOut with your json string and give as an input to drawPoses component */
    drawPoses.stdin() << detectPosesOut << std::endl;
    • For Python you will find the examples in the folder python-examples/pose-estimation/drawPoses
    • Open the file draw_poses.py
    • Modify the line to set the input json string
    # Replace detectPosesOut with your json string and give as an input to drawPoses component
    drawPosesOut = drawPoses.communicate(input=detectPosesOut)[0]

2. Get Image with drawn pose detections

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

    mkdir build && cd build
    cmake ../
    make
    ./drawPosesCpp
    python3 draw_poses.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 pose data is

      {
      "Image":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUG",
      "DetectedposesJSON":[
      {
      "Point0":{
      "Landmarks":{
      "x":112.5,
      "y":21.09375
      },
      "Prob":0.979064404964447

      },
      "Point1":{
      "Landmarks": {
      "x":117.1875,
      "y":17.578125
      },
      "Prob":0.9587295651435852
      },
      .....
      }
      }
    • Then the JSON output is

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

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

  • This is an example for pose-estimation and here we will be using 2 components: detectPoses and drawPoses

  • 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/pose-estimation
    ```shell git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git cd shunya-ai-examples/python-examples/pose-estimation ```
  • In this folder there is a file, pose_detect.cpp or pose_detect.py

  • detectbjects Components used

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

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

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

Facing errors with the component?