41 #include <visp3/core/vpMomentAlpha.h>
42 #include <visp3/core/vpMomentBasic.h>
43 #include <visp3/core/vpMomentCentered.h>
44 #include <visp3/core/vpMomentDatabase.h>
45 #include <visp3/core/vpMomentGravityCenter.h>
46 #include <visp3/core/vpMomentObject.h>
47 #include <visp3/io/vpImageIo.h>
49 #ifdef ENABLE_VISP_NAMESPACE
53 int test_moment_alpha(
const std::string &name,
bool symmetry,
const std::vector<int> &vec_angle,
double tolerance_deg,
54 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;
91 mu_ref.push_back(mc.
get(3, 0));
92 mu_ref.push_back(mc.
get(2, 1));
93 mu_ref.push_back(mc.
get(1, 2));
94 mu_ref.push_back(mc.
get(0, 3));
95 alpha_ref = malpha_ref.
get();
101 obj.fromImage(I, 127,
115 if (malpha.is_symmetric() != symmetry) {
116 std::cout <<
"Error in symmety detection" << std::endl;
123 std::cout <<
"*** Compute angle in relative mode using the last reference from the previous test" << std::endl;
125 for (
size_t i = 0; i < vec_angle.size(); i++) {
126 std::stringstream ss;
127 ss << name <<
"-" << vec_angle[i] <<
"deg.pgm";
128 std::cout <<
"Process image " << ss.str() << std::endl;
148 double angle = vec_angle[i];
154 std::cout <<
"alpha expected " << angle <<
" computed " <<
vpMath::deg(malpha.get()) <<
" deg" << std::endl;
157 std::cout <<
"Error: result is not in the tolerance: " << tolerance_deg << std::endl;
163 double angle_des1 = vec_angle[i];
164 double angle_des2 = vec_angle[i] - 180;
169 std::cout <<
"alpha expected " << angle_des1 <<
" or " << angle_des2 <<
" computed " << alpha <<
" deg"
174 std::cout <<
"Error: result is not in the tolerance: " << tolerance_deg << std::endl;
179 std::cout <<
"Test succeed" << std::endl;
187 double tolerance_deg;
188 std::vector<int> vec_angle;
189 double symmetry_threshold;
198 vec_angle.push_back(0);
199 vec_angle.push_back(45);
200 vec_angle.push_back(90);
201 vec_angle.push_back(135);
202 vec_angle.push_back(180);
203 vec_angle.push_back(225);
204 vec_angle.push_back(270);
205 vec_angle.push_back(315);
207 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
218 vec_angle.push_back(0);
219 vec_angle.push_back(45);
220 vec_angle.push_back(90);
221 vec_angle.push_back(135);
223 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
230 name =
"ellipse-xfig";
233 symmetry_threshold = 1e-2;
235 vec_angle.push_back(0);
236 vec_angle.push_back(45);
237 vec_angle.push_back(90);
238 vec_angle.push_back(135);
240 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg, symmetry_threshold) == EXIT_FAILURE) {
251 vec_angle.push_back(0);
252 vec_angle.push_back(45);
253 vec_angle.push_back(90);
254 vec_angle.push_back(135);
255 vec_angle.push_back(180);
256 vec_angle.push_back(225);
257 vec_angle.push_back(270);
258 vec_angle.push_back(315);
260 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)