Exemple #1
0
def main():
    if len(sys.argv) < 3:
        print_usage()

    dataset = sys.argv[1]
    out_file = sys.argv[2]
    data_dir_dict = {
        'nyu': config.nyu_data_dir,
        'icvl': config.icvl_data_dir,
        'msra': config.msra_data_dir,
        'hands17': config.hands_data_dir
    }
    base_dir = data_dir_dict[dataset]  #sys.argv[3]
    batch_size = 64
    if len(sys.argv) == 4:
        batch_size = int(sys.argv[3])

    # generate deploy prototxt
    make_baseline_net(
        os.path.join('/home/boonyew/Documents/PoseRen', 'models/'), dataset)
    make_pose_ren_net(
        os.path.join('/home/boonyew/Documents/PoseRen', 'models/'), dataset)

    hand_model = ModelPoseREN(dataset)
    names = util.load_names(dataset)
    centers = util.load_centers(dataset)
    if dataset == 'msra':
        # the last index of frames belong to the same subject
        msra_id_split_range = np.array(
            [8499, 16991, 25403, 33891, 42391, 50888, 59385, 67883, 76375]) - 1
        results = []
        for test_id in range(9):
            hand_model.reset_model(dataset, test_id)
            sidx = msra_id_split_range[test_id - 1] + 1 if test_id else 0
            eidx = msra_id_split_range[test_id]
            sub_names = names[sidx:eidx + 1]
            sub_centers = centers[sidx:eidx + 1]
            print('evaluating for subject {} ...'.format(test_id))
            sub_results = hand_model.detect_files(base_dir,
                                                  sub_names,
                                                  sub_centers,
                                                  max_batch=batch_size)
            if test_id == 0:
                results = sub_results
            else:
                results = np.concatenate((results, sub_results), axis=0)
        util.save_results(results, out_file)
    else:
        results = hand_model.detect_files(base_dir,
                                          names,
                                          centers,
                                          max_batch=batch_size)
        util.save_results(results, out_file)
Exemple #2
0
def main():
    if len(sys.argv) < 3:
        print_usage()

    dataset = sys.argv[1]
    out_file = sys.argv[2]
    data_dir_dict = {'nyu': config.nyu_data_dir,
                     'icvl': config.icvl_data_dir + 'test/Depth/',
                     'msra': config.msra_data_dir}
    base_dir = data_dir_dict[dataset] #sys.argv[3]
    batch_size = 64
    if len(sys.argv) == 4:
        batch_size = int(sys.argv[3])

    # generate deploy prototxt
    make_baseline_net(os.path.join(ROOT_DIR, '../models'), dataset)
    make_pose_ren_net(os.path.join(ROOT_DIR, '../models'), dataset)

    hand_model = ModelPoseREN(dataset)
    names = util.load_names(dataset)
    centers = util.load_centers(dataset)
    # print("centers = {}".format(np.shape(centers)))
    # c = centers[0]
    # print("centers[0] = {}".format(list(c)))
    if dataset == 'msra':
        # the last index of frames belong to the same subject
        msra_id_split_range = np.array([8499, 16991, 25403, 33891, 42391, 50888, 59385, 67883, 76375]) - 1
        results = []
        for test_id in xrange(9):
            hand_model.reset_model(dataset, test_id)
            sidx = msra_id_split_range[test_id-1] + 1 if test_id else 0
            eidx = msra_id_split_range[test_id]
            sub_names = names[sidx:eidx+1]
            sub_centers= centers[sidx:eidx + 1]
            print('evaluating for subject {} ...'.format(test_id))
            sub_results = hand_model.detect_files(base_dir, sub_names, sub_centers, max_batch=batch_size)
            if test_id == 0:
                results = sub_results
            else:
                results = np.concatenate((results, sub_results), axis=0)
        util.save_results(results, out_file)
    else:
        results = hand_model.detect_files(base_dir, names, centers, max_batch=batch_size)
        print(results[0])
        img = cv2.imread("/media/reborn/Others/Study/Reborn/Github/Pose-REN/test/image_0000.png", 2).astype("float32")
        img_show = show_results(img, results[0], dataset)
        cv2.imwrite('result.jpg', img_show)
        util.save_results(results, out_file)
Exemple #3
0
def main():
    if len(sys.argv) < 3:
        print_usage()

    dataset = sys.argv[1]
    out_file = sys.argv[2]
    # data_dir_dict = {'nyu': config.nyu_data_dir,
    #                  'icvl': config.icvl_data_dir + "test/Depth",
    #                  'msra': config.msra_data_dir}
    # base_dir = data_dir_dict[dataset] #sys.argv[3]
    # name = os.path.join(base_dir, names[0])
    batch_size = 64
    if len(sys.argv) == 4:
        batch_size = int(sys.argv[3])

    # generate deploy prototxt
    make_baseline_net(os.path.join(ROOT_DIR, '../models'), dataset)
    make_pose_ren_net(os.path.join(ROOT_DIR, '../models'), dataset)

    names = util.load_names(dataset)
    # centers = util.load_centers(dataset)
    centers = None
    fx, fy, ux, uy = 587.270, 587.270, 326.548, 230.419
    # fx, fy, ux, uy = util.get_param(dataset)
    lower_ = 1
    upper_ = 650
    hand_model = ModelPoseREN(
        dataset,
        lambda img: get_center(img, lower=lower_, upper=upper_),
        param=(fx, fy, ux, uy),
        use_gpu=True)

    if dataset == 'msra':
        hand_model.reset_model(dataset, test_id=0)

    base_dir = "/media/reborn/Others/Study/Reborn/Github/Pose-REN/test"
    # depthName = os.path.join(base_dir, "000000_depth.bin")
    depthName = os.path.join(base_dir, "0.img")
    imgName = os.path.join(base_dir, "image_0000.png")

    if (dataset == "msra"):
        # with open(depthName,"rb") as file:
        # 	data = np.fromfile(file, dtype=np.uint32)
        # 	width, height, left, top, right , bottom = data[:6]
        # 	depth = np.zeros((height, width), dtype=np.float32)
        # 	file.seek(4*6)
        # 	data = np.fromfile(file, dtype=np.float32)
        # depth[top:bottom, left:right] = np.reshape(data, (bottom-top, right-left))
        # depth[depth == 0] = 10000
        # print(depth[depth < depth.max()])
        # cv2.imwrite("img0.jpg",depth)

        with open(depthName, "rb") as file:
            data = np.fromfile(file, dtype=np.uint16)
            height = 480
            width = 640
            # depth = np.zeros((height, width), dtype=np.uint16)
            depth = np.reshape(data, (height, width)).astype(np.float32)
            min = depth.min()
            max = depth.max()
            print("min = {}, max = {}".format(min, max))

            flag = np.logical_xor(depth <= upper_, depth >= lower_)
            depth[flag] = 0

            kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
            depth = cv2.morphologyEx(depth, cv2.MORPH_CLOSE, kernel)
            depth[depth == 0] = 10000
            # depth[depth == 0] = depth.max()

        # with open(depthName,"rb") as file:
        # 	depth = []
        # 	cnt = 0
        # 	contents = iter(partial(file.read, 2), b'')
        # 	for r in contents:
        # 		r_int = int.from_bytes(r, byteorder='big')  #将 byte转化为 int
        # 		cnt += 1
        # 		depth.append(r_int)
        # 	# print("i = {} -- {}".format(cnt,r_int))
        # depth = np.array(depth)
        # depth = np.reshape(depth,(480,640))
        # depth[depth == 0] = 10000
    elif (dataset == "icvl"):
        depth = cv2.imread(imgName, 2)
        depth[depth == 0] = depth.max()  # invalid pixel
        depth = depth.astype(float)

    # depth = np.reshape(depth,(240,320))
    # depth[depth == 0] = depth.max()
    print("np.shape(depth) = {}".format(np.shape(depth)))
    # depth = depth[:, ::-1]
    # print("names = {}".format(imgName))
    # print("np.shape(img) = {}".format(np.shape(img)))
    # results = hand_model.detect_files(base_dir, names, centers, max_batch=batch_size)
    results = hand_model.detect_image(depth)
    print("results = {}".format(results))
    print(np.shape(results))
    img_show = show_results(depth, results, dataset)
    cv2.imwrite('result.jpg', img_show)
    cv2.waitKey()