added gpu::buildWarpPlaneMaps and gpu::buildWarpCylindricalMaps functions, integrated into stitching
This commit is contained in:
@@ -233,10 +233,7 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
copyMakeBorder(img, img_with_border, top, bottom, left, right,
|
||||
BORDER_REFLECT);
|
||||
vector<Mat> src_pyr_laplace;
|
||||
if (can_use_gpu_)
|
||||
createLaplacePyrGpu(img_with_border, num_bands_, src_pyr_laplace);
|
||||
else
|
||||
createLaplacePyr(img_with_border, num_bands_, src_pyr_laplace);
|
||||
createLaplacePyr(img_with_border, num_bands_, src_pyr_laplace);
|
||||
|
||||
// Create the weight map Gaussian pyramid
|
||||
Mat weight_map;
|
||||
@@ -341,6 +338,7 @@ void createLaplacePyr(const Mat &img, int num_levels, vector<Mat> &pyr)
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void createLaplacePyrGpu(const Mat &img, int num_levels, vector<Mat> &pyr)
|
||||
{
|
||||
pyr.resize(num_levels + 1);
|
||||
@@ -360,7 +358,7 @@ void createLaplacePyrGpu(const Mat &img, int num_levels, vector<Mat> &pyr)
|
||||
|
||||
pyr[num_levels] = gpu_pyr[num_levels];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void restoreImageFromLaplacePyr(vector<Mat> &pyr)
|
||||
|
||||
@@ -108,7 +108,11 @@ void normalize(const cv::Mat& weight, cv::Mat& src);
|
||||
void createWeightMap(const cv::Mat& mask, float sharpness, cv::Mat& weight);
|
||||
|
||||
void createLaplacePyr(const cv::Mat &img, int num_levels, std::vector<cv::Mat>& pyr);
|
||||
|
||||
// TODO Use it after gpu::pyrDown and gpu::pyrUp are updated
|
||||
#if 0
|
||||
void createLaplacePyrGpu(const cv::Mat &img, int num_levels, std::vector<cv::Mat>& pyr);
|
||||
#endif
|
||||
|
||||
// Restores source image in-place (result will be stored in pyr[0])
|
||||
void restoreImageFromLaplacePyr(std::vector<cv::Mat>& pyr);
|
||||
|
||||
@@ -547,7 +547,7 @@ int main(int argc, char* argv[])
|
||||
else
|
||||
img = full_img;
|
||||
full_img.release();
|
||||
Size img_size = img.size();
|
||||
Size img_size = img.size();
|
||||
|
||||
// Warp the current image
|
||||
warper->warp(img, static_cast<float>(cameras[img_idx].focal), cameras[img_idx].R,
|
||||
|
||||
@@ -48,9 +48,9 @@ Ptr<Warper> Warper::createByCameraFocal(float focal, int type, bool try_gpu)
|
||||
{
|
||||
bool can_use_gpu = try_gpu && gpu::getCudaEnabledDeviceCount();
|
||||
if (type == PLANE)
|
||||
return new PlaneWarper(focal);
|
||||
return !can_use_gpu ? new PlaneWarper(focal) : new PlaneWarperGpu(focal);
|
||||
if (type == CYLINDRICAL)
|
||||
return new CylindricalWarper(focal);
|
||||
return !can_use_gpu ? new CylindricalWarper(focal) : new CylindricalWarperGpu(focal);
|
||||
if (type == SPHERICAL)
|
||||
return !can_use_gpu ? new SphericalWarper(focal) : new SphericalWarperGpu(focal);
|
||||
CV_Error(CV_StsBadArg, "unsupported warping type");
|
||||
@@ -105,6 +105,26 @@ void PlaneWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
|
||||
}
|
||||
|
||||
|
||||
Point PlaneWarperGpu::warp(const Mat &src, float focal, const cv::Mat &R, cv::Mat &dst, int interp_mode, int border_mode)
|
||||
{
|
||||
src_size_ = src.size();
|
||||
projector_.size = src.size();
|
||||
projector_.focal = focal;
|
||||
projector_.setTransformation(R);
|
||||
|
||||
cv::Point dst_tl, dst_br;
|
||||
detectResultRoi(dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpPlaneMaps(src.size(), Rect(dst_tl, Point(dst_br.x+1, dst_br.y+1)),
|
||||
R, focal, projector_.scale, projector_.plane_dist, d_xmap_, d_ymap_);
|
||||
|
||||
dst.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, src.type());
|
||||
remap(src, dst, Mat(d_xmap_), Mat(d_ymap_), interp_mode, border_mode);
|
||||
|
||||
return dst_tl;
|
||||
}
|
||||
|
||||
|
||||
void SphericalWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
detectResultRoiByBorder(dst_tl, dst_br);
|
||||
@@ -168,3 +188,24 @@ Point SphericalWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat &d
|
||||
|
||||
return dst_tl;
|
||||
}
|
||||
|
||||
|
||||
Point CylindricalWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat &dst,
|
||||
int interp_mode, int border_mode)
|
||||
{
|
||||
src_size_ = src.size();
|
||||
projector_.size = src.size();
|
||||
projector_.focal = focal;
|
||||
projector_.setTransformation(R);
|
||||
|
||||
cv::Point dst_tl, dst_br;
|
||||
detectResultRoi(dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpCylindricalMaps(src.size(), Rect(dst_tl, Point(dst_br.x+1, dst_br.y+1)),
|
||||
R, focal, projector_.scale, d_xmap_, d_ymap_);
|
||||
|
||||
dst.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, src.type());
|
||||
remap(src, dst, Mat(d_xmap_), Mat(d_ymap_), interp_mode, border_mode);
|
||||
|
||||
return dst_tl;
|
||||
}
|
||||
|
||||
@@ -109,11 +109,23 @@ public:
|
||||
projector_.scale = scale;
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br);
|
||||
};
|
||||
|
||||
|
||||
class PlaneWarperGpu : public PlaneWarper
|
||||
{
|
||||
public:
|
||||
PlaneWarperGpu(float plane_dist = 1.f, float scale = 1.f) : PlaneWarper(plane_dist, scale) {}
|
||||
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
|
||||
private:
|
||||
cv::gpu::GpuMat d_xmap_, d_ymap_, d_dst_;
|
||||
};
|
||||
|
||||
|
||||
struct SphericalProjector : ProjectorBase
|
||||
{
|
||||
void mapForward(float x, float y, float &u, float &v);
|
||||
@@ -158,13 +170,25 @@ class CylindricalWarper : public WarperBase<CylindricalProjector>
|
||||
public:
|
||||
CylindricalWarper(float scale = 300.f) { projector_.scale = scale; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br)
|
||||
{
|
||||
WarperBase<CylindricalProjector>::detectResultRoiByBorder(dst_tl, dst_br);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CylindricalWarperGpu : public CylindricalWarper
|
||||
{
|
||||
public:
|
||||
CylindricalWarperGpu(float scale = 300.f) : CylindricalWarper(scale) {}
|
||||
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
|
||||
int interp_mode, int border_mode);
|
||||
|
||||
private:
|
||||
cv::gpu::GpuMat d_xmap_, d_ymap_, d_dst_;
|
||||
};
|
||||
|
||||
#include "warpers_inl.hpp"
|
||||
|
||||
#endif // __OPENCV_WARPERS_HPP__
|
||||
|
||||
Reference in New Issue
Block a user