#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 23 05:29:05 2021

@author: ngbla
"""
from __future__ import print_function
import cv2 as cv
import argparse

# Begin fonction  
def detectAndDisplay(frame):
    #face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
    #face_cascade = cv.CascadeClassifier('webcammer-master/haarcascade_frontalface_default.xml')
    #eyes_cascade = cv.CascadeClassifier('webcammer-master/haarcascade_eye.xml')

    parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.')
    parser.add_argument('--face_cascade', help='Path to face cascade.', default='webcammer-master/haarcascade_frontalface_alt.xml')
    parser.add_argument('--eyes_cascade', help='Path to eyes cascade.', default='webcammer-master/haarcascade_eye_tree_eyeglasses.xml')
    parser.add_argument('--camera', help='Camera divide number.', type=int, default=0)
    args = parser.parse_args()
    
    face_cascade_name = args.face_cascade
    eyes_cascade_name = args.eyes_cascade
    
    face_cascade = cv.CascadeClassifier()
    eyes_cascade = cv.CascadeClassifier()
    
    #-- 1. Load the cascades (verification de l'existences des fichier xml)
    if not face_cascade.load(cv.samples.findFile(face_cascade_name)):
        print('--(!)Error loading face cascade')
        exit(0)
    if not eyes_cascade.load(cv.samples.findFile(eyes_cascade_name)):
        print('--(!)Error loading eyes cascade')
        exit(0)
        
    #-- Image en Gris
    frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    frame_gray = cv.equalizeHist(frame_gray)

    #-- Detect faces
    faces = face_cascade.detectMultiScale(frame_gray)
    for (x,y,w,h) in faces:
        center = (x + w//2, y + h//2)
        #frame = cv.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4)
        frame = cv.rectangle(frame,(x,y),(x+w,y+h),(255, 0, 255),2)
        #-- Affichage du nom de la personne
        text ="<NAME>"
        cv.putText(frame,text,(x,y), 
                   cv.FONT_HERSHEY_SIMPLEX,0.45,(0,0,255),2 );
        
        faceROI = frame_gray[y:y+h,x:x+w]
        #-- In each face, detect eyes
        eyes = eyes_cascade.detectMultiScale(faceROI)
        for (x2,y2,w2,h2) in eyes:
            eye_center = (x + x2 + w2//2, y + y2 + h2//2)
            radius = int(round((w2 + h2)*0.25))
            frame = cv.circle(frame, eye_center, radius, (255, 0, 0 ), 4)
    cv.imshow('Capture - Face detection', frame)
# End fonction   
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 23 05:29:05 2021

@author: ngbla
"""
from __future__ import print_function
import cv2 as cv
import argparse

# Begin fonction  
def detectAndDisplay(frame):
    #face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
    #face_cascade = cv.CascadeClassifier('webcammer-master/haarcascade_frontalface_default.xml')
    #eyes_cascade = cv.CascadeClassifier('webcammer-master/haarcascade_eye.xml')

    parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.')
    parser.add_argument('--face_cascade', help='Path to face cascade.', default='webcammer-master/haarcascade_frontalface_alt.xml')
    parser.add_argument('--eyes_cascade', help='Path to eyes cascade.', default='webcammer-master/haarcascade_eye_tree_eyeglasses.xml')
    parser.add_argument('--camera', help='Camera divide number.', type=int, default=0)
    args = parser.parse_args()
    
    face_cascade_name = args.face_cascade
    eyes_cascade_name = args.eyes_cascade
    
    face_cascade = cv.CascadeClassifier()
    eyes_cascade = cv.CascadeClassifier()
    
    #-- 1. Load the cascades (verification de l'existences des fichier xml)
    if not face_cascade.load(cv.samples.findFile(face_cascade_name)):
        print('--(!)Error loading face cascade')
        exit(0)
    if not eyes_cascade.load(cv.samples.findFile(eyes_cascade_name)):
        print('--(!)Error loading eyes cascade')
        exit(0)
        
    #-- Image en Gris
    frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    frame_gray = cv.equalizeHist(frame_gray)

    #-- Detect faces
    faces = face_cascade.detectMultiScale(frame_gray)
    for (x,y,w,h) in faces:
        center = (x + w//2, y + h//2)
        #frame = cv.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4)
        frame = cv.rectangle(frame,(x,y),(x+w,y+h),(255, 0, 255),2)
        #-- Affichage du nom de la personne
        text ="<NAME>"
        cv.putText(frame,text,(x,y), 
                   cv.FONT_HERSHEY_SIMPLEX,0.45,(0,0,255),2 );
        
        faceROI = frame_gray[y:y+h,x:x+w]
        #-- In each face, detect eyes
        eyes = eyes_cascade.detectMultiScale(faceROI)
        for (x2,y2,w2,h2) in eyes:
            eye_center = (x + x2 + w2//2, y + y2 + h2//2)
            radius = int(round((w2 + h2)*0.25))
            frame = cv.circle(frame, eye_center, radius, (255, 0, 0 ), 4)
    cv.imshow('Capture - Face detection', frame)
# End fonction   
#!/usr/bin/env python3 # -*- coding: utf-8 -*- Created on Wed Jun 23 05:29:05 2021  @author: ngbla # Begin fonction #face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') #face_cascade = cv.CascadeClassifier('webcammer-master/haarcascade_frontalface_default.xml') #eyes_cascade = cv.CascadeClassifier('webcammer-master/haarcascade_eye.xml') #-- 1. Load the cascades (verification de l'existences des fichier xml) #-- Image en Gris #-- Detect faces #frame = cv.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4) #-- Affichage du nom de la personne #-- In each face, detect eyes # End fonction