[opencv] 16/19: Made samples build independent from nonfree module.

Mattia Rizzolo mattia at debian.org
Tue Oct 4 17:51:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to annotated tag 2.4.12.3
in repository opencv.

commit 966d35a9fbd5102605c6742f493c405190b8a6cc
Author: Alexander Smorkalov <alexander.smorkalov at itseez.com>
Date:   Wed Oct 14 12:52:32 2015 +0300

    Made samples build independent from nonfree module.
    
    (cherry picked from commit bba8c0beacf34143509b60aaf5321c56b2a21013)
---
 samples/CMakeLists.txt                             | 10 +++-
 samples/c/CMakeLists.txt                           |  2 +-
 samples/c/find_obj.cpp                             | 36 ++++++++++----
 samples/c/find_obj_calonder.cpp                    | 31 +++++++++---
 samples/c/one_way_sample.cpp                       | 30 ++++++++---
 samples/cpp/CMakeLists.txt                         |  5 +-
 samples/cpp/bagofwords_classification.cpp          | 58 ++++++++++++++--------
 samples/cpp/descriptor_extractor_matcher.cpp       | 13 +++--
 samples/cpp/fabmap_sample.cpp                      | 18 ++++++-
 samples/cpp/freak_demo.cpp                         | 28 ++++++++---
 samples/cpp/generic_descriptor_match.cpp           | 26 +++++++---
 samples/cpp/matcher_simple.cpp                     | 22 ++++++--
 .../tutorial_code/features2D/SURF_FlannMatcher.cpp | 27 +++++++---
 .../tutorial_code/features2D/SURF_Homography.cpp   | 29 ++++++++---
 .../tutorial_code/features2D/SURF_descriptor.cpp   | 23 +++++++--
 .../cpp/tutorial_code/features2D/SURF_detector.cpp | 23 +++++++--
 samples/ocl/CMakeLists.txt                         |  5 +-
 samples/ocl/surf_matcher.cpp                       | 27 +++++++---
 18 files changed, 302 insertions(+), 111 deletions(-)

diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
index 1754649..df01dc7 100644
--- a/samples/CMakeLists.txt
+++ b/samples/CMakeLists.txt
@@ -68,8 +68,14 @@ endif()
 
 add_subdirectory(c)
 add_subdirectory(cpp)
-add_subdirectory(ocl)
-add_subdirectory(gpu)
+ocv_check_dependencies(opencv_ocl)
+if (OCV_DEPENDENCIES_FOUND)
+  add_subdirectory(ocl)
+endif()
+ocv_check_dependencies(opencv_gpu)
+if (OCV_DEPENDENCIES_FOUND)
+  add_subdirectory(gpu)
+endif()
 
 #
 # END OF BUILD CASE 2: Build samples with library binaries
diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt
index cb653c7..b26e4ab 100644
--- a/samples/c/CMakeLists.txt
+++ b/samples/c/CMakeLists.txt
@@ -4,7 +4,7 @@
 # ----------------------------------------------------------------------------
 
 SET(OPENCV_C_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc
-    opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree
+    opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo
     opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
 
 ocv_check_dependencies(${OPENCV_C_SAMPLES_REQUIRED_DEPS})
diff --git a/samples/c/find_obj.cpp b/samples/c/find_obj.cpp
index e0431fc..e0ae60c 100644
--- a/samples/c/find_obj.cpp
+++ b/samples/c/find_obj.cpp
@@ -4,19 +4,31 @@
  * Author: Liu Liu
  * liuliu.1987+opencv at gmail.com
  */
-#include "opencv2/objdetect/objdetect.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/calib3d/calib3d.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
-#include "opencv2/imgproc/imgproc_c.h"
-#include "opencv2/legacy/legacy.hpp"
-#include "opencv2/legacy/compat.hpp"
-
-#include <iostream>
-#include <vector>
+
+#include "opencv2/opencv_modules.hpp"
 #include <stdio.h>
 
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/objdetect/objdetect.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/calib3d/calib3d.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
+# include "opencv2/imgproc/imgproc_c.h"
+# include "opencv2/legacy/legacy.hpp"
+# include "opencv2/legacy/compat.hpp"
+
+# include <vector>
+
 using namespace std;
 static void help()
 {
@@ -320,3 +332,5 @@ int main(int argc, char** argv)
 
     return 0;
 }
+
+#endif
diff --git a/samples/c/find_obj_calonder.cpp b/samples/c/find_obj_calonder.cpp
index 02cd266..685e703 100644
--- a/samples/c/find_obj_calonder.cpp
+++ b/samples/c/find_obj_calonder.cpp
@@ -1,12 +1,25 @@
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/core/core.hpp"
-#include "opencv2/imgproc/imgproc.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
-#include "opencv2/legacy/legacy.hpp"
-
+#include "opencv2/opencv_modules.hpp"
 #include <iostream>
-#include <fstream>
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
+    return -1;
+}
+
+#else
+
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/core/core.hpp"
+# include "opencv2/imgproc/imgproc.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
+# include "opencv2/legacy/legacy.hpp"
+
+# include <iostream>
+# include <fstream>
 
 using namespace std;
 using namespace cv;
@@ -164,3 +177,5 @@ int main( int argc, char **argv )
 
     return 0;
 }
+
+#endif
diff --git a/samples/c/one_way_sample.cpp b/samples/c/one_way_sample.cpp
index ad0153b..6db28ba 100644
--- a/samples/c/one_way_sample.cpp
+++ b/samples/c/one_way_sample.cpp
@@ -7,16 +7,28 @@
  *
  */
 
-#include "opencv2/imgproc/imgproc.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/imgproc/imgproc_c.h"
-#include "opencv2/nonfree/nonfree.hpp"
-#include "opencv2/legacy/legacy.hpp"
-#include "opencv2/legacy/compat.hpp"
+#include "opencv2/opencv_modules.hpp"
+#include <stdio.h>
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/imgproc/imgproc.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/imgproc/imgproc_c.h"
+# include "opencv2/nonfree/nonfree.hpp"
+# include "opencv2/legacy/legacy.hpp"
+# include "opencv2/legacy/compat.hpp"
 
 #include <string>
-#include <stdio.h>
 
 static void help()
 {
@@ -116,3 +128,5 @@ Mat DrawCorrespondences(const Mat& img1, const vector<KeyPoint>& features1, cons
 
     return img_corr;
 }
+
+#endif
diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt
index fa52ac4..5eff52a 100644
--- a/samples/cpp/CMakeLists.txt
+++ b/samples/cpp/CMakeLists.txt
@@ -4,8 +4,9 @@
 # ----------------------------------------------------------------------------
 
 SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc
-    opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree
-    opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_videostab)
+    opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo
+    opencv_features2d opencv_calib3d opencv_legacy opencv_contrib
+    opencv_stitching opencv_videostab)
 
 ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
 
diff --git a/samples/cpp/bagofwords_classification.cpp b/samples/cpp/bagofwords_classification.cpp
index db194b5..d351baa 100644
--- a/samples/cpp/bagofwords_classification.cpp
+++ b/samples/cpp/bagofwords_classification.cpp
@@ -1,29 +1,41 @@
 #include "opencv2/opencv_modules.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/imgproc/imgproc.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
-#include "opencv2/ml/ml.hpp"
-#ifdef HAVE_OPENCV_OCL
-#define _OCL_SVM_ 1 //select whether using ocl::svm method or not, default is using
-#include "opencv2/ocl/ocl.hpp"
-#endif
-
-#include <fstream>
 #include <iostream>
-#include <memory>
-#include <functional>
 
-#if defined WIN32 || defined _WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#undef min
-#undef max
-#include "sys/types.h"
-#endif
-#include <sys/stat.h>
+#ifndef HAVE_OPENCV_NONFREE
 
-#define DEBUG_DESC_PROGRESS
+int main(int, char**)
+{
+    std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
+    return -1;
+}
+
+#else
+
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/imgproc/imgproc.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
+# include "opencv2/ml/ml.hpp"
+# ifdef HAVE_OPENCV_OCL
+# define _OCL_SVM_ 1 //select whether using ocl::svm method or not, default is using
+#  include "opencv2/ocl/ocl.hpp"
+# endif
+
+# include <fstream>
+# include <memory>
+# include <functional>
+
+
+# if defined WIN32 || defined _WIN32
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+#  undef min
+#  undef max
+#  include "sys/types.h"
+# endif
+# include <sys/stat.h>
+
+# define DEBUG_DESC_PROGRESS
 
 using namespace cv;
 using namespace std;
@@ -2623,3 +2635,5 @@ int main(int argc, char** argv)
     }
     return 0;
 }
+
+#endif
diff --git a/samples/cpp/descriptor_extractor_matcher.cpp b/samples/cpp/descriptor_extractor_matcher.cpp
index 98c6452..4a9a634 100644
--- a/samples/cpp/descriptor_extractor_matcher.cpp
+++ b/samples/cpp/descriptor_extractor_matcher.cpp
@@ -1,8 +1,11 @@
+#include "opencv2/opencv_modules.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/calib3d/calib3d.hpp"
 #include "opencv2/imgproc/imgproc.hpp"
 #include "opencv2/features2d/features2d.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
+#ifdef HAVE_OPENCV_NONFREE
+# include "opencv2/nonfree/nonfree.hpp"
+#endif
 
 #include <iostream>
 
@@ -17,14 +20,14 @@ static void help(char** argv)
      << "Case1: second image is obtained from the first (given) image using random generated homography matrix\n"
      << argv[0] << " [detectorType] [descriptorType] [matcherType] [matcherFilterType] [image] [evaluate(0 or 1)]\n"
      << "Example of case1:\n"
-     << "./descriptor_extractor_matcher SURF SURF FlannBased NoneFilter cola.jpg 0\n"
+     << "./descriptor_extractor_matcher ORB ORB FlannBased NoneFilter cola.jpg 0\n"
      << "\n"
      << "Case2: both images are given. If ransacReprojThreshold>=0 then homography matrix are calculated\n"
      << argv[0] << " [detectorType] [descriptorType] [matcherType] [matcherFilterType] [image1] [image2] [ransacReprojThreshold]\n"
      << "\n"
      << "Matches are filtered using homography matrix in case1 and case2 (if ransacReprojThreshold>=0)\n"
      << "Example of case2:\n"
-     << "./descriptor_extractor_matcher SURF SURF BruteForce CrossCheckFilter cola1.jpg cola2.jpg 3\n"
+     << "./descriptor_extractor_matcher ORB ORB BruteForce CrossCheckFilter cola1.jpg cola2.jpg 3\n"
      << "\n"
      << "Possible detectorType values: see in documentation on createFeatureDetector().\n"
      << "Possible descriptorType values: see in documentation on createDescriptorExtractor().\n"
@@ -239,7 +242,11 @@ int main(int argc, char** argv)
         return -1;
     }
 
+#ifdef HAVE_OPENCV_NONFREE
     cv::initModule_nonfree();
+#else
+    cout << "Warning: OpenCV is built without nonfree support SIFT, SURF and some other algorithms are not available." << endl;
+#endif
 
     bool isWarpPerspective = argc == 7;
     double ransacReprojThreshold = -1;
diff --git a/samples/cpp/fabmap_sample.cpp b/samples/cpp/fabmap_sample.cpp
index bbe5f2b..25b9dbd 100644
--- a/samples/cpp/fabmap_sample.cpp
+++ b/samples/cpp/fabmap_sample.cpp
@@ -49,9 +49,21 @@
 //
 //M*/
 
+#include "opencv2/opencv_modules.hpp"
+#include <iostream>
 
-#include "opencv2/opencv.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
+    return -1;
+}
+
+#else
+
+# include "opencv2/opencv.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
 
 using namespace cv;
 using namespace std;
@@ -212,3 +224,5 @@ int main(int argc, char * argv[]) {
 
     return 0;
 }
+
+#endif
diff --git a/samples/cpp/freak_demo.cpp b/samples/cpp/freak_demo.cpp
index 6dbd921..6a94159 100644
--- a/samples/cpp/freak_demo.cpp
+++ b/samples/cpp/freak_demo.cpp
@@ -34,15 +34,27 @@
 //  or tort (including negligence or otherwise) arising in any way out of
 //  the use of this software, even if advised of the possibility of such damage.
 
+#include "opencv2/opencv_modules.hpp"
 #include <iostream>
-#include <string>
-#include <vector>
 
-#include <opencv2/core/core.hpp>
-#include <opencv2/highgui/highgui.hpp>
-#include <opencv2/features2d/features2d.hpp>
-#include <opencv2/nonfree/features2d.hpp>
-#include <opencv2/legacy/legacy.hpp>
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
+    return -1;
+}
+
+#else
+
+# include <string>
+# include <vector>
+
+# include <opencv2/core/core.hpp>
+# include <opencv2/highgui/highgui.hpp>
+# include <opencv2/features2d/features2d.hpp>
+# include <opencv2/nonfree/features2d.hpp>
+# include <opencv2/legacy/legacy.hpp>
 
 using namespace cv;
 
@@ -126,3 +138,5 @@ int main( int argc, char** argv ) {
     imshow("matches", imgMatch);
     waitKey(0);
 }
+
+#endif
diff --git a/samples/cpp/generic_descriptor_match.cpp b/samples/cpp/generic_descriptor_match.cpp
index 1cb03c6..198f404 100644
--- a/samples/cpp/generic_descriptor_match.cpp
+++ b/samples/cpp/generic_descriptor_match.cpp
@@ -1,11 +1,23 @@
-#include "opencv2/calib3d/calib3d.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/imgproc/imgproc.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
-
+#include "opencv2/opencv_modules.hpp"
 #include <cstdio>
 
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/opencv_modules.hpp"
+# include "opencv2/calib3d/calib3d.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/imgproc/imgproc.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
+
 using namespace cv;
 
 static void help()
@@ -91,3 +103,5 @@ Mat DrawCorrespondences(const Mat& img1, const vector<KeyPoint>& features1, cons
 
     return img_corr;
 }
+
+#endif
diff --git a/samples/cpp/matcher_simple.cpp b/samples/cpp/matcher_simple.cpp
index 42e89fb..2df32eb 100644
--- a/samples/cpp/matcher_simple.cpp
+++ b/samples/cpp/matcher_simple.cpp
@@ -1,8 +1,20 @@
+#include "opencv2/opencv_modules.hpp"
 #include <stdio.h>
-#include "opencv2/core/core.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/core/core.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
 
 using namespace cv;
 
@@ -56,3 +68,5 @@ int main(int argc, char** argv)
 
     return 0;
 }
+
+#endif
diff --git a/samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp b/samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp
index 0934630..9cc1776 100644
--- a/samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp
+++ b/samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp
@@ -4,12 +4,23 @@
  * @author A. Huaman
  */
 
+#include "opencv2/opencv_modules.hpp"
 #include <stdio.h>
-#include <iostream>
-#include "opencv2/core/core.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/nonfree/features2d.hpp"
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/core/core.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/nonfree/features2d.hpp"
 
 using namespace cv;
 
@@ -28,7 +39,7 @@ int main( int argc, char** argv )
   Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
 
   if( !img_1.data || !img_2.data )
-  { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
+  { printf(" --(!) Error reading images \n"); return -1; }
 
   //-- Step 1: Detect the keypoints using SURF Detector
   int minHessian = 400;
@@ -97,4 +108,6 @@ int main( int argc, char** argv )
  * @function readme
  */
 void readme()
-{ std::cout << " Usage: ./SURF_FlannMatcher <img1> <img2>" << std::endl; }
+{ printf(" Usage: ./SURF_FlannMatcher <img1> <img2>\n"); }
+
+#endif
\ No newline at end of file
diff --git a/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp b/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp
index 4b29638..11dd074 100644
--- a/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp
+++ b/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp
@@ -4,13 +4,24 @@
  * @author A. Huaman
  */
 
+#include "opencv2/opencv_modules.hpp"
 #include <stdio.h>
-#include <iostream>
-#include "opencv2/core/core.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/calib3d/calib3d.hpp"
-#include "opencv2/nonfree/features2d.hpp"
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/core/core.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/calib3d/calib3d.hpp"
+# include "opencv2/nonfree/features2d.hpp"
 
 using namespace cv;
 
@@ -29,7 +40,7 @@ int main( int argc, char** argv )
   Mat img_scene = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
 
   if( !img_object.data || !img_scene.data )
-  { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
+  { printf(" --(!) Error reading images \n"); return -1; }
 
   //-- Step 1: Detect the keypoints using SURF Detector
   int minHessian = 400;
@@ -121,4 +132,6 @@ int main( int argc, char** argv )
  * @function readme
  */
 void readme()
-{ std::cout << " Usage: ./SURF_Homography <img1> <img2>" << std::endl; }
+{ printf(" Usage: ./SURF_Homography <img1> <img2>\n"); }
+
+#endif
\ No newline at end of file
diff --git a/samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp b/samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp
index 527e5dd..2fcd884 100644
--- a/samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp
+++ b/samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp
@@ -4,12 +4,23 @@
  * @author A. Huaman
  */
 
+#include "opencv2/opencv_modules.hpp"
 #include <stdio.h>
-#include <iostream>
-#include "opencv2/core/core.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/nonfree/features2d.hpp"
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    printf("The sample requires nonfree module that is not available in your OpenCV distribution.\n");
+    return -1;
+}
+
+#else
+
+# include "opencv2/core/core.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/nonfree/features2d.hpp"
 
 using namespace cv;
 
@@ -70,3 +81,5 @@ int main( int argc, char** argv )
  */
 void readme()
 { std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; }
+
+#endif
\ No newline at end of file
diff --git a/samples/cpp/tutorial_code/features2D/SURF_detector.cpp b/samples/cpp/tutorial_code/features2D/SURF_detector.cpp
index 2625f1d..21dc45a 100644
--- a/samples/cpp/tutorial_code/features2D/SURF_detector.cpp
+++ b/samples/cpp/tutorial_code/features2D/SURF_detector.cpp
@@ -4,12 +4,23 @@
  * @author A. Huaman
  */
 
-#include <stdio.h>
+#include "opencv2/opencv_modules.hpp"
 #include <iostream>
-#include "opencv2/core/core.hpp"
-#include "opencv2/features2d/features2d.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/nonfree/features2d.hpp"
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
+    return -1;
+}
+
+#else
+
+# include "opencv2/core/core.hpp"
+# include "opencv2/features2d/features2d.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/nonfree/features2d.hpp"
 
 using namespace cv;
 
@@ -60,3 +71,5 @@ int main( int argc, char** argv )
  */
 void readme()
 { std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }
+
+#endif
diff --git a/samples/ocl/CMakeLists.txt b/samples/ocl/CMakeLists.txt
index 706c4ae..90856f7 100644
--- a/samples/ocl/CMakeLists.txt
+++ b/samples/ocl/CMakeLists.txt
@@ -1,7 +1,6 @@
 SET(OPENCV_OCL_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui
                                      opencv_ml opencv_video opencv_objdetect opencv_features2d
-                                     opencv_calib3d opencv_legacy opencv_contrib opencv_ocl
-                                     opencv_nonfree)
+                                     opencv_calib3d opencv_legacy opencv_contrib opencv_ocl)
 
 ocv_check_dependencies(${OPENCV_OCL_SAMPLES_REQUIRED_DEPS})
 
@@ -52,7 +51,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
 endif()
 
 if (OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32)
-  file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd *.txt)
+  file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* *.txt)
   install(FILES ${install_list}
           DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/ocl"
           PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT samples)
diff --git a/samples/ocl/surf_matcher.cpp b/samples/ocl/surf_matcher.cpp
index 6023de9..19b7f56 100644
--- a/samples/ocl/surf_matcher.cpp
+++ b/samples/ocl/surf_matcher.cpp
@@ -1,11 +1,22 @@
+#include "opencv2/opencv_modules.hpp"
 #include <iostream>
-#include <stdio.h>
-#include "opencv2/core/core.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include "opencv2/ocl/ocl.hpp"
-#include "opencv2/nonfree/ocl.hpp"
-#include "opencv2/calib3d/calib3d.hpp"
-#include "opencv2/nonfree/nonfree.hpp"
+
+#ifndef HAVE_OPENCV_NONFREE
+
+int main(int, char**)
+{
+    std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
+    return -1;
+}
+
+#else
+
+# include "opencv2/core/core.hpp"
+# include "opencv2/highgui/highgui.hpp"
+# include "opencv2/ocl/ocl.hpp"
+# include "opencv2/nonfree/ocl.hpp"
+# include "opencv2/calib3d/calib3d.hpp"
+# include "opencv2/nonfree/nonfree.hpp"
 
 using namespace cv;
 using namespace cv::ocl;
@@ -326,3 +337,5 @@ int main(int argc, char* argv[])
     waitKey(0);
     return EXIT_SUCCESS;
 }
+
+#endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git



More information about the debian-science-commits mailing list