Update DataProviderFromFolder, which reads images from a folder

This commit is contained in:
Henri Rebecq 2019-09-16 14:09:49 +02:00
parent 71300eb8b1
commit 5f99781fb2
2 changed files with 16 additions and 11 deletions

View File

@ -35,7 +35,8 @@ private:
std::string path_to_data_folder_;
std::ifstream images_in_str_;
const char delimiter_{','};
const size_t num_tokens_in_line_ = 3; // stamp, image, depth
const size_t num_tokens_in_line_ = 2; // stamp, image
bool finished_parsing_;
SimulatorData sim_data_;
};

View File

@ -1,21 +1,26 @@
#include <esim/data_provider/data_provider_from_folder.hpp>
#include <ze/common/file_utils.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <ze/cameras/camera_impl.hpp>
namespace event_camera_simulator {
DataProviderFromFolder::DataProviderFromFolder(const std::string& path_to_data_folder)
: DataProviderBase(DataProviderType::Folder),
path_to_data_folder_(path_to_data_folder)
path_to_data_folder_(path_to_data_folder),
finished_parsing_(false)
{
// Load CSV image file
images_in_str_.open(ze::joinPath(path_to_data_folder, "images.csv"));
CHECK(images_in_str_.is_open());
// Load camera rig
camera_rig_ = ze::cameraRigFromYaml(ze::joinPath(path_to_data_folder, "calib.yaml"));
CHECK(camera_rig_);
CHECK_EQ(camera_rig_->size(), 1u) << "Only one camera in the rig is supported at the moment";
// Create dummy camera rig
// these intrinsic values are filled with garbage (width = height = 1) since the actual values are not known
ze::CameraVector cameras;
cameras.emplace_back(ze::createEquidistantCameraShared(1, 1, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
ze::TransformationVector extrinsics;
extrinsics.push_back(ze::Transformation());
camera_rig_ = std::make_shared<ze::CameraRig>(extrinsics, cameras, "camera");
// Allocate memory for image data
sim_data_.images.emplace_back(ImagePtr(new Image(
@ -46,6 +51,8 @@ bool DataProviderFromFolder::spinOnce()
std::string line;
if(!getline(images_in_str_, line))
{
VLOG(1) << "Finished parsing images.csv file";
finished_parsing_ = true;
return false;
}
@ -55,12 +62,9 @@ bool DataProviderFromFolder::spinOnce()
CHECK_GE(items.size(), num_tokens_in_line_);
int64_t stamp = getTimeStamp(items[0]);
const std::string& path_to_image = ze::joinPath(path_to_data_folder_, "frame", "cam_0", items[1]);
const std::string& path_to_image = ze::joinPath(path_to_data_folder_, items[1]);
cv::Mat image = cv::imread(path_to_image, 0);
CHECK(image.data) << "Could not load image from file: " << path_to_image;
CHECK(image.rows == camera_rig_->at(0).height()
&& image.cols == camera_rig_->at(0).width()) << "The image size in the data folder and the image size"
"specified in the camera rig do not match";
VLOG(3) << "Read image from file: " << path_to_image;
image.convertTo(*sim_data_.images[0], cv::DataType<ImageFloatType>::type, 1./255.);
@ -77,7 +81,7 @@ bool DataProviderFromFolder::spinOnce()
bool DataProviderFromFolder::ok() const
{
if (!running_)
if (!running_ || finished_parsing_)
{
VLOG(1) << "Data Provider was paused/terminated.";
return false;