@@ -290,7 +290,7 @@ kitti_oxts_t *kitti_oxts_load(const char *data_dir) {
290
290
strcat (format , "%lf %lf %lf %lf %lf " ); // Velocity
291
291
strcat (format , "%lf %lf %lf %lf %lf %lf " ); // Acceleration
292
292
strcat (format , "%lf %lf %lf %lf %lf %lf " ); // Angular velocity
293
- strcat (format , "%lf %lf %d %d %d %d %d " ); // Satellite tracking
293
+ strcat (format , "%lf %lf %s %s %s %s %s " ); // Satellite tracking
294
294
295
295
for (int i = 0 ; i < num_rows ; ++ i ) {
296
296
// Open oxts entry
@@ -301,7 +301,12 @@ kitti_oxts_t *kitti_oxts_load(const char *data_dir) {
301
301
KITTI_FATAL ("Failed to open [%s]!\n" , timestamps_path );
302
302
}
303
303
304
- // Others
304
+ // Parse
305
+ char navstat_str [30 ] = {0 }; // Navigation status
306
+ char numsats_str [30 ] = {0 }; // Number of satelllites tracked by GPS
307
+ char posmode_str [30 ] = {0 }; // Position mode
308
+ char velmode_str [30 ] = {0 }; // Velocity mode
309
+ char orimode_str [30 ] = {0 }; // Orientation mode
305
310
int retval = fscanf (fp ,
306
311
format ,
307
312
// GPS
@@ -335,13 +340,23 @@ kitti_oxts_t *kitti_oxts_load(const char *data_dir) {
335
340
// Satellite tracking
336
341
& data -> pos_accuracy [i ],
337
342
& data -> vel_accuracy [i ],
338
- & data -> navstat [i ],
339
- & data -> numsats [i ],
340
- & data -> posmode [i ],
341
- & data -> velmode [i ],
342
- & data -> orimode [i ]);
343
+ navstat_str ,
344
+ numsats_str ,
345
+ posmode_str ,
346
+ velmode_str ,
347
+ orimode_str );
348
+
349
+ // There's a bug in the KITTI OXTS data where in should be integer
350
+ // but sometimes its float. Here we are parsing the satellite
351
+ // tracking data as a string and converting it to integers.
352
+ data -> navstat [i ] = strtol (navstat_str , NULL , 10 );
353
+ data -> numsats [i ] = strtol (numsats_str , NULL , 10 );
354
+ data -> posmode [i ] = strtol (posmode_str , NULL , 10 );
355
+ data -> velmode [i ] = strtol (velmode_str , NULL , 10 );
356
+ data -> orimode [i ] = strtol (orimode_str , NULL , 10 );
357
+
343
358
if (retval != 30 ) {
344
- KITTI_FATAL ("Failed to parse line in [%s]\n" , entry_path );
359
+ KITTI_FATAL ("Failed to parse [%s]\n" , entry_path );
345
360
}
346
361
fclose (fp );
347
362
}
@@ -424,7 +439,7 @@ static timestamp_t *load_timestamps(const char *file_path) {
424
439
return timestamps ;
425
440
}
426
441
427
- point_xyzr_t * kitti_load_points (const char * pcd_path ) {
442
+ float * kitti_load_points (const char * pcd_path , size_t * num_points ) {
428
443
// Load pcd file
429
444
FILE * pcd_file = fopen (pcd_path , "rb" );
430
445
if (!pcd_file ) {
@@ -434,22 +449,22 @@ point_xyzr_t *kitti_load_points(const char *pcd_path) {
434
449
435
450
// Get the size of the file to know how many points
436
451
fseek (pcd_file , 0 , SEEK_END );
437
- const long file_size = ftell (pcd_file );
438
- fseek (pcd_file , 0 , SEEK_SET );
452
+ const long int file_size = ftell (pcd_file );
453
+ rewind (pcd_file );
439
454
440
455
// Allocate memory for the points
441
- const int num_points = file_size / 16 ;
442
- point_xyzr_t * points = malloc (sizeof (point_xyzr_t ) * num_points );
456
+ * num_points = file_size / ( sizeof ( float ) * 4 ) ;
457
+ float * points = malloc (sizeof (float ) * 4 * * num_points );
443
458
if (!points ) {
444
459
KITTI_LOG ("Failed to allocate memory for points" );
445
460
fclose (pcd_file );
446
461
return NULL ;
447
462
}
448
463
449
464
// Read points from the file
450
- const size_t point_size = sizeof (point_xyzr_t ) ;
451
- const size_t read_count = fread (points , point_size , num_points , pcd_file );
452
- if (read_count != num_points ) {
465
+ const size_t point_size = sizeof (float ) * 4 ;
466
+ const size_t read_count = fread (points , point_size , * num_points , pcd_file );
467
+ if (read_count != * num_points ) {
453
468
KITTI_LOG ("Failed to read all points" );
454
469
free (points );
455
470
fclose (pcd_file );
@@ -691,7 +706,7 @@ kitti_raw_t *kitti_raw_load(const char *data_dir, const char *seq_name) {
691
706
data -> image_02 = kitti_camera_load (image_02_path );
692
707
data -> image_03 = kitti_camera_load (image_03_path );
693
708
data -> oxts = kitti_oxts_load (oxts_path );
694
- data -> velodyne_points = kitti_velodyne_load (velodyne_points_path );
709
+ data -> velodyne = kitti_velodyne_load (velodyne_points_path );
695
710
data -> calib = kitti_calib_load (data_dir );
696
711
697
712
return data ;
@@ -703,7 +718,7 @@ void kitti_raw_free(kitti_raw_t *data) {
703
718
kitti_camera_free (data -> image_02 );
704
719
kitti_camera_free (data -> image_03 );
705
720
kitti_oxts_free (data -> oxts );
706
- kitti_velodyne_free (data -> velodyne_points );
721
+ kitti_velodyne_free (data -> velodyne );
707
722
kitti_calib_free (data -> calib );
708
723
free (data );
709
724
}
0 commit comments