Skip to content

Commit

Permalink
[localization] rig calibration now can use SIFT, CCTAG or SIFT_CCTAG
Browse files Browse the repository at this point in the history
  • Loading branch information
simogasp committed Nov 18, 2015
1 parent 25cb71e commit e009d87
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/software/RigCalibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
IF(OpenMVG_BUILD_VOCTREE)

IF(OpenMVG_USE_CCTAG)
###
# Calibrate a rig based on CCTag localizers
###
ADD_EXECUTABLE(openMVG_main_rigCalibration main_rigCalibration.cpp)
INSTALL(TARGETS openMVG_main_rigCalibration DESTINATION bin/)
TARGET_LINK_LIBRARIES(openMVG_main_rigCalibration openMVG_rig openMVG_localization openMVG_dataio openMVG_image openMVG_features vlsift ${CCTAG_LIBRARIES} ${BOOST_LIBRARIES}) #todo: delete vlsift
ENDIF(OpenMVG_USE_CCTAG)

ENDIF(OpenMVG_BUILD_VOCTREE)
164 changes: 147 additions & 17 deletions src/software/RigCalibration/main_rigCalibration.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <openMVG/localization/VoctreeLocalizer.hpp>
#if HAVE_CCTAG
#include <openMVG/localization/CCTagLocalizer.hpp>
#endif
#include <openMVG/rig/Rig.hpp>
#include <openMVG/sfm/pipelines/localization/SfM_Localizer.hpp>
#include <openMVG/image/image_io.hpp>
Expand Down Expand Up @@ -34,6 +36,53 @@ namespace po = boost::program_options;

using namespace openMVG;

enum DescriberType
{
SIFT
#if HAVE_CCTAG
,CCTAG,
SIFT_CCTAG
#endif
};

inline DescriberType stringToDescriberType(const std::string& describerType)
{
if(describerType == "SIFT")
return DescriberType::SIFT;
#if HAVE_CCTAG
if (describerType == "CCTAG")
return DescriberType::CCTAG;
if(describerType == "SIFT_CCTAG")
return DescriberType::SIFT_CCTAG;
#endif
throw std::invalid_argument("Unsupported describer type "+describerType);
}

inline std::string describerTypeToString(DescriberType describerType)
{
if(describerType == DescriberType::SIFT)
return "SIFT";
if (describerType == DescriberType::CCTAG)
return "CCTAG";
if(describerType == DescriberType::SIFT_CCTAG)
return "SIFT_CCTAG";
throw std::invalid_argument("Unrecognized DescriberType "+std::to_string(describerType));
}

std::ostream& operator<<(std::ostream& os, const DescriberType describerType)
{
os << describerTypeToString(describerType);
return os;
}

std::istream& operator>>(std::istream &in, DescriberType &describerType)
{
int i;
in >> i;
describerType = static_cast<DescriberType>(i);
return in;
}

std::string myToString(std::size_t i, std::size_t zeroPadding)
{
std::stringstream ss;
Expand All @@ -43,24 +92,45 @@ std::string myToString(std::size_t i, std::size_t zeroPadding)

int main(int argc, char** argv)
{
std::string sfmFilePath; //< the OpenMVG .json data file
std::string descriptorsFolder; //< the OpenMVG .json data file
std::string mediaFilepath; //< the media file to localize
localization::CCTagLocalizer::Parameters param = localization::CCTagLocalizer::Parameters();
// common parameters
std::string sfmFilePath; //< the OpenMVG .json data file
std::string descriptorsFolder; //< the OpenMVG .json data file
std::string mediaFilepath; //< the media file to localize
std::string preset = features::describerPreset_enumToString(features::EDESCRIBER_PRESET::NORMAL_PRESET); //< the preset for the feature extractor
std::string str_descriptorType = describerTypeToString(DescriberType::CCTAG); //< the preset for the feature extractor
bool refineIntrinsics = false;
// parameters for voctree localizer
std::string vocTreeFilepath; //< the vocabulary tree file
std::string weightsFilepath; //< the vocabulary tree weights file
std::string algostring = "FirstBest"; //< the localization algorithm to use for the voctree localizer
size_t numResults = 10; //< number of documents to search when querying the voctree
// parameters for cctag localizer
size_t nNearestKeyFrames = 5; //

#if HAVE_ALEMBIC
std::string exportFile = "trackedcameras.abc"; //!< the export file
#endif

std::size_t nCam = 3;
po::options_description desc("This program takes as input a media (image, image sequence, video) and a database (voctree, 3D structure data) \n"
"and returns for each frame a pose estimation for the camera.");
po::options_description desc("This program is used to calibrate a camera rig composed of internally calibrated cameras");
desc.add_options()
("help,h", "Print this message")
("results,r", po::value<size_t>(&param._nNearestKeyFrames)->default_value(param._nNearestKeyFrames), "Number of images to retrieve in database")
("sfmdata,d", po::value<std::string>(&sfmFilePath)->required(), "The sfm_data.json kind of file generated by OpenMVG [it could be also a bundle.out to use an older version of OpenMVG]")
("siftPath,s", po::value<std::string>(&descriptorsFolder), "Folder containing the .desc. If not provided, it will be assumed to be parent(sfmdata)/matches [for the older version of openMVG it is the list.txt]")
("mediafile,m", po::value<std::string>(&mediaFilepath)->required(), "The folder path containing all the synchronised image subfolders assocated to each camera")
("refineIntrinsics,", po::bool_switch(&param._refineIntrinsics), "Enable/Disable camera intrinsics refinement for each localized image")
("nCameras", po::value<size_t>(&nCam)->default_value(nCam), "Enable/Disable camera intrinsics refinement for each localized image")
("refineIntrinsics,", po::bool_switch(&refineIntrinsics), "Enable/Disable camera intrinsics refinement for each localized image")
("nCameras", po::value<size_t>(&nCam)->default_value(nCam), "Number of cameras composing the rig")
("preset,", po::value<std::string>(&preset)->default_value(preset), "Preset for the feature extractor when localizing a new image {LOW,NORMAL,HIGH,ULTRA}")
("descriptors,", po::value<std::string>(&str_descriptorType)->default_value(str_descriptorType), "Type of descriptors to use")
// parameters for voctree localizer
("voctree,t", po::value<std::string>(&vocTreeFilepath), "Filename for the vocabulary tree")
("weights,w", po::value<std::string>(&weightsFilepath), "Filename for the vocabulary tree weights")
("algorithm,", po::value<std::string>(&algostring)->default_value(algostring), "Algorithm type: FirstBest=0, BestResult=1, AllResults=2, Cluster=3" )
("results,r", po::value<size_t>(&numResults)->default_value(numResults), "Number of images to retrieve in database")
#if HAVE_CCTAG
// parameters for cctag localizer
("nNearestKeyFrames", po::value<size_t>(&nNearestKeyFrames)->default_value(nNearestKeyFrames), "Number of images to retrieve in database")
#endif
#if HAVE_ALEMBIC
("export,e", po::value<std::string>(&exportFile)->default_value(exportFile), "Filename for the SfM_Data export file (where camera poses will be stored). Default : trackedcameras.json If Alambic is enable it will also export an .abc file of the scene with the same name")
#endif
Expand Down Expand Up @@ -92,27 +162,87 @@ int main(int argc, char** argv)
POPART_COUT("Usage:\n\n" << desc);
return EXIT_FAILURE;
}
// just debugging prints
{
POPART_COUT("Program called with the following parameters:");
POPART_COUT("\tsfmdata: " << sfmFilePath);
POPART_COUT("\tmediafile: " << mediaFilepath);
POPART_COUT("\tsiftPath: " << descriptorsFolder);
POPART_COUT("\tresults: " << param._nNearestKeyFrames);
POPART_COUT("\trefineIntrinsics: " << param._refineIntrinsics);
POPART_COUT("\trefineIntrinsics: " << refineIntrinsics);
POPART_COUT("\tnCameras: " << nCam);
POPART_COUT("\tpreset: " << preset);
POPART_COUT("\tdescriptors: " << str_descriptorType);
if((DescriberType::SIFT==stringToDescriberType(str_descriptorType))
#if HAVE_CCTAG
||(DescriberType::SIFT_CCTAG==stringToDescriberType(str_descriptorType))
#endif
)
{
// parameters for voctree localizer
POPART_COUT("\tvoctree: " << vocTreeFilepath);
POPART_COUT("\tweights: " << weightsFilepath);
POPART_COUT("\talgorithm: " << algostring);
POPART_COUT("\tresults: " << numResults);
}
#if HAVE_CCTAG
else
{
POPART_COUT("\tnNearestKeyFrames: " << nNearestKeyFrames);
}
#endif

}

localization::LocalizerParameters *param;

localization::ILocalizer *localizer;

DescriberType describer = stringToDescriberType(str_descriptorType);

// initialize the localizer according to the chosen type of describer
if((DescriberType::SIFT==describer)
#if HAVE_CCTAG
||(DescriberType::SIFT_CCTAG==describer)
#endif
)
{
localizer = new localization::VoctreeLocalizer(sfmFilePath,
descriptorsFolder,
vocTreeFilepath,
weightsFilepath
#if HAVE_CCTAG
, DescriberType::SIFT_CCTAG==describer
#endif
);
param = new localization::VoctreeLocalizer::Parameters();
param->_featurePreset = features::describerPreset_stringToEnum(preset);
param->_refineIntrinsics = refineIntrinsics;
localization::VoctreeLocalizer::Parameters *casted = static_cast<localization::VoctreeLocalizer::Parameters *>(param);
casted->_algorithm = localization::VoctreeLocalizer::initFromString(algostring);;
casted->_numResults = numResults;
}
#if HAVE_CCTAG
else
{
localizer = new localization::CCTagLocalizer(sfmFilePath, descriptorsFolder);
param = new localization::CCTagLocalizer::Parameters();
param->_featurePreset = features::describerPreset_stringToEnum(preset);
param->_refineIntrinsics = refineIntrinsics;
localization::CCTagLocalizer::Parameters *casted = static_cast<localization::CCTagLocalizer::Parameters *>(param);
casted->_nNearestKeyFrames = nNearestKeyFrames;
}
#endif

// init the localizer
localization::CCTagLocalizer localizer(sfmFilePath, descriptorsFolder);

if(!localizer.isInit())
if(!localizer->isInit())
{
POPART_CERR("ERROR while initializing the localizer!");
return EXIT_FAILURE;
}

#if HAVE_ALEMBIC
dataio::AlembicExporter exporter(exportFile);
exporter.addPoints(localizer.getSfMData().GetLandmarks());
exporter.addPoints(localizer->getSfMData().GetLandmarks());
#endif

// Create a camera rig
Expand Down Expand Up @@ -161,8 +291,8 @@ int main(int argc, char** argv)
std::vector<pair<IndexT, IndexT> > ids;
auto detect_start = std::chrono::steady_clock::now();
localization::LocalizationResult localizationResult;
localizer.localize(imageGrey,
&param,
localizer->localize(imageGrey,
param,
hasIntrinsics/*useInputIntrinsics*/,
queryIntrinsics,
localizationResult);
Expand Down

0 comments on commit e009d87

Please sign in to comment.