drawObjects

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

drawObjects component is used to draw object data(detected object information) on image.

  • Description : drawObjects() takes the detected objects info(bounding boxes co-ordinates, probability and Label) as an input and original image as base64 sting 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 : Information about detected Objects
        • Bounding box co-ordinates
        • Probability being object
        • Label
      • Input2 : Original Image (.jpg/.png) in base64 format
    • Output(Via STDOUT) : A JSON string with following contents
      • Base64 string with drawn bounding boxes and probability with label
      • int responseID

List of drawObject features in shunya stack#

  1. Get Image with drawn object detections

Using drawObject#

Requirements to use drawObject#

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

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

Steps are

1. Give object data JSON as an input.#

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

2. Get Image with drawn object detections#

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

    mkdir build && cd build
    cmake ../
    make
    ./drawObjectsCpp
    python3 draw_objects.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 object data is

      {
      "Image":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUG",
      "DetectedObjectsJSON":[
      {
      "Object0":{
      "Rect":{
      "x":1.5101313591003419,
      "y":11.274658203125,
      "height":261.7319030761719,
      "width":177.1690673828125
      },
      "Label":15,
      "Prob":0.8778005838394165
      }
      },
      {
      "responseID":1606898488
      }
      ]
      }
    • Then the JSON output is

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

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

  • This is an example for object-detection and here we will be using 2 components: detectObjects and drawObjects

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

  • detectbjects Components used

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

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

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

Facing errors with the component?#