def load(self, path): """ Load a viewpoints.json to dataset's structure Todo: datastructure should be more similar to json structure... :return: return false if the dataset is empty. """ # Load viewpoints file and camera file with open(os.path.join(path, "viewpoints.json")) as data_file: data = json.load(data_file) self.camera = Camera.load_from_json(path) self.metadata = data["metaData"] self.set_save_type(self.metadata["save_type"]) count = 0 # todo this is not clean!i while True: try: id = str(count) pose = Transform.from_parameters( *[float(data[id]["vector"][str(x)]) for x in range(6)]) self.add_pose(None, None, pose) if "pairs" in data[id]: for i in range(int(data[id]["pairs"])): pair_id = "{}n{}".format(id, i) pair_pose = Transform.from_parameters(*[ float(data[pair_id]["vector"][str(x)]) for x in range(6) ]) self.add_pair(None, None, pair_pose, count) count += 1 except KeyError: break return self.data_pose
def __call__(self, data): rgbA, depthA, rgbB, depthB, prior = data prior_T = Transform.from_parameters(*prior) if random.uniform(0, 1) < self.proba: rand_id = random.randint(0, self.loader.size() - 1) occluder_rgb, occluder_depth, occ_pose = self.loader.load_image( rand_id) if random.randint(0, 1): occluder_rgb, occluder_depth, _ = self.loader.load_pair( rand_id, 0) occluder_depth = occluder_depth.astype(np.float32) # Z offset of occluder to be closer to the occluded object offset = occ_pose.matrix[2, 3] - prior_T.matrix[2, 3] occluder_depth[occluder_depth != 0] += offset * 1000 occluder_depth[occluder_depth != 0] -= random.randint(0, 500) occluder_rgb = add_hsv_noise(occluder_rgb, 1, 0.1, 0.1) occluder_rgb = imresize(occluder_rgb, depthB.shape, interp='nearest') occluder_depth = imresize(occluder_depth, depthB.shape, interp='nearest', mode="F").astype(np.int16) rgbB, depthB, occluder_mask = depth_blend(rgbB, depthB, occluder_rgb, occluder_depth) else: occluder_mask = None return rgbA, depthA, rgbB, depthB, prior, occluder_mask
def __call__(self, data): rgbA, depthA, rgbB, depthB, prior = data prior_T = Transform.from_parameters(*prior) depthA = self.normalize_depth(depthA, prior_T) depthB = self.normalize_depth(depthB, prior_T) #show_frames(rgbA, depthA, rgbB, depthB) return rgbA.astype(np.float32), depthA, rgbB.astype( np.float32), depthB, prior
def predict(self, frame): try: for _ in range(self.repeat): prediction = self._predict(frame) prediction_transform = Transform.from_parameters( *prediction, is_degree=self.is_degree) self.current_pose = combine_view_transform( self.current_pose, prediction_transform) self.poses.append(self.current_pose.to_parameters(rodrigues=False)) return prediction except ValueError: return None
def random_normal_magnitude(max_T, max_R): #maximum_magnitude_T = np.sqrt(3*(max_T**2)) #maximum_magnitude_R = np.sqrt(3*(max_R**2)) direction_T = UniformSphereSampler.random_direction() magn_T = UniformSphereSampler.normal_clip(max_T) #magn_T = random.uniform(0, max_T) T = angle_axis2euler(magn_T, direction_T) direction_R = UniformSphereSampler.random_direction() magn_R = UniformSphereSampler.normal_clip(max_R) #magn_R = random.uniform(0, max_R) R = angle_axis2euler(magn_R, direction_R) return Transform.from_parameters(T[2], T[1], T[0], R[2], R[1], R[0])
def _get_poses(self, indexA, indexB, transform=False): if self.poses is None: return None, None, None indexA = indexA indexB = indexB poseA = Transform.from_parameters(*self.poses[indexA], is_degree=True) poseB = Transform.from_parameters(*self.poses[indexB], is_degree=True) if transform: pose_A_flip = Transform.scale(1, -1, -1).combine(poseA) pose_A_flip = self.matrix_transformation.combine(pose_A_flip, copy=True) poseA = Transform().scale(1, -1, -1).combine(pose_A_flip, copy=True) pose_B_flip = Transform.scale(1, -1, -1).combine(poseB) pose_B_flip = self.matrix_transformation.combine(pose_B_flip, copy=True) poseB = Transform().scale(1, -1, -1).combine(pose_B_flip, copy=True) delta = delta_transform( poseA, poseB).to_parameters(isDegree=True).astype(np.float32) return delta, poseA, poseB
def predict(self, event_frame, rgb_frame): self.tracker_event.current_pose = self.to_event( self.tracker_frame.current_pose) pose = self.tracker_event._predict(event_frame) self.last_event_frame = self.tracker_event.last_frame prediction = Transform.from_parameters( *pose, is_degree=self.tracker_event.is_degree) new_pose_e = combine_view_transform( self.tracker_event.current_pose, prediction) new_pose_f = self.to_frame(new_pose_e) self.tracker_frame.current_pose = new_pose_f self.tracker_event.current_pose = new_pose_e self.tracker_frame.predict(rgb_frame) self.current_pose = (new_pose_f, self.tracker_frame.current_pose) self.poses.append((self.current_pose[0].to_parameters(rodrigues=False), self.current_pose[1].to_parameters(rodrigues=False)))