mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
feat: fix faceId loop error caused by async (#3651)
This commit is contained in:
parent
9610ce5b8c
commit
30789138e2
@ -289,20 +289,20 @@ const FaceRecognitionModal = (props) => {
|
|||||||
<p>{i18next.t("general:Click to Upload")}</p>
|
<p>{i18next.t("general:Click to Upload")}</p>
|
||||||
</Dragger >
|
</Dragger >
|
||||||
{
|
{
|
||||||
modelsLoaded ? <Button style={{width: "100%"}} onClick={() => {
|
modelsLoaded ? <Button style={{width: "100%"}} onClick={async() => {
|
||||||
let maxScore = 0;
|
let maxScore = 0;
|
||||||
files.forEach((file, fileIndex) => {
|
for (const file of files) {
|
||||||
|
const fileIndex = files.indexOf(file);
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = file.base64;
|
img.src = file.base64;
|
||||||
faceapi.detectAllFaces(img, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptors().then(res2 => {
|
const faceIds = await faceapi.detectAllFaces(img, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptors();
|
||||||
if (res2[0]?.detection.score > 0.9 && res2[0]?.detection.score > maxScore) {
|
if (faceIds[0]?.detection.score > 0.9 && faceIds[0]?.detection.score > maxScore) {
|
||||||
maxScore = res2[0]?.detection.score;
|
maxScore = faceIds[0]?.detection.score;
|
||||||
setCurrentFaceId(res2[0]);
|
setCurrentFaceId(faceIds[0]);
|
||||||
setCurrentFaceIndex(fileIndex);
|
setCurrentFaceIndex(fileIndex);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
if (maxScore < 0.9) {
|
||||||
if (currentFaceId?.length === 0) {
|
|
||||||
message.error(i18next.t("login:Face recognition failed"));
|
message.error(i18next.t("login:Face recognition failed"));
|
||||||
}
|
}
|
||||||
}}> {i18next.t("application:Generate faceId")}</Button> : null
|
}}> {i18next.t("application:Generate faceId")}</Button> : null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user