Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDetectorBase.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 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 * Base class for object detection.
32 */
33#include <visp3/core/vpConfig.h>
34
35#include <visp3/detection/vpDetectorBase.h>
37
42
46
50std::vector<vpImagePoint> &vpDetectorBase::getPolygon(size_t i)
51{
52 if (i < m_polygon.size()) {
53 return m_polygon[i];
54 }
55 else {
56 throw(vpException(vpException::badValue, "Bad index to retrieve object %d. Only %d objects are detected.", i,
57 m_polygon.size()));
58 }
59}
60
64std::string &vpDetectorBase::getMessage(size_t i)
65{
66 if (i < m_polygon.size()) {
67 return m_message[i];
68 }
69 else {
70 throw(vpException(vpException::badValue, "Bad index to retrieve object %d . Only %d objects are detected.", i,
71 m_polygon.size()));
72 }
73}
74
79{
80 vpImagePoint cog(0, 0);
81 size_t m_polygon_i_size = m_polygon[i].size();
82 for (size_t j = 0; j < m_polygon_i_size; ++j) {
83 cog += m_polygon[i][j];
84 }
85 cog /= static_cast<double>(m_polygon[i].size());
86 return cog;
87}
88
93{
94 assert(m_polygon[i].size() > 2);
95
96 double left, right;
97 double top, bottom;
98 left = m_polygon[i][0].get_u();
99 right = m_polygon[i][0].get_u();
100 top = m_polygon[i][0].get_v();
101 bottom = m_polygon[i][0].get_v();
102 size_t m_polygon_i_size = m_polygon[i].size();
103 for (size_t j = 0; j < m_polygon_i_size; ++j) {
104 double u = m_polygon[i][j].get_u();
105 double v = m_polygon[i][j].get_v();
106 if (u < left) {
107 left = u;
108 }
109 if (u > right) {
110 right = u;
111 }
112 if (v < top) {
113 top = v;
114 }
115 if (v > bottom) {
116 bottom = v;
117 }
118 }
119 vpRect roi(vpImagePoint(top, left), vpImagePoint(bottom, right));
120 return roi;
121}
122
123END_VISP_NAMESPACE
std::vector< std::string > m_message
Message attached to each object.
std::vector< std::vector< vpImagePoint > > & getPolygon()
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.
vpRect getBBox(size_t i) const
size_t m_nb_objects
Number of detected objects.
unsigned long m_timeout_ms
Detection timeout.
std::vector< std::string > & getMessage()
vpImagePoint getCog(size_t i) const
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Defines a rectangle in the plane.
Definition vpRect.h:79