Normalize line endings and whitespace
This commit is contained in:

committed by
Andrey Kamaev

parent
0442bca235
commit
81f826db2b
@@ -1,65 +1,65 @@
|
||||
/*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_AUTOCALIB_HPP__
|
||||
#define __OPENCV_STITCHING_AUTOCALIB_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "matchers.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
// See "Construction of Panoramic Image Mosaics with Global and Local Alignment"
|
||||
// by Heung-Yeung Shum and Richard Szeliski.
|
||||
void CV_EXPORTS focalsFromHomography(const Mat &H, double &f0, double &f1, bool &f0_ok, bool &f1_ok);
|
||||
|
||||
void CV_EXPORTS estimateFocal(const std::vector<ImageFeatures> &features,
|
||||
const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<double> &focals);
|
||||
|
||||
bool CV_EXPORTS calibrateRotatingCamera(const std::vector<Mat> &Hs, Mat &K);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_AUTOCALIB_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_AUTOCALIB_HPP__
|
||||
#define __OPENCV_STITCHING_AUTOCALIB_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "matchers.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
// See "Construction of Panoramic Image Mosaics with Global and Local Alignment"
|
||||
// by Heung-Yeung Shum and Richard Szeliski.
|
||||
void CV_EXPORTS focalsFromHomography(const Mat &H, double &f0, double &f1, bool &f0_ok, bool &f1_ok);
|
||||
|
||||
void CV_EXPORTS estimateFocal(const std::vector<ImageFeatures> &features,
|
||||
const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<double> &focals);
|
||||
|
||||
bool CV_EXPORTS calibrateRotatingCamera(const std::vector<Mat> &Hs, Mat &K);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_AUTOCALIB_HPP__
|
||||
|
@@ -1,137 +1,137 @@
|
||||
/*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_BLENDERS_HPP__
|
||||
#define __OPENCV_STITCHING_BLENDERS_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
|
||||
// Simple blender which puts one image over another
|
||||
class CV_EXPORTS Blender
|
||||
{
|
||||
public:
|
||||
virtual ~Blender() {}
|
||||
|
||||
enum { NO, FEATHER, MULTI_BAND };
|
||||
static Ptr<Blender> createDefault(int type, bool try_gpu = false);
|
||||
|
||||
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:
|
||||
Mat dst_, dst_mask_;
|
||||
Rect dst_roi_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS FeatherBlender : public Blender
|
||||
{
|
||||
public:
|
||||
FeatherBlender(float sharpness = 0.02f);
|
||||
|
||||
float sharpness() const { return sharpness_; }
|
||||
void setSharpness(float val) { sharpness_ = val; }
|
||||
|
||||
void prepare(Rect dst_roi);
|
||||
void feed(const Mat &img, const Mat &mask, Point tl);
|
||||
void blend(Mat &dst, Mat &dst_mask);
|
||||
|
||||
// Creates weight maps for fixed set of source images by their masks and top-left corners.
|
||||
// Final image can be obtained by simple weighting of the source images.
|
||||
Rect createWeightMaps(const std::vector<Mat> &masks, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &weight_maps);
|
||||
|
||||
private:
|
||||
float sharpness_;
|
||||
Mat weight_map_;
|
||||
Mat dst_weight_map_;
|
||||
};
|
||||
|
||||
inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); }
|
||||
|
||||
|
||||
class CV_EXPORTS MultiBandBlender : public Blender
|
||||
{
|
||||
public:
|
||||
MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F);
|
||||
|
||||
int numBands() const { return actual_num_bands_; }
|
||||
void setNumBands(int val) { actual_num_bands_ = val; }
|
||||
|
||||
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<Mat> dst_pyr_laplace_;
|
||||
std::vector<Mat> dst_band_weights_;
|
||||
Rect dst_roi_final_;
|
||||
bool can_use_gpu_;
|
||||
int weight_type_; //CV_32F or CV_16S
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
|
||||
void CV_EXPORTS normalizeUsingWeightMap(const Mat& weight, Mat& src);
|
||||
|
||||
void CV_EXPORTS createWeightMap(const Mat& mask, float sharpness, Mat& weight);
|
||||
|
||||
void CV_EXPORTS createLaplacePyr(const Mat &img, int num_levels, std::vector<Mat>& pyr);
|
||||
void CV_EXPORTS createLaplacePyrGpu(const Mat &img, int num_levels, std::vector<Mat>& pyr);
|
||||
|
||||
// Restores source image
|
||||
void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<Mat>& pyr);
|
||||
void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<Mat>& pyr);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_BLENDERS_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_BLENDERS_HPP__
|
||||
#define __OPENCV_STITCHING_BLENDERS_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
|
||||
// Simple blender which puts one image over another
|
||||
class CV_EXPORTS Blender
|
||||
{
|
||||
public:
|
||||
virtual ~Blender() {}
|
||||
|
||||
enum { NO, FEATHER, MULTI_BAND };
|
||||
static Ptr<Blender> createDefault(int type, bool try_gpu = false);
|
||||
|
||||
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:
|
||||
Mat dst_, dst_mask_;
|
||||
Rect dst_roi_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS FeatherBlender : public Blender
|
||||
{
|
||||
public:
|
||||
FeatherBlender(float sharpness = 0.02f);
|
||||
|
||||
float sharpness() const { return sharpness_; }
|
||||
void setSharpness(float val) { sharpness_ = val; }
|
||||
|
||||
void prepare(Rect dst_roi);
|
||||
void feed(const Mat &img, const Mat &mask, Point tl);
|
||||
void blend(Mat &dst, Mat &dst_mask);
|
||||
|
||||
// Creates weight maps for fixed set of source images by their masks and top-left corners.
|
||||
// Final image can be obtained by simple weighting of the source images.
|
||||
Rect createWeightMaps(const std::vector<Mat> &masks, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &weight_maps);
|
||||
|
||||
private:
|
||||
float sharpness_;
|
||||
Mat weight_map_;
|
||||
Mat dst_weight_map_;
|
||||
};
|
||||
|
||||
inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); }
|
||||
|
||||
|
||||
class CV_EXPORTS MultiBandBlender : public Blender
|
||||
{
|
||||
public:
|
||||
MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F);
|
||||
|
||||
int numBands() const { return actual_num_bands_; }
|
||||
void setNumBands(int val) { actual_num_bands_ = val; }
|
||||
|
||||
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<Mat> dst_pyr_laplace_;
|
||||
std::vector<Mat> dst_band_weights_;
|
||||
Rect dst_roi_final_;
|
||||
bool can_use_gpu_;
|
||||
int weight_type_; //CV_32F or CV_16S
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
|
||||
void CV_EXPORTS normalizeUsingWeightMap(const Mat& weight, Mat& src);
|
||||
|
||||
void CV_EXPORTS createWeightMap(const Mat& mask, float sharpness, Mat& weight);
|
||||
|
||||
void CV_EXPORTS createLaplacePyr(const Mat &img, int num_levels, std::vector<Mat>& pyr);
|
||||
void CV_EXPORTS createLaplacePyrGpu(const Mat &img, int num_levels, std::vector<Mat>& pyr);
|
||||
|
||||
// Restores source image
|
||||
void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<Mat>& pyr);
|
||||
void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<Mat>& pyr);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_BLENDERS_HPP__
|
||||
|
@@ -1,106 +1,106 @@
|
||||
/*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_EXPOSURE_COMPENSATE_HPP__
|
||||
#define __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS ExposureCompensator
|
||||
{
|
||||
public:
|
||||
virtual ~ExposureCompensator() {}
|
||||
|
||||
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 CV_EXPORTS 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 CV_EXPORTS 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 CV_EXPORTS 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 detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_EXPOSURE_COMPENSATE_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_EXPOSURE_COMPENSATE_HPP__
|
||||
#define __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS ExposureCompensator
|
||||
{
|
||||
public:
|
||||
virtual ~ExposureCompensator() {}
|
||||
|
||||
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 CV_EXPORTS 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 CV_EXPORTS 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 CV_EXPORTS 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 detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__
|
||||
|
@@ -1,188 +1,188 @@
|
||||
/*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_MATCHERS_HPP__
|
||||
#define __OPENCV_STITCHING_MATCHERS_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#endif
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
struct CV_EXPORTS ImageFeatures
|
||||
{
|
||||
int img_idx;
|
||||
Size img_size;
|
||||
std::vector<KeyPoint> keypoints;
|
||||
Mat descriptors;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS FeaturesFinder
|
||||
{
|
||||
public:
|
||||
virtual ~FeaturesFinder() {}
|
||||
void operator ()(const Mat &image, ImageFeatures &features);
|
||||
void operator ()(const Mat &image, ImageFeatures &features, const std::vector<cv::Rect> &rois);
|
||||
virtual void collectGarbage() {}
|
||||
|
||||
protected:
|
||||
virtual void find(const Mat &image, ImageFeatures &features) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder
|
||||
{
|
||||
public:
|
||||
SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
|
||||
int num_octaves_descr = /*4*/3, int num_layers_descr = /*2*/4);
|
||||
|
||||
private:
|
||||
void find(const Mat &image, ImageFeatures &features);
|
||||
|
||||
Ptr<FeatureDetector> detector_;
|
||||
Ptr<DescriptorExtractor> extractor_;
|
||||
Ptr<Feature2D> surf;
|
||||
};
|
||||
|
||||
class CV_EXPORTS OrbFeaturesFinder : public FeaturesFinder
|
||||
{
|
||||
public:
|
||||
OrbFeaturesFinder(Size _grid_size = Size(3,1), int nfeatures=1500, float scaleFactor=1.3f, int nlevels=5);
|
||||
|
||||
private:
|
||||
void find(const Mat &image, ImageFeatures &features);
|
||||
|
||||
Ptr<ORB> orb;
|
||||
Size grid_size;
|
||||
};
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder
|
||||
{
|
||||
public:
|
||||
SurfFeaturesFinderGpu(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
|
||||
int num_octaves_descr = 4, int num_layers_descr = 2);
|
||||
|
||||
void collectGarbage();
|
||||
|
||||
private:
|
||||
void find(const Mat &image, ImageFeatures &features);
|
||||
|
||||
gpu::GpuMat image_;
|
||||
gpu::GpuMat gray_image_;
|
||||
gpu::SURF_GPU surf_;
|
||||
gpu::GpuMat keypoints_;
|
||||
gpu::GpuMat descriptors_;
|
||||
int num_octaves_, num_layers_;
|
||||
int num_octaves_descr_, num_layers_descr_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
struct CV_EXPORTS MatchesInfo
|
||||
{
|
||||
MatchesInfo();
|
||||
MatchesInfo(const MatchesInfo &other);
|
||||
const MatchesInfo& operator =(const MatchesInfo &other);
|
||||
|
||||
int src_img_idx, dst_img_idx; // Images indices (optional)
|
||||
std::vector<DMatch> matches;
|
||||
std::vector<uchar> inliers_mask; // Geometrically consistent matches mask
|
||||
int num_inliers; // Number of geometrically consistent matches
|
||||
Mat H; // Estimated homography
|
||||
double confidence; // Confidence two images are from the same panorama
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS FeaturesMatcher
|
||||
{
|
||||
public:
|
||||
virtual ~FeaturesMatcher() {}
|
||||
|
||||
void operator ()(const ImageFeatures &features1, const ImageFeatures &features2,
|
||||
MatchesInfo& matches_info) { match(features1, features2, matches_info); }
|
||||
|
||||
void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
|
||||
const cv::Mat &mask = cv::Mat());
|
||||
|
||||
bool isThreadSafe() const { return is_thread_safe_; }
|
||||
|
||||
virtual void collectGarbage() {}
|
||||
|
||||
protected:
|
||||
FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {}
|
||||
|
||||
virtual void match(const ImageFeatures &features1, const ImageFeatures &features2,
|
||||
MatchesInfo& matches_info) = 0;
|
||||
|
||||
bool is_thread_safe_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher
|
||||
{
|
||||
public:
|
||||
BestOf2NearestMatcher(bool try_use_gpu = false, float match_conf = 0.3f, int num_matches_thresh1 = 6,
|
||||
int num_matches_thresh2 = 6);
|
||||
|
||||
void collectGarbage();
|
||||
|
||||
protected:
|
||||
void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info);
|
||||
|
||||
int num_matches_thresh1_;
|
||||
int num_matches_thresh2_;
|
||||
Ptr<FeaturesMatcher> impl_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_MATCHERS_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_MATCHERS_HPP__
|
||||
#define __OPENCV_STITCHING_MATCHERS_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#endif
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
struct CV_EXPORTS ImageFeatures
|
||||
{
|
||||
int img_idx;
|
||||
Size img_size;
|
||||
std::vector<KeyPoint> keypoints;
|
||||
Mat descriptors;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS FeaturesFinder
|
||||
{
|
||||
public:
|
||||
virtual ~FeaturesFinder() {}
|
||||
void operator ()(const Mat &image, ImageFeatures &features);
|
||||
void operator ()(const Mat &image, ImageFeatures &features, const std::vector<cv::Rect> &rois);
|
||||
virtual void collectGarbage() {}
|
||||
|
||||
protected:
|
||||
virtual void find(const Mat &image, ImageFeatures &features) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder
|
||||
{
|
||||
public:
|
||||
SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
|
||||
int num_octaves_descr = /*4*/3, int num_layers_descr = /*2*/4);
|
||||
|
||||
private:
|
||||
void find(const Mat &image, ImageFeatures &features);
|
||||
|
||||
Ptr<FeatureDetector> detector_;
|
||||
Ptr<DescriptorExtractor> extractor_;
|
||||
Ptr<Feature2D> surf;
|
||||
};
|
||||
|
||||
class CV_EXPORTS OrbFeaturesFinder : public FeaturesFinder
|
||||
{
|
||||
public:
|
||||
OrbFeaturesFinder(Size _grid_size = Size(3,1), int nfeatures=1500, float scaleFactor=1.3f, int nlevels=5);
|
||||
|
||||
private:
|
||||
void find(const Mat &image, ImageFeatures &features);
|
||||
|
||||
Ptr<ORB> orb;
|
||||
Size grid_size;
|
||||
};
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder
|
||||
{
|
||||
public:
|
||||
SurfFeaturesFinderGpu(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
|
||||
int num_octaves_descr = 4, int num_layers_descr = 2);
|
||||
|
||||
void collectGarbage();
|
||||
|
||||
private:
|
||||
void find(const Mat &image, ImageFeatures &features);
|
||||
|
||||
gpu::GpuMat image_;
|
||||
gpu::GpuMat gray_image_;
|
||||
gpu::SURF_GPU surf_;
|
||||
gpu::GpuMat keypoints_;
|
||||
gpu::GpuMat descriptors_;
|
||||
int num_octaves_, num_layers_;
|
||||
int num_octaves_descr_, num_layers_descr_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
struct CV_EXPORTS MatchesInfo
|
||||
{
|
||||
MatchesInfo();
|
||||
MatchesInfo(const MatchesInfo &other);
|
||||
const MatchesInfo& operator =(const MatchesInfo &other);
|
||||
|
||||
int src_img_idx, dst_img_idx; // Images indices (optional)
|
||||
std::vector<DMatch> matches;
|
||||
std::vector<uchar> inliers_mask; // Geometrically consistent matches mask
|
||||
int num_inliers; // Number of geometrically consistent matches
|
||||
Mat H; // Estimated homography
|
||||
double confidence; // Confidence two images are from the same panorama
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS FeaturesMatcher
|
||||
{
|
||||
public:
|
||||
virtual ~FeaturesMatcher() {}
|
||||
|
||||
void operator ()(const ImageFeatures &features1, const ImageFeatures &features2,
|
||||
MatchesInfo& matches_info) { match(features1, features2, matches_info); }
|
||||
|
||||
void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
|
||||
const cv::Mat &mask = cv::Mat());
|
||||
|
||||
bool isThreadSafe() const { return is_thread_safe_; }
|
||||
|
||||
virtual void collectGarbage() {}
|
||||
|
||||
protected:
|
||||
FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {}
|
||||
|
||||
virtual void match(const ImageFeatures &features1, const ImageFeatures &features2,
|
||||
MatchesInfo& matches_info) = 0;
|
||||
|
||||
bool is_thread_safe_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher
|
||||
{
|
||||
public:
|
||||
BestOf2NearestMatcher(bool try_use_gpu = false, float match_conf = 0.3f, int num_matches_thresh1 = 6,
|
||||
int num_matches_thresh2 = 6);
|
||||
|
||||
void collectGarbage();
|
||||
|
||||
protected:
|
||||
void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info);
|
||||
|
||||
int num_matches_thresh1_;
|
||||
int num_matches_thresh2_;
|
||||
Ptr<FeaturesMatcher> impl_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_MATCHERS_HPP__
|
||||
|
@@ -1,205 +1,205 @@
|
||||
/*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_MOTION_ESTIMATORS_HPP__
|
||||
#define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "matchers.hpp"
|
||||
#include "util.hpp"
|
||||
#include "camera.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS Estimator
|
||||
{
|
||||
public:
|
||||
virtual ~Estimator() {}
|
||||
|
||||
void operator ()(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras)
|
||||
{ estimate(features, pairwise_matches, cameras); }
|
||||
|
||||
protected:
|
||||
virtual void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS HomographyBasedEstimator : public Estimator
|
||||
{
|
||||
public:
|
||||
HomographyBasedEstimator(bool is_focals_estimated = false)
|
||||
: is_focals_estimated_(is_focals_estimated) {}
|
||||
|
||||
private:
|
||||
void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras);
|
||||
|
||||
bool is_focals_estimated_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS BundleAdjusterBase : public Estimator
|
||||
{
|
||||
public:
|
||||
const Mat refinementMask() const { return refinement_mask_.clone(); }
|
||||
void setRefinementMask(const Mat &mask)
|
||||
{
|
||||
CV_Assert(mask.type() == CV_8U && mask.size() == Size(3, 3));
|
||||
refinement_mask_ = mask.clone();
|
||||
}
|
||||
|
||||
double confThresh() const { return conf_thresh_; }
|
||||
void setConfThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }
|
||||
|
||||
CvTermCriteria termCriteria() { return term_criteria_; }
|
||||
void setTermCriteria(const CvTermCriteria& term_criteria) { term_criteria_ = term_criteria; }
|
||||
|
||||
protected:
|
||||
BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement)
|
||||
: num_params_per_cam_(num_params_per_cam),
|
||||
num_errs_per_measurement_(num_errs_per_measurement)
|
||||
{
|
||||
setRefinementMask(Mat::ones(3, 3, CV_8U));
|
||||
setConfThresh(1.);
|
||||
setTermCriteria(cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 1000, DBL_EPSILON));
|
||||
}
|
||||
|
||||
// Runs bundle adjustment
|
||||
virtual void estimate(const std::vector<ImageFeatures> &features,
|
||||
const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras);
|
||||
|
||||
virtual void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) = 0;
|
||||
virtual void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const = 0;
|
||||
virtual void calcError(Mat &err) = 0;
|
||||
virtual void calcJacobian(Mat &jac) = 0;
|
||||
|
||||
// 3x3 8U mask, where 0 means don't refine respective parameter, != 0 means refine
|
||||
Mat refinement_mask_;
|
||||
|
||||
int num_images_;
|
||||
int total_num_matches_;
|
||||
|
||||
int num_params_per_cam_;
|
||||
int num_errs_per_measurement_;
|
||||
|
||||
const ImageFeatures *features_;
|
||||
const MatchesInfo *pairwise_matches_;
|
||||
|
||||
// Threshold to filter out poorly matched image pairs
|
||||
double conf_thresh_;
|
||||
|
||||
//Levenberg–Marquardt algorithm termination criteria
|
||||
CvTermCriteria term_criteria_;
|
||||
|
||||
// Camera parameters matrix (CV_64F)
|
||||
Mat cam_params_;
|
||||
|
||||
// Connected images pairs
|
||||
std::vector<std::pair<int,int> > edges_;
|
||||
};
|
||||
|
||||
|
||||
// Minimizes reprojection error.
|
||||
// It can estimate focal length, aspect ratio, principal point.
|
||||
// You can affect only on them via the refinement mask.
|
||||
class CV_EXPORTS BundleAdjusterReproj : public BundleAdjusterBase
|
||||
{
|
||||
public:
|
||||
BundleAdjusterReproj() : BundleAdjusterBase(7, 2) {}
|
||||
|
||||
private:
|
||||
void setUpInitialCameraParams(const std::vector<CameraParams> &cameras);
|
||||
void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const;
|
||||
void calcError(Mat &err);
|
||||
void calcJacobian(Mat &jac);
|
||||
|
||||
Mat err1_, err2_;
|
||||
};
|
||||
|
||||
|
||||
// Minimizes sun of ray-to-ray distances.
|
||||
// It can estimate focal length. It ignores the refinement mask for now.
|
||||
class CV_EXPORTS BundleAdjusterRay : public BundleAdjusterBase
|
||||
{
|
||||
public:
|
||||
BundleAdjusterRay() : BundleAdjusterBase(4, 3) {}
|
||||
|
||||
private:
|
||||
void setUpInitialCameraParams(const std::vector<CameraParams> &cameras);
|
||||
void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const;
|
||||
void calcError(Mat &err);
|
||||
void calcJacobian(Mat &jac);
|
||||
|
||||
Mat err1_, err2_;
|
||||
};
|
||||
|
||||
|
||||
enum WaveCorrectKind
|
||||
{
|
||||
WAVE_CORRECT_HORIZ,
|
||||
WAVE_CORRECT_VERT
|
||||
};
|
||||
|
||||
void CV_EXPORTS waveCorrect(std::vector<Mat> &rmats, WaveCorrectKind kind);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
|
||||
// Returns matches graph representation in DOT language
|
||||
std::string CV_EXPORTS matchesGraphAsString(std::vector<std::string> &pathes, std::vector<MatchesInfo> &pairwise_matches,
|
||||
float conf_threshold);
|
||||
|
||||
std::vector<int> CV_EXPORTS leaveBiggestComponent(std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
|
||||
float conf_threshold);
|
||||
|
||||
void CV_EXPORTS findMaxSpanningTree(int num_images, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
Graph &span_tree, std::vector<int> ¢ers);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_MOTION_ESTIMATORS_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_MOTION_ESTIMATORS_HPP__
|
||||
#define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "matchers.hpp"
|
||||
#include "util.hpp"
|
||||
#include "camera.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS Estimator
|
||||
{
|
||||
public:
|
||||
virtual ~Estimator() {}
|
||||
|
||||
void operator ()(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras)
|
||||
{ estimate(features, pairwise_matches, cameras); }
|
||||
|
||||
protected:
|
||||
virtual void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS HomographyBasedEstimator : public Estimator
|
||||
{
|
||||
public:
|
||||
HomographyBasedEstimator(bool is_focals_estimated = false)
|
||||
: is_focals_estimated_(is_focals_estimated) {}
|
||||
|
||||
private:
|
||||
void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras);
|
||||
|
||||
bool is_focals_estimated_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS BundleAdjusterBase : public Estimator
|
||||
{
|
||||
public:
|
||||
const Mat refinementMask() const { return refinement_mask_.clone(); }
|
||||
void setRefinementMask(const Mat &mask)
|
||||
{
|
||||
CV_Assert(mask.type() == CV_8U && mask.size() == Size(3, 3));
|
||||
refinement_mask_ = mask.clone();
|
||||
}
|
||||
|
||||
double confThresh() const { return conf_thresh_; }
|
||||
void setConfThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }
|
||||
|
||||
CvTermCriteria termCriteria() { return term_criteria_; }
|
||||
void setTermCriteria(const CvTermCriteria& term_criteria) { term_criteria_ = term_criteria; }
|
||||
|
||||
protected:
|
||||
BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement)
|
||||
: num_params_per_cam_(num_params_per_cam),
|
||||
num_errs_per_measurement_(num_errs_per_measurement)
|
||||
{
|
||||
setRefinementMask(Mat::ones(3, 3, CV_8U));
|
||||
setConfThresh(1.);
|
||||
setTermCriteria(cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 1000, DBL_EPSILON));
|
||||
}
|
||||
|
||||
// Runs bundle adjustment
|
||||
virtual void estimate(const std::vector<ImageFeatures> &features,
|
||||
const std::vector<MatchesInfo> &pairwise_matches,
|
||||
std::vector<CameraParams> &cameras);
|
||||
|
||||
virtual void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) = 0;
|
||||
virtual void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const = 0;
|
||||
virtual void calcError(Mat &err) = 0;
|
||||
virtual void calcJacobian(Mat &jac) = 0;
|
||||
|
||||
// 3x3 8U mask, where 0 means don't refine respective parameter, != 0 means refine
|
||||
Mat refinement_mask_;
|
||||
|
||||
int num_images_;
|
||||
int total_num_matches_;
|
||||
|
||||
int num_params_per_cam_;
|
||||
int num_errs_per_measurement_;
|
||||
|
||||
const ImageFeatures *features_;
|
||||
const MatchesInfo *pairwise_matches_;
|
||||
|
||||
// Threshold to filter out poorly matched image pairs
|
||||
double conf_thresh_;
|
||||
|
||||
//Levenberg–Marquardt algorithm termination criteria
|
||||
CvTermCriteria term_criteria_;
|
||||
|
||||
// Camera parameters matrix (CV_64F)
|
||||
Mat cam_params_;
|
||||
|
||||
// Connected images pairs
|
||||
std::vector<std::pair<int,int> > edges_;
|
||||
};
|
||||
|
||||
|
||||
// Minimizes reprojection error.
|
||||
// It can estimate focal length, aspect ratio, principal point.
|
||||
// You can affect only on them via the refinement mask.
|
||||
class CV_EXPORTS BundleAdjusterReproj : public BundleAdjusterBase
|
||||
{
|
||||
public:
|
||||
BundleAdjusterReproj() : BundleAdjusterBase(7, 2) {}
|
||||
|
||||
private:
|
||||
void setUpInitialCameraParams(const std::vector<CameraParams> &cameras);
|
||||
void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const;
|
||||
void calcError(Mat &err);
|
||||
void calcJacobian(Mat &jac);
|
||||
|
||||
Mat err1_, err2_;
|
||||
};
|
||||
|
||||
|
||||
// Minimizes sun of ray-to-ray distances.
|
||||
// It can estimate focal length. It ignores the refinement mask for now.
|
||||
class CV_EXPORTS BundleAdjusterRay : public BundleAdjusterBase
|
||||
{
|
||||
public:
|
||||
BundleAdjusterRay() : BundleAdjusterBase(4, 3) {}
|
||||
|
||||
private:
|
||||
void setUpInitialCameraParams(const std::vector<CameraParams> &cameras);
|
||||
void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const;
|
||||
void calcError(Mat &err);
|
||||
void calcJacobian(Mat &jac);
|
||||
|
||||
Mat err1_, err2_;
|
||||
};
|
||||
|
||||
|
||||
enum WaveCorrectKind
|
||||
{
|
||||
WAVE_CORRECT_HORIZ,
|
||||
WAVE_CORRECT_VERT
|
||||
};
|
||||
|
||||
void CV_EXPORTS waveCorrect(std::vector<Mat> &rmats, WaveCorrectKind kind);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
|
||||
// Returns matches graph representation in DOT language
|
||||
std::string CV_EXPORTS matchesGraphAsString(std::vector<std::string> &pathes, std::vector<MatchesInfo> &pairwise_matches,
|
||||
float conf_threshold);
|
||||
|
||||
std::vector<int> CV_EXPORTS leaveBiggestComponent(std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
|
||||
float conf_threshold);
|
||||
|
||||
void CV_EXPORTS findMaxSpanningTree(int num_images, const std::vector<MatchesInfo> &pairwise_matches,
|
||||
Graph &span_tree, std::vector<int> ¢ers);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
|
||||
|
@@ -1,259 +1,259 @@
|
||||
/*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_SEAM_FINDERS_HPP__
|
||||
#define __OPENCV_STITCHING_SEAM_FINDERS_HPP__
|
||||
|
||||
#include <set>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS SeamFinder
|
||||
{
|
||||
public:
|
||||
virtual ~SeamFinder() {}
|
||||
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS NoSeamFinder : public SeamFinder
|
||||
{
|
||||
public:
|
||||
void find(const std::vector<Mat>&, const std::vector<Point>&, std::vector<Mat>&) {}
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS PairwiseSeamFinder : public SeamFinder
|
||||
{
|
||||
public:
|
||||
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
|
||||
protected:
|
||||
void run();
|
||||
virtual void findInPair(size_t first, size_t second, Rect roi) = 0;
|
||||
|
||||
std::vector<Mat> images_;
|
||||
std::vector<Size> sizes_;
|
||||
std::vector<Point> corners_;
|
||||
std::vector<Mat> masks_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS VoronoiSeamFinder : public PairwiseSeamFinder
|
||||
{
|
||||
public:
|
||||
virtual void find(const std::vector<Size> &size, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
private:
|
||||
void findInPair(size_t first, size_t second, Rect roi);
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS DpSeamFinder : public SeamFinder
|
||||
{
|
||||
public:
|
||||
enum CostFunction { COLOR, COLOR_GRAD };
|
||||
|
||||
DpSeamFinder(CostFunction costFunc = COLOR);
|
||||
|
||||
CostFunction costFunction() const { return costFunc_; }
|
||||
void setCostFunction(CostFunction val) { costFunc_ = val; }
|
||||
|
||||
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
|
||||
private:
|
||||
enum ComponentState
|
||||
{
|
||||
FIRST = 1, SECOND = 2, INTERS = 4,
|
||||
INTERS_FIRST = INTERS | FIRST,
|
||||
INTERS_SECOND = INTERS | SECOND
|
||||
};
|
||||
|
||||
class ImagePairLess
|
||||
{
|
||||
public:
|
||||
ImagePairLess(const std::vector<Mat> &images, const std::vector<Point> &corners)
|
||||
: src_(&images[0]), corners_(&corners[0]) {}
|
||||
|
||||
bool operator() (const std::pair<size_t, size_t> &l, const std::pair<size_t, size_t> &r) const
|
||||
{
|
||||
Point c1 = corners_[l.first] + Point(src_[l.first].cols / 2, src_[l.first].rows / 2);
|
||||
Point c2 = corners_[l.second] + Point(src_[l.second].cols / 2, src_[l.second].rows / 2);
|
||||
int d1 = (c1 - c2).dot(c1 - c2);
|
||||
|
||||
c1 = corners_[r.first] + Point(src_[r.first].cols / 2, src_[r.first].rows / 2);
|
||||
c2 = corners_[r.second] + Point(src_[r.second].cols / 2, src_[r.second].rows / 2);
|
||||
int d2 = (c1 - c2).dot(c1 - c2);
|
||||
|
||||
return d1 < d2;
|
||||
}
|
||||
|
||||
private:
|
||||
const Mat *src_;
|
||||
const Point *corners_;
|
||||
};
|
||||
|
||||
class ClosePoints
|
||||
{
|
||||
public:
|
||||
ClosePoints(int minDist) : minDist_(minDist) {}
|
||||
|
||||
bool operator() (const Point &p1, const Point &p2) const
|
||||
{
|
||||
int dist2 = (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y);
|
||||
return dist2 < minDist_ * minDist_;
|
||||
}
|
||||
|
||||
private:
|
||||
int minDist_;
|
||||
};
|
||||
|
||||
void process(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2, Mat &mask1, Mat &mask2);
|
||||
|
||||
void findComponents();
|
||||
|
||||
void findEdges();
|
||||
|
||||
void resolveConflicts(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2, Mat &mask1, Mat &mask2);
|
||||
|
||||
void computeGradients(const Mat &image1, const Mat &image2);
|
||||
|
||||
bool hasOnlyOneNeighbor(int comp);
|
||||
|
||||
bool closeToContour(int y, int x, const Mat_<uchar> &contourMask);
|
||||
|
||||
bool getSeamTips(int comp1, int comp2, Point &p1, Point &p2);
|
||||
|
||||
void computeCosts(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2,
|
||||
int comp, Mat_<float> &costV, Mat_<float> &costH);
|
||||
|
||||
bool estimateSeam(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2, int comp,
|
||||
Point p1, Point p2, std::vector<Point> &seam, bool &isHorizontal);
|
||||
|
||||
void updateLabelsUsingSeam(
|
||||
int comp1, int comp2, const std::vector<Point> &seam, bool isHorizontalSeam);
|
||||
|
||||
CostFunction costFunc_;
|
||||
|
||||
// processing images pair data
|
||||
Point unionTl_, unionBr_;
|
||||
Size unionSize_;
|
||||
Mat_<uchar> mask1_, mask2_;
|
||||
Mat_<uchar> contour1mask_, contour2mask_;
|
||||
Mat_<float> gradx1_, grady1_;
|
||||
Mat_<float> gradx2_, grady2_;
|
||||
|
||||
// components data
|
||||
int ncomps_;
|
||||
Mat_<int> labels_;
|
||||
std::vector<ComponentState> states_;
|
||||
std::vector<Point> tls_, brs_;
|
||||
std::vector<std::vector<Point> > contours_;
|
||||
std::set<std::pair<int, int> > edges_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS GraphCutSeamFinderBase
|
||||
{
|
||||
public:
|
||||
enum { COST_COLOR, COST_COLOR_GRAD };
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS GraphCutSeamFinder : public GraphCutSeamFinderBase, public SeamFinder
|
||||
{
|
||||
public:
|
||||
GraphCutSeamFinder(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,
|
||||
float bad_region_penalty = 1000.f);
|
||||
|
||||
~GraphCutSeamFinder();
|
||||
|
||||
void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
|
||||
private:
|
||||
// To avoid GCGraph dependency
|
||||
class Impl;
|
||||
Ptr<PairwiseSeamFinder> impl_;
|
||||
};
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder
|
||||
{
|
||||
public:
|
||||
GraphCutSeamFinderGpu(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,
|
||||
float bad_region_penalty = 1000.f)
|
||||
: cost_type_(cost_type), terminal_cost_(terminal_cost),
|
||||
bad_region_penalty_(bad_region_penalty) {}
|
||||
|
||||
void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
||||
std::vector<cv::Mat> &masks);
|
||||
void findInPair(size_t first, size_t second, Rect roi);
|
||||
|
||||
private:
|
||||
void setGraphWeightsColor(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &mask1, const cv::Mat &mask2,
|
||||
cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom);
|
||||
void setGraphWeightsColorGrad(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &dx1, const cv::Mat &dx2,
|
||||
const cv::Mat &dy1, const cv::Mat &dy2, const cv::Mat &mask1, const cv::Mat &mask2,
|
||||
cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom);
|
||||
std::vector<Mat> dx_, dy_;
|
||||
int cost_type_;
|
||||
float terminal_cost_;
|
||||
float bad_region_penalty_;
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_SEAM_FINDERS_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_SEAM_FINDERS_HPP__
|
||||
#define __OPENCV_STITCHING_SEAM_FINDERS_HPP__
|
||||
|
||||
#include <set>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS SeamFinder
|
||||
{
|
||||
public:
|
||||
virtual ~SeamFinder() {}
|
||||
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS NoSeamFinder : public SeamFinder
|
||||
{
|
||||
public:
|
||||
void find(const std::vector<Mat>&, const std::vector<Point>&, std::vector<Mat>&) {}
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS PairwiseSeamFinder : public SeamFinder
|
||||
{
|
||||
public:
|
||||
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
|
||||
protected:
|
||||
void run();
|
||||
virtual void findInPair(size_t first, size_t second, Rect roi) = 0;
|
||||
|
||||
std::vector<Mat> images_;
|
||||
std::vector<Size> sizes_;
|
||||
std::vector<Point> corners_;
|
||||
std::vector<Mat> masks_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS VoronoiSeamFinder : public PairwiseSeamFinder
|
||||
{
|
||||
public:
|
||||
virtual void find(const std::vector<Size> &size, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
private:
|
||||
void findInPair(size_t first, size_t second, Rect roi);
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS DpSeamFinder : public SeamFinder
|
||||
{
|
||||
public:
|
||||
enum CostFunction { COLOR, COLOR_GRAD };
|
||||
|
||||
DpSeamFinder(CostFunction costFunc = COLOR);
|
||||
|
||||
CostFunction costFunction() const { return costFunc_; }
|
||||
void setCostFunction(CostFunction val) { costFunc_ = val; }
|
||||
|
||||
virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
|
||||
private:
|
||||
enum ComponentState
|
||||
{
|
||||
FIRST = 1, SECOND = 2, INTERS = 4,
|
||||
INTERS_FIRST = INTERS | FIRST,
|
||||
INTERS_SECOND = INTERS | SECOND
|
||||
};
|
||||
|
||||
class ImagePairLess
|
||||
{
|
||||
public:
|
||||
ImagePairLess(const std::vector<Mat> &images, const std::vector<Point> &corners)
|
||||
: src_(&images[0]), corners_(&corners[0]) {}
|
||||
|
||||
bool operator() (const std::pair<size_t, size_t> &l, const std::pair<size_t, size_t> &r) const
|
||||
{
|
||||
Point c1 = corners_[l.first] + Point(src_[l.first].cols / 2, src_[l.first].rows / 2);
|
||||
Point c2 = corners_[l.second] + Point(src_[l.second].cols / 2, src_[l.second].rows / 2);
|
||||
int d1 = (c1 - c2).dot(c1 - c2);
|
||||
|
||||
c1 = corners_[r.first] + Point(src_[r.first].cols / 2, src_[r.first].rows / 2);
|
||||
c2 = corners_[r.second] + Point(src_[r.second].cols / 2, src_[r.second].rows / 2);
|
||||
int d2 = (c1 - c2).dot(c1 - c2);
|
||||
|
||||
return d1 < d2;
|
||||
}
|
||||
|
||||
private:
|
||||
const Mat *src_;
|
||||
const Point *corners_;
|
||||
};
|
||||
|
||||
class ClosePoints
|
||||
{
|
||||
public:
|
||||
ClosePoints(int minDist) : minDist_(minDist) {}
|
||||
|
||||
bool operator() (const Point &p1, const Point &p2) const
|
||||
{
|
||||
int dist2 = (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y);
|
||||
return dist2 < minDist_ * minDist_;
|
||||
}
|
||||
|
||||
private:
|
||||
int minDist_;
|
||||
};
|
||||
|
||||
void process(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2, Mat &mask1, Mat &mask2);
|
||||
|
||||
void findComponents();
|
||||
|
||||
void findEdges();
|
||||
|
||||
void resolveConflicts(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2, Mat &mask1, Mat &mask2);
|
||||
|
||||
void computeGradients(const Mat &image1, const Mat &image2);
|
||||
|
||||
bool hasOnlyOneNeighbor(int comp);
|
||||
|
||||
bool closeToContour(int y, int x, const Mat_<uchar> &contourMask);
|
||||
|
||||
bool getSeamTips(int comp1, int comp2, Point &p1, Point &p2);
|
||||
|
||||
void computeCosts(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2,
|
||||
int comp, Mat_<float> &costV, Mat_<float> &costH);
|
||||
|
||||
bool estimateSeam(
|
||||
const Mat &image1, const Mat &image2, Point tl1, Point tl2, int comp,
|
||||
Point p1, Point p2, std::vector<Point> &seam, bool &isHorizontal);
|
||||
|
||||
void updateLabelsUsingSeam(
|
||||
int comp1, int comp2, const std::vector<Point> &seam, bool isHorizontalSeam);
|
||||
|
||||
CostFunction costFunc_;
|
||||
|
||||
// processing images pair data
|
||||
Point unionTl_, unionBr_;
|
||||
Size unionSize_;
|
||||
Mat_<uchar> mask1_, mask2_;
|
||||
Mat_<uchar> contour1mask_, contour2mask_;
|
||||
Mat_<float> gradx1_, grady1_;
|
||||
Mat_<float> gradx2_, grady2_;
|
||||
|
||||
// components data
|
||||
int ncomps_;
|
||||
Mat_<int> labels_;
|
||||
std::vector<ComponentState> states_;
|
||||
std::vector<Point> tls_, brs_;
|
||||
std::vector<std::vector<Point> > contours_;
|
||||
std::set<std::pair<int, int> > edges_;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS GraphCutSeamFinderBase
|
||||
{
|
||||
public:
|
||||
enum { COST_COLOR, COST_COLOR_GRAD };
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS GraphCutSeamFinder : public GraphCutSeamFinderBase, public SeamFinder
|
||||
{
|
||||
public:
|
||||
GraphCutSeamFinder(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,
|
||||
float bad_region_penalty = 1000.f);
|
||||
|
||||
~GraphCutSeamFinder();
|
||||
|
||||
void find(const std::vector<Mat> &src, const std::vector<Point> &corners,
|
||||
std::vector<Mat> &masks);
|
||||
|
||||
private:
|
||||
// To avoid GCGraph dependency
|
||||
class Impl;
|
||||
Ptr<PairwiseSeamFinder> impl_;
|
||||
};
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder
|
||||
{
|
||||
public:
|
||||
GraphCutSeamFinderGpu(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,
|
||||
float bad_region_penalty = 1000.f)
|
||||
: cost_type_(cost_type), terminal_cost_(terminal_cost),
|
||||
bad_region_penalty_(bad_region_penalty) {}
|
||||
|
||||
void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
||||
std::vector<cv::Mat> &masks);
|
||||
void findInPair(size_t first, size_t second, Rect roi);
|
||||
|
||||
private:
|
||||
void setGraphWeightsColor(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &mask1, const cv::Mat &mask2,
|
||||
cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom);
|
||||
void setGraphWeightsColorGrad(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &dx1, const cv::Mat &dx2,
|
||||
const cv::Mat &dy1, const cv::Mat &dy2, const cv::Mat &mask1, const cv::Mat &mask2,
|
||||
cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom);
|
||||
std::vector<Mat> dx_, dy_;
|
||||
int cost_type_;
|
||||
float terminal_cost_;
|
||||
float bad_region_penalty_;
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_SEAM_FINDERS_HPP__
|
||||
|
@@ -1,162 +1,162 @@
|
||||
/*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_UTIL_HPP__
|
||||
#define __OPENCV_STITCHING_UTIL_HPP__
|
||||
|
||||
#include <list>
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
#define ENABLE_LOG 0
|
||||
|
||||
// TODO remove LOG macros, add logging class
|
||||
#if ENABLE_LOG
|
||||
#ifdef ANDROID
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <android/log.h>
|
||||
#define LOG_STITCHING_MSG(msg) \
|
||||
do { \
|
||||
std::stringstream _os; \
|
||||
_os << msg; \
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "STITCHING", "%s", _os.str().c_str()); \
|
||||
} while(0);
|
||||
#else
|
||||
#include <iostream>
|
||||
#define LOG_STITCHING_MSG(msg) for(;;) { std::cout << msg; std::cout.flush(); break; }
|
||||
#endif
|
||||
#else
|
||||
#define LOG_STITCHING_MSG(msg)
|
||||
#endif
|
||||
|
||||
#define LOG_(_level, _msg) \
|
||||
for(;;) \
|
||||
{ \
|
||||
if ((_level) >= ::cv::detail::stitchingLogLevel()) \
|
||||
{ \
|
||||
LOG_STITCHING_MSG(_msg); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
|
||||
|
||||
#define LOG(msg) LOG_(1, msg)
|
||||
#define LOG_CHAT(msg) LOG_(0, msg)
|
||||
|
||||
#define LOGLN(msg) LOG(msg << std::endl)
|
||||
#define LOGLN_CHAT(msg) LOG_CHAT(msg << std::endl)
|
||||
|
||||
//#if DEBUG_LOG_CHAT
|
||||
// #define LOG_CHAT(msg) LOG(msg)
|
||||
// #define LOGLN_CHAT(msg) LOGLN(msg)
|
||||
//#else
|
||||
// #define LOG_CHAT(msg) do{}while(0)
|
||||
// #define LOGLN_CHAT(msg) do{}while(0)
|
||||
//#endif
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS DisjointSets
|
||||
{
|
||||
public:
|
||||
DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); }
|
||||
|
||||
void createOneElemSets(int elem_count);
|
||||
int findSetByElem(int elem);
|
||||
int mergeSets(int set1, int set2);
|
||||
|
||||
std::vector<int> parent;
|
||||
std::vector<int> size;
|
||||
|
||||
private:
|
||||
std::vector<int> rank_;
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS GraphEdge
|
||||
{
|
||||
GraphEdge(int from, int to, float weight);
|
||||
bool operator <(const GraphEdge& other) const { return weight < other.weight; }
|
||||
bool operator >(const GraphEdge& other) const { return weight > other.weight; }
|
||||
|
||||
int from, to;
|
||||
float weight;
|
||||
};
|
||||
|
||||
inline GraphEdge::GraphEdge(int _from, int _to, float _weight) : from(_from), to(_to), weight(_weight) {}
|
||||
|
||||
|
||||
class CV_EXPORTS Graph
|
||||
{
|
||||
public:
|
||||
Graph(int num_vertices = 0) { create(num_vertices); }
|
||||
void create(int num_vertices) { edges_.assign(num_vertices, std::list<GraphEdge>()); }
|
||||
int numVertices() const { return static_cast<int>(edges_.size()); }
|
||||
void addEdge(int from, int to, float weight);
|
||||
template <typename B> B forEach(B body) const;
|
||||
template <typename B> B walkBreadthFirst(int from, B body) const;
|
||||
|
||||
private:
|
||||
std::vector< std::list<GraphEdge> > edges_;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
|
||||
CV_EXPORTS bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi);
|
||||
CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<Mat> &images);
|
||||
CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes);
|
||||
CV_EXPORTS Point resultTl(const std::vector<Point> &corners);
|
||||
|
||||
// Returns random 'count' element subset of the {0,1,...,size-1} set
|
||||
CV_EXPORTS void selectRandomSubset(int count, int size, std::vector<int> &subset);
|
||||
|
||||
CV_EXPORTS int& stitchingLogLevel();
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#include "util_inl.hpp"
|
||||
|
||||
#endif // __OPENCV_STITCHING_UTIL_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_UTIL_HPP__
|
||||
#define __OPENCV_STITCHING_UTIL_HPP__
|
||||
|
||||
#include <list>
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
#define ENABLE_LOG 0
|
||||
|
||||
// TODO remove LOG macros, add logging class
|
||||
#if ENABLE_LOG
|
||||
#ifdef ANDROID
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <android/log.h>
|
||||
#define LOG_STITCHING_MSG(msg) \
|
||||
do { \
|
||||
std::stringstream _os; \
|
||||
_os << msg; \
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "STITCHING", "%s", _os.str().c_str()); \
|
||||
} while(0);
|
||||
#else
|
||||
#include <iostream>
|
||||
#define LOG_STITCHING_MSG(msg) for(;;) { std::cout << msg; std::cout.flush(); break; }
|
||||
#endif
|
||||
#else
|
||||
#define LOG_STITCHING_MSG(msg)
|
||||
#endif
|
||||
|
||||
#define LOG_(_level, _msg) \
|
||||
for(;;) \
|
||||
{ \
|
||||
if ((_level) >= ::cv::detail::stitchingLogLevel()) \
|
||||
{ \
|
||||
LOG_STITCHING_MSG(_msg); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
|
||||
|
||||
#define LOG(msg) LOG_(1, msg)
|
||||
#define LOG_CHAT(msg) LOG_(0, msg)
|
||||
|
||||
#define LOGLN(msg) LOG(msg << std::endl)
|
||||
#define LOGLN_CHAT(msg) LOG_CHAT(msg << std::endl)
|
||||
|
||||
//#if DEBUG_LOG_CHAT
|
||||
// #define LOG_CHAT(msg) LOG(msg)
|
||||
// #define LOGLN_CHAT(msg) LOGLN(msg)
|
||||
//#else
|
||||
// #define LOG_CHAT(msg) do{}while(0)
|
||||
// #define LOGLN_CHAT(msg) do{}while(0)
|
||||
//#endif
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
class CV_EXPORTS DisjointSets
|
||||
{
|
||||
public:
|
||||
DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); }
|
||||
|
||||
void createOneElemSets(int elem_count);
|
||||
int findSetByElem(int elem);
|
||||
int mergeSets(int set1, int set2);
|
||||
|
||||
std::vector<int> parent;
|
||||
std::vector<int> size;
|
||||
|
||||
private:
|
||||
std::vector<int> rank_;
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS GraphEdge
|
||||
{
|
||||
GraphEdge(int from, int to, float weight);
|
||||
bool operator <(const GraphEdge& other) const { return weight < other.weight; }
|
||||
bool operator >(const GraphEdge& other) const { return weight > other.weight; }
|
||||
|
||||
int from, to;
|
||||
float weight;
|
||||
};
|
||||
|
||||
inline GraphEdge::GraphEdge(int _from, int _to, float _weight) : from(_from), to(_to), weight(_weight) {}
|
||||
|
||||
|
||||
class CV_EXPORTS Graph
|
||||
{
|
||||
public:
|
||||
Graph(int num_vertices = 0) { create(num_vertices); }
|
||||
void create(int num_vertices) { edges_.assign(num_vertices, std::list<GraphEdge>()); }
|
||||
int numVertices() const { return static_cast<int>(edges_.size()); }
|
||||
void addEdge(int from, int to, float weight);
|
||||
template <typename B> B forEach(B body) const;
|
||||
template <typename B> B walkBreadthFirst(int from, B body) const;
|
||||
|
||||
private:
|
||||
std::vector< std::list<GraphEdge> > edges_;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
|
||||
CV_EXPORTS bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi);
|
||||
CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<Mat> &images);
|
||||
CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes);
|
||||
CV_EXPORTS Point resultTl(const std::vector<Point> &corners);
|
||||
|
||||
// Returns random 'count' element subset of the {0,1,...,size-1} set
|
||||
CV_EXPORTS void selectRandomSubset(int count, int size, std::vector<int> &subset);
|
||||
|
||||
CV_EXPORTS int& stitchingLogLevel();
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#include "util_inl.hpp"
|
||||
|
||||
#endif // __OPENCV_STITCHING_UTIL_HPP__
|
||||
|
@@ -1,127 +1,127 @@
|
||||
/*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_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 {
|
||||
namespace detail {
|
||||
|
||||
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 detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_UTIL_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_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 {
|
||||
namespace detail {
|
||||
|
||||
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 detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_STITCHING_UTIL_INL_HPP__
|
||||
|
@@ -218,7 +218,7 @@ public:
|
||||
|
||||
struct CV_EXPORTS CompressedRectilinearProjector : ProjectorBase
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
|
||||
void mapForward(float x, float y, float &u, float &v);
|
||||
void mapBackward(float u, float v, float &x, float &y);
|
||||
@@ -239,7 +239,7 @@ public:
|
||||
|
||||
struct CV_EXPORTS CompressedRectilinearPortraitProjector : ProjectorBase
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
|
||||
void mapForward(float x, float y, float &u, float &v);
|
||||
void mapBackward(float u, float v, float &x, float &y);
|
||||
@@ -251,8 +251,8 @@ class CV_EXPORTS CompressedRectilinearPortraitWarper : public RotationWarperBase
|
||||
public:
|
||||
CompressedRectilinearPortraitWarper(float scale, float A = 1, float B = 1)
|
||||
{
|
||||
projector_.a = A;
|
||||
projector_.b = B;
|
||||
projector_.a = A;
|
||||
projector_.b = B;
|
||||
projector_.scale = scale;
|
||||
}
|
||||
};
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
|
||||
struct CV_EXPORTS PaniniProjector : ProjectorBase
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
|
||||
void mapForward(float x, float y, float &u, float &v);
|
||||
void mapBackward(float u, float v, float &x, float &y);
|
||||
@@ -272,8 +272,8 @@ class CV_EXPORTS PaniniWarper : public RotationWarperBase<PaniniProjector>
|
||||
public:
|
||||
PaniniWarper(float scale, float A = 1, float B = 1)
|
||||
{
|
||||
projector_.a = A;
|
||||
projector_.b = B;
|
||||
projector_.a = A;
|
||||
projector_.b = B;
|
||||
projector_.scale = scale;
|
||||
}
|
||||
};
|
||||
@@ -281,7 +281,7 @@ public:
|
||||
|
||||
struct CV_EXPORTS PaniniPortraitProjector : ProjectorBase
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
|
||||
void mapForward(float x, float y, float &u, float &v);
|
||||
void mapBackward(float u, float v, float &x, float &y);
|
||||
@@ -293,8 +293,8 @@ class CV_EXPORTS PaniniPortraitWarper : public RotationWarperBase<PaniniPortrait
|
||||
public:
|
||||
PaniniPortraitWarper(float scale, float A = 1, float B = 1)
|
||||
{
|
||||
projector_.a = A;
|
||||
projector_.b = B;
|
||||
projector_.a = A;
|
||||
projector_.b = B;
|
||||
projector_.scale = scale;
|
||||
}
|
||||
|
||||
|
@@ -302,27 +302,27 @@ void CylindricalProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
inline
|
||||
void FisheyeProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = (float)CV_PI - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
u = scale * v_ * cosf(u_);
|
||||
v = scale * v_ * sinf(u_);
|
||||
u = scale * v_ * cosf(u_);
|
||||
v = scale * v_ * sinf(u_);
|
||||
}
|
||||
|
||||
inline
|
||||
void FisheyeProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
|
||||
float u_ = atan2f(v, u);
|
||||
float v_ = sqrtf(u*u + v*v);
|
||||
float u_ = atan2f(v, u);
|
||||
float v_ = sqrtf(u*u + v*v);
|
||||
|
||||
float sinv = sinf((float)CV_PI - v_);
|
||||
float sinv = sinf((float)CV_PI - v_);
|
||||
float x_ = sinv * sinf(u_);
|
||||
float y_ = cosf((float)CV_PI - v_);
|
||||
float z_ = sinv * cosf(u_);
|
||||
@@ -332,37 +332,37 @@ void FisheyeProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
|
||||
z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
|
||||
|
||||
if (z > 0) { x /= z; y /= z; }
|
||||
if (z > 0) { x /= z; y /= z; }
|
||||
else x = y = -1;
|
||||
}
|
||||
|
||||
inline
|
||||
void StereographicProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = (float)CV_PI - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
float r = sinf(v_) / (1 - cosf(v_));
|
||||
float r = sinf(v_) / (1 - cosf(v_));
|
||||
|
||||
u = scale * r * cos(u_);
|
||||
v = scale * r * sin(u_);
|
||||
u = scale * r * cos(u_);
|
||||
v = scale * r * sin(u_);
|
||||
}
|
||||
|
||||
inline
|
||||
void StereographicProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
|
||||
float u_ = atan2f(v, u);
|
||||
float r = sqrtf(u*u + v*v);
|
||||
float v_ = 2 * atanf(1.f / r);
|
||||
float u_ = atan2f(v, u);
|
||||
float r = sqrtf(u*u + v*v);
|
||||
float v_ = 2 * atanf(1.f / r);
|
||||
|
||||
float sinv = sinf((float)CV_PI - v_);
|
||||
float sinv = sinf((float)CV_PI - v_);
|
||||
float x_ = sinv * sinf(u_);
|
||||
float y_ = cosf((float)CV_PI - v_);
|
||||
float z_ = sinv * cosf(u_);
|
||||
@@ -372,33 +372,33 @@ void StereographicProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
|
||||
z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
|
||||
|
||||
if (z > 0) { x /= z; y /= z; }
|
||||
if (z > 0) { x /= z; y /= z; }
|
||||
else x = y = -1;
|
||||
}
|
||||
|
||||
inline
|
||||
void CompressedRectilinearProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
u = scale * a * tanf(u_ / a);
|
||||
v = scale * b * tanf(v_) / cosf(u_);
|
||||
u = scale * a * tanf(u_ / a);
|
||||
v = scale * b * tanf(v_) / cosf(u_);
|
||||
}
|
||||
|
||||
inline
|
||||
void CompressedRectilinearProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
|
||||
float aatg = a * atanf(u / a);
|
||||
float u_ = aatg;
|
||||
float v_ = atanf(v * cosf(aatg) / b);
|
||||
float aatg = a * atanf(u / a);
|
||||
float u_ = aatg;
|
||||
float v_ = atanf(v * cosf(aatg) / b);
|
||||
|
||||
float cosv = cosf(v_);
|
||||
float x_ = cosv * sinf(u_);
|
||||
@@ -417,26 +417,26 @@ void CompressedRectilinearProjector::mapBackward(float u, float v, float &x, flo
|
||||
inline
|
||||
void CompressedRectilinearPortraitProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
u = - scale * a * tanf(u_ / a);
|
||||
v = scale * b * tanf(v_) / cosf(u_);
|
||||
u = - scale * a * tanf(u_ / a);
|
||||
v = scale * b * tanf(v_) / cosf(u_);
|
||||
}
|
||||
|
||||
inline
|
||||
void CompressedRectilinearPortraitProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= - scale;
|
||||
u /= - scale;
|
||||
v /= scale;
|
||||
|
||||
float aatg = a * atanf(u / a);
|
||||
float u_ = aatg;
|
||||
float v_ = atanf(v * cosf( aatg ) / b);
|
||||
float aatg = a * atanf(u / a);
|
||||
float u_ = aatg;
|
||||
float v_ = atanf(v * cosf( aatg ) / b);
|
||||
|
||||
float cosv = cosf(v_);
|
||||
float y_ = cosv * sinf(u_);
|
||||
@@ -455,37 +455,37 @@ void CompressedRectilinearPortraitProjector::mapBackward(float u, float v, float
|
||||
inline
|
||||
void PaniniProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
float tg = a * tanf(u_ / a);
|
||||
u = scale * tg;
|
||||
float tg = a * tanf(u_ / a);
|
||||
u = scale * tg;
|
||||
|
||||
float sinu = sinf(u_);
|
||||
if ( fabs(sinu) < 1E-7 )
|
||||
v = scale * b * tanf(v_);
|
||||
else
|
||||
v = scale * b * tg * tanf(v_) / sinu;
|
||||
float sinu = sinf(u_);
|
||||
if ( fabs(sinu) < 1E-7 )
|
||||
v = scale * b * tanf(v_);
|
||||
else
|
||||
v = scale * b * tg * tanf(v_) / sinu;
|
||||
}
|
||||
|
||||
inline
|
||||
void PaniniProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
|
||||
float lamda = a * atanf(u / a);
|
||||
float u_ = lamda;
|
||||
float lamda = a * atanf(u / a);
|
||||
float u_ = lamda;
|
||||
|
||||
float v_;
|
||||
if ( fabs(lamda) > 1E-7)
|
||||
v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda / a)));
|
||||
else
|
||||
v_ = atanf(v / b);
|
||||
float v_;
|
||||
if ( fabs(lamda) > 1E-7)
|
||||
v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda / a)));
|
||||
else
|
||||
v_ = atanf(v / b);
|
||||
|
||||
float cosv = cosf(v_);
|
||||
float x_ = cosv * sinf(u_);
|
||||
@@ -504,37 +504,37 @@ void PaniniProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
inline
|
||||
void PaniniPortraitProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
float tg = a * tanf(u_ / a);
|
||||
u = - scale * tg;
|
||||
float tg = a * tanf(u_ / a);
|
||||
u = - scale * tg;
|
||||
|
||||
float sinu = sinf( u_ );
|
||||
if ( fabs(sinu) < 1E-7 )
|
||||
v = scale * b * tanf(v_);
|
||||
else
|
||||
v = scale * b * tg * tanf(v_) / sinu;
|
||||
float sinu = sinf( u_ );
|
||||
if ( fabs(sinu) < 1E-7 )
|
||||
v = scale * b * tanf(v_);
|
||||
else
|
||||
v = scale * b * tg * tanf(v_) / sinu;
|
||||
}
|
||||
|
||||
inline
|
||||
void PaniniPortraitProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= - scale;
|
||||
u /= - scale;
|
||||
v /= scale;
|
||||
|
||||
float lamda = a * atanf(u / a);
|
||||
float u_ = lamda;
|
||||
float lamda = a * atanf(u / a);
|
||||
float u_ = lamda;
|
||||
|
||||
float v_;
|
||||
if ( fabs(lamda) > 1E-7)
|
||||
v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda/a)));
|
||||
else
|
||||
v_ = atanf(v / b);
|
||||
float v_;
|
||||
if ( fabs(lamda) > 1E-7)
|
||||
v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda/a)));
|
||||
else
|
||||
v_ = atanf(v / b);
|
||||
|
||||
float cosv = cosf(v_);
|
||||
float y_ = cosv * sinf(u_);
|
||||
@@ -553,25 +553,25 @@ void PaniniPortraitProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
inline
|
||||
void MercatorProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
u = scale * u_;
|
||||
v = scale * logf( tanf( (float)(CV_PI/4) + v_/2 ) );
|
||||
u = scale * u_;
|
||||
v = scale * logf( tanf( (float)(CV_PI/4) + v_/2 ) );
|
||||
}
|
||||
|
||||
inline
|
||||
void MercatorProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
|
||||
float v_ = atanf( sinhf(v) );
|
||||
float u_ = u;
|
||||
float v_ = atanf( sinhf(v) );
|
||||
float u_ = u;
|
||||
|
||||
float cosv = cosf(v_);
|
||||
float x_ = cosv * sinf(u_);
|
||||
@@ -590,27 +590,27 @@ void MercatorProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
inline
|
||||
void TransverseMercatorProjector::mapForward(float x, float y, float &u, float &v)
|
||||
{
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
|
||||
float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
|
||||
float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
|
||||
|
||||
float u_ = atan2f(x_, z_);
|
||||
float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
|
||||
|
||||
float B = cosf(v_) * sinf(u_);
|
||||
float B = cosf(v_) * sinf(u_);
|
||||
|
||||
u = scale / 2 * logf( (1+B) / (1-B) );
|
||||
v = scale * atan2f(tanf(v_), cosf(u_));
|
||||
u = scale / 2 * logf( (1+B) / (1-B) );
|
||||
v = scale * atan2f(tanf(v_), cosf(u_));
|
||||
}
|
||||
|
||||
inline
|
||||
void TransverseMercatorProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
|
||||
float v_ = asinf( sinf(v) / coshf(u) );
|
||||
float u_ = atan2f( sinhf(u), cos(v) );
|
||||
float v_ = asinf( sinf(v) / coshf(u) );
|
||||
float u_ = atan2f( sinhf(u), cos(v) );
|
||||
|
||||
float cosv = cosf(v_);
|
||||
float x_ = cosv * sinf(u_);
|
||||
|
@@ -89,45 +89,45 @@ public:
|
||||
|
||||
class CompressedRectilinearWarper: public WarperCreator
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
public:
|
||||
CompressedRectilinearWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
CompressedRectilinearWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
Ptr<detail::RotationWarper> create(float scale) const { return new detail::CompressedRectilinearWarper(scale, a, b); }
|
||||
};
|
||||
|
||||
class CompressedRectilinearPortraitWarper: public WarperCreator
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
public:
|
||||
CompressedRectilinearPortraitWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
CompressedRectilinearPortraitWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
Ptr<detail::RotationWarper> create(float scale) const { return new detail::CompressedRectilinearPortraitWarper(scale, a, b); }
|
||||
};
|
||||
|
||||
class PaniniWarper: public WarperCreator
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
public:
|
||||
PaniniWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
PaniniWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
Ptr<detail::RotationWarper> create(float scale) const { return new detail::PaniniWarper(scale, a, b); }
|
||||
};
|
||||
|
||||
class PaniniPortraitWarper: public WarperCreator
|
||||
{
|
||||
float a, b;
|
||||
float a, b;
|
||||
public:
|
||||
PaniniPortraitWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
PaniniPortraitWarper(float A = 1, float B = 1)
|
||||
{
|
||||
a = A; b = B;
|
||||
}
|
||||
Ptr<detail::RotationWarper> create(float scale) const { return new detail::PaniniPortraitWarper(scale, a, b); }
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user