41 #include <visp3/core/vpConfig.h> 43 #ifdef VISP_HAVE_CATCH2 45 #include <visp3/core/vpMath.h> 46 #include <visp3/core/vpGaussRand.h> 48 #define CATCH_CONFIG_RUNNER 52 void convertLineEquation(
double A,
double B,
double C,
double& a,
double& b)
59 TEST_CASE(
"Line fitting - Horizontal",
"[line_fitting]") {
60 std::cout <<
"\nLine fitting - Horizontal" << std::endl;
62 std::vector<vpImagePoint> imPts;
63 for (
int i = 0; i < 3; i++) {
66 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
69 double A = 0, B = 0, C = 0;
71 std::cout <<
"error: " << error << std::endl;
72 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
73 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
74 double a_est = 0, b_est = 0;
75 convertLineEquation(A, B, C, a_est, b_est);
76 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
78 CHECK(a == Approx(a_est).margin(1e-6));
79 CHECK(b == Approx(b_est).epsilon(1e-6));
82 TEST_CASE(
"Line fitting",
"[line_fitting]") {
83 std::cout <<
"\nLine fitting" << std::endl;
84 double a = -4.68, b = 21.456;
85 std::vector<vpImagePoint> imPts;
86 const int nbPoints = 10;
87 for (
int i = 0; i < nbPoints; i++) {
91 std::cout <<
"imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
94 double A = 0, B = 0, C = 0;
96 std::cout <<
"error: " << error << std::endl;
97 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
98 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
99 double a_est = 0, b_est = 0;
100 convertLineEquation(A, B, C, a_est, b_est);
101 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
103 CHECK(a == Approx(a_est).epsilon(1e-6));
104 CHECK(b == Approx(b_est).epsilon(1e-6));
107 TEST_CASE(
"Line fitting - Gaussian noise",
"[line_fitting]") {
108 std::cout <<
"\nLine fitting - Gaussian noise" << std::endl;
109 const double sigma = 3, mean = 0;
112 double a = -4.68, b = 21.456;
113 std::vector<vpImagePoint> imPts;
114 const int nbPoints = 10;
115 for (
int i = 0; i < nbPoints; i++) {
118 imPts.push_back(
vpImagePoint(y + gauss(), x + gauss()));
119 std::cout <<
"x: " << x <<
" ; y: " << y
120 <<
" ; imPts: (" << imPts.back().get_u() <<
", " << imPts.back().get_v() <<
")" << std::endl;
123 double A = 0, B = 0, C = 0;
125 std::cout <<
"error: " << error << std::endl;
126 std::cout <<
"a: " << a <<
" ; b: " << b << std::endl;
127 std::cout <<
"A: " << A <<
" ; B: " << B <<
" ; C: " << C << std::endl;
128 double a_est = 0, b_est = 0;
129 convertLineEquation(A, B, C, a_est, b_est);
130 std::cout <<
"-A/B: " << a_est <<
" ; -C/B: " << b_est << std::endl;
132 REQUIRE(error < sigma);
135 int main(
int argc,
char *argv[])
137 Catch::Session session;
140 session.applyCommandLine(argc, argv);
142 int numFailed = session.run();
static double lineFitting(const std::vector< vpImagePoint > &imPts, double &a, double &b, double &c)
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 ...