2011-05-05 20:12:32 +08:00
|
|
|
#ifndef __OPENCV_MOTION_ESTIMATORS_HPP__
|
|
|
|
#define __OPENCV_MOTION_ESTIMATORS_HPP__
|
2011-05-04 19:09:42 +08:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <opencv2/core/core.hpp>
|
2011-05-06 16:05:02 +08:00
|
|
|
#include "matchers.hpp"
|
2011-05-04 19:09:42 +08:00
|
|
|
#include "util.hpp"
|
|
|
|
|
|
|
|
struct CameraParams
|
|
|
|
{
|
|
|
|
CameraParams();
|
|
|
|
CameraParams(const CameraParams& other);
|
|
|
|
const CameraParams& operator =(const CameraParams& other);
|
|
|
|
|
2011-05-16 13:11:09 +08:00
|
|
|
double focal; // Focal length
|
|
|
|
cv::Mat R; // Rotation
|
|
|
|
cv::Mat t; // Translation
|
2011-05-04 19:09:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Estimator
|
|
|
|
{
|
|
|
|
public:
|
2011-05-20 16:08:55 +08:00
|
|
|
void operator ()(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
|
|
|
std::vector<CameraParams> &cameras)
|
2011-05-04 19:09:42 +08:00
|
|
|
{
|
2011-05-20 16:08:55 +08:00
|
|
|
estimate(features, pairwise_matches, cameras);
|
2011-05-04 19:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2011-05-20 16:08:55 +08:00
|
|
|
virtual void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
|
|
|
std::vector<CameraParams> &cameras) = 0;
|
2011-05-04 19:09:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class HomographyBasedEstimator : public Estimator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HomographyBasedEstimator() : is_focals_estimated_(false) {}
|
|
|
|
bool isFocalsEstimated() const { return is_focals_estimated_; }
|
|
|
|
|
|
|
|
private:
|
2011-05-20 16:08:55 +08:00
|
|
|
void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
|
|
|
std::vector<CameraParams> &cameras);
|
2011-05-04 19:09:42 +08:00
|
|
|
|
|
|
|
bool is_focals_estimated_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BundleAdjuster : public Estimator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum { RAY_SPACE, FOCAL_RAY_SPACE };
|
|
|
|
|
2011-05-18 15:11:45 +08:00
|
|
|
BundleAdjuster(int cost_space = FOCAL_RAY_SPACE, float conf_thresh = 1.f)
|
|
|
|
: cost_space_(cost_space), conf_thresh_(conf_thresh) {}
|
2011-05-04 19:09:42 +08:00
|
|
|
|
|
|
|
private:
|
2011-05-20 16:08:55 +08:00
|
|
|
void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
|
|
|
std::vector<CameraParams> &cameras);
|
2011-05-04 19:09:42 +08:00
|
|
|
|
|
|
|
void calcError(cv::Mat &err);
|
|
|
|
void calcJacobian();
|
|
|
|
|
|
|
|
int num_images_;
|
|
|
|
int total_num_matches_;
|
|
|
|
const ImageFeatures *features_;
|
|
|
|
const MatchesInfo *pairwise_matches_;
|
|
|
|
cv::Mat cameras_;
|
|
|
|
std::vector<std::pair<int,int> > edges_;
|
|
|
|
|
|
|
|
int cost_space_;
|
2011-05-18 15:11:45 +08:00
|
|
|
float conf_thresh_;
|
2011-05-04 19:09:42 +08:00
|
|
|
cv::Mat err_, err1_, err2_;
|
|
|
|
cv::Mat J_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-05 23:12:36 +08:00
|
|
|
void waveCorrect(std::vector<cv::Mat> &rmats);
|
|
|
|
|
|
|
|
|
2011-05-04 19:09:42 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Auxiliary functions
|
|
|
|
|
2011-05-20 16:08:55 +08:00
|
|
|
std::vector<int> leaveBiggestComponent(std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
|
|
|
|
float conf_threshold);
|
2011-05-18 15:11:45 +08:00
|
|
|
|
2011-05-04 19:09:42 +08:00
|
|
|
void findMaxSpanningTree(int num_images, const std::vector<MatchesInfo> &pairwise_matches,
|
|
|
|
Graph &span_tree, std::vector<int> ¢ers);
|
|
|
|
|
2011-05-05 20:12:32 +08:00
|
|
|
#endif // __OPENCV_MOTION_ESTIMATORS_HPP__
|