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(
unsigned int i=1;i<
order;i++)
124 cache[i]=cache[i-1]*x;
126 for(
unsigned int j=order;j<order*
order;j+=
order)
127 cache[j]=cache[j-order]*y;
129 for(
unsigned int j=1;j<
order;j++){
130 for(
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(
unsigned int i=1;i<
order;i++)
149 cache[i]=cache[i-1]*x;
151 for(
unsigned int j=order;j<order*
order;j+=
order)
152 cache[j]=cache[j-order]*y;
154 for(
unsigned int j=1;j<
order;j++){
155 for(
unsigned int i=1;i<order-j;i++){
156 cache[j*order+i] = cache[j*
order]*cache[i]*invIntensityNormalized;
236 if(std::fabs(points.rbegin()->get_x()-points.begin()->get_x())>std::numeric_limits<double>::epsilon() ||
237 std::fabs(points.rbegin()->get_y()-points.begin()->get_y())>std::numeric_limits<double>::epsilon()){
238 points.resize(points.size()+1);
239 points[points.size()-1] = points[0];
241 for(
unsigned int j=0;j<order*
order;j++){
242 values[j]=calc_mom_polygon(j%order,j/order,points);
245 std::vector<double> cache(order*order,0.);
246 values.assign(order*order,0);
247 for(
unsigned int i=0;i<points.size();i++){
248 cacheValues(cache,points[i].get_x(),points[i].get_y());
249 for(
unsigned int j=0;j<
order;j++){
250 for(
unsigned int k=0;k<order-j;k++){
251 values[j*order+k]+=cache[j*order+k];
288 #ifdef VISP_HAVE_OPENMP
289 #pragma omp parallel shared(threshold)
291 std::vector<double> curvals(order*order);
292 curvals.assign(order*order,0.);
294 #pragma omp for nowait//automatically organize loop counter between threads
295 for(
int i=0;i<(int)image.
getCols();i++){
296 for(
int j=0;j<(int)image.
getRows();j++){
297 unsigned int i_ =
static_cast<unsigned int>(i);
298 unsigned int j_ =
static_cast<unsigned int>(j);
299 if(image[j_][i_]>threshold){
305 for(
unsigned int k=0;k<
order;k++){
307 for(
unsigned int l=0;l<order-k;l++){
308 curvals[(k*order+l)]+=(xval*yval);
317 #pragma omp master //only set this variable in master thread
319 values.assign(order*order, 0.);
323 for(
unsigned int k=0;k<
order;k++){
324 for(
unsigned int l=0;l<order-k;l++){
326 values[k*order+l]+= curvals[k*order+l];
332 std::vector<double> cache(order*order,0.);
333 values.assign(order*order,0);
334 for(
unsigned int i=0;i<image.
getCols();i++){
335 for(
unsigned int j=0;j<image.
getRows();j++){
336 if(image[j][i]>threshold){
341 for(
unsigned int k=0;k<
order;k++){
342 for(
unsigned int l=0;l<order-k;l++){
343 values[k*order+l]+=cache[k*order+l];
353 for (std::vector<double>::iterator it =
values.begin(); it!=
values.end(); ++it) {
354 *it = (*it) * norm_factor;
371 std::vector<double> cache(order*order,0.);
372 values.assign(order*order,0);
378 unsigned int idx = 0;
379 unsigned int kidx = 0;
381 double intensity = 0;
393 for(
unsigned int j=0;j<image.
getRows();j++){
394 for(
unsigned int i=0;i<image.
getCols();i++){
397 intensity = (double)(image[j][i])*iscale;
398 double intensity_white = 1. - intensity;
404 for(
unsigned int k=0;k<
order;k++){
406 for(
unsigned int l=0;l<order-k;l++){
416 for(
unsigned int j=0;j<image.
getRows();j++){
417 for(
unsigned int i=0;i<image.
getCols();i++){
420 intensity = (double)(image[j][i])*iscale;
427 for(
unsigned int k=0;k<
order;k++){
429 for(
unsigned int l=0;l<order-k;l++){
439 if (normalize_with_pix_size){
442 for (std::vector<double>::iterator it =
values.begin(); it!=
values.end(); ++it) {
443 *it = (*it) * norm_factor;
454 order = orderinp + 1;
457 values.resize((order+1)*(order+1));
458 values.assign((order+1)*(order+1),0);
487 : flg_normalize_intensity(true), order(max_order+1), type(
vpMomentObject::DENSE_FULL_OBJECT),
497 : flg_normalize_intensity(true), order(1), type(
vpMomentObject::DENSE_FULL_OBJECT),
549 values[j*order+i] = value_ij;
568 for(
unsigned int i = 0;i<m.
values.size();i++){
591 std::vector<double> moment = momobj.
get();
592 os << std::endl <<
"Order of vpMomentObject: "<<momobj.
getOrder()<<std::endl;
594 for(
unsigned int k=0; k<=momobj.
getOrder(); k++) {
595 for(
unsigned int l=0; l<(momobj.
getOrder()+1)-k; l++){
596 os <<
"m[" << l <<
"," << k <<
"] = " << moment[k*(momobj.
getOrder()+1)+ l] <<
"\t";
631 std::vector<double> moment = momobj.
get();
632 unsigned int order = momobj.
getOrder();
634 for(
unsigned int k=0; k<=
order; k++) {
635 for(
unsigned int l=0; l<(order+1)-k; l++){
636 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