#include <string>
#include <visp3/core/vpMomentAlpha.h>
#include <visp3/core/vpMomentBasic.h>
#include <visp3/core/vpMomentCentered.h>
#include <visp3/core/vpMomentDatabase.h>
#include <visp3/core/vpMomentGravityCenter.h>
#include <visp3/core/vpMomentObject.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
#endif
int test_moment_alpha(const std::string &name, bool symmetry, const std::vector<int> &vec_angle, double tolerance_deg,
double symmetry_threshold = 1e-6)
{
std::cout << "** Test " << (symmetry == true ? "symmetric " : "non symmetric ") << name << " object" << std::endl;
std::cout << "*** Test symmetry detection from mu 3rd order moments" << std::endl;
std::vector<double> mu_ref;
double alpha_ref = 0.;
for (unsigned int i = (unsigned int)vec_angle.size(); i >= 1; --i) {
std::stringstream ss;
ss << name << "-" << vec_angle[i - 1] << "deg.pgm";
std::cout << "Process image " << ss.str() << std::endl;
{
mu_ref.clear();
mu_ref.push_back(mc.
get(3, 0));
mu_ref.push_back(mc.
get(2, 1));
mu_ref.push_back(mc.
get(1, 2));
mu_ref.push_back(mc.
get(0, 3));
alpha_ref = malpha_ref.
get();
}
{
std::cout << "Error in symmety detection" << std::endl;
return EXIT_FAILURE;
}
}
}
std::cout << "*** Compute angle in relative mode using the last reference from the previous test" << std::endl;
for (size_t i = 0; i < vec_angle.size(); i++) {
std::stringstream ss;
ss << name << "-" << vec_angle[i] << "deg.pgm";
std::cout << "Process image " << ss.str() << std::endl;
if (!symmetry) {
double angle = vec_angle[i];
if (angle > 180)
angle -= 360;
if (angle < -180)
angle += 360;
std::cout <<
"alpha expected " << angle <<
" computed " <<
vpMath::deg(malpha.
get()) <<
" deg" << std::endl;
std::cout << "Error: result is not in the tolerance: " << tolerance_deg << std::endl;
return EXIT_FAILURE;
}
}
else {
double angle_des1 = vec_angle[i];
double angle_des2 = vec_angle[i] - 180;
std::cout << "alpha expected " << angle_des1 << " or " << angle_des2 << " computed " << alpha << " deg"
<< std::endl;
std::cout << "Error: result is not in the tolerance: " << tolerance_deg << std::endl;
return EXIT_FAILURE;
}
}
}
std::cout << "Test succeed" << std::endl;
return EXIT_SUCCESS;
}
int main()
{
std::string name;
bool symmetry;
double tolerance_deg;
std::vector<int> vec_angle;
double symmetry_threshold;
name = "arrow";
symmetry = false;
tolerance_deg = 0.5;
vec_angle.clear();
vec_angle.push_back(0);
vec_angle.push_back(45);
vec_angle.push_back(90);
vec_angle.push_back(135);
vec_angle.push_back(180);
vec_angle.push_back(225);
vec_angle.push_back(270);
vec_angle.push_back(315);
if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
return EXIT_FAILURE;
}
name = "ellipse";
symmetry = true;
tolerance_deg = 0.5;
vec_angle.clear();
vec_angle.push_back(0);
vec_angle.push_back(45);
vec_angle.push_back(90);
vec_angle.push_back(135);
if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
return EXIT_FAILURE;
}
name = "ellipse-xfig";
symmetry = true;
tolerance_deg = 2.5;
symmetry_threshold = 1e-2;
vec_angle.clear();
vec_angle.push_back(0);
vec_angle.push_back(45);
vec_angle.push_back(90);
vec_angle.push_back(135);
if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg, symmetry_threshold) == EXIT_FAILURE) {
return EXIT_FAILURE;
}
name = "baleine";
symmetry = false;
tolerance_deg = 5.;
vec_angle.clear();
vec_angle.push_back(0);
vec_angle.push_back(45);
vec_angle.push_back(90);
vec_angle.push_back(135);
vec_angle.push_back(180);
vec_angle.push_back(225);
vec_angle.push_back(270);
vec_angle.push_back(315);
if (test_moment_alpha(name, symmetry, vec_angle, tolerance_deg) == EXIT_FAILURE) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
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.
bool is_symmetric() const
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 setType(vpObjectType input_type)
void fromImage(const vpImage< unsigned char > &image, unsigned char threshold, const vpCameraParameters &cam)
void linkTo(vpMomentDatabase &moments)