diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index db773d405..d99a77926 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) int blend_type = Blender::MULTI_BAND; string result_name = "result.png"; - double work_scale = -1, compose_scale = -1; + double work_scale = 1, compose_scale = 1; bool is_work_scale_set = false, is_compose_scale_set = false; if (argc == 1) @@ -328,11 +328,11 @@ int main(int argc, char* argv[]) Ptr warper = Warper::createByCameraFocal(camera_focal, warp_type); for (int i = 0; i < num_images; ++i) { - corners[i] = (*warper)(images[i], static_cast(cameras[i].focal), cameras[i].R, - images_warped[i]); + corners[i] = warper->warp(images[i], static_cast(cameras[i].focal), cameras[i].R, + images_warped[i]); sizes[i] = images_warped[i].size(); - (*warper)(masks[i], static_cast(cameras[i].focal), cameras[i].R, masks_warped[i], - INTER_NEAREST, BORDER_CONSTANT); + warper->warp(masks[i], static_cast(cameras[i].focal), cameras[i].R, masks_warped[i], + INTER_NEAREST, BORDER_CONSTANT); } vector images_f(num_images); @@ -344,7 +344,7 @@ int main(int argc, char* argv[]) LOGLN("Finding seams..."); t = getTickCount(); Ptr seam_finder = SeamFinder::createDefault(seam_find_type); - (*seam_finder)(images_f, corners, masks_warped); + seam_finder->find(images_f, corners, masks_warped); LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); LOGLN("Blending images..."); diff --git a/modules/stitching/seam_finders.cpp b/modules/stitching/seam_finders.cpp index 1f870b187..1195c832d 100644 --- a/modules/stitching/seam_finders.cpp +++ b/modules/stitching/seam_finders.cpp @@ -20,13 +20,6 @@ Ptr SeamFinder::createDefault(int type) } -void SeamFinder::operator ()(const vector &src, const vector &corners, - vector &masks) -{ - find(src, corners, masks); -} - - void PairwiseSeamFinder::find(const vector &src, const vector &corners, vector &masks) { diff --git a/modules/stitching/seam_finders.hpp b/modules/stitching/seam_finders.hpp index 5f58e5d49..cc4f76f3e 100644 --- a/modules/stitching/seam_finders.hpp +++ b/modules/stitching/seam_finders.hpp @@ -8,15 +8,9 @@ class SeamFinder { public: enum { NO, VORONOI, GRAPH_CUT }; - static cv::Ptr createDefault(int type); virtual ~SeamFinder() {} - - void operator ()(const std::vector &src, const std::vector &corners, - std::vector &masks); - -protected: virtual void find(const std::vector &src, const std::vector &corners, std::vector &masks) = 0; }; @@ -24,17 +18,17 @@ protected: class NoSeamFinder : public SeamFinder { -protected: +public: void find(const std::vector&, const std::vector&, std::vector&) {} }; class PairwiseSeamFinder : public SeamFinder { -protected: +public: void find(const std::vector &src, const std::vector &corners, std::vector &masks); - +protected: virtual void findInPair(const cv::Mat &img1, const cv::Mat &img2, cv::Point tl1, cv::Point tl2, cv::Rect roi, cv::Mat &mask1, cv::Mat &mask2) = 0; }; @@ -53,7 +47,6 @@ class GraphCutSeamFinder : public PairwiseSeamFinder public: // TODO add COST_COLOR_GRAD support enum { COST_COLOR }; - GraphCutSeamFinder(int cost_type = COST_COLOR, float terminal_cost = 10000.f, float bad_region_penalty = 1000.f); diff --git a/modules/stitching/warpers.cpp b/modules/stitching/warpers.cpp index 6b14c8a48..3b74eb70b 100644 --- a/modules/stitching/warpers.cpp +++ b/modules/stitching/warpers.cpp @@ -16,7 +16,7 @@ Ptr Warper::createByCameraFocal(float focal, int type) } -void ProjectorBase::setCameraMatrix(const Mat &R) +void ProjectorBase::setTransformation(const Mat &R) { CV_Assert(R.size() == Size(3, 3)); CV_Assert(R.type() == CV_32F); @@ -31,13 +31,6 @@ void ProjectorBase::setCameraMatrix(const Mat &R) } -Point Warper::operator ()(const Mat &src, float focal, const Mat& R, Mat &dst, - int interp_mode, int border_mode) -{ - return warp(src, focal, R, dst, interp_mode, border_mode); -} - - void PlaneWarper::detectResultRoi(Point &dst_tl, Point &dst_br) { float tl_uf = numeric_limits::max(); diff --git a/modules/stitching/warpers.hpp b/modules/stitching/warpers.hpp index 63e1e2b64..a839b6c03 100644 --- a/modules/stitching/warpers.hpp +++ b/modules/stitching/warpers.hpp @@ -8,23 +8,17 @@ class Warper { public: enum { PLANE, CYLINDRICAL, SPHERICAL }; - static cv::Ptr createByCameraFocal(float focal, int type); virtual ~Warper() {} - - cv::Point operator ()(const cv::Mat &src, float focal, const cv::Mat& R, cv::Mat &dst, - int interp_mode = cv::INTER_LINEAR, int border_mode = cv::BORDER_REFLECT); - -protected: virtual cv::Point warp(const cv::Mat &src, float focal, const cv::Mat& R, cv::Mat &dst, - int interp_mode, int border_mode) = 0; + int interp_mode = cv::INTER_LINEAR, int border_mode = cv::BORDER_REFLECT) = 0; }; struct ProjectorBase { - void setCameraMatrix(const cv::Mat& R); + void setTransformation(const cv::Mat& R); cv::Size size; float focal; @@ -37,10 +31,11 @@ struct ProjectorBase template class WarperBase : public Warper { -protected: +public: cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst, int interp_mode, int border_mode); +protected: // Detects ROI of the destination image. It's correct for any projection. virtual void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br); diff --git a/modules/stitching/warpers_inl.hpp b/modules/stitching/warpers_inl.hpp index 9a558c2b8..3fcdfe443 100644 --- a/modules/stitching/warpers_inl.hpp +++ b/modules/stitching/warpers_inl.hpp @@ -11,7 +11,7 @@ cv::Point WarperBase

::warp(const cv::Mat &src, float focal, const cv::Mat &R, projector_.size = src.size(); projector_.focal = focal; - projector_.setCameraMatrix(R); + projector_.setTransformation(R); cv::Point dst_tl, dst_br; detectResultRoi(dst_tl, dst_br);