face_recognition.py
# Este trabalho está licenciado sob a licença MIT.
# Copyright (c) 2013-2023 OpenMV LLC. Todos os direitos reservados.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Reconhecimento facial com descritores LBP.
# Veja "Face Recognition with Local Binary Patterns" de Timo Ahonen.
#
# Antes de executar o exemplo:
# 1) Baixe o banco de dados de rostos da AT&T http://www.cl.cam.ac.uk/Research/DTG/attarchive/pub/data/att_faces.zip
# 2) Extraia e copie o diretório orl_faces para a raiz do cartão SD.
#
# NOTA: Esta é apenas uma implementação PoC do artigo mencionado acima; ela não funciona bem em condições reais.
import image
SUB = "s2"
NUM_SUBJECTS = 5
NUM_SUBJECTS_IMGS = 10
img = image.Image("orl_faces/%s/1.pgm" % (SUB)).mask_ellipse()
d0 = img.find_lbp(roi=(0, 0, img.width(), img.height()))
img = None
print("")
for s in range(1, NUM_SUBJECTS + 1):
dist = 0
for i in range(2, NUM_SUBJECTS_IMGS + 1):
img = image.Image("orl_faces/s%d/%d.pgm" % (s, i)).mask_ellipse()
d1 = img.find_lbp(roi=(0, 0, img.width(), img.height()))
dist += image.match_descriptor(d0, d1)
print("Average dist for subject %d: %d" % (s, dist / NUM_SUBJECTS_IMGS))