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";
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;
161 double angle_des1 = vec_angle[i];
162 double angle_des2 = vec_angle[i] - 180;
167 std::cout <<
"alpha expected " << angle_des1 <<
" or " << angle_des2 <<
" computed " << alpha <<
" deg" << std::endl;
170 std::cout <<
"Error: result is not in the tolerance: " << tolerance_deg << std::endl;
175 std::cout <<
"Test succeed" << std::endl;
183 double tolerance_deg;
184 std::vector<int> vec_angle;
185 double symmetry_threshold;
194 vec_angle.push_back(0);
195 vec_angle.push_back(45);
196 vec_angle.push_back(90);
197 vec_angle.push_back(135);
198 vec_angle.push_back(180);
199 vec_angle.push_back(225);
200 vec_angle.push_back(270);
201 vec_angle.push_back(315);
203 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
214 vec_angle.push_back(0);
215 vec_angle.push_back(45);
216 vec_angle.push_back(90);
217 vec_angle.push_back(135);
219 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
226 name =
"ellipse-xfig";
229 symmetry_threshold = 1e-2;
231 vec_angle.push_back(0);
232 vec_angle.push_back(45);
233 vec_angle.push_back(90);
234 vec_angle.push_back(135);
236 if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg, symmetry_threshold) == EXIT_FAILURE) {
247 vec_angle.push_back(0);
248 vec_angle.push_back(45);
249 vec_angle.push_back(90);
250 vec_angle.push_back(135);
251 vec_angle.push_back(180);
252 vec_angle.push_back(225);
253 vec_angle.push_back(270);
254 vec_angle.push_back(315);
256 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)