def __getitem__(self, index): image_path = self.images[index] kps = self.kp2ds[index].copy() box = self.boxs[index] scale = np.random.rand(4) * (self.scale_range[1] - self.scale_range[0]) + self.scale_range[0] image, kps = cut_image(image_path, kps, scale, box[0], box[1]) ratio = 1.0 * args.crop_size / image.shape[0] kps[:, :2] *= ratio dst_image = cv2.resize(image, (args.crop_size, args.crop_size), interpolation=cv2.INTER_CUBIC) if self.use_flip and random.random() <= self.flip_prob: dst_image, kps = flip_image(dst_image, kps) #normalize kp to [-1, 1] ratio = 1.0 / args.crop_size kps[:, :2] = 2.0 * kps[:, :2] * ratio - 1.0 return { 'image': torch.tensor( convert_image_by_pixformat_normalize(dst_image, self.pix_format, self.normalize)).float(), 'kp_2d': torch.tensor(kps).float(), 'image_name': self.images[index], 'data_set': 'lsp' }
def __getitem__(self, index): imgPath = self.images[index] keyps = self.keyps[index].copy() bbox = self.boxes[index] scale = np.random.rand(4) * (self.scaleRange[1] - self.scaleRange[0]) + self.scaleRange[0] bboxImg, bboxKps = util.cut_image(imgPath, keyps, scale, bbox[0], bbox[1]) ratio = 1.0 * self.cropSize / bboxImg.shape[0] bboxKps[:, :2] *= ratio resImg = cv2.resize(bboxImg, (self.cropSize, self.cropSize), interpolation=cv2.INTER_CUBIC) ratio = 1.0 / self.cropSize bboxKps[:, :2] = 2.0 * bboxKps[:, :2] * ratio - 1.0 return { "image": torch.tensor( util.convert_image_by_pixformat_normalize( resImg, self.pixFormat, self.normalize)).float(), "kp_2d": torch.tensor(bboxKps).float(), "image_name": imgPath, "data_set": "COCO 2017" }
def __getitem__(self, index): imgPath = self.images[index] keyps2d = self.keyps2d[index].copy() # remove head and neck points keyps2d = keyps2d[0:12, :] bbox = self.boxes[index] keyps3d = self.keyps3d[index].copy() keyps3d = keyps3d[0:12, :] """# plot points on image and save imgVis=cv2.imread(imgPath) for r in range(keyps2d.shape[0]): currX=int(keyps2d[r,0]) currY=int(keyps2d[r,1]) cv2.circle(imgVis,(currX,currY),2,(0,0,255),4) cv2.putText(imgVis,str(r),(currX,currY),cv2.FONT_HERSHEY_SIMPLEX,0.2,(255,255,255)) cv2.imwrite("/home/BaseCode/trainedModels/5/tmpFull.png",imgVis)""" #scale=np.random.rand(4)*(self.scaleRange[1]-self.scaleRange[0])+self.scaleRange[0] scale = 1 bboxImg, bboxKps = util.cut_image(imgPath, keyps2d, scale, bbox[0], bbox[1]) bboxKps = bboxKps[:, 0:2] bboxKps[:, 0] *= (1.0 * self.cropSize / bboxImg.shape[0]) bboxKps[:, 1] *= (1.0 * self.cropSize / bboxImg.shape[1]) resImg = cv2.resize(bboxImg, (self.cropSize, self.cropSize), interpolation=cv2.INTER_CUBIC) #bboxKps[:,:2]=2.0*bboxKps[:, :2]*ratio-1.0 bboxKps = (2.0 * bboxKps * 1.0 / self.cropSize) - 1.0 #print(bboxKps) shape, pose = self.smplShapeParams[index], self.smplPoseParams[index] #theta=np.concatenate((np.zeros(3),pose,shape),axis = 0) theta = np.concatenate((pose, shape), axis=0) return { "image": torch.from_numpy( util.convert_image_by_pixformat_normalize( resImg, self.pixFormat, self.normalize)).float(), "kp_2d": torch.from_numpy(bboxKps).float(), "kp_3d": torch.from_numpy(keyps3d).float(), "theta": torch.from_numpy(theta).float(), "image_name": self.images[index], "w_smpl": 1.0, "w_3d": 1.0, "data_set": "Human3.6M" }
def __getitem__(self, index): image_path = self.images[index] kps = self.kp2ds[index].copy() box = self.boxs[index] kp_3d = self.kp3ds[index].copy() scale = np.random.rand(4) * (self.scale_range[1] - self.scale_range[0]) + self.scale_range[0] image, kps = cut_image(image_path, kps, scale, box[0], box[1]) ratio = 1.0 * args.crop_size / image.shape[0] kps[:, :2] *= ratio dst_image = cv2.resize(image, (args.crop_size, args.crop_size), interpolation=cv2.INTER_CUBIC) trival, shape, pose = np.zeros( 3), self.shapes[index], self.poses[index] if self.use_flip and random.random() <= self.flip_prob: dst_image, kps = flip_image(dst_image, kps) pose = reflect_pose(pose) kp_3d = reflect_lsp_kp(kp_3d) #normalize kp to [-1, 1] ratio = 1.0 / args.crop_size kps[:, :2] = 2.0 * kps[:, :2] * ratio - 1.0 theta = np.concatenate((trival, pose, shape), axis=0) return { 'image': torch.from_numpy( convert_image_by_pixformat_normalize(dst_image, self.pix_format, self.normalize)).float(), 'kp_2d': torch.from_numpy(kps).float(), 'kp_3d': torch.from_numpy(kp_3d).float(), 'theta': torch.from_numpy(theta).float(), 'image_name': self.images[index], 'w_smpl': 1.0, 'w_3d': 1.0, 'data_set': 'hum3.6m' }