Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDetectorBase.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Base class for object detection.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 #include <visp3/core/vpConfig.h>
38 
39 #include <visp3/detection/vpDetectorBase.h>
40 
44 vpDetectorBase::vpDetectorBase() : m_polygon(), m_message(), m_nb_objects(0)
45 {}
46 
50 std::vector<vpImagePoint> &
52 {
53  if (i < m_polygon.size())
54  return m_polygon[i];
55  else
56  throw(vpException(vpException::badValue, "Bad index to retrieve object %d. Only %d objects are detected.", i, m_polygon.size()));
57 }
58 
62 std::string &
64 {
65  if (i < m_polygon.size())
66  return m_message[i];
67  else
68  throw(vpException(vpException::badValue, "Bad index to retrieve object %d . Only %d objects are detected.", i, m_polygon.size()));
69 }
70 
75 vpDetectorBase::getCog(size_t i) const
76 {
77  vpImagePoint cog(0, 0);
78  for (size_t j = 0; j < m_polygon[i].size(); j++) {
79  cog += m_polygon[i][j];
80  }
81  cog /= (double)m_polygon[i].size();
82  return cog;
83 }
84 
88 vpRect
89 vpDetectorBase::getBBox(size_t i) const
90 {
91  assert(m_polygon[i].size() > 2);
92 
93  double left, right;
94  double top, bottom;
95  left = right = m_polygon[i][0].get_u();
96  top = bottom = m_polygon[i][0].get_v();
97  for (size_t j = 0; j < m_polygon[i].size(); j++) {
98  double u = m_polygon[i][j].get_u();
99  double v = m_polygon[i][j].get_v();
100  if (u < left) left = u;
101  if (u > right) right = u;
102  if (v < top) top = v;
103  if (v > bottom) bottom = v;
104  }
105  vpRect roi(vpImagePoint(top, left), vpImagePoint(bottom, right));
106  return roi;
107 }
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpImagePoint getCog(size_t i) const
std::vector< std::vector< vpImagePoint > > & getPolygon()
std::vector< std::string > & getMessage()
std::vector< std::string > m_message
Message attached to each object.
Defines a rectangle in the plane.
Definition: vpRect.h:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
vpRect getBBox(size_t i) const
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.