46 #include <visp3/core/vpMomentObject.h> 47 #include <visp3/core/vpMomentGravityCenter.h> 48 #include <visp3/core/vpMomentDatabase.h> 49 #include <visp3/core/vpMomentCentered.h> 50 #include <visp3/core/vpMomentAlpha.h> 51 #include <visp3/core/vpMomentBasic.h> 52 #include <visp3/io/vpImageIo.h> 54 int test_moment_alpha(
const std::string &name,
bool symmetry,
const std::vector<int> &vec_angle,
double tolerance_deg,
double symmetry_threshold=1e-6)
58 std::cout <<
"** Test " << (symmetry ==
true ?
"symmetric " :
"non symmetric ") << name <<
" object" << std::endl;
61 std::cout <<
"*** Test symmetry detection from mu 3rd order moments" << std::endl;
63 std::vector<double> mu_ref;
64 double alpha_ref = 0.;
65 for(
unsigned int i = (
unsigned int)vec_angle.size(); i >= 1; --i) {
68 ss << name <<
"-" << vec_angle[i-1] <<
"deg.pgm";
69 std::cout <<
"Process image " << ss.str() << std::endl;
90 mu_ref.push_back(mc.
get(3,0));
91 mu_ref.push_back(mc.
get(2,1));
92 mu_ref.push_back(mc.
get(1,2));
93 mu_ref.push_back(mc.
get(0,3));
94 alpha_ref = malpha_ref.
get();
113 if (malpha.is_symmetric() != symmetry) {
114 std::cout <<
"Error in symmety detection" << std::endl;
121 std::cout <<
"*** Compute angle in relative mode using the last reference from the previous test" << std::endl;
123 for(
size_t i = 0; i < vec_angle.size(); i++) {
124 std::stringstream ss;
125 ss << name <<
"-" << vec_angle[i] <<
"deg.pgm";
127 std::cout <<
"Process image " << ss.str() << std::endl;
147 double angle = vec_angle[i];
153 std::cout <<
"alpha expected " << angle <<
" computed " <<
vpMath::deg(malpha.get()) <<
" deg" << std::endl;
156 std::cout <<
"Error: result is not in the tolerance: " << tolerance_deg << std::endl;
162 double angle_des1 = vec_angle[i];
163 double angle_des2 = vec_angle[i] - 180;
168 std::cout <<
"alpha expected " << angle_des1 <<
" or " << angle_des2 <<
" computed " << alpha <<
" deg" << std::endl;
171 std::cout <<
"Error: result is not in the tolerance: " << tolerance_deg << std::endl;
176 std::cout <<
"Test succeed" << std::endl;
184 double tolerance_deg;
185 std::vector<int> vec_angle;
186 double symmetry_threshold;
195 vec_angle.push_back(0);
196 vec_angle.push_back(45);
197 vec_angle.push_back(90);
198 vec_angle.push_back(135);
199 vec_angle.push_back(180);
200 vec_angle.push_back(225);
201 vec_angle.push_back(270);
202 vec_angle.push_back(315);
204 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
215 vec_angle.push_back(0);
216 vec_angle.push_back(45);
217 vec_angle.push_back(90);
218 vec_angle.push_back(135);
220 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
227 name =
"ellipse-xfig";
230 symmetry_threshold = 1e-2;
232 vec_angle.push_back(0);
233 vec_angle.push_back(45);
234 vec_angle.push_back(90);
235 vec_angle.push_back(135);
237 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg, symmetry_threshold) == EXIT_FAILURE) {
248 vec_angle.push_back(0);
249 vec_angle.push_back(45);
250 vec_angle.push_back(90);
251 vec_angle.push_back(135);
252 vec_angle.push_back(180);
253 vec_angle.push_back(225);
254 vec_angle.push_back(270);
255 vec_angle.push_back(315);
257 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
static bool equal(double x, double y, double s=0.001)
void linkTo(vpMomentDatabase &moments)
Class for generic objects.
This class allows to register all vpMoments so they can access each other according to their dependen...
Generic class defining intrinsic camera parameters.
virtual void updateAll(vpMomentObject &object)
This class defines the double-indexed centered moment descriptor .
This class defines the orientation of the object inside the plane parallel to the object...
double get(unsigned int i, unsigned int j) const
Class describing 2D gravity center moment.
static double deg(double rad)
static void read(vpImage< unsigned char > &I, const std::string &filename)