fixed some more compile errors and test failures

This commit is contained in:
Vadim Pisarevsky
2014-10-17 14:22:02 +04:00
parent 48a860a335
commit c422bdc3f8
16 changed files with 165 additions and 136 deletions

View File

@@ -59,100 +59,60 @@ Detects keypoints in an image (first variant) or image set (second variant).
:param masks: Masks for each input image specifying where to look for keypoints (optional). ``masks[i]`` is a mask for ``images[i]``.
FeatureDetector::create
-----------------------
Creates a feature detector by its name.
.. ocv:function:: Ptr<FeatureDetector> FeatureDetector::create( const String& detectorType )
.. ocv:pyfunction:: cv2.FeatureDetector_create(detectorType) -> retval
:param detectorType: Feature detector type.
The following detector types are supported:
* ``"FAST"`` -- :ocv:class:`FastFeatureDetector`
* ``"ORB"`` -- :ocv:class:`ORB`
* ``"BRISK"`` -- :ocv:class:`BRISK`
* ``"MSER"`` -- :ocv:class:`MSER`
* ``"GFTT"`` -- :ocv:class:`GoodFeaturesToTrackDetector`
* ``"HARRIS"`` -- :ocv:class:`GoodFeaturesToTrackDetector` with Harris detector enabled
* ``"SimpleBlob"`` -- :ocv:class:`SimpleBlobDetector`
FastFeatureDetector
-------------------
.. ocv:class:: FastFeatureDetector : public FeatureDetector
.. ocv:class:: FastFeatureDetector : public Feature2D
Wrapping class for feature detection using the
:ocv:func:`FAST` method. ::
class FastFeatureDetector : public FeatureDetector
class FastFeatureDetector : public Feature2D
{
public:
FastFeatureDetector( int threshold=1, bool nonmaxSuppression=true, type=FastFeatureDetector::TYPE_9_16 );
virtual void read( const FileNode& fn );
virtual void write( FileStorage& fs ) const;
protected:
...
static Ptr<FastFeatureDetector> create( int threshold=1, bool nonmaxSuppression=true, type=FastFeatureDetector::TYPE_9_16 );
};
GoodFeaturesToTrackDetector
GFTTDetector
---------------------------
.. ocv:class:: GoodFeaturesToTrackDetector : public FeatureDetector
.. ocv:class:: GFTTDetector : public FeatureDetector
Wrapping class for feature detection using the
:ocv:func:`goodFeaturesToTrack` function. ::
class GoodFeaturesToTrackDetector : public FeatureDetector
class GFTTDetector : public Feature2D
{
public:
class Params
{
public:
Params( int maxCorners=1000, double qualityLevel=0.01,
double minDistance=1., int blockSize=3,
bool useHarrisDetector=false, double k=0.04 );
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
int maxCorners;
double qualityLevel;
double minDistance;
int blockSize;
bool useHarrisDetector;
double k;
};
GoodFeaturesToTrackDetector( const GoodFeaturesToTrackDetector::Params& params=
GoodFeaturesToTrackDetector::Params() );
GoodFeaturesToTrackDetector( int maxCorners, double qualityLevel,
double minDistance, int blockSize=3,
bool useHarrisDetector=false, double k=0.04 );
virtual void read( const FileNode& fn );
virtual void write( FileStorage& fs ) const;
protected:
...
enum { USE_HARRIS_DETECTOR=10000 };
static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01,
double minDistance=1, int blockSize=3,
bool useHarrisDetector=false, double k=0.04 );
};
MserFeatureDetector
MSER
-------------------
.. ocv:class:: MserFeatureDetector : public FeatureDetector
.. ocv:class:: MSER : public Feature2D
Wrapping class for feature detection using the
:ocv:class:`MSER` class. ::
Maximally stable region detector ::
class MserFeatureDetector : public FeatureDetector
class MSER : public Feature2D
{
public:
MserFeatureDetector( CvMSERParams params=cvMSERParams() );
MserFeatureDetector( int delta, int minArea, int maxArea,
double maxVariation, double minDiversity,
int maxEvolution, double areaThreshold,
double minMargin, int edgeBlurSize );
virtual void read( const FileNode& fn );
virtual void write( FileStorage& fs ) const;
protected:
...
enum
{
DELTA=10000, MIN_AREA=10001, MAX_AREA=10002, PASS2_ONLY=10003,
MAX_EVOLUTION=10004, AREA_THRESHOLD=10005,
MIN_MARGIN=10006, EDGE_BLUR_SIZE=10007
};
//! the full constructor
static Ptr<MSER> create( int _delta=5, int _min_area=60, int _max_area=14400,
double _max_variation=0.25, double _min_diversity=.2,
int _max_evolution=200, double _area_threshold=1.01,
double _min_margin=0.003, int _edge_blur_size=5 );
virtual void detectRegions( InputArray image,
std::vector<std::vector<Point> >& msers,
std::vector<Rect>& bboxes ) = 0;
};
SimpleBlobDetector
@@ -189,10 +149,8 @@ Class for extracting blobs from an image. ::
float minConvexity, maxConvexity;
};
SimpleBlobDetector(const SimpleBlobDetector::Params &parameters = SimpleBlobDetector::Params());
protected:
...
static Ptr<SimpleBlobDetector> create(const SimpleBlobDetector::Params
&parameters = SimpleBlobDetector::Params());
};
The class implements a simple algorithm for extracting blobs from an image:

View File

@@ -14,11 +14,6 @@ Detects corners using the FAST algorithm
.. ocv:function:: void FAST( InputArray image, vector<KeyPoint>& keypoints, int threshold, bool nonmaxSuppression=true )
.. ocv:function:: void FAST( InputArray image, vector<KeyPoint>& keypoints, int threshold, bool nonmaxSuppression, int type )
.. ocv:pyfunction:: cv2.FastFeatureDetector([, threshold[, nonmaxSuppression]]) -> <FastFeatureDetector object>
.. ocv:pyfunction:: cv2.FastFeatureDetector(threshold, nonmaxSuppression, type) -> <FastFeatureDetector object>
.. ocv:pyfunction:: cv2.FastFeatureDetector.detect(image[, mask]) -> keypoints
:param image: grayscale image where keypoints (corners) are detected.
:param keypoints: keypoints detected on the image.
@@ -55,7 +50,7 @@ Maximally stable extremal region extractor. ::
// runs the extractor on the specified image; returns the MSERs,
// each encoded as a contour (vector<Point>, see findContours)
// the optional mask marks the area where MSERs are searched for
void operator()( const Mat& image, vector<vector<Point> >& msers, const Mat& mask ) const;
void detectRegions( InputArray image, vector<vector<Point> >& msers, vector<Rect>& bboxes ) const;
};
The class encapsulates all the parameters of the MSER extraction algorithm (see

View File

@@ -164,7 +164,13 @@ class CV_EXPORTS_W ORB : public Feature2D
{
public:
// the size of the signature in bytes
enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };
enum
{
kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1,
NFEATURES=10000, SCALE_FACTOR=10001, NLEVELS=10002,
EDGE_THRESHOLD=10003, FIRST_LEVEL=10004, WTA_K=10005,
SCORE_TYPE=10006, PATCH_SIZE=10007, FAST_THRESHOLD=10008
};
CV_WRAP static Ptr<ORB> create(int nfeatures = 500, float scaleFactor = 1.2f, int nlevels = 8, int edgeThreshold = 31,
int firstLevel = 0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold = 20);

View File

@@ -55,6 +55,24 @@ public:
{
}
void set(int prop, double value)
{
if( prop == USE_HARRIS_DETECTOR )
useHarrisDetector = value != 0;
else
CV_Error(Error::StsBadArg, "");
}
double get(int prop) const
{
double value = 0;
if( prop == USE_HARRIS_DETECTOR )
value = useHarrisDetector;
else
CV_Error(Error::StsBadArg, "");
return value;
}
void detect( InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask )
{
std::vector<Point2f> corners;

View File

@@ -100,12 +100,12 @@ ocl_ICAngles(const UMat& imgbuf, const UMat& layerinfo,
static bool
ocl_computeOrbDescriptors(const UMat& imgbuf, const UMat& layerInfo,
const UMat& keypoints, UMat& desc, const UMat& pattern,
int nkeypoints, int dsize, int WTA_K)
int nkeypoints, int dsize, int wta_k)
{
size_t globalSize[] = {nkeypoints};
ocl::Kernel desc_ker("ORB_computeDescriptor", ocl::features2d::orb_oclsrc,
format("-D ORB_DESCRIPTORS -D WTA_K=%d", WTA_K));
format("-D ORB_DESCRIPTORS -D wta_k=%d", wta_k));
if( desc_ker.empty() )
return false;
@@ -209,7 +209,7 @@ static void ICAngles(const Mat& img, const std::vector<Rect>& layerinfo,
static void
computeOrbDescriptors( const Mat& imagePyramid, const std::vector<Rect>& layerInfo,
const std::vector<float>& layerScale, std::vector<KeyPoint>& keypoints,
Mat& descriptors, const std::vector<Point>& _pattern, int dsize, int WTA_K )
Mat& descriptors, const std::vector<Point>& _pattern, int dsize, int wta_k )
{
int step = (int)imagePyramid.step;
int j, i, nkeypoints = (int)keypoints.size();
@@ -248,7 +248,7 @@ computeOrbDescriptors( const Mat& imagePyramid, const std::vector<Rect>& layerIn
center[iy*step + ix+1]*x*(1-y) + center[(iy+1)*step + ix+1]*x*y))
#endif
if( WTA_K == 2 )
if( wta_k == 2 )
{
for (i = 0; i < dsize; ++i, pattern += 16)
{
@@ -273,7 +273,7 @@ computeOrbDescriptors( const Mat& imagePyramid, const std::vector<Rect>& layerIn
desc[i] = (uchar)val;
}
}
else if( WTA_K == 3 )
else if( wta_k == 3 )
{
for (i = 0; i < dsize; ++i, pattern += 12)
{
@@ -293,7 +293,7 @@ computeOrbDescriptors( const Mat& imagePyramid, const std::vector<Rect>& layerIn
desc[i] = (uchar)val;
}
}
else if( WTA_K == 4 )
else if( wta_k == 4 )
{
for (i = 0; i < dsize; ++i, pattern += 16)
{
@@ -334,7 +334,7 @@ computeOrbDescriptors( const Mat& imagePyramid, const std::vector<Rect>& layerIn
}
}
else
CV_Error( Error::StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." );
CV_Error( Error::StsBadSize, "Wrong wta_k. It can be only 2, 3 or 4." );
#undef GET_VALUE
}
}
@@ -652,10 +652,60 @@ public:
explicit ORB_Impl(int _nfeatures, float _scaleFactor, int _nlevels, int _edgeThreshold,
int _firstLevel, int _WTA_K, int _scoreType, int _patchSize, int _fastThreshold) :
nfeatures(_nfeatures), scaleFactor(_scaleFactor), nlevels(_nlevels),
edgeThreshold(_edgeThreshold), firstLevel(_firstLevel), WTA_K(_WTA_K),
edgeThreshold(_edgeThreshold), firstLevel(_firstLevel), wta_k(_WTA_K),
scoreType(_scoreType), patchSize(_patchSize), fastThreshold(_fastThreshold)
{}
void set(int prop, double value)
{
if( prop == NFEATURES )
nfeatures = cvRound(value);
else if( prop == SCALE_FACTOR )
scaleFactor = value;
else if( prop == NLEVELS )
nlevels = cvRound(value);
else if( prop == EDGE_THRESHOLD )
edgeThreshold = cvRound(value);
else if( prop == FIRST_LEVEL )
firstLevel = cvRound(value);
else if( prop == WTA_K )
wta_k = cvRound(value);
else if( prop == SCORE_TYPE )
scoreType = cvRound(value);
else if( prop == PATCH_SIZE )
patchSize = cvRound(value);
else if( prop == FAST_THRESHOLD )
fastThreshold = cvRound(value);
else
CV_Error(Error::StsBadArg, "");
}
double get(int prop) const
{
double value = 0;
if( prop == NFEATURES )
value = nfeatures;
else if( prop == SCALE_FACTOR )
value = scaleFactor;
else if( prop == NLEVELS )
value = nlevels;
else if( prop == EDGE_THRESHOLD )
value = edgeThreshold;
else if( prop == FIRST_LEVEL )
value = firstLevel;
else if( prop == WTA_K )
value = wta_k;
else if( prop == SCORE_TYPE )
value = scoreType;
else if( prop == PATCH_SIZE )
value = patchSize;
else if( prop == FAST_THRESHOLD )
value = fastThreshold;
else
CV_Error(Error::StsBadArg, "");
return value;
}
// returns the descriptor size in bytes
int descriptorSize() const;
// returns the descriptor type
@@ -674,7 +724,7 @@ protected:
int nlevels;
int edgeThreshold;
int firstLevel;
int WTA_K;
int wta_k;
int scoreType;
int patchSize;
int fastThreshold;
@@ -1095,14 +1145,14 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
makeRandomPattern(patchSize, patternbuf, npoints);
}
CV_Assert( WTA_K == 2 || WTA_K == 3 || WTA_K == 4 );
CV_Assert( wta_k == 2 || wta_k == 3 || wta_k == 4 );
if( WTA_K == 2 )
if( wta_k == 2 )
std::copy(pattern0, pattern0 + npoints, std::back_inserter(pattern));
else
{
int ntuples = descriptorSize()*4;
initializeOrbPattern(pattern0, pattern, ntuples, WTA_K, npoints);
initializeOrbPattern(pattern0, pattern, ntuples, wta_k, npoints);
}
for( level = 0; level < nLevels; level++ )
@@ -1125,23 +1175,23 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
UMat udescriptors = _descriptors.getUMat();
useOCL = ocl_computeOrbDescriptors(uimagePyramid, ulayerInfo,
ukeypoints, udescriptors, upattern,
nkeypoints, dsize, WTA_K);
nkeypoints, dsize, wta_k);
}
if( !useOCL )
{
Mat descriptors = _descriptors.getMat();
computeOrbDescriptors(imagePyramid, layerInfo, layerScale,
keypoints, descriptors, pattern, dsize, WTA_K);
keypoints, descriptors, pattern, dsize, wta_k);
}
}
}
Ptr<ORB> ORB::create(int nfeatures, float scaleFactor, int nlevels, int edgeThreshold,
int firstLevel, int WTA_K, int scoreType, int patchSize, int fastThreshold)
int firstLevel, int wta_k, int scoreType, int patchSize, int fastThreshold)
{
return makePtr<ORB_Impl>(nfeatures, scaleFactor, nlevels, edgeThreshold,
firstLevel, WTA_K, scoreType, patchSize, fastThreshold);
firstLevel, wta_k, scoreType, patchSize, fastThreshold);
}
}

View File

@@ -267,7 +267,9 @@ TEST( Features2d_Detector_GFTT, regression )
TEST( Features2d_Detector_Harris, regression )
{
CV_FeatureDetectorTest test( "detector-harris", GFTTDetector::create(1000, 0.01, 1, 3, true, 0.04));
Ptr<FeatureDetector> gftt = GFTTDetector::create();
gftt->set(GFTTDetector::USE_HARRIS_DETECTOR, 1);
CV_FeatureDetectorTest test( "detector-harris", gftt);
test.safe_run();
}

View File

@@ -133,13 +133,16 @@ TEST(Features2d_Detector_Keypoints_FAST, validation)
TEST(Features2d_Detector_Keypoints_HARRIS, validation)
{
CV_FeatureDetectorKeypointsTest test(GFTTDetector::create(1000, 0.01, 1, 3, true, 0.04));
test.safe_run();
}
TEST(Features2d_Detector_Keypoints_GFTT, validation)
{
CV_FeatureDetectorKeypointsTest test(GFTTDetector::create());
Ptr<FeatureDetector> gftt = GFTTDetector::create();
gftt->set(GFTTDetector::USE_HARRIS_DETECTOR, 1);
CV_FeatureDetectorKeypointsTest test(gftt);
test.safe_run();
}