Added warp method into the RotationWarper interface, added find() into VoronoiSeamFin...
authorAlexey Spizhevoy <no@email>
Fri, 7 Oct 2011 08:17:55 +0000 (08:17 +0000)
committerAlexey Spizhevoy <no@email>
Fri, 7 Oct 2011 08:17:55 +0000 (08:17 +0000)
modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp
modules/stitching/include/opencv2/stitching/detail/warpers.hpp
modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp
modules/stitching/src/seam_finders.cpp
modules/stitching/src/warpers.cpp

index bd21958..c52d1cd 100644 (file)
@@ -71,9 +71,11 @@ public:
                       std::vector<Mat> &masks);\r
 \r
 protected:\r
+    void run();\r
     virtual void findInPair(size_t first, size_t second, Rect roi) = 0;\r
 \r
     std::vector<Mat> images_;\r
+    std::vector<Size> sizes_;\r
     std::vector<Point> corners_;\r
     std::vector<Mat> masks_;\r
 };\r
@@ -81,6 +83,9 @@ protected:
 \r
 class CV_EXPORTS VoronoiSeamFinder : public PairwiseSeamFinder\r
 {\r
+public:\r
+    virtual void find(const std::vector<Size> &size, const std::vector<Point> &corners,\r
+                      std::vector<Mat> &masks);\r
 private:\r
     void findInPair(size_t first, size_t second, Rect roi);\r
 };\r
index 0f168a4..5e36a6e 100644 (file)
@@ -57,11 +57,14 @@ class CV_EXPORTS RotationWarper
 public:\r
     virtual ~RotationWarper() {}\r
 \r
+    virtual Point2f warp(const Point2f &pt, const Mat &K, const Mat &R) = 0;\r
+\r
     virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) = 0;\r
 \r
     virtual Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,\r
                        Mat &dst) = 0;\r
 \r
+    // TODO add other backward functions for consistency or move this into a separated interface\r
     virtual void warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,\r
                               Size dst_size, Mat &dst) = 0;\r
 \r
@@ -88,6 +91,8 @@ template <class P>
 class CV_EXPORTS RotationWarperBase : public RotationWarper\r
 {   \r
 public:\r
+    Point2f warp(const Point2f &pt, const Mat &K, const Mat &R);\r
+    \r
     Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap);\r
 \r
     Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,\r
@@ -126,6 +131,8 @@ public:
 \r
     void setScale(float scale) { projector_.scale = scale; }\r
 \r
+    Point2f warp(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T);\r
+\r
     Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap);\r
 \r
     Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,\r
index 389deda..65532bb 100644 (file)
@@ -50,6 +50,16 @@ namespace cv {
 namespace detail {\r
 \r
 template <class P>\r
+Point2f RotationWarperBase<P>::warp(const Point2f &pt, const Mat &K, const Mat &R)\r
+{\r
+    projector_.setCameraParams(K, R);\r
+    Point2f uv;\r
+    projector_.mapForward(pt.x, pt.y, uv.x, uv.y);\r
+    return uv;\r
+}\r
+\r
+\r
+template <class P>\r
 Rect RotationWarperBase<P>::buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap)\r
 {\r
     projector_.setCameraParams(K, R);\r
index ef854e4..d2d50fd 100644 (file)
@@ -49,24 +49,50 @@ void PairwiseSeamFinder::find(const vector<Mat> &src, const vector<Point> &corne
                               vector<Mat> &masks)\r
 {\r
     LOGLN("Finding seams...");\r
-    int64 t = getTickCount();\r
-\r
-    if (src.size() == 0)\r
+    if (src.size() == 0) \r
         return;\r
 \r
+    int64 t = getTickCount();\r
+\r
     images_ = src;\r
+    sizes_.resize(src.size());\r
+    for (size_t i = 0; i < src.size(); ++i)\r
+        sizes_[i] = src[i].size();\r
     corners_ = corners;\r
     masks_ = masks;\r
+    run();\r
+\r
+    LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");\r
+}\r
+\r
 \r
-    for (size_t i = 0; i < src.size() - 1; ++i)\r
+void PairwiseSeamFinder::run()\r
+{\r
+    for (size_t i = 0; i < sizes_.size() - 1; ++i)\r
     {\r
-        for (size_t j = i + 1; j < src.size(); ++j)\r
+        for (size_t j = i + 1; j < sizes_.size(); ++j)\r
         {\r
             Rect roi;\r
-            if (overlapRoi(corners[i], corners[j], src[i].size(), src[j].size(), roi))\r
+            if (overlapRoi(corners_[i], corners_[j], sizes_[i], sizes_[j], roi))\r
                 findInPair(i, j, roi);\r
         }\r
     }\r
+}\r
+\r
+\r
+void VoronoiSeamFinder::find(const vector<Size> &sizes, const vector<Point> &corners,\r
+                             vector<Mat> &masks)\r
+{\r
+    LOGLN("Finding seams...");\r
+    if (sizes.size() == 0) \r
+        return;\r
+\r
+    int64 t = getTickCount();\r
+\r
+    sizes_ = sizes;\r
+    corners_ = corners;\r
+    masks_ = masks;\r
+    run();\r
 \r
     LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");\r
 }\r
@@ -78,7 +104,7 @@ void VoronoiSeamFinder::findInPair(size_t first, size_t second, Rect roi)
     Mat submask1(roi.height + 2 * gap, roi.width + 2 * gap, CV_8U);\r
     Mat submask2(roi.height + 2 * gap, roi.width + 2 * gap, CV_8U);\r
 \r
-    Mat img1 = images_[first], img2 = images_[second];\r
+    Size img1 = sizes_[first], img2 = sizes_[second];\r
     Mat mask1 = masks_[first], mask2 = masks_[second];\r
     Point tl1 = corners_[first], tl2 = corners_[second];\r
 \r
@@ -89,14 +115,14 @@ void VoronoiSeamFinder::findInPair(size_t first, size_t second, Rect roi)
         {\r
             int y1 = roi.y - tl1.y + y;\r
             int x1 = roi.x - tl1.x + x;\r
-            if (y1 >= 0 && x1 >= 0 && y1 < img1.rows && x1 < img1.cols)\r
+            if (y1 >= 0 && x1 >= 0 && y1 < img1.height && x1 < img1.width)\r
                 submask1.at<uchar>(y + gap, x + gap) = mask1.at<uchar>(y1, x1);\r
             else\r
                 submask1.at<uchar>(y + gap, x + gap) = 0;\r
 \r
             int y2 = roi.y - tl2.y + y;\r
             int x2 = roi.x - tl2.x + x;\r
-            if (y2 >= 0 && x2 >= 0 && y2 < img2.rows && x2 < img2.cols)\r
+            if (y2 >= 0 && x2 >= 0 && y2 < img2.height && x2 < img2.width)\r
                 submask2.at<uchar>(y + gap, x + gap) = mask2.at<uchar>(y2, x2);\r
             else\r
                 submask2.at<uchar>(y + gap, x + gap) = 0;\r
index 3bd0497..539bb08 100644 (file)
@@ -78,6 +78,15 @@ void ProjectorBase::setCameraParams(const Mat &K, const Mat &R, const Mat &T)
 }\r
 \r
 \r
+Point2f PlaneWarper::warp(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T)\r
+{\r
+    projector_.setCameraParams(K, R, T);\r
+    Point2f uv;\r
+    projector_.mapForward(pt.x, pt.y, uv.x, uv.y);\r
+    return uv;\r
+}\r
+\r
+\r
 Rect PlaneWarper::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap)\r
 {\r
     projector_.setCameraParams(K, R, T);\r