From: Alexey Spizhevoy Date: Sat, 28 May 2011 06:48:33 +0000 (+0000) Subject: refactored exposure compensators (opencv_stitching) X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~7231 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b4053705d3001ae7df230eb2baec7145d38a8c4;p=platform%2Fupstream%2Fopencv.git refactored exposure compensators (opencv_stitching) --- diff --git a/modules/stitching/exposure_compensate.cpp b/modules/stitching/exposure_compensate.cpp index d91d573..4a923f4 100644 --- a/modules/stitching/exposure_compensate.cpp +++ b/modules/stitching/exposure_compensate.cpp @@ -54,15 +54,23 @@ Ptr ExposureCompensator::createDefault(int type) return new NoExposureCompensator(); if (type == OVERLAP) return new OverlapExposureCompensator(); - if (type == SEGMENT) - return new SegmentExposureCompensator(); CV_Error(CV_StsBadArg, "unsupported exposure compensation method"); return NULL; } +void ExposureCompensator::feed(const vector &corners, const vector &images, + const vector &masks) +{ + vector > level_masks; + for (size_t i = 0; i < masks.size(); ++i) + level_masks.push_back(make_pair(masks[i], 255)); + feed(corners, images, level_masks); +} + + void OverlapExposureCompensator::feed(const vector &corners, const vector &images, - const vector &masks) + const vector > &masks) { CV_Assert(corners.size() == images.size() && images.size() == masks.size()); @@ -84,9 +92,9 @@ void OverlapExposureCompensator::feed(const vector &corners, const vector subimg1 = images[i](Rect(roi.tl() - corners[i], roi.br() - corners[i])); subimg2 = images[j](Rect(roi.tl() - corners[j], roi.br() - corners[j])); - submask1 = masks[i](Rect(roi.tl() - corners[i], roi.br() - corners[i])); - submask2 = masks[j](Rect(roi.tl() - corners[j], roi.br() - corners[j])); - intersect = submask1 & submask2; + submask1 = masks[i].first(Rect(roi.tl() - corners[i], roi.br() - corners[i])); + submask2 = masks[j].first(Rect(roi.tl() - corners[j], roi.br() - corners[j])); + intersect = (submask1 == masks[i].second) & (submask2 == masks[j].second); N(i, j) = N(j, i) = countNonZero(intersect); @@ -127,22 +135,11 @@ void OverlapExposureCompensator::feed(const vector &corners, const vector } } - solve(A, b, gains_); + solve(A, b, gains); } void OverlapExposureCompensator::apply(int index, Point /*corner*/, Mat &image, const Mat &/*mask*/) { - image *= gains_(index, 0); + image *= gains(index, 0); } - - -void SegmentExposureCompensator::feed(const vector &/*corners*/, const vector &/*images*/, - const vector &/*masks*/) -{ -} - - -void SegmentExposureCompensator::apply(int /*index*/, Point /*corner*/, Mat &/*image*/, const Mat &/*mask*/) -{ -} \ No newline at end of file diff --git a/modules/stitching/exposure_compensate.hpp b/modules/stitching/exposure_compensate.hpp index 5112bc5..a4d3cea 100644 --- a/modules/stitching/exposure_compensate.hpp +++ b/modules/stitching/exposure_compensate.hpp @@ -51,8 +51,10 @@ public: enum { NO, OVERLAP, SEGMENT }; static cv::Ptr createDefault(int type); + void feed(const std::vector &corners, const std::vector &images, + const std::vector &masks); virtual void feed(const std::vector &corners, const std::vector &images, - const std::vector &masks) = 0; + const std::vector > &masks) = 0; virtual void apply(int index, cv::Point corner, cv::Mat &image, const cv::Mat &mask) = 0; }; @@ -61,7 +63,7 @@ class NoExposureCompensator : public ExposureCompensator { public: void feed(const std::vector &/*corners*/, const std::vector &/*images*/, - const std::vector &/*masks*/) {}; + const std::vector > &/*masks*/) {}; void apply(int /*index*/, cv::Point /*corner*/, cv::Mat &/*image*/, const cv::Mat &/*mask*/) {}; }; @@ -70,20 +72,10 @@ class OverlapExposureCompensator : public ExposureCompensator { public: void feed(const std::vector &corners, const std::vector &images, - const std::vector &masks); + const std::vector > &masks); void apply(int index, cv::Point corner, cv::Mat &image, const cv::Mat &mask); -private: - cv::Mat_ gains_; -}; - - -class SegmentExposureCompensator : public ExposureCompensator -{ -public: - void feed(const std::vector &corners, const std::vector &images, - const std::vector &masks); - void apply(int index, cv::Point corner, cv::Mat &image, const cv::Mat &mask); + cv::Mat_ gains; }; #endif // __OPENCV_EXPOSURE_COMPENSATE_HPP__ \ No newline at end of file diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index 4c22fb8..bba10a6 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -201,8 +201,6 @@ int parseCmdArgs(int argc, char** argv) expos_comp_type = ExposureCompensator::NO; else if (string(argv[i + 1]) == "overlap") expos_comp_type = ExposureCompensator::OVERLAP; - else if (string(argv[i + 1]) == "segment") - expos_comp_type = ExposureCompensator::SEGMENT; else { cout << "Bad exposure compensation method\n"; diff --git a/modules/stitching/precomp.hpp b/modules/stitching/precomp.hpp index e45a147..1223f92 100644 --- a/modules/stitching/precomp.hpp +++ b/modules/stitching/precomp.hpp @@ -46,14 +46,16 @@ #include "cvconfig.h" #endif +#include +#include +#include #include "opencv2/core/core.hpp" #include "opencv2/core/internal.hpp" #include "opencv2/imgproc/imgproc.hpp" -#include "gcgraph.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/gpu/gpu.hpp" -#include +#include "gcgraph.hpp" #endif