turned opencv_stitching application to module and sample

pull/13383/head
Alexey Spizhevoy 13 years ago
parent 30ecb28877
commit 9be4701f24
  1. 42
      modules/stitching/CMakeLists.txt
  2. 17
      modules/stitching/include/opencv2/stitching/autocalib.hpp
  3. 59
      modules/stitching/include/opencv2/stitching/blenders.hpp
  4. 16
      modules/stitching/include/opencv2/stitching/camera.hpp
  5. 120
      modules/stitching/include/opencv2/stitching/exposure_compensate.hpp
  6. 14
      modules/stitching/include/opencv2/stitching/matchers.hpp
  7. 23
      modules/stitching/include/opencv2/stitching/motion_estimators.hpp
  8. 131
      modules/stitching/include/opencv2/stitching/seam_finders.hpp
  9. 54
      modules/stitching/include/opencv2/stitching/stitching.hpp
  10. 14
      modules/stitching/include/opencv2/stitching/util.hpp
  11. 164
      modules/stitching/include/opencv2/stitching/util_inl.hpp
  12. 55
      modules/stitching/include/opencv2/stitching/warpers.hpp
  13. 30
      modules/stitching/include/opencv2/stitching/warpers_inl.hpp
  14. 17
      modules/stitching/src/autocalib.cpp
  15. 15
      modules/stitching/src/blenders.cpp
  16. 8
      modules/stitching/src/camera.cpp
  17. 9
      modules/stitching/src/exposure_compensate.cpp
  18. 28
      modules/stitching/src/matchers.cpp
  19. 13
      modules/stitching/src/motion_estimators.cpp
  20. 0
      modules/stitching/src/precomp.cpp
  21. 11
      modules/stitching/src/precomp.hpp
  22. 8
      modules/stitching/src/seam_finders.cpp
  23. 8
      modules/stitching/src/util.cpp
  24. 8
      modules/stitching/src/warpers.cpp
  25. 6
      samples/cpp/CMakeLists.txt
  26. 1242
      samples/cpp/stitching.cpp

@ -1,40 +1,2 @@
project(stitching)
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}"
"${OpenCV_SOURCE_DIR}/modules/core/include"
"${OpenCV_SOURCE_DIR}/modules/imgproc/include"
"${OpenCV_SOURCE_DIR}/modules/objdetect/include"
"${OpenCV_SOURCE_DIR}/modules/ml/include"
"${OpenCV_SOURCE_DIR}/modules/highgui/include"
"${OpenCV_SOURCE_DIR}/modules/video/include"
"${OpenCV_SOURCE_DIR}/modules/features2d/include"
"${OpenCV_SOURCE_DIR}/modules/flann/include"
"${OpenCV_SOURCE_DIR}/modules/calib3d/include"
"${OpenCV_SOURCE_DIR}/modules/legacy/include"
"${OpenCV_SOURCE_DIR}/modules/imgproc/src" # for gcgraph.hpp
"${OpenCV_SOURCE_DIR}/modules/gpu/include"
)
set(stitching_libs opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_calib3d opencv_gpu)
FILE(GLOB stitching_files "*.hpp" "*.cpp")
set(the_target opencv_stitching)
add_executable(${the_target} ${stitching_files})
add_dependencies(${the_target} ${stitching_libs})
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib
OUTPUT_NAME "opencv_stitching")
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "applications")
endif()
target_link_libraries(${the_target} ${stitching_libs})
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
include_directories("${OpenCV_SOURCE_DIR}/modules/imgproc/src") # For gcgraph.hpp
define_opencv_module(stitching opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_gpu opencv_flann opencv_objdetect)

@ -39,19 +39,24 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_AUTOCALIB_HPP__
#define __OPENCV_AUTOCALIB_HPP__
#ifndef __OPENCV_STITCHING_AUTOCALIB_HPP__
#define __OPENCV_STITCHING_AUTOCALIB_HPP__
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
#include "matchers.hpp"
namespace cv
{
// See "Construction of Panoramic Image Mosaics with Global and Local Alignment"
// by Heung-Yeung Shum and Richard Szeliski.
void focalsFromHomography(const cv::Mat &H, double &f0, double &f1, bool &f0_ok, bool &f1_ok);
void focalsFromHomography(const Mat &H, double &f0, double &f1, bool &f0_ok, bool &f1_ok);
void estimateFocal(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
std::vector<double> &focals);
bool calibrateRotatingCamera(const std::vector<cv::Mat> &Hs, cv::Mat &K);
bool calibrateRotatingCamera(const std::vector<Mat> &Hs, Mat &K);
} // namespace cv
#endif // __OPENCV_AUTOCALIB_HPP__
#endif // __OPENCV_STITCHING_AUTOCALIB_HPP__

@ -39,26 +39,29 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_BLENDERS_HPP__
#define __OPENCV_BLENDERS_HPP__
#ifndef __OPENCV_STITCHING_BLENDERS_HPP__
#define __OPENCV_STITCHING_BLENDERS_HPP__
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
namespace cv
{
// Simple blender which puts one image over another
class Blender
{
public:
enum { NO, FEATHER, MULTI_BAND };
static cv::Ptr<Blender> createDefault(int type, bool try_gpu = false);
static Ptr<Blender> createDefault(int type, bool try_gpu = false);
void prepare(const std::vector<cv::Point> &corners, const std::vector<cv::Size> &sizes);
virtual void prepare(cv::Rect dst_roi);
virtual void feed(const cv::Mat &img, const cv::Mat &mask, cv::Point tl);
virtual void blend(cv::Mat &dst, cv::Mat &dst_mask);
void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
virtual void prepare(Rect dst_roi);
virtual void feed(const Mat &img, const Mat &mask, Point tl);
virtual void blend(Mat &dst, Mat &dst_mask);
protected:
cv::Mat dst_, dst_mask_;
cv::Rect dst_roi_;
Mat dst_, dst_mask_;
Rect dst_roi_;
};
@ -69,14 +72,14 @@ public:
float sharpness() const { return sharpness_; }
void setSharpness(float val) { sharpness_ = val; }
void prepare(cv::Rect dst_roi);
void feed(const cv::Mat &img, const cv::Mat &mask, cv::Point tl);
void blend(cv::Mat &dst, cv::Mat &dst_mask);
void prepare(Rect dst_roi);
void feed(const Mat &img, const Mat &mask, Point tl);
void blend(Mat &dst, Mat &dst_mask);
private:
float sharpness_;
cv::Mat weight_map_;
cv::Mat dst_weight_map_;
Mat weight_map_;
Mat dst_weight_map_;
};
@ -87,15 +90,15 @@ public:
int numBands() const { return actual_num_bands_; }
void setNumBands(int val) { actual_num_bands_ = val; }
void prepare(cv::Rect dst_roi);
void feed(const cv::Mat &img, const cv::Mat &mask, cv::Point tl);
void blend(cv::Mat &dst, cv::Mat &dst_mask);
void prepare(Rect dst_roi);
void feed(const Mat &img, const Mat &mask, Point tl);
void blend(Mat &dst, Mat &dst_mask);
private:
int actual_num_bands_, num_bands_;
std::vector<cv::Mat> dst_pyr_laplace_;
std::vector<cv::Mat> dst_band_weights_;
cv::Rect dst_roi_final_;
std::vector<Mat> dst_pyr_laplace_;
std::vector<Mat> dst_band_weights_;
Rect dst_roi_final_;
bool can_use_gpu_;
};
@ -103,15 +106,17 @@ private:
//////////////////////////////////////////////////////////////////////////////
// Auxiliary functions
void normalize(const cv::Mat& weight, cv::Mat& src);
void normalizeUsingWeightMap(const Mat& weight, Mat& src);
void createWeightMap(const cv::Mat& mask, float sharpness, cv::Mat& weight);
void createWeightMap(const Mat& mask, float sharpness, Mat& weight);
void createLaplacePyr(const cv::Mat &img, int num_levels, std::vector<cv::Mat>& pyr);
void createLaplacePyr(const Mat &img, int num_levels, std::vector<Mat>& pyr);
void createLaplacePyrGpu(const cv::Mat &img, int num_levels, std::vector<cv::Mat>& pyr);
void createLaplacePyrGpu(const Mat &img, int num_levels, std::vector<Mat>& pyr);
// Restores source image
void restoreImageFromLaplacePyr(std::vector<cv::Mat>& pyr);
void restoreImageFromLaplacePyr(std::vector<Mat>& pyr);
} // namespace cv
#endif // __OPENCV_BLENDERS_HPP__
#endif // __OPENCV_STITCHING_BLENDERS_HPP__

@ -39,11 +39,13 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_CAMERA_HPP__
#define __OPENCV_CAMERA_HPP__
#ifndef __OPENCV_STITCHING_CAMERA_HPP__
#define __OPENCV_STITCHING_CAMERA_HPP__
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
namespace cv
{
struct CameraParams
{
@ -52,8 +54,10 @@ struct CameraParams
const CameraParams& operator =(const CameraParams& other);
double focal; // Focal length
cv::Mat R; // Rotation
cv::Mat t; // Translation
Mat R; // Rotation
Mat t; // Translation
};
#endif // #ifndef __OPENCV_CAMERA_HPP__
} // namespace cv
#endif // #ifndef __OPENCV_STITCHING_CAMERA_HPP__

@ -38,61 +38,65 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_EXPOSURE_COMPENSATE_HPP__
#define __OPENCV_EXPOSURE_COMPENSATE_HPP__
#include "precomp.hpp"
class ExposureCompensator
{
public:
enum { NO, GAIN, GAIN_BLOCKS };
static cv::Ptr<ExposureCompensator> createDefault(int type);
void feed(const std::vector<cv::Point> &corners, const std::vector<cv::Mat> &images,
const std::vector<cv::Mat> &masks);
virtual void feed(const std::vector<cv::Point> &corners, const std::vector<cv::Mat> &images,
const std::vector<std::pair<cv::Mat,uchar> > &masks) = 0;
virtual void apply(int index, cv::Point corner, cv::Mat &image, const cv::Mat &mask) = 0;
};
class NoExposureCompensator : public ExposureCompensator
{
public:
void feed(const std::vector<cv::Point> &/*corners*/, const std::vector<cv::Mat> &/*images*/,
const std::vector<std::pair<cv::Mat,uchar> > &/*masks*/) {};
void apply(int /*index*/, cv::Point /*corner*/, cv::Mat &/*image*/, const cv::Mat &/*mask*/) {};
};
class GainCompensator : public ExposureCompensator
{
public:
void feed(const std::vector<cv::Point> &corners, const std::vector<cv::Mat> &images,
const std::vector<std::pair<cv::Mat,uchar> > &masks);
void apply(int index, cv::Point corner, cv::Mat &image, const cv::Mat &mask);
std::vector<double> gains() const;
private:
cv::Mat_<double> gains_;
};
class BlocksGainCompensator : public ExposureCompensator
{
public:
BlocksGainCompensator(int bl_width = 32, int bl_height = 32)
: bl_width_(bl_width), bl_height_(bl_height) {}
void feed(const std::vector<cv::Point> &corners, const std::vector<cv::Mat> &images,
const std::vector<std::pair<cv::Mat,uchar> > &masks);
void apply(int index, cv::Point corner, cv::Mat &image, const cv::Mat &mask);
private:
int bl_width_, bl_height_;
std::vector<cv::Mat_<float> > gain_maps_;
};
#endif // __OPENCV_EXPOSURE_COMPENSATE_HPP__
//M*/
#ifndef __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
#define __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
#include "opencv2/core/core.hpp"
namespace cv
{
class ExposureCompensator
{
public:
enum { NO, GAIN, GAIN_BLOCKS };
static Ptr<ExposureCompensator> createDefault(int type);
void feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<Mat> &masks);
virtual void feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<std::pair<Mat,uchar> > &masks) = 0;
virtual void apply(int index, Point corner, Mat &image, const Mat &mask) = 0;
};
class NoExposureCompensator : public ExposureCompensator
{
public:
void feed(const std::vector<Point> &/*corners*/, const std::vector<Mat> &/*images*/,
const std::vector<std::pair<Mat,uchar> > &/*masks*/) {};
void apply(int /*index*/, Point /*corner*/, Mat &/*image*/, const Mat &/*mask*/) {};
};
class GainCompensator : public ExposureCompensator
{
public:
void feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<std::pair<Mat,uchar> > &masks);
void apply(int index, Point corner, Mat &image, const Mat &mask);
std::vector<double> gains() const;
private:
Mat_<double> gains_;
};
class BlocksGainCompensator : public ExposureCompensator
{
public:
BlocksGainCompensator(int bl_width = 32, int bl_height = 32)
: bl_width_(bl_width), bl_height_(bl_height) {}
void feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<std::pair<Mat,uchar> > &masks);
void apply(int index, Point corner, Mat &image, const Mat &mask);
private:
int bl_width_, bl_height_;
std::vector<Mat_<float> > gain_maps_;
};
} // namespace cv
#endif // __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__

@ -39,10 +39,14 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_MATCHERS_HPP__
#define __OPENCV_MATCHERS_HPP__
#ifndef __OPENCV_STITCHING_MATCHERS_HPP__
#define __OPENCV_STITCHING_MATCHERS_HPP__
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
namespace cv
{
struct ImageFeatures
{
@ -136,4 +140,6 @@ protected:
cv::Ptr<FeaturesMatcher> impl_;
};
#endif // __OPENCV_MATCHERS_HPP__
} // namespace cv
#endif // __OPENCV_STITCHING_MATCHERS_HPP__

@ -39,14 +39,17 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_MOTION_ESTIMATORS_HPP__
#define __OPENCV_MOTION_ESTIMATORS_HPP__
#ifndef __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
#define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
#include "matchers.hpp"
#include "util.hpp"
#include "camera.hpp"
namespace cv
{
class Estimator
{
public:
@ -88,24 +91,24 @@ private:
void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
std::vector<CameraParams> &cameras);
void calcError(cv::Mat &err);
void calcError(Mat &err);
void calcJacobian();
int num_images_;
int total_num_matches_;
const ImageFeatures *features_;
const MatchesInfo *pairwise_matches_;
cv::Mat cameras_;
Mat cameras_;
std::vector<std::pair<int,int> > edges_;
int cost_space_;
float conf_thresh_;
cv::Mat err_, err1_, err2_;
cv::Mat J_;
Mat err_, err1_, err2_;
Mat J_;
};
void waveCorrect(std::vector<cv::Mat> &rmats);
void waveCorrect(std::vector<Mat> &rmats);
//////////////////////////////////////////////////////////////////////////////
@ -121,4 +124,6 @@ std::vector<int> leaveBiggestComponent(std::vector<ImageFeatures> &features, std
void findMaxSpanningTree(int num_images, const std::vector<MatchesInfo> &pairwise_matches,
Graph &span_tree, std::vector<int> &centers);
#endif // __OPENCV_MOTION_ESTIMATORS_HPP__
} // namespace cv
#endif // __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__

@ -38,66 +38,71 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_SEAM_FINDERS_HPP__
#define __OPENCV_SEAM_FINDERS_HPP__
#include "precomp.hpp"
class SeamFinder
{
public:
enum { NO, VORONOI, GC_COLOR, GC_COLOR_GRAD };
static cv::Ptr<SeamFinder> createDefault(int type);
virtual ~SeamFinder() {}
virtual void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
std::vector<cv::Mat> &masks) = 0;
};
class NoSeamFinder : public SeamFinder
{
public:
void find(const std::vector<cv::Mat>&, const std::vector<cv::Point>&, std::vector<cv::Mat>&) {}
};
class PairwiseSeamFinder : public SeamFinder
{
public:
virtual void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
std::vector<cv::Mat> &masks);
protected:
virtual void findInPair(size_t first, size_t second, cv::Rect roi) = 0;
std::vector<cv::Mat> images_;
std::vector<cv::Point> corners_;
std::vector<cv::Mat> masks_;
};
class VoronoiSeamFinder : public PairwiseSeamFinder
{
private:
void findInPair(size_t first, size_t second, cv::Rect roi);
};
class GraphCutSeamFinder : public SeamFinder
{
public:
enum { COST_COLOR, COST_COLOR_GRAD };
GraphCutSeamFinder(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,
float bad_region_penalty = 1000.f);
void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
std::vector<cv::Mat> &masks);
private:
class Impl;
cv::Ptr<Impl> impl_;
};
#endif // __OPENCV_SEAM_FINDERS_HPP__
//M*/
#ifndef __OPENCV_STITCHING_SEAM_FINDERS_HPP__
#define __OPENCV_STITCHING_SEAM_FINDERS_HPP__
#include "opencv2/core/core.hpp"
namespace cv
{
class SeamFinder
{
public:
enum { NO, VORONOI, GC_COLOR, GC_COLOR_GRAD };
static Ptr<SeamFinder> createDefault(int type);
virtual ~SeamFinder() {}
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks) = 0;
};
class NoSeamFinder : public SeamFinder
{
public:
void find(const std::vector<Mat>&, const std::vector<Point>&, std::vector<Mat>&) {}
};
class PairwiseSeamFinder : public SeamFinder
{
public:
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks);
protected:
virtual void findInPair(size_t first, size_t second, Rect roi) = 0;
std::vector<Mat> images_;
std::vector<Point> corners_;
std::vector<Mat> masks_;
};
class VoronoiSeamFinder : public PairwiseSeamFinder
{
private:
void findInPair(size_t first, size_t second, Rect roi);
};
class GraphCutSeamFinder : public SeamFinder
{
public:
enum { COST_COLOR, COST_COLOR_GRAD };
GraphCutSeamFinder(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,
float bad_region_penalty = 1000.f);
void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks);
private:
class Impl;
Ptr<Impl> impl_;
};
} // namespace cv
#endif // __OPENCV_STITCHING_SEAM_FINDERS_HPP__

@ -0,0 +1,54 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_STITCHING_HPP__
#define __OPENCV_STITCHING_HPP__
#include "opencv2/stitching/autocalib.hpp"
#include "opencv2/stitching/blenders.hpp"
#include "opencv2/stitching/camera.hpp"
#include "opencv2/stitching/exposure_compensate.hpp"
#include "opencv2/stitching/matchers.hpp"
#include "opencv2/stitching/motion_estimators.hpp"
#include "opencv2/stitching/seam_finders.hpp"
#include "opencv2/stitching/util.hpp"
#include "opencv2/stitching/warpers.hpp"
#endif // __OPENCV_STITCHING_HPP__

@ -43,7 +43,7 @@
#define __OPENCV_STITCHING_UTIL_HPP__
#include <list>
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
#define ENABLE_LOG 1
@ -56,6 +56,8 @@
#define LOGLN(msg) LOG(msg << std::endl)
namespace cv
{
class DisjointSets
{
@ -104,14 +106,16 @@ private:
//////////////////////////////////////////////////////////////////////////////
// Auxiliary functions
bool overlapRoi(cv::Point tl1, cv::Point tl2, cv::Size sz1, cv::Size sz2, cv::Rect &roi);
cv::Rect resultRoi(const std::vector<cv::Point> &corners, const std::vector<cv::Mat> &images);
cv::Rect resultRoi(const std::vector<cv::Point> &corners, const std::vector<cv::Size> &sizes);
cv::Point resultTl(const std::vector<cv::Point> &corners);
bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi);
Rect resultRoi(const std::vector<Point> &corners, const std::vector<Mat> &images);
Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes);
Point resultTl(const std::vector<Point> &corners);
// Returns random 'count' element subset of the {0,1,...,size-1} set
void selectRandomSubset(int count, int size, std::vector<int> &subset);
} // namespace cv
#include "util_inl.hpp"
#endif // __OPENCV_STITCHING_UTIL_HPP__

@ -38,82 +38,88 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_STITCHING_UTIL_INL_HPP__
#define __OPENCV_STITCHING_UTIL_INL_HPP__
#include <queue>
#include "util.hpp" // Make your IDE see declarations
template <typename B>
B Graph::forEach(B body) const
{
for (int i = 0; i < numVertices(); ++i)
{
std::list<GraphEdge>::const_iterator edge = edges_[i].begin();
for (; edge != edges_[i].end(); ++edge)
body(*edge);
}
return body;
}
template <typename B>
B Graph::walkBreadthFirst(int from, B body) const
{
std::vector<bool> was(numVertices(), false);
std::queue<int> vertices;
was[from] = true;
vertices.push(from);
while (!vertices.empty())
{
int vertex = vertices.front();
vertices.pop();
std::list<GraphEdge>::const_iterator edge = edges_[vertex].begin();
for (; edge != edges_[vertex].end(); ++edge)
{
if (!was[edge->to])
{
body(*edge);
was[edge->to] = true;
vertices.push(edge->to);
}
}
}
return body;
}
//////////////////////////////////////////////////////////////////////////////
// Some auxiliary math functions
static inline
float normL2(const cv::Point3f& a)
{
return a.x * a.x + a.y * a.y + a.z * a.z;
}
static inline
float normL2(const cv::Point3f& a, const cv::Point3f& b)
{
return normL2(a - b);
}
static inline
double normL2sq(const cv::Mat &r)
{
return r.dot(r);
}
static inline int sqr(int x) { return x * x; }
static inline float sqr(float x) { return x * x; }
static inline double sqr(double x) { return x * x; }
#endif // __OPENCV_STITCHING_UTIL_INL_HPP__
//M*/
#ifndef __OPENCV_STITCHING_UTIL_INL_HPP__
#define __OPENCV_STITCHING_UTIL_INL_HPP__
#include <queue>
#include "opencv2/core/core.hpp"
#include "util.hpp" // Make your IDE see declarations
namespace cv
{
template <typename B>
B Graph::forEach(B body) const
{
for (int i = 0; i < numVertices(); ++i)
{
std::list<GraphEdge>::const_iterator edge = edges_[i].begin();
for (; edge != edges_[i].end(); ++edge)
body(*edge);
}
return body;
}
template <typename B>
B Graph::walkBreadthFirst(int from, B body) const
{
std::vector<bool> was(numVertices(), false);
std::queue<int> vertices;
was[from] = true;
vertices.push(from);
while (!vertices.empty())
{
int vertex = vertices.front();
vertices.pop();
std::list<GraphEdge>::const_iterator edge = edges_[vertex].begin();
for (; edge != edges_[vertex].end(); ++edge)
{
if (!was[edge->to])
{
body(*edge);
was[edge->to] = true;
vertices.push(edge->to);
}
}
}
return body;
}
//////////////////////////////////////////////////////////////////////////////
// Some auxiliary math functions
static inline
float normL2(const Point3f& a)
{
return a.x * a.x + a.y * a.y + a.z * a.z;
}
static inline
float normL2(const Point3f& a, const Point3f& b)
{
return normL2(a - b);
}
static inline
double normL2sq(const Mat &r)
{
return r.dot(r);
}
static inline int sqr(int x) { return x * x; }
static inline float sqr(float x) { return x * x; }
static inline double sqr(double x) { return x * x; }
} // namespace cv
#endif // __OPENCV_STITCHING_UTIL_INL_HPP__

@ -39,29 +39,34 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_WARPERS_HPP__
#define __OPENCV_WARPERS_HPP__
#ifndef __OPENCV_STITCHING_WARPERS_HPP__
#define __OPENCV_STITCHING_WARPERS_HPP__
#include "precomp.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/gpu/gpu.hpp"
namespace cv
{
class Warper
{
public:
enum { PLANE, CYLINDRICAL, SPHERICAL };
static cv::Ptr<Warper> createByCameraFocal(float focal, int type, bool try_gpu = false);
static Ptr<Warper> createByCameraFocal(float focal, int type, bool try_gpu = false);
virtual ~Warper() {}
virtual cv::Point warp(const cv::Mat &src, float focal, const cv::Mat& R, cv::Mat &dst,
int interp_mode = cv::INTER_LINEAR, int border_mode = cv::BORDER_REFLECT) = 0;
virtual cv::Rect warpRoi(const cv::Size &sz, float focal, const cv::Mat &R) = 0;
virtual Point warp(const Mat &src, float focal, const Mat& R, Mat &dst,
int interp_mode = INTER_LINEAR, int border_mode = BORDER_REFLECT) = 0;
virtual Rect warpRoi(const Size &sz, float focal, const Mat &R) = 0;
};
struct ProjectorBase
{
void setTransformation(const cv::Mat& R);
void setTransformation(const Mat& R);
cv::Size size;
Size size;
float focal;
float r[9];
float rinv[9];
@ -73,20 +78,20 @@ template <class P>
class WarperBase : public Warper
{
public:
virtual cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
virtual Point warp(const Mat &src, float focal, const Mat &R, Mat &dst,
int interp_mode, int border_mode);
virtual cv::Rect warpRoi(const cv::Size &sz, float focal, const cv::Mat &R);
virtual Rect warpRoi(const Size &sz, float focal, const Mat &R);
protected:
// Detects ROI of the destination image. It's correct for any projection.
virtual void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br);
virtual void detectResultRoi(Point &dst_tl, Point &dst_br);
// Detects ROI of the destination image by walking over image border.
// Correctness for any projection isn't guaranteed.
void detectResultRoiByBorder(cv::Point &dst_tl, cv::Point &dst_br);
void detectResultRoiByBorder(Point &dst_tl, Point &dst_br);
cv::Size src_size_;
Size src_size_;
P projector_;
};
@ -110,7 +115,7 @@ public:
}
protected:
void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br);
void detectResultRoi(Point &dst_tl, Point &dst_br);
};
@ -118,11 +123,11 @@ class PlaneWarperGpu : public PlaneWarper
{
public:
PlaneWarperGpu(float plane_dist = 1.f, float scale = 1.f) : PlaneWarper(plane_dist, scale) {}
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
Point warp(const Mat &src, float focal, const Mat &R, Mat &dst,
int interp_mode, int border_mode);
private:
cv::gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
};
@ -141,7 +146,7 @@ public:
SphericalWarper(float scale = 300.f) { projector_.scale = scale; }
protected:
void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br);
void detectResultRoi(Point &dst_tl, Point &dst_br);
};
@ -149,11 +154,11 @@ class SphericalWarperGpu : public SphericalWarper
{
public:
SphericalWarperGpu(float scale = 300.f) : SphericalWarper(scale) {}
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
Point warp(const Mat &src, float focal, const Mat &R, Mat &dst,
int interp_mode, int border_mode);
private:
cv::gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
};
@ -171,7 +176,7 @@ public:
CylindricalWarper(float scale = 300.f) { projector_.scale = scale; }
protected:
void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br)
void detectResultRoi(Point &dst_tl, Point &dst_br)
{
WarperBase<CylindricalProjector>::detectResultRoiByBorder(dst_tl, dst_br);
}
@ -182,13 +187,15 @@ class CylindricalWarperGpu : public CylindricalWarper
{
public:
CylindricalWarperGpu(float scale = 300.f) : CylindricalWarper(scale) {}
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
Point warp(const Mat &src, float focal, const Mat &R, Mat &dst,
int interp_mode, int border_mode);
private:
cv::gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
};
} // namespace cv
#include "warpers_inl.hpp"
#endif // __OPENCV_WARPERS_HPP__
#endif // __OPENCV_STITCHING_WARPERS_HPP__

@ -39,13 +39,17 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_WARPERS_INL_HPP__
#define __OPENCV_WARPERS_INL_HPP__
#ifndef __OPENCV_STITCHING_WARPERS_INL_HPP__
#define __OPENCV_STITCHING_WARPERS_INL_HPP__
#include "opencv2/core/core.hpp"
#include "warpers.hpp" // Make your IDE see declarations
namespace cv
{
template <class P>
cv::Point WarperBase<P>::warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
Point WarperBase<P>::warp(const Mat &src, float focal, const Mat &R, Mat &dst,
int interp_mode, int border_mode)
{
src_size_ = src.size();
@ -54,11 +58,11 @@ cv::Point WarperBase<P>::warp(const cv::Mat &src, float focal, const cv::Mat &R,
projector_.focal = focal;
projector_.setTransformation(R);
cv::Point dst_tl, dst_br;
Point dst_tl, dst_br;
detectResultRoi(dst_tl, dst_br);
cv::Mat xmap(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
cv::Mat ymap(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
Mat xmap(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
Mat ymap(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
float x, y;
for (int v = dst_tl.y; v <= dst_br.y; ++v)
@ -79,7 +83,7 @@ cv::Point WarperBase<P>::warp(const cv::Mat &src, float focal, const cv::Mat &R,
template <class P>
cv::Rect WarperBase<P>::warpRoi(const cv::Size &sz, float focal, const cv::Mat &R)
Rect WarperBase<P>::warpRoi(const Size &sz, float focal, const Mat &R)
{
src_size_ = sz;
@ -87,15 +91,15 @@ cv::Rect WarperBase<P>::warpRoi(const cv::Size &sz, float focal, const cv::Mat &
projector_.focal = focal;
projector_.setTransformation(R);
cv::Point dst_tl, dst_br;
Point dst_tl, dst_br;
detectResultRoi(dst_tl, dst_br);
return cv::Rect(dst_tl, cv::Point(dst_br.x + 1, dst_br.y + 1));
return Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1));
}
template <class P>
void WarperBase<P>::detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br)
void WarperBase<P>::detectResultRoi(Point &dst_tl, Point &dst_br)
{
float tl_uf = std::numeric_limits<float>::max();
float tl_vf = std::numeric_limits<float>::max();
@ -121,7 +125,7 @@ void WarperBase<P>::detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br)
template <class P>
void WarperBase<P>::detectResultRoiByBorder(cv::Point &dst_tl, cv::Point &dst_br)
void WarperBase<P>::detectResultRoiByBorder(Point &dst_tl, Point &dst_br)
{
float tl_uf = std::numeric_limits<float>::max();
float tl_vf = std::numeric_limits<float>::max();
@ -252,4 +256,6 @@ void CylindricalProjector::mapBackward(float u, float v, float &x, float &y)
y = focal * y / z + size.height * 0.5f;
}
#endif // __OPENCV_WARPERS_INL_HPP__
} // namespace cv
#endif // __OPENCV_STITCHING_WARPERS_INL_HPP__

@ -39,11 +39,12 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "autocalib.hpp"
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace cv
{
void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, bool &f1_ok)
{
@ -59,8 +60,8 @@ void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, boo
d2 = (h[7] - h[6]) * (h[7] + h[6]);
v1 = -(h[0] * h[1] + h[3] * h[4]) / d1;
v2 = (h[0] * h[0] + h[3] * h[3] - h[1] * h[1] - h[4] * h[4]) / d2;
if (v1 < v2) swap(v1, v2);
if (v1 > 0 && v2 > 0) f1 = sqrt(abs(d1) > abs(d2) ? v1 : v2);
if (v1 < v2) std::swap(v1, v2);
if (v1 > 0 && v2 > 0) f1 = sqrt(std::abs(d1) > std::abs(d2) ? v1 : v2);
else if (v1 > 0) f1 = sqrt(v1);
else f1_ok = false;
@ -69,8 +70,8 @@ void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, boo
d2 = h[0] * h[0] + h[1] * h[1] - h[3] * h[3] - h[4] * h[4];
v1 = -h[2] * h[5] / d1;
v2 = (h[5] * h[5] - h[2] * h[2]) / d2;
if (v1 < v2) swap(v1, v2);
if (v1 > 0 && v2 > 0) f0 = sqrt(abs(d1) > abs(d2) ? v1 : v2);
if (v1 < v2) std::swap(v1, v2);
if (v1 > 0 && v2 > 0) f0 = sqrt(std::abs(d1) > std::abs(d2) ? v1 : v2);
else if (v1 > 0) f0 = sqrt(v1);
else f0_ok = false;
}
@ -182,3 +183,5 @@ bool calibrateRotatingCamera(const vector<Mat> &Hs, Mat &K)
K = W.t();
return true;
}
} // namespace cv

@ -39,11 +39,12 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "blenders.hpp"
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace cv
{
static const float WEIGHT_EPS = 1e-5f;
@ -147,7 +148,7 @@ void FeatherBlender::feed(const Mat &img, const Mat &mask, Point tl)
void FeatherBlender::blend(Mat &dst, Mat &dst_mask)
{
normalize(dst_weight_map_, dst_);
normalizeUsingWeightMap(dst_weight_map_, dst_);
dst_mask_ = dst_weight_map_ > WEIGHT_EPS;
Blender::blend(dst, dst_mask);
}
@ -281,7 +282,7 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
void MultiBandBlender::blend(Mat &dst, Mat &dst_mask)
{
for (int i = 0; i <= num_bands_; ++i)
normalize(dst_band_weights_[i], dst_pyr_laplace_[i]);
normalizeUsingWeightMap(dst_band_weights_[i], dst_pyr_laplace_[i]);
restoreImageFromLaplacePyr(dst_pyr_laplace_);
@ -299,7 +300,7 @@ void MultiBandBlender::blend(Mat &dst, Mat &dst_mask)
//////////////////////////////////////////////////////////////////////////////
// Auxiliary functions
void normalize(const Mat& weight, Mat& src)
void normalizeUsingWeightMap(const Mat& weight, Mat& src)
{
CV_Assert(weight.type() == CV_32F);
CV_Assert(src.type() == CV_16SC3);
@ -374,4 +375,4 @@ void restoreImageFromLaplacePyr(vector<Mat> &pyr)
}
}
} // namespace cv

@ -1,9 +1,9 @@
#include <fstream>
#include "camera.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace cv
{
CameraParams::CameraParams() : focal(1), R(Mat::eye(3, 3, CV_64F)), t(Mat::zeros(3, 1, CV_64F)) {}
@ -16,3 +16,5 @@ const CameraParams& CameraParams::operator =(const CameraParams &other)
t = other.t.clone();
return *this;
}
} // namespace cv

@ -39,14 +39,13 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "exposure_compensate.hpp"
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
namespace cv
{
Ptr<ExposureCompensator> ExposureCompensator::createDefault(int type)
{
@ -243,3 +242,5 @@ void BlocksGainCompensator::apply(int index, Point /*corner*/, Mat &image, const
}
}
}
} // namespace cv

@ -39,17 +39,13 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include <algorithm>
#include <functional>
#include "matchers.hpp"
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
//////////////////////////////////////////////////////////////////////////////
namespace cv
{
void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features)
{
@ -58,10 +54,13 @@ void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features)
//features.img = image.clone();
}
//////////////////////////////////////////////////////////////////////////////
} // namespace cv
namespace
{
using namespace cv;
class CpuSurfFeaturesFinder : public FeaturesFinder
{
public:
@ -153,9 +152,12 @@ namespace
keypoints_.release();
descriptors_.release();
}
} // anonymous namespace
} // namespace
namespace cv
{
SurfFeaturesFinder::SurfFeaturesFinder(bool try_use_gpu, double hess_thresh, int num_octaves, int num_layers,
int num_octaves_descr, int num_layers_descr)
{
@ -240,8 +242,8 @@ struct MatchPairsBody
pairwise_matches[dual_pair_idx].H = pairwise_matches[pair_idx].H.inv();
for (size_t j = 0; j < pairwise_matches[dual_pair_idx].matches.size(); ++j)
swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx,
pairwise_matches[dual_pair_idx].matches[j].trainIdx);
std::swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx,
pairwise_matches[dual_pair_idx].matches[j].trainIdx);
LOG(".");
}
}
@ -457,7 +459,7 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea
// Find pair-wise motion
matches_info.H = findHomography(src_points, dst_points, matches_info.inliers_mask, CV_RANSAC);
if (abs(determinant(matches_info.H)) < numeric_limits<double>::epsilon())
if (std::abs(determinant(matches_info.H)) < numeric_limits<double>::epsilon())
return;
// Find number of inliers
@ -504,3 +506,5 @@ void BestOf2NearestMatcher::releaseMemory()
{
impl_->releaseMemory();
}
} // namespace cv

@ -39,17 +39,12 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include <algorithm>
#include <sstream>
#include "autocalib.hpp"
#include "motion_estimators.hpp"
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
//////////////////////////////////////////////////////////////////////////////
namespace cv
{
struct IncDistance
{
@ -605,3 +600,5 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
centers.push_back(i);
CV_Assert(centers.size() > 0 && centers.size() <= 2);
}
} // namespace cv

@ -51,10 +51,19 @@
#include <utility>
#include <set>
#include <functional>
#include <sstream>
#include "opencv2/stitching/autocalib.hpp"
#include "opencv2/stitching/blenders.hpp"
#include "opencv2/stitching/camera.hpp"
#include "opencv2/stitching/exposure_compensate.hpp"
#include "opencv2/stitching/matchers.hpp"
#include "opencv2/stitching/motion_estimators.hpp"
#include "opencv2/stitching/seam_finders.hpp"
#include "opencv2/stitching/util.hpp"
#include "opencv2/stitching/warpers.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/gpu/gpu.hpp"

@ -39,12 +39,12 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "seam_finders.hpp"
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace cv
{
Ptr<SeamFinder> SeamFinder::createDefault(int type)
{
@ -405,3 +405,5 @@ void GraphCutSeamFinder::find(const vector<Mat> &src, const vector<Point> &corne
{
impl_->find(src, corners, masks);
}
} // namespace cv

@ -39,10 +39,12 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "util.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace cv
{
void DisjointSets::createOneElemSets(int n)
{
@ -161,3 +163,5 @@ void selectRandomSubset(int count, int size, vector<int> &subset)
}
}
}
} // namespace cv

@ -39,10 +39,12 @@
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "warpers.hpp"
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace cv
{
Ptr<Warper> Warper::createByCameraFocal(float focal, int type, bool try_gpu)
{
@ -227,3 +229,5 @@ Point CylindricalWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat
return dst_tl;
}
} // namespace cv

@ -18,6 +18,8 @@ if (BUILD_EXAMPLES)
"${CMAKE_SOURCE_DIR}/modules/objdetect/include"
"${CMAKE_SOURCE_DIR}/modules/legacy/include"
"${CMAKE_SOURCE_DIR}/modules/contrib/include"
"${CMAKE_SOURCE_DIR}/modules/stitching/include"
"${CMAKE_SOURCE_DIR}/modules/gpu/include"
)
if(CMAKE_COMPILER_IS_GNUCXX)
@ -35,10 +37,10 @@ if (BUILD_EXAMPLES)
PROJECT_LABEL "(EXAMPLE) ${name}")
add_dependencies(${the_target} opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib)
opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_gpu)
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_gpu)
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp")

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save