From 1eacb485c57a6451481abaf1e0b4a12d1d818431 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 13 Aug 2013 17:30:14 +0400 Subject: [PATCH] Boring changes - features2d. --- modules/features2d/include/opencv2/features2d.hpp | 6 +-- modules/features2d/src/brisk.cpp | 4 +- modules/features2d/src/descriptors.cpp | 6 +-- modules/features2d/src/detectors.cpp | 10 ++--- modules/features2d/src/dynamic.cpp | 14 +++---- modules/features2d/src/evaluation.cpp | 4 +- modules/features2d/src/matchers.cpp | 44 +++++++++++----------- .../test/test_descriptors_regression.cpp | 6 +-- .../features2d/test/test_detectors_regression.cpp | 2 +- modules/features2d/test/test_keypoints.cpp | 2 +- .../test/test_rotation_and_scale_invariance.cpp | 12 +++--- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index 4e3f3b8..af687e3 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -646,7 +646,7 @@ public: * gridRows Grid rows count. * gridCols Grid column count. */ - CV_WRAP GridAdaptedFeatureDetector( const Ptr& detector=0, + CV_WRAP GridAdaptedFeatureDetector( const Ptr& detector=Ptr(), int maxTotalKeypoints=1000, int gridRows=4, int gridCols=4 ); @@ -1143,8 +1143,8 @@ protected: class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher { public: - CV_WRAP FlannBasedMatcher( const Ptr& indexParams=new flann::KDTreeIndexParams(), - const Ptr& searchParams=new flann::SearchParams() ); + CV_WRAP FlannBasedMatcher( const Ptr& indexParams=makePtr(), + const Ptr& searchParams=makePtr() ); virtual void add( const std::vector& descriptors ); virtual void clear(); diff --git a/modules/features2d/src/brisk.cpp b/modules/features2d/src/brisk.cpp index 9e017d5..76bded6 100644 --- a/modules/features2d/src/brisk.cpp +++ b/modules/features2d/src/brisk.cpp @@ -2003,7 +2003,7 @@ BriskLayer::BriskLayer(const cv::Mat& img_in, float scale_in, float offset_in) scale_ = scale_in; offset_ = offset_in; // create an agast detector - fast_9_16_ = new FastFeatureDetector(1, true, FastFeatureDetector::TYPE_9_16); + fast_9_16_ = makePtr(1, true, FastFeatureDetector::TYPE_9_16); makeOffsets(pixel_5_8_, (int)img_.step, 8); makeOffsets(pixel_9_16_, (int)img_.step, 16); } @@ -2025,7 +2025,7 @@ BriskLayer::BriskLayer(const BriskLayer& layer, int mode) offset_ = 0.5f * scale_ - 0.5f; } scores_ = cv::Mat::zeros(img_.rows, img_.cols, CV_8U); - fast_9_16_ = new FastFeatureDetector(1, false, FastFeatureDetector::TYPE_9_16); + fast_9_16_ = makePtr(1, false, FastFeatureDetector::TYPE_9_16); makeOffsets(pixel_5_8_, (int)img_.step, 8); makeOffsets(pixel_9_16_, (int)img_.step, 16); } diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index 4f43403..b79768a 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -99,7 +99,7 @@ Ptr DescriptorExtractor::create(const String& descriptorExt { size_t pos = String("Opponent").size(); String type = descriptorExtractorType.substr(pos); - return new OpponentColorDescriptorExtractor(DescriptorExtractor::create(type)); + return makePtr(DescriptorExtractor::create(type)); } return Algorithm::create("Feature2D." + descriptorExtractorType); @@ -119,7 +119,7 @@ CV_WRAP void Feature2D::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector< OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor( const Ptr& _descriptorExtractor ) : descriptorExtractor(_descriptorExtractor) { - CV_Assert( !descriptorExtractor.empty() ); + CV_Assert( descriptorExtractor ); } static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, std::vector& opponentChannels ) @@ -249,7 +249,7 @@ int OpponentColorDescriptorExtractor::descriptorType() const bool OpponentColorDescriptorExtractor::empty() const { - return descriptorExtractor.empty() || (DescriptorExtractor*)(descriptorExtractor)->empty(); + return !descriptorExtractor || descriptorExtractor->empty(); } } diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index c20d573..63a882d 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -90,19 +90,19 @@ Ptr FeatureDetector::create( const String& detectorType ) { if( detectorType.find("Grid") == 0 ) { - return new GridAdaptedFeatureDetector(FeatureDetector::create( + return makePtr(FeatureDetector::create( detectorType.substr(strlen("Grid")))); } if( detectorType.find("Pyramid") == 0 ) { - return new PyramidAdaptedFeatureDetector(FeatureDetector::create( + return makePtr(FeatureDetector::create( detectorType.substr(strlen("Pyramid")))); } if( detectorType.find("Dynamic") == 0 ) { - return new DynamicAdaptedFeatureDetector(AdjusterAdapter::create( + return makePtr(AdjusterAdapter::create( detectorType.substr(strlen("Dynamic")))); } @@ -190,7 +190,7 @@ GridAdaptedFeatureDetector::GridAdaptedFeatureDetector( const Ptrempty(); + return !detector || detector->empty(); } struct ResponseComparator @@ -295,7 +295,7 @@ PyramidAdaptedFeatureDetector::PyramidAdaptedFeatureDetector( const Ptrempty(); + return !detector || detector->empty(); } void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const diff --git a/modules/features2d/src/dynamic.cpp b/modules/features2d/src/dynamic.cpp index d08434d..6bd6ab4 100644 --- a/modules/features2d/src/dynamic.cpp +++ b/modules/features2d/src/dynamic.cpp @@ -51,7 +51,7 @@ DynamicAdaptedFeatureDetector::DynamicAdaptedFeatureDetector(const Ptrempty(); + return !adjuster_ || adjuster_->empty(); } void DynamicAdaptedFeatureDetector::detectImpl(const Mat& image, std::vector& keypoints, const Mat& mask) const @@ -124,7 +124,7 @@ bool FastAdjuster::good() const Ptr FastAdjuster::clone() const { - Ptr cloned_obj = new FastAdjuster( init_thresh_, nonmax_, min_thresh_, max_thresh_ ); + Ptr cloned_obj(new FastAdjuster( init_thresh_, nonmax_, min_thresh_, max_thresh_ )); return cloned_obj; } @@ -158,7 +158,7 @@ bool StarAdjuster::good() const Ptr StarAdjuster::clone() const { - Ptr cloned_obj = new StarAdjuster( init_thresh_, min_thresh_, max_thresh_ ); + Ptr cloned_obj(new StarAdjuster( init_thresh_, min_thresh_, max_thresh_ )); return cloned_obj; } @@ -195,7 +195,7 @@ bool SurfAdjuster::good() const Ptr SurfAdjuster::clone() const { - Ptr cloned_obj = new SurfAdjuster( init_thresh_, min_thresh_, max_thresh_ ); + Ptr cloned_obj(new SurfAdjuster( init_thresh_, min_thresh_, max_thresh_ )); return cloned_obj; } @@ -205,15 +205,15 @@ Ptr AdjusterAdapter::create( const String& detectorType ) if( !detectorType.compare( "FAST" ) ) { - adapter = new FastAdjuster(); + adapter = makePtr(); } else if( !detectorType.compare( "STAR" ) ) { - adapter = new StarAdjuster(); + adapter = makePtr(); } else if( !detectorType.compare( "SURF" ) ) { - adapter = new SurfAdjuster(); + adapter = makePtr(); } return adapter; diff --git a/modules/features2d/src/evaluation.cpp b/modules/features2d/src/evaluation.cpp index 369ba44..5bde951 100644 --- a/modules/features2d/src/evaluation.cpp +++ b/modules/features2d/src/evaluation.cpp @@ -461,7 +461,7 @@ void cv::evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H keypoints1 = _keypoints1 != 0 ? _keypoints1 : &buf1; keypoints2 = _keypoints2 != 0 ? _keypoints2 : &buf2; - if( (keypoints1->empty() || keypoints2->empty()) && fdetector.empty() ) + if( (keypoints1->empty() || keypoints2->empty()) && !fdetector ) CV_Error( Error::StsBadArg, "fdetector must not be empty when keypoints1 or keypoints2 is empty" ); if( keypoints1->empty() ) @@ -575,7 +575,7 @@ void cv::evaluateGenericDescriptorMatcher( const Mat& img1, const Mat& img2, con if( keypoints1.empty() ) CV_Error( Error::StsBadArg, "keypoints1 must not be empty" ); - if( matches1to2->empty() && dmatcher.empty() ) + if( matches1to2->empty() && !dmatcher ) CV_Error( Error::StsBadArg, "dmatch must not be empty when matches1to2 is empty" ); bool computeKeypoints2ByPrj = keypoints2.empty(); diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 54da183..087c6a7 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -326,7 +326,7 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck ) Ptr BFMatcher::clone( bool emptyTrainData ) const { - BFMatcher* matcher = new BFMatcher(normType, crossCheck); + Ptr matcher = makePtr(normType, crossCheck); if( !emptyTrainData ) { matcher->trainDescCollection.resize(trainDescCollection.size()); @@ -458,31 +458,31 @@ void BFMatcher::radiusMatchImpl( const Mat& queryDescriptors, std::vector DescriptorMatcher::create( const String& descriptorMatcherType ) { - DescriptorMatcher* dm = 0; + Ptr dm; if( !descriptorMatcherType.compare( "FlannBased" ) ) { - dm = new FlannBasedMatcher(); + dm = makePtr(); } else if( !descriptorMatcherType.compare( "BruteForce" ) ) // L2 { - dm = new BFMatcher(NORM_L2); + dm = makePtr(int(NORM_L2)); // anonymous enums can't be template parameters } else if( !descriptorMatcherType.compare( "BruteForce-SL2" ) ) // Squared L2 { - dm = new BFMatcher(NORM_L2SQR); + dm = makePtr(int(NORM_L2SQR)); } else if( !descriptorMatcherType.compare( "BruteForce-L1" ) ) { - dm = new BFMatcher(NORM_L1); + dm = makePtr(int(NORM_L1)); } else if( !descriptorMatcherType.compare("BruteForce-Hamming") || !descriptorMatcherType.compare("BruteForce-HammingLUT") ) { - dm = new BFMatcher(NORM_HAMMING); + dm = makePtr(int(NORM_HAMMING)); } else if( !descriptorMatcherType.compare("BruteForce-Hamming(2)") ) { - dm = new BFMatcher(NORM_HAMMING2); + dm = makePtr(int(NORM_HAMMING2)); } else CV_Error( Error::StsBadArg, "Unknown matcher name" ); @@ -497,8 +497,8 @@ Ptr DescriptorMatcher::create( const String& descriptorMatche FlannBasedMatcher::FlannBasedMatcher( const Ptr& _indexParams, const Ptr& _searchParams ) : indexParams(_indexParams), searchParams(_searchParams), addedDescCount(0) { - CV_Assert( !_indexParams.empty() ); - CV_Assert( !_searchParams.empty() ); + CV_Assert( _indexParams ); + CV_Assert( _searchParams ); } void FlannBasedMatcher::add( const std::vector& descriptors ) @@ -522,17 +522,17 @@ void FlannBasedMatcher::clear() void FlannBasedMatcher::train() { - if( flannIndex.empty() || mergedDescriptors.size() < addedDescCount ) + if( !flannIndex || mergedDescriptors.size() < addedDescCount ) { mergedDescriptors.set( trainDescCollection ); - flannIndex = new flann::Index( mergedDescriptors.getDescriptors(), *indexParams ); + flannIndex = makePtr( mergedDescriptors.getDescriptors(), *indexParams ); } } void FlannBasedMatcher::read( const FileNode& fn) { - if (indexParams.empty()) - indexParams = new flann::IndexParams(); + if (!indexParams) + indexParams = makePtr(); FileNode ip = fn["indexParams"]; CV_Assert(ip.type() == FileNode::SEQ); @@ -570,8 +570,8 @@ void FlannBasedMatcher::read( const FileNode& fn) }; } - if (searchParams.empty()) - searchParams = new flann::SearchParams(); + if (!searchParams) + searchParams = makePtr(); FileNode sp = fn["searchParams"]; CV_Assert(sp.type() == FileNode::SEQ); @@ -725,7 +725,7 @@ bool FlannBasedMatcher::isMaskSupported() const Ptr FlannBasedMatcher::clone( bool emptyTrainData ) const { - FlannBasedMatcher* matcher = new FlannBasedMatcher(indexParams, searchParams); + Ptr matcher = makePtr(indexParams, searchParams); if( !emptyTrainData ) { CV_Error( Error::StsNotImplemented, "deep clone functionality is not implemented, because " @@ -1066,7 +1066,7 @@ Ptr GenericDescriptorMatcher::create( const String& ge Ptr descriptorMatcher = Algorithm::create("DescriptorMatcher." + genericDescritptorMatcherType); - if( !paramsFilename.empty() && !descriptorMatcher.empty() ) + if( !paramsFilename.empty() && descriptorMatcher ) { FileStorage fs = FileStorage( paramsFilename, FileStorage::READ ); if( fs.isOpened() ) @@ -1086,7 +1086,7 @@ VectorDescriptorMatcher::VectorDescriptorMatcher( const Ptr const Ptr& _matcher ) : extractor( _extractor ), matcher( _matcher ) { - CV_Assert( !extractor.empty() && !matcher.empty() ); + CV_Assert( extractor && matcher ); } VectorDescriptorMatcher::~VectorDescriptorMatcher() @@ -1152,14 +1152,14 @@ void VectorDescriptorMatcher::write (FileStorage& fs) const bool VectorDescriptorMatcher::empty() const { - return extractor.empty() || extractor->empty() || - matcher.empty() || matcher->empty(); + return !extractor || extractor->empty() || + !matcher || matcher->empty(); } Ptr VectorDescriptorMatcher::clone( bool emptyTrainData ) const { // TODO clone extractor - return new VectorDescriptorMatcher( extractor, matcher->clone(emptyTrainData) ); + return makePtr( extractor, matcher->clone(emptyTrainData) ); } } diff --git a/modules/features2d/test/test_descriptors_regression.cpp b/modules/features2d/test/test_descriptors_regression.cpp index 548e818..08eb59e 100644 --- a/modules/features2d/test/test_descriptors_regression.cpp +++ b/modules/features2d/test/test_descriptors_regression.cpp @@ -141,7 +141,7 @@ protected: void emptyDataTest() { - assert( !dextractor.empty() ); + assert( dextractor ); // One image. Mat image; @@ -186,7 +186,7 @@ protected: void regressionTest() { - assert( !dextractor.empty() ); + assert( dextractor ); // Read the test image. string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME; @@ -267,7 +267,7 @@ protected: void run(int) { createDescriptorExtractor(); - if( dextractor.empty() ) + if( !dextractor ) { ts->printf(cvtest::TS::LOG, "Descriptor extractor is empty.\n"); ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); diff --git a/modules/features2d/test/test_detectors_regression.cpp b/modules/features2d/test/test_detectors_regression.cpp index 9a88c42..8f34913 100644 --- a/modules/features2d/test/test_detectors_regression.cpp +++ b/modules/features2d/test/test_detectors_regression.cpp @@ -230,7 +230,7 @@ void CV_FeatureDetectorTest::regressionTest() void CV_FeatureDetectorTest::run( int /*start_from*/ ) { - if( fdetector.empty() ) + if( !fdetector ) { ts->printf( cvtest::TS::LOG, "Feature detector is empty.\n" ); ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); diff --git a/modules/features2d/test/test_keypoints.cpp b/modules/features2d/test/test_keypoints.cpp index c689cd3..e15d4fa 100644 --- a/modules/features2d/test/test_keypoints.cpp +++ b/modules/features2d/test/test_keypoints.cpp @@ -62,7 +62,7 @@ protected: virtual void run(int) { cv::initModule_features2d(); - CV_Assert(!detector.empty()); + CV_Assert(detector); string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME; // Read the test image. diff --git a/modules/features2d/test/test_rotation_and_scale_invariance.cpp b/modules/features2d/test/test_rotation_and_scale_invariance.cpp index dd0e48e..adfe428 100644 --- a/modules/features2d/test/test_rotation_and_scale_invariance.cpp +++ b/modules/features2d/test/test_rotation_and_scale_invariance.cpp @@ -196,7 +196,7 @@ public: minKeyPointMatchesRatio(_minKeyPointMatchesRatio), minAngleInliersRatio(_minAngleInliersRatio) { - CV_Assert(!featureDetector.empty()); + CV_Assert(featureDetector); } protected: @@ -307,8 +307,8 @@ public: normType(_normType), minDescInliersRatio(_minDescInliersRatio) { - CV_Assert(!featureDetector.empty()); - CV_Assert(!descriptorExtractor.empty()); + CV_Assert(featureDetector); + CV_Assert(descriptorExtractor); } protected: @@ -392,7 +392,7 @@ public: minKeyPointMatchesRatio(_minKeyPointMatchesRatio), minScaleInliersRatio(_minScaleInliersRatio) { - CV_Assert(!featureDetector.empty()); + CV_Assert(featureDetector); } protected: @@ -510,8 +510,8 @@ public: normType(_normType), minDescInliersRatio(_minDescInliersRatio) { - CV_Assert(!featureDetector.empty()); - CV_Assert(!descriptorExtractor.empty()); + CV_Assert(featureDetector); + CV_Assert(descriptorExtractor); } protected: -- 2.7.4