43 #include <visp3/core/vpMomentAlpha.h>
44 #include <visp3/core/vpMomentBasic.h>
45 #include <visp3/core/vpMomentCentered.h>
46 #include <visp3/core/vpMomentDatabase.h>
47 #include <visp3/core/vpMomentGravityCenter.h>
48 #include <visp3/core/vpMomentObject.h>
49 #include <visp3/io/vpImageIo.h>
51 int test_moment_alpha(
const std::string &name,
bool symmetry,
const std::vector<int> &vec_angle,
double tolerance_deg,
52 double symmetry_threshold = 1e-6)
56 std::cout <<
"** Test " << (symmetry ==
true ?
"symmetric " :
"non symmetric ") << name <<
" object" << std::endl;
59 std::cout <<
"*** Test symmetry detection from mu 3rd order moments" << std::endl;
61 std::vector<double> mu_ref;
62 double alpha_ref = 0.;
63 for (
unsigned int i = (
unsigned int)vec_angle.size(); i >= 1; --i) {
66 ss << name <<
"-" << vec_angle[i - 1] <<
"deg.pgm";
67 std::cout <<
"Process image " << ss.str() << std::endl;
89 mu_ref.push_back(mc.
get(3, 0));
90 mu_ref.push_back(mc.
get(2, 1));
91 mu_ref.push_back(mc.
get(1, 2));
92 mu_ref.push_back(mc.
get(0, 3));
93 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";
126 std::cout <<
"Process image " << ss.str() << std::endl;
146 double angle = vec_angle[i];
152 std::cout <<
"alpha expected " << angle <<
" computed " <<
vpMath::deg(malpha.get()) <<
" deg" << std::endl;
155 std::cout <<
"Error: result is not in the tolerance: " << tolerance_deg << std::endl;
160 double angle_des1 = vec_angle[i];
161 double angle_des2 = vec_angle[i] - 180;
166 std::cout <<
"alpha expected " << angle_des1 <<
" or " << angle_des2 <<
" computed " << alpha <<
" deg"
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) {
Generic class defining intrinsic camera parameters.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static bool equal(double x, double y, double threshold=0.001)
static double deg(double rad)
This class defines the orientation of the object inside the plane parallel to the object.
This class defines the double-indexed centered moment descriptor .
double get(unsigned int i, unsigned int j) const
This class allows to register all vpMoments so they can access each other according to their dependen...
virtual void updateAll(vpMomentObject &object)
Class describing 2D gravity center moment.
Class for generic objects.
void linkTo(vpMomentDatabase &moments)