#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 25 22:19:35 2019

@author: eye-slash98
"""
#import libraries
from HaarClassifierFunctions import faceFinder as fd
from HaarClassifierFunctions import haarTraining as tr
from HaarClassifierFunctions import boundingBoxes as bd
import cv2
import os
import numpy as np

    
#passing a test image to the classifier
test_img = cv2.imread("./TestImages/luis2.jpg")
face_detected, gray_img = fd.faceDetection(test_img)
print("faces_detected: ", face_detected)


"Training Haar Classifier"

"This part is run only once for training"
#faces, faceID = tr.labels_for_training_data('HaarCascadeDataset')
#face_recognizer = tr.train_classifier(faces, faceID)
#face_recognizer.write('trainingData.yml')
"-----"


"This part is run for testing"
face_recognizer = cv2.face.LBPHFaceRecognizer_create()
face_recognizer.read('./HaarCascadeDataset/trainingData.yml') #use this to load training data for subsquent ones
" --- "

#Dictionary of output
name={0:"<NAME>", 1: "<NAME>", 2:"<NAME>",
      3:"<NAME>", 4: "<NAME>"} 


for face in face_detected:
    (x,y,w,h) = face
    roi_gray = gray_img[y:y+h, x:x+h]
    label,confidence = face_recognizer.predict(roi_gray)#predicting the label
    print("Confidence:",confidence)
    print("label:",label)
    bd.draw_rect(test_img,face)
    predicted_name =  name[label]
    bd.put_text(test_img, predicted_name, x, y)
    
resized_img = cv2.resize(test_img,(500,500))
cv2.imshow("",resized_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 25 22:19:35 2019

@author: eye-slash98
"""
#import libraries
from HaarClassifierFunctions import faceFinder as fd
from HaarClassifierFunctions import haarTraining as tr
from HaarClassifierFunctions import boundingBoxes as bd
import cv2
import os
import numpy as np

    
#passing a test image to the classifier
test_img = cv2.imread("./TestImages/luis2.jpg")
face_detected, gray_img = fd.faceDetection(test_img)
print("faces_detected: ", face_detected)


"Training Haar Classifier"

"This part is run only once for training"
#faces, faceID = tr.labels_for_training_data('HaarCascadeDataset')
#face_recognizer = tr.train_classifier(faces, faceID)
#face_recognizer.write('trainingData.yml')
"-----"


"This part is run for testing"
face_recognizer = cv2.face.LBPHFaceRecognizer_create()
face_recognizer.read('./HaarCascadeDataset/trainingData.yml') #use this to load training data for subsquent ones
" --- "

#Dictionary of output
name={0:"<NAME>", 1: "<NAME>", 2:"<NAME>",
      3:"<NAME>", 4: "<NAME>"} 


for face in face_detected:
    (x,y,w,h) = face
    roi_gray = gray_img[y:y+h, x:x+h]
    label,confidence = face_recognizer.predict(roi_gray)#predicting the label
    print("Confidence:",confidence)
    print("label:",label)
    bd.draw_rect(test_img,face)
    predicted_name =  name[label]
    bd.put_text(test_img, predicted_name, x, y)
    
resized_img = cv2.resize(test_img,(500,500))
cv2.imshow("",resized_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

#!/usr/bin/env python3 # -*- coding: utf-8 -*- Created on Wed Sep 25 22:19:35 2019  @author: eye-slash98 #import libraries #passing a test image to the classifier #faces, faceID = tr.labels_for_training_data('HaarCascadeDataset') #face_recognizer = tr.train_classifier(faces, faceID) #face_recognizer.write('trainingData.yml') #use this to load training data for subsquent ones #Dictionary of output #predicting the label