|
1 | 1 |
|
| 2 | +from sldatasets.annotations import Human |
2 | 3 | from os import path as osp
|
3 | 4 | import numpy as np
|
4 |
| -from sldatasets.body import Human |
| 5 | +from sldatasets.annotations import Human as H, Frame_annotation as fa, BodyPart |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def positions_mat_to_npz(path=None):
|
@@ -94,42 +95,27 @@ def process_video(video, e):
|
94 | 95 | for j in range(0, n):
|
95 | 96 | img = video[j, :]
|
96 | 97 | humans = e.inference(img, True, 4.0)
|
| 98 | + h = H([]) |
97 | 99 | if len(humans) != 1:
|
98 | 100 | b = True
|
99 | 101 | else:
|
100 |
| - h = Human([]) |
101 |
| - h.body_parts = humans[0].body_parts |
102 |
| - h.score = humans[0].score |
103 |
| - frames.append(humans) |
| 102 | + h = translate(humans, h) |
| 103 | + frames.append(fa(h)) |
104 | 104 | if b:
|
105 | 105 | raise InferenceError(frames)
|
106 | 106 | return frames
|
107 | 107 |
|
108 | 108 |
|
| 109 | +def translate(humans, h): |
| 110 | + body = {} |
| 111 | + for key, part in humans[0].body_parts.items(): |
| 112 | + body[key] = BodyPart(part.uidx, part.part_idx, |
| 113 | + part.x, part.y, part.score) |
| 114 | + h.body_parts = body |
| 115 | + h.score = humans[0].score |
| 116 | + return h |
| 117 | + |
| 118 | + |
109 | 119 | class InferenceError(Exception):
|
110 | 120 | def __init__(self, arg):
|
111 | 121 | self.args = arg
|
112 |
| - |
113 |
| - |
114 |
| -def translate_tf_pose_humans(npz_file): |
115 |
| - from sldatasets.body import Human |
116 |
| - npz = np.load(npz_file) |
117 |
| - data = {} |
118 |
| - for video in npz.files: |
119 |
| - video_annotation = npz[video] |
120 |
| - n = video_annotation.size |
121 |
| - result = np.empty((n,), dtype=object) |
122 |
| - for i, frame_annotation in enumerate(video_annotation): |
123 |
| - h = Human([]) |
124 |
| - try: |
125 |
| - human = frame_annotation[0] |
126 |
| - h.body_parts = human.body_parts |
127 |
| - h.score = human.score |
128 |
| - except: |
129 |
| - print('frame', str(i), ' of video ', video, |
130 |
| - " has no annotations. processing videos wait...") |
131 |
| - result[i] = h |
132 |
| - data[video] = result |
133 |
| - outfile = osp.join(osp.dirname(npz_file), 'positions.npz') |
134 |
| - np.savez(outfile, **data) |
135 |
| - return outfile |
0 commit comments