-
Notifications
You must be signed in to change notification settings - Fork 21
/
shrec17_process.py
42 lines (41 loc) · 1.79 KB
/
shrec17_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import re
import os
import cv2
import pdb
import copy
import utils
import imageio
import numpy as np
if __name__ == "__main__":
pts_size = 256
r = re.compile('[ \t\n\r]+')
dataset_prefix = "./SHREC2017"
prefix = dataset_prefix + "/gesture_{}/finger_{}/subject_{}/essai_{}"
train_list = open(dataset_prefix + "/train_gestures.txt").readlines()
test_list = open(dataset_prefix + "/test_gestures.txt").readlines()
input_list = train_list + test_list
for idx, line in enumerate(input_list):
# Loading dataset
splitLine = r.split(line)
dir_path = prefix.format(splitLine[0], splitLine[1], splitLine[2], splitLine[3])
print(idx, len(input_list), dir_path)
hand_regions = np.loadtxt(dir_path + '/general_informations.txt').astype(int)
pts = np.zeros((32, pts_size, 8), dtype=int)
ind = utils.key_frame_sampling(int(splitLine[-2]), 32)
hand_regions = hand_regions[ind]
depth_video = []
for i, frame_id in enumerate(ind):
# Reconstruct point cloud sequence from depth video
depth_image = imageio.imread(dir_path + "/{}_depth.png".format(frame_id))
depth_video.append(depth_image)
hand_crop = depth_image[hand_regions[i][2]:hand_regions[i][2] + hand_regions[i][4],
hand_regions[i][1]:hand_regions[i][1] + hand_regions[i][3]]
hand_crop = cv2.medianBlur(hand_crop, 3)
pts[i, :, :4] = utils.generate_pts_cloud_sequence(hand_crop, hand_regions, pts_size, i)
pts[i, :, 4:8] = utils.uvd2xyz_sherc(copy.deepcopy(pts[i, :, :4]))
save_dir = utils.insert(dir_path, "Processed_", 2)
try:
os.makedirs(save_dir)
except FileExistsError:
pass
np.save(save_dir + "/pts_label.npy", pts)