def __getitem__(self, index): example = self.examples[index] img_id = example["img_id"] calib_path = self.calib_dir + img_id + ".txt" calib = calibread(calib_path) camera_matrix = calib['P2'] u_min = example["u_min"] # (left) u_max = example["u_max"] # (rigth) v_min = example["v_min"] # (top) v_max = example["v_max"] # (bottom) score_2d = example["score_2d"] input_2Dbbox = np.array([u_min, u_max, v_min, v_max]) w = u_max - u_min h = v_max - v_min u_center = u_min + w / 2.0 v_center = v_min + h / 2.0 ######################################################################## # get the input 2dbbox img crop and resize to 224 x 224: ######################################################################## img_path = self.img_dir + img_id + ".png" img = cv2.imread(img_path, -1) bbox_2d_img = img[int(np.max([0, v_min])):int(v_max), int(np.max([0, u_min])):int(u_max)] bbox_2d_img = cv2.resize(bbox_2d_img, (224, 224)) # # # # # debug visualization: #cv2.imshow("test", bbox_2d_img) #cv2.waitKey(0) # # # # # ######################################################################## # normalize the 2dbbox img crop: ######################################################################## bbox_2d_img = bbox_2d_img / 255.0 bbox_2d_img = bbox_2d_img - np.array([0.485, 0.456, 0.406]) bbox_2d_img = bbox_2d_img / np.array([0.229, 0.224, 0.225 ]) # (shape: (H, W, 3)) bbox_2d_img = np.transpose(bbox_2d_img, (2, 0, 1)) # (shape: (3, H, W)) bbox_2d_img = bbox_2d_img.astype(np.float32) ######################################################################## # convert numpy -> torch: ######################################################################## bbox_2d_img = torch.from_numpy( bbox_2d_img) # (shape: (3, H, W) = (3, 224, 224)) return (bbox_2d_img, img_id, self.mean_car_size, w, h, u_center, v_center, input_2Dbbox, camera_matrix, self.mean_distance, score_2d)
lineType=cv2.LINE_AA, thickness=2) return img for sequence in ["0001", "0002", "0007", "0011"]: print(sequence) project_dir = "/home/fregu856/3DOD_thesis/" # NOTE! you'll have to adapt this for your file structure data_dir = project_dir + "data/kitti/tracking/testing/" img_dir = data_dir + "image_02/" + sequence + "/" calib_path = project_dir + "data/kitti/meta/tracking/testing/calib/" + sequence + ".txt" # NOTE! kitti/meta lidar_dir = data_dir + "velodyne/" + sequence + "/" calib = calibread(calib_path) P2 = calib["P2"] Tr_velo_to_cam_orig = calib["Tr_velo_to_cam"] R0_rect_orig = calib["R0_rect"] R0_rect = np.eye(4) R0_rect[0:3, 0:3] = R0_rect_orig Tr_velo_to_cam = np.eye(4) Tr_velo_to_cam[0:3, :] = Tr_velo_to_cam_orig # NOTE! here you can choose what model's output you want to visualize # Frustum-PointNet: with open( "/home/fregu856/3DOD_thesis/training_logs/model_Frustum-PointNet_eval_test_seq/eval_dict_test_seq_%s.pkl" % sequence, "rb"
"000000", "000001", "000002", "000003", "000004", "000005", "000006", "000007", "000008", "000009", "000010" ]: print img_id bbox_dicts = eval_dict[img_id] img = cv2.imread(img_dir + img_id + ".png", -1) lidar_path = lidar_dir + img_id + ".bin" point_cloud = np.fromfile(lidar_path, dtype=np.float32).reshape(-1, 4) # remove points that are located behind the camera: point_cloud = point_cloud[point_cloud[:, 0] > -2.5, :] calib = calibread(calib_dir + img_id + ".txt") P2 = calib["P2"] Tr_velo_to_cam_orig = calib["Tr_velo_to_cam"] R0_rect_orig = calib["R0_rect"] # R0_rect = np.eye(4) R0_rect[0:3, 0:3] = R0_rect_orig # Tr_velo_to_cam = np.eye(4) Tr_velo_to_cam[0:3, :] = Tr_velo_to_cam_orig point_cloud_xyz = point_cloud[:, 0:3] point_cloud_xyz_hom = np.ones((point_cloud.shape[0], 4)) point_cloud_xyz_hom[:, 0: 3] = point_cloud[:, 0: 3] # (point_cloud_xyz_hom has shape (num_points, 4))