stereo
sparse_stereo.hpp
Go to the documentation of this file.
1 #ifndef __VISUAL_ODOMETRY_STEREO_HPP__
2 #define __VISUAL_ODOMETRY_STEREO_HPP__
3 
4 #include <stereo/config.h>
5 #include <stereo/sparse_stereo_types.h>
6 #include <frame_helper/CalibrationCv.h>
7 #include <base/Time.hpp>
8 #include <base/Eigen.hpp>
9 #include <base/samples/DistanceImage.hpp>
10 
11 #ifdef OPENCV_HAS_GPUMAT_IN_CORE
12 #include <opencv2/core/gpumat.hpp>
13 #else
14 #include <opencv2/gpu/gpu.hpp>
15 #endif
16 
17 namespace stereo
18 {
19 
21 {
22  base::Time detectorTime;
23  base::Time descriptorTime;
24 
25  std::vector<cv::KeyPoint> keypoints;
26  cv::Mat descriptors;
27 };
28 
30 {
31 public:
33 
36  void setCalibration( const frame_helper::StereoCalibration &calib );
37 
42 
45  void setDetectorConfiguration( const DetectorConfiguration &detector_config );
46 
53  void setDistanceImages(
54  const base::samples::DistanceImage *left,
55  const base::samples::DistanceImage *right );
56 
63  void processFramePair( const cv::Mat &left_image, const cv::Mat &right_image, StereoFeatureArray *stereo_features = NULL );
64 
68 
72 
76 
79  void calculateInterFrameCorrespondences( const StereoFeatureArray& frame1, const StereoFeatureArray& frame2, int filterMethod );
81  const cv::Mat& feat1, const std::vector<cv::KeyPoint>& keyp1, const std::vector<Eigen::Vector3d>& points1,
82  const cv::Mat& feat2, const std::vector<cv::KeyPoint>& keyp2, const std::vector<Eigen::Vector3d>& points2,
83  int filterMethod );
84 
90  std::vector<std::pair<long,long> > getInterFrameCorrespondences() { return correspondences; }
91 
96 
103  const cv::Mat& getDebugImage() { return debugImage; }
104 
107  cv::Mat getInterFrameDebugImage( const cv::Mat& debug1, const StereoFeatureArray& frame1, const cv::Mat& debug2, const StereoFeatureArray& frame2 , std::vector<std::pair<long,long> > *correspondence = NULL);
108 
109 public:
110  // use threading parameter: 0 for no threads, 1 for 2 threads (one per image), 2 for 8 threads (4 per image).
111  void findFeatures( const cv::Mat &left_image, const cv::Mat &right_image, int use_threading = 1, int crop_left = 0, int crop_right = 0);
115 
116  void crossCheckMatching( const cv::Mat& descriptors1, const cv::Mat& descriptors2,
117  std::vector<cv::DMatch>& filteredMatches12, int knn = 1, float distanceFactor = 2.0 );
118 
119  cv::Mat getHomography() { return homography;}
120 
121 protected:
122  void initDetector( size_t lastNumFeatures );
123  void findFeatures2( const cv::Mat &image, FeatureInfo& info, bool left_frame = true, int crop_left = 0, int crop_right = 0 );
124  void findFeatures_threading( const cv::Mat &image, FeatureInfo& info, bool left_frame = true, int crop_left = 0, int crop_right = 0);
125 
126  void crossCheckMatching( std::vector<std::vector<cv::DMatch> > matches12, std::vector<std::vector<cv::DMatch> > matches21, std::vector<cv::DMatch>& filteredMatches12, int knn = 1, float distanceFactor = 2.0);
127 
128  frame_helper::StereoCalibrationCv calib;
131 
135 
137  std::vector<std::pair<long,long> > correspondences;
138  base::Affine3d correspondenceTransform;
139 
140  cv::Ptr<cv::FeatureDetector> detector;
141  cv::Ptr<cv::DescriptorExtractor> descriptorExtractor;
142  cv::Ptr<cv::DescriptorMatcher> descriptorMatcher;
143 
144  cv::Mat homography;
145 
146  cv::Mat debugImage;
148  const base::samples::DistanceImage *dist_left, *dist_right;
150  cv::gpu::GpuMat descriptors_gpu_left;
151  cv::gpu::GpuMat descriptors_gpu_right;
152 };
153 
154 }
155 
156 #endif
Definition: sparse_stereo.hpp:20
Definition: sparse_stereo.hpp:29
FeatureInfo leftMatches
Definition: sparse_stereo.hpp:134
FeatureInfo rightPutativeMatches
Definition: sparse_stereo.hpp:133
const base::samples::DistanceImage * dist_right
Definition: sparse_stereo.hpp:148
Definition: sparse_stereo_types.h:120
void setCalibration(const frame_helper::StereoCalibration &calib)
Definition: sparse_stereo.cpp:40
DetectorConfiguration detectorParams
Definition: sparse_stereo.hpp:130
cv::gpu::GpuMat descriptors_gpu_left
Definition: sparse_stereo.hpp:150
Definition: sparse_stereo_types.h:41
cv::Ptr< cv::DescriptorExtractor > descriptorExtractor
Definition: sparse_stereo.hpp:141
cv::Ptr< cv::DescriptorMatcher > descriptorMatcher
Definition: sparse_stereo.hpp:142
void calculateDepthInformationBetweenCorrespondences(StereoFeatureArray *stereo_features=NULL)
Definition: sparse_stereo.cpp:697
cv::Mat homography
Definition: sparse_stereo.hpp:144
cv::Mat getHomography()
Definition: sparse_stereo.hpp:119
bool use_gpu_detector
Definition: sparse_stereo.hpp:149
FeatureInfo & getFeatureInfoRight()
Definition: sparse_stereo.hpp:75
void findFeatures2(const cv::Mat &image, FeatureInfo &info, bool left_frame=true, int crop_left=0, int crop_right=0)
Definition: sparse_stereo.cpp:253
cv::Mat getInterFrameDebugImage(const cv::Mat &debug1, const StereoFeatureArray &frame1, const cv::Mat &debug2, const StereoFeatureArray &frame2, std::vector< std::pair< long, long > > *correspondence=NULL)
Definition: sparse_stereo.cpp:953
void findFeatures(const cv::Mat &left_image, const cv::Mat &right_image, int use_threading=1, int crop_left=0, int crop_right=0)
Definition: sparse_stereo.cpp:334
void calculateInterFrameCorrespondences(const StereoFeatureArray &frame1, const StereoFeatureArray &frame2, int filterMethod)
Definition: sparse_stereo.cpp:756
bool getPutativeStereoCorrespondences()
Definition: sparse_stereo.cpp:480
const cv::Mat & getDebugImage()
Definition: sparse_stereo.hpp:103
FeatureInfo rightMatches
Definition: sparse_stereo.hpp:134
bool refineFeatureCorrespondences()
Definition: sparse_stereo.cpp:548
FeatureInfo & getFeatureInfoLeft()
Definition: sparse_stereo.hpp:71
const base::samples::DistanceImage * dist_left
Definition: sparse_stereo.hpp:148
base::Affine3d getInterFrameCorrespondenceTransform()
Definition: sparse_stereo.hpp:95
std::vector< std::pair< long, long > > getInterFrameCorrespondences()
Definition: sparse_stereo.hpp:90
StereoFeatures()
Definition: sparse_stereo.cpp:31
frame_helper::StereoCalibrationCv calib
Definition: sparse_stereo.hpp:128
int debugRightOffset
Definition: sparse_stereo.hpp:147
cv::Mat descriptors
Definition: sparse_stereo.hpp:26
void setDistanceImages(const base::samples::DistanceImage *left, const base::samples::DistanceImage *right)
Definition: sparse_stereo.cpp:65
std::vector< cv::KeyPoint > keypoints
Definition: sparse_stereo.hpp:25
void crossCheckMatching(const cv::Mat &descriptors1, const cv::Mat &descriptors2, std::vector< cv::DMatch > &filteredMatches12, int knn=1, float distanceFactor=2.0)
Definition: sparse_stereo.cpp:444
FeatureInfo leftPutativeMatches
Definition: sparse_stereo.hpp:133
cv::Ptr< cv::FeatureDetector > detector
Definition: sparse_stereo.hpp:140
base::Time descriptorTime
Definition: sparse_stereo.hpp:23
base::Affine3d correspondenceTransform
Definition: sparse_stereo.hpp:138
void setConfiguration(const FeatureConfiguration &config)
Definition: sparse_stereo.cpp:50
void initDetector(size_t lastNumFeatures)
Definition: sparse_stereo.cpp:73
Definition: sparse_stereo_types.h:58
void processFramePair(const cv::Mat &left_image, const cv::Mat &right_image, StereoFeatureArray *stereo_features=NULL)
Definition: sparse_stereo.cpp:320
void findFeatures_threading(const cv::Mat &image, FeatureInfo &info, bool left_frame=true, int crop_left=0, int crop_right=0)
Definition: sparse_stereo.cpp:186
FeatureInfo rightFeatures
Definition: sparse_stereo.hpp:132
StereoFeatureArray stereoFeatures
Definition: sparse_stereo.hpp:136
void setDetectorConfiguration(const DetectorConfiguration &detector_config)
Definition: sparse_stereo.cpp:45
FeatureConfiguration config
Definition: sparse_stereo.hpp:129
FeatureInfo leftFeatures
Definition: sparse_stereo.hpp:132
StereoFeatureArray & getStereoFeatures()
Definition: sparse_stereo.hpp:67
cv::gpu::GpuMat descriptors_gpu_right
Definition: sparse_stereo.hpp:151
base::Time detectorTime
Definition: sparse_stereo.hpp:22
cv::Mat debugImage
Definition: sparse_stereo.hpp:146
std::vector< std::pair< long, long > > correspondences
Definition: sparse_stereo.hpp:137