def test_normalized_tensor_range_and_shape(): sigma = 1 smoothed_tensor = smooth_trajectory_tensor(tensor, sigma) normalized_tensor = normalize_trajectory_tensor(smoothed_tensor) assert smoothed_tensor.shape == normalized_tensor.shape assert normalized_tensor.max() == 1 assert normalized_tensor.min() == 0
def test_correct_dimentions_smoothed(): sigma = 1 smoothed_tensor = smooth_trajectory_tensor(tensor, sigma) # Camera dimention assert np.all(tensor[0] != smoothed_tensor[0]) assert np.all(tensor[1] == smoothed_tensor[1]) # Time dimention assert np.all(tensor[0][1] != smoothed_tensor[0][1])
def __getitem__(self, idx): this_input = self.inputs[idx].astype(np.float32) this_target = self.targets[idx] if self.heatmap_smoothing_sigma != 0: this_input = smooth_trajectory_tensor(this_input, self.heatmap_smoothing_sigma) this_input = normalize_trajectory_tensor(this_input) return {"inputs": this_input, "targets": this_target}
def __getitem__(self, idx): this_input = np.stack(self.inputs[idx], axis=0).astype(np.float32) this_target = np.stack(self.targets[idx], axis=0) if self.heatmap_smoothing_sigma != 0: for target_num in range(this_input.shape[0]): this_input[target_num] = smooth_trajectory_tensor( this_input[target_num], self.heatmap_smoothing_sigma) this_input[target_num] = normalize_trajectory_tensor( this_input[target_num]) return {"inputs": this_input, "targets": this_target}
output_video = np.zeros((20, 1080, 1920, 3), dtype="uint8") for camera_num in range(1, NUM_CAMERAS + 1): print(camera_num) video_path = os.path.join( DATA_PATH, "videos", "day_" + str(args.day), "departures", "camera_" + str(camera_num), "departure_" + str(args.match_number).zfill(3) + ".mp4", ) video = utils.read_video(video_path) video = utils.resize_video(video, (480, 270)) input_tensor = input_tensor.astype(float) input_tensor = smooth_trajectory_tensor(input_tensor, 1) input_tensor = normalize_trajectory_tensor(input_tensor) for frame in range(10): this_heatmap = input_tensor[camera_num - 1, frame] this_heatmap = cv2.resize(this_heatmap, dsize=(480, 270), interpolation=cv2.INTER_NEAREST) this_heatmap = 255 - (this_heatmap * 255) this_heatmap = this_heatmap.astype("uint8") this_heatmap = cv2.applyColorMap(this_heatmap, cmapy.cmap("coolwarm")) video[frame + 10] = cv2.addWeighted(this_heatmap, 0.6, video[frame + 10], 0.4, 0) video[frame + 10] = utils.draw_grid(video[frame + 10], (27, 48), 1) start_x = int(math.floor((camera_num - 1) / 4) * 270) start_y = int(((camera_num - 1) % 4) * 480)