Skip to content

Commit

Permalink
feat(detectors): process images from specific cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Jun 12, 2022
1 parent 82422be commit 5d39d0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ detectors:
# comma-separated slugs of face plugins
# https://github.com/exadel-inc/CompreFace/blob/master/docs/Face-services-and-plugins.md)
# face_plugins: mask,gender,age
# only process images from specific cameras, if omitted then all cameras will be processed
cameras:
- front-door
- garage

deepstack:
url:
Expand All @@ -460,13 +464,21 @@ detectors:
timeout: 15
# require opencv to find a face before processing with detector
opencv_face_required: false
# only process images from specific cameras, if omitted then all cameras will be processed
cameras:
- front-door
- garage

facebox:
url:
# number of seconds before the request times out and is aborted
timeout: 15
# require opencv to find a face before processing with detector
opencv_face_required: false
# only process images from specific cameras, if omitted then all cameras will be processed
cameras:
- front-door
- garage
```

### `schedule`
Expand Down
3 changes: 3 additions & 0 deletions api/src/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ module.exports.config = {
properties: {
url: { type: 'string' },
opencv_face_required: { type: 'boolean' },
cameras: { type: 'array' },
},
},
deepstack: {
Expand All @@ -123,6 +124,7 @@ module.exports.config = {
properties: {
url: { type: 'string' },
opencv_face_required: { type: 'boolean' },
cameras: { type: 'array' },
},
},
facebox: {
Expand All @@ -131,6 +133,7 @@ module.exports.config = {
properties: {
url: { type: 'string' },
opencv_face_required: { type: 'boolean' },
cameras: { type: 'array' },
},
},
},
Expand Down
19 changes: 14 additions & 5 deletions api/src/util/process.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,31 @@ module.exports.save = async (event, results, filename, tmp) => {
};

module.exports.start = async ({ camera, filename, tmp, attempts = 1, errors = {} }) => {
const processed = [];
const promises = [];

const faceCount = opencv.shouldLoad() ? await opencv.faceCount(tmp) : null;

for (const detector of DETECTORS) {
if (!errors[detector]) errors[detector] = 0;
const faceCountRequired = config()?.detectors?.[detector]?.opencv_face_required;
if ((faceCountRequired && faceCount > 0) || !faceCountRequired)
promises.push(this.process({ camera, detector, tmp, errors }));
else console.verbose(`processing skipped for ${detector}: no faces found`);

const detectorConfig = config()?.detectors?.[detector];
const cameraAllowed =
(detectorConfig?.cameras || [camera]).includes(camera) || !detectorConfig?.cameras.length;
const faceCountRequired = detectorConfig?.opencv_face_required;

if (cameraAllowed) {
if ((faceCountRequired && faceCount > 0) || !faceCountRequired) {
promises.push(this.process({ camera, detector, tmp, errors }));
processed.push(detector);
} else console.verbose(`processing skipped for ${detector}: no faces found`);
} else console.verbose(`processing skipped for ${detector}: ${camera} not allowed`);
}
let results = await Promise.all(promises);

results = results.map((array, j) => {
return {
detector: DETECTORS[j],
detector: processed[j],
duration: array ? array.duration : 0,
attempt: attempts,
results: array ? array.results : [],
Expand Down

0 comments on commit 5d39d0c

Please sign in to comment.