Make a WebSocket Stream
Nvision with Streaming Videos
WebSocket stream is another way to submit images to the Nvision service. To use the WebSocket stream, the easiest way is to use our provided SDK, see JavaScript SDK.
Consider using the WebSocket stream if you need to continuously submit images (i.e., frames of the video stream).
To use Nvision with streaming videos, your application needs to implement the following:
Stream video frames to Nvision service: Develop websocket stream using SDK.
Get results from the WebSocket via WebHook: Create a webhook url to receive HTTP callback.
Set up callback endpoints: in the Nvision service page.
Stream video frames to Nvision service
In this quickstart, we present an end-to-end use case of how to stream video frames from edge services and set up your backend service to receive the results.
Some application need to be run as a Headless agent on edge compute. For example, you develop a headless agent running on a RaspberryPi to read video frames from CCTV and submit them to the Nvision service as the following diagram.
Installation
Initialize your NPM project, then install @nipacloud/nvision
and opencv4nodejs
using npm
or yarn
command.
Headless Agent
Get results from the WebSocket via WebHook
To get results, you need to configure a Webhook endpoint to your service. Webhook is a user-defined HTTP callback endpoint.
Installation
Headless Agent
For testing webhook integration, we use ngrok to create a secure tunnel on local machine along with public URLs for exposing local web server.
By running this command ngrok http 3000
, you will get public URLs as follows:
Set up callback endpoints
As the socket protocol is used, we provide a custom callback endpoint configuration that allows you to have independent backends for receiving and analyzing prediction results.
WebSocket Streaming Callback URL
Now, input your exposed URL to the WebSocket streaming callback URL in service's setting.
Lastly, when the image is processed, the Nvision service will make a HTTP request to the specified endpoint with the prediction results structured as follow.
Method: POST
Body: The request body will be provided as
Example output
Output Logs from Streaming agent (left) and Webhook callback (right)
Last updated