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>
49 #ifdef VISP_HAVE_OPENMP
63 double vpMomentObject::calc_mom_polygon(
unsigned int p,
unsigned int q,
const std::vector<vpPoint>& points){
71 den =
static_cast<double>( (p+q+2)*(p+q+1)*
vpMath::comb(p+q,p) );
74 for (i=1;i<=points.size()-1;i++)
81 x_p_k = pow(points[i-1].get_x(), (
int)(p-k));
84 y_q_l=pow(points[i-1].get_y(), (
int)(q-l));
86 s +=
static_cast<double>(
94 y_l*=points[i].get_y();
97 x_k*=points[i].get_x();
101 s *= ((points[i-1].get_x())*(points[i].get_y())-(points[i].get_x())*(points[i-1].get_y()));
121 void vpMomentObject::cacheValues(std::vector<double>& cache,
double x,
double y){
124 for(
register unsigned int i=1;i<order;i++)
125 cache[i]=cache[i-1]*x;
127 for(
register unsigned int j=order;j<order*order;j+=order)
128 cache[j]=cache[j-order]*y;
130 for(
register unsigned int j=1;j<order;j++){
131 for(
register unsigned int i=1;i<order-j;i++){
132 cache[j*order+i] = cache[j*order]*cache[i];
212 std::abs(points.rbegin()->get_x()-points.begin()->get_x())>std::numeric_limits<double>::epsilon() ||
213 std::abs(points.rbegin()->get_y()-points.begin()->get_y())>std::numeric_limits<double>::epsilon()
215 points.resize(points.size()+1);
216 points[points.size()-1] = points[0];
218 for(
register unsigned int j=0;j<order*order;j++){
219 values[j]=calc_mom_polygon(j%order,j/order,points);
222 std::vector<double> cache(order*order,0.);
223 values.assign(order*order,0);
224 for(
register unsigned int i=0;i<points.size();i++){
225 cacheValues(cache,points[i].get_x(),points[i].get_y());
226 for(
register unsigned int j=0;j<order;j++){
227 for(
register unsigned int k=0;k<order-j;k++){
228 values[j*order+k]+=cache[j*order+k];
265 #ifdef VISP_HAVE_OPENMP
266 #pragma omp parallel shared(threshold)
268 std::vector<double> curvals(order*order);
269 curvals.assign(order*order,0.);
272 #pragma omp for nowait//automatically organize loop counter between threads
273 for(
int i=0;i<(int)image.
getCols();i++){
274 for(
int j=0;j<(int)image.
getRows();j++){
275 i_ =
static_cast<unsigned int>(i);
276 j_ =
static_cast<unsigned int>(j);
277 if(image[j_][i_]>threshold){
284 for(
register unsigned int k=0;k<order;k++){
286 for(
register unsigned int l=0;l<order-k;l++){
287 curvals[(k*order+l)]+=(xval*yval);
296 #pragma omp master //only set this variable in master thread
298 values.assign(order*order, 0.);
303 for(
register unsigned int k=0;k<order;k++){
304 for(
register unsigned int l=0;l<order-k;l++){
306 values[k*order+l]+= curvals[k*order+l];
313 std::vector<double> cache(order*order,0.);
314 values.assign(order*order,0);
315 for(
register unsigned int i=0;i<image.
getCols();i++){
316 for(
register unsigned int j=0;j<image.
getRows();j++){
317 if(image[j][i]>threshold){
321 cacheValues(cache,x,y);
322 for(
register unsigned int k=0;k<order;k++){
323 for(
register unsigned int l=0;l<order-k;l++){
324 values[k*order+l]+=cache[k*order+l];
347 values.resize((order+1)*(order+1)*12);
348 values.assign((order+1)*(order+1)*12,0);
385 return values[j*order+i];
404 for(
unsigned int i = 0;i<m.values.size();i++){
409 if((i%(m.order)+i/(m.order))<m.order)
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...
void fromImage(const vpImage< unsigned char > &image, unsigned char threshold, const vpCameraParameters &cam)
unsigned int getRows() const
std::vector< double > & get()
Generic class defining intrinsic camera parameters.
VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
void fromVector(std::vector< vpPoint > &points)
static long double comb(unsigned int n, unsigned int p)
unsigned int getOrder() const