Visual Servoing Platform  version 3.6.1 under development (2024-04-19)
vpBasicKeyPoint.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  * Key point used in matching algorithm.
32  */
33 
34 #ifndef vpBasicKeyPoint_H
35 #define vpBasicKeyPoint_H
36 
42 #include <visp3/core/vpColor.h>
43 #include <visp3/core/vpImage.h>
44 #include <visp3/core/vpImagePoint.h>
45 #include <visp3/core/vpRect.h>
46 
47 #include <vector>
48 
57 class VISP_EXPORT vpBasicKeyPoint
58 {
59 public:
64  : m_referenceImagePointsList(), m_currentImagePointsList(), m_matchedReferencePoints(), m_reference_computed(false)
65  { }
66 
70  virtual ~vpBasicKeyPoint()
71  {
72  m_matchedReferencePoints.resize(0);
73  m_currentImagePointsList.resize(0);
74  m_referenceImagePointsList.resize(0);
75  }
76 
80  virtual unsigned int buildReference(const vpImage<unsigned char> &I) = 0;
81 
85  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int height,
86  unsigned int width) = 0;
87 
91  virtual unsigned int buildReference(const vpImage<unsigned char> &I, const vpRect &rectangle) = 0;
92 
96  virtual unsigned int matchPoint(const vpImage<unsigned char> &I) = 0;
97 
101  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int height,
102  unsigned int width) = 0;
103 
107  virtual unsigned int matchPoint(const vpImage<unsigned char> &I, const vpRect &rectangle) = 0;
108 
112  virtual void display(const vpImage<unsigned char> &Iref, const vpImage<unsigned char> &Icurrent,
113  unsigned int size = 3) = 0;
114 
118  virtual void display(const vpImage<unsigned char> &Icurrent, unsigned int size = 3,
119  const vpColor &color = vpColor::green) = 0;
120 
126  bool referenceBuilt() const { return m_reference_computed; }
127 
134  inline const vpImagePoint *getAllPointsInReferenceImage() { return &m_referenceImagePointsList[0]; }
135 
145  inline void getReferencePoint(unsigned int index, vpImagePoint &referencePoint)
146  {
147  if (index >= m_referenceImagePointsList.size()) {
148  vpTRACE("Index of the reference point out of range");
149  throw(vpException(vpException::fatalError, "Index of the reference point out of range"));
150  }
151 
152  referencePoint.set_ij(m_referenceImagePointsList[index].get_i(), m_referenceImagePointsList[index].get_j());
153  }
154 
166  inline void getMatchedPoints(unsigned int index, vpImagePoint &referencePoint, vpImagePoint &currentPoint)
167  {
168  if (index >= m_matchedReferencePoints.size()) {
169  vpTRACE("Index of the matched points out of range");
170  throw(vpException(vpException::fatalError, "Index of the matched points out of range"));
171  }
172  referencePoint.set_ij(m_referenceImagePointsList[m_matchedReferencePoints[index]].get_i(),
173  m_referenceImagePointsList[m_matchedReferencePoints[index]].get_j());
174  currentPoint.set_ij(m_currentImagePointsList[index].get_i(), m_currentImagePointsList[index].get_j());
175  }
176 
200  inline unsigned int getIndexInAllReferencePointList(unsigned int indexInMatchedPointList)
201  {
202  if (indexInMatchedPointList >= m_matchedReferencePoints.size()) {
203  vpTRACE("Index of the matched reference point out of range");
204  throw(vpException(vpException::fatalError, "Index of the matched reference point out of range"));
205  }
206  return m_matchedReferencePoints[indexInMatchedPointList];
207  }
208 
214  inline unsigned int getReferencePointNumber() const { return (unsigned int)m_referenceImagePointsList.size(); };
215 
221  inline unsigned int getMatchedPointNumber() const { return (unsigned int)m_matchedReferencePoints.size(); };
222 
230  const std::vector<vpImagePoint> &getReferenceImagePointsList() const { return m_referenceImagePointsList; }
231 
239  const std::vector<vpImagePoint> &getCurrentImagePointsList() const { return m_currentImagePointsList; }
240 
250  const std::vector<unsigned int> &getMatchedReferencePoints() const { return m_matchedReferencePoints; }
251 
252 protected:
256  std::vector<vpImagePoint> m_referenceImagePointsList;
257 
262  std::vector<vpImagePoint> m_currentImagePointsList;
263 
272  std::vector<unsigned int> m_matchedReferencePoints;
273 
278 
279 private:
280  virtual void init() = 0;
281 };
282 
283 #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:152
static const vpColor green
Definition: vpColor.h:214
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ fatalError
Fatal error.
Definition: vpException.h:84
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:315
Defines a rectangle in the plane.
Definition: vpRect.h:76
#define vpTRACE
Definition: vpDebug.h:405