英文:
Face-api NodeJs same result returns , every two image matches
问题
The problem you're encountering is related to the way the output text is being displayed, with HTML entities such as "
and '
instead of the actual double quotes and single quotes. This can make the text look incorrect or not properly formatted.
To resolve this issue, you can replace these HTML entities with their corresponding characters. Here's the corrected version of the text:
I use face-api in node js. When I match two images, the result always returns the same value like "Similarity: person 1 (0) FaceMatch { _label: 'person 1', _distance: 0 }"
**Node.js FaceRecognition Class**
const path = require('path');
class FaceRecognition {
constructor() {
this.faceMatcher = null;
}
async compareFaces(imgPath1, imgPath2) {
try {
// Load the models
await this.loadModel();
// Load the images
const image1 = await canvas.loadImage(imgPath1);
const image2 = await canvas.loadImage(imgPath2);
// Detect faces in the images
const face1 = await faceapi.detectSingleFace(image1).withFaceLandmarks().withFaceDescriptor();
const face2 = await faceapi.detectSingleFace(image2).withFaceLandmarks().withFaceDescriptor();
// Check if faces were detected in both images
if (face1 && face2) {
// Create an array of face descriptors
const faceDescriptors = [face1.descriptor];
// Create a FaceMatcher with the face descriptors
const faceMatcher = new faceapi.FaceMatcher(faceDescriptors);
// Compare the face descriptors of the second image
const result = faceMatcher.findBestMatch(face2.descriptor);
// Output the result
console.log(`Similarity: ${result.toString()}`);
return result;
} else {
throw new Error('Unable to detect faces in one or both images.');
}
} catch (error) {
console.error(`Error occurred: ${error}`);
throw error;
}
}
}
I've replaced "
with double quotes ("
) and '
with single quotes ('
) to make the text more readable and properly formatted. If you have any further questions or need assistance with anything else, please feel free to ask.
英文:
I use face-api in node js. When I match two images , the result
always return the same value like "Similarity: person 1 (0)
FaceMatch { _label: 'person 1', _distance: 0 }"
Node js FaceRecognition Class
const path = require('path');
class FaceRecognition {
constructor() {
this.faceMatcher = null;
}
async compareFaces(imgPath1, imgPath2) {
try {
// Load the models
await this.loadModel();
// Load the images
const image1 = await canvas.loadImage(imgPath1);
const image2 = await canvas.loadImage(imgPath2);
// Detect faces in the images
const face1 = await faceapi.detectSingleFace(image1).withFaceLandmarks().withFaceDescriptor();
const face2 = await faceapi.detectSingleFace(image2).withFaceLandmarks().withFaceDescriptor();
// Check if faces were detected in both images
if (face1 && face2) {
// Create an array of face descriptors
const faceDescriptors = [face1.descriptor];
// Create a FaceMatcher with the face descriptors
const faceMatcher = new faceapi.FaceMatcher(faceDescriptors);
// Compare the face descriptors of the second image
const result = faceMatcher.findBestMatch(face2.descriptor);
// Output the result
console.log(`Similarity: ${result.toString()}`);
return result;
} else {
throw new Error('Unable to detect faces in one or both images.');
}
} catch (error) {
console.error(`Error occurred: ${error}`);
throw error;
}
}
}
The result you provided indicates that the similarity comparison between the two faces resulted in a match labeled as "person 1" with a distance of 0. This suggests that the faces in the two images are considered to be highly similar or identical according to the comparison algorithm.
The label "person 1" and the distance of 0 indicate a perfect match between the two faces. The algorithm has determined that the face in the second image is the same as the face in the first image.
It's important to note that the exact label and distance values may vary depending on the specific implementation and the dataset used for training the face matching model. In your case, the result shows that the faces are considered a match with a distance of 0, indicating a very close resemblance.
If you have any further questions or if there's anything else I can assist you with, please let me know.
Chatpgt answers me like that but I don't think so.
What is the problem ? Can you help me ?
答案1
得分: 0
我修复了生成两幅图像描述并将描述与faceapi.euclidean距离匹配的问题。
英文:
I fix the issue with generating two image's description, and matching the descriptions with faceapi.euclidean Distance.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论