Visual Servoing Platform  version 3.4.0
vpMomentObject.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Object input structure used by moments.
33  *
34  * Authors:
35  * Filip Novotny
36  * Manikandan Bakthavatchalam
37  *****************************************************************************/
42 #ifndef _vpMomentObject_h_
43 #define _vpMomentObject_h_
44 
45 #include <cstdlib>
46 #include <utility>
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpMoment.h>
50 #include <visp3/core/vpPoint.h>
51 
52 class vpCameraParameters;
53 
219 class VISP_EXPORT vpMomentObject
220 {
221 public:
225  typedef enum {
226  DENSE_FULL_OBJECT = 0,
228  DENSE_POLYGON = 1,
231  DISCRETE = 2,
232  } vpObjectType;
233 
237  typedef enum {
238  BLACK = 0,
239  WHITE = 1,
241 
242  bool flg_normalize_intensity; // To scale the intensity of each individual
243  // pixel in the image by the maximum intensity
244  // value present in it
245 
246  // Constructors
247  explicit vpMomentObject(unsigned int order);
248  vpMomentObject(const vpMomentObject &srcobj);
257  virtual ~vpMomentObject();
258 
259  void fromImage(const vpImage<unsigned char> &image, unsigned char threshold,
260  const vpCameraParameters &cam); // Binary version
261  void fromImage(const vpImage<unsigned char> &image, const vpCameraParameters &cam, vpCameraImgBckGrndType bg_type,
262  bool normalize_with_pix_size = true); // Photometric version
263 
264  void fromVector(std::vector<vpPoint> &points);
265  const std::vector<double> &get() const;
266  double get(unsigned int i, unsigned int j) const;
267 
271  vpObjectType getType() const { return type; }
272 
277  unsigned int getOrder() const { return order - 1; }
278 
279  // Constructor helpers
280  void init(unsigned int orderinp);
281  void init(const vpMomentObject &objin);
282 
283  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentObject &v);
289  static void printWithIndices(const vpMomentObject &momobj, std::ostream &os);
294  void setType(vpObjectType input_type) { this->type = input_type; }
295 
300  static vpMatrix convertTovpMatrix(const vpMomentObject &momobj);
301 
302 protected:
303  unsigned int order;
305  std::vector<double> values;
306  void set(unsigned int i, unsigned int j, const double &value_ij);
307  void cacheValues(std::vector<double> &cache, double x, double y);
308 
309 private:
310  void cacheValues(std::vector<double> &cache, double x, double y, double IntensityNormalized);
311  double calc_mom_polygon(unsigned int p, unsigned int q, const std::vector<vpPoint> &points);
312 };
313 
314 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
Class for generic objects.
Generic class defining intrinsic camera parameters.
bool flg_normalize_intensity
unsigned int order
std::vector< double > values
vpObjectType getType() const
vpObjectType type
void setType(vpObjectType input_type)
unsigned int getOrder() const