* gridRows Grid rows count.
* gridCols Grid column count.
*/
- CV_WRAP GridAdaptedFeatureDetector( const Ptr<FeatureDetector>& detector=0,
+ CV_WRAP GridAdaptedFeatureDetector( const Ptr<FeatureDetector>& detector=Ptr<FeatureDetector>(),
int maxTotalKeypoints=1000,
int gridRows=4, int gridCols=4 );
class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
{
public:
- CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=new flann::KDTreeIndexParams(),
- const Ptr<flann::SearchParams>& searchParams=new flann::SearchParams() );
+ CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
+ const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
virtual void add( const std::vector<Mat>& descriptors );
virtual void clear();
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<FastFeatureDetector>(1, true, FastFeatureDetector::TYPE_9_16);
makeOffsets(pixel_5_8_, (int)img_.step, 8);
makeOffsets(pixel_9_16_, (int)img_.step, 16);
}
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<FastFeatureDetector>(1, false, FastFeatureDetector::TYPE_9_16);
makeOffsets(pixel_5_8_, (int)img_.step, 8);
makeOffsets(pixel_9_16_, (int)img_.step, 16);
}
{
size_t pos = String("Opponent").size();
String type = descriptorExtractorType.substr(pos);
- return new OpponentColorDescriptorExtractor(DescriptorExtractor::create(type));
+ return makePtr<OpponentColorDescriptorExtractor>(DescriptorExtractor::create(type));
}
return Algorithm::create<DescriptorExtractor>("Feature2D." + descriptorExtractorType);
OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor( const Ptr<DescriptorExtractor>& _descriptorExtractor ) :
descriptorExtractor(_descriptorExtractor)
{
- CV_Assert( !descriptorExtractor.empty() );
+ CV_Assert( descriptorExtractor );
}
static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, std::vector<Mat>& opponentChannels )
bool OpponentColorDescriptorExtractor::empty() const
{
- return descriptorExtractor.empty() || (DescriptorExtractor*)(descriptorExtractor)->empty();
+ return !descriptorExtractor || descriptorExtractor->empty();
}
}
{
if( detectorType.find("Grid") == 0 )
{
- return new GridAdaptedFeatureDetector(FeatureDetector::create(
+ return makePtr<GridAdaptedFeatureDetector>(FeatureDetector::create(
detectorType.substr(strlen("Grid"))));
}
if( detectorType.find("Pyramid") == 0 )
{
- return new PyramidAdaptedFeatureDetector(FeatureDetector::create(
+ return makePtr<PyramidAdaptedFeatureDetector>(FeatureDetector::create(
detectorType.substr(strlen("Pyramid"))));
}
if( detectorType.find("Dynamic") == 0 )
{
- return new DynamicAdaptedFeatureDetector(AdjusterAdapter::create(
+ return makePtr<DynamicAdaptedFeatureDetector>(AdjusterAdapter::create(
detectorType.substr(strlen("Dynamic"))));
}
bool GridAdaptedFeatureDetector::empty() const
{
- return detector.empty() || (FeatureDetector*)detector->empty();
+ return !detector || detector->empty();
}
struct ResponseComparator
bool PyramidAdaptedFeatureDetector::empty() const
{
- return detector.empty() || (FeatureDetector*)detector->empty();
+ return !detector || detector->empty();
}
void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask ) const
bool DynamicAdaptedFeatureDetector::empty() const
{
- return adjuster_.empty() || adjuster_->empty();
+ return !adjuster_ || adjuster_->empty();
}
void DynamicAdaptedFeatureDetector::detectImpl(const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask) const
Ptr<AdjusterAdapter> FastAdjuster::clone() const
{
- Ptr<AdjusterAdapter> cloned_obj = new FastAdjuster( init_thresh_, nonmax_, min_thresh_, max_thresh_ );
+ Ptr<AdjusterAdapter> cloned_obj(new FastAdjuster( init_thresh_, nonmax_, min_thresh_, max_thresh_ ));
return cloned_obj;
}
Ptr<AdjusterAdapter> StarAdjuster::clone() const
{
- Ptr<AdjusterAdapter> cloned_obj = new StarAdjuster( init_thresh_, min_thresh_, max_thresh_ );
+ Ptr<AdjusterAdapter> cloned_obj(new StarAdjuster( init_thresh_, min_thresh_, max_thresh_ ));
return cloned_obj;
}
Ptr<AdjusterAdapter> SurfAdjuster::clone() const
{
- Ptr<AdjusterAdapter> cloned_obj = new SurfAdjuster( init_thresh_, min_thresh_, max_thresh_ );
+ Ptr<AdjusterAdapter> cloned_obj(new SurfAdjuster( init_thresh_, min_thresh_, max_thresh_ ));
return cloned_obj;
}
if( !detectorType.compare( "FAST" ) )
{
- adapter = new FastAdjuster();
+ adapter = makePtr<FastAdjuster>();
}
else if( !detectorType.compare( "STAR" ) )
{
- adapter = new StarAdjuster();
+ adapter = makePtr<StarAdjuster>();
}
else if( !detectorType.compare( "SURF" ) )
{
- adapter = new SurfAdjuster();
+ adapter = makePtr<SurfAdjuster>();
}
return adapter;
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() )
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();
Ptr<DescriptorMatcher> BFMatcher::clone( bool emptyTrainData ) const
{
- BFMatcher* matcher = new BFMatcher(normType, crossCheck);
+ Ptr<BFMatcher> matcher = makePtr<BFMatcher>(normType, crossCheck);
if( !emptyTrainData )
{
matcher->trainDescCollection.resize(trainDescCollection.size());
*/
Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatcherType )
{
- DescriptorMatcher* dm = 0;
+ Ptr<DescriptorMatcher> dm;
if( !descriptorMatcherType.compare( "FlannBased" ) )
{
- dm = new FlannBasedMatcher();
+ dm = makePtr<FlannBasedMatcher>();
}
else if( !descriptorMatcherType.compare( "BruteForce" ) ) // L2
{
- dm = new BFMatcher(NORM_L2);
+ dm = makePtr<BFMatcher>(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<BFMatcher>(int(NORM_L2SQR));
}
else if( !descriptorMatcherType.compare( "BruteForce-L1" ) )
{
- dm = new BFMatcher(NORM_L1);
+ dm = makePtr<BFMatcher>(int(NORM_L1));
}
else if( !descriptorMatcherType.compare("BruteForce-Hamming") ||
!descriptorMatcherType.compare("BruteForce-HammingLUT") )
{
- dm = new BFMatcher(NORM_HAMMING);
+ dm = makePtr<BFMatcher>(int(NORM_HAMMING));
}
else if( !descriptorMatcherType.compare("BruteForce-Hamming(2)") )
{
- dm = new BFMatcher(NORM_HAMMING2);
+ dm = makePtr<BFMatcher>(int(NORM_HAMMING2));
}
else
CV_Error( Error::StsBadArg, "Unknown matcher name" );
FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParams, const Ptr<flann::SearchParams>& _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<Mat>& descriptors )
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<flann::Index>( mergedDescriptors.getDescriptors(), *indexParams );
}
}
void FlannBasedMatcher::read( const FileNode& fn)
{
- if (indexParams.empty())
- indexParams = new flann::IndexParams();
+ if (!indexParams)
+ indexParams = makePtr<flann::IndexParams>();
FileNode ip = fn["indexParams"];
CV_Assert(ip.type() == FileNode::SEQ);
};
}
- if (searchParams.empty())
- searchParams = new flann::SearchParams();
+ if (!searchParams)
+ searchParams = makePtr<flann::SearchParams>();
FileNode sp = fn["searchParams"];
CV_Assert(sp.type() == FileNode::SEQ);
Ptr<DescriptorMatcher> FlannBasedMatcher::clone( bool emptyTrainData ) const
{
- FlannBasedMatcher* matcher = new FlannBasedMatcher(indexParams, searchParams);
+ Ptr<FlannBasedMatcher> matcher = makePtr<FlannBasedMatcher>(indexParams, searchParams);
if( !emptyTrainData )
{
CV_Error( Error::StsNotImplemented, "deep clone functionality is not implemented, because "
Ptr<GenericDescriptorMatcher> descriptorMatcher =
Algorithm::create<GenericDescriptorMatcher>("DescriptorMatcher." + genericDescritptorMatcherType);
- if( !paramsFilename.empty() && !descriptorMatcher.empty() )
+ if( !paramsFilename.empty() && descriptorMatcher )
{
FileStorage fs = FileStorage( paramsFilename, FileStorage::READ );
if( fs.isOpened() )
const Ptr<DescriptorMatcher>& _matcher )
: extractor( _extractor ), matcher( _matcher )
{
- CV_Assert( !extractor.empty() && !matcher.empty() );
+ CV_Assert( extractor && matcher );
}
VectorDescriptorMatcher::~VectorDescriptorMatcher()
bool VectorDescriptorMatcher::empty() const
{
- return extractor.empty() || extractor->empty() ||
- matcher.empty() || matcher->empty();
+ return !extractor || extractor->empty() ||
+ !matcher || matcher->empty();
}
Ptr<GenericDescriptorMatcher> VectorDescriptorMatcher::clone( bool emptyTrainData ) const
{
// TODO clone extractor
- return new VectorDescriptorMatcher( extractor, matcher->clone(emptyTrainData) );
+ return makePtr<VectorDescriptorMatcher>( extractor, matcher->clone(emptyTrainData) );
}
}
void emptyDataTest()
{
- assert( !dextractor.empty() );
+ assert( dextractor );
// One image.
Mat image;
void regressionTest()
{
- assert( !dextractor.empty() );
+ assert( dextractor );
// Read the test image.
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
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 );
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 );
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.
minKeyPointMatchesRatio(_minKeyPointMatchesRatio),
minAngleInliersRatio(_minAngleInliersRatio)
{
- CV_Assert(!featureDetector.empty());
+ CV_Assert(featureDetector);
}
protected:
normType(_normType),
minDescInliersRatio(_minDescInliersRatio)
{
- CV_Assert(!featureDetector.empty());
- CV_Assert(!descriptorExtractor.empty());
+ CV_Assert(featureDetector);
+ CV_Assert(descriptorExtractor);
}
protected:
minKeyPointMatchesRatio(_minKeyPointMatchesRatio),
minScaleInliersRatio(_minScaleInliersRatio)
{
- CV_Assert(!featureDetector.empty());
+ CV_Assert(featureDetector);
}
protected:
normType(_normType),
minDescInliersRatio(_minDescInliersRatio)
{
- CV_Assert(!featureDetector.empty());
- CV_Assert(!descriptorExtractor.empty());
+ CV_Assert(featureDetector);
+ CV_Assert(descriptorExtractor);
}
protected: