41 #include <visp3/core/vpConfig.h>
43 #ifdef VISP_HAVE_CATCH2
45 #include <visp3/core/vpGaussRand.h>
46 #include <visp3/core/vpMath.h>
48 #define CATCH_CONFIG_RUNNER
53 void convertLineEquation(
double A,
double B,
double C,
double &a,
double &b)
60 TEST_CASE(
"Line fitting - Horizontal",
"[line_fitting]")
62 std::cout <<
"\nLine fitting - Horizontal" << std::endl;
64 std::vector<vpImagePoint> imPts;
65 for (
int i = 0; i < 3; i++) {
68 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
71 double A = 0, B = 0, C = 0;
73 std::cout <<
"error: " << error << std::endl;
74 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
75 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
76 double a_est = 0, b_est = 0;
77 convertLineEquation(A, B, C, a_est, b_est);
78 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
80 CHECK(a == Approx(a_est).margin(1e-6));
81 CHECK(b == Approx(b_est).epsilon(1e-6));
84 TEST_CASE(
"Line fitting",
"[line_fitting]")
86 std::cout <<
"\nLine fitting" << std::endl;
87 double a = -4.68, b = 21.456;
88 std::vector<vpImagePoint> imPts;
89 const int nbPoints = 10;
90 for (
int i = 0; i < nbPoints; i++) {
94 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
97 double A = 0, B = 0, C = 0;
99 std::cout <<
"error: " << error << std::endl;
100 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
101 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
102 double a_est = 0, b_est = 0;
103 convertLineEquation(A, B, C, a_est, b_est);
104 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
106 CHECK(a == Approx(a_est).epsilon(1e-6));
107 CHECK(b == Approx(b_est).epsilon(1e-6));
110 TEST_CASE(
"Line fitting - Gaussian noise",
"[line_fitting]")
112 std::cout <<
"\nLine fitting - Gaussian noise" << std::endl;
113 const double sigma = 3, mean = 0;
116 double a = -4.68, b = 21.456;
117 std::vector<vpImagePoint> imPts;
118 const int nbPoints = 10;
119 for (
int i = 0; i < nbPoints; i++) {
121 double y = a * x + b;
122 imPts.push_back(
vpImagePoint(y + gauss(), x + gauss()));
123 std::cout <<
"x: " << x <<
" ; y: " << y <<
" ; imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v()
127 double A = 0, B = 0, C = 0;
129 std::cout <<
"error: " << error << std::endl;
130 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
131 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
132 double a_est = 0, b_est = 0;
133 convertLineEquation(A, B, C, a_est, b_est);
134 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
136 REQUIRE(error < sigma);
139 int main(
int argc,
char *argv[])
141 Catch::Session session;
144 session.applyCommandLine(argc, argv);
146 int numFailed = session.run();
156 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)