Skip to content

Commit 1d77931

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 698f805 + f398261 commit 1d77931

File tree

5 files changed

+48
-65
lines changed

5 files changed

+48
-65
lines changed

modules/xfeatures2d/include/opencv2/xfeatures2d.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@ namespace cv
6767
namespace xfeatures2d
6868
{
6969

70+
71+
/** @brief Class for extracting keypoints and computing descriptors using the Scale Invariant Feature Transform
72+
(SIFT) algorithm by D. Lowe @cite Lowe04 .
73+
*/
74+
class CV_EXPORTS_W SIFT : public Feature2D
75+
{
76+
public:
77+
/**
78+
@param nfeatures The number of best features to retain. The features are ranked by their scores
79+
(measured in SIFT algorithm as the local contrast)
80+
81+
@param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. The
82+
number of octaves is computed automatically from the image resolution.
83+
84+
@param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
85+
(low-contrast) regions. The larger the threshold, the less features are produced by the detector.
86+
87+
@param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
88+
is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
89+
filtered out (more features are retained).
90+
91+
@param sigma The sigma of the Gaussian applied to the input image at the octave \#0. If your image
92+
is captured with a weak camera with soft lenses, you might want to reduce the number.
93+
*/
94+
CV_WRAP static Ptr<SIFT> create(int nfeatures = 0, int nOctaveLayers = 3,
95+
double contrastThreshold = 0.04, double edgeThreshold = 10,
96+
double sigma = 1.6);
97+
};
98+
99+
typedef SIFT SiftFeatureDetector;
100+
typedef SIFT SiftDescriptorExtractor;
101+
102+
70103
//! @addtogroup xfeatures2d_experiment
71104
//! @{
72105

modules/xfeatures2d/include/opencv2/xfeatures2d/nonfree.hpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,6 @@ namespace cv
5050
namespace xfeatures2d
5151
{
5252

53-
//! @addtogroup xfeatures2d_nonfree
54-
//! @{
55-
56-
/** @brief Class for extracting keypoints and computing descriptors using the Scale Invariant Feature Transform
57-
(SIFT) algorithm by D. Lowe @cite Lowe04 .
58-
*/
59-
class CV_EXPORTS_W SIFT : public Feature2D
60-
{
61-
public:
62-
/**
63-
@param nfeatures The number of best features to retain. The features are ranked by their scores
64-
(measured in SIFT algorithm as the local contrast)
65-
66-
@param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. The
67-
number of octaves is computed automatically from the image resolution.
68-
69-
@param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
70-
(low-contrast) regions. The larger the threshold, the less features are produced by the detector.
71-
72-
@param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
73-
is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
74-
filtered out (more features are retained).
75-
76-
@param sigma The sigma of the Gaussian applied to the input image at the octave \#0. If your image
77-
is captured with a weak camera with soft lenses, you might want to reduce the number.
78-
*/
79-
CV_WRAP static Ptr<SIFT> create( int nfeatures = 0, int nOctaveLayers = 3,
80-
double contrastThreshold = 0.04, double edgeThreshold = 10,
81-
double sigma = 1.6);
82-
};
83-
84-
typedef SIFT SiftFeatureDetector;
85-
typedef SIFT SiftDescriptorExtractor;
86-
8753
/** @brief Class for extracting Speeded Up Robust Features from an image @cite Bay06 .
8854
8955
The algorithm parameters:

modules/xfeatures2d/src/freak.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ void FREAK_Impl::buildPattern()
283283
const float dx = patternLookup[orientationPairs[m].i].x-patternLookup[orientationPairs[m].j].x;
284284
const float dy = patternLookup[orientationPairs[m].i].y-patternLookup[orientationPairs[m].j].y;
285285
const float norm_sq = (dx*dx+dy*dy);
286-
orientationPairs[m].weight_dx = int((dx/(norm_sq))*4096.0+0.5);
287-
orientationPairs[m].weight_dy = int((dy/(norm_sq))*4096.0+0.5);
286+
orientationPairs[m].weight_dx = cvRound((dx/(norm_sq))*4096.0);
287+
orientationPairs[m].weight_dy = cvRound((dy/(norm_sq))*4096.0);
288288
}
289289

290290
// build the list of description pairs
@@ -482,7 +482,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
482482
}
483483
else
484484
{
485-
const int scIdx = std::max( (int)(1.0986122886681*sizeCst+0.5) ,0);
485+
const int scIdx = std::max( cvRound(1.0986122886681*sizeCst) ,0);
486486
for( size_t k = keypoints.size(); k--; )
487487
{
488488
kpScaleIdx[k] = scIdx; // equivalent to the formule when the scale is normalized with a constant size of keypoints[k].size=3*SMALLEST_KP_SIZE
@@ -539,10 +539,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
539539

540540
keypoints[k].angle = static_cast<float>(atan2((float)direction1,(float)direction0)*(180.0/CV_PI));//estimate orientation
541541

542-
if(keypoints[k].angle < 0.f)
543-
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)-0.5);
544-
else
545-
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)+0.5);
542+
thetaIdx = cvRound(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0));
546543

547544
if( thetaIdx < 0 )
548545
thetaIdx += FREAK_NB_ORIENTATION;
@@ -596,10 +593,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
596593

597594
keypoints[k].angle = static_cast<float>(atan2((float)direction1,(float)direction0)*(180.0/CV_PI)); //estimate orientation
598595

599-
if(keypoints[k].angle < 0.f)
600-
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)-0.5);
601-
else
602-
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)+0.5);
596+
thetaIdx = cvRound(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0));
603597

604598
if( thetaIdx < 0 )
605599
thetaIdx += FREAK_NB_ORIENTATION;
@@ -671,10 +665,10 @@ imgType FREAK_Impl::meanIntensity( InputArray _image, InputArray _integral,
671665
// expected case:
672666

673667
// calculate borders
674-
const int x_left = int(xf-radius+0.5);
675-
const int y_top = int(yf-radius+0.5);
676-
const int x_right = int(xf+radius+1.5);//integral image is 1px wider
677-
const int y_bottom = int(yf+radius+1.5);//integral image is 1px higher
668+
const int x_left = cvRound(xf-radius);
669+
const int y_top = cvRound(yf-radius);
670+
const int x_right = cvRound(xf+radius+1);//integral image is 1px wider
671+
const int y_bottom = cvRound(yf+radius+1);//integral image is 1px higher
678672
iiType ret_val;
679673

680674
ret_val = integral.at<iiType>(y_bottom,x_right);//bottom right corner

modules/xfeatures2d/src/sift.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ namespace cv
114114
namespace xfeatures2d
115115
{
116116

117-
#ifdef OPENCV_ENABLE_NONFREE
118-
119117
/*!
120118
SIFT implementation.
121119
@@ -1202,14 +1200,5 @@ void SIFT_Impl::detectAndCompute(InputArray _image, InputArray _mask,
12021200
}
12031201
}
12041202

1205-
#else // ! #ifdef OPENCV_ENABLE_NONFREE
1206-
Ptr<SIFT> SIFT::create( int, int, double, double, double )
1207-
{
1208-
CV_Error(Error::StsNotImplemented,
1209-
"This algorithm is patented and is excluded in this configuration; "
1210-
"Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library");
1211-
}
1212-
#endif
1213-
12141203
}
12151204
}

modules/xfeatures2d/test/test_features2d.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ const string IMAGE_FILENAME = "tsukuba.png";
5353

5454
namespace opencv_test { namespace {
5555

56-
#ifdef OPENCV_ENABLE_NONFREE
57-
TEST( Features2d_Detector_SIFT, regression)
56+
TEST( Features2d_Detector_SIFT, regression )
5857
{
5958
CV_FeatureDetectorTest test( "detector-sift", SIFT::create() );
6059
test.safe_run();
6160
}
6261

62+
#ifdef OPENCV_ENABLE_NONFREE
6363
TEST( Features2d_Detector_SURF, regression )
6464
{
6565
CV_FeatureDetectorTest test( "detector-surf", SURF::create() );
@@ -94,14 +94,14 @@ TEST( Features2d_Detector_Harris_Laplace_Affine, regression )
9494
/*
9595
* Descriptors
9696
*/
97-
#ifdef OPENCV_ENABLE_NONFREE
9897
TEST( Features2d_DescriptorExtractor_SIFT, regression )
9998
{
10099
CV_DescriptorExtractorTest<L1<float> > test( "descriptor-sift", 1.0f,
101100
SIFT::create() );
102101
test.safe_run();
103102
}
104103

104+
#ifdef OPENCV_ENABLE_NONFREE
105105
TEST( Features2d_DescriptorExtractor_SURF, regression )
106106
{
107107
#ifdef HAVE_OPENCL
@@ -375,8 +375,9 @@ class CV_DetectPlanarTest : public cvtest::BaseTest
375375
Ptr<Feature2D> f2d;
376376
};
377377

378-
#ifdef OPENCV_ENABLE_NONFREE
379378
TEST(Features2d_SIFTHomographyTest, regression) { CV_DetectPlanarTest test("SIFT", 80, SIFT::create()); test.safe_run(); }
379+
380+
#ifdef OPENCV_ENABLE_NONFREE
380381
TEST(Features2d_SURFHomographyTest, regression) { CV_DetectPlanarTest test("SURF", 80, SURF::create()); test.safe_run(); }
381382
#endif
382383

@@ -441,13 +442,13 @@ class FeatureDetectorUsingMaskTest : public cvtest::BaseTest
441442
Ptr<FeatureDetector> featureDetector_;
442443
};
443444

444-
#ifdef OPENCV_ENABLE_NONFREE
445445
TEST(Features2d_SIFT_using_mask, regression)
446446
{
447447
FeatureDetectorUsingMaskTest test(SIFT::create());
448448
test.safe_run();
449449
}
450450

451+
#ifdef OPENCV_ENABLE_NONFREE
451452
TEST(DISABLED_Features2d_SURF_using_mask, regression)
452453
{
453454
FeatureDetectorUsingMaskTest test(SURF::create());

0 commit comments

Comments
 (0)