Last active
April 24, 2020 07:34
-
-
Save insaneyilin/f56cc04fad19aec06e21e50821b1569f to your computer and use it in GitHub Desktop.
A C++ example showing how to load lidar points from .bin file of KITTI dataset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
// e.g. ./main data_tracking_velodyne/testing/velodyne/0000/000000.bin | |
int main(int argc, char **argv) { | |
if (argc != 2) { | |
std::cerr << "Usage: " << argv[0] << " <filepath>\n"; | |
return 1; | |
} | |
std::string input_filepath(argv[1]); | |
std::fstream ifs(input_filepath.c_str(), std::ios::in|std::ios::binary); | |
if(!ifs.good()) { | |
std::cerr << "Could not read file: " << input_filepath << '\n'; | |
return -1; | |
} | |
ifs.seekg(0, std::ios::beg); | |
float px = 0.f; | |
float py = 0.f; | |
float pz = 0.f; | |
float intensity = 0.f; | |
for (int i = 0; ifs.good() && !ifs.eof(); ++i) { | |
ifs.read((char*) &px, sizeof(float)); | |
ifs.read((char*) &py, sizeof(float)); | |
ifs.read((char*) &pz, sizeof(float)); | |
ifs.read((char*) &intensity, sizeof(float)); | |
std::cout << "pt: [" << px << " " << py << " " << pz << "] intensity: " | |
<< intensity << '\n'; | |
} | |
ifs.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment