From e559256719ea994c86dd59d8691bb748357f548e Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 24 Jan 2014 19:39:05 +0400 Subject: [PATCH] added cv::GFTTDetector --- modules/features2d/include/opencv2/features2d.hpp | 66 ++++++++++----------- modules/features2d/src/blobdetector.cpp | 33 +---------- modules/features2d/src/brisk.cpp | 6 +- modules/features2d/src/detectors.cpp | 69 +++++++++++++++++----- modules/features2d/src/dynamic.cpp | 10 ++-- modules/features2d/src/fast.cpp | 7 ++- modules/features2d/src/matchers.cpp | 28 +++++---- modules/features2d/src/mser.cpp | 3 +- modules/features2d/src/orb.cpp | 4 +- modules/features2d/src/stardetector.cpp | 4 +- .../nonfree/include/opencv2/nonfree/features2d.hpp | 4 +- modules/nonfree/src/sift.cpp | 4 +- modules/nonfree/src/surf.cpp | 4 +- 13 files changed, 128 insertions(+), 114 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index f43d85f..8f2d056 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -108,7 +108,7 @@ public: * mask Mask specifying where to look for keypoints (optional). Must be a char * matrix with non-zero values in the region of interest. */ - CV_WRAP void detect( const Mat& image, CV_OUT std::vector& keypoints, const Mat& mask=Mat() ) const; + CV_WRAP void detect( InputArray image, CV_OUT std::vector& keypoints, InputArray mask=noArray() ) const; /* * Detect keypoints in an image set. @@ -116,7 +116,7 @@ public: * keypoints Collection of keypoints detected in an input images. keypoints[i] is a set of keypoints detected in an images[i]. * masks Masks for image set. masks[i] is a mask for images[i]. */ - void detect( const std::vector& images, std::vector >& keypoints, const std::vector& masks=std::vector() ) const; + void detect( InputArrayOfArrays images, std::vector >& keypoints, InputArrayOfArrays masks=noArray() ) const; // Return true if detector object is empty CV_WRAP virtual bool empty() const; @@ -125,14 +125,14 @@ public: CV_WRAP static Ptr create( const String& detectorType ); protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const = 0; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const = 0; /* * Remove keypoints that are not in the mask. * Helper function, useful when wrapping a library call for keypoint detection that * does not support a mask argument. */ - static void removeInvalidPoints( const Mat& mask, std::vector& keypoints ); + static void removeInvalidPoints( const Mat & mask, std::vector& keypoints ); }; @@ -253,7 +253,7 @@ public: protected: void computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors ) const; - void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; void computeKeypointsNoOrientation(InputArray image, InputArray mask, std::vector& keypoints) const; void computeDescriptorsAndOrOrientation(InputArray image, InputArray mask, std::vector& keypoints, @@ -338,7 +338,7 @@ public: protected: void computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors ) const; - void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; CV_PROP_RW int nfeatures; CV_PROP_RW double scaleFactor; @@ -470,7 +470,7 @@ public: AlgorithmInfo* info() const; protected: - void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; int delta; int minArea; @@ -506,7 +506,7 @@ public: AlgorithmInfo* info() const; protected: - void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; int maxSize; int responseThreshold; @@ -535,7 +535,7 @@ public: AlgorithmInfo* info() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; int threshold; bool nonmaxSuppression; @@ -551,7 +551,7 @@ public: AlgorithmInfo* info() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; int nfeatures; double qualityLevel; @@ -608,7 +608,7 @@ protected: double confidence; }; - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; virtual void findBlobs(const Mat &image, const Mat &binaryImage, std::vector
¢ers) const; Params params; @@ -627,7 +627,7 @@ public: AlgorithmInfo* info() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; double initFeatureScale; int featureScaleLevels; @@ -664,7 +664,7 @@ public: AlgorithmInfo* info() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; Ptr detector; int maxTotalKeypoints; @@ -686,7 +686,7 @@ public: virtual bool empty() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; Ptr detector; int maxLevel; @@ -747,7 +747,7 @@ public: virtual bool empty() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; private: DynamicAdaptedFeatureDetector& operator=(const DynamicAdaptedFeatureDetector&); @@ -776,7 +776,7 @@ public: virtual Ptr clone() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; int thresh_; bool nonmax_; @@ -799,7 +799,7 @@ public: virtual Ptr clone() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl(InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; double thresh_, init_thresh_, min_thresh_, max_thresh_; }; @@ -816,7 +816,7 @@ public: virtual Ptr clone() const; protected: - virtual void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask=Mat() ) const; + virtual void detectImpl( InputArray image, std::vector& keypoints, InputArray mask=noArray() ) const; double thresh_, init_thresh_, min_thresh_, max_thresh_; }; @@ -1035,29 +1035,29 @@ public: */ // Find one best match for each query descriptor (if mask is empty). CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors, - CV_OUT std::vector& matches, InputArray mask=Mat() ) const; + CV_OUT std::vector& matches, InputArray mask=noArray() ) const; // Find k best matches for each query descriptor (in increasing order of distances). // compactResult is used when mask is not empty. If compactResult is false matches // vector will have the same size as queryDescriptors rows. If compactResult is true // matches vector will not contain matches for fully masked out query descriptors. CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors, CV_OUT std::vector >& matches, int k, - InputArray mask=Mat(), bool compactResult=false ) const; + InputArray mask=noArray(), bool compactResult=false ) const; // Find best matches for each query descriptor which have distance less than // maxDistance (in increasing order of distances). void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors, std::vector >& matches, float maxDistance, - InputArray mask=Mat(), bool compactResult=false ) const; + InputArray mask=noArray(), bool compactResult=false ) const; /* * Group of methods to match descriptors from one image to image set. * See description of similar methods for matching image pair above. */ CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector& matches, - const std::vector& masks=std::vector() ); + const std::vector& masks=std::vector() ); CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector >& matches, int k, - const std::vector& masks=std::vector(), bool compactResult=false ); + const std::vector& masks=std::vector(), bool compactResult=false ); void radiusMatch( InputArray queryDescriptors, std::vector >& matches, float maxDistance, - const std::vector& masks=std::vector(), bool compactResult=false ); + const std::vector& masks=std::vector(), bool compactResult=false ); // Reads matcher object from a file node virtual void read( const FileNode& ); @@ -1102,9 +1102,9 @@ protected: // that the class object has been trained already. Public match methods call these methods // after calling train(). virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, - InputArrayOfArrays masks=std::vector(), bool compactResult=false ) = 0; + InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0; virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector >& matches, float maxDistance, - InputArrayOfArrays masks=std::vector(), bool compactResult=false ) = 0; + InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0; static bool isPossibleMatch( const Mat& mask, int queryIdx, int trainIdx ); static bool isMaskedOut( const std::vector& masks, int queryIdx ); @@ -1139,15 +1139,9 @@ public: AlgorithmInfo* info() const; protected: virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, - InputArrayOfArrays masks=std::vector(), bool compactResult=false ); + InputArrayOfArrays masks=noArray(), bool compactResult=false ); virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector >& matches, float maxDistance, - InputArrayOfArrays masks=std::vector(), bool compactResult=false ); - - bool ocl_knnMatch(InputArray query, InputArray train, std::vector< std::vector > &matches, - int k, int dstType, bool compactResult=false); - bool ocl_radiusMatch(InputArray query, InputArray train, std::vector< std::vector > &matches, - float maxDistance, int dstType, bool compactResult=false); - bool ocl_match(InputArray query, InputArray train, std::vector< std::vector > &matches, int dstType); + InputArrayOfArrays masks=noArray(), bool compactResult=false ); int normType; bool crossCheck; @@ -1183,9 +1177,9 @@ protected: std::vector >& matches ); virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, - InputArrayOfArrays masks=std::vector(), bool compactResult=false ); + InputArrayOfArrays masks=noArray(), bool compactResult=false ); virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector >& matches, float maxDistance, - InputArrayOfArrays masks=std::vector(), bool compactResult=false ); + InputArrayOfArrays masks=noArray(), bool compactResult=false ); Ptr indexParams; Ptr searchParams; diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index 92d50ee..fb7e30f 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -276,7 +276,7 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm #endif } -void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector& keypoints, const cv::Mat&) const +void SimpleBlobDetector::detectImpl(InputArray image, std::vector& keypoints, InputArray) const { //TODO: support mask keypoints.clear(); @@ -284,7 +284,7 @@ void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector > centers; for (double thresh = params.minThreshold; thresh < params.maxThreshold; thresh += params.thresholdStep) @@ -292,20 +292,11 @@ void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector curCenters; findBlobs(grayscaleImage, binarizedImage, curCenters); std::vector < std::vector
> newCenters; for (size_t i = 0; i < curCenters.size(); i++) { -#ifdef DEBUG_BLOB_DETECTOR - // circle(keypointsImage, curCenters[i].location, curCenters[i].radius, Scalar(0,0,255),-1); -#endif - bool isNew = true; for (size_t j = 0; j < centers.size(); j++) { @@ -327,17 +318,9 @@ void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector (1, curCenters[i])); - //centers.push_back(std::vector
(1, curCenters[i])); - } } std::copy(newCenters.begin(), newCenters.end(), std::back_inserter(centers)); - -#ifdef DEBUG_BLOB_DETECTOR - // imshow("binarized", keypointsImage ); - //waitKey(); -#endif } for (size_t i = 0; i < centers.size(); i++) @@ -355,16 +338,4 @@ void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector& keypoints, const Mat& mask) const +BRISK::detectImpl( InputArray image, std::vector& keypoints, InputArray mask) const { - (*this)(image, mask, keypoints); + (*this)(image.getMat(), mask.getMat(), keypoints); } void @@ -2229,7 +2229,7 @@ BriskLayer::halfsample(const cv::Mat& srcimg, cv::Mat& dstimg) CV_Assert(srcimg.cols / 2 == dstimg.cols); CV_Assert(srcimg.rows / 2 == dstimg.rows); - // handle non-SSE case + // handle non-SSE case resize(srcimg, dstimg, dstimg.size(), 0, 0, INTER_AREA); } diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index 63a882d..d3c1f3f 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -51,7 +51,7 @@ namespace cv FeatureDetector::~FeatureDetector() {} -void FeatureDetector::detect( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void FeatureDetector::detect( InputArray image, std::vector& keypoints, InputArray mask ) const { keypoints.clear(); @@ -63,11 +63,29 @@ void FeatureDetector::detect( const Mat& image, std::vector& keypoints detectImpl( image, keypoints, mask ); } -void FeatureDetector::detect(const std::vector& imageCollection, std::vector >& pointCollection, const std::vector& masks ) const +void FeatureDetector::detect(InputArrayOfArrays _imageCollection, std::vector >& pointCollection, + InputArrayOfArrays _masks ) const { + if (_imageCollection.isUMatVector()) + { + std::vector uimageCollection, umasks; + _imageCollection.getUMatVector(uimageCollection); + _masks.getUMatVector(umasks); + + pointCollection.resize( uimageCollection.size() ); + for( size_t i = 0; i < uimageCollection.size(); i++ ) + detect( uimageCollection[i], pointCollection[i], umasks.empty() ? noArray() : umasks[i] ); + + return; + } + + std::vector imageCollection, masks; + _imageCollection.getMatVector(imageCollection); + _masks.getMatVector(masks); + pointCollection.resize( imageCollection.size() ); for( size_t i = 0; i < imageCollection.size(); i++ ) - detect( imageCollection[i], pointCollection[i], masks.empty() ? Mat() : masks[i] ); + detect( imageCollection[i], pointCollection[i], masks.empty() ? noArray() : masks[i] ); } /*void FeatureDetector::read( const FileNode& ) @@ -125,21 +143,37 @@ GFTTDetector::GFTTDetector( int _nfeatures, double _qualityLevel, { } -void GFTTDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask) const +void GFTTDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask) const { - Mat grayImage = image; - if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY ); - std::vector corners; - goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, mask, - blockSize, useHarrisDetector, k ); + + if (_image.isUMat()) + { + UMat ugrayImage; + if( _image.type() != CV_8U ) + cvtColor( _image, ugrayImage, COLOR_BGR2GRAY ); + else + ugrayImage = _image.getUMat(); + + goodFeaturesToTrack( ugrayImage, corners, nfeatures, qualityLevel, minDistance, _mask, + blockSize, useHarrisDetector, k ); + } + else + { + Mat image = _image.getMat(), grayImage = image; + if( image.type() != CV_8U ) + cvtColor( image, grayImage, COLOR_BGR2GRAY ); + + goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, _mask, + blockSize, useHarrisDetector, k ); + } + keypoints.resize(corners.size()); std::vector::const_iterator corner_it = corners.begin(); std::vector::iterator keypoint_it = keypoints.begin(); for( ; corner_it != corners.end(); ++corner_it, ++keypoint_it ) - { *keypoint_it = KeyPoint( *corner_it, (float)blockSize ); - } + } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -157,8 +191,10 @@ DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featur {} -void DenseFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void DenseFeatureDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask ) const { + Mat image = _image.getMat(), mask = _mask.getMat(); + float curScale = static_cast(initFeatureScale); int curStep = initXyStep; int curBound = initImgBound; @@ -271,9 +307,9 @@ public: }; } // namepace -void GridAdaptedFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void GridAdaptedFeatureDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask ) const { - if (image.empty() || maxTotalKeypoints < gridRows * gridCols) + if (_image.empty() || maxTotalKeypoints < gridRows * gridCols) { keypoints.clear(); return; @@ -281,6 +317,8 @@ void GridAdaptedFeatureDetector::detectImpl( const Mat& image, std::vectorempty(); } -void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void PyramidAdaptedFeatureDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask ) const { + Mat image = _image.getMat(), mask = _mask.getMat(); Mat src = image; Mat src_mask = mask; diff --git a/modules/features2d/src/dynamic.cpp b/modules/features2d/src/dynamic.cpp index 6bd6ab4..560005f 100644 --- a/modules/features2d/src/dynamic.cpp +++ b/modules/features2d/src/dynamic.cpp @@ -54,8 +54,10 @@ bool DynamicAdaptedFeatureDetector::empty() const return !adjuster_ || adjuster_->empty(); } -void DynamicAdaptedFeatureDetector::detectImpl(const Mat& image, std::vector& keypoints, const Mat& mask) const +void DynamicAdaptedFeatureDetector::detectImpl(InputArray _image, std::vector& keypoints, InputArray _mask) const { + Mat image = _image.getMat(), mask = _mask.getMat(); + //for oscillation testing bool down = false; bool up = false; @@ -98,7 +100,7 @@ FastAdjuster::FastAdjuster( int init_thresh, bool nonmax, int min_thresh, int ma min_thresh_(min_thresh), max_thresh_(max_thresh) {} -void FastAdjuster::detectImpl(const Mat& image, std::vector& keypoints, const Mat& mask) const +void FastAdjuster::detectImpl(InputArray image, std::vector& keypoints, InputArray mask) const { FastFeatureDetector(thresh_, nonmax_).detect(image, keypoints, mask); } @@ -133,7 +135,7 @@ StarAdjuster::StarAdjuster(double initial_thresh, double min_thresh, double max_ min_thresh_(min_thresh), max_thresh_(max_thresh) {} -void StarAdjuster::detectImpl(const Mat& image, std::vector& keypoints, const Mat& mask) const +void StarAdjuster::detectImpl(InputArray image, std::vector& keypoints, InputArray mask) const { StarFeatureDetector detector_tmp(16, cvRound(thresh_), 10, 8, 3); detector_tmp.detect(image, keypoints, mask); @@ -167,7 +169,7 @@ SurfAdjuster::SurfAdjuster( double initial_thresh, double min_thresh, double max min_thresh_(min_thresh), max_thresh_(max_thresh) {} -void SurfAdjuster::detectImpl(const Mat& image, std::vector& keypoints, const cv::Mat& mask) const +void SurfAdjuster::detectImpl(InputArray image, std::vector& keypoints, InputArray mask) const { Ptr surf = FeatureDetector::create("SURF"); surf->set("hessianThreshold", thresh_); diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index 9e2181c..b3335a0 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -283,10 +283,11 @@ FastFeatureDetector::FastFeatureDetector( int _threshold, bool _nonmaxSuppressio : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type((short)_type) {} -void FastFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void FastFeatureDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask ) const { - Mat grayImage = image; - if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY ); + Mat image = _image.getMat(), mask = _mask.getMat(), grayImage = image; + if( image.type() != CV_8U ) + cvtColor( image, grayImage, COLOR_BGR2GRAY ); FAST( grayImage, keypoints, threshold, nonmaxSuppression, type ); KeyPointsFilter::runByPixelsMask( keypoints, mask ); } diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index b2001d9..f8b98d4 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -891,21 +891,25 @@ Ptr BFMatcher::clone( bool emptyTrainData ) const return matcher; } -bool BFMatcher::ocl_match(InputArray query, InputArray _train, std::vector< std::vector > &matches, int dstType) +static bool ocl_match(InputArray query, InputArray _train, std::vector< std::vector > &matches, int dstType) { UMat trainIdx, distance; - if(!ocl_matchSingle(query, _train, trainIdx, distance, dstType)) return false; - if(!ocl_matchDownload(trainIdx, distance, matches)) return false; + if (!ocl_matchSingle(query, _train, trainIdx, distance, dstType)) + return false; + if (!ocl_matchDownload(trainIdx, distance, matches)) + return false; return true; } -bool BFMatcher::ocl_knnMatch(InputArray query, InputArray _train, std::vector< std::vector > &matches, int k, int dstType, bool compactResult) +static bool ocl_knnMatch(InputArray query, InputArray _train, std::vector< std::vector > &matches, int k, int dstType, bool compactResult) { UMat trainIdx, distance; if (k != 2) return false; - if (!ocl_knnMatchSingle(query, _train, trainIdx, distance, dstType)) return false; - if( !ocl_knnMatchDownload(trainIdx, distance, matches, compactResult) ) return false; + if (!ocl_knnMatchSingle(query, _train, trainIdx, distance, dstType)) + return false; + if (!ocl_knnMatchDownload(trainIdx, distance, matches, compactResult) ) + return false; return true; } @@ -1033,12 +1037,14 @@ void BFMatcher::knnMatchImpl( InputArray _queryDescriptors, std::vector > &matches, +static bool ocl_radiusMatch(InputArray query, InputArray _train, std::vector< std::vector > &matches, float maxDistance, int dstType, bool compactResult) { UMat trainIdx, distance, nMatches; - if(!ocl_radiusMatchSingle(query, _train, trainIdx, distance, nMatches, maxDistance, dstType)) return false; - if(!ocl_radiusMatchDownload(trainIdx, distance, nMatches, matches, compactResult)) return false; + if (!ocl_radiusMatchSingle(query, _train, trainIdx, distance, nMatches, maxDistance, dstType)) + return false; + if (!ocl_radiusMatchDownload(trainIdx, distance, nMatches, matches, compactResult)) + return false; return true; } @@ -1076,14 +1082,14 @@ void BFMatcher::radiusMatchImpl( InputArray _queryDescriptors, std::vector >& dstco } -void MserFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void MserFeatureDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask ) const { + Mat image = _image.getMat(), mask = _mask.getMat(); std::vector > msers; (*this)(image, msers, mask); diff --git a/modules/features2d/src/orb.cpp b/modules/features2d/src/orb.cpp index be06c69..da5dd56 100644 --- a/modules/features2d/src/orb.cpp +++ b/modules/features2d/src/orb.cpp @@ -943,9 +943,9 @@ void ORB::operator()( InputArray _image, InputArray _mask, std::vector } } -void ORB::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask) const +void ORB::detectImpl( InputArray image, std::vector& keypoints, InputArray mask) const { - (*this)(image, mask, keypoints, noArray(), false); + (*this)(image.getMat(), mask.getMat(), keypoints, noArray(), false); } void ORB::computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors) const diff --git a/modules/features2d/src/stardetector.cpp b/modules/features2d/src/stardetector.cpp index 02b999b..1e00ee6 100644 --- a/modules/features2d/src/stardetector.cpp +++ b/modules/features2d/src/stardetector.cpp @@ -426,9 +426,9 @@ StarDetector::StarDetector(int _maxSize, int _responseThreshold, {} -void StarDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const +void StarDetector::detectImpl( InputArray _image, std::vector& keypoints, InputArray _mask ) const { - Mat grayImage = image; + Mat image = _image.getMat(), mask = _mask.getMat(), grayImage = image; if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY ); (*this)(grayImage, keypoints); diff --git a/modules/nonfree/include/opencv2/nonfree/features2d.hpp b/modules/nonfree/include/opencv2/nonfree/features2d.hpp index 88a1731..353d1bf 100644 --- a/modules/nonfree/include/opencv2/nonfree/features2d.hpp +++ b/modules/nonfree/include/opencv2/nonfree/features2d.hpp @@ -87,7 +87,7 @@ public: std::vector& keypoints ) const; protected: - void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask = Mat() ) const; + void detectImpl( InputArray image, std::vector& keypoints, InputArray mask = noArray() ) const; void computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors ) const; CV_PROP_RW int nfeatures; @@ -143,7 +143,7 @@ public: protected: - void detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask = Mat() ) const; + void detectImpl( InputArray image, std::vector& keypoints, InputArray mask = noArray() ) const; void computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors ) const; }; diff --git a/modules/nonfree/src/sift.cpp b/modules/nonfree/src/sift.cpp index 4a36c2d..9032214 100644 --- a/modules/nonfree/src/sift.cpp +++ b/modules/nonfree/src/sift.cpp @@ -818,9 +818,9 @@ void SIFT::operator()(InputArray _image, InputArray _mask, } } -void SIFT::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask) const +void SIFT::detectImpl( InputArray image, std::vector& keypoints, InputArray mask) const { - (*this)(image, mask, keypoints, noArray()); + (*this)(image.getMat(), mask.getMat(), keypoints, noArray()); } void SIFT::computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors) const diff --git a/modules/nonfree/src/surf.cpp b/modules/nonfree/src/surf.cpp index be8d14d..db846bb 100644 --- a/modules/nonfree/src/surf.cpp +++ b/modules/nonfree/src/surf.cpp @@ -979,9 +979,9 @@ void SURF::operator()(InputArray _img, InputArray _mask, } -void SURF::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask) const +void SURF::detectImpl( InputArray image, std::vector& keypoints, InputArray mask) const { - (*this)(image, mask, keypoints, noArray(), false); + (*this)(image.getMat(), mask.getMat(), keypoints, noArray(), false); } void SURF::computeImpl( const Mat& image, std::vector& keypoints, Mat& descriptors) const -- 2.7.4