Skip to content

Commit

Permalink
feat: ability to include base64 encoded string in API results and MQT…
Browse files Browse the repository at this point in the history
…T messages (#52)
  • Loading branch information
jakowenko committed Sep 7, 2021
1 parent caf6a89 commit 233d56a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ detectors:
| objects.face.min_area_match | `10000` | Minimum area in pixels to consider a result a match |
| save.matches | `true` | Save match images |
| save.unknown | `true` | Save unknown images |
| save.base64 | `false` | Include Base64 encoded string in API results and MQTT messages. Options include: `true`, `false`, or `box`. |
| purge.matches | `168` | Hours to keep match images until they are deleted |
| purge.unknown | `8` | Hours to keep unknown images until they are deleted |
| frigate.url | | Base URL for Frigate |
Expand Down
1 change: 1 addition & 0 deletions api/src/constants/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
save: {
matches: true,
unknown: true,
base64: false,
},
objects: {
face: { min_area_match: 10000 },
Expand Down
14 changes: 12 additions & 2 deletions api/src/util/process.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const database = require('./db.util');
const mask = require('./mask.image.util');
const sleep = require('./sleep.util');
const { recognize, normalize } = require('./detectors/actions');
const { FRIGATE, STORAGE, SAVE } = require('../constants');
const { SERVER, FRIGATE, STORAGE, SAVE } = require('../constants');
const DETECTORS = require('../constants/config').detectors();

module.exports.polling = async (event, { retries, id, type, url, breakMatch, MATCH_IDS }) => {
Expand Down Expand Up @@ -53,8 +53,18 @@ module.exports.polling = async (event, { retries, id, type, url, breakMatch, MAT
.length;
const totalFaces = results.flatMap((obj) => obj.results.filter((item) => item)).length;

if (foundMatch || (SAVE.UNKNOWN && totalFaces > 0))
if (foundMatch || (SAVE.UNKNOWN && totalFaces > 0)) {
await this.save(event, results, filename, maskBuffer?.visible ? tmp.mask : tmp.source);
if (SAVE.BASE64 === true || SAVE.BASE64 === 'box') {
const base64 =
SAVE.BASE64 === true
? stream
: await this.stream(
`http://0.0.0.0:${SERVER.PORT}/api/storage/matches/${filename}?box=true`
);
results.forEach((result) => (result.base64 = base64.toString('base64')));
}
}

allResults.push(...results);

Expand Down
3 changes: 3 additions & 0 deletions api/src/util/recognize.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports.normalize = (results = []) => {
duration: attempt.duration,
detector: attempt.detector,
filename: attempt.filename,
base64: attempt.base64,
};
}
});
Expand All @@ -34,6 +35,7 @@ module.exports.normalize = (results = []) => {
duration: attempt.duration,
detector: attempt.detector,
filename: attempt.filename,
base64: attempt.base64,
};
}
});
Expand All @@ -49,6 +51,7 @@ module.exports.normalize = (results = []) => {
duration: attempt.duration,
detector: attempt.detector,
filename: attempt.filename,
base64: attempt.base64,
};
}
});
Expand Down

0 comments on commit 233d56a

Please sign in to comment.