Skip to content

Commit

Permalink
support for compreface face_plugins (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed May 25, 2021
1 parent aca0b0b commit edad31b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,37 +385,38 @@ time:
timezone: America/Detroit
```

| Option | Default | Description |
| --------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| server.port | `3000` | API Port |
| mqtt.host | | MQTT host |
| mqtt.username | | MQTT username |
| mqtt.password | | MQTT password |
| mqtt.topics.frigate | `frigate/events` | MQTT topic for Frigate message subscription |
| mqtt.topics.matches | `double-take/matches` | MQTT topic where matches are published |
| mqtt.topics.cameras | `double-take/cameras` | MQTT topic where matches are published by camera name |
| confidence.match | `60` | Minimum confidence needed to consider a result a match |
| confidence.unknown | `40` | Minimum confidence needed before classifying a match name as unknown |
| 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 |
| 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 |
| frigate.attempts.latest | `10` | Amount of times API will request a Frigate `latest.jpg` for analysis |
| frigate.attempts.snapshot | `0` | Amount of times API will request a Frigate `snapshot.jpg` for analysis |
| frigate.image.height | `500` | Height of Frigate image passed for facial recognition |
| frigate.cameras | | Only process images from specific cameras |
| frigate.zones | | Only process images from specific zones |
| home_assistant.url | | Base URL for Home Assistant |
| home_assistant.token | | Home Assistant Long-Lived Access Token |
| detectors.compreface.url | | Base URL for CompreFace API |
| detectors.compreface.key | | API Key for CompreFace collection |
| detectors.deepstack.url | | Base URL for DeepStack API |
| detectors.facebox.url | | Base URL for Facebox API |
| time.format | | Defaults to ISO 8601 format with support for [token-based formatting](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens) |
| time.timezone | `UTC` | Time zone used in logs |
| Option | Default | Description |
| --------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| server.port | `3000` | API Port |
| mqtt.host | | MQTT host |
| mqtt.username | | MQTT username |
| mqtt.password | | MQTT password |
| mqtt.topics.frigate | `frigate/events` | MQTT topic for Frigate message subscription |
| mqtt.topics.matches | `double-take/matches` | MQTT topic where matches are published |
| mqtt.topics.cameras | `double-take/cameras` | MQTT topic where matches are published by camera name |
| confidence.match | `60` | Minimum confidence needed to consider a result a match |
| confidence.unknown | `40` | Minimum confidence needed before classifying a match name as unknown |
| 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 |
| 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 |
| frigate.attempts.latest | `10` | Amount of times API will request a Frigate `latest.jpg` for analysis |
| frigate.attempts.snapshot | `0` | Amount of times API will request a Frigate `snapshot.jpg` for analysis |
| frigate.image.height | `500` | Height of Frigate image passed for facial recognition |
| frigate.cameras | | Only process images from specific cameras |
| frigate.zones | | Only process images from specific zones |
| home_assistant.url | | Base URL for Home Assistant |
| home_assistant.token | | Home Assistant Long-Lived Access Token |
| detectors.compreface.url | | Base URL for CompreFace API |
| detectors.compreface.key | | API Key for CompreFace collection |
| detectors.compreface.face_plugins | | Comma-separated slugs of [face plugins](https://github.com/exadel-inc/CompreFace/blob/master/docs/Face-services-and-plugins.md) |
| detectors.deepstack.url | | Base URL for DeepStack API |
| detectors.facebox.url | | Base URL for Facebox API |
| time.format | | Defaults to ISO 8601 format with support for [token-based formatting](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens) |
| time.timezone | `UTC` | Time zone used in logs |

## Known Issues

In rare scenarios, requesting images from Frigate's API causes Frigate to crash. There is an [open issue](https://github.com/blakeblackshear/frigate/discussions/853) with more information, but it appears sometimes the database connection isn't being closed in time causing Frigate's API to crash. Double Take does use random jitter up to 1 second before all Frigate API requests to help reduce the likelihood of the API crashing. This appears to be related to processing the `snapshot.jpg`. Setting `frigate.attempts.snapshot` to `0` will disable the processing of that image.
In rare scenarios, requesting images from Frigate's API causes Frigate to crash. There is an [open issue](https://github.com/blakeblackshear/frigate/discussions/853) with more information, but it appears sometimes the database connection isn't being closed in time causing Frigate's API to crash. This appears to be related to processing the `snapshot.jpg`. Setting `frigate.attempts.snapshot` to `0` will disable the processing of that image.
9 changes: 6 additions & 3 deletions api/src/util/detectors/compreface.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports.config = () => {
};

module.exports.recognize = (key) => {
const { URL, KEY } = this.config();
const { URL, KEY, FACE_PLUGINS } = this.config();
const formData = new FormData();
formData.append('file', fs.createReadStream(key));
return axios({
Expand All @@ -17,7 +17,7 @@ module.exports.recognize = (key) => {
...formData.getHeaders(),
'x-api-key': KEY,
},
url: `${URL}/api/v1/recognition/recognize`,
url: `${URL}/api/v1/recognition/recognize?face_plugins=${FACE_PLUGINS}`,
validateStatus() {
return true;
},
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports.normalize = ({ data }) => {
const [face] = obj.subjects;
const confidence = face ? parseFloat((face.similarity * 100).toFixed(2)) : 0;
const { box } = obj;
return {
const output = {
name: face && confidence >= CONFIDENCE.UNKNOWN ? face.subject.toLowerCase() : 'unknown',
confidence,
match:
Expand All @@ -83,6 +83,9 @@ module.exports.normalize = ({ data }) => {
height: box.y_max - box.y_min,
},
};
if (obj.age) output.age = obj.age;
if (obj.gender) output.gender = obj.gender;
return output;
});
return normalized;
};
13 changes: 10 additions & 3 deletions frontend/src/components/match/Asset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<Badge v-if="match.camera" :value="match.camera" />
<Badge v-if="match.type" :value="match.type" />
<Badge v-if="match.zones.length" :value="[...match.zones].join(', ')" />
<Badge v-if="gender" :value="gender" />
<Badge v-if="age" :value="age.join('-')" />
</div>
</div>
</template>
Expand Down Expand Up @@ -132,12 +134,17 @@ export default {
}));
data = data.concat(results);
});
} else {
data.push(this.match.meta);
}
return data;
},
gender() {
const [target] = this.results.filter((obj) => obj.detector === 'compreface');
return target && target.gender ? target.gender : null;
},
age() {
const [target] = this.results.filter((obj) => obj.detector === 'compreface');
return target && target.age ? target.age : null;
},
createdAt() {
const units = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second'];
Expand Down

0 comments on commit edad31b

Please sign in to comment.