39 #include <visp3/core/vpConfig.h>
41 #if defined(VISP_HAVE_CATCH2)
43 #include <visp3/core/vpGaussRand.h>
44 #include <visp3/core/vpMath.h>
46 #include <catch_amalgamated.hpp>
48 #ifdef ENABLE_VISP_NAMESPACE
54 void convertLineEquation(
double A,
double B,
double C,
double &a,
double &b)
61 TEST_CASE(
"Line fitting - Horizontal",
"[line_fitting]")
63 std::cout <<
"\nLine fitting - Horizontal" << std::endl;
65 std::vector<vpImagePoint> imPts;
66 for (
int i = 0; i < 3; i++) {
69 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
72 double A = 0, B = 0, C = 0;
74 std::cout <<
"error: " << error << std::endl;
75 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
76 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
77 double a_est = 0, b_est = 0;
78 convertLineEquation(A, B, C, a_est, b_est);
79 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
81 CHECK(a == Catch::Approx(a_est).margin(1e-6));
82 CHECK(b == Catch::Approx(b_est).epsilon(1e-6));
85 TEST_CASE(
"Line fitting",
"[line_fitting]")
87 std::cout <<
"\nLine fitting" << std::endl;
88 double a = -4.68, b = 21.456;
89 std::vector<vpImagePoint> imPts;
90 const int nbPoints = 10;
91 for (
int i = 0; i < nbPoints; i++) {
95 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
98 double A = 0, B = 0, C = 0;
100 std::cout <<
"error: " << error << std::endl;
101 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
102 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
103 double a_est = 0, b_est = 0;
104 convertLineEquation(A, B, C, a_est, b_est);
105 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
107 CHECK(a == Catch::Approx(a_est).epsilon(1e-6));
108 CHECK(b == Catch::Approx(b_est).epsilon(1e-6));
111 TEST_CASE(
"Line fitting - Gaussian noise",
"[line_fitting]")
113 std::cout <<
"\nLine fitting - Gaussian noise" << std::endl;
114 const double sigma = 3, mean = 0;
117 double a = -4.68, b = 21.456;
118 std::vector<vpImagePoint> imPts;
119 const int nbPoints = 10;
120 for (
int i = 0; i < nbPoints; i++) {
122 double y = a * x + b;
123 imPts.push_back(
vpImagePoint(y + gauss(), x + gauss()));
124 std::cout <<
"x: " << x <<
" ; y: " << y <<
" ; imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v()
128 double A = 0, B = 0, C = 0;
130 std::cout <<
"error: " << error << std::endl;
131 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
132 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
133 double a_est = 0, b_est = 0;
134 convertLineEquation(A, B, C, a_est, b_est);
135 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
137 REQUIRE(error < sigma);
140 int main(
int argc,
char *argv[])
142 Catch::Session session;
143 session.applyCommandLine(argc, argv);
144 int numFailed = session.run();
150 int main() {
return EXIT_SUCCESS; }
Class for generating random number with normal probability density.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double lineFitting(const std::vector< vpImagePoint > &imPts, double &a, double &b, double &c)