示例#1
0
 def saving_faces(faces, pickle_face):
     Colors.print_infos("\n[SAVING] Serializing Faces...")
     f = open(pickle_face, "wb")
     f.write(pickle.dumps(faces))
     f.close()
     del f
     Colors.print_sucess("[SUCCESS] Serializing Faces Completed...\n")
示例#2
0
def _getting_config(max_threads):
    # *=============================*
    # |  Read the ini config file   |
    # *=============================*
    Colors.print_infos("[INFOS] Reading config detector.ini...")
    config = ConfigParser(interpolation=ExtendedInterpolation())
    config.read(config_path)

    # *=============================*
    # | Create Face/object detector |
    # *=============================*
    Colors.print_infos(
        "[INFOS] Loading object/Face detector and Recognizer ...")
    object_detector = create_object_detector(config, max_threads)
    face_detector = create_face_detector(config)
    recognizer = Recognizer(
        config['Training']["data_Pickle"], config['Training']['train_embs'],
        config['FaceDetectorTiny']['Tiny_Face_detection_model'],
        config['Model']['OPENFACE_NN4_SMALL2_V1_H5'],
        config['Model']['PREDICATOR_68_FACE_LANDMARKS'])

    Colors.print_sucess(
        "[SUCCESS] Object/Face detector and Recognizer Loaded !")
    return _convert_boolean(
        config['General']['use_facial_recognizion']
    ), _convert_boolean(config['General']['use_alpr']), config['Training'][
        "data_Pickle"], object_detector, face_detector, recognizer, config
示例#3
0
def _training(object_detector, face_detector, pickle_data):
    Colors.print_sucess("[NEW] New Image Detected Run Analyse...\n")
    ex = ExtractFaces()
    ex.run(face_detector, object_detector, pickle_data)
    Colors.print_infos("[INFOS] Reloading the Serialized Data")
    recognizer.data = Serializer.loading_data(pickle_data)
    del ex
示例#4
0
def _extractfaces(yolo_result, face_detector):
    faces_extracted = []
    bbox_list = []
    faces_images = []
    cpt = 0

    score_final, average_image, clusters_w, clusters_h, normal_idx, clusters, session = _load_model(
        face_detector)

    with tf.compat.v1.Session() as sess:
        sess.run(tf.compat.v1.global_variables_initializer())

        for x in yolo_result.Images:
            if "person" in yolo_result.Result[cpt]:
                Colors.print_infos(
                    "[PROCESSING] Person was detected !\n"
                    "[PROCESSING] Running extract face process...\n")

                faces, refined_bbox = face_detector.detectFaceTiny(
                    cv2.imread(x), score_final, average_image, clusters_w,
                    clusters_h, normal_idx, clusters, session, sess)
                Colors.print_sucess("\n[PROCESSING] " + str(len(faces)) +
                                    " Face(s) Found(s)\n")

                faces_images.append(x)
                faces_extracted.append(faces)
                bbox_list.append(refined_bbox)

    Colors.print_sucess("[SUCESS] Extracted FINISHED")

    return [faces_extracted, bbox_list, faces_images]
示例#5
0
def _reconignizing(face_detector, reco, imgPath):
    # *==================*
    # | Extract the Face |
    # *==================*
    Colors.print_infos("[INFOS] Person Was detected !\n"
                       "[PROCESSING] Running Detect Face Process...\n")

    result = face_detector.detectFaceTiny(frame=cv2.imread(imgPath))
    faces = result[0]
    refined_bbox = result[1]
    del result

    Colors.print_sucess("\n[PROCESSING] " + str(len(faces)) +
                        " Face Detected\n")

    if len(faces) > 0 and faces is not None:
        Colors.print_infos("[PROCESSING] Running Facial Recognizing...\n")

        result = reco.run(faces, face_detector, cv2.imread(imgPath),
                          refined_bbox)

        if result is not None:
            Colors.print_sucess("\n[SUCESS] Detected Person: " +
                                str(result[1]) + " \n")
            try:
                cv2.imwrite(imgPath, result[0])
                cv2.destroyAllWindows()
                return result[1]
            except:
                pass
        else:
            return None
示例#6
0
 def start_threads(self):
     cpt = 0
     for thread in self.list_thread:
         if not thread.is_alive():
             thread.start()
             cpt += 1
             Colors.print_infos("[INFOS] Starting Thread {0}/{1}...".format(cpt, self.thread_launched))
示例#7
0
 def waiting_threads(self):
     for thread in self.list_thread:
         if thread.is_alive():
             while thread.is_alive():
                 Colors.print_infos("[INFOS] Waiting Thread...\n")
                 self.thread_launched -= 1
                 thread.join()
示例#8
0
 def saving_static(obj, pickle_obj):
     Colors.print_infos("\n[SAVING] Serializing Static object...")
     f = open(pickle_obj, "wb")
     f.write(pickle.dumps(obj))
     f.close()
     del f
     Colors.print_sucess(
         "[SUCCESS] Serializing Static object Completed...\n")
示例#9
0
 def saving_data(data, pickle_data):
     Colors.print_infos("\n[SAVING] Serializing Preformated Data...")
     # Serialize the model
     f = open(pickle_data, "wb")
     f.write(pickle.dumps(data))
     f.close()
     del f
     Colors.print_sucess("[SUCCESS] Serializing Completed\n")
示例#10
0
 def loading_data(pickle_data):
     if path.isfile(pickle_data):
         Colors.print_infos("[LOADING] Loading Data Serialised...")
         # Load the serialised Data
         data = pickle.loads(open(pickle_data, "rb").read())
         Colors.print_sucess("[LOADING] Loading Data Completed\n")
         return data
     else:
         Colors.print_error("[ERROR] File Not Found : " + str(pickle_data))
         return None
示例#11
0
    def loading_static(pickle_obj):
        Colors.print_infos("[LOADING] Loading Static object...")
        obj = []

        # Load the serialised Data
        data = pickle.loads(open(pickle_obj, "rb").read())
        for d in data:
            obj.append(d)
        del data

        Colors.print_sucess("[LOADING] Loading Static object Completed\n")
        return obj
示例#12
0
    def loading_faces(pickle_face):
        Colors.print_infos("[LOADING] Loading Faces Serialised...")
        faces = []

        # Load the serialised Data
        data = pickle.loads(open(pickle_face, "rb").read())
        for d in data:
            faces.append(d)
        del data

        Colors.print_sucess("[LOADING] Loading Faces Completed\n")
        return faces
示例#13
0
def _top():
    os.system("clear")
    Colors.print_infos(
        "\n*-----------------------------------------------------*\n"
        "| __author__ = Jordan BERTIEAUX                       |\n"
        "| __copyright__ = Copyright 2020, Facial Recognition  |\n"
        "| __credits__ = [Jordan BERTIEAUX]                    |\n"
        "| __license__ = GPL                                   |\n"
        "| __version__ = 1.0                                   |\n"
        "| __maintainer__ = Jordan BERTIEAUX                   |\n"
        "| __email__ = [email protected]             |\n"
        "| __status__ = Production                             |\n"
        "*-----------------------------------------------------*\n")
示例#14
0
    def run(self):
        cpt = 0
        for img in self.list_img:
            self.list_thread.append(ObjectDetector(self._confidence, self.threshold, self._data_load, self._show_percent, self.override_zm, self._lock, self, img, self.pattern))
            self.thread_launched += 1
            Colors.print_infos("[PROCESSING] Detection process {0}/{1}".format(cpt + 1, len(self.list_img)))
            cpt += 1
            if self.thread_launched == self.max_thread:
                self.start_threads()
                self.waiting_threads()
                self.clean_thread()

        data = {'Result': self._result_temp,
                'Images': self._image_temp}

        self.cleanning()
        return pd.DataFrame(data)
示例#15
0
def _reconignizing(face_detector, reco, imgPath, faces, refined_bbox):
    if len(faces) > 0 and faces is not None:
        Colors.print_infos("[PROCESSING] Running Facial Recognizing...\n")

        result = reco.run(faces, face_detector, cv2.imread(imgPath),
                          refined_bbox)

        if result is not None:
            Colors.print_sucess("\n[SUCCESS] Found Person: " + str(result[1]) +
                                " \n")
            try:
                cv2.imwrite(imgPath, result[0])
                cv2.destroyAllWindows()
                return result[1]
            except:
                pass
        else:
            return None
示例#16
0
    def __init__(self, pickle_data, pickle_embs, tiny_model, openface_model, predicator_landmarks):
        self.data = Serializer.loading_data(pickle_data)
        self._pickles_embs = pickle_embs
        self._train_paths = glob.glob("Data/IMAGE_DB/*")
        self._nb_classes = len(self._train_paths)
        self._label_index = []

        self._tinyFace_model = tiny_face_model.Model(tiny_model)
        self._nn4_small2 = create_model()

        Colors.print_infos("[LOADING] Load the model size of openface")
        Colors.print_infos("[LOADING] Align the face Predicator 68 Face Landmarks")
        # self._nn4_small2.summary()

        self._nn4_small2.load_weights(openface_model)
        self._alignment = AlignDlib(predicator_landmarks)

        Colors.print_sucess("[LOADING] Loading Model Completed\n")
示例#17
0
 def wait_lock(self):
     if self._lock.locked():
         while self._lock.locked() is True:
             Colors.print_infos("[INFOS] Waiting unlocked thread...")
示例#18
0
    clusters_h = clusters[:, 3] - clusters[:, 1] + 1
    clusters_w = clusters[:, 2] - clusters[:, 0] + 1
    normal_idx = np.where(clusters[:, 4] == 1)

    return [
        score_final, average_image, clusters_w, clusters_h, normal_idx,
        clusters, x
    ]


# ============================================= < MAIN FUNCTION > =====================================================

if __name__ == "__main__":
    while _check_running():
        time.sleep(1)
        Colors.print_infos("[INFOS] Waiting end !")

    # *=====================*
    # | Getting Args/Config |
    # *=====================*
    _enable_lock()
    _top()
    imagesdb, images, pattern, config_path, max_threads = _getting_args()
    use_FacialRecognizer, use_ALPR, pickle_data, object_detector, face_detector, recognizer, config = _getting_config(
        max_threads)

    # *==========================*
    # |  Check Training Process  |
    # *==========================*
    _training(object_detector, face_detector, pickle_data)
示例#19
0
    def run(self, fd, obj, pickle_data):
        # Get list of files in Folder
        data = Serializer.format_data(glob.glob("IMAGE_DB_RAW/*"))

        # *======================*
        # | Create Database Tree |
        # *======================*
        Colors.print_infos("[INFO] Create Folders of databases...\n")
        for name in data.name:
            if not os.path.isdir("Data/IMAGE_DB/" + name):
                os.mkdir("Data/IMAGE_DB/" + name)

        # *===================*
        # | Performed Process |
        # *===================*
        obj.list_img = list(paths.list_images('IMAGE_DB_RAW'))
        obj.override_zm = False
        yolo_result = obj.run()
        obj.override_zm = True

        # *=======================*
        # | Extract Faces Process |
        # *=======================*
        cpt = 0
        t2 = time.time()
        for img_path in yolo_result.Images:
            Colors.print_infos("\n[PROCESSING] Try to Detect a Person...")

            if "person" in yolo_result.Result[cpt]:
                Colors.print_infos(
                    "[PROCESSING] Person(s) Found(s) !"
                    "[PROCESSING] Running Extract Faces Processing...")

                # print(img_path)
                Colors.print_infos("[PROCESSING] Extract Faces {}/{}".format(
                    cpt + 1, len(yolo_result.Images)))
                t1 = time.time()
                path = "Data/IMAGE_DB/" + str(
                    data.name[cpt]) + "/result_" + str(cpt)
                result = fd.ExtractFace(cv2.imread(img_path), path)
                Colors.print_infos(
                    "[PROCESSING] Faces Detected : {} in {} s".format(
                        result,
                        time.time() - t1))
                del t1
                del result
            else:
                Colors.print_error("[PROCESSING] No Face Detected !")
            cpt += 1

        Colors.print_infos("[INFO] Remove file in IMG_DB_RAW...")
        os.system("rm -rfv IMAGE_DB_RAW/*")

        Colors.print_sucess("\n[SUCCESS] Extraction Completed in " +
                            str(round(time.time() - t2, 4)) + " s\n")

        # Cleanning RAM
        del data
        del fd
        del cpt
        del t2

        data = Serializer.format_data(glob.glob("Data/IMAGE_DB/*"))

        # Saving Data
        Serializer.saving_data(data, pickle_data)
示例#20
0
if __name__ == "__main__":
    # *=====================*
    # | Getting Args/Config |
    # *=====================*
    _top()
    imagesdb, images, pattern, config_path = _getting_args()
    use_FacialRecognizer, use_ALPR, pickle_data, object_detector, face_detector, recognizer, config = _getting_config(
    )

    # *==========================*
    # |  Check Training Process  |
    # *==========================*
    if len(imagesdb) > 0:
        _training(object_detector, face_detector, pickle_data)
    else:
        Colors.print_infos("\n[INFO] No Faces to Train now\n")

    t1 = time.time()
    result = ''

    # *========================*
    # | check files to Detect  |
    # |         AND            |
    # | Launch Infos Extractor |
    # *========================*
    if len(images) > 0:
        cpt = 0

        # *=============================*
        # | Running the Object Detector |
        # *=============================*