@@ -5594,36 +5594,80 @@ def test_load(self):
5594
5594
5595
5595
5596
5596
class KittiCameraData :
5597
- """ KittiCameraDataset """
5598
- def __init__ (self , cam_idx , seq_path ):
5597
+ """ Kitti Camera Data """
5598
+ def __init__ (self , cam_idx , seq_dir : Path ):
5599
5599
self .cam_idx = cam_idx
5600
- self .seq_path = seq_path
5601
- self .cam_path = Path ( self .seq_path , "image_" + str (self .cam_idx ).zfill (2 ))
5602
- self .img_dir = Path ( self .cam_path , "data" )
5600
+ self .seq_dir = seq_dir
5601
+ self .cam_path = self .seq_dir / ( "image_" + str (self .cam_idx ).zfill (2 ))
5602
+ self .img_dir = self .cam_path / "data"
5603
5603
self .img_paths = sorted (glob .glob (str (Path (self .img_dir , "*.png" ))))
5604
5604
5605
5605
5606
+ class KittiVelodyneData :
5607
+ """ Kitti Velodyne Data"""
5608
+ def __init__ (self , seq_dir : Path ):
5609
+ self .seq_dir = seq_dir
5610
+ self .velodyne_path = Path (self .seq_dir , "velodyne_points" )
5611
+ self .bins_dir = self .velodyne_path / "data"
5612
+
5613
+ ts_file = self .velodyne_path / "timestamps.txt"
5614
+ ts_start_file = self .velodyne_path / "timestamps_start.txt"
5615
+ ts_end_file = self .velodyne_path / "timestamps_end.txt"
5616
+
5617
+ self .timestamps = self ._load_timestamps (ts_file )
5618
+ self .timestamps_start = self ._load_timestamps (ts_start_file )
5619
+ self .timestamps_end = self ._load_timestamps (ts_end_file )
5620
+ self .bin_paths = sorted (self .bins_dir .glob ("*.bin" ))
5621
+
5622
+ def _load_timestamps (self , data_file : Path ) -> list [np .int64 ]:
5623
+ """ Load timestamps from file """
5624
+ f = open (data_file , "r" )
5625
+
5626
+ timestamps = []
5627
+ for line in f :
5628
+ line = line .strip ()
5629
+ dt = line .split ('.' )[0 ]
5630
+ dt_obj = datetime .strptime (dt , "%Y-%m-%d %H:%M:%S" )
5631
+ seconds = dt_obj .timestamp ()
5632
+ nanoseconds = int (line .split ('.' )[1 ])
5633
+ timestamps .append (int (seconds * 1e9 ) + nanoseconds )
5634
+
5635
+ f .close ()
5636
+ return timestamps
5637
+
5638
+ def load_scan (self , ts : np .int64 ) -> MatNx4 :
5639
+ """ Load scan based on timestamp """
5640
+ index = self .timestamps .index (ts )
5641
+ bin_path = self .bin_paths [index ]
5642
+ pcd = np .fromfile (bin_path , dtype = np .float32 ).reshape (- 1 , 4 )
5643
+ return pcd
5644
+
5645
+
5606
5646
class KittiRawDataset :
5607
5647
""" KittiRawDataset """
5608
- def __init__ (self , data_dir , date , seq , is_sync ):
5648
+ def __init__ (self , data_dir : Path , date : str , seq : str , is_sync : bool ):
5609
5649
# Paths
5610
5650
self .data_dir = data_dir
5611
5651
self .date = date
5652
+ self .date_dir = data_dir / self .date
5612
5653
self .seq = seq .zfill (4 )
5613
5654
self .sync = "sync" if is_sync else "extract"
5614
5655
self .seq_name = "_" .join ([self .date , "drive" , self .seq , self .sync ])
5615
- self .seq_path = Path (self .data_dir , self .date , self .seq_name )
5656
+ self .seq_dir = Path (self .data_dir , self .date , self .seq_name )
5616
5657
5617
5658
# Camera data
5618
- self .cam0_data = KittiCameraData (0 , self .seq_path )
5619
- self .cam1_data = KittiCameraData (1 , self .seq_path )
5620
- self .cam2_data = KittiCameraData (2 , self .seq_path )
5621
- self .cam3_data = KittiCameraData (3 , self .seq_path )
5659
+ self .cam0_data = KittiCameraData (0 , self .seq_dir )
5660
+ self .cam1_data = KittiCameraData (1 , self .seq_dir )
5661
+ self .cam2_data = KittiCameraData (2 , self .seq_dir )
5662
+ self .cam3_data = KittiCameraData (3 , self .seq_dir )
5663
+
5664
+ # Velodyne data
5665
+ self .velodyne_data = KittiVelodyneData (self .seq_dir )
5622
5666
5623
5667
# Calibration
5624
- calib_cam_to_cam_filepath = Path (self .data_dir , "calib_cam_to_cam.txt" )
5625
- calib_imu_to_velo_filepath = Path (self .data_dir , "calib_imu_to_velo.txt" )
5626
- calib_velo_to_cam_filepath = Path (self .data_dir , "calib_velo_to_cam.txt" )
5668
+ calib_cam_to_cam_filepath = Path (self .date_dir , "calib_cam_to_cam.txt" )
5669
+ calib_imu_to_velo_filepath = Path (self .date_dir , "calib_imu_to_velo.txt" )
5670
+ calib_velo_to_cam_filepath = Path (self .date_dir , "calib_velo_to_cam.txt" )
5627
5671
self .calib_cam_to_cam = self ._read_calib_file (calib_cam_to_cam_filepath )
5628
5672
self .calib_imu_to_velo = self ._read_calib_file (calib_imu_to_velo_filepath )
5629
5673
self .calib_velo_to_cam = self ._read_calib_file (calib_velo_to_cam_filepath )
@@ -5716,7 +5760,7 @@ def plot_frames(self):
5716
5760
T_BC3 = self .get_camera_extrinsics (3 )
5717
5761
5718
5762
plt .figure ()
5719
- ax = plt .axes (projection = '3d' )
5763
+ ax : Axes3D = plt .axes (projection = '3d' )
5720
5764
plot_tf (ax , eye (4 ), size = 0.1 , name = "imu" )
5721
5765
plot_tf (ax , T_BV , size = 0.1 , name = "velo" )
5722
5766
plot_tf (ax , T_BC0 , size = 0.1 , name = "cam0" )
0 commit comments