From 624469143a2402e8284d50adefb9a06d4e78ba1f Mon Sep 17 00:00:00 2001 From: Andrews Sobral <andrewssobral@gmail.com> Date: Wed, 20 Jul 2022 23:50:15 +0200 Subject: [PATCH] Fixed python wrapper --- demo2.py | 29 +++++++++++------- wrapper/python/bgslibrary_module.cpp | 44 +++++++++++++++------------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/demo2.py b/demo2.py index 321896c..befb409 100644 --- a/demo2.py +++ b/demo2.py @@ -18,6 +18,10 @@ def is_cv2(): def is_cv3(): return check_opencv_version("3.") +def is_lower_or_equals_cv347(): + [major, minor, revision] = str(cv2.__version__).split('.') + return int(major) == 3 and int(minor) <= 4 and int(revision) <= 7 + def is_cv4(): return check_opencv_version("4.") @@ -33,11 +37,22 @@ algorithms.append(bgs.WeightedMovingVariance()) algorithms.append(bgs.AdaptiveBackgroundLearning()) algorithms.append(bgs.AdaptiveSelectiveBackgroundLearning()) algorithms.append(bgs.MixtureOfGaussianV2()) +algorithms.append(bgs.PixelBasedAdaptiveSegmenter()) +algorithms.append(bgs.SigmaDelta()) +algorithms.append(bgs.SuBSENSE()) +algorithms.append(bgs.LOBSTER()) +algorithms.append(bgs.PAWCS()) +algorithms.append(bgs.TwoPoints()) +algorithms.append(bgs.ViBe()) +algorithms.append(bgs.CodeBook()) + if is_cv2(): algorithms.append(bgs.MixtureOfGaussianV1()) # if opencv 2.x algorithms.append(bgs.GMG()) # if opencv 2.x + if is_cv3(): algorithms.append(bgs.KNN()) # if opencv 3.x + if is_cv2() or is_cv3(): algorithms.append(bgs.DPAdaptiveMedian()) algorithms.append(bgs.DPGrimsonGMM()) @@ -58,20 +73,14 @@ if is_cv2() or is_cv3(): algorithms.append(bgs.LBMixtureOfGaussians()) algorithms.append(bgs.LBAdaptiveSOM()) algorithms.append(bgs.LBFuzzyAdaptiveSOM()) - algorithms.append(bgs.LBP_MRF()) - algorithms.append(bgs.MultiLayer()) - algorithms.append(bgs.PixelBasedAdaptiveSegmenter()) algorithms.append(bgs.VuMeter()) algorithms.append(bgs.KDE()) algorithms.append(bgs.IndependentMultimodal()) algorithms.append(bgs.MultiCue()) -algorithms.append(bgs.SigmaDelta()) -algorithms.append(bgs.SuBSENSE()) -algorithms.append(bgs.LOBSTER()) -algorithms.append(bgs.PAWCS()) -algorithms.append(bgs.TwoPoints()) -algorithms.append(bgs.ViBe()) -algorithms.append(bgs.CodeBook()) + +if is_cv2() or is_lower_or_equals_cv347(): + algorithms.append(bgs.LBP_MRF()) + algorithms.append(bgs.MultiLayer()) # check if we want to use the images diff --git a/wrapper/python/bgslibrary_module.cpp b/wrapper/python/bgslibrary_module.cpp index 6bc3757..7e996b5 100644 --- a/wrapper/python/bgslibrary_module.cpp +++ b/wrapper/python/bgslibrary_module.cpp @@ -83,7 +83,7 @@ PYBIND11_MODULE(pybgs, m) .def("getBackgroundModel", &MixtureOfGaussianV2::getBackgroundModel) ; -#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3 +#if CV_MAJOR_VERSION == 2 py::class_<MixtureOfGaussianV1>(m, "MixtureOfGaussianV1") .def(py::init<>()) .def("apply", &MixtureOfGaussianV1::apply) @@ -91,7 +91,7 @@ PYBIND11_MODULE(pybgs, m) ; #endif -#if CV_MAJOR_VERSION == 2 +#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3 py::class_<GMG>(m, "GMG") .def(py::init<>()) .def("apply", &GMG::apply) @@ -107,7 +107,7 @@ PYBIND11_MODULE(pybgs, m) ; #endif -#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3 +#if CV_MAJOR_VERSION == 2 || CV_MAJOR_VERSION == 3 py::class_<DPAdaptiveMedian>(m, "DPAdaptiveMedian") .def(py::init<>()) .def("apply", &DPAdaptiveMedian::apply) @@ -222,24 +222,6 @@ PYBIND11_MODULE(pybgs, m) .def("getBackgroundModel", &LBFuzzyAdaptiveSOM::getBackgroundModel) ; - py::class_<LBP_MRF>(m, "LBP_MRF") - .def(py::init<>()) - .def("apply", &LBP_MRF::apply) - .def("getBackgroundModel", &LBP_MRF::getBackgroundModel) - ; - - py::class_<MultiLayer>(m, "MultiLayer") - .def(py::init<>()) - .def("apply", &MultiLayer::apply) - .def("getBackgroundModel", &MultiLayer::getBackgroundModel) - ; - - py::class_<PixelBasedAdaptiveSegmenter>(m, "PixelBasedAdaptiveSegmenter") - .def(py::init<>()) - .def("apply", &PixelBasedAdaptiveSegmenter::apply) - .def("getBackgroundModel", &PixelBasedAdaptiveSegmenter::getBackgroundModel) - ; - py::class_<VuMeter>(m, "VuMeter") .def(py::init<>()) .def("apply", &VuMeter::apply) @@ -265,6 +247,26 @@ PYBIND11_MODULE(pybgs, m) ; #endif +#if (CV_MAJOR_VERSION == 2) || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION <= 4 && CV_VERSION_REVISION <= 7) + py::class_<LBP_MRF>(m, "LBP_MRF") + .def(py::init<>()) + .def("apply", &LBP_MRF::apply) + .def("getBackgroundModel", &LBP_MRF::getBackgroundModel) + ; + + py::class_<MultiLayer>(m, "MultiLayer") + .def(py::init<>()) + .def("apply", &MultiLayer::apply) + .def("getBackgroundModel", &MultiLayer::getBackgroundModel) + ; +#endif + + py::class_<PixelBasedAdaptiveSegmenter>(m, "PixelBasedAdaptiveSegmenter") + .def(py::init<>()) + .def("apply", &PixelBasedAdaptiveSegmenter::apply) + .def("getBackgroundModel", &PixelBasedAdaptiveSegmenter::getBackgroundModel) + ; + py::class_<SigmaDelta>(m, "SigmaDelta") .def(py::init<>()) .def("apply", &SigmaDelta::apply) -- GitLab