Skip to content

Commit 0c493fc

Browse files
Merge pull request justadudewhohacks#135 from rawrmonstar/tegan/fix-detect-single-face-task
DetectSingleFaceTask should return faceDetection with highest confidence
2 parents 6b101df + 346fec8 commit 0c493fc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/globalApi/DetectFacesTasks.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ export class DetectAllFacesTask extends DetectFacesTaskBase<FaceDetection[]> {
5858
export class DetectSingleFaceTask extends DetectFacesTaskBase<FaceDetection | undefined> {
5959

6060
public async run(): Promise<FaceDetection | undefined> {
61-
return (await new DetectAllFacesTask(this.input, this.options))
62-
.sort((f1, f2) => f1.score - f2.score)[0]
61+
const faceDetections = await new DetectAllFacesTask(this.input, this.options);
62+
let faceDetectionWithHighestScore = faceDetections[0];
63+
faceDetections.forEach(faceDetection => {
64+
if (faceDetection.score > faceDetectionWithHighestScore.score) {
65+
faceDetectionWithHighestScore = faceDetection;
66+
}
67+
});
68+
return faceDetectionWithHighestScore;
6369
}
6470

6571
withFaceLandmarks(useTinyLandmarkNet: boolean = false): DetectSingleFaceLandmarksTask {

0 commit comments

Comments
 (0)