diff --git a/plugins/objectdetector/package-lock.json b/plugins/objectdetector/package-lock.json index 1d87f32a2f..8b90050170 100644 --- a/plugins/objectdetector/package-lock.json +++ b/plugins/objectdetector/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.104", + "version": "0.0.105", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/objectdetector", - "version": "0.0.104", + "version": "0.0.105", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/objectdetector/package.json b/plugins/objectdetector/package.json index ea83ce99e7..2225f81efc 100644 --- a/plugins/objectdetector/package.json +++ b/plugins/objectdetector/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/objectdetector", - "version": "0.0.104", + "version": "0.0.105", "description": "Scrypted Video Analysis Plugin. Installed alongside a detection service like OpenCV or TensorFlow.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/objectdetector/src/main.ts b/plugins/objectdetector/src/main.ts index b7584597ed..5e4a7ea6e9 100644 --- a/plugins/objectdetector/src/main.ts +++ b/plugins/objectdetector/src/main.ts @@ -487,32 +487,39 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase; + let generator : () => Promise>; if (newPipeline === 'Snapshot') { const self = this; - generator = (async function* gen() { - while (true) { - const now = Date.now(); - const sleeper = async () => { - const diff = now + 1100 - Date.now(); - if (diff > 0) - await sleep(diff); - }; - let image: MediaObject & VideoFrame; - try { - const mo = await self.cameraDevice.takePicture({ - reason: 'event', - }); - image = await sdk.mediaManager.convertMediaObject(mo, ScryptedMimeTypes.Image); - } - catch (e) { - self.console.error('Video analysis snapshot failed. Will retry in a moment.'); + generator = async () => (async function* gen() { + try { + while (self.detectorRunning) { + const now = Date.now(); + const sleeper = async () => { + const diff = now + 1100 - Date.now(); + if (diff > 0) + await sleep(diff); + }; + let image: MediaObject & VideoFrame; + try { + const mo = await self.cameraDevice.takePicture({ + reason: 'event', + }); + image = await sdk.mediaManager.convertMediaObject(mo, ScryptedMimeTypes.Image); + } + catch (e) { + self.console.error('Video analysis snapshot failed. Will retry in a moment.'); + await sleeper(); + continue; + } + + // self.console.log('yield') + yield image; + // self.console.log('done yield') await sleeper(); - continue; } - - yield image; - await sleeper(); + } + finally { + self.console.log('Snapshot generation finished.'); } })(); } @@ -526,14 +533,14 @@ class ObjectDetectionMixin extends SettingsMixinDeviceBase videoFrameGenerator.generateVideoFrames(stream); } try { const start = Date.now(); let detections = 0; for await (const detected - of await this.objectDetection.generateObjectDetections(generator, { + of await this.objectDetection.generateObjectDetections(await generator(), { settings: this.getCurrentSettings(), })) { if (!this.detectorRunning) {