Commit c9a41c68 authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

added first version of public stitching API, added simple sample which uses that…

added first version of public stitching API, added simple sample which uses that API, old sample renamed to stitching_detailed
parent 1449dd1f
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_AUTOCALIB_HPP__ #ifndef __OPENCV_STITCHING_AUTOCALIB_HPP__
#define __OPENCV_STITCHING_AUTOCALIB_HPP__ #define __OPENCV_STITCHING_AUTOCALIB_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_BLENDERS_HPP__ #ifndef __OPENCV_STITCHING_BLENDERS_HPP__
#define __OPENCV_STITCHING_BLENDERS_HPP__ #define __OPENCV_STITCHING_BLENDERS_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_CAMERA_HPP__ #ifndef __OPENCV_STITCHING_CAMERA_HPP__
#define __OPENCV_STITCHING_CAMERA_HPP__ #define __OPENCV_STITCHING_CAMERA_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__ #ifndef __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
#define __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__ #define __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_MATCHERS_HPP__ #ifndef __OPENCV_STITCHING_MATCHERS_HPP__
#define __OPENCV_STITCHING_MATCHERS_HPP__ #define __OPENCV_STITCHING_MATCHERS_HPP__
...@@ -51,9 +52,9 @@ namespace detail { ...@@ -51,9 +52,9 @@ namespace detail {
struct CV_EXPORTS ImageFeatures struct CV_EXPORTS ImageFeatures
{ {
int img_idx; int img_idx;
cv::Size img_size; Size img_size;
std::vector<cv::KeyPoint> keypoints; std::vector<KeyPoint> keypoints;
cv::Mat descriptors; Mat descriptors;
}; };
...@@ -61,12 +62,13 @@ class CV_EXPORTS FeaturesFinder ...@@ -61,12 +62,13 @@ class CV_EXPORTS FeaturesFinder
{ {
public: public:
virtual ~FeaturesFinder() {} virtual ~FeaturesFinder() {}
void operator ()(const cv::Mat &image, ImageFeatures &features); void operator ()(const Mat &image, ImageFeatures &features);
virtual void releaseMemory() {} // TODO put it into operator ()
virtual void collectGarbage() {}
protected: protected:
virtual void find(const cv::Mat &image, ImageFeatures &features) = 0; virtual void find(const Mat &image, ImageFeatures &features) = 0;
}; };
...@@ -77,12 +79,12 @@ public: ...@@ -77,12 +79,12 @@ public:
int num_octaves = 3, int num_layers = 4, int num_octaves = 3, int num_layers = 4,
int num_octaves_descr = 4, int num_layers_descr = 2); int num_octaves_descr = 4, int num_layers_descr = 2);
void releaseMemory(); void collectGarbage();
protected: protected:
void find(const cv::Mat &image, ImageFeatures &features); void find(const Mat &image, ImageFeatures &features);
cv::Ptr<FeaturesFinder> impl_; Ptr<FeaturesFinder> impl_;
}; };
...@@ -93,10 +95,10 @@ struct CV_EXPORTS MatchesInfo ...@@ -93,10 +95,10 @@ struct CV_EXPORTS MatchesInfo
const MatchesInfo& operator =(const MatchesInfo &other); const MatchesInfo& operator =(const MatchesInfo &other);
int src_img_idx, dst_img_idx; // Images indices (optional) int src_img_idx, dst_img_idx; // Images indices (optional)
std::vector<cv::DMatch> matches; std::vector<DMatch> matches;
std::vector<uchar> inliers_mask; // Geometrically consistent matches mask std::vector<uchar> inliers_mask; // Geometrically consistent matches mask
int num_inliers; // Number of geometrically consistent matches int num_inliers; // Number of geometrically consistent matches
cv::Mat H; // Estimated homography Mat H; // Estimated homography
double confidence; // Confidence two images are from the same panorama double confidence; // Confidence two images are from the same panorama
}; };
...@@ -112,7 +114,7 @@ public: ...@@ -112,7 +114,7 @@ public:
bool isThreadSafe() const { return is_thread_safe_; } bool isThreadSafe() const { return is_thread_safe_; }
virtual void releaseMemory() {} virtual void collectGarbage() {}
protected: protected:
FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {} FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {}
...@@ -127,17 +129,17 @@ protected: ...@@ -127,17 +129,17 @@ protected:
class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher
{ {
public: public:
BestOf2NearestMatcher(bool try_use_gpu = true, float match_conf = 0.55f, int num_matches_thresh1 = 6, BestOf2NearestMatcher(bool try_use_gpu = true, float match_conf = 0.65f, int num_matches_thresh1 = 6,
int num_matches_thresh2 = 6); int num_matches_thresh2 = 6);
void releaseMemory(); void collectGarbage();
protected: protected:
void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info); void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info);
int num_matches_thresh1_; int num_matches_thresh1_;
int num_matches_thresh2_; int num_matches_thresh2_;
cv::Ptr<FeaturesMatcher> impl_; Ptr<FeaturesMatcher> impl_;
}; };
} // namespace detail } // namespace detail
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__ #ifndef __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
#define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__ #define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_SEAM_FINDERS_HPP__ #ifndef __OPENCV_STITCHING_SEAM_FINDERS_HPP__
#define __OPENCV_STITCHING_SEAM_FINDERS_HPP__ #define __OPENCV_STITCHING_SEAM_FINDERS_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_UTIL_HPP__ #ifndef __OPENCV_STITCHING_UTIL_HPP__
#define __OPENCV_STITCHING_UTIL_HPP__ #define __OPENCV_STITCHING_UTIL_HPP__
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
#define ENABLE_LOG 1 #define ENABLE_LOG 1
// TODO remove LOG macros, add logging class
#if ENABLE_LOG #if ENABLE_LOG
#include <iostream> #include <iostream>
#define LOG(msg) { std::cout << msg; std::cout.flush(); } #define LOG(msg) { std::cout << msg; std::cout.flush(); }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_UTIL_INL_HPP__ #ifndef __OPENCV_STITCHING_UTIL_INL_HPP__
#define __OPENCV_STITCHING_UTIL_INL_HPP__ #define __OPENCV_STITCHING_UTIL_INL_HPP__
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_WARPERS_HPP__ #ifndef __OPENCV_STITCHING_WARPERS_HPP__
#define __OPENCV_STITCHING_WARPERS_HPP__ #define __OPENCV_STITCHING_WARPERS_HPP__
...@@ -55,6 +56,8 @@ class CV_EXPORTS Warper ...@@ -55,6 +56,8 @@ class CV_EXPORTS Warper
{ {
public: public:
enum { PLANE, CYLINDRICAL, SPHERICAL }; enum { PLANE, CYLINDRICAL, SPHERICAL };
// TODO remove this method
static 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 ~Warper() {}
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_WARPERS_INL_HPP__ #ifndef __OPENCV_STITCHING_WARPERS_INL_HPP__
#define __OPENCV_STITCHING_WARPERS_INL_HPP__ #define __OPENCV_STITCHING_WARPERS_INL_HPP__
......
/*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.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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_STITCHER_HPP__
#define __OPENCV_STITCHING_STITCHER_HPP__
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "warpers.hpp"
#include "detail/matchers.hpp"
#include "detail/exposure_compensate.hpp"
#include "detail/seam_finders.hpp"
#include "detail/blenders.hpp"
namespace cv {
class Stitcher
{
public:
enum { ORIG_RESOL = -1 };
enum Status { OK, ERR_NEED_MORE_IMGS };
// Creates stitcher with default parameters
static Stitcher createDefault(bool try_use_gpu = false);
// Stitches the biggest found pano. Returns status code.
Status stitch(InputArray imgs, OutputArray pano);
double registrationResol() const { return registr_resol_; }
void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; }
double seamEstimationResol() const { return seam_est_resol_; }
void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; }
double compositingResol() const { return compose_resol_; }
void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; }
double panoConfidenceThresh() const { return conf_thresh_; }
void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }
bool horizontalStrightening() const { return horiz_stright_; }
void setHorizontalStrightening(bool flag) { horiz_stright_ = flag; }
Ptr<detail::FeaturesFinder> featuresFinder() { return features_finder_; }
const Ptr<detail::FeaturesFinder> featuresFinder() const { return features_finder_; }
void setFeaturesFinder(Ptr<detail::FeaturesFinder> features_finder)
{ features_finder_ = features_finder; }
Ptr<detail::FeaturesMatcher> featuresMatcher() { return features_matcher_; }
const Ptr<detail::FeaturesMatcher> featuresMatcher() const { return features_matcher_; }
void setFeaturesMatcher(Ptr<detail::FeaturesMatcher> features_matcher)
{ features_matcher_ = features_matcher; }
Ptr<WarperCreator> warper() { return warper_; }
const Ptr<WarperCreator> warper() const { return warper_; }
void setWarper(Ptr<WarperCreator> warper) { warper_ = warper; }
Ptr<detail::ExposureCompensator> exposureCompensator() { return exposure_comp_; }
const Ptr<detail::ExposureCompensator> exposureCompensator() const { return exposure_comp_; }
void setExposureCompenstor(Ptr<detail::ExposureCompensator> exposure_comp)
{ exposure_comp_ = exposure_comp; }
Ptr<detail::SeamFinder> seamFinder() { return seam_finder_; }
const Ptr<detail::SeamFinder> seamFinder() const { return seam_finder_; }
void setSeamFinder(Ptr<detail::SeamFinder> seam_finder) { seam_finder_ = seam_finder; }
Ptr<detail::Blender> blender() { return blender_; }
const Ptr<detail::Blender> blender() const { return blender_; }
void setBlender(Ptr<detail::Blender> blender) { blender_ = blender; }
private:
Stitcher() {}
double registr_resol_;
double seam_est_resol_;
double compose_resol_;
double conf_thresh_;
bool horiz_stright_;
Ptr<detail::FeaturesFinder> features_finder_;
Ptr<detail::FeaturesMatcher> features_matcher_;
Ptr<WarperCreator> warper_;
Ptr<detail::ExposureCompensator> exposure_comp_;
Ptr<detail::SeamFinder> seam_finder_;
Ptr<detail::Blender> blender_;
};
} // namespace cv
#endif // __OPENCV_STITCHING_STITCHER_HPP__
/*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.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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_WARPER_CREATORS_HPP__
#define __OPENCV_STITCHING_WARPER_CREATORS_HPP__
#include "detail/warpers.hpp"
namespace cv {
class WarperCreator
{
public:
virtual ~WarperCreator() {}
virtual Ptr<detail::Warper> createByFocalLength(double f) const = 0;
};
class PlaneWarper : public WarperCreator
{
public:
Ptr<detail::Warper> createByFocalLength(double f) const { return new detail::PlaneWarper(f); }
};
class CylindricalWarper: public WarperCreator
{
public:
Ptr<detail::Warper> createByFocalLength(double f) const { return new detail::CylindricalWarper(f); }
};
class SphericalWarper: public WarperCreator
{
public:
Ptr<detail::Warper> createByFocalLength(double f) const { return new detail::SphericalWarper(f); }
};
#ifndef ANDROID
class PlaneWarperGpu: public WarperCreator
{
public:
Ptr<detail::Warper> createByFocalLength(double f) const { return new detail::PlaneWarperGpu(f); }
};
class CylindricalWarperGpu: public WarperCreator
{
public:
Ptr<detail::Warper> createByFocalLength(double f) const { return new detail::CylindricalWarperGpu(f); }
};
class SphericalWarperGpu: public WarperCreator
{
public:
Ptr<detail::Warper> createByFocalLength(double f) const { return new detail::SphericalWarperGpu(f); }
};
#endif
} // namespace cv
#endif // __OPENCV_STITCHING_WARPER_CREATORS_HPP__
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
num_layers_descr_ = num_layers_descr; num_layers_descr_ = num_layers_descr;
} }
void releaseMemory(); void collectGarbage();
protected: protected:
void find(const Mat &image, ImageFeatures &features); void find(const Mat &image, ImageFeatures &features);
...@@ -136,7 +136,7 @@ void GpuSurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) ...@@ -136,7 +136,7 @@ void GpuSurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
descriptors_.download(features.descriptors); descriptors_.download(features.descriptors);
} }
void GpuSurfFeaturesFinder::releaseMemory() void GpuSurfFeaturesFinder::collectGarbage()
{ {
surf_.releaseMemory(); surf_.releaseMemory();
image_.release(); image_.release();
...@@ -231,7 +231,7 @@ public: ...@@ -231,7 +231,7 @@ public:
GpuMatcher(float match_conf) : match_conf_(match_conf) {} GpuMatcher(float match_conf) : match_conf_(match_conf) {}
void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info); void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info);
void releaseMemory(); void collectGarbage();
private: private:
float match_conf_; float match_conf_;
...@@ -326,7 +326,7 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat ...@@ -326,7 +326,7 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
} }
} }
void GpuMatcher::releaseMemory() void GpuMatcher::collectGarbage()
{ {
descriptors1_.release(); descriptors1_.release();
descriptors2_.release(); descriptors2_.release();
...@@ -369,9 +369,9 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) ...@@ -369,9 +369,9 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
} }
void SurfFeaturesFinder::releaseMemory() void SurfFeaturesFinder::collectGarbage()
{ {
impl_->releaseMemory(); impl_->collectGarbage();
} }
...@@ -511,9 +511,9 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea ...@@ -511,9 +511,9 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea
matches_info.H = findHomography(src_points, dst_points, CV_RANSAC); matches_info.H = findHomography(src_points, dst_points, CV_RANSAC);
} }
void BestOf2NearestMatcher::releaseMemory() void BestOf2NearestMatcher::collectGarbage()
{ {
impl_->releaseMemory(); impl_->collectGarbage();
} }
} // namespace detail } // namespace detail
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#ifndef __OPENCV_STITCHING_PRECOMP_H__ #ifndef __OPENCV_STITCHING_PRECOMP_H__
#define __OPENCV_STITCHING_PRECOMP_H__ #define __OPENCV_STITCHING_PRECOMP_H__
...@@ -52,6 +53,8 @@ ...@@ -52,6 +53,8 @@
#include <set> #include <set>
#include <functional> #include <functional>
#include <sstream> #include <sstream>
#include <cmath>
#include "opencv2/stitching/stitcher.hpp"
#include "opencv2/stitching/detail/autocalib.hpp" #include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp" #include "opencv2/stitching/detail/blenders.hpp"
#include "opencv2/stitching/detail/camera.hpp" #include "opencv2/stitching/detail/camera.hpp"
......
This diff is collapsed.
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
using namespace std; using namespace std;
......
This diff is collapsed.
This diff is collapsed.
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