MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / __call__

Method __call__

PATH/core/augmentation.py:66–126  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

64 self.half = half
65
66 def __call__(self, img):
67 ## transform
68 scale_diff_h = (np.random.rand()*2-1)*self.scale_aug
69 scale_diff_w = (np.random.rand()*2-1)*self.scale_aug
70 crop_aug_h = self.crop_size*(1+scale_diff_h)
71 crop_aug_w = self.crop_size*(1+scale_diff_w)
72
73 trans_diff_h = (np.random.rand()*2-1)*self.trans_aug
74 trans_diff_w = (np.random.rand()*2-1)*self.trans_aug
75
76 h, w, _ = img.shape
77 ct_x = (w/2+self.crop_center_x_offset)*(1+trans_diff_w)
78 ct_y = (h/2+self.crop_center_y_offset)*(1+trans_diff_h)
79
80 if ct_x < crop_aug_w/2:
81 crop_aug_w = ct_x*2 - 0.5
82 if ct_y < crop_aug_h/2:
83 crop_aug_h = ct_y*2 - 0.5
84 if ct_x + crop_aug_w/2 >= w:
85 crop_aug_w = (w-ct_x)*2 - 0.5
86 if ct_y + crop_aug_h/2 >= h:
87 crop_aug_h = (h-ct_y)*2 - 0.5
88
89 #rect = (ct_x-crop_aug_w/2, ct_y-crop_aug_h/2, ct_x+crop_aug_w/2, ct_y+crop_aug_h/2)
90 #img = img.resize((self.final_size, self.final_size), box=rect)
91 t = int(np.ceil(ct_y-crop_aug_h/2))
92 #d = int(np.ceil(ct_y+crop_aug_h/2))
93 l = int(np.ceil(ct_x-crop_aug_w/2))
94 #r = int(np.ceil(ct_x+crop_aug_w/2))
95 img = img[t:int(t+crop_aug_h),l:int(l+crop_aug_w),:]
96
97 img = cv2.resize(img, (self.final_size, self.final_size))
98
99 if self.half == 1:
100
101 img[:self.final_size // 2, :] = 0
102
103 elif self.half == -1:
104
105 img[self.final_size // 2 :, :] = 0
106
107 #self.mask_aug = 1
108 if self.mask_aug > 0:
109
110 seed = np.random.rand()
111 aug = self.final_size // 2 * min(np.random.rand() + 0.1, 1)
112 if seed < self.mask_aug / 2:
113 img[:int(self.final_size//2-aug), :] = 0
114 elif seed < self.mask_aug:
115 img[int(self.final_size//2+aug):, :] = 0
116
117 #print(self.flip)
118 if np.random.rand() <= self.flip:
119 #print('do flip')
120 img = cv2.flip(img, 1)
121
122 ## to BGR
123 #img = np.array(img)

Callers

nothing calls this directly

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected