mirror of
https://github.com/storytold/LiveScan3D.git
synced 2026-10-29 08:57:09 +00:00
Moved to Visual Studio 2015, OpenCV 3.2.0, x64
This commit is contained in:
@@ -40,46 +40,92 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_STITCHING_WARPERS_HPP__
|
||||
#define __OPENCV_STITCHING_WARPERS_HPP__
|
||||
#ifndef OPENCV_STITCHING_WARPERS_HPP
|
||||
#define OPENCV_STITCHING_WARPERS_HPP
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID)
|
||||
# include "opencv2/gpu/gpu.hpp"
|
||||
#endif
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
//! @addtogroup stitching_warp
|
||||
//! @{
|
||||
|
||||
/** @brief Rotation-only model image warper interface.
|
||||
*/
|
||||
class CV_EXPORTS RotationWarper
|
||||
{
|
||||
public:
|
||||
virtual ~RotationWarper() {}
|
||||
|
||||
virtual Point2f warpPoint(const Point2f &pt, const Mat &K, const Mat &R) = 0;
|
||||
/** @brief Projects the image point.
|
||||
|
||||
virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) = 0;
|
||||
@param pt Source point
|
||||
@param K Camera intrinsic parameters
|
||||
@param R Camera rotation matrix
|
||||
@return Projected point
|
||||
*/
|
||||
virtual Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) = 0;
|
||||
|
||||
virtual Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Mat &dst) = 0;
|
||||
/** @brief Builds the projection maps according to the given camera data.
|
||||
|
||||
virtual void warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Size dst_size, Mat &dst) = 0;
|
||||
@param src_size Source image size
|
||||
@param K Camera intrinsic parameters
|
||||
@param R Camera rotation matrix
|
||||
@param xmap Projection map for the x axis
|
||||
@param ymap Projection map for the y axis
|
||||
@return Projected image minimum bounding box
|
||||
*/
|
||||
virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) = 0;
|
||||
|
||||
virtual Rect warpRoi(Size src_size, const Mat &K, const Mat &R) = 0;
|
||||
/** @brief Projects the image.
|
||||
|
||||
float getScale() const { return 1.f; }
|
||||
void setScale(float) {}
|
||||
@param src Source image
|
||||
@param K Camera intrinsic parameters
|
||||
@param R Camera rotation matrix
|
||||
@param interp_mode Interpolation mode
|
||||
@param border_mode Border extrapolation mode
|
||||
@param dst Projected image
|
||||
@return Project image top-left corner
|
||||
*/
|
||||
virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
OutputArray dst) = 0;
|
||||
|
||||
/** @brief Projects the image backward.
|
||||
|
||||
@param src Projected image
|
||||
@param K Camera intrinsic parameters
|
||||
@param R Camera rotation matrix
|
||||
@param interp_mode Interpolation mode
|
||||
@param border_mode Border extrapolation mode
|
||||
@param dst_size Backward-projected image size
|
||||
@param dst Backward-projected image
|
||||
*/
|
||||
virtual void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
Size dst_size, OutputArray dst) = 0;
|
||||
|
||||
/**
|
||||
@param src_size Source image bounding box
|
||||
@param K Camera intrinsic parameters
|
||||
@param R Camera rotation matrix
|
||||
@return Projected image minimum bounding box
|
||||
*/
|
||||
virtual Rect warpRoi(Size src_size, InputArray K, InputArray R) = 0;
|
||||
|
||||
virtual float getScale() const { return 1.f; }
|
||||
virtual void setScale(float) {}
|
||||
};
|
||||
|
||||
|
||||
/** @brief Base class for warping logic implementation.
|
||||
*/
|
||||
struct CV_EXPORTS ProjectorBase
|
||||
{
|
||||
void setCameraParams(const Mat &K = Mat::eye(3, 3, CV_32F),
|
||||
const Mat &R = Mat::eye(3, 3, CV_32F),
|
||||
const Mat &T = Mat::zeros(3, 1, CV_32F));
|
||||
void setCameraParams(InputArray K = Mat::eye(3, 3, CV_32F),
|
||||
InputArray R = Mat::eye(3, 3, CV_32F),
|
||||
InputArray T = Mat::zeros(3, 1, CV_32F));
|
||||
|
||||
float scale;
|
||||
float k[9];
|
||||
@@ -89,22 +135,23 @@ struct CV_EXPORTS ProjectorBase
|
||||
float t[3];
|
||||
};
|
||||
|
||||
|
||||
/** @brief Base class for rotation-based warper using a detail::ProjectorBase_ derived class.
|
||||
*/
|
||||
template <class P>
|
||||
class CV_EXPORTS RotationWarperBase : public RotationWarper
|
||||
{
|
||||
public:
|
||||
Point2f warpPoint(const Point2f &pt, const Mat &K, const Mat &R);
|
||||
Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
|
||||
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Mat &dst);
|
||||
Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
OutputArray dst);
|
||||
|
||||
void warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Size dst_size, Mat &dst);
|
||||
void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
Size dst_size, OutputArray dst);
|
||||
|
||||
Rect warpRoi(Size src_size, const Mat &K, const Mat &R);
|
||||
Rect warpRoi(Size src_size, InputArray K, InputArray R);
|
||||
|
||||
float getScale() const { return projector_.scale; }
|
||||
void setScale(float val) { projector_.scale = val; }
|
||||
@@ -128,28 +175,64 @@ struct CV_EXPORTS PlaneProjector : ProjectorBase
|
||||
void mapBackward(float u, float v, float &x, float &y);
|
||||
};
|
||||
|
||||
|
||||
/** @brief Warper that maps an image onto the z = 1 plane.
|
||||
*/
|
||||
class CV_EXPORTS PlaneWarper : public RotationWarperBase<PlaneProjector>
|
||||
{
|
||||
public:
|
||||
/** @brief Construct an instance of the plane warper class.
|
||||
|
||||
@param scale Projected image scale multiplier
|
||||
*/
|
||||
PlaneWarper(float scale = 1.f) { projector_.scale = scale; }
|
||||
|
||||
void setScale(float scale) { projector_.scale = scale; }
|
||||
Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
|
||||
Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T);
|
||||
|
||||
Point2f warpPoint(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T);
|
||||
virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap);
|
||||
Point warp(InputArray src, InputArray K, InputArray R,
|
||||
int interp_mode, int border_mode, OutputArray dst);
|
||||
virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
|
||||
OutputArray dst);
|
||||
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
Mat &dst);
|
||||
|
||||
Rect warpRoi(Size src_size, const Mat &K, const Mat &R, const Mat &T);
|
||||
Rect warpRoi(Size src_size, InputArray K, InputArray R);
|
||||
Rect warpRoi(Size src_size, InputArray K, InputArray R, InputArray T);
|
||||
|
||||
protected:
|
||||
void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
|
||||
};
|
||||
|
||||
|
||||
/** @brief Affine warper that uses rotations and translations
|
||||
|
||||
Uses affine transformation in homogeneous coordinates to represent both rotation and
|
||||
translation in camera rotation matrix.
|
||||
*/
|
||||
class CV_EXPORTS AffineWarper : public PlaneWarper
|
||||
{
|
||||
public:
|
||||
/** @brief Construct an instance of the affine warper class.
|
||||
|
||||
@param scale Projected image scale multiplier
|
||||
*/
|
||||
AffineWarper(float scale = 1.f) : PlaneWarper(scale) {}
|
||||
|
||||
Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
|
||||
Point warp(InputArray src, InputArray K, InputArray R,
|
||||
int interp_mode, int border_mode, OutputArray dst);
|
||||
Rect warpRoi(Size src_size, InputArray K, InputArray R);
|
||||
|
||||
protected:
|
||||
/** @brief Extracts rotation and translation matrices from matrix H representing
|
||||
affine transformation in homogeneous coordinates
|
||||
*/
|
||||
void getRTfromHomogeneous(InputArray H, Mat &R, Mat &T);
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS SphericalProjector : ProjectorBase
|
||||
{
|
||||
void mapForward(float x, float y, float &u, float &v);
|
||||
@@ -157,13 +240,24 @@ struct CV_EXPORTS SphericalProjector : ProjectorBase
|
||||
};
|
||||
|
||||
|
||||
// Projects image onto unit sphere with origin at (0, 0, 0).
|
||||
// Poles are located at (0, -1, 0) and (0, 1, 0) points.
|
||||
/** @brief Warper that maps an image onto the unit sphere located at the origin.
|
||||
|
||||
Projects image onto unit sphere with origin at (0, 0, 0) and radius scale, measured in pixels.
|
||||
A 360° panorama would therefore have a resulting width of 2 * scale * PI pixels.
|
||||
Poles are located at (0, -1, 0) and (0, 1, 0) points.
|
||||
*/
|
||||
class CV_EXPORTS SphericalWarper : public RotationWarperBase<SphericalProjector>
|
||||
{
|
||||
public:
|
||||
/** @brief Construct an instance of the spherical warper class.
|
||||
|
||||
@param scale Radius of the projected sphere, in pixels. An image spanning the
|
||||
whole sphere will have a width of 2 * scale * PI pixels.
|
||||
*/
|
||||
SphericalWarper(float scale) { projector_.scale = scale; }
|
||||
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
|
||||
Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst);
|
||||
protected:
|
||||
void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
|
||||
};
|
||||
@@ -176,12 +270,19 @@ struct CV_EXPORTS CylindricalProjector : ProjectorBase
|
||||
};
|
||||
|
||||
|
||||
// Projects image onto x * x + z * z = 1 cylinder
|
||||
/** @brief Warper that maps an image onto the x\*x + z\*z = 1 cylinder.
|
||||
*/
|
||||
class CV_EXPORTS CylindricalWarper : public RotationWarperBase<CylindricalProjector>
|
||||
{
|
||||
public:
|
||||
/** @brief Construct an instance of the cylindrical warper class.
|
||||
|
||||
@param scale Projected image scale multiplier
|
||||
*/
|
||||
CylindricalWarper(float scale) { projector_.scale = scale; }
|
||||
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
|
||||
Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst);
|
||||
protected:
|
||||
void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
@@ -331,13 +432,12 @@ public:
|
||||
};
|
||||
|
||||
|
||||
#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID)
|
||||
class CV_EXPORTS PlaneWarperGpu : public PlaneWarper
|
||||
{
|
||||
public:
|
||||
PlaneWarperGpu(float scale = 1.f) : PlaneWarper(scale) {}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap)
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
|
||||
d_xmap_.download(xmap);
|
||||
@@ -345,7 +445,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap)
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
Rect result = buildMaps(src_size, K, R, T, d_xmap_, d_ymap_);
|
||||
d_xmap_.download(xmap);
|
||||
@@ -353,8 +453,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Mat &dst)
|
||||
Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
OutputArray dst)
|
||||
{
|
||||
d_src_.upload(src);
|
||||
Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
|
||||
@@ -362,8 +462,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
Mat &dst)
|
||||
Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
|
||||
OutputArray dst)
|
||||
{
|
||||
d_src_.upload(src);
|
||||
Point result = warp(d_src_, K, R, T, interp_mode, border_mode, d_dst_);
|
||||
@@ -371,18 +471,18 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, gpu::GpuMat &xmap, gpu::GpuMat &ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
|
||||
|
||||
Point warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst);
|
||||
Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
cuda::GpuMat & dst);
|
||||
|
||||
Point warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst);
|
||||
Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
|
||||
cuda::GpuMat & dst);
|
||||
|
||||
private:
|
||||
gpu::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
|
||||
cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
|
||||
};
|
||||
|
||||
|
||||
@@ -391,7 +491,7 @@ class CV_EXPORTS SphericalWarperGpu : public SphericalWarper
|
||||
public:
|
||||
SphericalWarperGpu(float scale) : SphericalWarper(scale) {}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap)
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
|
||||
d_xmap_.download(xmap);
|
||||
@@ -399,8 +499,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Mat &dst)
|
||||
Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
OutputArray dst)
|
||||
{
|
||||
d_src_.upload(src);
|
||||
Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
|
||||
@@ -408,13 +508,13 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
|
||||
|
||||
Point warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst);
|
||||
Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
cuda::GpuMat & dst);
|
||||
|
||||
private:
|
||||
gpu::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
|
||||
cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
|
||||
};
|
||||
|
||||
|
||||
@@ -423,7 +523,7 @@ class CV_EXPORTS CylindricalWarperGpu : public CylindricalWarper
|
||||
public:
|
||||
CylindricalWarperGpu(float scale) : CylindricalWarper(scale) {}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap)
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
|
||||
d_xmap_.download(xmap);
|
||||
@@ -431,8 +531,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
Mat &dst)
|
||||
Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
OutputArray dst)
|
||||
{
|
||||
d_src_.upload(src);
|
||||
Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
|
||||
@@ -440,15 +540,14 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Rect buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
|
||||
|
||||
Point warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst);
|
||||
Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
|
||||
cuda::GpuMat & dst);
|
||||
|
||||
private:
|
||||
gpu::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
|
||||
cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
struct SphericalPortraitProjector : ProjectorBase
|
||||
@@ -507,9 +606,11 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
//! @} stitching_warp
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#include "warpers_inl.hpp"
|
||||
|
||||
#endif // __OPENCV_STITCHING_WARPERS_HPP__
|
||||
#endif // OPENCV_STITCHING_WARPERS_HPP
|
||||
|
||||
Reference in New Issue
Block a user