JavaScript SDK is based on the Nvision image processing service as Promise based function call and WebSocket client with TypeScript definition provided.
Quickstarts
Before you begin to use this SDK, these quickstarts will guide you to get started with the Nvision API.
Installation
Install @nipacloud/nvision via NPM or Yarn to your project.
yarn add @nipacloud/nvision
Importing the SDK
Import the SDK module to your source file
const nvision = require("@nipacloud/nvision")
// or use the ES6 import
import nvision from "@nipacloud/nvision"
Additional setup for front-end app
If you use the SDK in the front-end application, you need to import the browser variant provided at @nipacloud/nvision/dist/browser/nvision.js
const nvision = require("@nipacloud/nvision/dist/browser/nvision")
// or use the ES6 import
import nvision from "@nipacloud/nvision/dist/browser/nvision"
If you use the SDK in the webpack-based project, you can provide the module resolution alias in your webpack configuration.
You do not have to provide both apiKey or streamingKey . If you use only API call, you can provide only apiKey , this applied to WebSocket streaming too.
Making an API call
You can make an API call using predict() function of the service object
Set "OutputCroppedImage" parameter, if true, API response will include the cropped images for each bounding box in Base64 encoded JPEG/PNG format. Default is false.
confidenceThreshold (optional)
Set "ConfidenceThreshold" parameter" to define the minimum confidence score of the prediction results.
outputVisualizedImage (optional)
Set "OutputVisualizedImage" parameter to return drawn detection objects on raw image
Promised return object
Field
service_id
Service ID associated to the API key used
detected_object
List of the detected objects
name
Classified name of the object
confidence
Confidence value of the prediction
cropped_image
Bounding box cropped image
Example
import nvision from "@nipacloud/nvision";
const objectDetectionService = nvision.objectDetection({
apiKey: "<YOUR_RESTFUL_KEY>"
});
objectDetectionService.predict(
"BASE64_ENCODED_IMAGE"
).then((result) => {
// Outout the result object to console
console.log(result);
});
Streaming video frames through WebSocket
You can make a WebSocket connection using stream() generator function to get the streaming client object.