48 #include "lvr2/types/Hyperspectral.hpp" 57 #include <boost/filesystem.hpp> 59 #include <opencv2/core/core.hpp> 60 #include <opencv2/highgui/highgui.hpp> 63 using boost::filesystem::path;
64 using boost::filesystem::directory_iterator;
66 bool compare_path(boost::filesystem::path p1, boost::filesystem::path p2)
68 std::string ply_file_name1 = p1.stem().string();
69 std::string number1 = ply_file_name1.substr(15);
71 std::string ply_file_name2 = p2.stem().string();
72 std::string number2 = ply_file_name2.substr(15);
74 std::stringstream ss1(number1);
75 std::stringstream ss2(number2);
82 ss1 >> first1 >> dummy >> second1;
83 ss2 >> first2 >> dummy >> second2;
85 return ((first1 << 16) + second1) < ((first2 << 16) + second2);
88 bool checkPNGDir(path& dataDir, std::string number,
int numExspected)
90 bool consistency =
true;
91 path png_dir = dataDir/
"panoramas_fixed"/(
"panorama_channels_"+number);
94 int numPNGs = std::count_if(
95 directory_iterator(png_dir),
97 static_cast<bool(*)(
const path&)
>(boost::filesystem::is_regular_file) );
99 if(numPNGs != numExspected)
104 catch(boost::filesystem::filesystem_error)
137 HDF5IO hdf5(
"hyper.h5",
true);
140 vector<boost::filesystem::path> annotated_scans;
141 directory_iterator end;
142 for(directory_iterator it(dataDir); it != end; ++it)
144 std::string ext = it->path().extension().string();
145 std::string stem = it->path().stem().string();
146 if(ext ==
".ply" && stem.find(
"scan_annotated_") != string::npos)
148 annotated_scans.push_back(it->path());
151 std::sort(annotated_scans.begin(), annotated_scans.end(),
compare_path);
155 for(
auto it : annotated_scans)
159 std::string ply_file_name = it.stem().string();
160 std::string number = ply_file_name.substr(15);
166 path matrix_file = dataDir/path(
"scan_" + number +
"_transformation.txt");
167 std::cout <<
timestamp <<
"Reading transformation: " << matrix_file.string() << std::endl;
168 Transformd transformation = loadFromFile<double>(matrix_file.string());
171 std::cout <<
timestamp <<
"Reading scan data: " << it << std::endl;
177 std::cout <<
timestamp <<
"Calculating bounding box..." << std::endl;
179 floatArr points = pointCloud->getPointArray();
180 for(
int i = 0; i < pointCloud->numPoints(); i++)
190 data->m_points = pointCloud;
191 data->m_boundingBox = bBox;
192 data->m_registration = transformation;
194 std::cout <<
timestamp <<
" Adding raw scan data" << endl;
196 hdf5.addRawScan(scanNr, data);
204 path imgFile = dataDir/
"panoramas_fixed"/(
"panorama_channels_"+number)/
"channel0.png";
205 cv::Mat img = cv::imread(imgFile.string(), cv::IMREAD_GRAYSCALE);
207 size_t img_x = img.cols;
208 size_t img_y = img.rows;
209 unsigned char* cube =
new unsigned char[numExspectedPNGs * img.rows * img.cols];
210 for(
int i = 0; i < numExspectedPNGs; i++)
213 sprintf(buffer,
"channel%d.png", i);
214 path imgFile = dataDir/
"panoramas_fixed"/(
"panorama_channels_"+number)/buffer;
215 cv::Mat img = cv::imread(imgFile.string(), cv::IMREAD_GRAYSCALE);
216 memcpy(cube + i * (img_y * img_x), img.data, img_y * img_x *
sizeof(
unsigned char));
220 std::vector<size_t> dim = {numExspectedPNGs, img_y, img_x};
224 std::vector<hsize_t> chunks =
227 sprintf(groupName,
"/raw/spectral/position_%05d", scanNr);
228 std::cout <<
timestamp <<
"Adding spectral dataset to " << groupName <<
" with dims " 231 hdf5.addArray(groupName,
"spectral", dim, chunks,
ucharArr(cube));
238 std::cout <<
timestamp <<
"Will not add data from " 239 << ply_file_name <<
". Spectral data is not consistent." << std::endl;
const kaboom::Options * options
void expand(T v)
Expands the bounding box if the given Vector v} is outside the current volume.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
static ModelPtr readModel(std::string filename)
boost::shared_array< unsigned char > ucharArr
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
std::shared_ptr< PointBuffer > PointBufferPtr
A dynamic bounding box class.
Transform< double > Transformd
4x4 double precision transformation matrix
boost::shared_array< float > floatArr
std::shared_ptr< Model > ModelPtr