Skip to content

Commit 1c105ce

Browse files
committed
Merge pull request #1682 from berak:xfeatueres2d_nonfree
2 parents bcddb16 + c871e23 commit 1c105ce

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

modules/xfeatures2d/include/opencv2/xfeatures2d.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ This section describes experimental algorithms for 2d feature detection.
5151
@defgroup xfeatures2d_nonfree Non-free 2D Features Algorithms
5252
5353
This section describes two popular algorithms for 2d feature detection, SIFT and SURF, that are
54-
known to be patented. Use them at your own risk.
54+
known to be patented. You need to set the OPENCV_ENABLE_NONFREE option in cmake to use those. Use them at your own risk.
5555
5656
@defgroup xfeatures2d_match Experimental 2D Features Matching Algorithm
5757

modules/xfeatures2d/src/sift.cpp

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

115+
#ifdef OPENCV_ENABLE_NONFREE
116+
115117
/*!
116118
SIFT implementation.
117119
@@ -1197,5 +1199,14 @@ void SIFT_Impl::detectAndCompute(InputArray _image, InputArray _mask,
11971199
}
11981200
}
11991201

1202+
#else // ! #ifdef OPENCV_ENABLE_NONFREE
1203+
Ptr<SIFT> SIFT::create( int, int, double, double, double )
1204+
{
1205+
CV_Error(Error::StsNotImplemented,
1206+
"This algorithm is patented and is excluded in this configuration; "
1207+
"Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library");
1208+
}
1209+
#endif
1210+
12001211
}
12011212
}

modules/xfeatures2d/src/surf.cpp

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

118+
#ifdef OPENCV_ENABLE_NONFREE
119+
118120
static const int SURF_ORI_SEARCH_INC = 5;
119121
static const float SURF_ORI_SIGMA = 2.5f;
120122
static const float SURF_DESC_SIGMA = 3.3f;
@@ -1005,6 +1007,16 @@ Ptr<SURF> SURF::create(double _threshold, int _nOctaves, int _nOctaveLayers, boo
10051007
return makePtr<SURF_Impl>(_threshold, _nOctaves, _nOctaveLayers, _extended, _upright);
10061008
}
10071009

1010+
1011+
#else // ! #ifdef OPENCV_ENABLE_NONFREE
1012+
Ptr<SURF> SURF::create(double, int, int, bool, bool)
1013+
{
1014+
CV_Error(Error::StsNotImplemented,
1015+
"This algorithm is patented and is excluded in this configuration; "
1016+
"Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library");
1017+
}
1018+
#endif
1019+
10081020
}
10091021
}
10101022

modules/xfeatures2d/src/surf.cuda.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ void cv::cuda::SURF_CUDA::releaseMemory() { throw_no_cuda(); }
6464

6565
#else // !defined (HAVE_CUDA)
6666

67+
#if (!defined (OPENCV_ENABLE_NONFREE))
68+
#define throw_no_nonfree CV_Error(Error::StsNotImplemented, \
69+
"This algorithm is patented and is excluded in this configuration; " \
70+
"Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library");
71+
72+
cv::cuda::SURF_CUDA::SURF_CUDA() { throw_no_nonfree }
73+
cv::cuda::SURF_CUDA::SURF_CUDA(double, int, int, bool, float, bool) { throw_no_nonfree }
74+
int cv::cuda::SURF_CUDA::descriptorSize() const { throw_no_nonfree }
75+
void cv::cuda::SURF_CUDA::uploadKeypoints(const std::vector<KeyPoint>&, GpuMat&) { throw_no_nonfree }
76+
void cv::cuda::SURF_CUDA::downloadKeypoints(const GpuMat&, std::vector<KeyPoint>&) { throw_no_nonfree }
77+
void cv::cuda::SURF_CUDA::downloadDescriptors(const GpuMat&, std::vector<float>&) { throw_no_nonfree }
78+
void cv::cuda::SURF_CUDA::operator()(const GpuMat&, const GpuMat&, GpuMat&) { throw_no_nonfree }
79+
void cv::cuda::SURF_CUDA::operator()(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool) { throw_no_nonfree }
80+
void cv::cuda::SURF_CUDA::operator()(const GpuMat&, const GpuMat&, std::vector<KeyPoint>&) { throw_no_nonfree }
81+
void cv::cuda::SURF_CUDA::operator()(const GpuMat&, const GpuMat&, std::vector<KeyPoint>&, GpuMat&, bool) { throw_no_nonfree }
82+
void cv::cuda::SURF_CUDA::operator()(const GpuMat&, const GpuMat&, std::vector<KeyPoint>&, std::vector<float>&, bool) { throw_no_nonfree }
83+
void cv::cuda::SURF_CUDA::releaseMemory() { throw_no_nonfree }
84+
85+
#else // OPENCV_ENABLE_NONFREE
86+
6787
namespace cv { namespace cuda { namespace device
6888
{
6989
namespace surf
@@ -431,5 +451,6 @@ void cv::cuda::SURF_CUDA::releaseMemory()
431451
}
432452

433453
#endif // !defined (HAVE_CUDA)
454+
#endif // !defined (OPENCV_ENABLE_NONFREE)
434455
#endif
435456

modules/xfeatures2d/src/surf.ocl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ namespace cv
5757
namespace xfeatures2d
5858
{
5959

60+
#ifdef OPENCV_ENABLE_NONFREE
61+
6062
enum { ORI_SEARCH_INC=5, ORI_LOCAL_SIZE=(360 / ORI_SEARCH_INC) };
6163

6264
static inline int calcSize(int octave, int layer)
@@ -463,6 +465,8 @@ bool SURF_OCL::calcOrientation(UMat &keypoints)
463465
return kerOri.run(2, globalThreads, localThreads, true);
464466
}
465467

468+
#endif // ! #ifdef OPENCV_ENABLE_NONFREE
469+
466470
}
467471
}
468472

0 commit comments

Comments
 (0)