detectPoses

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 detectPoses component ?#

detectPoses component is used to detect pose of a person in input image.

  • Description : detectPoses() takes an input as image in base64 string format and returns the points(x,y) with probability for that point.Check Input and output parameters for details.
  • Parameters :
    • Input(Via STDIN) : A JSON String with following contents:
      • Input1 : Image (.jpg/.png) in base64 format
    • Output(Via STDOUT) : A JSON string with following contents
      • For each detected point
        • x,y co-ordinates
        • probability being point
      • int responseID

List of detectPoses features in shunya stack#

  1. Get human pose data.

Using detectPoses#

Requirements to use detectPoses#

  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 detectPoses#

  1. Set input image location.
  2. Get human pose data
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. Detect pose of person in an image.
  2. Get JSON output of detected pose data.

Steps are

Step 1: Set location of the input image for pose estimation#

  1. Start with an ready to use template for detecting pose from 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/detectPoses
    • Open the file detect_poses.cpp
    • Modify the line to set the location of the input image
    /* Modify the location of the image to your input image */
    cv::Mat inputImage = cv::imread("../images/pose.jpeg");
    • For Python you will find the examples in the folder python-examples/pose-estimation/detectPoses
    • Open the file detect_poses.py
    • Modify the line to set the location of the input image
    # Modify the location of the image to your input image
    img = cv2.imread("images/pose.jpeg")

Step 2: Get human pose data.#

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

    mkdir build && cd build
    cmake ../
    make
    ./detectPosesCpp
    python3 detect_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 is

      {
      "inputImage": "4h32e898473urmcrkd947ryuemcc3x21j98k09754ycmx1k030i1d98754yn==",
      }
    • Then the JSON output 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
      },
      .....
      }
      }

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?#