Skip to content

Commit

Permalink
Made samples build independent from nonfree module.
Browse files Browse the repository at this point in the history
(cherry picked from commit bba8c0b)
  • Loading branch information
asmorkalov committed Oct 26, 2015
1 parent 42447a7 commit 966d35a
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 111 deletions.
10 changes: 8 additions & 2 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
36 changes: 25 additions & 11 deletions samples/c/find_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
* Author: Liu Liu
* [email protected]
*/
#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()
{
Expand Down Expand Up @@ -320,3 +332,5 @@ int main(int argc, char** argv)

return 0;
}

#endif
31 changes: 23 additions & 8 deletions samples/c/find_obj_calonder.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -164,3 +177,5 @@ int main( int argc, char **argv )

return 0;
}

#endif
30 changes: 22 additions & 8 deletions samples/c/one_way_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -116,3 +128,5 @@ Mat DrawCorrespondences(const Mat& img1, const vector<KeyPoint>& features1, cons

return img_corr;
}

#endif
5 changes: 3 additions & 2 deletions samples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
58 changes: 36 additions & 22 deletions samples/cpp/bagofwords_classification.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -2623,3 +2635,5 @@ int main(int argc, char** argv)
}
return 0;
}

#endif
13 changes: 10 additions & 3 deletions samples/cpp/descriptor_extractor_matcher.cpp
Original file line number Diff line number Diff line change
@@ -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>

Expand All @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions samples/cpp/fabmap_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,3 +224,5 @@ int main(int argc, char * argv[]) {

return 0;
}

#endif
28 changes: 21 additions & 7 deletions samples/cpp/freak_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -126,3 +138,5 @@ int main( int argc, char** argv ) {
imshow("matches", imgMatch);
waitKey(0);
}

#endif
26 changes: 20 additions & 6 deletions samples/cpp/generic_descriptor_match.cpp
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -91,3 +103,5 @@ Mat DrawCorrespondences(const Mat& img1, const vector<KeyPoint>& features1, cons

return img_corr;
}

#endif
Loading

0 comments on commit 966d35a

Please sign in to comment.