Skip to content

Commit

Permalink
Merge branch 'aluaces-patch-1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon committed Sep 10, 2021
2 parents 66ad6e5 + a4342e5 commit e3d9e91
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
project(openMVG C CXX)

# Run automoc on .hh files in new versions of cmake
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17")
if (${CMAKE_VERSION} VERSION_GREATER "3.17" OR
${CMAKE_VERSION} VERSION_EQUAL "3.17")
cmake_policy(SET CMP0100 NEW)
endif()

Expand Down
69 changes: 22 additions & 47 deletions src/openMVG/multiview/solver_fundamental_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,18 @@ void SevenPointSolver::Solve
assert(x1.cols() == x2.cols());

Vec9 f1, f2;
if (x1.cols() == 7) {
// Set up the homogeneous system Af = 0 from the equations x'T*F*x = 0.
using Mat9 = Eigen::Matrix<double, 9, 9>;
// In the minimal solution use fixed sized matrix to let Eigen and the
// compiler doing the maximum of optimization.
Mat9 epipolar_constraint = Mat::Zero(9,9);
EncodeEpipolarEquation(x1.colwise().homogeneous(),
x2.colwise().homogeneous(),
&epipolar_constraint);
// Find the two F matrices in the nullspace of epipolar_constraint.
Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 9, 9>> solver
(epipolar_constraint.transpose() * epipolar_constraint);
f1 = solver.eigenvectors().leftCols<2>().col(0);
f2 = solver.eigenvectors().leftCols<2>().col(1);
}
else {
// Set up the homogeneous system Af = 0 from the equations x'T*F*x = 0.
Mat epipolar_constraint(x1.cols(), 9);
EncodeEpipolarEquation(x1.colwise().homogeneous(),
x2.colwise().homogeneous(),
&epipolar_constraint);
// Find the two F matrices in the nullspace of epipolar_constraint.
Eigen::SelfAdjointEigenSolver<Mat> solver
(epipolar_constraint.transpose() * epipolar_constraint);
f1 = solver.eigenvectors().leftCols<2>().col(0);
f2 = solver.eigenvectors().leftCols<2>().col(1);
}
// Set up the homogeneous system Af = 0 from the equations x'T*F*x = 0.
MatX9 epipolar_constraint = MatX9::Zero((x1.cols() == 7) ? 9 : x1.cols(), 9);
EncodeEpipolarEquation(x1.colwise().homogeneous(),
x2.colwise().homogeneous(),
&epipolar_constraint);

using Mat9 = Eigen::Matrix<double, 9, 9>;
// Find the two F matrices in the nullspace of epipolar_constraint.
Eigen::SelfAdjointEigenSolver<Mat9> solver
(epipolar_constraint.transpose() * epipolar_constraint);
f1 = solver.eigenvectors().leftCols<2>().col(0);
f2 = solver.eigenvectors().leftCols<2>().col(1);

const Mat3 F1 = Map<RMat3>(f1.data());
const Mat3 F2 = Map<RMat3>(f2.data());
Expand Down Expand Up @@ -118,26 +103,16 @@ void EightPointSolver::Solve
assert(x1.cols() == x2.cols());

Vec9 f;
if (x1.cols() == 8) {
using Mat9 = Eigen::Matrix<double, 9, 9>;
// In the minimal solution use fixed sized matrix to let Eigen and the
// compiler doing the maximum of optimization.
Mat9 epipolar_constraint = Mat::Zero(9,9);
EncodeEpipolarEquation(x1.colwise().homogeneous(),
x2.colwise().homogeneous(),
&epipolar_constraint);
Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 9, 9>> solver
(epipolar_constraint.transpose() * epipolar_constraint);
f = solver.eigenvectors().leftCols<1>();
}
else {
MatX9 epipolar_constraint(x1.cols(), 9);
epipolar_constraint.fill(0.0);
EncodeEpipolarEquation(x1, x2, &epipolar_constraint);
Eigen::SelfAdjointEigenSolver<MatX9> solver
(epipolar_constraint.transpose() * epipolar_constraint);
f = solver.eigenvectors().leftCols<1>();
}
using Mat9 = Eigen::Matrix<double, 9, 9>;
// Set up the homogeneous system Af = 0 from the equations x'T*F*x = 0.
MatX9 epipolar_constraint = MatX9::Zero((x1.cols() == 8) ? 9 : x1.cols(), 9);
EncodeEpipolarEquation(x1.colwise().homogeneous(),
x2.colwise().homogeneous(),
&epipolar_constraint);
// Find the F matrice in the nullspace of epipolar_constraint.
Eigen::SelfAdjointEigenSolver<Mat9> solver
(epipolar_constraint.transpose() * epipolar_constraint);
f = solver.eigenvectors().leftCols<1>();

Mat3 F = Map<RMat3>(f.data());

Expand Down
2 changes: 1 addition & 1 deletion src/openMVG/sfm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ UNIT_TEST(openMVG sfm_data_BA "openMVG_multiview_test_data;openMVG_sfm;${STLPLUS
UNIT_TEST(openMVG sfm_data_utils "openMVG_sfm;${STLPLUS_LIBRARY}")
UNIT_TEST(openMVG sfm_data_filters "openMVG_sfm")
UNIT_TEST(openMVG sfm_data_graph_utils "openMVG_sfm")
UNIT_TEST(openMVG sfm_data_triangulation "openMVG_sfm;openMVG_multiview_test_data")
UNIT_TEST(openMVG sfm_data_triangulation "openMVG_sfm;openMVG_multiview_test_data;${STLPLUS_LIBRARY}")

add_subdirectory(pipelines)
10 changes: 10 additions & 0 deletions src/software/SfM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ target_link_libraries(openMVG_main_ComputeMatches
${STLPLUS_LIBRARY}
)

# - convert matches from one format (bin, txt) to the other format
#
add_executable(openMVG_main_ConvertMatches main_ConvertMatches.cpp)
target_link_libraries(openMVG_main_ConvertMatches
openMVG_system
openMVG_features
openMVG_sfm
${STLPLUS_LIBRARY}
)

add_executable(openMVG_main_MatchesToTracks main_MatchesToTracks.cpp)
target_link_libraries(openMVG_main_MatchesToTracks
PRIVATE
Expand Down
69 changes: 69 additions & 0 deletions src/software/SfM/main_ConvertMatches.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file is part of OpenMVG, an Open Multiple View Geometry C++ library.

// Copyright (c) 2012, 2013, 2015 Pierre MOULON.

// 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 http://mozilla.org/MPL/2.0/.

#include "openMVG/matching/indMatch.hpp"
#include "openMVG/matching/indMatch_utils.hpp"

#include "third_party/cmdLine/cmdLine.h"

#include <cstdlib>
#include <string>

using namespace openMVG;
using namespace openMVG::matching;

int main(int argc, char ** argv)
{
CmdLine cmd;

std::string sMatchFile;
std::string sOutMatchFile;

cmd.add( make_option('m', sMatchFile, "matchfile") );
cmd.add( make_option('o', sOutMatchFile, "outmatchfile") );

try {
if (argc == 1) throw std::string("Invalid command line parameter.");
cmd.process(argc, argv);
} catch (const std::string& s) {
std::cerr << "Convert matches from bin to txt or txt to bin.\nUsage: " << argv[0] << "\n"
<< "[-m|--sMatchFile filename]\n"
<< "[-o|--outmatchfile filename]\n"
<< std::endl;

std::cerr << s << std::endl;
return EXIT_FAILURE;
}

if (sMatchFile.empty()) {
std::cerr << "\nmatchfile cannot be an empty option" << std::endl;
return EXIT_FAILURE;
}
if (sOutMatchFile.empty()) {
std::cerr << "\noutmatchfile cannot be an empty option" << std::endl;
return EXIT_FAILURE;
}

// Read the matches
matching::PairWiseMatches pairWise_matches;
if (!Load(pairWise_matches, sMatchFile)) {
std::cerr << "\nInvalid matches file." << std::endl;
return EXIT_FAILURE;
}

// Write the matches
if (!Save(pairWise_matches, sOutMatchFile))
{
std::cerr
<< "Cannot save matches to: "
<< sOutMatchFile;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

0 comments on commit e3d9e91

Please sign in to comment.