From f21851f0f468c98b6ecb1bdb5a37b7066dbc817a Mon Sep 17 00:00:00 2001 From: Roman Donchenko <roman.donchenko@itseez.com> Date: Tue, 13 Aug 2013 17:54:12 +0400 Subject: [PATCH] Boring changes - stitching. --- .../include/opencv2/stitching/warpers.hpp | 28 +++++++-------- modules/stitching/perf/perf_stich.cpp | 36 +++++++++---------- modules/stitching/src/blenders.cpp | 8 ++--- modules/stitching/src/exposure_compensate.cpp | 8 ++--- modules/stitching/src/matchers.cpp | 16 ++++----- modules/stitching/src/stitcher.cpp | 24 ++++++------- modules/stitching/test/test_matchers.cpp | 2 +- 7 files changed, 61 insertions(+), 61 deletions(-) diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp index 9d62d356b..37cf84b7c 100644 --- a/modules/stitching/include/opencv2/stitching/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/warpers.hpp @@ -58,33 +58,33 @@ public: class PlaneWarper : public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::PlaneWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::PlaneWarper>(scale); } }; class CylindricalWarper: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::CylindricalWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::CylindricalWarper>(scale); } }; class SphericalWarper: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::SphericalWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::SphericalWarper>(scale); } }; class FisheyeWarper : public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::FisheyeWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::FisheyeWarper>(scale); } }; class StereographicWarper: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::StereographicWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::StereographicWarper>(scale); } }; class CompressedRectilinearWarper: public WarperCreator @@ -95,7 +95,7 @@ public: { a = A; b = B; } - Ptr<detail::RotationWarper> create(float scale) const { return new detail::CompressedRectilinearWarper(scale, a, b); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::CompressedRectilinearWarper>(scale, a, b); } }; class CompressedRectilinearPortraitWarper: public WarperCreator @@ -106,7 +106,7 @@ public: { a = A; b = B; } - Ptr<detail::RotationWarper> create(float scale) const { return new detail::CompressedRectilinearPortraitWarper(scale, a, b); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::CompressedRectilinearPortraitWarper>(scale, a, b); } }; class PaniniWarper: public WarperCreator @@ -117,7 +117,7 @@ public: { a = A; b = B; } - Ptr<detail::RotationWarper> create(float scale) const { return new detail::PaniniWarper(scale, a, b); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::PaniniWarper>(scale, a, b); } }; class PaniniPortraitWarper: public WarperCreator @@ -128,19 +128,19 @@ public: { a = A; b = B; } - Ptr<detail::RotationWarper> create(float scale) const { return new detail::PaniniPortraitWarper(scale, a, b); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::PaniniPortraitWarper>(scale, a, b); } }; class MercatorWarper: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::MercatorWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::MercatorWarper>(scale); } }; class TransverseMercatorWarper: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::TransverseMercatorWarper(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::TransverseMercatorWarper>(scale); } }; @@ -149,21 +149,21 @@ public: class PlaneWarperGpu: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::PlaneWarperGpu(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::PlaneWarperGpu>(scale); } }; class CylindricalWarperGpu: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::CylindricalWarperGpu(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::CylindricalWarperGpu>(scale); } }; class SphericalWarperGpu: public WarperCreator { public: - Ptr<detail::RotationWarper> create(float scale) const { return new detail::SphericalWarperGpu(scale); } + Ptr<detail::RotationWarper> create(float scale) const { return makePtr<detail::SphericalWarperGpu>(scale); } }; #endif diff --git a/modules/stitching/perf/perf_stich.cpp b/modules/stitching/perf/perf_stich.cpp index e42dea968..8cf89651f 100644 --- a/modules/stitching/perf/perf_stich.cpp +++ b/modules/stitching/perf/perf_stich.cpp @@ -34,12 +34,12 @@ PERF_TEST_P(stitch, a123, TEST_DETECTORS) imgs.push_back( imread( getDataPath("stitching/a3.png") ) ); Ptr<detail::FeaturesFinder> featuresFinder = GetParam() == "orb" - ? (detail::FeaturesFinder*)new detail::OrbFeaturesFinder() - : (detail::FeaturesFinder*)new detail::SurfFeaturesFinder(); + ? Ptr<detail::FeaturesFinder>(new detail::OrbFeaturesFinder()) + : Ptr<detail::FeaturesFinder>(new detail::SurfFeaturesFinder()); Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb" - ? new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE) - : new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); + ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE) + : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE); declare.time(30 * 20).iterations(20); @@ -48,7 +48,7 @@ PERF_TEST_P(stitch, a123, TEST_DETECTORS) Stitcher stitcher = Stitcher::createDefault(); stitcher.setFeaturesFinder(featuresFinder); stitcher.setFeaturesMatcher(featuresMatcher); - stitcher.setWarper(new SphericalWarper()); + stitcher.setWarper(makePtr<SphericalWarper>()); stitcher.setRegistrationResol(WORK_MEGAPIX); startTimer(); @@ -72,12 +72,12 @@ PERF_TEST_P(stitch, b12, TEST_DETECTORS) imgs.push_back( imread( getDataPath("stitching/b2.png") ) ); Ptr<detail::FeaturesFinder> featuresFinder = GetParam() == "orb" - ? (detail::FeaturesFinder*)new detail::OrbFeaturesFinder() - : (detail::FeaturesFinder*)new detail::SurfFeaturesFinder(); + ? Ptr<detail::FeaturesFinder>(new detail::OrbFeaturesFinder()) + : Ptr<detail::FeaturesFinder>(new detail::SurfFeaturesFinder()); Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb" - ? new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE) - : new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); + ? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE) + : makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE); declare.time(30 * 20).iterations(20); @@ -86,7 +86,7 @@ PERF_TEST_P(stitch, b12, TEST_DETECTORS) Stitcher stitcher = Stitcher::createDefault(); stitcher.setFeaturesFinder(featuresFinder); stitcher.setFeaturesMatcher(featuresMatcher); - stitcher.setWarper(new SphericalWarper()); + stitcher.setWarper(makePtr<SphericalWarper>()); stitcher.setRegistrationResol(WORK_MEGAPIX); startTimer(); @@ -114,13 +114,13 @@ PERF_TEST_P( match, bestOf2Nearest, TEST_DETECTORS) Ptr<detail::FeaturesMatcher> matcher; if (GetParam() == "surf") { - finder = new detail::SurfFeaturesFinder(); - matcher = new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); + finder = makePtr<detail::SurfFeaturesFinder>(); + matcher = makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE); } else if (GetParam() == "orb") { - finder = new detail::OrbFeaturesFinder(); - matcher = new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE); + finder = makePtr<detail::OrbFeaturesFinder>(); + matcher = makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE); } else { @@ -169,13 +169,13 @@ PERF_TEST_P( matchVector, bestOf2NearestVectorFeatures, testing::Combine( int featuresVectorSize = get<1>(GetParam()); if (detectorName == "surf") { - finder = new detail::SurfFeaturesFinder(); - matcher = new detail::BestOf2NearestMatcher(false, SURF_MATCH_CONFIDENCE); + finder = makePtr<detail::SurfFeaturesFinder>(); + matcher = makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE); } else if (detectorName == "orb") { - finder = new detail::OrbFeaturesFinder(); - matcher = new detail::BestOf2NearestMatcher(false, ORB_MATCH_CONFIDENCE); + finder = makePtr<detail::OrbFeaturesFinder>(); + matcher = makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE); } else { diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index 0043b7348..254c6a149 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -50,13 +50,13 @@ static const float WEIGHT_EPS = 1e-5f; Ptr<Blender> Blender::createDefault(int type, bool try_gpu) { if (type == NO) - return new Blender(); + return makePtr<Blender>(); if (type == FEATHER) - return new FeatherBlender(); + return makePtr<FeatherBlender>(); if (type == MULTI_BAND) - return new MultiBandBlender(try_gpu); + return makePtr<MultiBandBlender>(try_gpu); CV_Error(Error::StsBadArg, "unsupported blending method"); - return NULL; + return Ptr<Blender>(); } diff --git a/modules/stitching/src/exposure_compensate.cpp b/modules/stitching/src/exposure_compensate.cpp index 0a22daeb7..78ce6d371 100644 --- a/modules/stitching/src/exposure_compensate.cpp +++ b/modules/stitching/src/exposure_compensate.cpp @@ -48,13 +48,13 @@ namespace detail { Ptr<ExposureCompensator> ExposureCompensator::createDefault(int type) { if (type == NO) - return new NoExposureCompensator(); + return makePtr<NoExposureCompensator>(); if (type == GAIN) - return new GainCompensator(); + return makePtr<GainCompensator>(); if (type == GAIN_BLOCKS) - return new BlocksGainCompensator(); + return makePtr<BlocksGainCompensator>(); CV_Error(Error::StsBadArg, "unsupported exposure compensation method"); - return NULL; + return Ptr<ExposureCompensator>(); } diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index e8b7bf24f..0ad0c1f1d 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -155,8 +155,8 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat matches_info.matches.clear(); - Ptr<flann::IndexParams> indexParams = new flann::KDTreeIndexParams(); - Ptr<flann::SearchParams> searchParams = new flann::SearchParams(); + Ptr<flann::IndexParams> indexParams = makePtr<flann::KDTreeIndexParams>(); + Ptr<flann::SearchParams> searchParams = makePtr<flann::SearchParams>(); if (features2.descriptors.depth() == CV_8U) { @@ -314,7 +314,7 @@ SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int if (num_octaves_descr == num_octaves && num_layers_descr == num_layers) { surf = Algorithm::create<Feature2D>("Feature2D.SURF"); - if( surf.empty() ) + if( !surf ) CV_Error( Error::StsNotImplemented, "OpenCV was built without SURF support" ); surf->set("hessianThreshold", hess_thresh); surf->set("nOctaves", num_octaves); @@ -325,7 +325,7 @@ SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int detector_ = Algorithm::create<FeatureDetector>("Feature2D.SURF"); extractor_ = Algorithm::create<DescriptorExtractor>("Feature2D.SURF"); - if( detector_.empty() || extractor_.empty() ) + if( !detector_ || !extractor_ ) CV_Error( Error::StsNotImplemented, "OpenCV was built without SURF support" ); detector_->set("hessianThreshold", hess_thresh); @@ -349,7 +349,7 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) { gray_image = image; } - if (surf.empty()) + if (!surf) { detector_->detect(gray_image, features.keypoints); extractor_->compute(gray_image, features.keypoints, features.descriptors); @@ -365,7 +365,7 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) OrbFeaturesFinder::OrbFeaturesFinder(Size _grid_size, int n_features, float scaleFactor, int nlevels) { grid_size = _grid_size; - orb = new ORB(n_features * (99 + grid_size.area())/100/grid_size.area(), scaleFactor, nlevels); + orb = makePtr<ORB>(n_features * (99 + grid_size.area())/100/grid_size.area(), scaleFactor, nlevels); } void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features) @@ -534,12 +534,12 @@ BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, #ifdef HAVE_OPENCV_GPUFEATURES2D if (try_use_gpu && getCudaEnabledDeviceCount() > 0) { - impl_ = new GpuMatcher(match_conf); + impl_ = makePtr<GpuMatcher>(match_conf); } else #endif { - impl_ = new CpuMatcher(match_conf); + impl_ = makePtr<CpuMatcher>(match_conf); } is_thread_safe_ = impl_->isThreadSafe(); diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index 75307209d..00e02b07c 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -53,34 +53,34 @@ Stitcher Stitcher::createDefault(bool try_use_gpu) stitcher.setPanoConfidenceThresh(1); stitcher.setWaveCorrection(true); stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ); - stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(try_use_gpu)); - stitcher.setBundleAdjuster(new detail::BundleAdjusterRay()); + stitcher.setFeaturesMatcher(makePtr<detail::BestOf2NearestMatcher>(try_use_gpu)); + stitcher.setBundleAdjuster(makePtr<detail::BundleAdjusterRay>()); #ifdef HAVE_OPENCV_GPU if (try_use_gpu && gpu::getCudaEnabledDeviceCount() > 0) { #ifdef HAVE_OPENCV_NONFREE - stitcher.setFeaturesFinder(new detail::SurfFeaturesFinderGpu()); + stitcher.setFeaturesFinder(makePtr<detail::SurfFeaturesFinderGpu>()); #else - stitcher.setFeaturesFinder(new detail::OrbFeaturesFinder()); + stitcher.setFeaturesFinder(makePtr<detail::OrbFeaturesFinder>()); #endif - stitcher.setWarper(new SphericalWarperGpu()); - stitcher.setSeamFinder(new detail::GraphCutSeamFinderGpu()); + stitcher.setWarper(makePtr<SphericalWarperGpu>()); + stitcher.setSeamFinder(makePtr<detail::GraphCutSeamFinderGpu>()); } else #endif { #ifdef HAVE_OPENCV_NONFREE - stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder()); + stitcher.setFeaturesFinder(makePtr<detail::SurfFeaturesFinder>()); #else - stitcher.setFeaturesFinder(new detail::OrbFeaturesFinder()); + stitcher.setFeaturesFinder(makePtr<detail::OrbFeaturesFinder>()); #endif - stitcher.setWarper(new SphericalWarper()); - stitcher.setSeamFinder(new detail::GraphCutSeamFinder(detail::GraphCutSeamFinderBase::COST_COLOR)); + stitcher.setWarper(makePtr<SphericalWarper>()); + stitcher.setSeamFinder(makePtr<detail::GraphCutSeamFinder>(detail::GraphCutSeamFinderBase::COST_COLOR)); } - stitcher.setExposureCompensator(new detail::BlocksGainCompensator()); - stitcher.setBlender(new detail::MultiBandBlender(try_use_gpu)); + stitcher.setExposureCompensator(makePtr<detail::BlocksGainCompensator>()); + stitcher.setBlender(makePtr<detail::MultiBandBlender>(try_use_gpu)); return stitcher; } diff --git a/modules/stitching/test/test_matchers.cpp b/modules/stitching/test/test_matchers.cpp index ba5c43ae2..c7f068b7f 100644 --- a/modules/stitching/test/test_matchers.cpp +++ b/modules/stitching/test/test_matchers.cpp @@ -49,7 +49,7 @@ using namespace std; TEST(SurfFeaturesFinder, CanFindInROIs) { - Ptr<detail::FeaturesFinder> finder = new detail::SurfFeaturesFinder(); + Ptr<detail::FeaturesFinder> finder = makePtr<detail::SurfFeaturesFinder>(); Mat img = imread(string(cvtest::TS::ptr()->get_data_path()) + "cv/shared/lena.png"); vector<Rect> rois;