Skip to content

Commit

Permalink
Merge pull request #1406 from alicevision/dev/sfmDataKeyframeSelection
Browse files Browse the repository at this point in the history
Keyframe Selection: Add support for SfMData files as inputs and outputs
  • Loading branch information
mugulmd authored Apr 26, 2023
2 parents 548d4c7 + 73fb09f commit be2bb06
Show file tree
Hide file tree
Showing 16 changed files with 1,564 additions and 975 deletions.
2 changes: 2 additions & 0 deletions src/aliceVision/dataio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ set(dataio_files_headers
FeedProvider.hpp
IFeed.hpp
ImageFeed.hpp
SfMDataFeed.hpp
)

# Sources
set(dataio_files_sources
FeedProvider.cpp
IFeed.cpp
ImageFeed.cpp
SfMDataFeed.cpp
)

if(ALICEVISION_HAVE_OPENCV)
Expand Down
149 changes: 76 additions & 73 deletions src/aliceVision/dataio/FeedProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "FeedProvider.hpp"
#include <aliceVision/config.hpp>
#include "ImageFeed.hpp"
#include "SfMDataFeed.hpp"
#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_OPENCV)
#include "VideoFeed.hpp"
#endif
Expand All @@ -19,116 +20,118 @@
#include <limits>
#include <ctype.h>

namespace aliceVision{
namespace dataio{
namespace aliceVision
{
namespace dataio
{

FeedProvider::FeedProvider(const std::string &feedPath, const std::string &calibPath)
: _isVideo(false), _isLiveFeed(false)
FeedProvider::FeedProvider(const std::string& feedPath, const std::string& calibPath)
: _isVideo(false)
, _isLiveFeed(false)
, _isSfmData(false)
{
namespace bf = boost::filesystem;
if(feedPath.empty())
{
throw std::invalid_argument("Empty filepath.");
}
if(bf::is_regular_file(bf::path(feedPath)))
{
// Image or video file
const std::string extension = bf::path(feedPath).extension().string();
if(ImageFeed::isSupported(extension))
namespace bf = boost::filesystem;
if(feedPath.empty())
{
_feeder.reset(new ImageFeed(feedPath, calibPath));
throw std::invalid_argument("Empty filepath.");
}
else
if(bf::is_regular_file(bf::path(feedPath)))
{
// Image or video file
const std::string extension = bf::path(feedPath).extension().string();
if(SfMDataFeed::isSupported(extension))
{
_feeder.reset(new SfMDataFeed(feedPath, calibPath));
_isSfmData = true;
}
else if(ImageFeed::isSupported(extension))
{
_feeder.reset(new ImageFeed(feedPath, calibPath));
}
else
{
#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_OPENCV)
if(VideoFeed::isSupported(extension))
{

// let's try it with a video
_feeder.reset(new VideoFeed(feedPath, calibPath));
_isVideo = true;
}
else
{
throw std::invalid_argument("Unsupported file format: " + feedPath);
}
if(VideoFeed::isSupported(extension))
{
// let's try it with a video
_feeder.reset(new VideoFeed(feedPath, calibPath));
_isVideo = true;
}
else
{
throw std::invalid_argument("Unsupported file format: " + feedPath);
}
#else
throw std::invalid_argument("Unsupported mode! If you intended to use a video"
" please add OpenCV support");
throw std::invalid_argument("Unsupported mode! If you intended to use a video"
" please add OpenCV support");
#endif
}
}
// parent_path() returns "/foo/bar/" when input path equals to "/foo/bar/"
// if the user just gives the relative path as "bar", throws invalid argument exception.
else if(bf::is_directory(bf::path(feedPath)) || bf::is_directory(bf::path(feedPath).parent_path()))
{
// Folder or sequence of images
_feeder.reset(new ImageFeed(feedPath, calibPath));
}
}
// parent_path() returns "/foo/bar/" when input path equals to "/foo/bar/"
// if the user just gives the relative path as "bar", throws invalid argument exception.
else if(bf::is_directory(bf::path(feedPath)) || bf::is_directory(bf::path(feedPath).parent_path()))
{
// Folder or sequence of images
_feeder.reset(new ImageFeed(feedPath, calibPath));
}
#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_OPENCV)
else if(isdigit(feedPath[0]))
{
// let's try it with a video
const int deviceNumber = std::stoi(feedPath);
_feeder.reset(new VideoFeed(deviceNumber, calibPath));
_isVideo = true;
_isLiveFeed = true;
}
else if(isdigit(feedPath[0]))
{
// let's try it with a video
const int deviceNumber = std::stoi(feedPath);
_feeder.reset(new VideoFeed(deviceNumber, calibPath));
_isVideo = true;
_isLiveFeed = true;
}
#endif
else
{
throw std::invalid_argument(std::string("Input filepath not supported: ") + feedPath);
}
else
{
throw std::invalid_argument(std::string("Input filepath not supported: ") + feedPath);
}
}

bool FeedProvider::readImage(image::Image<image::RGBColor> &imageRGB,
camera::PinholeRadialK3 &camIntrinsics,
std::string &mediaPath,
bool &hasIntrinsics)
bool FeedProvider::readImage(image::Image<image::RGBColor>& imageRGB, camera::PinholeRadialK3& camIntrinsics,
std::string& mediaPath, bool& hasIntrinsics)
{
return(_feeder->readImage(imageRGB, camIntrinsics, mediaPath, hasIntrinsics));
return (_feeder->readImage(imageRGB, camIntrinsics, mediaPath, hasIntrinsics));
}

bool FeedProvider::readImage(image::Image<float> &imageGray,
camera::PinholeRadialK3 &camIntrinsics,
std::string &mediaPath,
bool &hasIntrinsics)
bool FeedProvider::readImage(image::Image<float>& imageGray, camera::PinholeRadialK3& camIntrinsics,
std::string& mediaPath, bool& hasIntrinsics)
{
return(_feeder->readImage(imageGray, camIntrinsics, mediaPath, hasIntrinsics));
return (_feeder->readImage(imageGray, camIntrinsics, mediaPath, hasIntrinsics));
}

bool FeedProvider::readImage(image::Image<unsigned char> &imageGray,
camera::PinholeRadialK3 &camIntrinsics,
std::string &mediaPath,
bool &hasIntrinsics)
bool FeedProvider::readImage(image::Image<unsigned char>& imageGray, camera::PinholeRadialK3& camIntrinsics,
std::string& mediaPath, bool& hasIntrinsics)
{
return(_feeder->readImage(imageGray, camIntrinsics, mediaPath, hasIntrinsics));
return (_feeder->readImage(imageGray, camIntrinsics, mediaPath, hasIntrinsics));
}

std::size_t FeedProvider::nbFrames() const
{
if(_isLiveFeed)
return std::numeric_limits<std::size_t>::infinity();
if(_isLiveFeed)
return std::numeric_limits<std::size_t>::infinity();

return _feeder->nbFrames();
return _feeder->nbFrames();
}

bool FeedProvider::goToFrame(const unsigned int frame)
{
return _feeder->goToFrame(frame);
return _feeder->goToFrame(frame);
}

bool FeedProvider::goToNextFrame()
{
return _feeder->goToNextFrame();
return _feeder->goToNextFrame();
}

bool FeedProvider::isInit() const
{
return(_feeder->isInit());
return (_feeder->isInit());
}

FeedProvider::~FeedProvider( ) { }
FeedProvider::~FeedProvider() {}

}//namespace dataio
}//namespace aliceVision
} // namespace dataio
} // namespace aliceVision
Loading

0 comments on commit be2bb06

Please sign in to comment.