Skip to content

Commit

Permalink
client: detection jpeg example
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed May 13, 2023
1 parent 9e7b57f commit 1ed7d03
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/client/examples/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ async function example() {
if (!backyard)
throw new Error('Device not found');

backyard.listen(ScryptedInterface.ObjectDetector, (source, details, data) => {
backyard.listen(ScryptedInterface.ObjectDetector, async (source, details, data) => {
const results = data as ObjectsDetected;
console.log(results);
})
console.log('detection results', results);
// detections that are flagged for retention will have a detectionId.
// tf etc won't retain automatically, and this requires a wrapping detector like Scrypted NVR Object Detection
// to decide which frames to keep. Otherwise saving all images would be extremely poor performance.
if (!results.detectionId)
return;

const media = await backyard.getDetectionInput(results.detectionId);
const jpeg = await sdk.mediaManager.convertMediaObjectToBuffer(media, 'image/jpeg');
// do something with the buffer like save to disk or send to a service.
});
}

example();

0 comments on commit 1ed7d03

Please sign in to comment.