40 #include <visp3/core/vpCameraParameters.h>
41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpMomentBasic.h>
43 #include <visp3/core/vpMomentObject.h>
44 #include <visp3/core/vpPixelMeterConversion.h>
49 #ifdef VISP_HAVE_OPENMP
64 double vpMomentObject::calc_mom_polygon(
unsigned int p,
unsigned int q,
const std::vector<vpPoint> &points)
72 den =
static_cast<double>((p + q + 2) * (p + q + 1) *
vpMath::comb(p + q, p));
75 for (i = 1; i <= points.size() - 1; i++) {
78 for (k = 0; k <= p; k++) {
80 x_p_k = pow(points[i - 1].get_x(), (
int)(p - k));
81 for (l = 0; l <= q; l++) {
82 y_q_l = pow(points[i - 1].get_y(), (
int)(q - l));
87 y_l *= points[i].get_y();
89 x_k *= points[i].get_x();
92 s *= ((points[i - 1].get_x()) * (points[i].get_y()) - (points[i].get_x()) * (points[i - 1].get_y()));
116 for (
unsigned int i = 1; i <
order; i++)
117 cache[i] = cache[i - 1] * x;
120 cache[j] = cache[j -
order] * y;
122 for (
unsigned int j = 1; j <
order; j++) {
123 for (
unsigned int i = 1; i <
order - j; i++) {
124 cache[j *
order + i] = cache[j *
order] * cache[i];
136 cache[0] = IntensityNormalized;
138 double invIntensityNormalized = 0.;
139 if (std::fabs(IntensityNormalized) >= std::numeric_limits<double>::epsilon())
140 invIntensityNormalized = 1.0 / IntensityNormalized;
142 for (
unsigned int i = 1; i <
order; i++)
143 cache[i] = cache[i - 1] * x;
146 cache[j] = cache[j -
order] * y;
148 for (
unsigned int j = 1; j <
order; j++) {
149 for (
unsigned int i = 1; i <
order - j; i++) {
150 cache[j *
order + i] = cache[j *
order] * cache[i] * invIntensityNormalized;
239 if (std::fabs(points.rbegin()->get_x() - points.begin()->get_x()) > std::numeric_limits<double>::epsilon() ||
240 std::fabs(points.rbegin()->get_y() - points.begin()->get_y()) > std::numeric_limits<double>::epsilon()) {
241 points.resize(points.size() + 1);
242 points[points.size() - 1] = points[0];
244 for (
unsigned int j = 0; j <
order *
order; j++) {
251 for (
unsigned int i = 0; i < points.size(); i++) {
252 cacheValues(cache, points[i].get_x(), points[i].get_y());
253 for (
unsigned int j = 0; j <
order; j++) {
254 for (
unsigned int k = 0; k <
order - j; k++) {
303 #ifdef VISP_HAVE_OPENMP
304 #pragma omp parallel shared(threshold)
309 #pragma omp for nowait
310 for (
int i = 0; i < (int)image.
getCols(); i++) {
311 for (
int j = 0; j < (int)image.
getRows(); j++) {
312 unsigned int i_ =
static_cast<unsigned int>(i);
313 unsigned int j_ =
static_cast<unsigned int>(j);
314 if (image[j_][i_] > threshold) {
320 for (
unsigned int k = 0; k <
order; k++) {
322 for (
unsigned int l = 0; l <
order - k; l++) {
323 curvals[(k *
order + l)] += (xval * yval);
338 for (
unsigned int k = 0; k <
order; k++) {
339 for (
unsigned int l = 0; l <
order - k; l++) {
348 for (
unsigned int i = 0; i < image.
getCols(); i++) {
349 for (
unsigned int j = 0; j < image.
getRows(); j++) {
350 if (image[j][i] > threshold) {
355 for (
unsigned int k = 0; k <
order; k++) {
356 for (
unsigned int l = 0; l <
order - k; l++) {
366 double norm_factor = 1. / (cam.
get_px() * cam.
get_py());
367 for (std::vector<double>::iterator it =
values.begin(); it !=
values.end(); ++it) {
368 *it = (*it) * norm_factor;
393 unsigned int idx = 0;
394 unsigned int kidx = 0;
396 double intensity = 0;
409 for (
unsigned int j = 0; j < image.
getRows(); j++) {
410 for (
unsigned int i = 0; i < image.
getCols(); i++) {
413 intensity = (double)(image[j][i]) * iscale;
414 double intensity_white = 1. - intensity;
422 for (
unsigned int k = 0; k <
order; k++) {
424 for (
unsigned int l = 0; l <
order - k; l++) {
426 values[idx] += cache[idx];
434 for (
unsigned int j = 0; j < image.
getRows(); j++) {
435 for (
unsigned int i = 0; i < image.
getCols(); i++) {
438 intensity = (double)(image[j][i]) * iscale;
446 for (
unsigned int k = 0; k <
order; k++) {
448 for (
unsigned int l = 0; l <
order - k; l++) {
450 values[idx] += cache[idx];
457 if (normalize_with_pix_size) {
459 double norm_factor = 1. / (cam.
get_px() * cam.
get_py());
460 for (std::vector<double>::iterator it =
values.begin(); it !=
values.end(); ++it) {
461 *it = (*it) * norm_factor;
472 order = orderinp + 1;
507 : flg_normalize_intensity(true), order(max_order + 1), type(
vpMomentObject::DENSE_FULL_OBJECT), values()
516 : flg_normalize_intensity(true), order(1), type(
vpMomentObject::DENSE_FULL_OBJECT), values()
555 "been computed, you should "
556 "specify a higher order.");
572 "a higher order for the moment object.");
583 std::vector<double> moment = momobj.
get();
584 os << std::endl <<
"Order of vpMomentObject: " << momobj.
getOrder() << std::endl;
586 for (
unsigned int k = 0; k <= momobj.
getOrder(); k++) {
587 for (
unsigned int l = 0; l < (momobj.
getOrder() + 1) - k; l++) {
588 os <<
"m[" << l <<
"," << k <<
"] = " << moment[k * (momobj.
getOrder() + 1) + l] <<
"\t";
623 std::vector<double> moment = momobj.
get();
626 for (
unsigned int k = 0; k <=
order; k++) {
627 for (
unsigned int l = 0; l < (
order + 1) - k; l++) {
628 M[l][k] = moment[k * (
order + 1) + l];
664 for (
unsigned int i = 0; i < m.
values.size(); ++i) {
666 if (i % (m.
order) == 0)
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
unsigned int getCols() const
unsigned int getRows() const
static long double comb(unsigned int n, unsigned int p)
Implementation of a matrix and operations on matrices.
Class for generic objects.
static void printWithIndices(const vpMomentObject &momobj, std::ostream &os)
unsigned int getOrder() const
VP_EXPLICIT vpMomentObject(unsigned int order)
virtual ~vpMomentObject()
void cacheValues(std::vector< double > &cache, double x, double y)
bool flg_normalize_intensity
void set(unsigned int i, unsigned int j, const double &value_ij)
@ WHITE
Not functional right now.
const std::vector< double > & get() const
static vpMatrix convertTovpMatrix(const vpMomentObject &momobj)
std::vector< double > values
vpObjectType getType() const
void fromImage(const vpImage< unsigned char > &image, unsigned char threshold, const vpCameraParameters &cam)
void fromVector(std::vector< vpPoint > &points)
void init(unsigned int orderinp)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)