From eaa7fcc3e617c6e11090466d4ebbed0e98bd7c4a Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 13 Aug 2013 18:29:36 +0400 Subject: [PATCH] Boring changes - legacy. --- modules/legacy/src/features2d.cpp | 10 +++++----- modules/legacy/src/kdtree.cpp | 2 +- modules/legacy/src/oneway.cpp | 22 ++++++++++++---------- modules/legacy/src/planardetect.cpp | 15 ++++++++------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/modules/legacy/src/features2d.cpp b/modules/legacy/src/features2d.cpp index 578b73292..f313875ac 100644 --- a/modules/legacy/src/features2d.cpp +++ b/modules/legacy/src/features2d.cpp @@ -73,7 +73,7 @@ cvExtractSURF( const CvArr* _img, const CvArr* _mask, Mat descr; Ptr surf = Algorithm::create("Feature2D.SURF"); - if( surf.empty() ) + if( !surf ) CV_Error(CV_StsNotImplemented, "OpenCV was built without SURF support"); surf->set("hessianThreshold", params.hessianThreshold); @@ -107,10 +107,10 @@ CV_IMPL CvSeq* cvGetStarKeypoints( const CvArr* _img, CvMemStorage* storage, CvStarDetectorParams params ) { - Ptr star = new StarDetector(params.maxSize, params.responseThreshold, - params.lineThresholdProjected, - params.lineThresholdBinarized, - params.suppressNonmaxSize); + Ptr star(new StarDetector(params.maxSize, params.responseThreshold, + params.lineThresholdProjected, + params.lineThresholdBinarized, + params.suppressNonmaxSize)); std::vector kpts; star->detect(cvarrToMat(_img), kpts, Mat()); diff --git a/modules/legacy/src/kdtree.cpp b/modules/legacy/src/kdtree.cpp index a32677b79..418395075 100644 --- a/modules/legacy/src/kdtree.cpp +++ b/modules/legacy/src/kdtree.cpp @@ -172,7 +172,7 @@ public: CV_Error(CV_StsUnsupportedFormat, "dist must be CV_64FC1"); if (CV_MAT_TYPE(type()) != CV_MAT_TYPE(desc->type)) { - tmp_desc = cvCreateMat(desc->rows, desc->cols, type()); + tmp_desc.reset(cvCreateMat(desc->rows, desc->cols, type())); cvConvert(desc, tmp_desc); desc = tmp_desc; } diff --git a/modules/legacy/src/oneway.cpp b/modules/legacy/src/oneway.cpp index 7fa4bee33..43ded8593 100644 --- a/modules/legacy/src/oneway.cpp +++ b/modules/legacy/src/oneway.cpp @@ -1736,7 +1736,7 @@ namespace cv{ { std::vector features; Ptr surf_extractor = FeatureDetector::create("SURF"); - if( surf_extractor.empty() ) + if( !surf_extractor ) CV_Error(CV_StsNotImplemented, "OpenCV was built without SURF support"); surf_extractor->set("hessianThreshold", 1.0); //printf("Extracting SURF features..."); @@ -2186,7 +2186,7 @@ namespace cv{ { clear(); - if( _base.empty() ) + if( !_base ) base = _base; params = _params; @@ -2197,16 +2197,17 @@ namespace cv{ GenericDescriptorMatcher::clear(); prevTrainCount = 0; - if( !base.empty() ) + if( base ) base->clear(); } void OneWayDescriptorMatcher::train() { - if( base.empty() || prevTrainCount < (int)trainPointCollection.keypointCount() ) + if( !base || prevTrainCount < (int)trainPointCollection.keypointCount() ) { - base = new OneWayDescriptorObject( params.patchSize, params.poseCount, params.pcaFilename, - params.trainPath, params.trainImagesList, params.minScale, params.maxScale, params.stepScale ); + base.reset( + new OneWayDescriptorObject( params.patchSize, params.poseCount, params.pcaFilename, + params.trainPath, params.trainImagesList, params.minScale, params.maxScale, params.stepScale )); base->Allocate( (int)trainPointCollection.keypointCount() ); prevTrainCount = (int)trainPointCollection.keypointCount(); @@ -2270,8 +2271,9 @@ namespace cv{ void OneWayDescriptorMatcher::read( const FileNode &fn ) { - base = new OneWayDescriptorObject( params.patchSize, params.poseCount, String (), String (), String (), - params.minScale, params.maxScale, params.stepScale ); + base.reset( + new OneWayDescriptorObject( params.patchSize, params.poseCount, String (), String (), String (), + params.minScale, params.maxScale, params.stepScale )); base->Read (fn); } @@ -2282,12 +2284,12 @@ namespace cv{ bool OneWayDescriptorMatcher::empty() const { - return base.empty() || base->empty(); + return !base || base->empty(); } Ptr OneWayDescriptorMatcher::clone( bool emptyTrainData ) const { - OneWayDescriptorMatcher* matcher = new OneWayDescriptorMatcher( params ); + Ptr matcher = makePtr( params ); if( !emptyTrainData ) { diff --git a/modules/legacy/src/planardetect.cpp b/modules/legacy/src/planardetect.cpp index 2bffea0ed..fa9152d47 100644 --- a/modules/legacy/src/planardetect.cpp +++ b/modules/legacy/src/planardetect.cpp @@ -1240,7 +1240,7 @@ FernDescriptorMatcher::FernDescriptorMatcher( const Params& _params ) params = _params; if( !params.filename.empty() ) { - classifier = new FernClassifier; + classifier = makePtr(); FileStorage fs(params.filename, FileStorage::READ); if( fs.isOpened() ) classifier->read( fs.getFirstTopLevelNode() ); @@ -1260,7 +1260,7 @@ void FernDescriptorMatcher::clear() void FernDescriptorMatcher::train() { - if( classifier.empty() || prevTrainCount < (int)trainPointCollection.keypointCount() ) + if( !classifier || prevTrainCount < (int)trainPointCollection.keypointCount() ) { assert( params.filename.empty() ); @@ -1268,9 +1268,10 @@ void FernDescriptorMatcher::train() for( size_t imgIdx = 0; imgIdx < trainPointCollection.imageCount(); imgIdx++ ) KeyPoint::convert( trainPointCollection.getKeypoints((int)imgIdx), points[imgIdx] ); - classifier = new FernClassifier( points, trainPointCollection.getImages(), std::vector >(), 0, // each points is a class - params.patchSize, params.signatureSize, params.nstructs, params.structSize, - params.nviews, params.compressionMethod, params.patchGenerator ); + classifier.reset( + new FernClassifier( points, trainPointCollection.getImages(), std::vector >(), 0, // each points is a class + params.patchSize, params.signatureSize, params.nstructs, params.structSize, + params.nviews, params.compressionMethod, params.patchGenerator )); } } @@ -1384,12 +1385,12 @@ void FernDescriptorMatcher::write( FileStorage& fs ) const bool FernDescriptorMatcher::empty() const { - return classifier.empty() || classifier->empty(); + return !classifier || classifier->empty(); } Ptr FernDescriptorMatcher::clone( bool emptyTrainData ) const { - FernDescriptorMatcher* matcher = new FernDescriptorMatcher( params ); + Ptr matcher = makePtr( params ); if( !emptyTrainData ) { CV_Error( CV_StsNotImplemented, "deep clone dunctionality is not implemented, because "