From ea26e21f4e46f7b4f3967716d3331800fd0856c1 Mon Sep 17 00:00:00 2001
From: Bob Estes <github@headdab.com>
Date: Mon, 10 Sep 2018 09:06:16 -0700
Subject: [PATCH] Update CV_MAJOR_VERSION == 3 to >= 3.0. (#139)

---
 CMakeLists.txt                                  | 13 ++++++-------
 FrameProcessor.cpp                              | 12 ++++++------
 FrameProcessor.h                                |  2 +-
 gui_qt/mainwindow.cpp                           |  4 ++--
 package_bgs/MixtureOfGaussianV2.cpp             |  4 ++--
 package_bgs/MixtureOfGaussianV2.h               |  2 +-
 wrapper_java/bgslibrary_java_module.cpp         |  8 ++++----
 wrapper_matlab/backgroundSubtractor_wrapper.cpp |  4 ++--
 wrapper_python/bgslibrary_module.cpp            |  4 ++--
 9 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c6de79b..17e6dde 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@ if(UNIX)
   set(CMAKE_MACOSX_RPATH 1)
 endif(UNIX)
 
-# Avoid cmake warnings about changes in behavior of some Mac OS X path 
+# Avoid cmake warnings about changes in behavior of some Mac OS X path
 # variable we don't care about.
 if (POLICY CMP0042)
   cmake_policy(SET CMP0042 NEW)
@@ -97,10 +97,10 @@ if(BGS_PYTHON_SUPPORT)
   #else()
   #  set(Boost_USE_STATIC_LIBS OFF)
   #endif()
-  
+
   #set(Boost_USE_MULTITHREADED ON)
   #set(Boost_USE_STATIC_RUNTIME OFF)
-  
+
   #message(STATUS "SEARCHING FOR BOOST COMPONENT FOR PYTHON ${BGS_PYTHON_VERSION}")
   #if(BGS_PYTHON_VERSION EQUAL 2)
   #  find_package(Boost REQUIRED COMPONENTS python)
@@ -134,7 +134,6 @@ if(BGS_PYTHON_SUPPORT)
   #message(STATUS "    libraries: ${PYTHON_LIBRARIES}")
   message(STATUS "    library: ${PYTHON_LIBRARY}")
   message(STATUS "    include path: ${PYTHON_INCLUDE_DIRS}")
-    
   if(NOT NUMPY_INCLUDE_DIR)
     # message(FATAL_ERROR "You must define NUMPY_INCLUDE_DIR by 'cmake -D NUMPY_INCLUDE_DIR=/python/lib/site-packages/numpy/core/include ..'")
     exec_program ("${PYTHON_EXECUTABLE}"
@@ -236,10 +235,10 @@ if(UNIX AND BGS_PYTHON_SUPPORT)
     OUTPUT_VARIABLE PYTHON_SITE
     OUTPUT_STRIP_TRAILING_WHITESPACE
   )
-  
+
   message(STATUS "")
   message(STATUS "The bgslibrary python package will be installed at: ${PYTHON_SITE}\n")
-  
+
   install(TARGETS bgs_python DESTINATION ${PYTHON_SITE})
   #install(FILES ${mypackage_python_files} DESTINATION ${PYTHON_SITE}/mypackage)
   #install(TARGETS bgs_python DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
@@ -265,4 +264,4 @@ endif()
 if(WIN32)
   message(STATUS "You might need to add ${CMAKE_CURRENT_BINARY_DIR} to your PATH to be able to run your applications.")
   message(STATUS "> set PATH=%PATH%;${CMAKE_CURRENT_BINARY_DIR}\n")
-endif()
\ No newline at end of file
+endif()
diff --git a/FrameProcessor.cpp b/FrameProcessor.cpp
index 3180589..fb9445c 100644
--- a/FrameProcessor.cpp
+++ b/FrameProcessor.cpp
@@ -65,7 +65,7 @@ namespace bgslibrary
       gmg = new GMG;
 #endif
 
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (enableKNN)
       knn = new KNN;
 #endif
@@ -220,7 +220,7 @@ namespace bgslibrary
       process("GMG", gmg, img_preProcessor, img_gmg);
 #endif
 
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (enableKNN)
       process("KNN", knn, img_preProcessor, img_knn);
 #endif
@@ -345,7 +345,7 @@ namespace bgslibrary
 #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
       foregroundMaskAnalysis->process(frameNumber, "GMG", img_gmg);
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
       foregroundMaskAnalysis->process(frameNumber, "KNN", img_knn);
 #endif
       foregroundMaskAnalysis->process(frameNumber, "DPAdaptiveMedian", img_dpAdaptiveMedian);
@@ -513,7 +513,7 @@ namespace bgslibrary
       delete gmg;
 #endif
 
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (enableKNN)
       delete knn;
 #endif
@@ -579,7 +579,7 @@ namespace bgslibrary
 #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     cvWriteInt(fs, "enableGMG", enableGMG);
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     cvWriteInt(fs, "enableKNN", enableKNN);
 #endif
 
@@ -645,7 +645,7 @@ namespace bgslibrary
 #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     enableGMG = cvReadIntByName(fs, 0, "enableGMG", false);
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     enableKNN = cvReadIntByName(fs, 0, "enableKNN", false);
 #endif
 
diff --git a/FrameProcessor.h b/FrameProcessor.h
index 025984a..7bf688e 100644
--- a/FrameProcessor.h
+++ b/FrameProcessor.h
@@ -75,7 +75,7 @@ namespace bgslibrary
     bool enableGMG;
 #endif
 
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     cv::Mat img_knn;
     KNN* knn;
     bool enableKNN;
diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp
index f0dd602..5b11765 100644
--- a/gui_qt/mainwindow.cpp
+++ b/gui_qt/mainwindow.cpp
@@ -37,7 +37,7 @@ namespace bgslibrary
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     map["GMG"] = &createInstance<GMG>; // only for OpenCV >= 2.4.3
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     map["KNN"] = &createInstance<KNN>; // only on OpenCV 3.x
 #endif
     map["DPAdaptiveMedian"] = &createInstance<DPAdaptiveMedian>;
@@ -93,7 +93,7 @@ namespace bgslibrary
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     stringList.append("GMG"); // only for OpenCV >= 2.4.3
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     stringList.append("KNN"); // only on OpenCV 3.x
 #endif
     stringList.append("DPAdaptiveMedian");
diff --git a/package_bgs/MixtureOfGaussianV2.cpp b/package_bgs/MixtureOfGaussianV2.cpp
index 085b1a9..7aa1075 100644
--- a/package_bgs/MixtureOfGaussianV2.cpp
+++ b/package_bgs/MixtureOfGaussianV2.cpp
@@ -35,7 +35,7 @@ void MixtureOfGaussianV2::process(const cv::Mat &img_input, cv::Mat &img_output,
   init(img_input, img_output, img_bgmodel);
 
   if (firstTime) {
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     mog = cv::createBackgroundSubtractorMOG2();
 #endif
   }
@@ -60,7 +60,7 @@ void MixtureOfGaussianV2::process(const cv::Mat &img_input, cv::Mat &img_output,
 #if CV_MAJOR_VERSION == 2
   mog(img_input, img_foreground, alpha);
   mog.getBackgroundImage(img_background);
-#elif CV_MAJOR_VERSION == 3
+#elif CV_MAJOR_VERSION >= 3
   mog->apply(img_input, img_foreground, alpha);
   mog->getBackgroundImage(img_background);
 #endif
diff --git a/package_bgs/MixtureOfGaussianV2.h b/package_bgs/MixtureOfGaussianV2.h
index edc8add..ff4816d 100644
--- a/package_bgs/MixtureOfGaussianV2.h
+++ b/package_bgs/MixtureOfGaussianV2.h
@@ -31,7 +31,7 @@ namespace bgslibrary
     private:
 #if CV_MAJOR_VERSION == 2
       cv::BackgroundSubtractorMOG2 mog;
-#elif CV_MAJOR_VERSION == 3
+#elif CV_MAJOR_VERSION >= 3
       cv::Ptr<cv::BackgroundSubtractorMOG2> mog;
 #endif
       double alpha;
diff --git a/wrapper_java/bgslibrary_java_module.cpp b/wrapper_java/bgslibrary_java_module.cpp
index 2758470..2b63e4b 100644
--- a/wrapper_java/bgslibrary_java_module.cpp
+++ b/wrapper_java/bgslibrary_java_module.cpp
@@ -48,7 +48,7 @@ namespace bgslibrary
     if (alg_name.compare("GMG") == 0)
       return (IBGS *)malloc(sizeof(GMG)); // only for OpenCV >= 2.4.3
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (alg_name.compare("KNN") == 0)
       return (IBGS *)malloc(sizeof(KNN)); // only for OpenCV 3.x
 #endif
@@ -145,7 +145,7 @@ namespace bgslibrary
     if (alg_name.compare("GMG") == 0)
       return new (ptrBGS) GMG(); // only for OpenCV >= 2.4.3
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (alg_name.compare("KNN") == 0)
       return new (ptrBGS) KNN(); // only on OpenCV 3.x
 #endif
@@ -257,9 +257,9 @@ void computeForegroundMask(const cv::Mat &img_input, cv::Mat &img_output)
       fgmask = cv::Mat::zeros(img_input.size(), CV_8UC1);
     if (bgmodel.empty())
       bgmodel = cv::Mat::zeros(img_input.size(), CV_8UC3);
-    
+
     fgmask.copyTo(img_output);
-    
+
     fgmask.release();
     bgmodel.release();
   }
diff --git a/wrapper_matlab/backgroundSubtractor_wrapper.cpp b/wrapper_matlab/backgroundSubtractor_wrapper.cpp
index 96fb4a6..63880e4 100644
--- a/wrapper_matlab/backgroundSubtractor_wrapper.cpp
+++ b/wrapper_matlab/backgroundSubtractor_wrapper.cpp
@@ -98,7 +98,7 @@ namespace bgslibrary
     if (alg_name.compare("GMG") == 0)
       return (IBGS *)mxCalloc(1, sizeof(GMG)); // only for OpenCV >= 2.4.3
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (alg_name.compare("KNN") == 0)
       return (IBGS *)mxCalloc(1, sizeof(KNN)); // only for OpenCV 3.x
 #endif
@@ -195,7 +195,7 @@ namespace bgslibrary
     if (alg_name.compare("GMG") == 0)
       return new (ptrBGS) GMG(); // only for OpenCV >= 2.4.3
 #endif
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
     if (alg_name.compare("KNN") == 0)
       return new (ptrBGS) KNN(); // only on OpenCV 3.x
 #endif
diff --git a/wrapper_python/bgslibrary_module.cpp b/wrapper_python/bgslibrary_module.cpp
index 4c1d0d3..893591a 100644
--- a/wrapper_python/bgslibrary_module.cpp
+++ b/wrapper_python/bgslibrary_module.cpp
@@ -47,7 +47,7 @@ PYBIND11_MODULE(bgs, m)
 {
 	NDArrayConverter::init_numpy();
 	m.doc() = "python wrapper for bgslibrary using pybind11";
-	
+
 	// Basic test
   m.def("read_image", &read_image, "A function that read an image", py::arg("image"));
   m.def("show_image", &show_image, "A function that show an image", py::arg("image"));
@@ -157,7 +157,7 @@ PYBIND11_MODULE(bgs, m)
 		.def("getBackgroundModel", &KDE::getBackgroundModel)
 		;
 
-#if CV_MAJOR_VERSION == 3
+#if CV_MAJOR_VERSION >= 3
 	py::class_<KNN>(m, "KNN")
     .def(py::init<>())
 		.def("apply", &KNN::apply)
-- 
GitLab