@edgeros/jsre-camera-src v1.0.4
Overview
CameraSource module is a media source of WebMedia framewrok. It has the following characteristics:
- Connect
rtspaudio and video stream, outputflvlive stream; - Integrated
facennmodule, which can recognize face information; - Built-in face-following algorithm to generate face-following coordinates (in accordance with the
onvifprotocol); - Face recognition and face follow functions can be controlled separately;
AIruns in a separate thread and does not block the main framework ofWebMedia.
User can use the following code to import the CameraSource module .
var source = require('@edgeros/jsre-camera-src');Support
The following shows CameraSource module APIs avaliable for each permissions.
| User Mode | Privilege Mode | |
|---|---|---|
| source.autoMove | ● | ● |
| source.openAI | ● | ● |
CameraSource Object
source.autoMove
- {Boolean} true - start face-following, the source control camera movement by emit
camStopandcamMoveevent. Otherwise setautoMovetofalse. default: false.
source.openAI(enable)
enable{Boolean} OpenAIor not. default: false.
When AI is opened, source broadcasts the recognized face information to each client. face information to see Media Data.
FaceFlvSource Events
camStop
Stop move. Stop camera to see onvif camera.stop().
When source.autoMove is set, source will continuously generate camMove and camStop events until the recognized face is in the middle of the screen.
camMove
rx{Number} Move distance x.ry{Number} Move distance y.
Move camera to see onvif camera.continuousMove().
Use CameraSource
To use CameraSource, you first need to register the media source on the WebMedia framework, em:
var WebMedia = require('webmedia');
var CameraSource = require('@edgeros/jsre-camera-src');
const sourceName = 'camera-flv';
WebMedia.registerSource(sourceName, CameraSource);CameraSource object create by WebMedia framework, em:
var opts = {
mode: 2,
mediaSource: {
source: 'camera-flv',
inOpts: inOpts, // source input options
outOpts: outOpts // source output options
},
streamChannel: {
protocol: 'ws',
},
dataChannel: {
protocol: 'ws',
}
}
var ser = WebMedia.createServer(opts, app);
ser.on('open', (ser, media) => {
// access source by media.source
}You need to provide the CameraSource options when creating the WebMedia server. The CameraSource options are as follows:
inOpts{Ojbect} +host{String} Media source hostname. +port{Integer} Media source port. default: 10000. +path{String} Media source path. default: '/'. +user{String} default: 'admin' +pass{String} default: 'admin'outOpts{Object} +faceDetecOpts{Object} +enable{Boolean} default: true. +faceLibs{Array} {id, keys} Face information retrieval db. +threshold{Number} threshold value of similarity, default: 0.6. +format{Object} Identify information output options, default: {male=false, age=false, emotion=false, area=true}. +fps{Integer} Detection frequency, default: 1.
Media Data
Media data is sent to the client by client.send(opts, data[, cb]) of MediaClient. For details, please refer to the WebMedia module.
CameraSource outputs two kinds of media data:
media
opts{Object} Must be: {type: 'media'}data{Object} +width{Integer} Video width. +height{Integer} Video height. +fps{Integer} Video fps.
push media info data first.
face
opts{Object} Must be: {type: 'face'}data{Array} Object array, options: +id{Integer} Detected face id. +male{Integer} Detected male. +age{Integer} Detected age. +emotion{Integer} Detected emotion. +x0{Integer} Begin position x of face. +y0{Integer} Begin position y of face. +x1{Integer} End positon x of face. +y1{Integer} End position y of face.
face detected output info. Data setting base outOpts.faceDetecOpts.format option.
NOTICE: id(0) meen detected face not match any one in libs.