Test line fitting.
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_CATCH2
#include <visp3/core/vpMath.h>
#include <visp3/core/vpGaussRand.h>
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
namespace {
void convertLineEquation(double A, double B, double C, double& a, double& b)
{
a = -A/B;
b = C/B;
}
}
TEST_CASE("Line fitting - Horizontal", "[line_fitting]") {
std::cout << "\nLine fitting - Horizontal" << std::endl;
double a = 0, b = 10;
std::vector<vpImagePoint> imPts;
for (int i = 0; i < 3; i++) {
double x = i*10;
std::cout << "imPts: (" << imPts.back().get_u() << ", " << imPts.back().get_v() << ")" << std::endl;
}
double A = 0, B = 0, C = 0;
std::cout << "error: " << error << std::endl;
std::cout << "a: " << a << " ; b: " << b << std::endl;
std::cout << "A: " << A << " ; B: " << B << " ; C: " << C << std::endl;
double a_est = 0, b_est = 0;
convertLineEquation(A, B, C, a_est, b_est);
std::cout << "-A/B: " << a_est << " ; -C/B: " << b_est << std::endl;
CHECK(a == Approx(a_est).margin(1e-6));
CHECK(b == Approx(b_est).epsilon(1e-6));
}
TEST_CASE("Line fitting", "[line_fitting]") {
std::cout << "\nLine fitting" << std::endl;
double a = -4.68, b = 21.456;
std::vector<vpImagePoint> imPts;
const int nbPoints = 10;
for (int i = 0; i < nbPoints; i++) {
double x = i*10;
double y = a*x + b;
std::cout << "imPts: (" << imPts.back().get_u() << ", " << imPts.back().get_v() << ")" << std::endl;
}
double A = 0, B = 0, C = 0;
std::cout << "error: " << error << std::endl;
std::cout << "a: " << a << " ; b: " << b << std::endl;
std::cout << "A: " << A << " ; B: " << B << " ; C: " << C << std::endl;
double a_est = 0, b_est = 0;
convertLineEquation(A, B, C, a_est, b_est);
std::cout << "-A/B: " << a_est << " ; -C/B: " << b_est << std::endl;
CHECK(a == Approx(a_est).epsilon(1e-6));
CHECK(b == Approx(b_est).epsilon(1e-6));
}
TEST_CASE("Line fitting - Gaussian noise", "[line_fitting]") {
std::cout << "\nLine fitting - Gaussian noise" << std::endl;
const double sigma = 3, mean = 0;
double a = -4.68, b = 21.456;
std::vector<vpImagePoint> imPts;
const int nbPoints = 10;
for (int i = 0; i < nbPoints; i++) {
double x = i*10;
double y = a*x + b;
std::cout << "x: " << x << " ; y: " << y
<< " ; imPts: (" << imPts.back().get_u() << ", " << imPts.back().get_v() << ")" << std::endl;
}
double A = 0, B = 0, C = 0;
std::cout << "error: " << error << std::endl;
std::cout << "a: " << a << " ; b: " << b << std::endl;
std::cout << "A: " << A << " ; B: " << B << " ; C: " << C << std::endl;
double a_est = 0, b_est = 0;
convertLineEquation(A, B, C, a_est, b_est);
std::cout << "-A/B: " << a_est << " ; -C/B: " << b_est << std::endl;
REQUIRE(error < sigma);
}
int main(int argc, char *argv[])
{
Catch::Session session;
session.applyCommandLine(argc, argv);
int numFailed = session.run();
return numFailed;
}
#else
#include <iostream>
int main()
{
return 0;
}
#endif