Added translation parameter into stitching module warpers. For now only PlaneWarper and PlaneWarperGpu warpers support it.
This commit is contained in:
@@ -57,20 +57,26 @@ class CV_EXPORTS Warper
|
||||
public:
|
||||
virtual ~Warper() {}
|
||||
virtual Point warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst,
|
||||
int interp_mode = INTER_LINEAR, int border_mode = BORDER_REFLECT) = 0;
|
||||
int interp_mode, int border_mode) = 0;
|
||||
virtual Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, Mat &dst,
|
||||
int interp_mode, int border_mode) = 0;
|
||||
virtual Rect warpRoi(const Size &sz, const Mat &K, const Mat &R) = 0;
|
||||
virtual Rect warpRoi(const Size &sz, const Mat &K, const Mat &R, const Mat &T) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS ProjectorBase
|
||||
{
|
||||
void setCameraParams(const Mat &K, const Mat &R);
|
||||
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));
|
||||
|
||||
float scale;
|
||||
float k[9];
|
||||
float rinv[9];
|
||||
float r_kinv[9];
|
||||
float k_rinv[9];
|
||||
float t[3];
|
||||
};
|
||||
|
||||
|
||||
@@ -78,10 +84,12 @@ template <class P>
|
||||
class CV_EXPORTS WarperBase : public Warper
|
||||
{
|
||||
public:
|
||||
virtual Point warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
|
||||
virtual Rect warpRoi(const Size &sz, const Mat &K, const Mat &R);
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
Rect warpRoi(const Size &sz, const Mat &K, const Mat &R);
|
||||
Rect warpRoi(const Size &sz, const Mat &K, const Mat &R, const Mat &T);
|
||||
|
||||
protected:
|
||||
// Detects ROI of the destination image. It's correct for any projection.
|
||||
@@ -108,6 +116,10 @@ class CV_EXPORTS PlaneWarper : public WarperBase<PlaneProjector>
|
||||
{
|
||||
public:
|
||||
PlaneWarper(float scale = 1.f) { projector_.scale = scale; }
|
||||
void setScale(float scale) { projector_.scale = scale; }
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
Rect warpRoi(const Size &sz, const Mat &K, const Mat &R, const Mat &T);
|
||||
|
||||
protected:
|
||||
void detectResultRoi(Point &dst_tl, Point &dst_br);
|
||||
@@ -120,6 +132,8 @@ public:
|
||||
PlaneWarperGpu(float scale = 1.f) : PlaneWarper(scale) {}
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
|
||||
private:
|
||||
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
|
||||
|
@@ -80,6 +80,15 @@ Point WarperBase<P>::warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst,
|
||||
}
|
||||
|
||||
|
||||
template <class P>
|
||||
Point WarperBase<P>::warp(const Mat &/*src*/, const Mat &/*K*/, const Mat &/*R*/, const Mat &/*T*/, Mat &/*dst*/,
|
||||
int /*interp_mode*/, int /*border_mode*/)
|
||||
{
|
||||
CV_Error(CV_StsNotImplemented, "translation support isn't implemented");
|
||||
return Point();
|
||||
}
|
||||
|
||||
|
||||
template <class P>
|
||||
Rect WarperBase<P>::warpRoi(const Size &sz, const Mat &K, const Mat &R)
|
||||
{
|
||||
@@ -93,6 +102,14 @@ Rect WarperBase<P>::warpRoi(const Size &sz, const Mat &K, const Mat &R)
|
||||
}
|
||||
|
||||
|
||||
template <class P>
|
||||
Rect WarperBase<P>::warpRoi(const Size &sz, const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
CV_Error(CV_StsNotImplemented, "translation support isn't implemented");
|
||||
return Rect();
|
||||
}
|
||||
|
||||
|
||||
template <class P>
|
||||
void WarperBase<P>::detectResultRoi(Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
@@ -163,21 +180,24 @@ void PlaneProjector::mapForward(float x, float y, float &u, float &v)
|
||||
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];
|
||||
|
||||
u = scale * x_ / z_;
|
||||
v = scale * y_ / z_;
|
||||
x_ = t[0] + x_ / z_ * (1 - t[2]);
|
||||
y_ = t[1] + y_ / z_ * (1 - t[2]);
|
||||
|
||||
u = scale * x_;
|
||||
v = scale * y_;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
void PlaneProjector::mapBackward(float u, float v, float &x, float &y)
|
||||
{
|
||||
u /= scale;
|
||||
v /= scale;
|
||||
u = u / scale - t[0];
|
||||
v = v / scale - t[1];
|
||||
|
||||
float z;
|
||||
x = k_rinv[0] * u + k_rinv[1] * v + k_rinv[2];
|
||||
y = k_rinv[3] * u + k_rinv[4] * v + k_rinv[5];
|
||||
z = k_rinv[6] * u + k_rinv[7] * v + k_rinv[8];
|
||||
x = k_rinv[0] * u + k_rinv[1] * v + k_rinv[2] * (1 - t[2]);
|
||||
y = k_rinv[3] * u + k_rinv[4] * v + k_rinv[5] * (1 - t[2]);
|
||||
z = k_rinv[6] * u + k_rinv[7] * v + k_rinv[8] * (1 - t[2]);
|
||||
|
||||
x /= z;
|
||||
y /= z;
|
||||
|
Reference in New Issue
Block a user