OKVIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Frame.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: Mar 30, 2015
30  * Author: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
31  * Modified: Andreas Forster (an.forster@gmail.com)
32  *********************************************************************************/
33 
41 #ifndef INCLUDE_OKVIS_FRAME_HPP_
42 #define INCLUDE_OKVIS_FRAME_HPP_
43 
44 #include <Eigen/StdVector>
45 #include <Eigen/Core>
46 #include <memory>
47 #pragma GCC diagnostic push
48 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
49 #include <opencv2/core/core.hpp> // Code that causes warning goes here
50 #pragma GCC diagnostic pop
51 #pragma GCC diagnostic push
52 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
53 #include <opencv2/features2d/features2d.hpp> // Code that causes warning goes here
54 #pragma GCC diagnostic pop
55 #include <okvis/Time.hpp>
56 #include <okvis/assert_macros.hpp>
58 
60 namespace okvis {
61 
64 class Frame
65 {
66  public:
67  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
68  OKVIS_DEFINE_EXCEPTION(Exception, std::runtime_error)
69 
70 
71  inline Frame()
72  {
73  }
74 
81  inline Frame(const cv::Mat & image,
82  std::shared_ptr<cameras::CameraBase> & cameraGeometry,
83  std::shared_ptr<cv::FeatureDetector> & detector,
84  std::shared_ptr<cv::DescriptorExtractor> & extractor);
85 
87  inline virtual ~Frame()
88  {
89  }
90 
93  inline void setImage(const cv::Mat & image);
94 
97  inline void setGeometry(std::shared_ptr<const cameras::CameraBase> cameraGeometry);
98 
101  inline void setDetector(std::shared_ptr<cv::FeatureDetector> detector);
102 
105  inline void setExtractor(std::shared_ptr<cv::DescriptorExtractor> extractor);
106 
109  inline const cv::Mat & image() const;
110 
113  inline std::shared_ptr<const cameras::CameraBase> geometry() const;
114 
118  template<class GEOMETRY_T>
119  inline std::shared_ptr<const GEOMETRY_T> geometryAs() const;
120 
124  inline int detect();
125 
130  inline int describe(
131  const Eigen::Vector3d & extractionDirection = Eigen::Vector3d(0, 0, 1));
132 
138  template<class GEOMETRY_T>
139  inline int describeAs(
140  const Eigen::Vector3d & extractionDirection = Eigen::Vector3d(0, 0, 1));
141 
146  inline bool getCvKeypoint(size_t keypointIdx, cv::KeyPoint & keypoint) const;
147 
152  inline bool getKeypoint(size_t keypointIdx, Eigen::Vector2d & keypoint) const;
153 
158  inline bool getKeypointSize(size_t keypointIdx, double & keypointSize) const;
159 
163  inline const unsigned char * keypointDescriptor(size_t keypointIdx);
164 
169  inline bool setLandmarkId(size_t keypointIdx, uint64_t landmarkId);
170 
174  inline uint64_t landmarkId(size_t keypointIdx) const;
175 
179  inline bool resetKeypoints(const std::vector<cv::KeyPoint> & keypoints);
180 
184  inline bool resetDescriptors(const cv::Mat & descriptors);
185 
188  inline size_t numKeypoints() const;
189 
190  protected:
191  cv::Mat image_;
192  std::shared_ptr<const cameras::CameraBase> cameraGeometry_;
193  std::shared_ptr<cv::FeatureDetector> detector_;
194  std::shared_ptr<cv::DescriptorExtractor> extractor_;
195  std::vector<cv::KeyPoint> keypoints_;
196  cv::Mat descriptors_;
197  std::vector<uint64_t> landmarkIds_;
198 };
199 
200 } // namespace okvis
201 
202 #include "implementation/Frame.hpp"
203 
204 #endif /* INCLUDE_OKVIS_FRAME_HPP_ */
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Frame()
a default constructor
Definition: Frame.hpp:71
Header implementation file for the Frame class.
uint64_t landmarkId(size_t keypointIdx) const
Access the landmark ID.
Definition: Frame.hpp:278
std::shared_ptr< const cameras::CameraBase > cameraGeometry_
the camera geometry
Definition: Frame.hpp:192
int describe(const Eigen::Vector3d &extractionDirection=Eigen::Vector3d(0, 0, 1))
Describe keypoints. This uses virtual function calls. That's a negligibly small overhead for many det...
Definition: Frame.hpp:128
cv::Mat descriptors_
we store the descriptors using OpenCV's matrices
Definition: Frame.hpp:196
A single camera frame equipped with keypoint detector / extractor.
Definition: Frame.hpp:64
cv::Mat image_
the image as OpenCV's matrix
Definition: Frame.hpp:191
bool resetDescriptors(const cv::Mat &descriptors)
provide descriptors externally
Definition: Frame.hpp:300
std::vector< uint64_t > landmarkIds_
landmark Id, if associated – 0 otherwise
Definition: Frame.hpp:197
Header file for the TimeBase, Time and WallTime class.
int detect()
Detect keypoints. This uses virtual function calls. That's a negligibly small overhead for many detec...
Definition: Frame.hpp:110
bool getKeypoint(size_t keypointIdx, Eigen::Vector2d &keypoint) const
Get a specific keypoint.
Definition: Frame.hpp:210
const cv::Mat & image() const
Obtain the image.
Definition: Frame.hpp:82
bool getCvKeypoint(size_t keypointIdx, cv::KeyPoint &keypoint) const
Access a specific keypoint in OpenCV format.
Definition: Frame.hpp:193
#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
Macro for defining an exception with a given parent.
Definition: assert_macros.hpp:52
std::shared_ptr< cv::FeatureDetector > detector_
the detector
Definition: Frame.hpp:193
bool getKeypointSize(size_t keypointIdx, double &keypointSize) const
Get the size of a specific keypoint.
Definition: Frame.hpp:228
This file contains some useful assert macros.
std::vector< cv::KeyPoint > keypoints_
we store keypoints using OpenCV's struct
Definition: Frame.hpp:195
int describeAs(const Eigen::Vector3d &extractionDirection=Eigen::Vector3d(0, 0, 1))
Describe keypoints. This uses virtual function calls. That's a negligibly small overhead for many det...
Definition: Frame.hpp:162
std::shared_ptr< cv::DescriptorExtractor > extractor_
the extractor
Definition: Frame.hpp:194
std::shared_ptr< const cameras::CameraBase > geometry() const
get the base class geometry (will be slow to use)
Definition: Frame.hpp:88
void setExtractor(std::shared_ptr< cv::DescriptorExtractor > extractor)
Set the extractor.
Definition: Frame.hpp:76
bool resetKeypoints(const std::vector< cv::KeyPoint > &keypoints)
Provide keypoints externally.
Definition: Frame.hpp:293
const unsigned char * keypointDescriptor(size_t keypointIdx)
Access the descriptor – CAUTION: high-speed version.
Definition: Frame.hpp:246
Header file for the CameraBase class.
bool setLandmarkId(size_t keypointIdx, uint64_t landmarkId)
Set the landmark ID.
Definition: Frame.hpp:261
std::shared_ptr< const GEOMETRY_T > geometryAs() const
Get the specific geometry (will be fast to use)
Definition: Frame.hpp:95
size_t numKeypoints() const
Get the number of keypoints.
Definition: Frame.hpp:305
virtual ~Frame()
A simple destructor.
Definition: Frame.hpp:87
void setDetector(std::shared_ptr< cv::FeatureDetector > detector)
Set the detector.
Definition: Frame.hpp:70
void setGeometry(std::shared_ptr< const cameras::CameraBase > cameraGeometry)
Set the geometry.
Definition: Frame.hpp:64
void setImage(const cv::Mat &image)
Set the frame image;.
Definition: Frame.hpp:58