def __init__(self):
        self.ROOT_PATH = os.path.dirname(sys.modules['__main__'].__file__)
        self.azureService = Azure()
        self.codeError = 0
        self.gotAttributes = False
        self.frame = None
        self.framesTrain = None
        self.bb_service = []
        # self.service = None
        self.name = "desconocido"
        self.id_debug = None
        self.faceId = ""
        self.accuracy = None
        self.age = 0  #
        self.gender = ""  #male-female
        self.smile = 0  #0-1
        self.pose = {}  #dict pitch, roll, yaw (double)
        self.emotion = None  #anger, contempt, disgust, fear, happiness, neutral, sadness, surprise
        self.beard = 0  #0-1
        self.glasses = ""  #glasses - noglasses
        self.eyesOpen = 0
        self.mouthOpen = 0
        self.bald = 0  #número
        self.hairColor = ""  #brown, blond, red, gray, other, black
        self.sideburns = 0  #0-1
        self.eyeMakeUp = False  #true-false
        self.lipMakeUp = False  #true-false
        self.headWear = 0  #0-1
        self.mask = 0
        self.mustache = 0  #0-1

        self.bb_actual = []
        self.image_actual = None
        self.imageBBPair = ([], None)
        self.happiness = 0
        self.sadness = 0
        self.neutral = 0
        self.surprise = 0
        self.anger = 0

        self.table = 0
        self.country = ""
        self.id = ""
        self.id_azure = ""
        self.interaction = 0

        self.lastInteractionTime = 0
        self.G = Group()

        self.bb = []
Exemplo n.º 2
0
    def __init__(self):
        self.ROOT_PATH = os.path.dirname(sys.modules['__main__'].__file__)
        self.azureService = Azure()
        self.codeError = 0
        self.gotAttributes = False
        self.frame = None
        self.framesTrain = None
        self.bb_service = []
        # self.service = None
        self.name = "desconocido"
        self.id_debug = None
        self.faceId = ""
        self.accuracy = None
        self.age = 0
        self.gender = ""
        self.smile = 0
        self.pose = {}
        self.emotion = None
        self.beard = 0
        self.glasses = ""
        self.eyesOpen = 0
        self.mouthOpen = 0
        self.bald = 0
        self.hairColor = ""
        self.sideburns = 0
        self.eyeMakeUp = False
        self.lipMakeUp = False
        self.headWear = 0
        self.mask = 0
        self.mustache = 0

        self.bb_actual = []
        self.image_actual = None
        self.imageBBPair = ([], None)
        self.happiness = 0
        self.sadness = 0
        self.neutral = 0
        self.surprise = 0
        self.anger = 0

        self.table = 0
        self.country = ""
        self.id = ""
        self.id_azure = ""
        self.interaction = 0

        self.lastInteractionTime = 0
        self.image = None
        self.G = Group()
Exemplo n.º 3
0
 def add_person(self, name, capture):
     G = Group()
     personsList = G.persons
     add = False
     for i in range(len(personsList)):
         if (G.persons[i].name == name):
             print('Person already added')
             add = True
             break
     if not add:
         #cap = cv2.VideoCapture(0)
         cap = capture
         images = {}
         print('Tomando fotos')
         for i in range(5):
             ret, frame = cap.read()
         for i in range(20):
             #print('FOTO: '+str(i))
             ret, frame = cap.read()
             frame = frame[115:600, 320:960]
             frame = cv2.flip(frame, 0)
             frame = cv2.flip(frame, 1)
             # cv2.imshow('image',frame)
             # print("Press Enter to Exit")
             # cv2.waitKey(0)
             time.sleep(0.3)
             frame = cv2.GaussianBlur(frame, (5, 5), 0)
             images[i] = frame
         #cap.release()
         self.blurry.sort_less_blurred(images)
         self.persons.enrol(name, self.blurry.frames)
         return 1
     return 0
 def add_person(self, name):
     G = Group()
     personsList = G.persons
     add = False
     for i in range(len(personsList)):
         if (G.persons[i].name == name):
             print('Person already added')
             add = True
             break
     if not add:
         cap = cv2.VideoCapture(1)
         cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
         cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
         cap.set(cv2.CAP_PROP_FPS, 10)
         #cap = capture
         images = {}
         print('Tomando fotos')
         for i in range(5):
             ret, frame = cap.read()
         for i in range(20):
             print('FOTO: ' + str(i))
             ret, frame = cap.read()
             frame = frame[115:600, 320:960]
             frame = cv2.flip(frame, 0)
             frame = cv2.flip(frame, 1)
             cv2.imshow('image', frame)
             time.sleep(0.3)
             frame = cv2.GaussianBlur(frame, (5, 5), 0)
             images[i] = frame
         cap.release()
         self.blurry.sort_less_blurred(images)
         self.persons.enrol(name, self.blurry.frames)
         return 1
     return 0
Exemplo n.º 5
0
 def delete_all_person(self):
     G = Group()
     personsList = G.persons
     for i in range(len(personsList)):
         self.delete_person(G.persons[i].name)
     ids = self.persons.azureService.get_all_names()
     for person in ids[0]:
         self.persons.azureService.delete_person(person['personId'])
Exemplo n.º 6
0
    def get_persons_attributes(self):
        G = Group()
        for p in G.persons:
            print(p)
        return G.persons


# c = Characterization("local")
# c.get_persons()
# c.indentify_person(True)
Exemplo n.º 7
0
 def get_person_attribute(self, name):
     G = Group()
     personsList = G.persons
     id = -1
     for i in range(len(personsList)):
         if (G.persons[i].name == name):
             id = i
             break
     if (id == -1):
         print('Person not recognized')
         return {}
     else:
         attributes = {'age':G.persons[id].age, 'gender':G.persons[id].gender, 'smile':G.persons[id].smile, 'glasses':G.persons[id].glasses, \
                     'bald':G.persons[id].bald, 'hairColor':G.persons[id].hairColor, 'eyeMakeUp':G.persons[id].eyeMakeUp, 'lipMakeUp':G.persons[id].lipMakeUp, \
                     'headWear':G.persons[id].headWear, 'mustache':G.persons[id].mustache, 'beard':G.persons[id].beard}
         return attributes
class Person:
    def __init__(self):
        self.ROOT_PATH = os.path.dirname(sys.modules['__main__'].__file__)
        self.azureService = Azure()
        self.codeError = 0
        self.gotAttributes = False
        self.frame = None
        self.framesTrain = None
        self.bb_service = []
        # self.service = None
        self.name = "desconocido"
        self.id_debug = None
        self.faceId = ""
        self.accuracy = None
        self.age = 0  #
        self.gender = ""  #male-female
        self.smile = 0  #0-1
        self.pose = {}  #dict pitch, roll, yaw (double)
        self.emotion = None  #anger, contempt, disgust, fear, happiness, neutral, sadness, surprise
        self.beard = 0  #0-1
        self.glasses = ""  #glasses - noglasses
        self.eyesOpen = 0
        self.mouthOpen = 0
        self.bald = 0  #número
        self.hairColor = ""  #brown, blond, red, gray, other, black
        self.sideburns = 0  #0-1
        self.eyeMakeUp = False  #true-false
        self.lipMakeUp = False  #true-false
        self.headWear = 0  #0-1
        self.mask = 0
        self.mustache = 0  #0-1

        self.bb_actual = []
        self.image_actual = None
        self.imageBBPair = ([], None)
        self.happiness = 0
        self.sadness = 0
        self.neutral = 0
        self.surprise = 0
        self.anger = 0

        self.table = 0
        self.country = ""
        self.id = ""
        self.id_azure = ""
        self.interaction = 0

        self.lastInteractionTime = 0
        self.G = Group()

        self.bb = []

    def frame2bytes(self, frame):
        retval, encoded_image = cv2.imencode('.png', frame)
        return encoded_image.tobytes()

    def check_img(self, frame):
        if type(frame) != bytes:
            return self.frame2bytes(frame)
        else:
            return frame

    def enrol(self, id, frames):
        person_id, self.codeError = self.azureService.create_person(id)
        success_list = []
        if person_id is not None:
            self.id_azure = person_id
            #print('enrol'+str(len(frames)))
            for frame in frames:
                imgBytes = self.check_img(frame)
                successEnrol, self.codeError = self.azureService.add_face(
                    imgBytes, person_id, frame)
                success_list.append(successEnrol)
            if self.azureService.attributes:
                for key, value in self.azureService.attributes.items():
                    setattr(self, key, value)
                self.G.add(
                    PersonFiles(id, person_id, self.hairColor, self.glasses,
                                self.gender, self.age, self.smile, self.pose,
                                self.emotion, self.beard, self.eyesOpen,
                                self.mouthOpen, self.bald, self.sideburns,
                                self.eyeMakeUp, self.lipMakeUp, self.headWear,
                                self.mask, self.mustache))
            self.azureService.train()
        return success_list.count(True)

    def identify(self, frame):
        self.reset_attributes()
        self.frame = frame
        imgBytes = self.check_img(frame)
        attributes, self.codeError = self.azureService.identify(imgBytes)
        if attributes:
            for key, value in attributes.items():
                setattr(self, key, value)
            self.gotAttributes = True
            return True
        else:
            self.reset_attributes()
            return False

    def identifyPerson(self, frame):
        personsList = self.persons_in_group()
        isIdentified = self.identify(frame)
        if isIdentified:
            for person in personsList:
                if person['personId'] == self.id_azure:
                    self.name = person['name']
                    print('Person Identified: {}'.format(self.name))
                    break
        else:
            print('The person was not identified !!')

    def delete_person_by_name(self, name):
        deleted = False
        personsList, self.codeError = self.azureService.get_all_names()
        for person in personsList:
            if person['name'] == name:
                self.azureService.delete_person(person['personId'])
                deleted = True
                print('Person: {} Deleted !!'.format(name))
                self.G.delete(name)
                break
        if not deleted:
            print('Person: {} Not Found !!'.format(name))

    def persons_in_group(self):
        personsList, self.codeError = self.azureService.get_all_names()
        return personsList

    def reset_attributes(self):
        attrNoEdit = [
            'azureService', 'debug', 'ROOT_PATH', 'db_handler', 'information'
        ]
        for attr in dir(self):
            if not callable(getattr(self, attr)) and not attr.startswith(
                    "__") and attr not in attrNoEdit:
                if attr == 'name':
                    setattr(self, attr, "desconocido")
                else:
                    if type(getattr(self, attr)) == int:
                        setattr(self, attr, 0)
                    elif type(getattr(self, attr)) == str:
                        setattr(self, attr, "")
                    elif type(getattr(self, attr)) == bool:
                        setattr(self, attr, False)
                    elif type(getattr(self, attr)) == dict:
                        setattr(self, attr, {})
                    elif type(getattr(self, attr)) == tuple:
                        setattr(self, attr, ([], None))
                    else:
                        setattr(self, attr, None)
Exemplo n.º 9
0
 def get_persons_attributes(self):
     G = Group()
     for p in G.persons:
         print(p)
     return G.persons
Exemplo n.º 10
0
 def get_persons(self):
     G = Group()
     personsList = G.persons
     return personsList
Exemplo n.º 11
0
class Person:
    def __init__(self):
        self.ROOT_PATH = os.path.dirname(sys.modules['__main__'].__file__)
        self.azureService = Azure()
        self.codeError = 0
        self.gotAttributes = False
        self.frame = None
        self.framesTrain = None
        self.bb_service = []
        # self.service = None
        self.name = "desconocido"
        self.id_debug = None
        self.faceId = ""
        self.accuracy = None
        self.age = 0
        self.gender = ""
        self.smile = 0
        self.pose = {}
        self.emotion = None
        self.beard = 0
        self.glasses = ""
        self.eyesOpen = 0
        self.mouthOpen = 0
        self.bald = 0
        self.hairColor = ""
        self.sideburns = 0
        self.eyeMakeUp = False
        self.lipMakeUp = False
        self.headWear = 0
        self.mask = 0
        self.mustache = 0

        self.bb_actual = []
        self.image_actual = None
        self.imageBBPair = ([], None)
        self.happiness = 0
        self.sadness = 0
        self.neutral = 0
        self.surprise = 0
        self.anger = 0

        self.table = 0
        self.country = ""
        self.id = ""
        self.id_azure = ""
        self.interaction = 0

        self.lastInteractionTime = 0
        self.image = None
        self.G = Group()

    def frame2bytes(self, frame):
        retval, encoded_image = cv2.imencode('.png', frame)
        return encoded_image.tobytes()

    def check_img(self, frame):
        if type(frame) != bytes:
            return self.frame2bytes(frame)
        else:
            return frame

    def enrol(self, id, frames):
        person_id, self.codeError = self.azureService.create_person(id)
        succes = False
        if person_id is not None:
            self.id_azure = person_id
            for frame in frames:
                imgBytes = self.check_img(frame)
                successEnrol, self.codeError = self.azureService.add_face(
                    imgBytes, person_id)
                if successEnrol:
                    succes = True
                    if self.azureService.attributes:
                        for key, value in self.azureService.attributes.items():
                            setattr(self, key, value)
                        self.image = frame
                        self.G.add(
                            PersonFiles(id, person_id, self.hairColor,
                                        self.glasses, self.gender, self.age))
            if succes:
                self.azureService.train()
            else:
                print('No entrenado')
        return person_id

    def identify(self, frame):
        self.reset_attributes()
        self.frame = frame
        imgBytes = self.check_img(frame)
        identify, error = self.azureService.identify(imgBytes)
        # print('IDENTIFY VERIFICATION: ', identify)
        return identify

    def identifyPerson(self, frame):
        personsList = self.persons_in_group()
        people = self.identify(frame)
        for person in personsList:
            if people['verify_recognition']:
                if person['personId'] == people['id_azure']:
                    people['name'] = person['name']
                    print('Person Identified: {}'.format(person['name']))
            else:
                people['name'] = 'Desconocido'
        return people

    def faceDetector(self, frame):
        self.frame = frame
        #cap = cv2.VideoCapture(0)
        #ret, img = cap.read()
        rgb_frame = frame[:, :, ::-1]
        frame_size = frame.shape[0] * frame.shape[1]
        face_locations = face_recognition.face_locations(rgb_frame)
        peoples = list()
        print(face_locations)

        for face_location in face_locations:
            #cv2.rectangle(frame, (face_location[1], face_location[0]), (face_location[3], face_location[2]), (255, 255, 0), 2)
            width = face_location[1] - face_location[3]
            height = face_location[2] - face_location[0]
            dictionary_of_features = {
                'faceId': None,
                'faceRectangle': {
                    'width': int(width),
                    'top': int(face_location[0]),
                    'height': int(height),
                    'left': int(face_location[3])
                },
                'faceAttributes': None
            }
            peoples.append(dictionary_of_features)
        peoples.sort(key=sortDictionary, reverse=True)

        return peoples

    def detectPerson(self, frame):
        self.frame = frame
        # imgBytes = self.check_img(frame)
        people = self.faceDetector(frame)
        print(people)
        return people

    def delete_persons(self):
        deleted = False
        personsList, self.codeError = self.azureService.get_all_names()
        for person in personsList:
            self.azureService.delete_person(person['personId'])
            deleted = True
            print('Person: {} Deleted !!'.format(person['personId']))
            break
        if not deleted:
            print('Person: {} Not Found !!'.format(person['personId']))

    def delete_person_by_name(self, name):
        deleted = False
        personsList, self.codeError = self.azureService.get_all_names()
        for person in personsList:
            if person['name'] == name:
                self.azureService.delete_person(person['personId'])
                deleted = True
                print('Person: {} Deleted !!'.format(name))
                self.G.delete(name)
                break
        if not deleted:
            print('Person: {} Not Found !!'.format(name))

    def persons_in_group(self):
        personsList, self.codeError = self.azureService.get_all_names()
        return personsList

    def reset_attributes(self):
        attrNoEdit = [
            'azureService', 'debug', 'ROOT_PATH', 'db_handler', 'information'
        ]
        for attr in dir(self):
            if not callable(getattr(self, attr)) and not attr.startswith(
                    "__") and attr not in attrNoEdit:
                if attr == 'name':
                    setattr(self, attr, "desconocido")
                else:
                    if type(getattr(self, attr)) == int:
                        setattr(self, attr, 0)
                    elif type(getattr(self, attr)) == str:
                        setattr(self, attr, "")
                    elif type(getattr(self, attr)) == bool:
                        setattr(self, attr, False)
                    elif type(getattr(self, attr)) == dict:
                        setattr(self, attr, {})
                    elif type(getattr(self, attr)) == tuple:
                        setattr(self, attr, ([], None))
                    else:
                        setattr(self, attr, None)
 def delete_all_person(self):
     G = Group()
     personsList = G.persons
     for i in range(len(personsList)):
         self.delete_person(G.persons[i].name)