Get started with FacePing's face recognition API using Node.js
First, install the required dependencies:
npm install node-fetch form-data
Groups help organize your face vectors. Here's how to create one:
const fetch = require('node-fetch');
async function createGroup(groupName) {
const response = await fetch(`https://api.faceping.ai/groups/${groupName}`, {
method: 'POST'
});
return await response.json();
}
// Usage
createGroup('my-group')
.then(result => console.log(result))
.catch(error => console.error(error));
After creating a group, you can store face images as vectors:
const fs = require('fs');
const FormData = require('form-data');
async function storeFace(groupName, imagePath) {
const formData = new FormData();
formData.append('image', fs.createReadStream(imagePath));
const response = await fetch(`https://api.faceping.ai/groups/${groupName}/faces`, {
method: 'POST',
body: formData
});
return await response.json();
}
// Usage
storeFace('my-group', './face.jpg')
.then(result => console.log(result))
.catch(error => console.error(error));
Once you have stored faces, you can search for similar ones:
async function searchFaces(groupName, imagePath) {
const formData = new FormData();
formData.append('image', fs.createReadStream(imagePath));
const response = await fetch(`https://api.faceping.ai/groups/${groupName}/search`, {
method: 'POST',
body: formData
});
return await response.json();
}
// Usage
searchFaces('my-group', './search-face.jpg')
.then(results => console.log(results))
.catch(error => console.error(error));