JavaScript SDK
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.
Importing the SDK
Import the SDK module to your source file
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
If you use the SDK in the webpack-based project, you can provide the module resolution alias in your webpack configuration.
If you correctly setup the module resolution, you can import module using a typical module name @nipacloud/nvision
without path.
Using the object detection service
To use the object detection service, you need to create the service object using objectDetection()
generator function
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
Parameters
Parameter
Description
rawData
Base64 string encoded JPEG/PNG image
outputCroppedImage (optional)
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
Streaming video frames through WebSocket
You can make a WebSocket connection using stream()
generator function to get the streaming client object.
>
Returned object
Field
Description
on()
Add an event subscriber, Possible event are "connect", "message", "error"
once()
Add a one-time event subscriber, Possible event are "connect", "message", "error"
connect()
Establish the WebSocket connection
predict()
Send the data through the websocket
Example
This example uses opencv4nodejs
to capture the webcam image, then submit it through the WebSocket channel.
Last updated