39 #include <visp3/core/vpConfig.h>
41 #ifdef VISP_HAVE_CATCH2
43 #include <visp3/core/vpGaussRand.h>
44 #include <visp3/core/vpMath.h>
46 #define CATCH_CONFIG_RUNNER
49 #ifdef ENABLE_VISP_NAMESPACE
55 void convertLineEquation(
double A,
double B,
double C,
double &a,
double &b)
62 TEST_CASE(
"Line fitting - Horizontal",
"[line_fitting]")
64 std::cout <<
"\nLine fitting - Horizontal" << std::endl;
66 std::vector<vpImagePoint> imPts;
67 for (
int i = 0; i < 3; i++) {
70 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
73 double A = 0, B = 0, C = 0;
75 std::cout <<
"error: " << error << std::endl;
76 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
77 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
78 double a_est = 0, b_est = 0;
79 convertLineEquation(A, B, C, a_est, b_est);
80 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
82 CHECK(a == Approx(a_est).margin(1e-6));
83 CHECK(b == Approx(b_est).epsilon(1e-6));
86 TEST_CASE(
"Line fitting",
"[line_fitting]")
88 std::cout <<
"\nLine fitting" << std::endl;
89 double a = -4.68, b = 21.456;
90 std::vector<vpImagePoint> imPts;
91 const int nbPoints = 10;
92 for (
int i = 0; i < nbPoints; i++) {
96 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
99 double A = 0, B = 0, C = 0;
101 std::cout <<
"error: " << error << std::endl;
102 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
103 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
104 double a_est = 0, b_est = 0;
105 convertLineEquation(A, B, C, a_est, b_est);
106 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
108 CHECK(a == Approx(a_est).epsilon(1e-6));
109 CHECK(b == Approx(b_est).epsilon(1e-6));
112 TEST_CASE(
"Line fitting - Gaussian noise",
"[line_fitting]")
114 std::cout <<
"\nLine fitting - Gaussian noise" << std::endl;
115 const double sigma = 3, mean = 0;
118 double a = -4.68, b = 21.456;
119 std::vector<vpImagePoint> imPts;
120 const int nbPoints = 10;
121 for (
int i = 0; i < nbPoints; i++) {
123 double y = a * x + b;
124 imPts.push_back(
vpImagePoint(y + gauss(), x + gauss()));
125 std::cout <<
"x: " << x <<
" ; y: " << y <<
" ; imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v()
129 double A = 0, B = 0, C = 0;
131 std::cout <<
"error: " << error << std::endl;
132 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
133 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
134 double a_est = 0, b_est = 0;
135 convertLineEquation(A, B, C, a_est, b_est);
136 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
138 REQUIRE(error < sigma);
141 int main(
int argc,
char *argv[])
143 Catch::Session session;
146 session.applyCommandLine(argc, argv);
148 int numFailed = session.run();
158 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)