File

src/interfaces/IDetector.ts

Description

Interface used to configure, load and get detections from the camera.

Index

Methods

Methods

destroy
destroy()

This function takes care of appropriately tearing down the detector instance by unregistering all previously setup subscriptions. In case the detector has been configured to generate detection data without streaming main, then this method will make sure the camera stops generating detection events and stops it's internal streaming.

Returns : Promise<void>

A void function.

init
init()

Convenience function for setting detection and/or framing data event listeners.

Returns : Promise<void>

A void function.

on
on(message: string, callback: any)

EventEmitter on listener. It is used for emitting detector events such as DETECTOR_START, DETECTOR_STOP, DETECTIONS etc. The list of detector events together with all the other camera events can be found in the Events.ts class.

Parameters :
Name Type Optional Description
message string No

The message use to setup the listener for.

callback any No

A callback used to perform actions on the caught event.

Returns : any
once
once(message: string, callback: any)

EventEmitter once listener. Similar to the #on function, instead here the listener is invoked only once and that is the first time the message is emitted from the Detector implementation class.

Parameters :
Name Type Optional Description
message string No

The message use to setup the listener for

callback any No

A callback used to perform actions on the caught event.

Returns : any
removeAllListeners
removeAllListeners(message: string)

EventEmitter removeAllListeners method. Unregisters all event listeners setup on the given message name.

Parameters :
Name Type Optional Description
message string No

The message used to setup the listeners

Returns : any
removeListener
removeListener(message: string, callbackFn: any)

EventEmitter removeListener method. Unregisters any event listeners setup on the detector class (that is either the detection or framing data event listeners).

Parameters :
Name Type Optional Description
message string No

The message used to setup the listener

callbackFn any No

The callback function used to perform actions on the caught event.

Returns : any

How to use the detector interface!

In order to use the detector interface you need to make sure that the autozoom feature is enabled on the camera (see the IAutozoomControl interface for documentation on how to do it).

The detector interface allows you to subscribe to detection and/or framing data from the camera. From version 0.4.0 we support getting detection data from Detector without having to stream the camera on the host machine. NOTE that this is the default behavior now. It is still possible to get detections the old way, where you only get detection when streaming the camera on the host machine. We show you below how to do that!

/* 
We suppose that the sdk has been initialized and autozoom feature is enabled
and running.
*/
...

/**
 * Get an instance of detector implementation from the
 * camera manager.
 */
const detector = cameraManager.getDetector();

// Always call `init`
await detector.init();

/*
Detector class implements EventEmitter and therefor implements
all the event emitter methods. Below we show how to listen
to detector events such as DETECTIONS and FRAMING.
*/

detector.on('DETECTIONS', (detectionList) => {
  // Process the array
});

detector.on('FRAMING', (framingInfo) => {
  // Process framing info
});


/**
 * When you are done, call `destroy` method to properly teardown
 * the detection instance.
 */
await detector.destroy();

...

!! NOTE !! When tearing down your application which is using the detector object, it is important that you call destroy method before closing the host application. Not doing so will leave the camera streaming internally after you have closed the application which might lead to confusion. The camera will stop generating detection data at some point when it detects that no host application is consuming its data. However, it is strongly recommended to properly teardown the detector instance from the host application.

Get detections only when streaming (DOWS)

If you would like to configure the detector so that you get detection events only and only when the user starts streaming the camera on the host machine, then the following code sinppet illustrates how to do just that:

...

/**
 * The `getDetector` method accepts options documented on
 * `IDetectorOpts` interface. One of the options allows you
 * to configure the detector to get detection only when
 * camera is streaming on the host machine. This option is
 * called `DOWS` short for Detections Only When Streaming.
 */
const detector = await cameraManager.getDetector({
  DOWS: true,
});

// Call init
await detector.init();

// Setup detection event listener
detector.on('DETECTIONS', (detectionList) => {
  // Your code here
});

// Teardown
await detector.destroy();
...

Detector Events

The detector class can emit the following events:

Event Description
DETECTIONS Subscribe to this event to get detections from the camera. At the moment only the People class is supported from the detector.
FRAMING Subscribe to this event to get information about the framing. Framing data consists of a property called bbox which contains the coordinates (x, y, width and height) representing the framing data. The framer configuration on the camera will always make sure that the perfect framing of the people in the view is selected.

export default interface IDetector {
  /**
   * Convenience function for setting detection and/or
   * framing data event listeners.
   *
   * @returns {Promise<any>} A void function.
   * @memberof IDetector
   */
  init(): Promise<void>;

  /**
   * This function takes care of appropriately tearing down the
   * detector instance by unregistering all previously setup
   * subscriptions. In case the detector has been configured
   * to generate detection data without streaming main, then
   * this method will make sure the camera stops generating
   * detection events and stops it's internal streaming.
   *
   * @returns {Promise<void>} A void function.
   * @memberof IDetector
   */
  destroy(): Promise<void>;

  /**
   * EventEmitter `on` listener. It is used for emitting detector events
   * such as DETECTOR_START, DETECTOR_STOP, DETECTIONS etc. The list of
   * detector events together with all the other camera events can be found in the `Events.ts` class.
   *
   * @param {string} message The message use to setup the listener for.
   * @param {*} callback A callback used to perform actions on the caught event.
   * @memberof IDetector
   */
  on(message: string, callback: any);

  /**
   * EventEmitter `once` listener. Similar to the `#on` function,
   * instead here the listener is invoked only once and that is
   * the first time the message is emitted from the `Detector` implementation class.
   *
   * @param {string} message The message use to setup the listener for
   * @param {*} callback A callback used to perform actions on the caught event.
   * @memberof IDetector
   */
  once(message: string, callback: any);

  /**
   * EventEmitter `removeListener` method. Unregisters any event listeners
   * setup on the detector class (that is either the detection or framing
   * data event listeners).
   *
   * @param {string} message The message used to setup the listener
   * @param {*} callbackFn The callback function used to perform actions
   * on the caught event.
   * @memberof IDetector
   */
  removeListener(message: string, callbackFn: any);

  /**
   * EventEmitter `removeAllListeners` method. Unregisters all event
   * listeners setup on the given message name.
   *
   * @param {string} message The message used to setup the listeners
   * @memberof IDetector
   */
  removeAllListeners(message: string);
}

result-matching ""

    No results matching ""