38 #include <visp3/core/vpMomentBasic.h>
39 #include <visp3/core/vpMomentObject.h>
40 #include <visp3/core/vpCameraParameters.h>
41 #include <visp3/core/vpPixelMeterConversion.h>
42 #include <visp3/core/vpConfig.h>
48 #ifdef VISP_HAVE_OPENMP
62 double vpMomentObject::calc_mom_polygon(
unsigned int p,
unsigned int q,
const std::vector<vpPoint>& points){
70 den =
static_cast<double>( (p+q+2)*(p+q+1)*
vpMath::comb(p+q,p) );
73 for (i=1;i<=points.size()-1;i++)
80 x_p_k = pow(points[i-1].get_x(), (
int)(p-k));
83 y_q_l=pow(points[i-1].get_y(), (
int)(q-l));
85 s +=
static_cast<double>(
93 y_l*=points[i].get_y();
96 x_k*=points[i].get_x();
100 s *= ((points[i-1].get_x())*(points[i].get_y())-(points[i].get_x())*(points[i-1].get_y()));
123 for(
register unsigned int i=1;i<
order;i++)
124 cache[i]=cache[i-1]*x;
126 for(
register unsigned int j=order;j<order*
order;j+=
order)
127 cache[j]=cache[j-order]*y;
129 for(
register unsigned int j=1;j<
order;j++){
130 for(
register unsigned int i=1;i<order-j;i++){
131 cache[j*order+i] = cache[j*
order]*cache[i];
142 cache[0]=IntensityNormalized;
144 double invIntensityNormalized = 0.;
145 if (std::fabs(IntensityNormalized)>=std::numeric_limits<double>::epsilon())
146 invIntensityNormalized = 1.0/IntensityNormalized;
148 for(
register unsigned int i=1;i<
order;i++)
149 cache[i]=cache[i-1]*x;
151 for(
register unsigned int j=order;j<order*
order;j+=
order)
152 cache[j]=cache[j-order]*y;
154 for(
register unsigned int j=1;j<
order;j++){
155 for(
register unsigned int i=1;i<order-j;i++){
156 cache[j*order+i] = cache[j*
order]*cache[i]*invIntensityNormalized;
237 std::abs(points.rbegin()->get_x()-points.begin()->get_x())>std::numeric_limits<double>::epsilon() ||
238 std::abs(points.rbegin()->get_y()-points.begin()->get_y())>std::numeric_limits<double>::epsilon()
240 points.resize(points.size()+1);
241 points[points.size()-1] = points[0];
243 for(
register unsigned int j=0;j<order*
order;j++){
244 values[j]=calc_mom_polygon(j%order,j/order,points);
247 std::vector<double> cache(order*order,0.);
248 values.assign(order*order,0);
249 for(
register unsigned int i=0;i<points.size();i++){
250 cacheValues(cache,points[i].get_x(),points[i].get_y());
251 for(
register unsigned int j=0;j<
order;j++){
252 for(
register unsigned int k=0;k<order-j;k++){
253 values[j*order+k]+=cache[j*order+k];
290 #ifdef VISP_HAVE_OPENMP
291 #pragma omp parallel shared(threshold)
293 std::vector<double> curvals(order*order);
294 curvals.assign(order*order,0.);
297 #pragma omp for nowait//automatically organize loop counter between threads
298 for(
int i=0;i<(int)image.
getCols();i++){
299 for(
int j=0;j<(int)image.
getRows();j++){
300 i_ =
static_cast<unsigned int>(i);
301 j_ =
static_cast<unsigned int>(j);
302 if(image[j_][i_]>threshold){
309 for(
register unsigned int k=0;k<
order;k++){
311 for(
register unsigned int l=0;l<order-k;l++){
312 curvals[(k*order+l)]+=(xval*yval);
321 #pragma omp master //only set this variable in master thread
323 values.assign(order*order, 0.);
328 for(
register unsigned int k=0;k<
order;k++){
329 for(
register unsigned int l=0;l<order-k;l++){
331 values[k*order+l]+= curvals[k*order+l];
337 std::vector<double> cache(order*order,0.);
338 values.assign(order*order,0);
339 for(
register unsigned int i=0;i<image.
getCols();i++){
340 for(
register unsigned int j=0;j<image.
getRows();j++){
341 if(image[j][i]>threshold){
346 for(
register unsigned int k=0;k<
order;k++){
347 for(
register unsigned int l=0;l<order-k;l++){
348 values[k*order+l]+=cache[k*order+l];
358 for (std::vector<double>::iterator it =
values.begin(); it!=
values.end(); it++) {
359 *it = (*it) * norm_factor;
376 std::vector<double> cache(order*order,0.);
377 values.assign(order*order,0);
383 unsigned int idx = 0;
384 unsigned int kidx = 0;
386 double intensity = 0;
387 double intensity_white = 0;
398 for(
register unsigned int j=0;j<image.
getRows();j++){
399 for(
register unsigned int i=0;i<image.
getCols();i++){
402 intensity = (double)(image[j][i])*iscale;
403 intensity_white = 1. - intensity;
409 for(
register unsigned int k=0;k<
order;k++){
411 for(
register unsigned int l=0;l<order-k;l++){
421 for(
register unsigned int j=0;j<image.
getRows();j++){
422 for(
register unsigned int i=0;i<image.
getCols();i++){
425 intensity = (double)(image[j][i])*iscale;
432 for(
register unsigned int k=0;k<
order;k++){
434 for(
register unsigned int l=0;l<order-k;l++){
444 if (normalize_with_pix_size){
447 for (std::vector<double>::iterator it =
values.begin(); it!=
values.end(); it++) {
448 *it = (*it) * norm_factor;
459 order = orderinp + 1;
462 values.resize((order+1)*(order+1));
463 values.assign((order+1)*(order+1),0);
492 : flg_normalize_intensity(true), order(max_order+1), type(
vpMomentObject::DENSE_FULL_OBJECT),
502 : flg_normalize_intensity(true), order(1), type(
vpMomentObject::DENSE_FULL_OBJECT),
554 values[j*order+i] = value_ij;
573 for(
unsigned int i = 0;i<m.
values.size();i++){
596 std::vector<double> moment = momobj.
get();
597 os << std::endl <<
"Order of vpMomentObject: "<<momobj.
getOrder()<<std::endl;
599 for(
unsigned int k=0; k<=momobj.
getOrder(); k++) {
600 for(
unsigned int l=0; l<(momobj.
getOrder()+1)-k; l++){
601 os <<
"m[" << l <<
"," << k <<
"] = " << moment[k*(momobj.
getOrder()+1)+ l] <<
"\t";
636 std::vector<double> moment = momobj.
get();
637 unsigned int order = momobj.
getOrder();
639 for(
unsigned int k=0; k<=
order; k++) {
640 for(
unsigned int l=0; l<(order+1)-k; l++){
641 M[l][k] = moment[k*(order+1)+ l];
unsigned int getCols() const
Implementation of a matrix and operations on matrices.
vpMomentObject(unsigned int order)
static vpMatrix convertTovpMatrix(const vpMomentObject &momobj)
static void printWithIndices(const vpMomentObject &momobj, std::ostream &os)
error that can be emited by ViSP classes.
Class for generic objects.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
const std::vector< double > & get() const
virtual ~vpMomentObject()
void fromImage(const vpImage< unsigned char > &image, unsigned char threshold, const vpCameraParameters &cam)
void init(unsigned int orderinp)
unsigned int getRows() const
void cacheValues(std::vector< double > &cache, double x, double y)
void set(unsigned int i, unsigned int j, const double &value_ij)
Generic class defining intrinsic camera parameters.
bool flg_normalize_intensity
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
void fromVector(std::vector< vpPoint > &points)
std::vector< double > values
vpObjectType getType() const
static long double comb(unsigned int n, unsigned int p)
unsigned int getOrder() const