classifyImage
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 classifyImage component ?classifyImage component is used to classify image.
- Description : classifyImage() takes an input as image in base64 format and N i.e. top N probability of classes with probabilities. Check Input and output parameters for details.
- Parameters :
- Input(Via STDIN) :
classifyImage.stdin() << jsonDoc2Text(inputJson) << std::endl;
- An inputJson String with following parameters:
- Parameter1 : Image (.jpg/.png) in base64 format
- Parameter2 : N : Top N class predictions (value between 1 to 1000)
- An inputJson String with following parameters:
- Output(Via STDOUT) :
classifyImage.stdout() >> outputJson;
- An outputJson string with following contents
- For each class in top n
- Score/Probabillity
- Index
- int requestID
- For each class in top n
- An outputJson string with following contents
- Input(Via STDIN) :
#
List of classifyImage features in shunya stack- Set N, get top N predictions
- Get class data.
classifyImage
#
Using classifyImage
#
Requirements to use - Shunya OS installed (supported Arm devices) or Shunya OS docker container (X86 based windows/linux devices)
- Shunya AI installed in Shunya OS.
- Shunya Video component installed in Shunya OS.
classifyImage
#
Steps to use - Set input video location.
- Read Video frames
- Convert cv image to base64 string
- Customize top N prediction value.
- Print classified image's output
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
- Get top N classes predictions
- Get JSON output of classified image.
Steps are
#
Step 1: Set input video location- Start with a ready to use template for classfication from video/image.
- Open the examples in a text editor and modify as per your usecase.
- We will use video compnent to set input video location in configuration file.
- Please check here, how to setup the video source path in video component.
#
Step 2: Read video framesOnce video path is set using video component, lets read video frames one by one.
- For CPP you will find the examples in the folder
cpp-examples/image-classification/
- Open the file
image_classify.cpp
- Code to read first video frame. If you want to read all frames one by one, put following code in while loop.
- For CPP you will find the examples in the folder
#
Step 3: Convert cv image to base64 string- Since classifyImage API needs image in base64 string format, we will convert image from cv::Mat to base64 string.
- Code to do it
#
Step 4: Customize top N prediction value.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/image-classification/classifyImage
- Open the file
classify_image.cpp
- Modify the line to set the N.
- For CPP you will find the examples in the folder
#
Step 5: Call API binaryWe will now call API binary by giving input image(parameter1) and N value(parameter2) an input through STDIN.
You will get output in outputJson string.
#
Step 6: Print output.- Code to print the json output, got from classifyImage API.
#
Run ready to use example.Once you are done editing, save and run the code, by running
Running the codes will print the JSON output on the terminal (to STDOUT).
For Example:
Lets say the input image is
Input JSON is
Then the JSON output is
#
Related Components to classifyImage that you may need to complete your application- no related components