def conv9(): detect_cv = detect.FaceDetectorCV() detect_dnn = detect.FaceDetectorDNN(".") path_dir_root = "/home/nobuyuki/project/face/rect_manual" for path_csv in glob.glob(path_dir_root + "/**/*.csv", recursive=True): dict_data = detect.get_csv_data(path_csv) bnwe_md5 = os.path.basename(path_csv).split(".", 1)[0] path_dir = path_csv.rsplit("/", 1)[0] ext = ".png" if not os.path.isfile(path_dir + "/" + bnwe_md5 + ext): ext = ".jpg" path_img = path_dir + "/" + bnwe_md5 + ext # print(path_img) img = cv2.imread(path_img) #### reject image if you don't like rect_cv2 = detect_cv.get_one_face(img) rect_dnn = detect_dnn.get_one_face(img) # print(rect_dnn) #### if rect_cv2 is not None: dict_data["rect_face_cv"] = str(rect_cv2[0]) + "," + str( rect_cv2[1]) + "," + str(rect_cv2[2]) + "," + str(rect_cv2[3]) if rect_dnn is not None: dict_data["rect_face_dnn"] = str(rect_dnn[0]) + "," + str( rect_dnn[1]) + "," + str(rect_dnn[2]) + "," + str(rect_dnn[3]) detect.save_csv_data(path_csv, dict_data)
def conv8(): path_dir_root = "/Volumes/PortableHDD/face/rect_cv" for path_csv in glob.glob(path_dir_root + "/**/*.csv", recursive=True): dict_data = detect.get_csv_data(path_csv) if not "url_name" in dict_data: continue url_name = dict_data["url_name"] if not os.path.isfile(path_dir_root + "/x/" + url_name): continue bnwe_md5 = os.path.basename(path_csv).split(".", 1)[0] path_dir = path_csv.rsplit("/", 1)[0] ext = ".png" if not os.path.isfile(path_dir + "/" + bnwe_md5 + ext): ext = ".jpg" path_img = path_dir + "/" + bnwe_md5 + ext print(path_img) path_img_rect = path_dir + "/" + bnwe_md5 + "_rect.png" assert os.path.isfile(path_img_rect) assert os.path.isfile(path_csv) assert os.path.isfile(path_img) print(path_csv) print(path_img_rect) print(path_img) os.remove(path_csv) os.remove(path_img_rect) os.remove(path_img)
def conv3(): key_old = "face_rect" key_new = "rect_face_manual" for path_csv in glob.glob("/Volumes/PortableHDD/face/rect_manual/*.csv"): # print(path_csv) dict_data = detect.get_csv_data(path_csv) detect.swap_keyword(key_old, key_new, dict_data) print(dict_data) detect.save_csv_data(path_csv, dict_data)
def conv11(): #path_dir_root = "/home/nobuyuki/project/face/rect_manual" #path_dir_root = "/Volumes/PortableHDD/rect_manual" path_dir_root = "/Volumes/PortableHDD/umet55" for path_csv in glob.glob(path_dir_root + "/**/*.csv", recursive=True): dict_data = detect.get_csv_data(path_csv) bnwe_md5 = os.path.basename(path_csv).split(".", 1)[0] path_dir = path_csv.rsplit("/", 1)[0] ext = ".png" if not os.path.isfile(path_dir + "/" + bnwe_md5 + ext): ext = ".jpg" path_img = path_dir + "/" + bnwe_md5 + ext img = cv2.imread(path_img) print(path_csv, img.shape) dict_data["shape_img"] = str(img.shape[0]) + "," + str(img.shape[1]) detect.save_csv_data(path_csv, dict_data)
def load_file(path_dir): global dict_path_csv_datetime list_path_img = [] list_path_img = glob.glob(path_dir + '/*.jpg', recursive=True) + list_path_img list_path_img = glob.glob(path_dir + '/*.png', recursive=True) + list_path_img print(list_path_img) for path_img in list_path_img: path_without_ext = path_img.rsplit(".")[0] if os.path.isfile(path_without_ext + ".csv"): continue file = open(path_without_ext + ".csv", "w") ### dict_path_csv_datetime = {} if os.path.isfile(path_dir + "/dict_path_csv__datetime.p"): dict_path_csv_datetime = pickle.load( open(path_dir + "/dict_path_csv__datetime.p", "rb")) list_path_csv = glob.glob(path_dir + "/**/*.csv", recursive=True) print("number of csv files:", len(list_path_csv)) for path_csv in list_path_csv: if path_csv in dict_path_csv_datetime: continue dict_data = detect.get_csv_data(path_csv) if "last_looked" in dict_data: dt0 = datetime.datetime.strptime(dict_data["last_looked"], '%Y-%m-%d %H:%M:%S.%f') else: dt0 = datetime.datetime.now() dt0 -= datetime.timedelta(days=random.randint(10, 20)) dt0 += datetime.timedelta(seconds=random.randint(0, 60)) dict_path_csv_datetime[path_csv] = dt0 pickle.dump(dict_path_csv_datetime, open(path_dir + "/dict_path_csv__datetime.p", "wb")) print("load dict finished")
def conv7(): path_dir_root = "/Volumes/PortableHDD/face/rect_cv" hex = [str(format(i, 'x')) for i in range(0, 16)] print(hex) for ch in hex: if not os.path.isdir(path_dir_root + "/" + ch): os.mkdir(path_dir_root + "/" + ch) for path_csv in glob.glob(path_dir_root + "/**/*.csv", recursive=True): dict_data = detect.get_csv_data(path_csv) bn = os.path.basename(path_csv) bnwe = bn.rsplit(".", 1)[0] path_dir_img = os.path.dirname(path_csv) ext_img = ".png" if not os.path.isfile(path_dir_img + "/" + bnwe + ext_img): ext_img = ".jpg" dict_data["url_name"] = bnwe + ext_img detect.save_csv_data(path_csv, dict_data) path_img = path_dir_img + "/" + bnwe + ext_img assert os.path.isfile(path_img) bnwe_md5 = detect.getMD5(path_img) print(bn, bnwe_md5)
def set_id_path(): global img_size_info, dict_info, view_mode ### img = detect.get_imgage_train(path_csv_current) dict_info = detect.get_csv_data(path_csv_current) #### id_tex_org = img_size_info[4] if id_tex_org is not None and glIsTexture(id_tex_org): glDeleteTextures(id_tex_org) img_size_info = detect_gl.loadTexture(img) if view_mode == "ORIGINAL": glutReshapeWindow(img_size_info[0], img_size_info[1]) #### if "last_looked" in dict_info: print(path_csv_current, " ", dict_info["last_looked"]) else: print(path_csv_current) #### list_rect = detect.get_list_rect_from_dict_info(dict_info) if view_mode.startswith("CENTER"): ir = int(view_mode.split("_")[1]) if ir >= len(list_rect): view_mode = "ORIGINAL"
def keyboard(bkey, x, y): global view_mode, dict_info, edit_mode, path_csv_current, dict_path_csv_datetime key = bkey.decode("utf-8") dt0 = datetime.datetime.now() if key == 'w': pickle.dump(dict_path_csv_datetime, open(path_dir + "/dict_path_csv__datetime.p", "wb")) if key == "W": os.remove(path_dir + "/dict_path_csv__datetime.p") load_file(path_dir) path_csv_current = get_oldest_path(dict_path_csv_datetime) set_id_path() if key == 'd': save(dt0) ### path_csv_current = get_oldest_path(dict_path_csv_datetime) set_id_path() if key == 'D': dt1 = dt0 - datetime.timedelta(days=random.randint(40, 100)) save(dt1) ### path_csv_current = get_newest_path(dict_path_csv_datetime) set_id_path() if key == 'c': if edit_mode == "LIP_TOP-DOWN": dict_info.pop("lip_top", None) dict_info.pop("lip_down", None) if edit_mode == "NOSE_TIP": dict_info.pop("nose_tip", None) if edit_mode == "NOSE_TOP": dict_info.pop("nose_top", None) if edit_mode == "RIGHT_EYE_CORNER-TAIL": dict_info.pop("right_eye_corner") dict_info.pop("right_eye_tail", None) if edit_mode == "LEFT_EYE_CORNER-TAIL": dict_info.pop("left_eye_corner", None) dict_info.pop("left_eye_tail", None) if edit_mode == "RECT_FACE": dict_info.pop("rect_face_manual", None) if key == 'X': # move to trash box print(path_csv_current) dir_dist = os.path.abspath( os.path.dirname(path_csv_current) + "/../xtrash") csv_data = detect.get_csv_data(path_csv_current) base_md5 = path_csv_current.rsplit(".", 1)[0] ext = ".png" if not os.path.isfile(base_md5 + ext): ext = ".jpg" assert os.path.isfile(base_md5 + ext) if "url_name" in csv_data: url_name = csv_data["url_name"] print(ext, base_md5, url_name) os.remove(path_csv_current) os.rename(base_md5 + ext, dir_dist + "/" + url_name) print("move to trash", dir_dist + "/" + url_name) else: os.remove(path_csv_current) os.remove(base_md5 + ext) del dict_path_csv_datetime[path_csv_current] path_csv_current = min(dict_path_csv_datetime, key=dict_path_csv_datetime.get) set_id_path() if key == '`': if not "no_face" in dict_info: dict_info["no_face"] = "True" else: del dict_info["no_face"] if key == '1': edit_mode = "LIP_TOP-DOWN" if key == '2': edit_mode = "NOSE_TIP" if key == '3': edit_mode = "RIGHT_EYE_CORNER-TAIL" if key == '4': edit_mode = "LEFT_EYE_CORNER-TAIL" if key == '5': edit_mode = "NOSE_TOP" if key == '0': edit_mode = "RECT_FACE" if key == ' ': list_rect = detect.get_list_rect_from_dict_info(dict_info) print(len(list_rect)) if view_mode == "ORIGINAL": if len(list_rect) > 0: view_mode = "CENTER_0" glutReshapeWindow(600, 600) else: assert view_mode.startswith("CENTER") ir = int(view_mode.split("_")[1]) if ir + 1 >= len(list_rect): view_mode = "ORIGINAL" glutReshapeWindow(img_size_info[0], img_size_info[1]) else: view_mode = "CENTER_" + str(ir + 1) glutReshapeWindow(600, 600) print(view_mode) if key == 'q': exit() glutPostRedisplay()