Exemple #1
0
def save(dt0: datetime):
    global dict_path_csv_datetime, dict_info
    dict_info["last_looked"] = str(dt0)
    dict_info["shape_img"] = str(img_size_info[1]) + "," + str(
        img_size_info[0])
    detect.save_csv_data(path_csv_current, dict_info)
    dict_path_csv_datetime[path_csv_current] = dt0
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
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)
Exemple #6
0
def conv12(path_dir_root):
    is_cuda = torch.cuda.is_available()
    if is_cuda:
        print("using GPU")
    else:
        print("using CPU")

    net_d, net_c, net_l = detect.load_detection_network(is_cuda, '.')
    ######
    print("select good and bad:", path_dir_root)
    list_path_img = []
    list_path_img = glob.glob(path_dir_root + '/xinbox/*.jpg',
                              recursive=True) + list_path_img
    list_path_img = glob.glob(path_dir_root + '/xinbox/*.png',
                              recursive=True) + list_path_img
    print("there is ", len(list_path_img), "images")
    for path_img in list_path_img:
        if not os.path.isfile(path_img):
            continue
        npImg = cv2.imread(path_img)
        if npImg is None:
            continue
        ####
        print(npImg.shape[0], npImg.shape[1])
        list_rect_dnn0 = detect.detect_face_dnn_multires(net_d,
                                                         net_c,
                                                         net_l,
                                                         npImg,
                                                         threshold_prob=0.6)
        for rect in list_rect_dnn0:
            detect.highlight_rect(npImg, rect, (255, 255, 0), width=1)
        list_rect_dnn = detect.marge_rects(list_rect_dnn0)
        for rect in list_rect_dnn:
            detect.highlight_rect(npImg, rect, (0, 255, 255), width=2)
        cv2.imshow('img', npImg)
        key = cv2.waitKey(100)
        ikey = int(key)
        print(ikey)
        if ikey == 113:
            exit()
        '''
        if key == 8: # delete key
            path_img_new = path_dir_root + '/xtrash/' + os.path.basename(path_img)
            print("move_to_trash")
            shutil.move(path_img, path_img_new)
            continue

        if ikey != 32: #space key
            print("this image is bad. do nothing")
            continue
        '''
        ### md5
        bnwe_md5 = detect.getMD5(path_img)
        ext = path_img.rsplit(".", 1)[1]
        dir_dist = path_dir_root + "/" + str(bnwe_md5[0])
        path_img_new = dir_dist + "/" + bnwe_md5 + "." + ext
        print(path_img_new, dir_dist)

        if os.path.isfile(path_img_new):
            print("there is already one:")
            os.remove(path_img)
            continue

        ### register image
        print("found new iamge:", path_img, path_img_new)

        shutil.move(path_img, path_img_new)

        dict_data = {}
        dict_data["url_name"] = os.path.basename(path_img)
        dict_data["shape_img"] = str(npImg.shape[0]) + "," + str(
            npImg.shape[1])
        if len(list_rect_dnn) > 0:
            str_csv = detect.get_str_csv_list_rect(list_rect_dnn)
            dict_data["rect_face_dnn"] = str_csv
        detect.save_csv_data(dir_dist + "/" + bnwe_md5 + ".csv", dict_data)