Skip to content

Instantly share code, notes, and snippets.

@AnthonyLzq
Last active January 24, 2023 04:27
Show Gist options
  • Save AnthonyLzq/e06f9950b89dee1ecc9812efc1f15607 to your computer and use it in GitHub Desktop.
Save AnthonyLzq/e06f9950b89dee1ecc9812efc1f15607 to your computer and use it in GitHub Desktop.
Script to compare faces using Human
const compareFaces = async (
image1: string,
image2: string,
log: logger
) => {
await init(log)
const [res1, res2] = await Promise.all([
detect(decodeImage(Buffer.from(readFileSync(image1)))),
detect(decodeImage(Buffer.from(readFileSync(image1))))
])
if (
!res1 ||
!res1.face ||
res1.face.length === 0 ||
!res1.face[0].embedding ||
!res2 ||
!res2.face ||
res2.face.length === 0 ||
!res2.face[0].embedding
)
throw new CustomError('Could not detect face descriptors')
const similarity = global.__human__.match.similarity(
res1.face[0].embedding,
res2.face[0].embedding,
{ order: 2 }
)
const result = {
match: similarity > 0.5
}
log.info(result, 'Similarity result')
return result
}
compareFaces('img1.png', 'img2.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment