MCPcopy Create free account
hub / github.com/danini/magsac / testEssentialMatrixFitting

Function testEssentialMatrixFitting

examples/cpp_example.cpp:368–531  ·  view source on GitHub ↗

A method applying MAGSAC for essential matrix estimation to one of the built-in scenes

Source from the content-addressed store, hash-verified

366
367// A method applying MAGSAC for essential matrix estimation to one of the built-in scenes
368void testEssentialMatrixFitting(
369 double ransac_confidence_,
370 double maximum_threshold_,
371 const std::string &test_scene_,
372 bool use_magsac_plus_plus_, // A flag to decide if MAGSAC++ or MAGSAC should be used
373 bool draw_results_,
374 double drawing_threshold_)
375{
376 std::cout << "Processed scene = '" << test_scene_ << "'";
377
378 // Load the images of the current test scene
379 cv::Mat image1 = cv::imread("../data/essential_matrix/" + test_scene_ + "1.png");
380 cv::Mat image2 = cv::imread("../data/essential_matrix/" + test_scene_ + "2.png");
381 if (image1.cols == 0)
382 {
383 image1 = cv::imread("../data/essential_matrix/" + test_scene_ + "1.jpg");
384 image2 = cv::imread("../data/essential_matrix/" + test_scene_ + "2.jpg");
385 }
386
387 if (image1.cols == 0)
388 {
389 std::cerr << "A problem occured when loading the images for test scene " << test_scene_ << ".";
390 return;
391 }
392
393 cv::Mat points; // The point correspondences, each is of format x1 y1 x2 y2
394 Eigen::Matrix3d intrinsics_source, // The intrinsic parameters of the source camera
395 intrinsics_destination; // The intrinsic parameters of the destination camera
396
397 // A function loading the points from files
398 readPoints<4>("../data/essential_matrix/" + test_scene_ + "_pts.txt",
399 points);
400
401 // Loading the intrinsic camera matrices
402 static const std::string source_intrinsics_path = "../data/essential_matrix/" + test_scene_ + "1.K";
403 if (!gcransac::utils::loadMatrix<double, 3, 3>(source_intrinsics_path,
404 intrinsics_source))
405 {
406 std::cerr << "An error occured when loading the intrinsics camera matrix from " << source_intrinsics_path << ".";
407 return;
408 }
409
410 static const std::string destination_intrinsics_path = "../data/essential_matrix/" + test_scene_ + "2.K";
411 if (!gcransac::utils::loadMatrix<double, 3, 3>(destination_intrinsics_path,
412 intrinsics_destination))
413 {
414 std::cerr << "An error occured when loading the intrinsics camera matrix from " << destination_intrinsics_path << ".";
415 return;
416 }
417
418 // Normalize the point coordinates by the intrinsic matrices
419 cv::Mat normalized_points(points.size(), CV_64F);
420 gcransac::utils::normalizeCorrespondences(points,
421 intrinsics_source,
422 intrinsics_destination,
423 normalized_points);
424
425 // Normalize the threshold by the average of the focal lengths

Callers 1

runTestFunction · 0.85

Calls 6

showImageFunction · 0.85
setMaximumThresholdMethod · 0.80
setReferenceThresholdMethod · 0.80
getReferenceThresholdMethod · 0.80
setIterationLimitMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected