Skip to content

Commit 9e8a978

Browse files
committed
Fix bug in KITTI oxts satellite data
1 parent 024ba64 commit 9e8a978

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

src/xyz_kitti.c

+33-18
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ kitti_oxts_t *kitti_oxts_load(const char *data_dir) {
290290
strcat(format, "%lf %lf %lf %lf %lf "); // Velocity
291291
strcat(format, "%lf %lf %lf %lf %lf %lf "); // Acceleration
292292
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
294294

295295
for (int i = 0; i < num_rows; ++i) {
296296
// Open oxts entry
@@ -301,7 +301,12 @@ kitti_oxts_t *kitti_oxts_load(const char *data_dir) {
301301
KITTI_FATAL("Failed to open [%s]!\n", timestamps_path);
302302
}
303303

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
305310
int retval = fscanf(fp,
306311
format,
307312
// GPS
@@ -335,13 +340,23 @@ kitti_oxts_t *kitti_oxts_load(const char *data_dir) {
335340
// Satellite tracking
336341
&data->pos_accuracy[i],
337342
&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+
343358
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);
345360
}
346361
fclose(fp);
347362
}
@@ -424,7 +439,7 @@ static timestamp_t *load_timestamps(const char *file_path) {
424439
return timestamps;
425440
}
426441

427-
point_xyzr_t *kitti_load_points(const char *pcd_path) {
442+
float *kitti_load_points(const char *pcd_path, size_t *num_points) {
428443
// Load pcd file
429444
FILE *pcd_file = fopen(pcd_path, "rb");
430445
if (!pcd_file) {
@@ -434,22 +449,22 @@ point_xyzr_t *kitti_load_points(const char *pcd_path) {
434449

435450
// Get the size of the file to know how many points
436451
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);
439454

440455
// 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);
443458
if (!points) {
444459
KITTI_LOG("Failed to allocate memory for points");
445460
fclose(pcd_file);
446461
return NULL;
447462
}
448463

449464
// 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) {
453468
KITTI_LOG("Failed to read all points");
454469
free(points);
455470
fclose(pcd_file);
@@ -691,7 +706,7 @@ kitti_raw_t *kitti_raw_load(const char *data_dir, const char *seq_name) {
691706
data->image_02 = kitti_camera_load(image_02_path);
692707
data->image_03 = kitti_camera_load(image_03_path);
693708
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);
695710
data->calib = kitti_calib_load(data_dir);
696711

697712
return data;
@@ -703,7 +718,7 @@ void kitti_raw_free(kitti_raw_t *data) {
703718
kitti_camera_free(data->image_02);
704719
kitti_camera_free(data->image_03);
705720
kitti_oxts_free(data->oxts);
706-
kitti_velodyne_free(data->velodyne_points);
721+
kitti_velodyne_free(data->velodyne);
707722
kitti_calib_free(data->calib);
708723
free(data);
709724
}

src/xyz_kitti.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ void kitti_oxts_free(kitti_oxts_t *data);
9090
* kitti_velodyne_t
9191
****************************************************************************/
9292

93-
typedef struct {
94-
float x;
95-
float y;
96-
float z;
97-
float r;
98-
} point_xyzr_t;
99-
10093
typedef struct kitti_velodyne_t {
10194
int num_timestamps;
10295
timestamp_t *timestamps;
@@ -105,7 +98,7 @@ typedef struct kitti_velodyne_t {
10598
char **pcd_paths;
10699
} kitti_velodyne_t;
107100

108-
point_xyzr_t *kitti_load_points(const char *pcd_path);
101+
float *kitti_load_points(const char *pcd_path, size_t *num_points);
109102
kitti_velodyne_t *kitti_velodyne_load(const char *data_dir);
110103
void kitti_velodyne_free(kitti_velodyne_t *data);
111104

@@ -179,7 +172,7 @@ typedef struct kitti_raw_t {
179172
kitti_camera_t *image_02;
180173
kitti_camera_t *image_03;
181174
kitti_oxts_t *oxts;
182-
kitti_velodyne_t *velodyne_points;
175+
kitti_velodyne_t *velodyne;
183176
kitti_calib_t *calib;
184177
} kitti_raw_t;
185178

0 commit comments

Comments
 (0)