File size: 4,614 Bytes
ec7f7c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import random
import copy
import numpy as np

def pose_aug_diff(pose, size, offset, scale, aspect_ratio_range, add_aug=True):

    h, w = size
    if h >= w: 
        new_h = int(h*1024/w)
        new_w = 1024
    else:
        new_h = 1024
        new_w = int(w*1024/h)

    # bodies = pose[0]['bodies']
    # hands = pose[0]['hands']
    # candidate = bodies['candidate']

    # center = candidate[0]
    # pose_refer = copy.deepcopy(pose[0])
    
    if add_aug:

        # offset = random.uniform(*offset)
        offset_x, offset_y = offset
        offset_x = random.uniform(*offset_x)
        offset_y = random.uniform(*offset_y)
        scale = random.uniform(*scale)
        asp_ratio = random.uniform(*aspect_ratio_range)

        # for p in pose:

        #     # adjust ratio
        #     p['bodies']['candidate'][:, 0] = p['bodies']['candidate'][:, 0] * asp_ratio
        #     p['hands'][:, :, 0] = p['hands'][:, :, 0] * asp_ratio

        #     # scale the pose
        #     p['hands'] *= scale
        #     p['bodies']['candidate'] *= scale

        #     # move the center of pose
        #     p['hands'] += offset
        #     p['bodies']['candidate'] += offset

        # run align
        # pose_aug = run_align_video_with_filterPose_translate_smooth_woload(pose, pose_refer, size, frame_num=len(pose), align_pose=True)

        _pose = copy.deepcopy(pose)
        
        # adjust ratio
        pose['bodies']['candidate'][:, 0] = pose['bodies']['candidate'][:, 0] * asp_ratio
        pose['hands'][:, :, 0] = pose['hands'][:, :, 0] * asp_ratio

        # scale the pose
        pose['hands'] *= scale
        pose['bodies']['candidate'] *= scale

        # # move the center of pose
        # # offset_x, offset_y = offset
        # # pose['hands'] += offset
        # pose['hands'][:, :, 0] += offset_x
        # pose['hands'][:, :, 1] += offset_y
        # # pose['bodies']['candidate'] += offset
        # pose['bodies']['candidate'][:, 0] += offset_x
        # pose['bodies']['candidate'][:, 1] += offset_y

        _offset = _pose['bodies']['candidate'][1] - pose['bodies']['candidate'][1]

        pose['bodies']['candidate'] += _offset[np.newaxis, :]
        pose['faces'] += _offset[np.newaxis, np.newaxis, :]
        pose['hands'] += _offset[np.newaxis, np.newaxis, :]

        return pose


def pose_aug_same(pose, size, offset, scale, asp_ratio, add_aug=True):

    h, w = size
    if h >= w: 
        new_h = int(h*1024/w)
        new_w = 1024
    else:
        new_h = 1024
        new_w = int(w*1024/h)

    # bodies = pose[0]['bodies']
    # hands = pose[0]['hands']
    # candidate = bodies['candidate']

    # center = candidate[0]
    # pose_refer = copy.deepcopy(pose[0])
    
    if add_aug:

        # offset = random.uniform(*offset)
        # scale = random.uniform(*scale)
        # asp_ratio = random.uniform(*aspect_ratio_range)

        # for p in pose:

        #     # adjust ratio
        #     p['bodies']['candidate'][:, 0] = p['bodies']['candidate'][:, 0] * asp_ratio
        #     p['hands'][:, :, 0] = p['hands'][:, :, 0] * asp_ratio

        #     # scale the pose
        #     p['hands'] *= scale
        #     p['bodies']['candidate'] *= scale

        #     # move the center of pose
        #     p['hands'] += offset
        #     p['bodies']['candidate'] += offset

        # run align
        # pose_aug = run_align_video_with_filterPose_translate_smooth_woload(pose, pose_refer, size, frame_num=len(pose), align_pose=True)

        _pose = copy.deepcopy(pose)
        
        # adjust ratio
        pose['bodies']['candidate'][:, 0] = pose['bodies']['candidate'][:, 0] * asp_ratio
        pose['hands'][:, :, 0] = pose['hands'][:, :, 0] * asp_ratio

        # scale the pose
        pose['hands'] *= scale
        pose['bodies']['candidate'] *= scale

        # # move the center of pose
        # offset_x, offset_y = offset
        # # pose['hands'] += offset
        # pose['hands'][:, :, 0] += offset_x
        # pose['hands'][:, :, 1] += offset_y
        # # pose['bodies']['candidate'] += offset
        # pose['bodies']['candidate'][:, 0] += offset_x
        # pose['bodies']['candidate'][:, 1] += offset_y

        _offset = _pose['bodies']['candidate'][1] - pose['bodies']['candidate'][1]

        pose['bodies']['candidate'] += _offset[np.newaxis, :]
        pose['faces'] += _offset[np.newaxis, np.newaxis, :]
        pose['hands'] += _offset[np.newaxis, np.newaxis, :]

        return pose