i need to use this script inside a laravel controller. the script uses a facial recognition library to compare the faces that are in the photos. How can I use this code inside a public function?
const imageUpload = document.getElementById('imageUpload')
Promise.all([
faceapi.nets.faceRecognitionNet.loadFromUri('/models'),
faceapi.nets.faceLandmark68Net.loadFromUri('/models'),
faceapi.nets.ssdMobilenetv1.loadFromUri('/models'),
faceapi.nets.tinyFaceDetector.loadFromUri('/models')
]).then(start)
async function start() {
document.body.append('Loaded')
imageUpload.addEventListener('change', async () => {
image = await faceapi.bufferToImage(imageUpload.files[0])
const descriptions = []
const detections1 = await faceapi.detectAllFaces(image).withFaceLandmarks().withFaceDescriptors();
const faceMatcher = new faceapi.FaceMatcher(detections1, 0.6)
var a = 0;
const images = [];
for (var i = 100; i <= 618; i++) {
let image = 0;
let img = new Image();
img.src = 'test/' + i + '.jpeg';
image = i + '.jpeg';
const results = await faceapi.detectAllFaces(img).withFaceLandmarks().withFaceDescriptors()
results.forEach(fd => {
const bestMatch = faceMatcher.findBestMatch(fd.descriptor)
if (bestMatch.label == "person 1") {
images[a] = image;
a++;
}
})
}
})
}
This project is to work as an API, I don't want it to have views, the user will just have an APP in react native making requests to the laravel API
Laravel is php. The php interpreter does not execute javascript. You can run JS in a browser OR in a nodeJS micro-service. If you really want to get funky you can setup a headless browser on your server.
You can't run javascript in Laravel controller. Also this function loads from the DOM, so it needs a document.