Skip to content

Commit

Permalink
added unknown image detector/descriptor type
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Hog authored and mh0g committed May 27, 2024
1 parent 634a539 commit 3641d52
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/aliceVision/feature/ImageDescriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ std::unique_ptr<ImageDescriber> createImageDescriber(EImageDescriberType imageDe
case EImageDescriberType::AKAZE_LIOP:
describerPtr.reset(new ImageDescriber_AKAZE(AKAZEParams(AKAZEOptions(), feature::AKAZE_LIOP)));
break;
//Unknown descriptor to be used when the descriptor computed outside of alicevsion
case EImageDescriberType::UNKNOWN:
describerPtr.reset(new UnknownImageDescriber());
break;

#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_CCTAG)
case EImageDescriberType::CCTAG3:
Expand Down
120 changes: 120 additions & 0 deletions src/aliceVision/feature/ImageDescriber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <aliceVision/numeric/numeric.hpp>
#include <aliceVision/feature/imageDescriberCommon.hpp>
#include <aliceVision/feature/Regions.hpp>
#include <aliceVision/feature/regionsFactory.hpp>
#include <aliceVision/image/Image.hpp>
#include <memory>

Expand Down Expand Up @@ -260,6 +261,125 @@ class ImageDescriber
void LoadFeatures(Regions* regions, const std::string& sfileNameFeats) const { regions->LoadFeatures(sfileNameFeats); }
};

/**
* @brief Used to load descripters computed outside of meshroom.
*/
class UnknownImageDescriber : public ImageDescriber
{
public:
UnknownImageDescriber() = default;

virtual ~UnknownImageDescriber() = default;

/**
* @brief Check if the image describer use CUDA
* @return True if the image describer use CUDA
*/
bool useCuda() const override { return false; }

/**
* @brief Check if the image describer use float image
* @return True if the image describer use float image
*/
bool useFloatImage() const override { return false; }

/**
* @brief Get the corresponding EImageDescriberType
* @return EImageDescriberType
*/
EImageDescriberType getDescriberType() const override { return EImageDescriberType::UNKNOWN; }

/**
* @brief Get the total amount of RAM needed for a
* feature extraction of an image of the given dimension.
* @param[in] width The image width
* @param[in] height The image height
* @return total amount of memory needed
*/
std::size_t getMemoryConsumption(std::size_t width, std::size_t height) const override
{
std::cout<<"Bonjour 0"<<std::endl;
return 0;
}

/**
* @brief Set image describer always upRight
* @param[in] upRight
*/
void setUpRight(bool upRight) override
{std::cout<<"Bonjour 1"<<std::endl;}

/**
* @brief Set if yes or no imageDescriber need to use cuda implementation
* @param[in] useCuda
*/
void setUseCuda(bool useCuda) override
{
std::cout<<"Bonjour 2"<<std::endl;
}

/**
* @brief set the CUDA pipe
* @param[in] pipe The CUDA pipe id
*/
void setCudaPipe(int pipe) override
{
std::cout<<"Bonjour 3"<<std::endl;
}

/**
* @brief Use a preset to control the number of detected regions
* @param[in] preset The preset configuration
*/
void setConfigurationPreset(ConfigurationPreset preset) override
{
std::cout<<"Bonjour 4"<<std::endl;
}

/**
* @brief Detect regions on the 8-bit image and compute their attributes (description)
* @param[in] image Image.
* @param[out] regions The detected regions and attributes (the caller must delete the allocated data)
* @param[in] mask 8-bit grayscale image for keypoint filtering (optional)
* Non-zero values depict the region of interest.
* @return True if detection succed.
*/
bool describe(const image::Image<unsigned char>& image,
std::unique_ptr<Regions>& regions,
const image::Image<unsigned char>* mask = nullptr) override
{
std::cout<<"Bonjour 5"<<std::endl;
return false;
}

/**
* @brief Detect regions on the float image and compute their attributes (description)
* @param[in] image Image.
* @param[out] regions The detected regions and attributes (the caller must delete the allocated data)
* @param[in] mask 8-bit gray image for keypoint filtering (optional).
* Non-zero values depict the region of interest.
* @return True if detection succed.
*/
bool describe(const image::Image<float>& image, std::unique_ptr<Regions>& regions, const image::Image<unsigned char>* mask = nullptr) override
{
std::cout<<"Bonjour 6"<<std::endl;
return false;
}

/**
* @brief Allocate Regions type depending of the ImageDescriber
* @param[in,out] regions
*/
void allocate(std::unique_ptr<Regions>& regions) const override
{
std::cout<<"Bonjour 7"<<std::endl;
regions.reset(new UNKNOWN_Regions);
}

private:
std::unique_ptr<ImageDescriber> _imageDescriberImpl = nullptr;
};

/**
* @brief Create the desired ImageDescriber method.
* Don't use a factory, perform direct allocation.
Expand Down
5 changes: 2 additions & 3 deletions src/aliceVision/feature/imageDescriberCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ enum class EImageDescriberType : unsigned char
SIFT = 10,
SIFT_FLOAT = 11,
SIFT_UPRIGHT = 12,
DSPSIFT = 13

,
DSPSIFT = 13,

AKAZE = 20,
AKAZE_LIOP = 21,
AKAZE_MLDB = 22
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/feature/regionsFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ using AKAZE_Liop_Regions = ScalarRegions<unsigned char, 144>;
/// Define the AKAZE Keypoint (with a binary descriptor saved in an uchar array)
using AKAZE_BinaryRegions = BinaryRegions<64>;

/// Define an unknown feature regions
using UNKNOWN_Regions = ScalarRegions<float, 128>;

} // namespace feature
} // namespace aliceVision
4 changes: 2 additions & 2 deletions src/aliceVision/sfm/pipeline/regionsIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace sfmData;
std::unique_ptr<feature::Regions> loadRegions(const std::vector<std::string>& folders, IndexT viewId, const feature::ImageDescriber& imageDescriber)
{
assert(!folders.empty());

const std::string imageDescriberTypeName = feature::EImageDescriberType_enumToString(imageDescriber.getDescriberType());
const std::string basename = std::to_string(viewId);

Expand Down Expand Up @@ -228,7 +228,7 @@ bool loadRegionsPerView(feature::RegionsPerView& regionsPerView,
std::unique_ptr<feature::Regions> regionsPtr;
try
{
regionsPtr = loadRegions(featuresFolders, iter->second.get()->getViewId(), *(imageDescribers.at(i)));
regionsPtr = loadRegions(featuresFolders, iter->second.get()->getViewId(), *(imageDescribers.at(i)));
}
catch (const std::exception& e)
{
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/voctree/VocabularyTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ inline std::unique_ptr<IVocabularyTree> createVoctreeForDescriberType(feature::E
case EImageDescriberType::AKAZE_MLDB:
res.reset(new VocabularyTree<AKAZE_BinaryRegions::DescriptorT>);
break;
case EImageDescriberType::UNKNOWN:
res.reset(new VocabularyTree<UNKNOWN_Regions::DescriptorT>);
break;

#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_CCTAG)
case EImageDescriberType::CCTAG3:
Expand Down

0 comments on commit 3641d52

Please sign in to comment.