-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlabel_reader.cpp
More file actions
47 lines (40 loc) · 1.43 KB
/
label_reader.cpp
File metadata and controls
47 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2016 Baidu.com, Inc. All Rights Reserved
// @author erlangz(zhengwenchao@baidu.com)
// @date 2016/12/22 16:36:23
// @file label_reader.cpp
// @brief
//
#include "label_reader.h"
#include <exception>
namespace adu {
namespace perception {
bool LabelsReader::init(const std::string& file_name) {
_labels_file_name = file_name;
//Read Data from line
std::ifstream ifs;
ifs.open(_labels_file_name.c_str(), std::fstream::in);
if (!ifs) {
std::cerr << "Open File:" << _labels_file_name << " failed. e:" << strerror(errno) << std::endl;
return false;
}
//Parse Data from Columns
std::string line;
while (std::getline(ifs, line)) {
std::vector<std::string> columns;
boost::split(columns, line, boost::is_any_of(" \t"));
const std::string& pcd_file_name = columns[2].substr(8); //"./files/xxx" -> "xxx"
std::string& json_data = columns[3];
std::stringstream json_stream;
json_stream << json_data;
pt::ptree root;
pt::read_json(json_stream, root);
_labels[pcd_file_name] = Label::Ptr(new Label(pcd_file_name, root));
// if (pcd_file_name == "QB9178_12_1461753402_1461753702_3641.pcd") {
// std::cout << _labels[pcd_file_name]->debug_string();
// }
// std::cout << "LabelsReader pcd_file_name:" << pcd_file_name << std::endl;
}
return true;
}
} // namespace perception
} // namespace adu