Skip to content

Commit

Permalink
Merge pull request #1343 from alicevision/dev/cleanKeyframeSelection
Browse files Browse the repository at this point in the history
Keyframe Selection: Rework and add new selection methods
  • Loading branch information
fabiencastan authored Mar 14, 2023
2 parents 7ad51ed + 5cbbbd8 commit 8eb3db8
Show file tree
Hide file tree
Showing 19 changed files with 1,486 additions and 1,118 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ set(ALICEVISION_HAVE_OPENCV_CONTRIB 0)

if(ALICEVISION_BUILD_SFM)
if(NOT ALICEVISION_USE_OPENCV STREQUAL "OFF")
find_package(OpenCV COMPONENTS core imgproc video imgcodecs videoio features2d photo)
find_package(OpenCV COMPONENTS core imgproc video imgcodecs videoio features2d optflow photo)

if(OpenCV_FOUND)
# We do not set the minimal version directly in find_package
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if(ALICEVISION_BUILD_SFM)
add_subdirectory(graph)
add_subdirectory(gpu)
add_subdirectory(imageMatching)
add_subdirectory(keyframe)
add_subdirectory(linearProgramming)
add_subdirectory(lensCorrectionProfile)
add_subdirectory(localization)
Expand All @@ -36,6 +35,7 @@ if(ALICEVISION_BUILD_SFM)
add_subdirectory(calibration)
if(ALICEVISION_HAVE_OPENCV)
add_subdirectory(imageMasking)
add_subdirectory(keyframe)
endif()
endif()

Expand Down
27 changes: 17 additions & 10 deletions src/aliceVision/dataio/FeedProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,39 @@
namespace aliceVision{
namespace dataio{

FeedProvider::FeedProvider(const std::string &feedPath, const std::string &calibPath)
FeedProvider::FeedProvider(const std::string &feedPath, const std::string &calibPath)
: _isVideo(false), _isLiveFeed(false)
{
namespace bf = boost::filesystem;
if(feedPath.empty())
{
throw std::invalid_argument("Empty filepath.");
}
if(bf::is_regular_file(bf::path(feedPath)))
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))
{
_feeder.reset(new ImageFeed(feedPath, calibPath));
}
else
else
{
if(VideoFeed::isSupported(extension))
{
#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_OPENCV)
// let's try it with a video
_feeder.reset(new VideoFeed(feedPath, calibPath));
_isVideo = true;
// let's try it with a video
_feeder.reset(new VideoFeed(feedPath, calibPath));
_isVideo = true;
#else
throw std::invalid_argument("Unsupported mode! If you intended to use a video"
throw std::invalid_argument("Unsupported mode! If you intended to use a video"
" please add OpenCV support");
#endif
}
else
{
throw std::invalid_argument("Unsupported file format: " + feedPath);
}
}
}
// parent_path() returns "/foo/bar/" when input path equals to "/foo/bar/"
Expand Down Expand Up @@ -96,12 +103,12 @@ bool FeedProvider::readImage(image::Image<unsigned char> &imageGray,
{
return(_feeder->readImage(imageGray, camIntrinsics, mediaPath, hasIntrinsics));
}

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

return _feeder->nbFrames();
}

Expand All @@ -122,5 +129,5 @@ bool FeedProvider::isInit() const

FeedProvider::~FeedProvider( ) { }

}//namespace dataio
}//namespace dataio
}//namespace aliceVision
12 changes: 6 additions & 6 deletions src/aliceVision/dataio/FeedProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace dataio{
class FeedProvider
{
public:

FeedProvider(const std::string &feedPath, const std::string &calibPath = "");

/**
* @brief Provide a new RGB image from the feed.
*
Expand Down Expand Up @@ -51,7 +51,7 @@ class FeedProvider
camera::PinholeRadialK3 &camIntrinsics,
std::string &mediaPath,
bool &hasIntrinsics);

/**
* @brief Provide a new grayscale image from the feed.
*
Expand Down Expand Up @@ -101,7 +101,7 @@ class FeedProvider
* @return True if the feed is a video.
*/
bool isVideo() const {return _isVideo; }

/**
* @brief Return true if the feed is a live stream (e.g. a webcam).
*
Expand All @@ -110,14 +110,14 @@ class FeedProvider
bool isLiveFeed() const {return _isLiveFeed; }

virtual ~FeedProvider();

private:
std::unique_ptr<IFeed> _feeder;
bool _isVideo;
bool _isLiveFeed;

};

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

8 changes: 4 additions & 4 deletions src/aliceVision/dataio/IFeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ void readCalibrationFromFile(const std::string &filename, camera::PinholeRadialK
int height = 0;
const size_t numParam = 6;
std::vector<double> params(numParam, 0);

fs >> width;
fs >> height;
for(size_t i = 0; i < numParam; ++i)
{
fs >> params[i];
}
camIntrinsics = camera::PinholeRadialK3(width, height,
camIntrinsics = camera::PinholeRadialK3(width, height,
params[0], params[1], params[2],
params[3], params[4], params[5]);

fs.close();
}

}//namespace dataio
}//namespace dataio
}//namespace aliceVision
16 changes: 8 additions & 8 deletions src/aliceVision/dataio/IFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IFeed
* @return True if the feed is correctly initialized.
*/
virtual bool isInit() const = 0;

/**
* @brief Provide a new RGB image from the feed
* @param[out] imageRGB The new RGB image from the feed.
Expand Down Expand Up @@ -51,7 +51,7 @@ class IFeed
camera::PinholeRadialK3 &camIntrinsics,
std::string &mediaPath,
bool &hasIntrinsics) = 0;

/**
* @brief Provide a new grayscale image from the feed
* @param[out] imageGray The new image from the feed.
Expand All @@ -62,16 +62,16 @@ class IFeed
* @return True if there is a new image, false otherwise.
*/
virtual bool readImage(image::Image<unsigned char> &imageGray,
camera::PinholeRadialK3 &camIntrinsics,
camera::PinholeRadialK3 &camIntrinsics,
std::string &mediaPath,
bool &hasIntrinsics) = 0;
bool &hasIntrinsics) = 0;

virtual std::size_t nbFrames() const = 0;

virtual bool goToFrame(const unsigned int frame) = 0;

virtual bool goToNextFrame() = 0;

virtual ~IFeed( ) {}

};
Expand All @@ -84,6 +84,6 @@ class IFeed
*/
void readCalibrationFromFile(const std::string &filename, camera::PinholeRadialK3 &camIntrinsics);

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

Loading

0 comments on commit 8eb3db8

Please sign in to comment.