forked from Phonicavi/dv-posenet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (62 loc) · 2.17 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/local/anaconda2/bin/python
from __future__ import print_function
from PA import parse_args
from H5 import Input, Target, LIMBS
from file_validation import load_names
from matplotlib import pyplot as plt
import cv2
import os
import dataproc.skeleton as sk
def h5_initialize(base_dir):
input_list = ["train_input.h5", "valid_input.h5"]
target_list = ["train_target.h5", "valid_target.h5"]
return (Input(base_dir, input_list[0]), Input(base_dir, input_list[1]),
Target(base_dir, target_list[0]), Target(base_dir, target_list[1]))
def dataset_process(base_dir, save_dir, thick, _set, _list):
[ipt, tgt] = _set
num = len(_list)
if num != ipt.count() or num != tgt.count():
return None
for i in range(1000):
fn = _list[i]
fp = os.path.join(base_dir, fn)
sfn = "%s._marked.png" % fn[:-4]
sfp = os.path.join(save_dir, sfn)
print("[%d/%d] >> %s" % (i + 1, num, fn))
# show_rank(ipt.rank[i])
# show_rankMat(ipt.rankMat[i])
raw_img = cv2.cvtColor(cv2.imread(fp, cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)
img2 = sk.draw_vec_skel2D_16(ipt.S2d[i], ipt.rankMat[i], raw_img, thick, tgt.S3d[i])
#img2 = sk.draw_wrongs_skel2D_16(ipt.S2d[i], ipt.rankMat[i], raw_img, thick, tgt.S3d[i])
img = sk.draw_skel2D_16(tgt.S2d[i], img2, (255,255,255) ,1)
cv2.imwrite(sfp, cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
# plt.imshow(img)
# plt.pause(0.001)
#
# plt.show()
print('[DataProc] set finished ... ')
def show_rank(mat):
for i in range(LIMBS):
print("%d " % mat[i], end='')
print()
def show_rankMat(mat):
for i in range(LIMBS):
for j in range(LIMBS):
print("%.3f " % mat[i][j], end='')
pass
print()
print()
if __name__ == "__main__":
option = parse_args()
bp_annot = option.path_ann
bp_img = option.path_img
bp_img_marked = option.path_img_marked
t_input, v_input, t_target, v_target = h5_initialize(option.dir_data)
train_set = [t_input, t_target]
valid_set = [v_input, v_target]
train_list = load_names(bp_annot, "train_images.txt")
valid_list = load_names(bp_annot, "valid_images.txt")
pairs = [(valid_set, valid_list), (train_set, train_list)]
for _s, _l in pairs:
dataset_process(bp_img, bp_img_marked, option.thick, _s, _l)
#break # train_set first