42 #include <visp/vpMomentBasic.h>
43 #include <visp/vpMomentObject.h>
44 #include <visp/vpCameraParameters.h>
45 #include <visp/vpPixelMeterConversion.h>
46 #include <visp/vpConfig.h>
52 #ifdef VISP_HAVE_OPENMP
66 double vpMomentObject::calc_mom_polygon(
unsigned int p,
unsigned int q,
const std::vector<vpPoint>& points){
74 den =
static_cast<double>( (p+q+2)*(p+q+1)*
vpMath::comb(p+q,p) );
77 for (i=1;i<=points.size()-1;i++)
84 x_p_k = pow(points[i-1].get_x(), (
int)(p-k));
87 y_q_l=pow(points[i-1].get_y(), (
int)(q-l));
89 s +=
static_cast<double>(
97 y_l*=points[i].get_y();
100 x_k*=points[i].get_x();
104 s *= ((points[i-1].get_x())*(points[i].get_y())-(points[i].get_x())*(points[i-1].get_y()));
127 for(
register unsigned int i=1;i<
order;i++)
128 cache[i]=cache[i-1]*x;
130 for(
register unsigned int j=order;j<order*
order;j+=
order)
131 cache[j]=cache[j-order]*y;
133 for(
register unsigned int j=1;j<
order;j++){
134 for(
register unsigned int i=1;i<order-j;i++){
135 cache[j*order+i] = cache[j*
order]*cache[i];
146 cache[0]=IntensityNormalized;
148 double invIntensityNormalized = 0.;
149 if (std::fabs(IntensityNormalized)>=std::numeric_limits<double>::epsilon())
150 invIntensityNormalized = 1.0/IntensityNormalized;
152 for(
register unsigned int i=1;i<
order;i++)
153 cache[i]=cache[i-1]*x;
155 for(
register unsigned int j=order;j<order*
order;j+=
order)
156 cache[j]=cache[j-order]*y;
158 for(
register unsigned int j=1;j<
order;j++){
159 for(
register unsigned int i=1;i<order-j;i++){
160 cache[j*order+i] = cache[j*
order]*cache[i]*invIntensityNormalized;
241 std::abs(points.rbegin()->get_x()-points.begin()->get_x())>std::numeric_limits<double>::epsilon() ||
242 std::abs(points.rbegin()->get_y()-points.begin()->get_y())>std::numeric_limits<double>::epsilon()
244 points.resize(points.size()+1);
245 points[points.size()-1] = points[0];
247 for(
register unsigned int j=0;j<order*
order;j++){
248 values[j]=calc_mom_polygon(j%order,j/order,points);
251 std::vector<double> cache(order*order,0.);
252 values.assign(order*order,0);
253 for(
register unsigned int i=0;i<points.size();i++){
254 cacheValues(cache,points[i].get_x(),points[i].get_y());
255 for(
register unsigned int j=0;j<
order;j++){
256 for(
register unsigned int k=0;k<order-j;k++){
257 values[j*order+k]+=cache[j*order+k];
294 #ifdef VISP_HAVE_OPENMP
295 #pragma omp parallel shared(threshold)
297 std::vector<double> curvals(order*order);
298 curvals.assign(order*order,0.);
301 #pragma omp for nowait//automatically organize loop counter between threads
302 for(
int i=0;i<(int)image.
getCols();i++){
303 for(
int j=0;j<(int)image.
getRows();j++){
304 i_ =
static_cast<unsigned int>(i);
305 j_ =
static_cast<unsigned int>(j);
306 if(image[j_][i_]>threshold){
313 for(
register unsigned int k=0;k<
order;k++){
315 for(
register unsigned int l=0;l<order-k;l++){
316 curvals[(k*order+l)]+=(xval*yval);
325 #pragma omp master //only set this variable in master thread
327 values.assign(order*order, 0.);
332 for(
register unsigned int k=0;k<
order;k++){
333 for(
register unsigned int l=0;l<order-k;l++){
335 values[k*order+l]+= curvals[k*order+l];
341 std::vector<double> cache(order*order,0.);
342 values.assign(order*order,0);
343 for(
register unsigned int i=0;i<image.
getCols();i++){
344 for(
register unsigned int j=0;j<image.
getRows();j++){
345 if(image[j][i]>threshold){
350 for(
register unsigned int k=0;k<
order;k++){
351 for(
register unsigned int l=0;l<order-k;l++){
352 values[k*order+l]+=cache[k*order+l];
362 for (std::vector<double>::iterator it =
values.begin(); it!=
values.end(); it++) {
363 *it = (*it) * norm_factor;
380 std::vector<double> cache(order*order,0.);
381 values.assign(order*order,0);
387 unsigned int idx = 0;
388 unsigned int kidx = 0;
390 double intensity = 0;
391 double intensity_white = 0;
402 for(
register unsigned int j=0;j<image.
getRows();j++){
403 for(
register unsigned int i=0;i<image.
getCols();i++){
406 intensity = (double)(image[j][i])*iscale;
407 intensity_white = 1. - intensity;
413 for(
register unsigned int k=0;k<
order;k++){
415 for(
register unsigned int l=0;l<order-k;l++){
425 for(
register unsigned int j=0;j<image.
getRows();j++){
426 for(
register unsigned int i=0;i<image.
getCols();i++){
429 intensity = (double)(image[j][i])*iscale;
436 for(
register unsigned int k=0;k<
order;k++){
438 for(
register unsigned int l=0;l<order-k;l++){
448 if (normalize_with_pix_size){
451 for (std::vector<double>::iterator it =
values.begin(); it!=
values.end(); it++) {
452 *it = (*it) * norm_factor;
463 order = orderinp + 1;
466 values.resize((order+1)*(order+1));
467 values.assign((order+1)*(order+1),0);
496 : flg_normalize_intensity(true), order(max_order+1), type(
vpMomentObject::DENSE_FULL_OBJECT),
506 : flg_normalize_intensity(true), order(order+1), type(
vpMomentObject::DENSE_FULL_OBJECT),
558 values[j*order+i] = value_ij;
576 VISP_EXPORT std::ostream & operator<<(std::ostream & os,
const vpMomentObject& m){
577 for(
unsigned int i = 0;i<m.
values.size();i++){
unsigned int getCols() const
vpMomentObject(unsigned int order)
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
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
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