From 60cc3add253c698f56b5d314d2dd99dd7059ba44 Mon Sep 17 00:00:00 2001 From: SeydX Date: Tue, 11 Jan 2022 21:27:23 +0100 Subject: [PATCH] videoanalysis improvements --- CHANGELOG.md | 8 +++ package-lock.json | 4 +- package.json | 2 +- .../camera/services/session.service.js | 2 +- .../camera/services/stream.service.js | 5 ++ .../camera/services/videoanalysis.service.js | 65 ++++++++++--------- ui/src/components/navbar.vue | 6 +- ui/src/views/Camview/Camview.vue | 2 +- 8 files changed, 56 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5011ce8a..c94ec38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Changelog All notable changes to this project will be documented in this file. +# Next + +## Other Changes +- Minor UI improvements + +## Bugfixes +- Fixed an issue where the video analysis sensitivity does not work as desired + # [1.0.4] - 2022-01-11 ## Other Changes diff --git a/package-lock.json b/package-lock.json index f1f291fe..62445740 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "camera.ui", - "version": "1.0.4", + "version": "1.0.5-beta.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "camera.ui", - "version": "1.0.4", + "version": "1.0.5-beta.0", "funding": [ { "type": "paypal", diff --git a/package.json b/package.json index d410a524..525758ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "camera.ui", - "version": "1.0.4", + "version": "1.0.5-beta.0", "description": "User Interface for RTSP capable cameras.", "author": "SeydX (https://github.com/SeydX/camera.ui)", "scripts": { diff --git a/src/controller/camera/services/session.service.js b/src/controller/camera/services/session.service.js index 3ec5045d..ffb09656 100644 --- a/src/controller/camera/services/session.service.js +++ b/src/controller/camera/services/session.service.js @@ -15,7 +15,7 @@ class SessionService { this.session = { activeStreams: 0, - maxStreams: camera.videoConfig.maxStreams, + maxStreams: camera.videoConfig.maxStreams || 4, }; } diff --git a/src/controller/camera/services/stream.service.js b/src/controller/camera/services/stream.service.js index 4702d6a6..056aa538 100644 --- a/src/controller/camera/services/stream.service.js +++ b/src/controller/camera/services/stream.service.js @@ -123,6 +123,11 @@ class StreamService { if (!prebuffer) { const allowStream = this.#sessionService.requestSession(); + console.log('ALLOW???'); + console.log(allowStream); + + console.log(this.#sessionService); + if (!allowStream) { log.error('Not allowed to start stream. Session limit exceeded!', this.cameraName, 'streams'); return; diff --git a/src/controller/camera/services/videoanalysis.service.js b/src/controller/camera/services/videoanalysis.service.js index 9b3766ef..2948ddda 100644 --- a/src/controller/camera/services/videoanalysis.service.js +++ b/src/controller/camera/services/videoanalysis.service.js @@ -19,6 +19,12 @@ const { log } = LoggerService; const isUINT = (value) => Number.isInteger(value) && value >= 0; +const FFMPEG_MODE = 'rgba'; // gray, rgba, rgb24 +const FFMPEG_RESOLUTION = '640:360'; +const FFMPEG_FPS = '2'; +const DIFFERENCE = 9; +const GRAYSCALE = 'luminosity'; + class VideoAnalysisService { #camera; #socket; @@ -56,28 +62,19 @@ class VideoAnalysisService { } } - // 0 - 100 changeSensitivity(sensitivity) { if (sensitivity >= 0 && sensitivity <= 100 && this.videoanalysisSession?.pamDiff) { - const value = 100 - sensitivity; - - // 0: MAX - 100: MIN - const difference = Math.round(value / 3); - - // 0: MAX - 100: MIN - const percentage = value; - - this.videoanalysisSession.pamDiff.setDifference(difference); - this.videoanalysisSession.pamDiff.setPercent(percentage); + this.videoanalysisSession.pamDiff.setDifference(DIFFERENCE); + this.videoanalysisSession.pamDiff.setPercent(100 - sensitivity); } } - changeZone(regions, sensitivity) { - if (regions && regions.length > 0 && this.videoanalysisSession?.pamDiff) { - const zones = this.#createRegions(regions, sensitivity); - this.videoanalysisSession.pamDiff.regions = zones.length > 0 ? zones : null; - + changeZone(regions = [], sensitivity) { + if (this.videoanalysisSession?.pamDiff) { + this.videoanalysisSession.pamDiff.resetCache(); this.changeSensitivity(sensitivity); + const zones = this.#createRegions(regions, sensitivity); + this.videoanalysisSession.pamDiff.setRegions(zones.length > 0 ? zones : null); } } @@ -193,11 +190,11 @@ class VideoAnalysisService { '-vcodec', 'pam', '-pix_fmt', - 'gray', + FFMPEG_MODE, '-f', 'image2pipe', '-vf', - 'fps=2,scale=400:225', + `fps=${FFMPEG_FPS},scale=${FFMPEG_RESOLUTION}`, 'pipe:1', ]; @@ -213,12 +210,16 @@ class VideoAnalysisService { const p2p = new P2P(); const pamDiff = new PamDiff({ - difference: settings?.videoanalysis?.difference || 10, - percent: settings?.videoanalysis?.percentage || 30, + //difference: settings?.videoanalysis?.difference || 9, + grayscale: GRAYSCALE, + difference: DIFFERENCE, + percent: settings?.videoanalysis?.percentage || 5, + regions: regions.length > 0 ? regions : null, + //response: 'percent', + response: 'bounds', + draw: true, }); - pamDiff.regions = regions.length > 0 ? regions : null; - const restartWatchdog = () => { clearTimeout(this.watchdog); this.watchdog = setTimeout(() => { @@ -243,16 +244,16 @@ class VideoAnalysisService { // eslint-disable-next-line no-unused-vars pamDiff.on('diff', async (data) => { if (!this.motionTriggered) { - log.debug(`Motion detected via Videoanalysis: ${JSON.stringify(data.trigger)}`, this.cameraName); - this.motionTriggered = true; + log.debug(`Motion detected via Videoanalysis: ${JSON.stringify(data.trigger)}`, this.cameraName); + const result = await MotionController.handleMotion('motion', this.cameraName, true, 'videoanalysis', {}); log.debug(`Received a new VIDEOANALYSIS message ${JSON.stringify(result)} (${this.cameraName})`); setTimeout(() => { this.motionTriggered = false; - }, 45000); + }, 60000); } }); @@ -331,14 +332,18 @@ class VideoAnalysisService { if (region.coords?.length > 2) { return { name: `region${index}`, - difference: Math.round(sensitivity / 3), - percent: sensitivity, + difference: 9, + percent: 100 - sensitivity, polygon: region.coords ?.map((coord) => { - if (isUINT(coord[0]) && isUINT(coord[1])) { + let x = coord[0] < 0 ? 0 : coord[0] > 100 ? 100 : coord[0]; + let y = coord[1] < 0 ? 0 : coord[1] > 100 ? 100 : coord[1]; + if (isUINT(x) && isUINT(y)) { + //x: 0 - 100 % => 0 - 640 px + //y: 0 - 100 % => 0 - 360 px return { - x: coord[0], - y: coord[1], + x: Math.round((640 / 100) * x), + y: Math.round((360 / 100) * y), }; } }) diff --git a/ui/src/components/navbar.vue b/ui/src/components/navbar.vue index 31c8b32c..fba643d9 100644 --- a/ui/src/components/navbar.vue +++ b/ui/src/components/navbar.vue @@ -1,8 +1,8 @@