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

Port remaining VXL tests to Google Test #351

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
12 changes: 6 additions & 6 deletions arrows/vxl/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ set(test_libraries kwiver_algo_vxl)
kwiver_discover_gtests(vxl bounding_box LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl bundle_adjust LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl camera LIBRARIES ${test_libraries})
kwiver_discover_tests(vxl_estimate_essential_matrix test_libraries test_estimate_essential_matrix.cxx)
kwiver_discover_tests(vxl_estimate_fundamental_matrix test_libraries test_estimate_fundamental_matrix.cxx)
kwiver_discover_tests(vxl_estimate_homography test_libraries test_estimate_homography.cxx)
kwiver_discover_tests(vxl_estimate_similarity test_libraries test_estimate_similarity.cxx)
kwiver_discover_gtests(vxl estimate_essential_matrix LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl estimate_fundamental_matrix LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl estimate_homography LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl estimate_similarity LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl image LIBRARIES ${test_libraries})
kwiver_discover_tests(vxl_optimize_cameras test_libraries test_optimize_cameras.cxx)
kwiver_discover_gtests(vxl optimize_cameras LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl polygon LIBRARIES ${test_libraries})
kwiver_discover_gtests(vxl triangulate_landmarks LIBRARIES ${test_libraries})

# This test is really for an algorithm in core, but it's here
# because the test depends on availablity of VXL sub-algorithms
set(test_libraries kwiver_algo_vxl kwiver_algo_core)

kwiver_discover_tests(vxl_initialize_cameras_landmarks test_libraries test_initialize_cameras_landmarks.cxx)
kwiver_discover_gtests(vxl initialize_cameras_landmarks LIBRARIES ${test_libraries})
87 changes: 36 additions & 51 deletions arrows/vxl/tests/test_estimate_essential_matrix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <test_common.h>
#include <test_math.h>
#include <test_eigen.h>
#include <test_scene.h>

#include <vital/plugin_loader/plugin_manager.h>
Expand All @@ -40,36 +39,27 @@

#include <Eigen/LU>

#include <gtest/gtest.h>

#define TEST_ARGS ()

DECLARE_TEST_MAP();
using namespace kwiver::vital;

int
main(int argc, char* argv[])
// ----------------------------------------------------------------------------
int main(int argc, char** argv)
{
CHECK_ARGS(1);
::testing::InitGoogleTest( &argc, argv );

kwiver::vital::plugin_manager::instance().load_all_plugins();

testname_t const testname = argv[1];

RUN_TEST(testname);
return RUN_ALL_TESTS();
}

using namespace kwiver::vital;

IMPLEMENT_TEST(create)
// ----------------------------------------------------------------------------
TEST(estimate_essential_matrix, create)
{
using namespace kwiver::arrows;
algo::estimate_essential_matrix_sptr est_e = algo::estimate_essential_matrix::create("vxl");
if (!est_e)
{
TEST_ERROR("Unable to create vxl::estimate_essential_matrix by name");
}
EXPECT_NE( nullptr, algo::estimate_essential_matrix::create("vxl") );
}


// ----------------------------------------------------------------------------
// Print epipolar distance of pairs of points given a fundamental matrix
void print_epipolar_distances(const kwiver::vital::matrix_3x3d& F,
const std::vector<kwiver::vital::vector_2d> right_pts,
Expand All @@ -93,9 +83,9 @@ void print_epipolar_distances(const kwiver::vital::matrix_3x3d& F,
}
}


// test essential matrix estimation with ideal points
IMPLEMENT_TEST(ideal_points)
// ----------------------------------------------------------------------------
// Test essential matrix estimation with ideal points
TEST(estimate_essential_matrix, ideal_points)
{
using namespace kwiver::arrows;
vxl::estimate_essential_matrix est_e;
Expand Down Expand Up @@ -139,29 +129,27 @@ IMPLEMENT_TEST(ideal_points)

// compute the essential matrix from the corresponding points
std::vector<bool> inliers;
essential_matrix_sptr E_sptr = est_e.estimate(pts1, pts2, cal1, cal2,
inliers, 1.5);
matrix_3x3d E = E_sptr->matrix();
auto estimated_E_sptr = est_e.estimate(pts1, pts2, cal1, cal2, inliers, 1.5);
matrix_3x3d estimated_E = estimated_E_sptr->matrix();
// check for sign difference
if( true_E->matrix().cwiseProduct(E).sum() < 0.0 )
if( true_E->matrix().cwiseProduct(estimated_E).sum() < 0.0 )
{
E *= -1;
estimated_E *= -1;
}

// compare true and computed essential matrices
std::cout << "true E = "<< *true_E << std::endl;
std::cout << "Estimated E = "<< E << std::endl;
TEST_NEAR("Essential Matrix Estimate", E, true_E->matrix(), 1e-8);
std::cout << "Estimated E = "<< estimated_E << std::endl;
EXPECT_MATRIX_NEAR( true_E->matrix(), estimated_E, 1e-8 );

unsigned num_inliers = static_cast<unsigned>(std::count(inliers.begin(),
inliers.end(), true));
std::cout << "num inliers "<<num_inliers<<std::endl;
TEST_EQUAL("All points are inliers", num_inliers, pts1.size());
std::cout << "num inliers " << inliers.size() << std::endl;
EXPECT_EQ( pts1.size(), inliers.size() )
<< "All points should be inliers";
}


// test essential matrix estimation with noisy points
IMPLEMENT_TEST(noisy_points)
// ----------------------------------------------------------------------------
// Test essential matrix estimation with noisy points
TEST(estimate_essential_matrix, noisy_points)
{
using namespace kwiver::arrows;
vxl::estimate_essential_matrix est_e;
Expand Down Expand Up @@ -208,23 +196,20 @@ IMPLEMENT_TEST(noisy_points)

// compute the essential matrix from the corresponding points
std::vector<bool> inliers;
essential_matrix_sptr E_sptr = est_e.estimate(pts1, pts2, cal1, cal2,
inliers, 1.5);
matrix_3x3d E = E_sptr->matrix();
auto estimated_E_sptr = est_e.estimate(pts1, pts2, cal1, cal2, inliers, 1.5);
matrix_3x3d estimated_E = estimated_E_sptr->matrix();
// check for sign difference
if( true_E->matrix().cwiseProduct(E).sum() < 0.0 )
if( true_E->matrix().cwiseProduct(estimated_E).sum() < 0.0 )
{
E *= -1;
estimated_E *= -1;
}

// compare true and computed essential matrices
std::cout << "true E = "<< *true_E << std::endl;
std::cout << "Estimated E = "<< E << std::endl;
TEST_NEAR("Essential Matrix Estimate", E, true_E->matrix(), 0.01);

unsigned num_inliers = static_cast<unsigned>(std::count(inliers.begin(),
inliers.end(), true));
std::cout << "num inliers "<<num_inliers<<std::endl;
bool enough_inliers = num_inliers > pts1.size() / 3;
TEST_EQUAL("Enough inliers", enough_inliers, true);
std::cout << "Estimated E = "<< estimated_E << std::endl;
EXPECT_MATRIX_NEAR( true_E->matrix(), estimated_E, 1e-2 );

std::cout << "num inliers " << inliers.size() << std::endl;
EXPECT_GT( inliers.size(), pts1.size() / 3 )
<< "Not enough inliers";
}
87 changes: 36 additions & 51 deletions arrows/vxl/tests/test_estimate_fundamental_matrix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <test_common.h>
#include <test_math.h>
#include <test_eigen.h>
#include <test_scene.h>

#include <vital/plugin_loader/plugin_manager.h>
Expand All @@ -41,36 +40,27 @@

#include <Eigen/LU>

#include <gtest/gtest.h>

#define TEST_ARGS ()

DECLARE_TEST_MAP();
using namespace kwiver::vital;

int
main(int argc, char* argv[])
// ----------------------------------------------------------------------------
int main(int argc, char** argv)
{
CHECK_ARGS(1);
::testing::InitGoogleTest( &argc, argv );

kwiver::vital::plugin_manager::instance().load_all_plugins();

testname_t const testname = argv[1];

RUN_TEST(testname);
return RUN_ALL_TESTS();
}

using namespace kwiver::vital;

IMPLEMENT_TEST(create)
// ----------------------------------------------------------------------------
TEST(estimate_fundamental_matrix, create)
{
using namespace kwiver::arrows;
algo::estimate_fundamental_matrix_sptr est_e = algo::estimate_fundamental_matrix::create("vxl");
if (!est_e)
{
TEST_ERROR("Unable to create vxl::estimate_fundamental_matrix by name");
}
EXPECT_NE( nullptr, algo::estimate_fundamental_matrix::create("vxl") );
}


// ----------------------------------------------------------------------------
// Print epipolar distance of pairs of points given a fundamental matrix
void print_epipolar_distances(const kwiver::vital::matrix_3x3d& F,
const std::vector<kwiver::vital::vector_2d> right_pts,
Expand All @@ -94,9 +84,9 @@ void print_epipolar_distances(const kwiver::vital::matrix_3x3d& F,
}
}


// test fundamental matrix estimation with ideal points
IMPLEMENT_TEST(ideal_points)
// ----------------------------------------------------------------------------
// Test fundamental matrix estimation with ideal points
TEST(estimate_fundamental_matrix, ideal_points)
{
using namespace kwiver::arrows;
vxl::estimate_fundamental_matrix est_f;
Expand Down Expand Up @@ -139,29 +129,27 @@ IMPLEMENT_TEST(ideal_points)

// compute the fundmental matrix from the corresponding points
std::vector<bool> inliers;
fundamental_matrix_sptr F_sptr = est_f.estimate(pts1, pts2,
inliers, 1.5);
matrix_3x3d F = F_sptr->matrix();
auto estimated_F_sptr = est_f.estimate( pts1, pts2, inliers, 1.5 );
matrix_3x3d estimated_F = estimated_F_sptr->matrix();
// check for sign difference
if( true_F->matrix().cwiseProduct(F).sum() < 0.0 )
if( true_F->matrix().cwiseProduct(estimated_F).sum() < 0.0 )
{
F *= -1;
estimated_F *= -1;
}

// compare true and computed fundamental matrices
std::cout << "true F = "<<*true_F<<std::endl;
std::cout << "Estimated F = "<< F <<std::endl;
TEST_NEAR("Fundamental Matrix Estimate", F, true_F->matrix(), 1e-8);
std::cout << "Estimated F = "<< estimated_F <<std::endl;
EXPECT_MATRIX_NEAR( true_F->matrix(), estimated_F, 1e-8 );

unsigned num_inliers = static_cast<unsigned>(std::count(inliers.begin(),
inliers.end(), true));
std::cout << "num inliers "<<num_inliers<<std::endl;
TEST_EQUAL("All points are inliers", num_inliers, pts1.size());
std::cout << "num inliers " << inliers.size() << std::endl;
EXPECT_EQ( pts1.size(), inliers.size() )
<< "All points should be inliers";
}


// test essential matrix estimation with noisy points
IMPLEMENT_TEST(noisy_points)
// ----------------------------------------------------------------------------
// Test essential matrix estimation with noisy points
TEST(estimate_fundamental_matrix, noisy_points)
{
using namespace kwiver::arrows;
vxl::estimate_fundamental_matrix est_f;
Expand Down Expand Up @@ -206,23 +194,20 @@ IMPLEMENT_TEST(noisy_points)

// compute the essential matrix from the corresponding points
std::vector<bool> inliers;
fundamental_matrix_sptr F_sptr = est_f.estimate(pts1, pts2,
inliers, 1.5);
matrix_3x3d F = F_sptr->matrix();
auto estimated_F_sptr = est_f.estimate( pts1, pts2, inliers, 1.5 );
matrix_3x3d estimated_F = estimated_F_sptr->matrix();
// check for sign difference
if( true_F->matrix().cwiseProduct(F).sum() < 0.0 )
if( true_F->matrix().cwiseProduct(estimated_F).sum() < 0.0 )
{
F *= -1;
estimated_F *= -1;
}

// compare true and computed fundamental matrices
std::cout << "true F = "<<*true_F<<std::endl;
std::cout << "Estimated F = "<< F <<std::endl;
TEST_NEAR("Fundamental Matrix Estimate", F, true_F->matrix(), 0.01);

unsigned num_inliers = static_cast<unsigned>(std::count(inliers.begin(),
inliers.end(), true));
std::cout << "num inliers "<<num_inliers<<std::endl;
bool enough_inliers = num_inliers > pts1.size() / 3;
TEST_EQUAL("Enough inliers", enough_inliers, true);
std::cout << "Estimated F = "<< estimated_F <<std::endl;
EXPECT_MATRIX_NEAR( true_F->matrix(), estimated_F, 0.01 );

std::cout << "num inliers " << inliers.size() << std::endl;
EXPECT_GT( inliers.size(), pts1.size() / 3 )
<< "Not enough inliers";
}
Loading