This project uses PostgreSQL's cube type and face-api.js to find faces in the images uploaded to Strapi and create Face records for them.
This allows the Face content type to used in queries to return content that contains that face (e.g. a list of pages that contain images for a person)
This project is a proof-of-concept and as such will only work with a PostgreSQL backend
Strapi doesn't configure PostgreSQL databases as part of the project generation so this needs to be done yourself.
In PostgreSQL use the following (change mydb, myuser, mypass to your preferred values)
create database mydb;
create user myuser with encrypted password 'mypass';
grant all privileges on database mydb to myuser;
alter DATABASE mydb OWNER TO admin;
- When bootstrapping the
face-recognitionplugin thevectorstable which stores the raw face descriptions is created - A lifecycle listener is also set up that gets called when media is created (updated & deleted coming soon). This is used to detect and get the face descriptions for storage
- Once a face has been found and the descriptions generated, these are stored in the
vectorstable - The vectors table has a link to the image ID
- A property -
face_idis used to link the vector to a specificFaceentry and thatFacein turn is linked to the created media - The media uploader has been extended to help with the tagging of
Faces - As more and more media is added the
vectorstable is used to suggest faces
- Set up PostgreSQL database as above
- Git clone the project and install the deps
- Update the
config/database.jsvalues to ensure that can connect to DB - Run
yarn develop(or use npm) to run the server (this will create thevectorstable) - Once strapi is set up and you've created admin account the upload functionality should be ready (uploaded images will take longer if face detected)
- In order to use the
faces/searchesendpoint you will need to enable the public role for the searches endpoint, this is done underSettings > Roles > Public > Face-recognitionand checkingsearch - you can then
POSTan image (use form-data andfileas field name) tohttp://localhost:1337/api/faces/searchesand it will return all matching faces