示例#1
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
示例#2
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)

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

            # *===================*
            # | Performed Process |
            # *===================*
            yolo_result = obj.run(img_path)

            if re.match('person', yolo_result):
                Colors.print_sucess("[PROCESSING] Person Detected !")
                Colors.print_infos("[PROCESSING] Running Extract Faces Processing...")

                # print(img_path)
                Colors.print_infos("[PROCESSING] Extract Faces {}/{}".format(cpt + 1, len(data.image)))
                t1 = time.time()
                result = fd.ExtractFace(cv2.imread(img_path), "Data/IMAGE_DB/" + str(data.name[cpt]) + "/result_" + str(cpt))
                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)
示例#3
0
 def __init__(self,
              user='******',
              passwd='zmpass',
              host='localhost',
              database='zm'):
     try:
         self._db = mysql.connector.connect(host=host,
                                            user=user,
                                            passwd=passwd,
                                            database=database)
     except mysql.connector.Error as err:
         Colors.print_error("\n[ERROR] Could not connect to " + host + "\n")
         traceback.print_exc()
         exit(1)
示例#4
0
    def _load_and_align_images(self, filepaths):
        aligned_images = []
        for filepath in filepaths:
            # print(filepath)
            img = cv2.imread(filepath)
            if img is not None:
                aligned = self._align_face(img)
                aligned = (aligned / 255.).astype(np.float32)
                aligned = np.expand_dims(aligned, axis=0)
                aligned_images.append(aligned)
            else:
                Colors.print_error("[ERROR] File Not Found in ImageDatabases: " + filepath)

        return np.array(aligned_images)
示例#5
0
            if "car" in yolo_result.Result[
                    cpt] or "truck" in yolo_result.Result[cpt]:
                if yolo_result.Result[cpt] not in result_voit:
                    result_voit += " " + yolo_result.Result[cpt]

        # *======================================*
        # | Remove Images that nothings detected |
        # *======================================*
        cpt = 0
        # sql = SQLHelpers()
        for im1 in images:
            for im2 in yolo_result.Images:
                if im1 not in im2:
                    id = re.findall(r'\b\d+\b', im1)
                    if len(id) == 2:
                        Colors.print_error("[DELETE] Delete Images : " + im1 +
                                           " With Id : " + str(id[1]))
                        # sql.delete_frames(str(id[0]), str(id[1]))
                        os.system("rm -rfv " + im1)
                    cpt += 1

    if result_pers:
        Colors.print_sucess("Person Detected : " + result_pers)

    if result_voit:
        Colors.print_sucess("Voiture Detected : " + result_voit)

    Colors.print_sucess("\n[SUCCESS] Finished with Total processing time : " +
                        str(round(time.time() - t1, 3)) + " s")

    _remove_lock()
    del images