def process_img(self, frame): image, kp, mask, max_bbox, center = frame # pad pad = (self.res, self.res) image, kp, center = pad_img(image, pad, kp, center) # crop around center crop = (300, 300) # crop = (int(max_bbox * self.bbox_factor), int(max_bbox * self.bbox_factor)) image, kp, center = crop_img(image, crop, kp=kp, center=center) # resize image image, kp, center = resize_img(image, to_shape=self.shape, kp=kp, center=center) return image, kp, mask, max_bbox, center
def process_img(self, frame): image, kp, kp_mask, bbox_wh, center = frame bb_w, bb_h = bbox_wh max_bbox = np.max(bbox_wh) (h, w, _) = image.shape real_bb_ratio = min(w / bb_w, h / bb_h) # padding sides: mirror edges to both sides img_length = max(w, h) image, kp, center = double_margin(image, new_margin=0.5, c=center, kp=kp, ratio=real_bb_ratio, l=img_length, bb_h=bb_h, bb_w=bb_w) image, kp, center = double_margin(image, new_margin=1., c=center, kp=kp, ratio=real_bb_ratio, l=img_length, bb_h=bb_h, bb_w=bb_w) if self.align_parity: left_eye = kp_mask[6] right_eye = kp_mask[10] if not left_eye and right_eye: image, kp = invert_img(image, kp) # resize image to intended final resolution image, kp, _ = resize_img(image, self.shape, kp=kp) # kp_x, kp_y = kp # # kp_x = [kp * kp_mask[k] for k, kp in enumerate(kp_x)] # todo mask out hidden kp: set to zero # kp_y = [kp * kp_mask[k] for k, kp in enumerate(kp_y)] # kp = [kp_x, kp_y] return image, kp, kp_mask, max_bbox, center
def process_img(self, frame): img, kp, bg_mask, max_bbox, center, action = frame if self.use_mask: # crop = (max_bbox, max_bbox) # img, kp, center = crop_img(img, crop, center=center, kp=kp) # bg_mask, _, _ = crop_img(bg_mask, crop, center=center, kp=None) bckgr = np.empty(img.shape) bckgr.fill(255) # 255 for white for i in range(3): img[:, :, i] = bg_mask * img[:, :, i] + ( 1 - bg_mask) * bckgr[:, :, i] # mask out image background img, kp, center = pad_img(img, kp=kp, center=center, mode='constant') c = int(max_bbox) crop = (c, c) img, kp, center = crop_img(img, crop=crop, center=center, kp=kp) img, kp, center = resize_img(img, to_shape=self.shape, center=center, kp=kp) else: crop = [max_bbox, max_bbox] img, kp, center = pad_crop_resize(img, crop, to_shape=self.shape, kp=kp, center=center) mask = None return img, kp, mask, max_bbox, center
def process_img(self, image): image = resize_img(image, self.shape) return image