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
\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
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
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
\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
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
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
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
{\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
}\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