Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpMomentObject.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Object input structure used by moments.
32  */
37 #ifndef _vpMomentObject_h_
38 #define _vpMomentObject_h_
39 
40 #include <cstdlib>
41 #include <utility>
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpImage.h>
44 #include <visp3/core/vpMath.h>
45 #include <visp3/core/vpMoment.h>
46 #include <visp3/core/vpPoint.h>
47 
49 class vpCameraParameters;
50 
223 class VISP_EXPORT vpMomentObject
224 {
225 public:
229  typedef enum
230  {
231  DENSE_FULL_OBJECT = 0,
233  DENSE_POLYGON = 1,
236  DISCRETE = 2,
237  } vpObjectType;
238 
242  typedef enum
243  {
244  BLACK = 0,
245  WHITE = 1,
246  } vpCameraImgBckGrndType;
247 
248  bool flg_normalize_intensity; // To scale the intensity of each individual
249  // pixel in the image by the maximum intensity
250  // value present in it
251 
252  // Constructors
253  VP_EXPLICIT vpMomentObject(unsigned int order);
254  vpMomentObject(const vpMomentObject &srcobj);
263  virtual ~vpMomentObject();
264 
265  void fromImage(const vpImage<unsigned char> &image, unsigned char threshold,
266  const vpCameraParameters &cam); // Binary version
267  void fromImage(const vpImage<unsigned char> &image, const vpCameraParameters &cam, vpCameraImgBckGrndType bg_type,
268  bool normalize_with_pix_size = true); // Photometric version
269 
270  void fromVector(std::vector<vpPoint> &points);
271  const std::vector<double> &get() const;
272  double get(unsigned int i, unsigned int j) const;
273 
277  vpObjectType getType() const { return type; }
278 
283  unsigned int getOrder() const { return order - 1; }
284 
285  // Constructor helpers
286  void init(unsigned int orderinp);
287  void init(const vpMomentObject &objin);
288 
289  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentObject &v);
295  static void printWithIndices(const vpMomentObject &momobj, std::ostream &os);
300  void setType(vpObjectType input_type) { this->type = input_type; }
301 
306  static vpMatrix convertTovpMatrix(const vpMomentObject &momobj);
307 
308 protected:
309  unsigned int order;
311  std::vector<double> values;
312  void set(unsigned int i, unsigned int j, const double &value_ij);
313  void cacheValues(std::vector<double> &cache, double x, double y);
314 
315 private:
316  void cacheValues(std::vector<double> &cache, double x, double y, double IntensityNormalized);
317  double calc_mom_polygon(unsigned int p, unsigned int q, const std::vector<vpPoint> &points);
318 };
319 END_VISP_NAMESPACE
320 
321 #endif
Generic class defining intrinsic camera parameters.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Class for generic objects.
unsigned int getOrder() const
unsigned int order
vpObjectType type
void setType(vpObjectType input_type)
bool flg_normalize_intensity
std::vector< double > values
vpObjectType getType() const