Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpBasicKeyPoint.h
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  * Key point used in matching algorithm.
32  */
33 
34 #ifndef VP_BASIC_KEYPOINT_H
35 #define VP_BASIC_KEYPOINT_H
36 
42 #include <visp3/core/vpDebug.h>
43 #include <visp3/core/vpColor.h>
44 #include <visp3/core/vpImage.h>
45 #include <visp3/core/vpImagePoint.h>
46 #include <visp3/core/vpRect.h>
47 
48 #include <vector>
49 
50 BEGIN_VISP_NAMESPACE
59 class VISP_EXPORT vpBasicKeyPoint
60 {
61 public:
66  : m_referenceImagePointsList(), m_currentImagePointsList(), m_matchedReferencePoints(), m_reference_computed(false)
67  { }
68 
72  virtual ~vpBasicKeyPoint()
73  {
74  m_matchedReferencePoints.resize(0);
75  m_currentImagePointsList.resize(0);
76  m_referenceImagePointsList.resize(0);
77  }
78 
82  virtual unsigned int buildReference(const vpImage<unsigned char> &I) = 0;
83 
87  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int height,
88  unsigned int width) = 0;
89 
93  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpRect &rectangle) = 0;
94 
98  virtual unsigned int matchPoint(const vpImage<unsigned char> &I) = 0;
99 
103  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int height,
104  unsigned int width) = 0;
105 
109  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpRect &rectangle) = 0;
110 
114  virtual void display(const vpImage<unsigned char> &Iref, const vpImage<unsigned char> &Icurrent,
115  unsigned int size = 3) = 0;
116 
120  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size = 3,
121  const vpColor &color = vpColor::green) = 0;
122 
128  bool referenceBuilt() const { return m_reference_computed; }
129 
136  inline const vpImagePoint *getAllPointsInReferenceImage() { return &m_referenceImagePointsList[0]; }
137 
147  inline void getReferencePoint(unsigned int index, vpImagePoint &referencePoint)
148  {
149  if (index >= m_referenceImagePointsList.size()) {
150  vpTRACE("Index of the reference point out of range");
151  throw(vpException(vpException::fatalError, "Index of the reference point out of range"));
152  }
153 
154  referencePoint.set_ij(m_referenceImagePointsList[index].get_i(), m_referenceImagePointsList[index].get_j());
155  }
156 
168  inline void getMatchedPoints(unsigned int index, vpImagePoint &referencePoint, vpImagePoint &currentPoint)
169  {
170  if (index >= m_matchedReferencePoints.size()) {
171  vpTRACE("Index of the matched points out of range");
172  throw(vpException(vpException::fatalError, "Index of the matched points out of range"));
173  }
174  referencePoint.set_ij(m_referenceImagePointsList[m_matchedReferencePoints[index]].get_i(),
175  m_referenceImagePointsList[m_matchedReferencePoints[index]].get_j());
176  currentPoint.set_ij(m_currentImagePointsList[index].get_i(), m_currentImagePointsList[index].get_j());
177  }
178 
202  inline unsigned int getIndexInAllReferencePointList(unsigned int indexInMatchedPointList)
203  {
204  if (indexInMatchedPointList >= m_matchedReferencePoints.size()) {
205  vpTRACE("Index of the matched reference point out of range");
206  throw(vpException(vpException::fatalError, "Index of the matched reference point out of range"));
207  }
208  return m_matchedReferencePoints[indexInMatchedPointList];
209  }
210 
216  inline unsigned int getReferencePointNumber() const { return (unsigned int)m_referenceImagePointsList.size(); };
217 
223  inline unsigned int getMatchedPointNumber() const { return (unsigned int)m_matchedReferencePoints.size(); };
224 
232  const std::vector<vpImagePoint> &getReferenceImagePointsList() const { return m_referenceImagePointsList; }
233 
241  const std::vector<vpImagePoint> &getCurrentImagePointsList() const { return m_currentImagePointsList; }
242 
252  const std::vector<unsigned int> &getMatchedReferencePoints() const { return m_matchedReferencePoints; }
253 
254 protected:
258  std::vector<vpImagePoint> m_referenceImagePointsList;
259 
264  std::vector<vpImagePoint> m_currentImagePointsList;
265 
274  std::vector<unsigned int> m_matchedReferencePoints;
275 
280 
281 private:
282  virtual void init() = 0;
283 };
284 END_VISP_NAMESPACE
285 #endif
class that defines what is a keypoint. This class provides all the basic elements to implement classe...
bool referenceBuilt() const
const std::vector< unsigned int > & getMatchedReferencePoints() const
virtual unsigned int buildReference(const vpImage< unsigned char > &I)=0
unsigned int getMatchedPointNumber() const
virtual unsigned int matchPoint(const vpImage< unsigned char > &I, const vpRect &rectangle)=0
std::vector< unsigned int > m_matchedReferencePoints
void getReferencePoint(unsigned int index, vpImagePoint &referencePoint)
void getMatchedPoints(unsigned int index, vpImagePoint &referencePoint, vpImagePoint &currentPoint)
virtual unsigned int matchPoint(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int height, unsigned int width)=0
std::vector< vpImagePoint > m_currentImagePointsList
std::vector< vpImagePoint > m_referenceImagePointsList
const vpImagePoint * getAllPointsInReferenceImage()
virtual unsigned int buildReference(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int height, unsigned int width)=0
const std::vector< vpImagePoint > & getReferenceImagePointsList() const
virtual void display(const vpImage< unsigned char > &Icurrent, unsigned int size=3, const vpColor &color=vpColor::green)=0
virtual unsigned int buildReference(const vpImage< unsigned char > &I, const vpRect &rectangle)=0
virtual ~vpBasicKeyPoint()
unsigned int getIndexInAllReferencePointList(unsigned int indexInMatchedPointList)
virtual unsigned int matchPoint(const vpImage< unsigned char > &I)=0
unsigned int getReferencePointNumber() const
virtual void display(const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3)=0
const std::vector< vpImagePoint > & getCurrentImagePointsList() const
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor green
Definition: vpColor.h:220
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ fatalError
Fatal error.
Definition: vpException.h:72
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
void set_ij(double ii, double jj)
Definition: vpImagePoint.h:320
Defines a rectangle in the plane.
Definition: vpRect.h:79