Commit 58b7c344 authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

refactored opencv_stitching

parent 29b917a5
......@@ -18,13 +18,7 @@ include_directories(
set(stitching_libs opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_calib3d opencv_gpu)
set(stitching_files blenders.hpp blenders.cpp
focal_estimators.hpp focal_estimators.cpp
motion_estimators.hpp motion_estimators.cpp
seam_finders.hpp seam_finders.cpp
util.hpp util.cpp util_inl.hpp
warpers.hpp warpers.cpp warpers_inl.hpp
main.cpp)
FILE(GLOB stitching_files "*.hpp" "*.cpp")
set(the_target opencv_stitching)
add_executable(${the_target} ${stitching_files})
......
This diff is collapsed.
#ifndef __OPENCV_MATCHERS_HPP__
#define __OPENCV_MATCHERS_HPP__
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
struct ImageFeatures
{
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
};
class FeaturesFinder
{
public:
virtual ~FeaturesFinder() {}
void operator ()(const std::vector<cv::Mat> &images, std::vector<ImageFeatures> &features) { find(images, features); }
protected:
virtual void find(const std::vector<cv::Mat> &images, std::vector<ImageFeatures> &features) = 0;
};
class SurfFeaturesFinder : public FeaturesFinder
{
public:
explicit SurfFeaturesFinder(bool gpu_hint = true, double hess_thresh = 500.0,
int num_octaves = 3, int num_layers = 4,
int num_octaves_descr = 4, int num_layers_descr = 2);
protected:
void find(const std::vector<cv::Mat> &images, std::vector<ImageFeatures> &features);
cv::Ptr<FeaturesFinder> impl_;
};
struct MatchesInfo
{
MatchesInfo();
MatchesInfo(const MatchesInfo &other);
const MatchesInfo& operator =(const MatchesInfo &other);
int src_img_idx, dst_img_idx; // Optional images indices
std::vector<cv::DMatch> matches;
std::vector<uchar> inliers_mask;
int num_inliers; // Number of geometrically consistent matches
cv::Mat H; // Homography
};
class FeaturesMatcher
{
public:
virtual ~FeaturesMatcher() {}
void operator ()(const cv::Mat &img1, const ImageFeatures &features1, const cv::Mat &img2, const ImageFeatures &features2,
MatchesInfo& matches_info) { match(img1, features1, img2, features2, matches_info); }
void operator ()(const std::vector<cv::Mat> &images, const std::vector<ImageFeatures> &features,
std::vector<MatchesInfo> &pairwise_matches);
protected:
virtual void match(const cv::Mat &img1, const ImageFeatures &features1, const cv::Mat &img2, const ImageFeatures &features2,
MatchesInfo& matches_info) = 0;
};
class BestOf2NearestMatcher : public FeaturesMatcher
{
public:
explicit BestOf2NearestMatcher(bool gpu_hint = true, float match_conf = 0.55f, int num_matches_thresh1 = 5, int num_matches_thresh2 = 5);
protected:
void match(const cv::Mat &img1, const ImageFeatures &features1, const cv::Mat &img2, const ImageFeatures &features2,
MatchesInfo &matches_info);
int num_matches_thresh1_;
int num_matches_thresh2_;
cv::Ptr<FeaturesMatcher> impl_;
};
#endif // __OPENCV_MATCHERS_HPP__
\ No newline at end of file
This diff is collapsed.
......@@ -3,84 +3,9 @@
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include "matchers.hpp"
#include "util.hpp"
struct ImageFeatures
{
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
};
class FeaturesFinder
{
public:
virtual ~FeaturesFinder() {}
void operator ()(const std::vector<cv::Mat> &images, std::vector<ImageFeatures> &features) { find(images, features); }
protected:
virtual void find(const std::vector<cv::Mat> &images, std::vector<ImageFeatures> &features) = 0;
};
class SurfFeaturesFinder : public FeaturesFinder
{
public:
explicit SurfFeaturesFinder(bool gpu_hint = true);
protected:
void find(const std::vector<cv::Mat> &images, std::vector<ImageFeatures> &features);
cv::Ptr<FeaturesFinder> impl_;
};
struct MatchesInfo
{
MatchesInfo();
MatchesInfo(const MatchesInfo &other);
const MatchesInfo& operator =(const MatchesInfo &other);
int src_img_idx, dst_img_idx; // Optional images indices
std::vector<cv::DMatch> matches;
std::vector<uchar> inliers_mask;
int num_inliers; // Number of geometrically consistent matches
cv::Mat H; // Homography
};
class FeaturesMatcher
{
public:
virtual ~FeaturesMatcher() {}
void operator ()(const cv::Mat &img1, const ImageFeatures &features1, const cv::Mat &img2, const ImageFeatures &features2,
MatchesInfo& matches_info) { match(img1, features1, img2, features2, matches_info); }
void operator ()(const std::vector<cv::Mat> &images, const std::vector<ImageFeatures> &features,
std::vector<MatchesInfo> &pairwise_matches);
protected:
virtual void match(const cv::Mat &img1, const ImageFeatures &features1, const cv::Mat &img2, const ImageFeatures &features2,
MatchesInfo& matches_info) = 0;
};
class BestOf2NearestMatcher : public FeaturesMatcher
{
public:
explicit BestOf2NearestMatcher(bool gpu_hint = true, float match_conf = 0.55f, int num_matches_thresh1 = 5, int num_matches_thresh2 = 5);
protected:
void match(const cv::Mat &img1, const ImageFeatures &features1, const cv::Mat &img2, const ImageFeatures &features2,
MatchesInfo &matches_info);
int num_matches_thresh1_;
int num_matches_thresh2_;
cv::Ptr<FeaturesMatcher> impl_;
};
struct CameraParams
{
CameraParams();
......
......@@ -52,7 +52,7 @@ class GraphCutSeamFinder : public PairwiseSeamFinder
{
public:
// TODO add COST_COLOR_GRAD support
enum { COST_COLOR/*, COST_COLOR_GRAD*/ };
enum { COST_COLOR };
GraphCutSeamFinder(int cost_type = COST_COLOR, float terminal_cost = 10000.f,
float bad_region_penalty = 1000.f);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment