Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFM bootstraping #1432

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/aliceVision/sfm/pipeline/relativePoses.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// This file is part of the AliceVision project.
// Copyright (c) 2023 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include <aliceVision/types.hpp>
#include <aliceVision/numeric/numeric.hpp>
#include <boost/json.hpp>
#include <aliceVision/geometry/lie.hpp>

namespace Eigen
{
template <typename T, int M, int N>
Eigen::Matrix<T, M, N> tag_invoke(boost::json::value_to_tag<Eigen::Matrix<T, M, N>>, boost::json::value const& jv)
{
Eigen::Matrix<T, M, N> ret;

std::vector<T> buf = boost::json::value_to<std::vector<T>>(jv);

int pos = 0;
for (int i = 0; i < M; i ++)
{
for (int j = 0; j < N; j++)
{
ret(i, j) = buf[pos];
pos++;
}
}

return ret;
}

template <typename T, int M, int N>
void tag_invoke(const boost::json::value_from_tag&, boost::json::value& jv, Eigen::Matrix<T, M, N> const& input)
{
std::vector<T> buf;

for (int i = 0; i < M; i ++)
{
for (int j = 0; j < N; j++)
{
buf.push_back(input(i, j));
}
}


jv = boost::json::value_from<std::vector<T>>(std::move(buf));
}

}

namespace aliceVision
{
namespace sfm
{

struct ReconstructedPair
{
IndexT reference;
IndexT next;
Mat3 R;
Vec3 t;
};


void tag_invoke(const boost::json::value_from_tag&, boost::json::value& jv, sfm::ReconstructedPair const& input)
{
jv = {
{"reference", input.reference},
{"next", input.next},
{"R", boost::json::value_from(SO3::logm(input.R))},
{"t", boost::json::value_from(input.t)}
};
}

ReconstructedPair tag_invoke(boost::json::value_to_tag<ReconstructedPair>, boost::json::value const& jv)
{
const boost::json::object& obj = jv.as_object();

ReconstructedPair ret;

ret.reference = boost::json::value_to<IndexT>(obj.at("reference"));
ret.next = boost::json::value_to<IndexT>(obj.at("next"));
ret.R = SO3::expm(boost::json::value_to<Vec3>(obj.at("R")));
ret.t = boost::json::value_to<Vec3>(obj.at("t"));

return ret;
}

}
}
11 changes: 11 additions & 0 deletions src/aliceVision/track/trackIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ void tag_invoke(const boost::json::value_from_tag&, boost::json::value& jv, alic
};
}

aliceVision::track::Track tag_invoke(boost::json::value_to_tag<aliceVision::track::Track>, boost::json::value const& jv)
{
const boost::json::object& obj = jv.as_object();

aliceVision::track::Track ret;
ret.descType = feature::EImageDescriberType_stringToEnum(boost::json::value_to<std::string>(obj.at("descType")));
ret.featPerView = flat_map_value_to<size_t>(obj.at("featPerView"));

return ret;
}

} // namespace track
} // namespace aliceVision
21 changes: 21 additions & 0 deletions src/aliceVision/track/trackIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,31 @@
namespace aliceVision {
namespace track {

template<class T>
stl::flat_map<size_t, T> flat_map_value_to(const boost::json::value& jv)
{
stl::flat_map<size_t, T> ret;

const boost::json::array obj = jv.as_array();

for (const auto & item: obj)
{
const boost::json::array inner = item.as_array();
ret.insert({boost::json::value_to<std::size_t>(inner[0]), boost::json::value_to<T>(inner[1])});
}

return ret;
}

/**
* @brief Serialize track to JSON object.
*/
void tag_invoke(const boost::json::value_from_tag&, boost::json::value& jv, aliceVision::track::Track const& input);

/**
* @brief Deserialize track from JSON object.
*/
aliceVision::track::Track tag_invoke(boost::json::value_to_tag<aliceVision::track::Track>, boost::json::value const& jv);

} // namespace track
} // namespace aliceVision
30 changes: 30 additions & 0 deletions src/software/pipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,36 @@ if(ALICEVISION_BUILD_SFM)
Boost::json
)

# Relative pose
alicevision_add_software(aliceVision_relativePoseEstimating
SOURCE main_relativePoseEstimating.cpp
FOLDER ${FOLDER_SOFTWARE_PIPELINE}
LINKS aliceVision_system
aliceVision_cmdline
aliceVision_feature
aliceVision_sfm
aliceVision_sfmData
aliceVision_track
Boost::program_options
Boost::filesystem
Boost::json
)

# bootstraping sfm
alicevision_add_software(aliceVision_sfmBootstraping
SOURCE main_sfmBootstraping.cpp
FOLDER ${FOLDER_SOFTWARE_PIPELINE}
LINKS aliceVision_system
aliceVision_cmdline
aliceVision_feature
aliceVision_sfm
aliceVision_sfmData
aliceVision_track
Boost::program_options
Boost::filesystem
Boost::json
)

# Incremental / Sequential SfM
alicevision_add_software(aliceVision_incrementalSfM
SOURCE main_incrementalSfM.cpp
Expand Down
Loading
Loading