Last active
January 15, 2017 13:22
-
-
Save conanak99/211c932d7b347130a0d5742ee03d9f44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nhận diện vị trí khuôn mặt và tên idol từ URL ảnh | |
function recognize(imageUrl) { | |
console.log(`Begin to recognize image: ${imageUrl}`); | |
var detectedFaces = detect(imageUrl); | |
if (detectedFaces.length == 0) { | |
console.log("Can't detect any face"); | |
return; | |
} | |
// Sau khi đã phát hiện các khuôn mặt, | |
// So sánh chúng với mặt đã có trong person group | |
var identifiedResult = identify(detectedFaces.map(face => face.faceId)); | |
var allIdols = identifiedResult.map(result => { | |
// Lấy vị trí khuôn mặt trong ảnh để hiển thị | |
result.face = detectedFaces.filter(face => face.faceId == result.faceId)[0].faceRectangle; | |
// Tìm idol đã được nhận diện từ file idol-person. | |
if (result.candidates.length > 0) { | |
// Kết quả chỉ trả về ID, dựa vào ID này ta tìm tên của idol | |
var idolId = result.candidates[0].personId; | |
var idol = idolPerson.filter(person => person.personId == idolId)[0]; | |
result.idol = { | |
id: idol.userData, | |
name: idol.name | |
}; | |
} else { | |
result.idol = { | |
id: 0, | |
name: 'Unknown' | |
} | |
} | |
return result; | |
}); | |
console.log(`Finish recognize image: ${imageUrl}`); | |
return allIdols; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment