-
The Immich API (https://immich.app/docs/api/) does not provide a possibility to run an external image, e.g. from the front-door camera through face recognition (or am I wrong?). Is there any way to use the defined faces in Immich as a foundation for a face recognition? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
For people coming across this in future: The Immich API does not support face recognition for "external" images (images not known by Immich as an asset). As a workaround, you may query the postgres database yourself to overcome this and use Immich and all the faces in Immich as your face recognition.
EXAMPLE Remark: Fill in your database connection details as well as URL for the machine learning instance. /*
* set sql query
*/
const query = `
WITH "cte" AS (
SELECT "person"."name", "face_search"."embedding" <=> '$1' AS "distance"
FROM "asset_faces"
INNER JOIN "face_search" ON "face_search"."faceId" = "asset_faces"."id"
LEFT JOIN "person" ON "person"."id" = "asset_faces"."personId"
)
SELECT "name", MIN("distance") AS "distance"
FROM "cte"
GROUP BY "name"
HAVING "name" <> ''
ORDER BY "distance"
`
/**
* set face detection options
*/
function face(file) {
let faces = [];
// connect to db
const client = new Client({
'user': '',
'password': '',
'host': '192.168.0.0',
'port': '5432',
'database': 'immich'
});
// run face detection
const data = new FormData();
data.append('entries', '{ "facial-recognition": { "recognition": { "modelName": "buffalo_l", "options": { "minScore": 0.035 }}, "detection": { "modelName": "buffalo_l" }}}');
data.append('image', fs.createReadStream(file));
const options = {
'method': 'post',
'maxBodyLength': Infinity,
'url': 'http://immich-machine-learning:3003/predict',
'headers': { ...data.getHeaders() },
data
};
return axios.request(options)
.then(result => {
faces = result?.data?.['facial-recognition'] || [];
return client.connect();
})
.then(() => {
return Promise.allSettled(
faces.map(face => {
return new Promise((resolve, reject) => {
client.query(query.replace('$1', face.embedding), (error, result) => {
if (error || !result || !result.rows || !result.rows[0] || !result.rows[0].name) {
return reject({ 'name': null, 'score': 0, error });
}
return resolve({ ...result.rows[0], 'score': Math.round(face.score * 100) });
})
})
})
);
})
.then(result => {
return { file, 'persons': result.map(res => res.status === 'fulfilled' ? res.value : res.reason) };
})
.catch(error => log(error, 'error'))
.finally(() => client.end());
} Use like
|
Beta Was this translation helpful? Give feedback.
-
i am using CodeProject.AI-Server for Face and carplate detection within JS-Adapter in iobroker. Works very well: |
Beta Was this translation helpful? Give feedback.
For people coming across this in future: The Immich API does not support face recognition for "external" images (images not known by Immich as an asset).
As a workaround, you may query the postgres database yourself to overcome this and use Immich and all the faces in Immich as your face recognition.
http://immich-machine-learning:3003/predict
(see payload in example below)embedding
returned by the request to query the database looking for faces / persons close to the embeddingEXAMPLE
Remark: Fill in your database connection details as well as URL for the machine learning instance.