From 82d784a4be816f696877cd713490fc178d8e9b91 Mon Sep 17 00:00:00 2001
From: Andrews Sobral <andrewssobral@users.noreply.github.com>
Date: Tue, 6 Aug 2019 18:19:08 +0200
Subject: [PATCH] Big refactoring to compile with OpenCV 4, changed license to
 MIT (#156)

* Refactoring 01

* Refactoring 02

* Refactoring 03

* Refactoring 04

* Refactoring 05

* Refactoring 06

* Refactoring 07

* Refactoring 08

* Refactoring 09

* Updated pybind11 module

* Refactoring of VideoCapture

* Updated README and python example
---
 .gitignore                                    |  12 +-
 .gitmodules                                   |   2 +-
 CMakeLists.txt                                |  30 +-
 COPYING.txt                                   | 674 -----------------
 Config.h                                      |  25 -
 IFrameProcessor.h                             |  29 -
 LICENSE                                       | 696 +-----------------
 LICENSE.txt                                   |  34 +-
 README.md                                     |  17 +-
 VideoAnalysis.h                               |  47 --
 VideoCapture.h                                |  81 --
 config/MultiCue.xml                           |  17 -
 Demo.py => demo.py                            |   0
 Demo2.py => demo2.py                          |  74 +-
 demos/linux_ubuntu/.gitignore                 |   8 -
 demos/linux_ubuntu/CMakeLists.txt             |  22 -
 demos/linux_ubuntu/FrameDifferenceTest.cpp    |  51 --
 demos/linux_ubuntu/README.txt                 |   9 -
 demos/macosx/.gitignore                       |   8 -
 demos/macosx/CMakeLists.txt                   |  33 -
 demos/macosx/FrameDifferenceTest.cpp          |  49 --
 demos/macosx/README.txt                       |   9 -
 examples/CMakeLists.txt                       | 139 ++++
 Demo.cpp => examples/Demo.cpp                 |  23 +-
 Demo2.cpp => examples/Demo2.cpp               |  29 +-
 examples/README.md                            |  14 +
 .../background => examples/build}/.gitignore  |   0
 .../foreground => examples/config}/.gitignore |   0
 examples/run_demo.bat                         |   2 +
 examples/run_demo.sh                          |   2 +
 examples/run_demo2.bat                        |   2 +
 examples/run_demo2.sh                         |   2 +
 gui/README.md                                 |   5 +
 {gui_java => gui/java}/README.txt             |   0
 .../java}/_COPY_bgslibrary.exe_HERE_          |   0
 {gui_java => gui/java}/bgslibrary_gui.jar     | Bin
 .../java}/bgslibrary_gui.properties           |   0
 {gui_java => gui/java}/build.xml              |   0
 {gui_java => gui/java}/config/.gitignore      |   0
 .../java}/config/FrameProcessor.xml           |   0
 .../java}/config/PreProcessor.xml             |   0
 .../java}/config/VideoCapture.xml             |   0
 .../java}/images/bgslibrary_gui_screen01.png  | Bin
 .../java}/images/bgslibrary_gui_screen02.png  | Bin
 .../java}/images/bgslibrary_gui_screen03.png  | Bin
 .../java}/images/bgslibrary_gui_screen04.png  | Bin
 {gui_java => gui/java}/images/logo.jpg        | Bin
 .../java}/lib/commons-configuration-1.8.jar   | Bin
 {gui_java => gui/java}/lib/commons-io-2.3.jar | Bin
 .../java}/lib/commons-lang-2.6.jar            | Bin
 .../java}/lib/commons-logging-1.1.1.jar       | Bin
 .../java}/lib/swingx-all-1.6.3.jar            | Bin
 .../java}/lib/swingx-beaninfo-1.6.3.jar       | Bin
 {gui_java => gui/java}/manifest.mf            |   0
 .../java}/nbproject/build-impl.xml            |   0
 .../java}/nbproject/genfiles.properties       |   0
 .../java}/nbproject/private/config.properties |   0
 .../nbproject/private/private.properties      |   0
 .../java}/nbproject/private/private.xml       |   0
 .../java}/nbproject/project.properties        |   0
 {gui_java => gui/java}/nbproject/project.xml  |   0
 {gui_java => gui/java}/run_camera.bat         |   0
 {gui_java => gui/java}/run_java_gui.bat       |   0
 .../java}/run_java_gui_with_console.bat       |   0
 {gui_java => gui/java}/run_video.bat          |   0
 .../java}/src/br/com/bgslibrary/Main.java     |  16 -
 .../src/br/com/bgslibrary/entity/Command.java |  16 -
 .../com/bgslibrary/entity/Configuration.java  |  16 -
 .../br/com/bgslibrary/gui/AboutDialog.form    |   0
 .../br/com/bgslibrary/gui/AboutDialog.java    |  16 -
 .../src/br/com/bgslibrary/gui/MainFrame.form  |   0
 .../src/br/com/bgslibrary/gui/MainFrame.java  |  16 -
 .../src/br/com/bgslibrary/resources/logo.jpg  | Bin
 {gui_mfc => gui/mfc}/.gitignore               |   0
 {gui_mfc => gui/mfc}/ReadMe.txt               |   0
 .../config/AdaptiveBackgroundLearning.xml     |   0
 .../AdaptiveSelectiveBackgroundLearning.xml   |   0
 .../mfc}/config/DPAdaptiveMedianBGS.xml       |   0
 .../mfc}/config/DPEigenbackgroundBGS.xml      |   0
 .../mfc}/config/DPGrimsonGMMBGS.xml           |   0
 {gui_mfc => gui/mfc}/config/DPMeanBGS.xml     |   0
 .../mfc}/config/DPPratiMediodBGS.xml          |   0
 {gui_mfc => gui/mfc}/config/DPTextureBGS.xml  |   0
 {gui_mfc => gui/mfc}/config/DPWrenGABGS.xml   |   0
 .../mfc}/config/DPZivkovicAGMMBGS.xml         |   0
 .../mfc}/config/FrameDifferenceBGS.xml        |   0
 .../mfc}/config/FuzzyChoquetIntegral.xml      |   0
 .../mfc}/config/FuzzySugenoIntegral.xml       |   0
 {gui_mfc => gui/mfc}/config/GMG.xml           |   0
 .../mfc}/config/IndependentMultimodalBGS.xml  |   0
 {gui_mfc => gui/mfc}/config/KDE.xml           |   0
 {gui_mfc => gui/mfc}/config/LBAdaptiveSOM.xml |   0
 .../mfc}/config/LBFuzzyAdaptiveSOM.xml        |   0
 .../mfc}/config/LBFuzzyGaussian.xml           |   0
 .../mfc}/config/LBMixtureOfGaussians.xml      |   0
 .../mfc}/config/LBSimpleGaussian.xml          |   0
 {gui_mfc => gui/mfc}/config/LOBSTERBGS.xml    |   0
 .../mfc}/config/MixtureOfGaussianV1BGS.xml    |   0
 .../mfc}/config/MixtureOfGaussianV2BGS.xml    |   0
 {gui_mfc => gui/mfc}/config/MultiCueBGS.xml   |   0
 {gui_mfc => gui/mfc}/config/MultiLayerBGS.xml |   0
 {gui_mfc => gui/mfc}/config/SigmaDeltaBGS.xml |   0
 .../mfc}/config/StaticFrameDifferenceBGS.xml  |   0
 {gui_mfc => gui/mfc}/config/SuBSENSEBGS.xml   |   0
 {gui_mfc => gui/mfc}/config/T2FGMM_UM.xml     |   0
 {gui_mfc => gui/mfc}/config/T2FGMM_UV.xml     |   0
 {gui_mfc => gui/mfc}/config/T2FMRF_UM.xml     |   0
 {gui_mfc => gui/mfc}/config/T2FMRF_UV.xml     |   0
 {gui_mfc => gui/mfc}/config/VuMeter.xml       |   0
 .../mfc}/config/WeightedMovingMeanBGS.xml     |   0
 .../mfc}/config/WeightedMovingVarianceBGS.xml |   0
 {gui_mfc => gui/mfc}/dataset/video.avi        | Bin
 .../mfc/outputs/background}/.gitignore        |   0
 .../mfc/outputs/foreground}/.gitignore        |   0
 .../mfc/outputs/input}/.gitignore             |   0
 {gui_mfc => gui/mfc}/src/.gitignore           |   0
 {gui_mfc => gui/mfc}/src/App.cpp              |   0
 {gui_mfc => gui/mfc}/src/App.h                |   0
 {gui_mfc => gui/mfc}/src/Dlg.cpp              |   0
 {gui_mfc => gui/mfc}/src/Dlg.h                |   0
 {gui_mfc => gui/mfc}/src/ReadMe.txt           |   0
 .../mfc}/src/bgslibrary_vs2013_mfc.rc         | Bin
 .../mfc}/src/bgslibrary_vs2013_mfc.sln        |   0
 .../mfc}/src/bgslibrary_vs2013_mfc.vcxproj    |   0
 .../src/bgslibrary_vs2013_mfc.vcxproj.filters |   0
 .../src/bgslibrary_vs2013_mfc.vcxproj.user    |   0
 .../mfc}/src/res/bgslibrary_vs2013_mfc.ico    | Bin
 .../mfc}/src/res/bgslibrary_vs2013_mfc.rc2    | Bin
 {gui_mfc => gui/mfc}/src/resource.h           | Bin
 {gui_mfc => gui/mfc}/src/stdafx.cpp           |   0
 {gui_mfc => gui/mfc}/src/stdafx.h             |   0
 {gui_mfc => gui/mfc}/src/targetver.h          |   0
 {gui_qt => gui/qt}/.gitignore                 |   0
 {gui_qt => gui/qt}/CMakeLists.txt             |   8 +-
 gui/qt/README.md                              | 118 +++
 {gui_qt => gui/qt}/application.qrc            |   0
 {gui_qt => gui/qt}/bgslibrary_gui.cpp         |  16 -
 gui/qt/bgslibrary_gui.pro                     | 255 +++++++
 .../config => gui/qt/build}/.gitignore        |   0
 {gui_qt => gui/qt}/figs/copy.png              | Bin
 {gui_qt => gui/qt}/figs/cut.png               | Bin
 {gui_qt => gui/qt}/figs/new.png               | Bin
 {gui_qt => gui/qt}/figs/open.png              | Bin
 {gui_qt => gui/qt}/figs/paste.png             | Bin
 {gui_qt => gui/qt}/figs/save.png              | Bin
 {gui_qt => gui/qt}/mainwindow.cpp             |  16 -
 {gui_qt => gui/qt}/mainwindow.h               |  18 +-
 {gui_qt => gui/qt}/mainwindow.ui              |   0
 {gui_qt => gui/qt}/qt_utils.cpp               |  17 -
 {gui_qt => gui/qt}/qt_utils.h                 |  16 -
 {gui_qt => gui/qt}/texteditor.cpp             |  17 -
 {gui_qt => gui/qt}/texteditor.h               |  16 -
 {gui_qt => gui/qt}/ui_mainwindow.h            |   0
 gui_qt/README.txt                             |  17 -
 gui_qt/bgslibrary_gui.pro                     | 255 -------
 modules/pybind11                              |   1 +
 package_bgs/AdaptiveBackgroundLearning.h      |  49 --
 .../AdaptiveSelectiveBackgroundLearning.h     |  49 --
 package_bgs/FrameDifference.cpp               |  84 ---
 package_bgs/FrameDifference.h                 |  45 --
 package_bgs/FuzzyChoquetIntegral.h            |  55 --
 package_bgs/GMG.h                             |  51 --
 package_bgs/IndependentMultimodal.h           |  45 --
 package_bgs/KDE/KernelTable.cpp               | 116 ---
 package_bgs/KDE/KernelTable.h                 |  67 --
 package_bgs/KDE/NPBGSubtractor.h              | 146 ----
 package_bgs/KDE/NPBGmodel.cpp                 | 127 ----
 package_bgs/KDE/NPBGmodel.h                   | 103 ---
 package_bgs/LBAdaptiveSOM.cpp                 | 102 ---
 package_bgs/LBAdaptiveSOM.h                   |  52 --
 package_bgs/LBFuzzyAdaptiveSOM.cpp            | 102 ---
 package_bgs/LBFuzzyGaussian.h                 |  51 --
 package_bgs/LBMixtureOfGaussians.h            |  52 --
 package_bgs/LBP_MRF.h                         |  45 --
 package_bgs/LBP_MRF/MEDefs.cpp                |  57 --
 package_bgs/LBP_MRF/MEDefs.hpp                |  90 ---
 package_bgs/LBP_MRF/block.h                   | 297 --------
 package_bgs/LBP_MRF/graph.cpp                 |  99 ---
 package_bgs/LBSimpleGaussian.h                |  50 --
 package_bgs/LOBSTER.cpp                       |  98 ---
 package_bgs/LOBSTER.h                         |  50 --
 package_bgs/MultiLayer/BlobExtraction.h       |  70 --
 .../MultiLayer/BlobLibraryConfiguration.h     |  63 --
 package_bgs/MultiLayer/LocalBinaryPattern.h   |  98 ---
 package_bgs/MultiLayer/OpenCvLegacyIncludes.h |  50 --
 package_bgs/PAWCS.cpp                         |  93 ---
 package_bgs/PAWCS.h                           |  50 --
 package_bgs/PixelBasedAdaptiveSegmenter.cpp   | 126 ----
 package_bgs/SigmaDelta.h                      |  51 --
 package_bgs/StaticFrameDifference.cpp         |  79 --
 package_bgs/StaticFrameDifference.h           |  44 --
 package_bgs/SuBSENSE.cpp                      |  96 ---
 package_bgs/SuBSENSE.h                        |  51 --
 package_bgs/TwoPoints.h                       |  48 --
 package_bgs/VuMeter.h                         |  54 --
 package_bgs/WeightedMovingMean.h              |  47 --
 package_bgs/_template_/Amber.h                |  47 --
 package_bgs/_template_/MyBGS.h                |  45 --
 package_bgs/bgslibrary.cpp                    |  18 -
 package_bgs/dp/AdaptiveMedianBGS.h            |  90 ---
 package_bgs/dp/Bgs.h                          |  63 --
 package_bgs/dp/BgsParams.h                    |  55 --
 package_bgs/dp/Error.cpp                      |  57 --
 package_bgs/dp/Error.h                        |  31 -
 package_bgs/lb/BGModel.cpp                    |  87 ---
 package_bgs/lb/BGModel.h                      |  74 --
 package_bgs/lb/BGModelFuzzyGauss.h            |  71 --
 package_bgs/lb/BGModelFuzzySom.h              |  91 ---
 package_bgs/lb/BGModelGauss.h                 |  69 --
 package_bgs/lb/BGModelMog.h                   |  79 --
 package_bgs/lb/BGModelSom.h                   |  88 ---
 package_bgs/lb/Types.h                        |  94 ---
 pybind11                                      |   1 -
 run_demo.bat                                  |   3 -
 run_demo.sh                                   |   2 -
 run_demo2.bat                                 |   3 -
 run_demo2.sh                                  |   2 -
 src/Config.h                                  |   9 +
 FrameProcessor.cpp => src/FrameProcessor.cpp  | 299 ++++----
 FrameProcessor.h => src/FrameProcessor.h      |  23 +-
 src/IFrameProcessor.h                         |  13 +
 Main.cpp => src/Main.cpp                      |  20 +-
 PreProcessor.cpp => src/PreProcessor.cpp      |  51 +-
 PreProcessor.h => src/PreProcessor.h          |  22 +-
 VideoAnalysis.cpp => src/VideoAnalysis.cpp    |  16 -
 src/VideoAnalysis.h                           |  31 +
 VideoCapture.cpp => src/VideoCapture.cpp      | 113 ++-
 src/VideoCapture.h                            |  58 ++
 .../ForegroundMaskAnalysis.cpp                |  46 +-
 .../ForegroundMaskAnalysis.h                  |  22 +-
 .../package_analysis}/PerformanceUtils.cpp    |  16 -
 .../package_analysis}/PerformanceUtils.h      |  17 -
 .../package_analysis}/PixelUtils.cpp          |  16 -
 .../package_analysis}/PixelUtils.h            |  16 -
 .../AdaptiveBackgroundLearning.cpp            |  45 +-
 src/package_bgs/AdaptiveBackgroundLearning.h  |  36 +
 .../AdaptiveSelectiveBackgroundLearning.cpp   |  45 +-
 .../AdaptiveSelectiveBackgroundLearning.h     |  36 +
 {package_bgs => src/package_bgs}/CodeBook.cpp |  41 +-
 {package_bgs => src/package_bgs}/CodeBook.h   |  19 +-
 .../package_bgs}/DPAdaptiveMedian.cpp         |  45 +-
 .../package_bgs}/DPAdaptiveMedian.h           |  24 +-
 .../package_bgs}/DPEigenbackground.cpp        |  45 +-
 .../package_bgs}/DPEigenbackground.h          |  25 +-
 .../package_bgs}/DPGrimsonGMM.cpp             |  45 +-
 .../package_bgs}/DPGrimsonGMM.h               |  25 +-
 {package_bgs => src/package_bgs}/DPMean.cpp   |  48 +-
 {package_bgs => src/package_bgs}/DPMean.h     |  25 +-
 .../package_bgs}/DPPratiMediod.cpp            |  49 +-
 .../package_bgs}/DPPratiMediod.h              |  25 +-
 .../package_bgs}/DPTexture.cpp                |  49 +-
 {package_bgs => src/package_bgs}/DPTexture.h  |  25 +-
 {package_bgs => src/package_bgs}/DPWrenGA.cpp |  53 +-
 {package_bgs => src/package_bgs}/DPWrenGA.h   |  25 +-
 .../package_bgs}/DPZivkovicAGMM.cpp           |  53 +-
 .../package_bgs}/DPZivkovicAGMM.h             |  25 +-
 src/package_bgs/FrameDifference.cpp           |  69 ++
 src/package_bgs/FrameDifference.h             |  30 +
 .../package_bgs}/FuzzyChoquetIntegral.cpp     |  69 +-
 src/package_bgs/FuzzyChoquetIntegral.h        |  46 ++
 .../package_bgs}/FuzzySugenoIntegral.cpp      |  69 +-
 .../package_bgs}/FuzzySugenoIntegral.h        |  25 +-
 {package_bgs => src/package_bgs}/GMG.cpp      |  45 +-
 src/package_bgs/GMG.h                         |  36 +
 {package_bgs => src/package_bgs}/IBGS.h       |  29 -
 src/package_bgs/ILoadSaveConfig.h             |  29 +
 .../package_bgs}/IMBS/IMBS.cpp                |  37 -
 .../package_bgs}/IMBS/IMBS.hpp                |  43 +-
 .../package_bgs}/IndependentMultimodal.cpp    |  41 +-
 src/package_bgs/IndependentMultimodal.h       |  36 +
 {package_bgs => src/package_bgs}/KDE.cpp      |  69 +-
 {package_bgs => src/package_bgs}/KDE.h        |  25 +-
 src/package_bgs/KDE/KernelTable.cpp           |  69 ++
 src/package_bgs/KDE/KernelTable.h             |  20 +
 .../package_bgs}/KDE/NPBGSubtractor.cpp       |  55 +-
 src/package_bgs/KDE/NPBGSubtractor.h          |  95 +++
 src/package_bgs/KDE/NPBGmodel.cpp             |  72 ++
 src/package_bgs/KDE/NPBGmodel.h               |  52 ++
 {package_bgs => src/package_bgs}/KNN.cpp      |  65 +-
 {package_bgs => src/package_bgs}/KNN.h        |  26 +-
 src/package_bgs/LBAdaptiveSOM.cpp             |  93 +++
 src/package_bgs/LBAdaptiveSOM.h               |  43 ++
 src/package_bgs/LBFuzzyAdaptiveSOM.cpp        |  91 +++
 .../package_bgs}/LBFuzzyAdaptiveSOM.h         |  25 +-
 .../package_bgs}/LBFuzzyGaussian.cpp          |  57 +-
 src/package_bgs/LBFuzzyGaussian.h             |  42 ++
 .../package_bgs}/LBMixtureOfGaussians.cpp     |  57 +-
 src/package_bgs/LBMixtureOfGaussians.h        |  42 ++
 {package_bgs => src/package_bgs}/LBP_MRF.cpp  |  45 +-
 src/package_bgs/LBP_MRF.h                     |  36 +
 src/package_bgs/LBP_MRF/MEDefs.cpp            |  20 +
 src/package_bgs/LBP_MRF/MEDefs.hpp            |  54 ++
 .../package_bgs}/LBP_MRF/MEHistogram.cpp      |  65 +-
 .../package_bgs}/LBP_MRF/MEHistogram.hpp      |  43 --
 .../package_bgs}/LBP_MRF/MEImage.cpp          | 100 +--
 .../package_bgs}/LBP_MRF/MEImage.hpp          |  51 +-
 .../package_bgs}/LBP_MRF/MotionDetection.cpp  |  70 +-
 .../package_bgs}/LBP_MRF/MotionDetection.hpp  |  44 +-
 src/package_bgs/LBP_MRF/block.h               | 172 +++++
 src/package_bgs/LBP_MRF/graph.cpp             |  65 ++
 .../package_bgs}/LBP_MRF/graph.h              |  65 +-
 .../package_bgs}/LBP_MRF/maxflow.cpp          |  67 +-
 .../LBSP/BackgroundSubtractorLBSP.cpp         |  24 +-
 .../LBSP/BackgroundSubtractorLBSP.h           |  17 +-
 .../LBSP/BackgroundSubtractorLBSP_.cpp        |  24 +-
 .../LBSP/BackgroundSubtractorLBSP_.h          |  17 +-
 .../LBSP/BackgroundSubtractorLOBSTER.cpp      |  23 +-
 .../LBSP/BackgroundSubtractorLOBSTER.h        |  16 -
 .../LBSP/BackgroundSubtractorPAWCS.cpp        |  23 +-
 .../LBSP/BackgroundSubtractorPAWCS.h          |  16 -
 .../LBSP/BackgroundSubtractorSuBSENSE.cpp     |  23 +-
 .../LBSP/BackgroundSubtractorSuBSENSE.h       |  16 -
 .../package_bgs}/LBSP/DistanceUtils.h         |  16 -
 .../package_bgs}/LBSP/LBSP.cpp                |  16 -
 {package_bgs => src/package_bgs}/LBSP/LBSP.h  |  17 +-
 .../package_bgs}/LBSP/LBSP_.cpp               |  16 -
 {package_bgs => src/package_bgs}/LBSP/LBSP_.h |  17 +-
 .../LBSP/LBSP_16bits_dbcross_1ch.i            |   0
 .../LBSP/LBSP_16bits_dbcross_3ch1t.i          |   0
 .../LBSP/LBSP_16bits_dbcross_3ch3t.i          |   0
 .../LBSP/LBSP_16bits_dbcross_s3ch.i           |   0
 .../package_bgs}/LBSP/RandUtils.h             |  16 -
 .../package_bgs}/LBSimpleGaussian.cpp         |  53 +-
 src/package_bgs/LBSimpleGaussian.h            |  41 ++
 src/package_bgs/LOBSTER.cpp                   |  83 +++
 src/package_bgs/LOBSTER.h                     |  36 +
 .../package_bgs}/MixtureOfGaussianV1.cpp      |  50 +-
 .../package_bgs}/MixtureOfGaussianV1.h        |  19 +-
 .../package_bgs}/MixtureOfGaussianV2.cpp      |  49 +-
 .../package_bgs}/MixtureOfGaussianV2.h        |  19 +-
 {package_bgs => src/package_bgs}/MultiCue.cpp | 104 ++-
 {package_bgs => src/package_bgs}/MultiCue.h   |  24 +-
 .../package_bgs}/MultiLayer.cpp               | 167 ++---
 {package_bgs => src/package_bgs}/MultiLayer.h |  24 +-
 .../package_bgs}/MultiLayer/BGS.h             |  52 --
 .../MultiLayer/BackgroundSubtractionAPI.h     |  62 --
 .../MultiLayer/BlobExtraction.cpp             |  58 +-
 src/package_bgs/MultiLayer/BlobExtraction.h   |  17 +
 .../MultiLayer/BlobLibraryConfiguration.h     |   9 +
 .../package_bgs}/MultiLayer/BlobResult.cpp    |  53 +-
 .../package_bgs}/MultiLayer/BlobResult.h      |  58 +-
 .../MultiLayer/CMultiLayerBGS.cpp             |  60 +-
 .../package_bgs}/MultiLayer/CMultiLayerBGS.h  |  73 +-
 .../MultiLayer/LocalBinaryPattern.cpp         |  46 --
 .../MultiLayer/LocalBinaryPattern.h           |  50 ++
 .../MultiLayer/OpenCvDataConversion.h         |  47 +-
 .../MultiLayer/OpenCvLegacyIncludes.h         |   5 +
 .../package_bgs}/MultiLayer/blob.cpp          |  59 --
 .../package_bgs}/MultiLayer/blob.h            |  61 +-
 src/package_bgs/PAWCS.cpp                     |  78 ++
 src/package_bgs/PAWCS.h                       |  35 +
 .../package_bgs}/PBAS/PBAS.cpp                |  16 -
 {package_bgs => src/package_bgs}/PBAS/PBAS.h  |  56 --
 .../PixelBasedAdaptiveSegmenter.cpp           | 109 +++
 .../PixelBasedAdaptiveSegmenter.h             |  19 +-
 .../package_bgs}/SigmaDelta.cpp               |  51 +-
 src/package_bgs/SigmaDelta.h                  |  36 +
 .../package_bgs}/SigmaDelta/sdLaMa091.cpp     |  17 -
 .../package_bgs}/SigmaDelta/sdLaMa091.h       |  16 -
 src/package_bgs/StaticFrameDifference.cpp     |  64 ++
 src/package_bgs/StaticFrameDifference.h       |  29 +
 src/package_bgs/SuBSENSE.cpp                  |  81 ++
 src/package_bgs/SuBSENSE.h                    |  36 +
 .../package_bgs}/T2F/FuzzyUtils.cpp           |  16 -
 .../package_bgs}/T2F/FuzzyUtils.h             |  16 -
 {package_bgs => src/package_bgs}/T2F/MRF.cpp  |  20 +-
 {package_bgs => src/package_bgs}/T2F/MRF.h    |  21 +-
 .../package_bgs}/T2F/T2FGMM.cpp               |  30 +-
 {package_bgs => src/package_bgs}/T2F/T2FGMM.h |  34 +-
 .../package_bgs}/T2F/T2FMRF.cpp               |  34 +-
 {package_bgs => src/package_bgs}/T2F/T2FMRF.h |  34 +-
 .../package_bgs}/T2FGMM_UM.cpp                |  61 +-
 {package_bgs => src/package_bgs}/T2FGMM_UM.h  |  24 +-
 .../package_bgs}/T2FGMM_UV.cpp                |  61 +-
 {package_bgs => src/package_bgs}/T2FGMM_UV.h  |  24 +-
 .../package_bgs}/T2FMRF_UM.cpp                |  61 +-
 {package_bgs => src/package_bgs}/T2FMRF_UM.h  |  24 +-
 .../package_bgs}/T2FMRF_UV.cpp                |  61 +-
 {package_bgs => src/package_bgs}/T2FMRF_UV.h  |  24 +-
 .../package_bgs}/TwoPoints.cpp                |  46 +-
 src/package_bgs/TwoPoints.h                   |  33 +
 .../package_bgs}/TwoPoints/two_points.cpp     |  16 -
 .../package_bgs}/TwoPoints/two_points.h       |  16 -
 {package_bgs => src/package_bgs}/ViBe.cpp     |  54 +-
 {package_bgs => src/package_bgs}/ViBe.h       |  19 +-
 {package_bgs => src/package_bgs}/ViBe/LICENSE |   0
 .../ViBe/vibe-background-sequential.cpp       |  22 -
 .../ViBe/vibe-background-sequential.h         |  50 --
 {package_bgs => src/package_bgs}/VuMeter.cpp  |  61 +-
 src/package_bgs/VuMeter.h                     |  44 ++
 .../package_bgs}/VuMeter/TBackground.cpp      |  25 -
 .../package_bgs}/VuMeter/TBackground.h        |  23 -
 .../VuMeter/TBackgroundVuMeter.cpp            |  23 -
 .../package_bgs}/VuMeter/TBackgroundVuMeter.h |  23 -
 .../package_bgs}/WeightedMovingMean.cpp       |  49 +-
 src/package_bgs/WeightedMovingMean.h          |  32 +
 .../package_bgs}/WeightedMovingVariance.cpp   |  49 +-
 .../package_bgs}/WeightedMovingVariance.h     |  19 +-
 .../package_bgs}/_template_/Amber.cpp         |  30 +-
 src/package_bgs/_template_/Amber.h            |  32 +
 .../package_bgs}/_template_/MyBGS.cpp         |  16 -
 src/package_bgs/_template_/MyBGS.h            |  30 +
 .../package_bgs}/_template_/amber/amber.cpp   |  22 -
 .../package_bgs}/_template_/amber/amber.h     |  16 -
 src/package_bgs/bgslibrary.cpp                |   1 +
 {package_bgs => src/package_bgs}/bgslibrary.h |  17 +-
 .../package_bgs}/dp/AdaptiveMedianBGS.cpp     |  36 +-
 src/package_bgs/dp/AdaptiveMedianBGS.h        |  61 ++
 src/package_bgs/dp/Bgs.h                      |  43 ++
 src/package_bgs/dp/BgsParams.h                |  29 +
 .../package_bgs}/dp/Eigenbackground.cpp       |  34 +-
 .../package_bgs}/dp/Eigenbackground.h         |  44 +-
 src/package_bgs/dp/Error.cpp                  |  31 +
 src/package_bgs/dp/Error.h                    |   6 +
 .../package_bgs}/dp/GrimsonGMM.cpp            |  46 +-
 .../package_bgs}/dp/GrimsonGMM.h              |  57 +-
 {package_bgs => src/package_bgs}/dp/Image.cpp |  33 +-
 {package_bgs => src/package_bgs}/dp/Image.h   |  34 +-
 .../package_bgs}/dp/MeanBGS.cpp               |  31 +-
 {package_bgs => src/package_bgs}/dp/MeanBGS.h |  43 +-
 .../package_bgs}/dp/PratiMediodBGS.cpp        |  42 +-
 .../package_bgs}/dp/PratiMediodBGS.h          |  52 +-
 .../package_bgs}/dp/TextureBGS.cpp            |  20 +-
 .../package_bgs}/dp/TextureBGS.h              |  20 +-
 .../package_bgs}/dp/WrenGA.cpp                |  35 +-
 {package_bgs => src/package_bgs}/dp/WrenGA.h  |  47 +-
 .../package_bgs}/dp/ZivkovicAGMM.cpp          |  45 +-
 .../package_bgs}/dp/ZivkovicAGMM.h            |  56 +-
 src/package_bgs/lb/BGModel.cpp                |  51 ++
 src/package_bgs/lb/BGModel.h                  |  40 +
 .../package_bgs}/lb/BGModelFuzzyGauss.cpp     |  36 -
 src/package_bgs/lb/BGModelFuzzyGauss.h        |  36 +
 .../package_bgs}/lb/BGModelFuzzySom.cpp       |  36 -
 src/package_bgs/lb/BGModelFuzzySom.h          |  56 ++
 .../package_bgs}/lb/BGModelGauss.cpp          |  36 -
 src/package_bgs/lb/BGModelGauss.h             |  34 +
 .../package_bgs}/lb/BGModelMog.cpp            |  36 -
 src/package_bgs/lb/BGModelMog.h               |  44 ++
 .../package_bgs}/lb/BGModelSom.cpp            |  36 -
 src/package_bgs/lb/BGModelSom.h               |  53 ++
 src/package_bgs/lb/Types.h                    |  59 ++
 {fet => tools/fet}/FG/1.png                   | Bin
 {fet => tools/fet}/FG/10.png                  | Bin
 {fet => tools/fet}/FG/11.png                  | Bin
 {fet => tools/fet}/FG/12.png                  | Bin
 {fet => tools/fet}/FG/13.png                  | Bin
 {fet => tools/fet}/FG/14.png                  | Bin
 {fet => tools/fet}/FG/15.png                  | Bin
 {fet => tools/fet}/FG/16.png                  | Bin
 {fet => tools/fet}/FG/17.png                  | Bin
 {fet => tools/fet}/FG/18.png                  | Bin
 {fet => tools/fet}/FG/19.png                  | Bin
 {fet => tools/fet}/FG/2.png                   | Bin
 {fet => tools/fet}/FG/20.png                  | Bin
 {fet => tools/fet}/FG/21.png                  | Bin
 {fet => tools/fet}/FG/22.png                  | Bin
 {fet => tools/fet}/FG/23.png                  | Bin
 {fet => tools/fet}/FG/24.png                  | Bin
 {fet => tools/fet}/FG/25.png                  | Bin
 {fet => tools/fet}/FG/26.png                  | Bin
 {fet => tools/fet}/FG/27.png                  | Bin
 {fet => tools/fet}/FG/28.png                  | Bin
 {fet => tools/fet}/FG/29.png                  | Bin
 {fet => tools/fet}/FG/3.png                   | Bin
 {fet => tools/fet}/FG/30.png                  | Bin
 {fet => tools/fet}/FG/31.png                  | Bin
 {fet => tools/fet}/FG/4.png                   | Bin
 {fet => tools/fet}/FG/5.png                   | Bin
 {fet => tools/fet}/FG/6.png                   | Bin
 {fet => tools/fet}/FG/7.png                   | Bin
 {fet => tools/fet}/FG/8.png                   | Bin
 {fet => tools/fet}/FG/9.png                   | Bin
 {fet => tools/fet}/GT/1.png                   | Bin
 {fet => tools/fet}/GT/10.png                  | Bin
 {fet => tools/fet}/GT/11.png                  | Bin
 {fet => tools/fet}/GT/12.png                  | Bin
 {fet => tools/fet}/GT/13.png                  | Bin
 {fet => tools/fet}/GT/14.png                  | Bin
 {fet => tools/fet}/GT/15.png                  | Bin
 {fet => tools/fet}/GT/16.png                  | Bin
 {fet => tools/fet}/GT/17.png                  | Bin
 {fet => tools/fet}/GT/18.png                  | Bin
 {fet => tools/fet}/GT/19.png                  | Bin
 {fet => tools/fet}/GT/2.png                   | Bin
 {fet => tools/fet}/GT/20.png                  | Bin
 {fet => tools/fet}/GT/21.png                  | Bin
 {fet => tools/fet}/GT/22.png                  | Bin
 {fet => tools/fet}/GT/23.png                  | Bin
 {fet => tools/fet}/GT/24.png                  | Bin
 {fet => tools/fet}/GT/25.png                  | Bin
 {fet => tools/fet}/GT/26.png                  | Bin
 {fet => tools/fet}/GT/27.png                  | Bin
 {fet => tools/fet}/GT/28.png                  | Bin
 {fet => tools/fet}/GT/29.png                  | Bin
 {fet => tools/fet}/GT/3.png                   | Bin
 {fet => tools/fet}/GT/30.png                  | Bin
 {fet => tools/fet}/GT/31.png                  | Bin
 {fet => tools/fet}/GT/4.png                   | Bin
 {fet => tools/fet}/GT/5.png                   | Bin
 {fet => tools/fet}/GT/6.png                   | Bin
 {fet => tools/fet}/GT/7.png                   | Bin
 {fet => tools/fet}/GT/8.png                   | Bin
 {fet => tools/fet}/GT/9.png                   | Bin
 {fet => tools/fet}/README.txt                 |   0
 {fet => tools/fet}/SC/1.png                   | Bin
 {fet => tools/fet}/SC/10.png                  | Bin
 {fet => tools/fet}/SC/11.png                  | Bin
 {fet => tools/fet}/SC/12.png                  | Bin
 {fet => tools/fet}/SC/13.png                  | Bin
 {fet => tools/fet}/SC/14.png                  | Bin
 {fet => tools/fet}/SC/15.png                  | Bin
 {fet => tools/fet}/SC/16.png                  | Bin
 {fet => tools/fet}/SC/17.png                  | Bin
 {fet => tools/fet}/SC/18.png                  | Bin
 {fet => tools/fet}/SC/19.png                  | Bin
 {fet => tools/fet}/SC/2.png                   | Bin
 {fet => tools/fet}/SC/20.png                  | Bin
 {fet => tools/fet}/SC/21.png                  | Bin
 {fet => tools/fet}/SC/22.png                  | Bin
 {fet => tools/fet}/SC/23.png                  | Bin
 {fet => tools/fet}/SC/24.png                  | Bin
 {fet => tools/fet}/SC/25.png                  | Bin
 {fet => tools/fet}/SC/26.png                  | Bin
 {fet => tools/fet}/SC/27.png                  | Bin
 {fet => tools/fet}/SC/28.png                  | Bin
 {fet => tools/fet}/SC/29.png                  | Bin
 {fet => tools/fet}/SC/3.png                   | Bin
 {fet => tools/fet}/SC/30.png                  | Bin
 {fet => tools/fet}/SC/31.png                  | Bin
 {fet => tools/fet}/SC/4.png                   | Bin
 {fet => tools/fet}/SC/5.png                   | Bin
 {fet => tools/fet}/SC/6.png                   | Bin
 {fet => tools/fet}/SC/7.png                   | Bin
 {fet => tools/fet}/SC/8.png                   | Bin
 {fet => tools/fet}/SC/9.png                   | Bin
 {fet => tools/fet}/fet.py                     |   0
 {wrapper_java => wrapper/java}/.gitignore     |   0
 {wrapper_java => wrapper/java}/CMakeLists.txt |   8 +-
 {wrapper_java => wrapper/java}/README.md      |   4 +-
 .../java}/bgslibrary_java_module.cpp          |  16 -
 .../java}/bgslibrary_java_module.hpp          |  18 +-
 .../java}/config/.gitignore                   |   2 +-
 .../java}/images/320x240.gif                  | Bin
 .../java}/images/640x480.png                  | Bin
 {wrapper_java => wrapper/java}/libs/README.md |   0
 .../java}/libs/opencv-320.jar                 | Bin
 .../java}/src/bgslibrary/.gitignore           |   0
 .../java}/src/bgslibrary/BgsLib.java          |  16 -
 .../java}/src/bgslibrary/ImagePanel.java      |   0
 .../java}/src/bgslibrary/Main.java            |  16 -
 .../java}/src/bgslibrary/Utils.java           |  16 -
 .../java}/src/bgslibrary_BgsLib.h             |   0
 {wrapper_matlab => wrapper/matlab}/.gitignore |   0
 {wrapper_matlab => wrapper/matlab}/README.txt |   0
 .../matlab}/README_visionopencv.txt           |   0
 .../matlab}/backgroundSubtractor.m            |  18 -
 .../matlab}/backgroundSubtractor_wrapper.cpp  |  20 +-
 wrapper/matlab/compile.m                      |  95 +++
 .../matlab}/config/.gitignore                 |   2 +-
 {wrapper_matlab => wrapper/matlab}/demo.m     |  20 +-
 {wrapper_matlab => wrapper/matlab}/mxarray.h  |   0
 {wrapper_matlab => wrapper/matlab}/mxtypes.h  |   0
 .../matlab}/opencvinterface.mlpkginstall      |   0
 {wrapper_matlab => wrapper/matlab}/run_demo.m |   0
 wrapper/python/bgslibrary_module.cpp          | 309 ++++++++
 .../python}/ndarray_converter.cpp             |  11 +-
 .../python}/ndarray_converter.h               |   1 -
 wrapper_matlab/compile.m                      |  95 ---
 wrapper_python/bgslibrary_module.cpp          | 319 --------
 569 files changed, 5294 insertions(+), 11984 deletions(-)
 delete mode 100644 COPYING.txt
 delete mode 100644 Config.h
 delete mode 100644 IFrameProcessor.h
 delete mode 100644 VideoAnalysis.h
 delete mode 100644 VideoCapture.h
 delete mode 100644 config/MultiCue.xml
 rename Demo.py => demo.py (100%)
 rename Demo2.py => demo2.py (68%)
 delete mode 100644 demos/linux_ubuntu/.gitignore
 delete mode 100644 demos/linux_ubuntu/CMakeLists.txt
 delete mode 100644 demos/linux_ubuntu/FrameDifferenceTest.cpp
 delete mode 100644 demos/linux_ubuntu/README.txt
 delete mode 100644 demos/macosx/.gitignore
 delete mode 100644 demos/macosx/CMakeLists.txt
 delete mode 100644 demos/macosx/FrameDifferenceTest.cpp
 delete mode 100644 demos/macosx/README.txt
 create mode 100644 examples/CMakeLists.txt
 rename Demo.cpp => examples/Demo.cpp (73%)
 rename Demo2.cpp => examples/Demo2.cpp (69%)
 create mode 100644 examples/README.md
 rename {gui_mfc/outputs/background => examples/build}/.gitignore (100%)
 rename {gui_mfc/outputs/foreground => examples/config}/.gitignore (100%)
 create mode 100644 examples/run_demo.bat
 create mode 100755 examples/run_demo.sh
 create mode 100644 examples/run_demo2.bat
 create mode 100755 examples/run_demo2.sh
 create mode 100644 gui/README.md
 rename {gui_java => gui/java}/README.txt (100%)
 rename {gui_java => gui/java}/_COPY_bgslibrary.exe_HERE_ (100%)
 rename {gui_java => gui/java}/bgslibrary_gui.jar (100%)
 rename {gui_java => gui/java}/bgslibrary_gui.properties (100%)
 rename {gui_java => gui/java}/build.xml (100%)
 rename {gui_java => gui/java}/config/.gitignore (100%)
 rename {gui_java => gui/java}/config/FrameProcessor.xml (100%)
 rename {gui_java => gui/java}/config/PreProcessor.xml (100%)
 rename {gui_java => gui/java}/config/VideoCapture.xml (100%)
 rename {gui_java => gui/java}/images/bgslibrary_gui_screen01.png (100%)
 rename {gui_java => gui/java}/images/bgslibrary_gui_screen02.png (100%)
 rename {gui_java => gui/java}/images/bgslibrary_gui_screen03.png (100%)
 rename {gui_java => gui/java}/images/bgslibrary_gui_screen04.png (100%)
 rename {gui_java => gui/java}/images/logo.jpg (100%)
 rename {gui_java => gui/java}/lib/commons-configuration-1.8.jar (100%)
 rename {gui_java => gui/java}/lib/commons-io-2.3.jar (100%)
 rename {gui_java => gui/java}/lib/commons-lang-2.6.jar (100%)
 rename {gui_java => gui/java}/lib/commons-logging-1.1.1.jar (100%)
 rename {gui_java => gui/java}/lib/swingx-all-1.6.3.jar (100%)
 rename {gui_java => gui/java}/lib/swingx-beaninfo-1.6.3.jar (100%)
 rename {gui_java => gui/java}/manifest.mf (100%)
 rename {gui_java => gui/java}/nbproject/build-impl.xml (100%)
 rename {gui_java => gui/java}/nbproject/genfiles.properties (100%)
 rename {gui_java => gui/java}/nbproject/private/config.properties (100%)
 rename {gui_java => gui/java}/nbproject/private/private.properties (100%)
 rename {gui_java => gui/java}/nbproject/private/private.xml (100%)
 rename {gui_java => gui/java}/nbproject/project.properties (100%)
 rename {gui_java => gui/java}/nbproject/project.xml (100%)
 rename {gui_java => gui/java}/run_camera.bat (100%)
 rename {gui_java => gui/java}/run_java_gui.bat (100%)
 rename {gui_java => gui/java}/run_java_gui_with_console.bat (100%)
 rename {gui_java => gui/java}/run_video.bat (100%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/Main.java (60%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/entity/Command.java (83%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/entity/Configuration.java (78%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/gui/AboutDialog.form (100%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/gui/AboutDialog.java (87%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/gui/MainFrame.form (100%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/gui/MainFrame.java (99%)
 rename {gui_java => gui/java}/src/br/com/bgslibrary/resources/logo.jpg (100%)
 rename {gui_mfc => gui/mfc}/.gitignore (100%)
 rename {gui_mfc => gui/mfc}/ReadMe.txt (100%)
 rename {gui_mfc => gui/mfc}/config/AdaptiveBackgroundLearning.xml (100%)
 rename {gui_mfc => gui/mfc}/config/AdaptiveSelectiveBackgroundLearning.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPAdaptiveMedianBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPEigenbackgroundBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPGrimsonGMMBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPMeanBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPPratiMediodBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPTextureBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPWrenGABGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/DPZivkovicAGMMBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/FrameDifferenceBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/FuzzyChoquetIntegral.xml (100%)
 rename {gui_mfc => gui/mfc}/config/FuzzySugenoIntegral.xml (100%)
 rename {gui_mfc => gui/mfc}/config/GMG.xml (100%)
 rename {gui_mfc => gui/mfc}/config/IndependentMultimodalBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/KDE.xml (100%)
 rename {gui_mfc => gui/mfc}/config/LBAdaptiveSOM.xml (100%)
 rename {gui_mfc => gui/mfc}/config/LBFuzzyAdaptiveSOM.xml (100%)
 rename {gui_mfc => gui/mfc}/config/LBFuzzyGaussian.xml (100%)
 rename {gui_mfc => gui/mfc}/config/LBMixtureOfGaussians.xml (100%)
 rename {gui_mfc => gui/mfc}/config/LBSimpleGaussian.xml (100%)
 rename {gui_mfc => gui/mfc}/config/LOBSTERBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/MixtureOfGaussianV1BGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/MixtureOfGaussianV2BGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/MultiCueBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/MultiLayerBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/SigmaDeltaBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/StaticFrameDifferenceBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/SuBSENSEBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/T2FGMM_UM.xml (100%)
 rename {gui_mfc => gui/mfc}/config/T2FGMM_UV.xml (100%)
 rename {gui_mfc => gui/mfc}/config/T2FMRF_UM.xml (100%)
 rename {gui_mfc => gui/mfc}/config/T2FMRF_UV.xml (100%)
 rename {gui_mfc => gui/mfc}/config/VuMeter.xml (100%)
 rename {gui_mfc => gui/mfc}/config/WeightedMovingMeanBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/config/WeightedMovingVarianceBGS.xml (100%)
 rename {gui_mfc => gui/mfc}/dataset/video.avi (100%)
 rename {gui_mfc/outputs/input => gui/mfc/outputs/background}/.gitignore (100%)
 rename {gui_qt/build => gui/mfc/outputs/foreground}/.gitignore (100%)
 rename {wrapper_java/config => gui/mfc/outputs/input}/.gitignore (100%)
 rename {gui_mfc => gui/mfc}/src/.gitignore (100%)
 rename {gui_mfc => gui/mfc}/src/App.cpp (100%)
 rename {gui_mfc => gui/mfc}/src/App.h (100%)
 rename {gui_mfc => gui/mfc}/src/Dlg.cpp (100%)
 rename {gui_mfc => gui/mfc}/src/Dlg.h (100%)
 rename {gui_mfc => gui/mfc}/src/ReadMe.txt (100%)
 rename {gui_mfc => gui/mfc}/src/bgslibrary_vs2013_mfc.rc (100%)
 rename {gui_mfc => gui/mfc}/src/bgslibrary_vs2013_mfc.sln (100%)
 rename {gui_mfc => gui/mfc}/src/bgslibrary_vs2013_mfc.vcxproj (100%)
 rename {gui_mfc => gui/mfc}/src/bgslibrary_vs2013_mfc.vcxproj.filters (100%)
 rename {gui_mfc => gui/mfc}/src/bgslibrary_vs2013_mfc.vcxproj.user (100%)
 rename {gui_mfc => gui/mfc}/src/res/bgslibrary_vs2013_mfc.ico (100%)
 rename {gui_mfc => gui/mfc}/src/res/bgslibrary_vs2013_mfc.rc2 (100%)
 rename {gui_mfc => gui/mfc}/src/resource.h (100%)
 rename {gui_mfc => gui/mfc}/src/stdafx.cpp (100%)
 rename {gui_mfc => gui/mfc}/src/stdafx.h (100%)
 rename {gui_mfc => gui/mfc}/src/targetver.h (100%)
 rename {gui_qt => gui/qt}/.gitignore (100%)
 rename {gui_qt => gui/qt}/CMakeLists.txt (90%)
 create mode 100644 gui/qt/README.md
 rename {gui_qt => gui/qt}/application.qrc (100%)
 rename {gui_qt => gui/qt}/bgslibrary_gui.cpp (54%)
 create mode 100644 gui/qt/bgslibrary_gui.pro
 rename {wrapper_matlab/config => gui/qt/build}/.gitignore (100%)
 rename {gui_qt => gui/qt}/figs/copy.png (100%)
 rename {gui_qt => gui/qt}/figs/cut.png (100%)
 rename {gui_qt => gui/qt}/figs/new.png (100%)
 rename {gui_qt => gui/qt}/figs/open.png (100%)
 rename {gui_qt => gui/qt}/figs/paste.png (100%)
 rename {gui_qt => gui/qt}/figs/save.png (100%)
 rename {gui_qt => gui/qt}/mainwindow.cpp (96%)
 rename {gui_qt => gui/qt}/mainwindow.h (73%)
 rename {gui_qt => gui/qt}/mainwindow.ui (100%)
 rename {gui_qt => gui/qt}/qt_utils.cpp (68%)
 rename {gui_qt => gui/qt}/qt_utils.h (78%)
 rename {gui_qt => gui/qt}/texteditor.cpp (93%)
 rename {gui_qt => gui/qt}/texteditor.h (57%)
 rename {gui_qt => gui/qt}/ui_mainwindow.h (100%)
 delete mode 100644 gui_qt/README.txt
 delete mode 100644 gui_qt/bgslibrary_gui.pro
 create mode 160000 modules/pybind11
 delete mode 100644 package_bgs/AdaptiveBackgroundLearning.h
 delete mode 100644 package_bgs/AdaptiveSelectiveBackgroundLearning.h
 delete mode 100644 package_bgs/FrameDifference.cpp
 delete mode 100644 package_bgs/FrameDifference.h
 delete mode 100644 package_bgs/FuzzyChoquetIntegral.h
 delete mode 100644 package_bgs/GMG.h
 delete mode 100644 package_bgs/IndependentMultimodal.h
 delete mode 100644 package_bgs/KDE/KernelTable.cpp
 delete mode 100644 package_bgs/KDE/KernelTable.h
 delete mode 100644 package_bgs/KDE/NPBGSubtractor.h
 delete mode 100644 package_bgs/KDE/NPBGmodel.cpp
 delete mode 100644 package_bgs/KDE/NPBGmodel.h
 delete mode 100644 package_bgs/LBAdaptiveSOM.cpp
 delete mode 100644 package_bgs/LBAdaptiveSOM.h
 delete mode 100644 package_bgs/LBFuzzyAdaptiveSOM.cpp
 delete mode 100644 package_bgs/LBFuzzyGaussian.h
 delete mode 100644 package_bgs/LBMixtureOfGaussians.h
 delete mode 100644 package_bgs/LBP_MRF.h
 delete mode 100644 package_bgs/LBP_MRF/MEDefs.cpp
 delete mode 100644 package_bgs/LBP_MRF/MEDefs.hpp
 delete mode 100644 package_bgs/LBP_MRF/block.h
 delete mode 100644 package_bgs/LBP_MRF/graph.cpp
 delete mode 100644 package_bgs/LBSimpleGaussian.h
 delete mode 100644 package_bgs/LOBSTER.cpp
 delete mode 100644 package_bgs/LOBSTER.h
 delete mode 100644 package_bgs/MultiLayer/BlobExtraction.h
 delete mode 100644 package_bgs/MultiLayer/BlobLibraryConfiguration.h
 delete mode 100644 package_bgs/MultiLayer/LocalBinaryPattern.h
 delete mode 100644 package_bgs/MultiLayer/OpenCvLegacyIncludes.h
 delete mode 100644 package_bgs/PAWCS.cpp
 delete mode 100644 package_bgs/PAWCS.h
 delete mode 100644 package_bgs/PixelBasedAdaptiveSegmenter.cpp
 delete mode 100644 package_bgs/SigmaDelta.h
 delete mode 100644 package_bgs/StaticFrameDifference.cpp
 delete mode 100644 package_bgs/StaticFrameDifference.h
 delete mode 100644 package_bgs/SuBSENSE.cpp
 delete mode 100644 package_bgs/SuBSENSE.h
 delete mode 100644 package_bgs/TwoPoints.h
 delete mode 100644 package_bgs/VuMeter.h
 delete mode 100644 package_bgs/WeightedMovingMean.h
 delete mode 100644 package_bgs/_template_/Amber.h
 delete mode 100644 package_bgs/_template_/MyBGS.h
 delete mode 100644 package_bgs/bgslibrary.cpp
 delete mode 100644 package_bgs/dp/AdaptiveMedianBGS.h
 delete mode 100644 package_bgs/dp/Bgs.h
 delete mode 100644 package_bgs/dp/BgsParams.h
 delete mode 100644 package_bgs/dp/Error.cpp
 delete mode 100644 package_bgs/dp/Error.h
 delete mode 100644 package_bgs/lb/BGModel.cpp
 delete mode 100644 package_bgs/lb/BGModel.h
 delete mode 100644 package_bgs/lb/BGModelFuzzyGauss.h
 delete mode 100644 package_bgs/lb/BGModelFuzzySom.h
 delete mode 100644 package_bgs/lb/BGModelGauss.h
 delete mode 100644 package_bgs/lb/BGModelMog.h
 delete mode 100644 package_bgs/lb/BGModelSom.h
 delete mode 100644 package_bgs/lb/Types.h
 delete mode 160000 pybind11
 delete mode 100644 run_demo.bat
 delete mode 100755 run_demo.sh
 delete mode 100644 run_demo2.bat
 delete mode 100755 run_demo2.sh
 create mode 100644 src/Config.h
 rename FrameProcessor.cpp => src/FrameProcessor.cpp (69%)
 rename FrameProcessor.h => src/FrameProcessor.h (87%)
 create mode 100644 src/IFrameProcessor.h
 rename Main.cpp => src/Main.cpp (66%)
 rename PreProcessor.cpp => src/PreProcessor.cpp (71%)
 rename PreProcessor.h => src/PreProcessor.h (53%)
 rename VideoAnalysis.cpp => src/VideoAnalysis.cpp (85%)
 create mode 100644 src/VideoAnalysis.h
 rename VideoCapture.cpp => src/VideoCapture.cpp (68%)
 create mode 100644 src/VideoCapture.h
 rename {package_analysis => src/package_analysis}/ForegroundMaskAnalysis.cpp (54%)
 rename {package_analysis => src/package_analysis}/ForegroundMaskAnalysis.h (50%)
 rename {package_analysis => src/package_analysis}/PerformanceUtils.cpp (95%)
 rename {package_analysis => src/package_analysis}/PerformanceUtils.h (60%)
 rename {package_analysis => src/package_analysis}/PixelUtils.cpp (93%)
 rename {package_analysis => src/package_analysis}/PixelUtils.h (68%)
 rename {package_bgs => src/package_bgs}/AdaptiveBackgroundLearning.cpp (60%)
 create mode 100644 src/package_bgs/AdaptiveBackgroundLearning.h
 rename {package_bgs => src/package_bgs}/AdaptiveSelectiveBackgroundLearning.cpp (67%)
 create mode 100644 src/package_bgs/AdaptiveSelectiveBackgroundLearning.h
 rename {package_bgs => src/package_bgs}/CodeBook.cpp (77%)
 rename {package_bgs => src/package_bgs}/CodeBook.h (61%)
 rename {package_bgs => src/package_bgs}/DPAdaptiveMedian.cpp (61%)
 rename {package_bgs => src/package_bgs}/DPAdaptiveMedian.h (53%)
 rename {package_bgs => src/package_bgs}/DPEigenbackground.cpp (61%)
 rename {package_bgs => src/package_bgs}/DPEigenbackground.h (53%)
 rename {package_bgs => src/package_bgs}/DPGrimsonGMM.cpp (60%)
 rename {package_bgs => src/package_bgs}/DPGrimsonGMM.h (52%)
 rename {package_bgs => src/package_bgs}/DPMean.cpp (57%)
 rename {package_bgs => src/package_bgs}/DPMean.h (51%)
 rename {package_bgs => src/package_bgs}/DPPratiMediod.cpp (59%)
 rename {package_bgs => src/package_bgs}/DPPratiMediod.h (53%)
 rename {package_bgs => src/package_bgs}/DPTexture.cpp (74%)
 rename {package_bgs => src/package_bgs}/DPTexture.h (57%)
 rename {package_bgs => src/package_bgs}/DPWrenGA.cpp (59%)
 rename {package_bgs => src/package_bgs}/DPWrenGA.h (51%)
 rename {package_bgs => src/package_bgs}/DPZivkovicAGMM.cpp (60%)
 rename {package_bgs => src/package_bgs}/DPZivkovicAGMM.h (52%)
 create mode 100644 src/package_bgs/FrameDifference.cpp
 create mode 100644 src/package_bgs/FrameDifference.h
 rename {package_bgs => src/package_bgs}/FuzzyChoquetIntegral.cpp (77%)
 create mode 100644 src/package_bgs/FuzzyChoquetIntegral.h
 rename {package_bgs => src/package_bgs}/FuzzySugenoIntegral.cpp (77%)
 rename {package_bgs => src/package_bgs}/FuzzySugenoIntegral.h (50%)
 rename {package_bgs => src/package_bgs}/GMG.cpp (53%)
 create mode 100644 src/package_bgs/GMG.h
 rename {package_bgs => src/package_bgs}/IBGS.h (76%)
 create mode 100644 src/package_bgs/ILoadSaveConfig.h
 rename {package_bgs => src/package_bgs}/IMBS/IMBS.cpp (94%)
 rename {package_bgs => src/package_bgs}/IMBS/IMBS.hpp (77%)
 rename {package_bgs => src/package_bgs}/IndependentMultimodal.cpp (51%)
 create mode 100644 src/package_bgs/IndependentMultimodal.h
 rename {package_bgs => src/package_bgs}/KDE.cpp (60%)
 rename {package_bgs => src/package_bgs}/KDE.h (53%)
 create mode 100644 src/package_bgs/KDE/KernelTable.cpp
 create mode 100644 src/package_bgs/KDE/KernelTable.h
 rename {package_bgs => src/package_bgs}/KDE/NPBGSubtractor.cpp (92%)
 create mode 100644 src/package_bgs/KDE/NPBGSubtractor.h
 create mode 100644 src/package_bgs/KDE/NPBGmodel.cpp
 create mode 100644 src/package_bgs/KDE/NPBGmodel.h
 rename {package_bgs => src/package_bgs}/KNN.cpp (51%)
 rename {package_bgs => src/package_bgs}/KNN.h (52%)
 create mode 100644 src/package_bgs/LBAdaptiveSOM.cpp
 create mode 100644 src/package_bgs/LBAdaptiveSOM.h
 create mode 100644 src/package_bgs/LBFuzzyAdaptiveSOM.cpp
 rename {package_bgs => src/package_bgs}/LBFuzzyAdaptiveSOM.h (50%)
 rename {package_bgs => src/package_bgs}/LBFuzzyGaussian.cpp (50%)
 create mode 100644 src/package_bgs/LBFuzzyGaussian.h
 rename {package_bgs => src/package_bgs}/LBMixtureOfGaussians.cpp (51%)
 create mode 100644 src/package_bgs/LBMixtureOfGaussians.h
 rename {package_bgs => src/package_bgs}/LBP_MRF.cpp (52%)
 create mode 100644 src/package_bgs/LBP_MRF.h
 create mode 100644 src/package_bgs/LBP_MRF/MEDefs.cpp
 create mode 100644 src/package_bgs/LBP_MRF/MEDefs.hpp
 rename {package_bgs => src/package_bgs}/LBP_MRF/MEHistogram.cpp (86%)
 rename {package_bgs => src/package_bgs}/LBP_MRF/MEHistogram.hpp (85%)
 rename {package_bgs => src/package_bgs}/LBP_MRF/MEImage.cpp (96%)
 rename {package_bgs => src/package_bgs}/LBP_MRF/MEImage.hpp (94%)
 rename {package_bgs => src/package_bgs}/LBP_MRF/MotionDetection.cpp (96%)
 rename {package_bgs => src/package_bgs}/LBP_MRF/MotionDetection.hpp (86%)
 create mode 100644 src/package_bgs/LBP_MRF/block.h
 create mode 100644 src/package_bgs/LBP_MRF/graph.cpp
 rename {package_bgs => src/package_bgs}/LBP_MRF/graph.h (63%)
 rename {package_bgs => src/package_bgs}/LBP_MRF/maxflow.cpp (84%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorLBSP.cpp (74%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorLBSP.h (85%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorLBSP_.cpp (73%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorLBSP_.h (86%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorLOBSTER.cpp (96%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorLOBSTER.h (85%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorPAWCS.cpp (99%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorPAWCS.h (92%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorSuBSENSE.cpp (98%)
 rename {package_bgs => src/package_bgs}/LBSP/BackgroundSubtractorSuBSENSE.h (91%)
 rename {package_bgs => src/package_bgs}/LBSP/DistanceUtils.h (95%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP.cpp (95%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP.h (92%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP_.cpp (95%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP_.h (92%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP_16bits_dbcross_1ch.i (100%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP_16bits_dbcross_3ch1t.i (100%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP_16bits_dbcross_3ch3t.i (100%)
 rename {package_bgs => src/package_bgs}/LBSP/LBSP_16bits_dbcross_s3ch.i (100%)
 rename {package_bgs => src/package_bgs}/LBSP/RandUtils.h (86%)
 rename {package_bgs => src/package_bgs}/LBSimpleGaussian.cpp (51%)
 create mode 100644 src/package_bgs/LBSimpleGaussian.h
 create mode 100644 src/package_bgs/LOBSTER.cpp
 create mode 100644 src/package_bgs/LOBSTER.h
 rename {package_bgs => src/package_bgs}/MixtureOfGaussianV1.cpp (60%)
 rename {package_bgs => src/package_bgs}/MixtureOfGaussianV1.h (50%)
 rename {package_bgs => src/package_bgs}/MixtureOfGaussianV2.cpp (66%)
 rename {package_bgs => src/package_bgs}/MixtureOfGaussianV2.h (52%)
 rename {package_bgs => src/package_bgs}/MultiCue.cpp (95%)
 rename {package_bgs => src/package_bgs}/MultiCue.h (93%)
 rename {package_bgs => src/package_bgs}/MultiLayer.cpp (57%)
 rename {package_bgs => src/package_bgs}/MultiLayer.h (74%)
 rename {package_bgs => src/package_bgs}/MultiLayer/BGS.h (72%)
 rename {package_bgs => src/package_bgs}/MultiLayer/BackgroundSubtractionAPI.h (56%)
 rename {package_bgs => src/package_bgs}/MultiLayer/BlobExtraction.cpp (94%)
 create mode 100644 src/package_bgs/MultiLayer/BlobExtraction.h
 create mode 100644 src/package_bgs/MultiLayer/BlobLibraryConfiguration.h
 rename {package_bgs => src/package_bgs}/MultiLayer/BlobResult.cpp (91%)
 rename {package_bgs => src/package_bgs}/MultiLayer/BlobResult.h (62%)
 rename {package_bgs => src/package_bgs}/MultiLayer/CMultiLayerBGS.cpp (96%)
 rename {package_bgs => src/package_bgs}/MultiLayer/CMultiLayerBGS.h (81%)
 rename {package_bgs => src/package_bgs}/MultiLayer/LocalBinaryPattern.cpp (75%)
 create mode 100644 src/package_bgs/MultiLayer/LocalBinaryPattern.h
 rename {package_bgs => src/package_bgs}/MultiLayer/OpenCvDataConversion.h (67%)
 create mode 100644 src/package_bgs/MultiLayer/OpenCvLegacyIncludes.h
 rename {package_bgs => src/package_bgs}/MultiLayer/blob.cpp (92%)
 rename {package_bgs => src/package_bgs}/MultiLayer/blob.h (88%)
 create mode 100644 src/package_bgs/PAWCS.cpp
 create mode 100644 src/package_bgs/PAWCS.h
 rename {package_bgs => src/package_bgs}/PBAS/PBAS.cpp (95%)
 rename {package_bgs => src/package_bgs}/PBAS/PBAS.h (73%)
 create mode 100644 src/package_bgs/PixelBasedAdaptiveSegmenter.cpp
 rename {package_bgs => src/package_bgs}/PixelBasedAdaptiveSegmenter.h (53%)
 rename {package_bgs => src/package_bgs}/SigmaDelta.cpp (56%)
 create mode 100644 src/package_bgs/SigmaDelta.h
 rename {package_bgs => src/package_bgs}/SigmaDelta/sdLaMa091.cpp (95%)
 rename {package_bgs => src/package_bgs}/SigmaDelta/sdLaMa091.h (67%)
 create mode 100644 src/package_bgs/StaticFrameDifference.cpp
 create mode 100644 src/package_bgs/StaticFrameDifference.h
 create mode 100644 src/package_bgs/SuBSENSE.cpp
 create mode 100644 src/package_bgs/SuBSENSE.h
 rename {package_bgs => src/package_bgs}/T2F/FuzzyUtils.cpp (96%)
 rename {package_bgs => src/package_bgs}/T2F/FuzzyUtils.h (62%)
 rename {package_bgs => src/package_bgs}/T2F/MRF.cpp (91%)
 rename {package_bgs => src/package_bgs}/T2F/MRF.h (77%)
 rename {package_bgs => src/package_bgs}/T2F/T2FGMM.cpp (89%)
 rename {package_bgs => src/package_bgs}/T2F/T2FGMM.h (73%)
 rename {package_bgs => src/package_bgs}/T2F/T2FMRF.cpp (90%)
 rename {package_bgs => src/package_bgs}/T2F/T2FMRF.h (77%)
 rename {package_bgs => src/package_bgs}/T2FGMM_UM.cpp (58%)
 rename {package_bgs => src/package_bgs}/T2FGMM_UM.h (52%)
 rename {package_bgs => src/package_bgs}/T2FGMM_UV.cpp (58%)
 rename {package_bgs => src/package_bgs}/T2FGMM_UV.h (52%)
 rename {package_bgs => src/package_bgs}/T2FMRF_UM.cpp (67%)
 rename {package_bgs => src/package_bgs}/T2FMRF_UM.h (55%)
 rename {package_bgs => src/package_bgs}/T2FMRF_UV.cpp (67%)
 rename {package_bgs => src/package_bgs}/T2FMRF_UV.h (55%)
 rename {package_bgs => src/package_bgs}/TwoPoints.cpp (61%)
 create mode 100644 src/package_bgs/TwoPoints.h
 rename {package_bgs => src/package_bgs}/TwoPoints/two_points.cpp (94%)
 rename {package_bgs => src/package_bgs}/TwoPoints/two_points.h (57%)
 rename {package_bgs => src/package_bgs}/ViBe.cpp (51%)
 rename {package_bgs => src/package_bgs}/ViBe.h (53%)
 rename {package_bgs => src/package_bgs}/ViBe/LICENSE (100%)
 rename {package_bgs => src/package_bgs}/ViBe/vibe-background-sequential.cpp (97%)
 rename {package_bgs => src/package_bgs}/ViBe/vibe-background-sequential.h (81%)
 rename {package_bgs => src/package_bgs}/VuMeter.cpp (53%)
 create mode 100644 src/package_bgs/VuMeter.h
 rename {package_bgs => src/package_bgs}/VuMeter/TBackground.cpp (80%)
 rename {package_bgs => src/package_bgs}/VuMeter/TBackground.h (54%)
 rename {package_bgs => src/package_bgs}/VuMeter/TBackgroundVuMeter.cpp (90%)
 rename {package_bgs => src/package_bgs}/VuMeter/TBackgroundVuMeter.h (65%)
 rename {package_bgs => src/package_bgs}/WeightedMovingMean.cpp (62%)
 create mode 100644 src/package_bgs/WeightedMovingMean.h
 rename {package_bgs => src/package_bgs}/WeightedMovingVariance.cpp (73%)
 rename {package_bgs => src/package_bgs}/WeightedMovingVariance.h (50%)
 rename {package_bgs => src/package_bgs}/_template_/Amber.cpp (68%)
 create mode 100644 src/package_bgs/_template_/Amber.h
 rename {package_bgs => src/package_bgs}/_template_/MyBGS.cpp (50%)
 create mode 100644 src/package_bgs/_template_/MyBGS.h
 rename {package_bgs => src/package_bgs}/_template_/amber/amber.cpp (64%)
 rename {package_bgs => src/package_bgs}/_template_/amber/amber.h (61%)
 create mode 100644 src/package_bgs/bgslibrary.cpp
 rename {package_bgs => src/package_bgs}/bgslibrary.h (68%)
 rename {package_bgs => src/package_bgs}/dp/AdaptiveMedianBGS.cpp (73%)
 create mode 100644 src/package_bgs/dp/AdaptiveMedianBGS.h
 create mode 100644 src/package_bgs/dp/Bgs.h
 create mode 100644 src/package_bgs/dp/BgsParams.h
 rename {package_bgs => src/package_bgs}/dp/Eigenbackground.cpp (80%)
 rename {package_bgs => src/package_bgs}/dp/Eigenbackground.h (51%)
 create mode 100644 src/package_bgs/dp/Error.cpp
 create mode 100644 src/package_bgs/dp/Error.h
 rename {package_bgs => src/package_bgs}/dp/GrimsonGMM.cpp (82%)
 rename {package_bgs => src/package_bgs}/dp/GrimsonGMM.h (61%)
 rename {package_bgs => src/package_bgs}/dp/Image.cpp (50%)
 rename {package_bgs => src/package_bgs}/dp/Image.h (85%)
 rename {package_bgs => src/package_bgs}/dp/MeanBGS.cpp (75%)
 rename {package_bgs => src/package_bgs}/dp/MeanBGS.h (52%)
 rename {package_bgs => src/package_bgs}/dp/PratiMediodBGS.cpp (84%)
 rename {package_bgs => src/package_bgs}/dp/PratiMediodBGS.h (61%)
 rename {package_bgs => src/package_bgs}/dp/TextureBGS.cpp (86%)
 rename {package_bgs => src/package_bgs}/dp/TextureBGS.h (69%)
 rename {package_bgs => src/package_bgs}/dp/WrenGA.cpp (75%)
 rename {package_bgs => src/package_bgs}/dp/WrenGA.h (50%)
 rename {package_bgs => src/package_bgs}/dp/ZivkovicAGMM.cpp (86%)
 rename {package_bgs => src/package_bgs}/dp/ZivkovicAGMM.h (62%)
 create mode 100644 src/package_bgs/lb/BGModel.cpp
 create mode 100644 src/package_bgs/lb/BGModel.h
 rename {package_bgs => src/package_bgs}/lb/BGModelFuzzyGauss.cpp (73%)
 create mode 100644 src/package_bgs/lb/BGModelFuzzyGauss.h
 rename {package_bgs => src/package_bgs}/lb/BGModelFuzzySom.cpp (80%)
 create mode 100644 src/package_bgs/lb/BGModelFuzzySom.h
 rename {package_bgs => src/package_bgs}/lb/BGModelGauss.cpp (71%)
 create mode 100644 src/package_bgs/lb/BGModelGauss.h
 rename {package_bgs => src/package_bgs}/lb/BGModelMog.cpp (81%)
 create mode 100644 src/package_bgs/lb/BGModelMog.h
 rename {package_bgs => src/package_bgs}/lb/BGModelSom.cpp (80%)
 create mode 100644 src/package_bgs/lb/BGModelSom.h
 create mode 100644 src/package_bgs/lb/Types.h
 rename {fet => tools/fet}/FG/1.png (100%)
 rename {fet => tools/fet}/FG/10.png (100%)
 rename {fet => tools/fet}/FG/11.png (100%)
 rename {fet => tools/fet}/FG/12.png (100%)
 rename {fet => tools/fet}/FG/13.png (100%)
 rename {fet => tools/fet}/FG/14.png (100%)
 rename {fet => tools/fet}/FG/15.png (100%)
 rename {fet => tools/fet}/FG/16.png (100%)
 rename {fet => tools/fet}/FG/17.png (100%)
 rename {fet => tools/fet}/FG/18.png (100%)
 rename {fet => tools/fet}/FG/19.png (100%)
 rename {fet => tools/fet}/FG/2.png (100%)
 rename {fet => tools/fet}/FG/20.png (100%)
 rename {fet => tools/fet}/FG/21.png (100%)
 rename {fet => tools/fet}/FG/22.png (100%)
 rename {fet => tools/fet}/FG/23.png (100%)
 rename {fet => tools/fet}/FG/24.png (100%)
 rename {fet => tools/fet}/FG/25.png (100%)
 rename {fet => tools/fet}/FG/26.png (100%)
 rename {fet => tools/fet}/FG/27.png (100%)
 rename {fet => tools/fet}/FG/28.png (100%)
 rename {fet => tools/fet}/FG/29.png (100%)
 rename {fet => tools/fet}/FG/3.png (100%)
 rename {fet => tools/fet}/FG/30.png (100%)
 rename {fet => tools/fet}/FG/31.png (100%)
 rename {fet => tools/fet}/FG/4.png (100%)
 rename {fet => tools/fet}/FG/5.png (100%)
 rename {fet => tools/fet}/FG/6.png (100%)
 rename {fet => tools/fet}/FG/7.png (100%)
 rename {fet => tools/fet}/FG/8.png (100%)
 rename {fet => tools/fet}/FG/9.png (100%)
 rename {fet => tools/fet}/GT/1.png (100%)
 rename {fet => tools/fet}/GT/10.png (100%)
 rename {fet => tools/fet}/GT/11.png (100%)
 rename {fet => tools/fet}/GT/12.png (100%)
 rename {fet => tools/fet}/GT/13.png (100%)
 rename {fet => tools/fet}/GT/14.png (100%)
 rename {fet => tools/fet}/GT/15.png (100%)
 rename {fet => tools/fet}/GT/16.png (100%)
 rename {fet => tools/fet}/GT/17.png (100%)
 rename {fet => tools/fet}/GT/18.png (100%)
 rename {fet => tools/fet}/GT/19.png (100%)
 rename {fet => tools/fet}/GT/2.png (100%)
 rename {fet => tools/fet}/GT/20.png (100%)
 rename {fet => tools/fet}/GT/21.png (100%)
 rename {fet => tools/fet}/GT/22.png (100%)
 rename {fet => tools/fet}/GT/23.png (100%)
 rename {fet => tools/fet}/GT/24.png (100%)
 rename {fet => tools/fet}/GT/25.png (100%)
 rename {fet => tools/fet}/GT/26.png (100%)
 rename {fet => tools/fet}/GT/27.png (100%)
 rename {fet => tools/fet}/GT/28.png (100%)
 rename {fet => tools/fet}/GT/29.png (100%)
 rename {fet => tools/fet}/GT/3.png (100%)
 rename {fet => tools/fet}/GT/30.png (100%)
 rename {fet => tools/fet}/GT/31.png (100%)
 rename {fet => tools/fet}/GT/4.png (100%)
 rename {fet => tools/fet}/GT/5.png (100%)
 rename {fet => tools/fet}/GT/6.png (100%)
 rename {fet => tools/fet}/GT/7.png (100%)
 rename {fet => tools/fet}/GT/8.png (100%)
 rename {fet => tools/fet}/GT/9.png (100%)
 rename {fet => tools/fet}/README.txt (100%)
 rename {fet => tools/fet}/SC/1.png (100%)
 rename {fet => tools/fet}/SC/10.png (100%)
 rename {fet => tools/fet}/SC/11.png (100%)
 rename {fet => tools/fet}/SC/12.png (100%)
 rename {fet => tools/fet}/SC/13.png (100%)
 rename {fet => tools/fet}/SC/14.png (100%)
 rename {fet => tools/fet}/SC/15.png (100%)
 rename {fet => tools/fet}/SC/16.png (100%)
 rename {fet => tools/fet}/SC/17.png (100%)
 rename {fet => tools/fet}/SC/18.png (100%)
 rename {fet => tools/fet}/SC/19.png (100%)
 rename {fet => tools/fet}/SC/2.png (100%)
 rename {fet => tools/fet}/SC/20.png (100%)
 rename {fet => tools/fet}/SC/21.png (100%)
 rename {fet => tools/fet}/SC/22.png (100%)
 rename {fet => tools/fet}/SC/23.png (100%)
 rename {fet => tools/fet}/SC/24.png (100%)
 rename {fet => tools/fet}/SC/25.png (100%)
 rename {fet => tools/fet}/SC/26.png (100%)
 rename {fet => tools/fet}/SC/27.png (100%)
 rename {fet => tools/fet}/SC/28.png (100%)
 rename {fet => tools/fet}/SC/29.png (100%)
 rename {fet => tools/fet}/SC/3.png (100%)
 rename {fet => tools/fet}/SC/30.png (100%)
 rename {fet => tools/fet}/SC/31.png (100%)
 rename {fet => tools/fet}/SC/4.png (100%)
 rename {fet => tools/fet}/SC/5.png (100%)
 rename {fet => tools/fet}/SC/6.png (100%)
 rename {fet => tools/fet}/SC/7.png (100%)
 rename {fet => tools/fet}/SC/8.png (100%)
 rename {fet => tools/fet}/SC/9.png (100%)
 rename {fet => tools/fet}/fet.py (100%)
 rename {wrapper_java => wrapper/java}/.gitignore (100%)
 rename {wrapper_java => wrapper/java}/CMakeLists.txt (91%)
 rename {wrapper_java => wrapper/java}/README.md (89%)
 rename {wrapper_java => wrapper/java}/bgslibrary_java_module.cpp (94%)
 rename {wrapper_java => wrapper/java}/bgslibrary_java_module.hpp (52%)
 rename {demos/linux_ubuntu => wrapper/java}/config/.gitignore (83%)
 rename {wrapper_java => wrapper/java}/images/320x240.gif (100%)
 rename {wrapper_java => wrapper/java}/images/640x480.png (100%)
 rename {wrapper_java => wrapper/java}/libs/README.md (100%)
 rename {wrapper_java => wrapper/java}/libs/opencv-320.jar (100%)
 rename {wrapper_java => wrapper/java}/src/bgslibrary/.gitignore (100%)
 rename {wrapper_java => wrapper/java}/src/bgslibrary/BgsLib.java (67%)
 rename {wrapper_java => wrapper/java}/src/bgslibrary/ImagePanel.java (100%)
 rename {wrapper_java => wrapper/java}/src/bgslibrary/Main.java (87%)
 rename {wrapper_java => wrapper/java}/src/bgslibrary/Utils.java (78%)
 rename {wrapper_java => wrapper/java}/src/bgslibrary_BgsLib.h (100%)
 rename {wrapper_matlab => wrapper/matlab}/.gitignore (100%)
 rename {wrapper_matlab => wrapper/matlab}/README.txt (100%)
 rename {wrapper_matlab => wrapper/matlab}/README_visionopencv.txt (100%)
 rename {wrapper_matlab => wrapper/matlab}/backgroundSubtractor.m (74%)
 rename {wrapper_matlab => wrapper/matlab}/backgroundSubtractor_wrapper.cpp (94%)
 create mode 100644 wrapper/matlab/compile.m
 rename {demos/macosx => wrapper/matlab}/config/.gitignore (83%)
 rename {wrapper_matlab => wrapper/matlab}/demo.m (62%)
 rename {wrapper_matlab => wrapper/matlab}/mxarray.h (100%)
 rename {wrapper_matlab => wrapper/matlab}/mxtypes.h (100%)
 rename {wrapper_matlab => wrapper/matlab}/opencvinterface.mlpkginstall (100%)
 rename {wrapper_matlab => wrapper/matlab}/run_demo.m (100%)
 create mode 100644 wrapper/python/bgslibrary_module.cpp
 rename {wrapper_python => wrapper/python}/ndarray_converter.cpp (96%)
 rename {wrapper_python => wrapper/python}/ndarray_converter.h (99%)
 delete mode 100644 wrapper_matlab/compile.m
 delete mode 100644 wrapper_python/bgslibrary_module.cpp

diff --git a/.gitignore b/.gitignore
index 5ee692f..7949c45 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,12 +3,11 @@ build-*/
 build_*/
 dataset_*/
 binaries*/
-java_gui/dist/
-java_gui/build/
-java_gui/bgslibrary.exe
-python/
-qt_gui/
-fet/etc/
+examples/build-*/
+examples/build_*/
+gui/java/dist/
+gui/java/build/
+gui/java/bgslibrary.exe
 _*
 *.exe
 *.pdb
@@ -22,3 +21,4 @@ _*
 *.files
 *.includes
 bgs.egg-info
+.vscode/
diff --git a/.gitmodules b/.gitmodules
index a90eb86..75ed460 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
 [submodule "pybind11"]
-	path = pybind11
+	path = modules/pybind11
 	url = https://github.com/pybind/pybind11.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32061f4..e92e6b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.12)
 
 project(bgslibrary)
 
@@ -19,6 +19,8 @@ if(BGS_PYTHON_SUPPORT)
   message(STATUS "PYTHON VERSION: ${BGS_PYTHON_VERSION}")
 endif()
 
+set(CMAKE_CXX_STANDARD 14)
+
 if(UNIX)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
   set(CMAKE_MACOSX_RPATH 1)
@@ -117,7 +119,7 @@ if(BGS_PYTHON_SUPPORT)
   #set(PYBIND11_PYTHON_VERSION 2.7 3.5 3.6)
   set(PYBIND11_PYTHON_VERSION ${BGS_PYTHON_VERSION})
   #find_package(pybind11 REQUIRED)
-  add_subdirectory(pybind11)
+  add_subdirectory(modules/pybind11)
 
   #find_package(PythonInterp ${BGS_PYTHON_VERSION} REQUIRED)
   #find_package(PythonLibs ${BGS_PYTHON_VERSION} REQUIRED)
@@ -144,22 +146,20 @@ if(BGS_PYTHON_SUPPORT)
   message(STATUS "NUMPY_INCLUDE_DIR: ${NUMPY_INCLUDE_DIR}\n")
 endif()
 
-file(GLOB main Main.cpp FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp)
-file(GLOB demo Demo.cpp)
-file(GLOB demo2 Demo2.cpp)
+file(GLOB main src/Main.cpp src/FrameProcessor.cpp src/PreProcessor.cpp src/VideoAnalysis.cpp src/VideoCapture.cpp)
 
-file(GLOB_RECURSE analysis_src package_analysis/*.cpp)
-file(GLOB_RECURSE bgs_src package_bgs/*.cpp package_bgs/*.c)
-file(GLOB_RECURSE bgs_include package_bgs/*.h)
+file(GLOB_RECURSE analysis_src src/package_analysis/*.cpp)
+file(GLOB_RECURSE bgs_src src/package_bgs/*.cpp src/package_bgs/*.c)
+file(GLOB_RECURSE bgs_include src/package_bgs/*.h)
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 include_directories(${OpenCV_INCLUDE_DIRS})
 
 if(BGS_PYTHON_SUPPORT)
-  file(GLOB_RECURSE bgs_python_src wrapper_python/*.cpp)
-  file(GLOB_RECURSE bgs_python_include wrapper_python/*.h)
+  file(GLOB_RECURSE bgs_python_src wrapper/python/*.cpp)
+  file(GLOB_RECURSE bgs_python_include wrapper/python/*.h)
 
-  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/pybind11/include)
+  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/pybind11/include)
   #include_directories(${Boost_INCLUDE_DIRS})
   include_directories(${PYTHON_INCLUDE_DIRS})
   include_directories(${NUMPY_INCLUDE_DIR})
@@ -167,7 +167,7 @@ endif()
 
 # GMG is not available in older OpenCV versions
 if(${OpenCV_VERSION} VERSION_LESS 2.4.3)
-  file(GLOB gmg package_bgs/GMG.cpp)
+  file(GLOB gmg src/package_bgs/GMG.cpp)
   list(REMOVE_ITEM bgs_src ${gmg})
 endif()
 
@@ -221,12 +221,6 @@ add_executable(bgslibrary ${main})
 target_link_libraries(bgslibrary ${OpenCV_LIBS} bgslibrary_core)
 # set_target_properties(bgslibrary PROPERTIES OUTPUT_NAME bgs)
 
-add_executable(bgs_demo ${demo})
-target_link_libraries(bgs_demo ${OpenCV_LIBS} bgslibrary_core)
-
-add_executable(bgs_demo2 ${demo2})
-target_link_libraries(bgs_demo2 ${OpenCV_LIBS} bgslibrary_core)
-
 if(UNIX AND BGS_PYTHON_SUPPORT)
   execute_process(
     COMMAND "${PYTHON_EXECUTABLE}" -c "if True:
diff --git a/COPYING.txt b/COPYING.txt
deleted file mode 100644
index 94a9ed0..0000000
--- a/COPYING.txt
+++ /dev/null
@@ -1,674 +0,0 @@
-                    GNU GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-                            Preamble
-
-  The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
-  The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works.  By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users.  We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors.  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
-  To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights.  Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received.  You must make sure that they, too, receive
-or can get the source code.  And you must show them these terms so they
-know their rights.
-
-  Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
-  For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software.  For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
-  Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so.  This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software.  The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable.  Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products.  If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
-  Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary.  To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-                       TERMS AND CONDITIONS
-
-  0. Definitions.
-
-  "This License" refers to version 3 of the GNU General Public License.
-
-  "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
-  "The Program" refers to any copyrightable work licensed under this
-License.  Each licensee is addressed as "you".  "Licensees" and
-"recipients" may be individuals or organizations.
-
-  To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy.  The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
-  A "covered work" means either the unmodified Program or a work based
-on the Program.
-
-  To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy.  Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
-  To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies.  Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
-  An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License.  If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
-  1. Source Code.
-
-  The "source code" for a work means the preferred form of the work
-for making modifications to it.  "Object code" means any non-source
-form of a work.
-
-  A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
-  The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form.  A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
-  The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities.  However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work.  For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
-  The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
-  The Corresponding Source for a work in source code form is that
-same work.
-
-  2. Basic Permissions.
-
-  All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met.  This License explicitly affirms your unlimited
-permission to run the unmodified Program.  The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work.  This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
-  You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force.  You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright.  Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
-  Conveying under any other circumstances is permitted solely under
-the conditions stated below.  Sublicensing is not allowed; section 10
-makes it unnecessary.
-
-  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
-  No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
-  When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
-  4. Conveying Verbatim Copies.
-
-  You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
-  You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
-  5. Conveying Modified Source Versions.
-
-  You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
-    a) The work must carry prominent notices stating that you modified
-    it, and giving a relevant date.
-
-    b) The work must carry prominent notices stating that it is
-    released under this License and any conditions added under section
-    7.  This requirement modifies the requirement in section 4 to
-    "keep intact all notices".
-
-    c) You must license the entire work, as a whole, under this
-    License to anyone who comes into possession of a copy.  This
-    License will therefore apply, along with any applicable section 7
-    additional terms, to the whole of the work, and all its parts,
-    regardless of how they are packaged.  This License gives no
-    permission to license the work in any other way, but it does not
-    invalidate such permission if you have separately received it.
-
-    d) If the work has interactive user interfaces, each must display
-    Appropriate Legal Notices; however, if the Program has interactive
-    interfaces that do not display Appropriate Legal Notices, your
-    work need not make them do so.
-
-  A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit.  Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
-  6. Conveying Non-Source Forms.
-
-  You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
-    a) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by the
-    Corresponding Source fixed on a durable physical medium
-    customarily used for software interchange.
-
-    b) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by a
-    written offer, valid for at least three years and valid for as
-    long as you offer spare parts or customer support for that product
-    model, to give anyone who possesses the object code either (1) a
-    copy of the Corresponding Source for all the software in the
-    product that is covered by this License, on a durable physical
-    medium customarily used for software interchange, for a price no
-    more than your reasonable cost of physically performing this
-    conveying of source, or (2) access to copy the
-    Corresponding Source from a network server at no charge.
-
-    c) Convey individual copies of the object code with a copy of the
-    written offer to provide the Corresponding Source.  This
-    alternative is allowed only occasionally and noncommercially, and
-    only if you received the object code with such an offer, in accord
-    with subsection 6b.
-
-    d) Convey the object code by offering access from a designated
-    place (gratis or for a charge), and offer equivalent access to the
-    Corresponding Source in the same way through the same place at no
-    further charge.  You need not require recipients to copy the
-    Corresponding Source along with the object code.  If the place to
-    copy the object code is a network server, the Corresponding Source
-    may be on a different server (operated by you or a third party)
-    that supports equivalent copying facilities, provided you maintain
-    clear directions next to the object code saying where to find the
-    Corresponding Source.  Regardless of what server hosts the
-    Corresponding Source, you remain obligated to ensure that it is
-    available for as long as needed to satisfy these requirements.
-
-    e) Convey the object code using peer-to-peer transmission, provided
-    you inform other peers where the object code and Corresponding
-    Source of the work are being offered to the general public at no
-    charge under subsection 6d.
-
-  A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
-  A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling.  In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage.  For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product.  A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
-  "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source.  The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
-  If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information.  But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
-  The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed.  Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
-  Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
-  7. Additional Terms.
-
-  "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law.  If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
-  When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it.  (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.)  You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
-  Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
-    a) Disclaiming warranty or limiting liability differently from the
-    terms of sections 15 and 16 of this License; or
-
-    b) Requiring preservation of specified reasonable legal notices or
-    author attributions in that material or in the Appropriate Legal
-    Notices displayed by works containing it; or
-
-    c) Prohibiting misrepresentation of the origin of that material, or
-    requiring that modified versions of such material be marked in
-    reasonable ways as different from the original version; or
-
-    d) Limiting the use for publicity purposes of names of licensors or
-    authors of the material; or
-
-    e) Declining to grant rights under trademark law for use of some
-    trade names, trademarks, or service marks; or
-
-    f) Requiring indemnification of licensors and authors of that
-    material by anyone who conveys the material (or modified versions of
-    it) with contractual assumptions of liability to the recipient, for
-    any liability that these contractual assumptions directly impose on
-    those licensors and authors.
-
-  All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10.  If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term.  If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
-  If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
-  Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
-  8. Termination.
-
-  You may not propagate or modify a covered work except as expressly
-provided under this License.  Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
-  However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
-  Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
-  Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License.  If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
-  9. Acceptance Not Required for Having Copies.
-
-  You are not required to accept this License in order to receive or
-run a copy of the Program.  Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance.  However,
-nothing other than this License grants you permission to propagate or
-modify any covered work.  These actions infringe copyright if you do
-not accept this License.  Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
-  10. Automatic Licensing of Downstream Recipients.
-
-  Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License.  You are not responsible
-for enforcing compliance by third parties with this License.
-
-  An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations.  If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
-  You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License.  For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
-  11. Patents.
-
-  A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based.  The
-work thus licensed is called the contributor's "contributor version".
-
-  A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version.  For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
-  Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
-  In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement).  To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
-  If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients.  "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
-  If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
-  A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License.  You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
-  Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
-  12. No Surrender of Others' Freedom.
-
-  If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all.  For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
-  13. Use with the GNU Affero General Public License.
-
-  Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work.  The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
-  14. Revised Versions of this License.
-
-  The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-  Each version is given a distinguishing version number.  If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation.  If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
-  If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
-  Later license versions may give you additional or different
-permissions.  However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
-  15. Disclaimer of Warranty.
-
-  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
-  16. Limitation of Liability.
-
-  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
-  17. Interpretation of Sections 15 and 16.
-
-  If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
-                     END OF TERMS AND CONDITIONS
-
-            How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
-  If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
-    <program>  Copyright (C) <year>  <name of author>
-    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
-  You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
-  The GNU General Public License does not permit incorporating your program
-into proprietary programs.  If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library.  If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.  But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/Config.h b/Config.h
deleted file mode 100644
index 61a992d..0000000
--- a/Config.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-namespace bgslibrary
-{
-  const int KEY_REPEAT = 'r';
-  const int KEY_SPACE = 32;
-  const int KEY_ESC = 27;
-  const int KEY_ESC2 = 'q';
-}
diff --git a/IFrameProcessor.h b/IFrameProcessor.h
deleted file mode 100644
index 61bdf3a..0000000
--- a/IFrameProcessor.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <opencv2/opencv.hpp>
-
-namespace bgslibrary
-{
-  class IFrameProcessor
-  {
-  public:
-    virtual void process(const cv::Mat &input) = 0;
-    virtual ~IFrameProcessor(){}
-  };
-}
diff --git a/LICENSE b/LICENSE
index ef7e7ef..f0f51ad 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,674 +1,22 @@
-GNU GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-                            Preamble
-
-  The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
-  The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works.  By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users.  We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors.  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
-  To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights.  Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received.  You must make sure that they, too, receive
-or can get the source code.  And you must show them these terms so they
-know their rights.
-
-  Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
-  For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software.  For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
-  Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so.  This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software.  The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable.  Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products.  If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
-  Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary.  To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-                       TERMS AND CONDITIONS
-
-  0. Definitions.
-
-  "This License" refers to version 3 of the GNU General Public License.
-
-  "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
-  "The Program" refers to any copyrightable work licensed under this
-License.  Each licensee is addressed as "you".  "Licensees" and
-"recipients" may be individuals or organizations.
-
-  To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy.  The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
-  A "covered work" means either the unmodified Program or a work based
-on the Program.
-
-  To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy.  Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
-  To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies.  Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
-  An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License.  If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
-  1. Source Code.
-
-  The "source code" for a work means the preferred form of the work
-for making modifications to it.  "Object code" means any non-source
-form of a work.
-
-  A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
-  The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form.  A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
-  The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities.  However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work.  For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
-  The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
-  The Corresponding Source for a work in source code form is that
-same work.
-
-  2. Basic Permissions.
-
-  All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met.  This License explicitly affirms your unlimited
-permission to run the unmodified Program.  The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work.  This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
-  You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force.  You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright.  Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
-  Conveying under any other circumstances is permitted solely under
-the conditions stated below.  Sublicensing is not allowed; section 10
-makes it unnecessary.
-
-  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
-  No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
-  When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
-  4. Conveying Verbatim Copies.
-
-  You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
-  You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
-  5. Conveying Modified Source Versions.
-
-  You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
-    a) The work must carry prominent notices stating that you modified
-    it, and giving a relevant date.
-
-    b) The work must carry prominent notices stating that it is
-    released under this License and any conditions added under section
-    7.  This requirement modifies the requirement in section 4 to
-    "keep intact all notices".
-
-    c) You must license the entire work, as a whole, under this
-    License to anyone who comes into possession of a copy.  This
-    License will therefore apply, along with any applicable section 7
-    additional terms, to the whole of the work, and all its parts,
-    regardless of how they are packaged.  This License gives no
-    permission to license the work in any other way, but it does not
-    invalidate such permission if you have separately received it.
-
-    d) If the work has interactive user interfaces, each must display
-    Appropriate Legal Notices; however, if the Program has interactive
-    interfaces that do not display Appropriate Legal Notices, your
-    work need not make them do so.
-
-  A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit.  Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
-  6. Conveying Non-Source Forms.
-
-  You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
-    a) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by the
-    Corresponding Source fixed on a durable physical medium
-    customarily used for software interchange.
-
-    b) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by a
-    written offer, valid for at least three years and valid for as
-    long as you offer spare parts or customer support for that product
-    model, to give anyone who possesses the object code either (1) a
-    copy of the Corresponding Source for all the software in the
-    product that is covered by this License, on a durable physical
-    medium customarily used for software interchange, for a price no
-    more than your reasonable cost of physically performing this
-    conveying of source, or (2) access to copy the
-    Corresponding Source from a network server at no charge.
-
-    c) Convey individual copies of the object code with a copy of the
-    written offer to provide the Corresponding Source.  This
-    alternative is allowed only occasionally and noncommercially, and
-    only if you received the object code with such an offer, in accord
-    with subsection 6b.
-
-    d) Convey the object code by offering access from a designated
-    place (gratis or for a charge), and offer equivalent access to the
-    Corresponding Source in the same way through the same place at no
-    further charge.  You need not require recipients to copy the
-    Corresponding Source along with the object code.  If the place to
-    copy the object code is a network server, the Corresponding Source
-    may be on a different server (operated by you or a third party)
-    that supports equivalent copying facilities, provided you maintain
-    clear directions next to the object code saying where to find the
-    Corresponding Source.  Regardless of what server hosts the
-    Corresponding Source, you remain obligated to ensure that it is
-    available for as long as needed to satisfy these requirements.
-
-    e) Convey the object code using peer-to-peer transmission, provided
-    you inform other peers where the object code and Corresponding
-    Source of the work are being offered to the general public at no
-    charge under subsection 6d.
-
-  A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
-  A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling.  In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage.  For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product.  A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
-  "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source.  The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
-  If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information.  But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
-  The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed.  Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
-  Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
-  7. Additional Terms.
-
-  "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law.  If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
-  When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it.  (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.)  You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
-  Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
-    a) Disclaiming warranty or limiting liability differently from the
-    terms of sections 15 and 16 of this License; or
-
-    b) Requiring preservation of specified reasonable legal notices or
-    author attributions in that material or in the Appropriate Legal
-    Notices displayed by works containing it; or
-
-    c) Prohibiting misrepresentation of the origin of that material, or
-    requiring that modified versions of such material be marked in
-    reasonable ways as different from the original version; or
-
-    d) Limiting the use for publicity purposes of names of licensors or
-    authors of the material; or
-
-    e) Declining to grant rights under trademark law for use of some
-    trade names, trademarks, or service marks; or
-
-    f) Requiring indemnification of licensors and authors of that
-    material by anyone who conveys the material (or modified versions of
-    it) with contractual assumptions of liability to the recipient, for
-    any liability that these contractual assumptions directly impose on
-    those licensors and authors.
-
-  All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10.  If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term.  If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
-  If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
-  Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
-  8. Termination.
-
-  You may not propagate or modify a covered work except as expressly
-provided under this License.  Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
-  However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
-  Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
-  Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License.  If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
-  9. Acceptance Not Required for Having Copies.
-
-  You are not required to accept this License in order to receive or
-run a copy of the Program.  Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance.  However,
-nothing other than this License grants you permission to propagate or
-modify any covered work.  These actions infringe copyright if you do
-not accept this License.  Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
-  10. Automatic Licensing of Downstream Recipients.
-
-  Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License.  You are not responsible
-for enforcing compliance by third parties with this License.
-
-  An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations.  If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
-  You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License.  For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
-  11. Patents.
-
-  A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based.  The
-work thus licensed is called the contributor's "contributor version".
-
-  A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version.  For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
-  Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
-  In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement).  To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
-  If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients.  "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
-  If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
-  A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License.  You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
-  Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
-  12. No Surrender of Others' Freedom.
-
-  If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all.  For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
-  13. Use with the GNU Affero General Public License.
-
-  Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work.  The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
-  14. Revised Versions of this License.
-
-  The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-  Each version is given a distinguishing version number.  If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation.  If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
-  If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
-  Later license versions may give you additional or different
-permissions.  However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
-  15. Disclaimer of Warranty.
-
-  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
-  16. Limitation of Liability.
-
-  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
-  17. Interpretation of Sections 15 and 16.
-
-  If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
-                     END OF TERMS AND CONDITIONS
-
-            How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    {one line to give the program's name and a brief idea of what it does.}
-    Copyright (C) {year}  {name of author}
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
-  If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
-    {project}  Copyright (C) {year}  {fullname}
-    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
-  You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
-  The GNU General Public License does not permit incorporating your program
-into proprietary programs.  If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library.  If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.  But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+The MIT License
+
+Copyright (c) 2012-2019 Andrews Cordolino Sobral, 
+https://github.com/andrewssobral/bgslibrary/
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/LICENSE.txt b/LICENSE.txt
index e2ce0d8..f0f51ad 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,12 +1,22 @@
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
\ No newline at end of file
+The MIT License
+
+Copyright (c) 2012-2019 Andrews Cordolino Sobral, 
+https://github.com/andrewssobral/bgslibrary/
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.md b/README.md
index c7803c7..5386b29 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,15 @@
 ## BGSLibrary
 A Background Subtraction Library
 
-[![Release](https://img.shields.io/badge/Release-v2.0.0-blue.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) [![Platform: Windows, Linux, OS X](https://img.shields.io/badge/Platform-Windows%2C%20Linux%2C%20OS%20X-blue.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![OpenCV](https://img.shields.io/badge/OpenCV-2.x%2C%203.x-blue.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![Wrapper: Python, MATLAB](https://img.shields.io/badge/Wrapper-Java%2C%20Python%2C%20MATLAB-orange.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![Algorithms](https://img.shields.io/badge/Algorithms-43-red.svg)](https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms)
+[![Release](https://img.shields.io/badge/Release-3.0.0-blue.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![License: GPL v3](https://img.shields.io/badge/License-MIT-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) [![Platform: Windows, Linux, OS X](https://img.shields.io/badge/Platform-Windows%2C%20Linux%2C%20OS%20X-blue.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![OpenCV](https://img.shields.io/badge/OpenCV-2.4.x%2C%203.x%2C%2004.x-blue.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![Wrapper: Python, MATLAB](https://img.shields.io/badge/Wrapper-Java%2C%20Python%2C%20MATLAB-orange.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![Algorithms](https://img.shields.io/badge/Algorithms-43-red.svg)](https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms)
 
 [![bgslibrary](http://i.giphy.com/5A94AZahSIVOw.gif)](https://youtu.be/_UbERwuQ0OU)
 
-Last page update: **12/09/2018**
+Last page update: **06/08/2019**
 
-Library Version: **2.0.0** (see **[Build Status](https://github.com/andrewssobral/bgslibrary/wiki/Build-status)** and **[Release Notes](https://github.com/andrewssobral/bgslibrary/wiki/Release-notes)** for more info)
+Library Version: **3.0.0** (see **[Build Status](https://github.com/andrewssobral/bgslibrary/wiki/Build-status)** and **[Release Notes](https://github.com/andrewssobral/bgslibrary/wiki/Release-notes)** for more info)
 
-The **BGSLibrary** was developed early 2012 by [Andrews Sobral](http://andrewssobral.wixsite.com/home) to provide an easy-to-use C++ framework (wrappers for Python, Java and MATLAB are also available) for foreground-background separation in videos based on [OpenCV](http://www.opencv.org/). The bgslibrary is compatible with OpenCV 2.x and 3.x (OpenCV 4.x is still not yet supported -- it's in progress), and compiles under Windows, Linux, and Mac OS X. Currently the library contains **43** algorithms. The source code is available under [GNU GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html), the library is available free of charge to all users, academic and commercial.
+The **BGSLibrary** was developed early 2012 by [Andrews Sobral](http://andrewssobral.wixsite.com/home) to provide an easy-to-use C++ framework (wrappers for Python, Java and MATLAB are also available) for foreground-background separation in videos based on [OpenCV](http://www.opencv.org/). The bgslibrary is compatible with OpenCV 2.4.x, 3.x and 4.x, and compiles under Windows, Linux, and Mac OS X. Currently the library contains **43** algorithms. The source code is available under the [MIT license](https://opensource.org/licenses/MIT), the library is available free of charge to all users, academic and commercial.
 
 * [List of available algorithms](https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms)
 * [Algorithms benchmark](https://github.com/andrewssobral/bgslibrary/wiki/Algorithms-benchmark)
@@ -18,7 +18,9 @@ The **BGSLibrary** was developed early 2012 by [Andrews Sobral](http://andrewsso
 
 * Installation instructions
 
-You can either install BGSLibrary via [pre-built binary package](https://github.com/andrewssobral/bgslibrary/releases) or build it from source:
+You can either install BGSLibrary via [pre-built binary package](https://github.com/andrewssobral/bgslibrary/releases) or build it from source via:
+
+`git clone --recursive https://github.com/andrewssobral/bgslibrary.git`
 
 * * [Windows installation](https://github.com/andrewssobral/bgslibrary/wiki/Installation-instructions---Windows)
 
@@ -28,13 +30,14 @@ Supported Compilers are:
 
     GCC 4.8 and above
     Clang 3.4 and above
-    MSVC 2015, 2017
+    MSVC 2015, 2017, 2019
 
 Other compilers might work, but are not officially supported.
+The bgslibrary requires some features from the ISO C++ 2014 standard.
 
 * Graphical User Interface:
 
-*  * [C++ QT](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-QT)
+*  * [C++ QT](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-QT) ***(Official)***
 *  * [C++ MFC](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-MFC) ***(Deprecated)***
 *  * [Java](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-Java) ***(Obsolete)***
 
diff --git a/VideoAnalysis.h b/VideoAnalysis.h
deleted file mode 100644
index b41d9ba..0000000
--- a/VideoAnalysis.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <iostream>
-#include <sstream>
-
-#include "VideoCapture.h"
-#include "FrameProcessor.h"
-
-namespace bgslibrary
-{
-  class VideoAnalysis
-  {
-  private:
-    std::unique_ptr<VideoCapture> videoCapture;
-    std::shared_ptr<FrameProcessor> frameProcessor;
-    bool use_file;
-    std::string filename;
-    bool use_camera;
-    int cameraIndex;
-    bool use_comp;
-    long frameToStop;
-    std::string imgref;
-
-  public:
-    VideoAnalysis();
-    ~VideoAnalysis();
-
-    bool setup(int argc, const char **argv);
-    void start();
-  };
-}
diff --git a/VideoCapture.h b/VideoCapture.h
deleted file mode 100644
index a4872c3..0000000
--- a/VideoCapture.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <iostream>
-#include <fstream>
-#include <memory>
-//#include <chrono>
-//#include <thread>
-#include <opencv2/opencv.hpp>
-#include <opencv2/imgproc/imgproc_c.h>
-#include <opencv2/imgproc/types_c.h>
-
-#include "Config.h"
-#include "IFrameProcessor.h"
-
-namespace bgslibrary
-{
-  class VideoCapture
-  {
-  private:
-    std::shared_ptr<IFrameProcessor> frameProcessor;
-    cv::VideoCapture capture;
-    cv::Mat frame;
-    int key;
-    int64 start_time;
-    int64 delta_time;
-    double freq;
-    double fps;
-    long long frameNumber;
-    long stopAt;
-    bool useCamera;
-    int cameraIndex;
-    bool useVideo;
-    std::string videoFileName;
-    int input_resize_percent;
-    bool showOutput;
-    bool enableFlip;
-    double loopDelay = 33.333;
-    bool firstTime = true;
-    std::string config_xml;
-    void setup(const std::string _config_xml) {
-      config_xml = _config_xml;
-      if (!config_xml.empty()) {
-        if (!std::ifstream(config_xml))
-          saveConfig();
-        loadConfig();
-      }
-    }
-
-  public:
-    VideoCapture();
-    ~VideoCapture();
-
-    void setFrameProcessor(std::shared_ptr<IFrameProcessor> frameProcessorPtr);
-    void setCamera(int cameraIndex);
-    void setVideo(std::string filename);
-    void start();
-
-  private:
-    void setUpCamera();
-    void setUpVideo();
-
-    void saveConfig();
-    void loadConfig();
-  };
-}
diff --git a/config/MultiCue.xml b/config/MultiCue.xml
deleted file mode 100644
index 25b693a..0000000
--- a/config/MultiCue.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0"?>
-<opencv_storage>
-<showOutput>1</showOutput>
-<g_fLearningRate>5.0000000745058060e-02</g_fLearningRate>
-<g_iAbsortionPeriod>200</g_iAbsortionPeriod>
-<g_iC_ModelThreshold>10</g_iC_ModelThreshold>
-<g_iT_ModelThreshold>1</g_iT_ModelThreshold>
-<g_iBackClearPeriod>300</g_iBackClearPeriod>
-<g_iCacheClearPeriod>30</g_iCacheClearPeriod>
-<g_nNeighborNum>6</g_nNeighborNum>
-<g_nRadius>2</g_nRadius>
-<g_nTextureTrainVolRange>15</g_nTextureTrainVolRange>
-<g_bAbsorptionEnable>1</g_bAbsorptionEnable>
-<g_iTrainingPeriod>20</g_iTrainingPeriod>
-<g_iRWidth>160</g_iRWidth>
-<g_iRHeight>120</g_iRHeight>
-</opencv_storage>
diff --git a/Demo.py b/demo.py
similarity index 100%
rename from Demo.py
rename to demo.py
diff --git a/Demo2.py b/demo2.py
similarity index 68%
rename from Demo2.py
rename to demo2.py
index 542ab3d..28eb318 100644
--- a/Demo2.py
+++ b/demo2.py
@@ -10,6 +10,9 @@ def is_cv2():
 def is_cv3():
   return check_opencv_version("3.")
 
+def is_cv4():
+  return check_opencv_version("4.")
+
 def check_opencv_version(major):
   return cv2.__version__.startswith(major)
 
@@ -17,46 +20,47 @@ def check_opencv_version(major):
 algorithms=[]
 algorithms.append(bgs.FrameDifference())
 algorithms.append(bgs.StaticFrameDifference())
+algorithms.append(bgs.WeightedMovingMean())
+algorithms.append(bgs.WeightedMovingVariance())
 algorithms.append(bgs.AdaptiveBackgroundLearning())
 algorithms.append(bgs.AdaptiveSelectiveBackgroundLearning())
-algorithms.append(bgs.DPAdaptiveMedian())
-algorithms.append(bgs.DPEigenbackground())
-algorithms.append(bgs.DPGrimsonGMM())
-algorithms.append(bgs.DPMean())
-algorithms.append(bgs.DPPratiMediod())
-algorithms.append(bgs.DPTexture())
-algorithms.append(bgs.DPWrenGA())
-algorithms.append(bgs.DPZivkovicAGMM())
-algorithms.append(bgs.FuzzyChoquetIntegral())
-algorithms.append(bgs.FuzzySugenoIntegral())
-algorithms.append(bgs.IndependentMultimodal())
-algorithms.append(bgs.KDE())
-if is_cv3():
-  algorithms.append(bgs.KNN()) # if opencv 3.x
-algorithms.append(bgs.LBAdaptiveSOM())
-algorithms.append(bgs.LBFuzzyAdaptiveSOM())
-algorithms.append(bgs.LBFuzzyGaussian())
-algorithms.append(bgs.LBMixtureOfGaussians())
-algorithms.append(bgs.LBSimpleGaussian())
-algorithms.append(bgs.LBP_MRF())
-algorithms.append(bgs.LOBSTER())
+algorithms.append(bgs.MixtureOfGaussianV2())
 if is_cv2():
-  algorithms.append(bgs.GMG()) # if opencv 2.x
   algorithms.append(bgs.MixtureOfGaussianV1()) # if opencv 2.x
-algorithms.append(bgs.MixtureOfGaussianV2())
-algorithms.append(bgs.MultiCue())
-algorithms.append(bgs.MultiLayer())
-algorithms.append(bgs.PAWCS())
-algorithms.append(bgs.PixelBasedAdaptiveSegmenter())
+  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())
+  algorithms.append(bgs.DPZivkovicAGMM())
+  algorithms.append(bgs.DPMean())
+  algorithms.append(bgs.DPWrenGA())
+  algorithms.append(bgs.DPPratiMediod())
+  algorithms.append(bgs.DPEigenbackground())
+  algorithms.append(bgs.DPTexture())
+  algorithms.append(bgs.T2FGMM_UM())
+  algorithms.append(bgs.T2FGMM_UV())
+  algorithms.append(bgs.T2FMRF_UM())
+  algorithms.append(bgs.T2FMRF_UV())
+  algorithms.append(bgs.FuzzySugenoIntegral())
+  algorithms.append(bgs.FuzzyChoquetIntegral())
+  algorithms.append(bgs.LBSimpleGaussian())
+  algorithms.append(bgs.LBFuzzyGaussian())
+  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.T2FGMM_UM())
-algorithms.append(bgs.T2FGMM_UV())
-algorithms.append(bgs.T2FMRF_UM())
-algorithms.append(bgs.T2FMRF_UV())
-algorithms.append(bgs.VuMeter())
-algorithms.append(bgs.WeightedMovingMean())
-algorithms.append(bgs.WeightedMovingVariance())
+algorithms.append(bgs.LOBSTER())
+algorithms.append(bgs.PAWCS())
 algorithms.append(bgs.TwoPoints())
 algorithms.append(bgs.ViBe())
 algorithms.append(bgs.CodeBook())
@@ -109,4 +113,4 @@ for algorithm in algorithms:
 
   cv2.destroyAllWindows()
 
-print("Finished")
\ No newline at end of file
+print("Finished")
diff --git a/demos/linux_ubuntu/.gitignore b/demos/linux_ubuntu/.gitignore
deleted file mode 100644
index 46d4288..0000000
--- a/demos/linux_ubuntu/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Ignore everything in this directory
-*
-# Except these files
-!.gitignore
-!CMakeLists.txt
-!FrameDifferenceTest.cpp
-!README.txt
-!config/
diff --git a/demos/linux_ubuntu/CMakeLists.txt b/demos/linux_ubuntu/CMakeLists.txt
deleted file mode 100644
index 8cc38e8..0000000
--- a/demos/linux_ubuntu/CMakeLists.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-cmake_minimum_required(VERSION 2.8)
-
-project(FrameDifferenceTest)
-
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
-
-find_package(OpenCV REQUIRED)
-
-file(GLOB source FrameDifferenceTest.cpp)
-
-file(GLOB_RECURSE bgs_src ../../package_bgs/*.cpp ../../package_bgs/*.c ../../package_analysis/*.cpp)
-file(GLOB_RECURSE bgs_inc ../../package_bgs/*.h ../../package_analysis/*.h)
-
-include_directories(${CMAKE_SOURCE_DIR})
-
-add_library(bgs SHARED ${bgs_src})
-target_link_libraries(bgs ${OpenCV_LIBS})
-set_property(TARGET bgs PROPERTY PUBLIC_HEADER ${bgs_inc})
-
-add_executable(FrameDifferenceTest ${source})
-target_link_libraries(FrameDifferenceTest ${OpenCV_LIBS} bgs)
diff --git a/demos/linux_ubuntu/FrameDifferenceTest.cpp b/demos/linux_ubuntu/FrameDifferenceTest.cpp
deleted file mode 100644
index 7ebe8b1..0000000
--- a/demos/linux_ubuntu/FrameDifferenceTest.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include <iostream>
-#include <cv.h>
-#include <highgui.h>
-
-#include "../../package_bgs/FrameDifference.h"
-
-using namespace bgslibrary::algorithms;
-
-int main(int argc, char **argv)
-{
-  CvCapture *capture = 0;
-  capture = cvCaptureFromCAM(0);
-
-  if(!capture){
-    std::cerr << "Cannot initialize video!" << std::endl;
-    return -1;
-  }
-
-  IBGS *bgs;
-  bgs = new FrameDifference;
-
-  IplImage *frame;
-  while(1)
-  {
-    frame = cvQueryFrame(capture);
-    if(!frame) break;
-
-    cv::Mat img_input(frame);
-    cv::imshow("Input", img_input);
-
-    cv::Mat img_mask;
-    cv::Mat img_bkgmodel;
-
-    // by default, it shows automatically the foreground mask image
-    bgs->process(img_input, img_mask, img_bkgmodel);
-
-    //if(!img_mask.empty())
-    //  cv::imshow("Foreground", img_mask);
-    //  do something
-
-    if(cvWaitKey(33) >= 0)
-		  break;
-  }
-
-  delete bgs;
-
-  cvDestroyAllWindows();
-  cvReleaseCapture(&capture);
-
-  return 0;
-}
diff --git a/demos/linux_ubuntu/README.txt b/demos/linux_ubuntu/README.txt
deleted file mode 100644
index 5558b71..0000000
--- a/demos/linux_ubuntu/README.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-#
-# HOW TO COMPILE ON LINUX
-#
-# Requirements:
-# cmake >= 2.8
-# opencv >= 2.3.1
-
-cmake .
-make
diff --git a/demos/macosx/.gitignore b/demos/macosx/.gitignore
deleted file mode 100644
index 46d4288..0000000
--- a/demos/macosx/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Ignore everything in this directory
-*
-# Except these files
-!.gitignore
-!CMakeLists.txt
-!FrameDifferenceTest.cpp
-!README.txt
-!config/
diff --git a/demos/macosx/CMakeLists.txt b/demos/macosx/CMakeLists.txt
deleted file mode 100644
index a9775d8..0000000
--- a/demos/macosx/CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-cmake_minimum_required(VERSION 2.8)
-
-project(FrameDifferenceTest)
-
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
-
-IF(UNIX)
-  # add some standard warnings
-  ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas)
-  
-  # -ansi does not compile with sjn module
-  #ADD_DEFINITIONS(-ansi)
-
-  # if you like to have warinings about conversions, e.g. double->int or double->float etc., or float compare
-  #ADD_DEFINITIONS(-Wconversion -Wfloat-equal)
-endif(UNIX)
-
-find_package(OpenCV REQUIRED)
-
-file(GLOB source FrameDifferenceTest.cpp)
-
-file(GLOB_RECURSE bgs_src ../../package_bgs/*.cpp ../../package_bgs/*.c ../../package_analysis/*.cpp)
-file(GLOB_RECURSE bgs_inc ../../package_bgs/*.h ../../package_analysis/*.h)
-
-include_directories(${CMAKE_SOURCE_DIR})
-
-add_library(bgs SHARED ${bgs_src})
-target_link_libraries(bgs ${OpenCV_LIBS})
-set_property(TARGET bgs PROPERTY PUBLIC_HEADER ${bgs_inc})
-
-add_executable(FrameDifferenceTest ${source})
-target_link_libraries(FrameDifferenceTest ${OpenCV_LIBS} bgs)
diff --git a/demos/macosx/FrameDifferenceTest.cpp b/demos/macosx/FrameDifferenceTest.cpp
deleted file mode 100644
index ccde86c..0000000
--- a/demos/macosx/FrameDifferenceTest.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <iostream>
-#include <opencv2/opencv.hpp>
-
-#include "../../package_bgs/FrameDifference.h"
-
-using namespace bgslibrary::algorithms;
-//using namespace cv;
-
-int main(int argc, char **argv)
-{
-  cv::VideoCapture capture(0);
-
-  if (!capture.isOpened())
-  {
-    std::cerr << "Cannot initialize video!" << std::endl;
-    return -1;
-  }
-
-  IBGS *bgs;
-  bgs = new FrameDifference;
-
-  int key = 0;
-  cv::Mat img_input;
-  while (key != 'q')
-  {
-    capture >> img_input;
-    if(img_input.empty()) break;
-
-    cv::imshow("Input", img_input);
-
-    cv::Mat img_mask;
-    cv::Mat img_bkgmodel;
-
-    // by default, it shows automatically the foreground mask image
-    bgs->process(img_input, img_mask, img_bkgmodel);
-
-    key = cvWaitKey(33);
-
-    if(key >= 0)
-		  break;
-  }
-
-  delete bgs;
-
-  capture.release();
-  cvDestroyAllWindows();
-
-  return 0;
-}
diff --git a/demos/macosx/README.txt b/demos/macosx/README.txt
deleted file mode 100644
index 5558b71..0000000
--- a/demos/macosx/README.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-#
-# HOW TO COMPILE ON LINUX
-#
-# Requirements:
-# cmake >= 2.8
-# opencv >= 2.3.1
-
-cmake .
-make
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..f605af3
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,139 @@
+cmake_minimum_required(VERSION 3.12)
+
+project(bgslibrary-examples)
+
+set(CMAKE_CXX_STANDARD 14)
+
+if(UNIX)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
+  set(CMAKE_MACOSX_RPATH 1)
+endif(UNIX)
+
+# 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)
+endif()
+
+#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
+#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
+
+# compilation mode setup
+set(CMAKE_BUILD_TYPE Release)
+#set(CMAKE_BUILD_TYPE Debug)
+
+if(WIN32)
+  set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+  set(BUILD_SHARED_LIBS TRUE)
+  #if(BGS_PYTHON_SUPPORT)
+    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
+    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
+  #else()
+  #  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
+  #  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
+  #endif()
+endif(WIN32)
+
+set(bgs_out_dir ".")
+# First for the generic no-config case (e.g. with mingw)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${bgs_out_dir})
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${bgs_out_dir})
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${bgs_out_dir})
+# Second, for multi-config builds (e.g. msvc)
+foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
+  string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
+  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir})
+  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir})
+  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir})
+endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
+
+if(UNIX)
+  # add some standard warnings
+  ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas)
+
+  # -ansi does not compile with sjn module
+  #ADD_DEFINITIONS(-ansi)
+
+  # if you like to have warinings about conversions, e.g. double->int or double->float etc., or float compare
+  #ADD_DEFINITIONS(-Wconversion -Wfloat-equal)
+endif(UNIX)
+
+set(OpenCV_STATIC OFF)
+find_package(OpenCV REQUIRED)
+if(OpenCV_FOUND)
+  message(STATUS "")
+  message(STATUS "OpenCV library status:")
+  message(STATUS "    version: ${OpenCV_VERSION}")
+  message(STATUS "    libraries: ${OpenCV_LIBS}")
+  message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}\n")
+endif()
+
+# if(${OpenCV_VERSION} VERSION_EQUAL 3 OR ${OpenCV_VERSION} VERSION_GREATER 3)
+#   message(FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}")
+# endif()
+
+if(${OpenCV_VERSION} VERSION_LESS 2.3.1)
+  message(FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}")
+endif()
+
+file(GLOB demo Demo.cpp)
+file(GLOB demo2 Demo2.cpp)
+
+file(GLOB_RECURSE analysis_src ../src/package_analysis/*.cpp)
+file(GLOB_RECURSE bgs_src ../src/package_bgs/*.cpp ../src/package_bgs/*.c)
+file(GLOB_RECURSE bgs_include ../src/package_bgs/*.h)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${OpenCV_INCLUDE_DIRS})
+
+# GMG is not available in older OpenCV versions
+if(${OpenCV_VERSION} VERSION_LESS 2.4.3)
+  file(GLOB gmg ../src/package_bgs/GMG.cpp)
+  list(REMOVE_ITEM bgs_src ${gmg})
+endif()
+
+add_library(bgslibrary_core SHARED ${bgs_src} ${analysis_src})
+# generates the export header bgslibrary_core_EXPORTS.h automatically
+include(GenerateExportHeader)
+GENERATE_EXPORT_HEADER(bgslibrary_core
+    BASE_NAME bgslibrary_core
+    EXPORT_MACRO_NAME bgslibrary_core_EXPORTS
+    EXPORT_FILE_NAME bgslibrary_core_EXPORTS.h
+    STATIC_DEFINE BGSLIBRARY_CORE_EXPORTS_BUILT_AS_STATIC)
+target_link_libraries(bgslibrary_core ${OpenCV_LIBS})
+set_property(TARGET bgslibrary_core PROPERTY PUBLIC_HEADER ${bgs_include})
+
+#if(WIN32)
+#  # set_property(TARGET bgslibrary_core PROPERTY SUFFIX ".lib")
+#  #if(BGS_PYTHON_SUPPORT)
+#  #  set_property(TARGET bgslibrary_core PROPERTY SUFFIX ".pyd")
+#  #endif()
+#else()
+#  set_property(TARGET bgslibrary_core PROPERTY OUTPUT_NAME "bgs")
+#endif()
+
+#if(APPLE)
+#  if(BGS_PYTHON_SUPPORT)
+#    set_property(TARGET bgslibrary_core PROPERTY SUFFIX ".so")
+#    set_target_properties(bgslibrary_core PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
+#  endif()
+#endif()
+
+add_executable(bgs_demo ${demo})
+target_link_libraries(bgs_demo ${OpenCV_LIBS} bgslibrary_core)
+
+add_executable(bgs_demo2 ${demo2})
+target_link_libraries(bgs_demo2 ${OpenCV_LIBS} bgslibrary_core)
+
+if(UNIX)
+  # to avoid: error while loading shared libraries: libbgslibrary_core.so
+  message(STATUS "You might need to run:")
+  message(STATUS "$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib")
+  message(STATUS "$ export LD_LIBRARY_PATH")
+  message(STATUS "after 'make install' to avoid error while loading libbgslibrary_core\n")
+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()
diff --git a/Demo.cpp b/examples/Demo.cpp
similarity index 73%
rename from Demo.cpp
rename to examples/Demo.cpp
index 762d2ae..9bf1f7c 100644
--- a/Demo.cpp
+++ b/examples/Demo.cpp
@@ -1,24 +1,13 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include <iostream>
 #include <vector>
 #include <opencv2/opencv.hpp>
 
-#include "package_bgs/bgslibrary.h"
+#include "../src/package_bgs/bgslibrary.h"
+
+#if CV_MAJOR_VERSION >= 4
+#define CV_CAP_PROP_POS_FRAMES cv::CAP_PROP_POS_FRAMES
+#define CV_CAP_PROP_FRAME_COUNT cv::CAP_PROP_FRAME_COUNT
+#endif
 
 int main(int argc, char **argv)
 {
diff --git a/Demo2.cpp b/examples/Demo2.cpp
similarity index 69%
rename from Demo2.cpp
rename to examples/Demo2.cpp
index 5e3b6c0..1d02d30 100644
--- a/Demo2.cpp
+++ b/examples/Demo2.cpp
@@ -1,29 +1,22 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include <iostream>
 #include <vector>
 #include <opencv2/opencv.hpp>
 
-#include "package_bgs/bgslibrary.h"
+#include "../src/package_bgs/bgslibrary.h"
+
+#if CV_MAJOR_VERSION >= 4
+#define CV_LOAD_IMAGE_COLOR cv::IMREAD_COLOR
+#endif
 
 int main(int argc, char **argv)
 {
   std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
 
+  std::string baseDir = "./dataset/frames";
+  if (argc > 1)
+    baseDir = argv[1];
+  std::cout << "Openning: " << baseDir << std::endl;
+
   /* Background Subtraction Methods */
   auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName();
 
@@ -41,7 +34,7 @@ int main(int argc, char **argv)
       frame_counter++;
       std::stringstream ss;
       ss << frame_counter;
-      auto fileName = "dataset/frames/" + ss.str() + ".png";
+      auto fileName = baseDir + "/" + ss.str() + ".png";
       std::cout << "reading " << fileName << std::endl;
 
       auto img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR);
diff --git a/examples/README.md b/examples/README.md
new file mode 100644
index 0000000..687cd43
--- /dev/null
+++ b/examples/README.md
@@ -0,0 +1,14 @@
+### BGS Library Examples
+
+#### CMake on Linux or MacOS
+```
+cd build
+cmake ..
+make
+cd ..
+
+chmod +x *.sh
+
+./run_demo.sh
+./run_demo2.sh
+```
diff --git a/gui_mfc/outputs/background/.gitignore b/examples/build/.gitignore
similarity index 100%
rename from gui_mfc/outputs/background/.gitignore
rename to examples/build/.gitignore
diff --git a/gui_mfc/outputs/foreground/.gitignore b/examples/config/.gitignore
similarity index 100%
rename from gui_mfc/outputs/foreground/.gitignore
rename to examples/config/.gitignore
diff --git a/examples/run_demo.bat b/examples/run_demo.bat
new file mode 100644
index 0000000..1b9c9d6
--- /dev/null
+++ b/examples/run_demo.bat
@@ -0,0 +1,2 @@
+@echo off
+build\bgs_demo.exe ../dataset/video.avi
diff --git a/examples/run_demo.sh b/examples/run_demo.sh
new file mode 100755
index 0000000..61373c7
--- /dev/null
+++ b/examples/run_demo.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+./build/bgs_demo ../dataset/video.avi
diff --git a/examples/run_demo2.bat b/examples/run_demo2.bat
new file mode 100644
index 0000000..7a1347c
--- /dev/null
+++ b/examples/run_demo2.bat
@@ -0,0 +1,2 @@
+@echo off
+build\bgs_demo2.exe ../dataset/frames
diff --git a/examples/run_demo2.sh b/examples/run_demo2.sh
new file mode 100755
index 0000000..6fe32da
--- /dev/null
+++ b/examples/run_demo2.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+./build/bgs_demo2 ../dataset/frames
diff --git a/gui/README.md b/gui/README.md
new file mode 100644
index 0000000..37f570e
--- /dev/null
+++ b/gui/README.md
@@ -0,0 +1,5 @@
+* Graphical User Interface:
+
+*  * [C++ QT](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-QT)
+*  * [C++ MFC](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-MFC) ***(Deprecated)***
+*  * [Java](https://github.com/andrewssobral/bgslibrary/wiki/Graphical-User-Interface:-Java) ***(Obsolete)***
diff --git a/gui_java/README.txt b/gui/java/README.txt
similarity index 100%
rename from gui_java/README.txt
rename to gui/java/README.txt
diff --git a/gui_java/_COPY_bgslibrary.exe_HERE_ b/gui/java/_COPY_bgslibrary.exe_HERE_
similarity index 100%
rename from gui_java/_COPY_bgslibrary.exe_HERE_
rename to gui/java/_COPY_bgslibrary.exe_HERE_
diff --git a/gui_java/bgslibrary_gui.jar b/gui/java/bgslibrary_gui.jar
similarity index 100%
rename from gui_java/bgslibrary_gui.jar
rename to gui/java/bgslibrary_gui.jar
diff --git a/gui_java/bgslibrary_gui.properties b/gui/java/bgslibrary_gui.properties
similarity index 100%
rename from gui_java/bgslibrary_gui.properties
rename to gui/java/bgslibrary_gui.properties
diff --git a/gui_java/build.xml b/gui/java/build.xml
similarity index 100%
rename from gui_java/build.xml
rename to gui/java/build.xml
diff --git a/gui_java/config/.gitignore b/gui/java/config/.gitignore
similarity index 100%
rename from gui_java/config/.gitignore
rename to gui/java/config/.gitignore
diff --git a/gui_java/config/FrameProcessor.xml b/gui/java/config/FrameProcessor.xml
similarity index 100%
rename from gui_java/config/FrameProcessor.xml
rename to gui/java/config/FrameProcessor.xml
diff --git a/gui_java/config/PreProcessor.xml b/gui/java/config/PreProcessor.xml
similarity index 100%
rename from gui_java/config/PreProcessor.xml
rename to gui/java/config/PreProcessor.xml
diff --git a/gui_java/config/VideoCapture.xml b/gui/java/config/VideoCapture.xml
similarity index 100%
rename from gui_java/config/VideoCapture.xml
rename to gui/java/config/VideoCapture.xml
diff --git a/gui_java/images/bgslibrary_gui_screen01.png b/gui/java/images/bgslibrary_gui_screen01.png
similarity index 100%
rename from gui_java/images/bgslibrary_gui_screen01.png
rename to gui/java/images/bgslibrary_gui_screen01.png
diff --git a/gui_java/images/bgslibrary_gui_screen02.png b/gui/java/images/bgslibrary_gui_screen02.png
similarity index 100%
rename from gui_java/images/bgslibrary_gui_screen02.png
rename to gui/java/images/bgslibrary_gui_screen02.png
diff --git a/gui_java/images/bgslibrary_gui_screen03.png b/gui/java/images/bgslibrary_gui_screen03.png
similarity index 100%
rename from gui_java/images/bgslibrary_gui_screen03.png
rename to gui/java/images/bgslibrary_gui_screen03.png
diff --git a/gui_java/images/bgslibrary_gui_screen04.png b/gui/java/images/bgslibrary_gui_screen04.png
similarity index 100%
rename from gui_java/images/bgslibrary_gui_screen04.png
rename to gui/java/images/bgslibrary_gui_screen04.png
diff --git a/gui_java/images/logo.jpg b/gui/java/images/logo.jpg
similarity index 100%
rename from gui_java/images/logo.jpg
rename to gui/java/images/logo.jpg
diff --git a/gui_java/lib/commons-configuration-1.8.jar b/gui/java/lib/commons-configuration-1.8.jar
similarity index 100%
rename from gui_java/lib/commons-configuration-1.8.jar
rename to gui/java/lib/commons-configuration-1.8.jar
diff --git a/gui_java/lib/commons-io-2.3.jar b/gui/java/lib/commons-io-2.3.jar
similarity index 100%
rename from gui_java/lib/commons-io-2.3.jar
rename to gui/java/lib/commons-io-2.3.jar
diff --git a/gui_java/lib/commons-lang-2.6.jar b/gui/java/lib/commons-lang-2.6.jar
similarity index 100%
rename from gui_java/lib/commons-lang-2.6.jar
rename to gui/java/lib/commons-lang-2.6.jar
diff --git a/gui_java/lib/commons-logging-1.1.1.jar b/gui/java/lib/commons-logging-1.1.1.jar
similarity index 100%
rename from gui_java/lib/commons-logging-1.1.1.jar
rename to gui/java/lib/commons-logging-1.1.1.jar
diff --git a/gui_java/lib/swingx-all-1.6.3.jar b/gui/java/lib/swingx-all-1.6.3.jar
similarity index 100%
rename from gui_java/lib/swingx-all-1.6.3.jar
rename to gui/java/lib/swingx-all-1.6.3.jar
diff --git a/gui_java/lib/swingx-beaninfo-1.6.3.jar b/gui/java/lib/swingx-beaninfo-1.6.3.jar
similarity index 100%
rename from gui_java/lib/swingx-beaninfo-1.6.3.jar
rename to gui/java/lib/swingx-beaninfo-1.6.3.jar
diff --git a/gui_java/manifest.mf b/gui/java/manifest.mf
similarity index 100%
rename from gui_java/manifest.mf
rename to gui/java/manifest.mf
diff --git a/gui_java/nbproject/build-impl.xml b/gui/java/nbproject/build-impl.xml
similarity index 100%
rename from gui_java/nbproject/build-impl.xml
rename to gui/java/nbproject/build-impl.xml
diff --git a/gui_java/nbproject/genfiles.properties b/gui/java/nbproject/genfiles.properties
similarity index 100%
rename from gui_java/nbproject/genfiles.properties
rename to gui/java/nbproject/genfiles.properties
diff --git a/gui_java/nbproject/private/config.properties b/gui/java/nbproject/private/config.properties
similarity index 100%
rename from gui_java/nbproject/private/config.properties
rename to gui/java/nbproject/private/config.properties
diff --git a/gui_java/nbproject/private/private.properties b/gui/java/nbproject/private/private.properties
similarity index 100%
rename from gui_java/nbproject/private/private.properties
rename to gui/java/nbproject/private/private.properties
diff --git a/gui_java/nbproject/private/private.xml b/gui/java/nbproject/private/private.xml
similarity index 100%
rename from gui_java/nbproject/private/private.xml
rename to gui/java/nbproject/private/private.xml
diff --git a/gui_java/nbproject/project.properties b/gui/java/nbproject/project.properties
similarity index 100%
rename from gui_java/nbproject/project.properties
rename to gui/java/nbproject/project.properties
diff --git a/gui_java/nbproject/project.xml b/gui/java/nbproject/project.xml
similarity index 100%
rename from gui_java/nbproject/project.xml
rename to gui/java/nbproject/project.xml
diff --git a/gui_java/run_camera.bat b/gui/java/run_camera.bat
similarity index 100%
rename from gui_java/run_camera.bat
rename to gui/java/run_camera.bat
diff --git a/gui_java/run_java_gui.bat b/gui/java/run_java_gui.bat
similarity index 100%
rename from gui_java/run_java_gui.bat
rename to gui/java/run_java_gui.bat
diff --git a/gui_java/run_java_gui_with_console.bat b/gui/java/run_java_gui_with_console.bat
similarity index 100%
rename from gui_java/run_java_gui_with_console.bat
rename to gui/java/run_java_gui_with_console.bat
diff --git a/gui_java/run_video.bat b/gui/java/run_video.bat
similarity index 100%
rename from gui_java/run_video.bat
rename to gui/java/run_video.bat
diff --git a/gui_java/src/br/com/bgslibrary/Main.java b/gui/java/src/br/com/bgslibrary/Main.java
similarity index 60%
rename from gui_java/src/br/com/bgslibrary/Main.java
rename to gui/java/src/br/com/bgslibrary/Main.java
index f986a21..339fae6 100644
--- a/gui_java/src/br/com/bgslibrary/Main.java
+++ b/gui/java/src/br/com/bgslibrary/Main.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 package br.com.bgslibrary;
 
 import br.com.bgslibrary.gui.MainFrame;
diff --git a/gui_java/src/br/com/bgslibrary/entity/Command.java b/gui/java/src/br/com/bgslibrary/entity/Command.java
similarity index 83%
rename from gui_java/src/br/com/bgslibrary/entity/Command.java
rename to gui/java/src/br/com/bgslibrary/entity/Command.java
index 57abcf4..452173b 100644
--- a/gui_java/src/br/com/bgslibrary/entity/Command.java
+++ b/gui/java/src/br/com/bgslibrary/entity/Command.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 package br.com.bgslibrary.entity;
 
 public class Command
diff --git a/gui_java/src/br/com/bgslibrary/entity/Configuration.java b/gui/java/src/br/com/bgslibrary/entity/Configuration.java
similarity index 78%
rename from gui_java/src/br/com/bgslibrary/entity/Configuration.java
rename to gui/java/src/br/com/bgslibrary/entity/Configuration.java
index caa07fd..d5abebd 100644
--- a/gui_java/src/br/com/bgslibrary/entity/Configuration.java
+++ b/gui/java/src/br/com/bgslibrary/entity/Configuration.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 package br.com.bgslibrary.entity;
 
 public interface Configuration
diff --git a/gui_java/src/br/com/bgslibrary/gui/AboutDialog.form b/gui/java/src/br/com/bgslibrary/gui/AboutDialog.form
similarity index 100%
rename from gui_java/src/br/com/bgslibrary/gui/AboutDialog.form
rename to gui/java/src/br/com/bgslibrary/gui/AboutDialog.form
diff --git a/gui_java/src/br/com/bgslibrary/gui/AboutDialog.java b/gui/java/src/br/com/bgslibrary/gui/AboutDialog.java
similarity index 87%
rename from gui_java/src/br/com/bgslibrary/gui/AboutDialog.java
rename to gui/java/src/br/com/bgslibrary/gui/AboutDialog.java
index 2c8afc0..836a5ab 100644
--- a/gui_java/src/br/com/bgslibrary/gui/AboutDialog.java
+++ b/gui/java/src/br/com/bgslibrary/gui/AboutDialog.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 package br.com.bgslibrary.gui;
 
 public class AboutDialog extends javax.swing.JDialog
diff --git a/gui_java/src/br/com/bgslibrary/gui/MainFrame.form b/gui/java/src/br/com/bgslibrary/gui/MainFrame.form
similarity index 100%
rename from gui_java/src/br/com/bgslibrary/gui/MainFrame.form
rename to gui/java/src/br/com/bgslibrary/gui/MainFrame.form
diff --git a/gui_java/src/br/com/bgslibrary/gui/MainFrame.java b/gui/java/src/br/com/bgslibrary/gui/MainFrame.java
similarity index 99%
rename from gui_java/src/br/com/bgslibrary/gui/MainFrame.java
rename to gui/java/src/br/com/bgslibrary/gui/MainFrame.java
index 4938426..538e189 100644
--- a/gui_java/src/br/com/bgslibrary/gui/MainFrame.java
+++ b/gui/java/src/br/com/bgslibrary/gui/MainFrame.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 package br.com.bgslibrary.gui;
 
 import br.com.bgslibrary.entity.Command;
diff --git a/gui_java/src/br/com/bgslibrary/resources/logo.jpg b/gui/java/src/br/com/bgslibrary/resources/logo.jpg
similarity index 100%
rename from gui_java/src/br/com/bgslibrary/resources/logo.jpg
rename to gui/java/src/br/com/bgslibrary/resources/logo.jpg
diff --git a/gui_mfc/.gitignore b/gui/mfc/.gitignore
similarity index 100%
rename from gui_mfc/.gitignore
rename to gui/mfc/.gitignore
diff --git a/gui_mfc/ReadMe.txt b/gui/mfc/ReadMe.txt
similarity index 100%
rename from gui_mfc/ReadMe.txt
rename to gui/mfc/ReadMe.txt
diff --git a/gui_mfc/config/AdaptiveBackgroundLearning.xml b/gui/mfc/config/AdaptiveBackgroundLearning.xml
similarity index 100%
rename from gui_mfc/config/AdaptiveBackgroundLearning.xml
rename to gui/mfc/config/AdaptiveBackgroundLearning.xml
diff --git a/gui_mfc/config/AdaptiveSelectiveBackgroundLearning.xml b/gui/mfc/config/AdaptiveSelectiveBackgroundLearning.xml
similarity index 100%
rename from gui_mfc/config/AdaptiveSelectiveBackgroundLearning.xml
rename to gui/mfc/config/AdaptiveSelectiveBackgroundLearning.xml
diff --git a/gui_mfc/config/DPAdaptiveMedianBGS.xml b/gui/mfc/config/DPAdaptiveMedianBGS.xml
similarity index 100%
rename from gui_mfc/config/DPAdaptiveMedianBGS.xml
rename to gui/mfc/config/DPAdaptiveMedianBGS.xml
diff --git a/gui_mfc/config/DPEigenbackgroundBGS.xml b/gui/mfc/config/DPEigenbackgroundBGS.xml
similarity index 100%
rename from gui_mfc/config/DPEigenbackgroundBGS.xml
rename to gui/mfc/config/DPEigenbackgroundBGS.xml
diff --git a/gui_mfc/config/DPGrimsonGMMBGS.xml b/gui/mfc/config/DPGrimsonGMMBGS.xml
similarity index 100%
rename from gui_mfc/config/DPGrimsonGMMBGS.xml
rename to gui/mfc/config/DPGrimsonGMMBGS.xml
diff --git a/gui_mfc/config/DPMeanBGS.xml b/gui/mfc/config/DPMeanBGS.xml
similarity index 100%
rename from gui_mfc/config/DPMeanBGS.xml
rename to gui/mfc/config/DPMeanBGS.xml
diff --git a/gui_mfc/config/DPPratiMediodBGS.xml b/gui/mfc/config/DPPratiMediodBGS.xml
similarity index 100%
rename from gui_mfc/config/DPPratiMediodBGS.xml
rename to gui/mfc/config/DPPratiMediodBGS.xml
diff --git a/gui_mfc/config/DPTextureBGS.xml b/gui/mfc/config/DPTextureBGS.xml
similarity index 100%
rename from gui_mfc/config/DPTextureBGS.xml
rename to gui/mfc/config/DPTextureBGS.xml
diff --git a/gui_mfc/config/DPWrenGABGS.xml b/gui/mfc/config/DPWrenGABGS.xml
similarity index 100%
rename from gui_mfc/config/DPWrenGABGS.xml
rename to gui/mfc/config/DPWrenGABGS.xml
diff --git a/gui_mfc/config/DPZivkovicAGMMBGS.xml b/gui/mfc/config/DPZivkovicAGMMBGS.xml
similarity index 100%
rename from gui_mfc/config/DPZivkovicAGMMBGS.xml
rename to gui/mfc/config/DPZivkovicAGMMBGS.xml
diff --git a/gui_mfc/config/FrameDifferenceBGS.xml b/gui/mfc/config/FrameDifferenceBGS.xml
similarity index 100%
rename from gui_mfc/config/FrameDifferenceBGS.xml
rename to gui/mfc/config/FrameDifferenceBGS.xml
diff --git a/gui_mfc/config/FuzzyChoquetIntegral.xml b/gui/mfc/config/FuzzyChoquetIntegral.xml
similarity index 100%
rename from gui_mfc/config/FuzzyChoquetIntegral.xml
rename to gui/mfc/config/FuzzyChoquetIntegral.xml
diff --git a/gui_mfc/config/FuzzySugenoIntegral.xml b/gui/mfc/config/FuzzySugenoIntegral.xml
similarity index 100%
rename from gui_mfc/config/FuzzySugenoIntegral.xml
rename to gui/mfc/config/FuzzySugenoIntegral.xml
diff --git a/gui_mfc/config/GMG.xml b/gui/mfc/config/GMG.xml
similarity index 100%
rename from gui_mfc/config/GMG.xml
rename to gui/mfc/config/GMG.xml
diff --git a/gui_mfc/config/IndependentMultimodalBGS.xml b/gui/mfc/config/IndependentMultimodalBGS.xml
similarity index 100%
rename from gui_mfc/config/IndependentMultimodalBGS.xml
rename to gui/mfc/config/IndependentMultimodalBGS.xml
diff --git a/gui_mfc/config/KDE.xml b/gui/mfc/config/KDE.xml
similarity index 100%
rename from gui_mfc/config/KDE.xml
rename to gui/mfc/config/KDE.xml
diff --git a/gui_mfc/config/LBAdaptiveSOM.xml b/gui/mfc/config/LBAdaptiveSOM.xml
similarity index 100%
rename from gui_mfc/config/LBAdaptiveSOM.xml
rename to gui/mfc/config/LBAdaptiveSOM.xml
diff --git a/gui_mfc/config/LBFuzzyAdaptiveSOM.xml b/gui/mfc/config/LBFuzzyAdaptiveSOM.xml
similarity index 100%
rename from gui_mfc/config/LBFuzzyAdaptiveSOM.xml
rename to gui/mfc/config/LBFuzzyAdaptiveSOM.xml
diff --git a/gui_mfc/config/LBFuzzyGaussian.xml b/gui/mfc/config/LBFuzzyGaussian.xml
similarity index 100%
rename from gui_mfc/config/LBFuzzyGaussian.xml
rename to gui/mfc/config/LBFuzzyGaussian.xml
diff --git a/gui_mfc/config/LBMixtureOfGaussians.xml b/gui/mfc/config/LBMixtureOfGaussians.xml
similarity index 100%
rename from gui_mfc/config/LBMixtureOfGaussians.xml
rename to gui/mfc/config/LBMixtureOfGaussians.xml
diff --git a/gui_mfc/config/LBSimpleGaussian.xml b/gui/mfc/config/LBSimpleGaussian.xml
similarity index 100%
rename from gui_mfc/config/LBSimpleGaussian.xml
rename to gui/mfc/config/LBSimpleGaussian.xml
diff --git a/gui_mfc/config/LOBSTERBGS.xml b/gui/mfc/config/LOBSTERBGS.xml
similarity index 100%
rename from gui_mfc/config/LOBSTERBGS.xml
rename to gui/mfc/config/LOBSTERBGS.xml
diff --git a/gui_mfc/config/MixtureOfGaussianV1BGS.xml b/gui/mfc/config/MixtureOfGaussianV1BGS.xml
similarity index 100%
rename from gui_mfc/config/MixtureOfGaussianV1BGS.xml
rename to gui/mfc/config/MixtureOfGaussianV1BGS.xml
diff --git a/gui_mfc/config/MixtureOfGaussianV2BGS.xml b/gui/mfc/config/MixtureOfGaussianV2BGS.xml
similarity index 100%
rename from gui_mfc/config/MixtureOfGaussianV2BGS.xml
rename to gui/mfc/config/MixtureOfGaussianV2BGS.xml
diff --git a/gui_mfc/config/MultiCueBGS.xml b/gui/mfc/config/MultiCueBGS.xml
similarity index 100%
rename from gui_mfc/config/MultiCueBGS.xml
rename to gui/mfc/config/MultiCueBGS.xml
diff --git a/gui_mfc/config/MultiLayerBGS.xml b/gui/mfc/config/MultiLayerBGS.xml
similarity index 100%
rename from gui_mfc/config/MultiLayerBGS.xml
rename to gui/mfc/config/MultiLayerBGS.xml
diff --git a/gui_mfc/config/SigmaDeltaBGS.xml b/gui/mfc/config/SigmaDeltaBGS.xml
similarity index 100%
rename from gui_mfc/config/SigmaDeltaBGS.xml
rename to gui/mfc/config/SigmaDeltaBGS.xml
diff --git a/gui_mfc/config/StaticFrameDifferenceBGS.xml b/gui/mfc/config/StaticFrameDifferenceBGS.xml
similarity index 100%
rename from gui_mfc/config/StaticFrameDifferenceBGS.xml
rename to gui/mfc/config/StaticFrameDifferenceBGS.xml
diff --git a/gui_mfc/config/SuBSENSEBGS.xml b/gui/mfc/config/SuBSENSEBGS.xml
similarity index 100%
rename from gui_mfc/config/SuBSENSEBGS.xml
rename to gui/mfc/config/SuBSENSEBGS.xml
diff --git a/gui_mfc/config/T2FGMM_UM.xml b/gui/mfc/config/T2FGMM_UM.xml
similarity index 100%
rename from gui_mfc/config/T2FGMM_UM.xml
rename to gui/mfc/config/T2FGMM_UM.xml
diff --git a/gui_mfc/config/T2FGMM_UV.xml b/gui/mfc/config/T2FGMM_UV.xml
similarity index 100%
rename from gui_mfc/config/T2FGMM_UV.xml
rename to gui/mfc/config/T2FGMM_UV.xml
diff --git a/gui_mfc/config/T2FMRF_UM.xml b/gui/mfc/config/T2FMRF_UM.xml
similarity index 100%
rename from gui_mfc/config/T2FMRF_UM.xml
rename to gui/mfc/config/T2FMRF_UM.xml
diff --git a/gui_mfc/config/T2FMRF_UV.xml b/gui/mfc/config/T2FMRF_UV.xml
similarity index 100%
rename from gui_mfc/config/T2FMRF_UV.xml
rename to gui/mfc/config/T2FMRF_UV.xml
diff --git a/gui_mfc/config/VuMeter.xml b/gui/mfc/config/VuMeter.xml
similarity index 100%
rename from gui_mfc/config/VuMeter.xml
rename to gui/mfc/config/VuMeter.xml
diff --git a/gui_mfc/config/WeightedMovingMeanBGS.xml b/gui/mfc/config/WeightedMovingMeanBGS.xml
similarity index 100%
rename from gui_mfc/config/WeightedMovingMeanBGS.xml
rename to gui/mfc/config/WeightedMovingMeanBGS.xml
diff --git a/gui_mfc/config/WeightedMovingVarianceBGS.xml b/gui/mfc/config/WeightedMovingVarianceBGS.xml
similarity index 100%
rename from gui_mfc/config/WeightedMovingVarianceBGS.xml
rename to gui/mfc/config/WeightedMovingVarianceBGS.xml
diff --git a/gui_mfc/dataset/video.avi b/gui/mfc/dataset/video.avi
similarity index 100%
rename from gui_mfc/dataset/video.avi
rename to gui/mfc/dataset/video.avi
diff --git a/gui_mfc/outputs/input/.gitignore b/gui/mfc/outputs/background/.gitignore
similarity index 100%
rename from gui_mfc/outputs/input/.gitignore
rename to gui/mfc/outputs/background/.gitignore
diff --git a/gui_qt/build/.gitignore b/gui/mfc/outputs/foreground/.gitignore
similarity index 100%
rename from gui_qt/build/.gitignore
rename to gui/mfc/outputs/foreground/.gitignore
diff --git a/wrapper_java/config/.gitignore b/gui/mfc/outputs/input/.gitignore
similarity index 100%
rename from wrapper_java/config/.gitignore
rename to gui/mfc/outputs/input/.gitignore
diff --git a/gui_mfc/src/.gitignore b/gui/mfc/src/.gitignore
similarity index 100%
rename from gui_mfc/src/.gitignore
rename to gui/mfc/src/.gitignore
diff --git a/gui_mfc/src/App.cpp b/gui/mfc/src/App.cpp
similarity index 100%
rename from gui_mfc/src/App.cpp
rename to gui/mfc/src/App.cpp
diff --git a/gui_mfc/src/App.h b/gui/mfc/src/App.h
similarity index 100%
rename from gui_mfc/src/App.h
rename to gui/mfc/src/App.h
diff --git a/gui_mfc/src/Dlg.cpp b/gui/mfc/src/Dlg.cpp
similarity index 100%
rename from gui_mfc/src/Dlg.cpp
rename to gui/mfc/src/Dlg.cpp
diff --git a/gui_mfc/src/Dlg.h b/gui/mfc/src/Dlg.h
similarity index 100%
rename from gui_mfc/src/Dlg.h
rename to gui/mfc/src/Dlg.h
diff --git a/gui_mfc/src/ReadMe.txt b/gui/mfc/src/ReadMe.txt
similarity index 100%
rename from gui_mfc/src/ReadMe.txt
rename to gui/mfc/src/ReadMe.txt
diff --git a/gui_mfc/src/bgslibrary_vs2013_mfc.rc b/gui/mfc/src/bgslibrary_vs2013_mfc.rc
similarity index 100%
rename from gui_mfc/src/bgslibrary_vs2013_mfc.rc
rename to gui/mfc/src/bgslibrary_vs2013_mfc.rc
diff --git a/gui_mfc/src/bgslibrary_vs2013_mfc.sln b/gui/mfc/src/bgslibrary_vs2013_mfc.sln
similarity index 100%
rename from gui_mfc/src/bgslibrary_vs2013_mfc.sln
rename to gui/mfc/src/bgslibrary_vs2013_mfc.sln
diff --git a/gui_mfc/src/bgslibrary_vs2013_mfc.vcxproj b/gui/mfc/src/bgslibrary_vs2013_mfc.vcxproj
similarity index 100%
rename from gui_mfc/src/bgslibrary_vs2013_mfc.vcxproj
rename to gui/mfc/src/bgslibrary_vs2013_mfc.vcxproj
diff --git a/gui_mfc/src/bgslibrary_vs2013_mfc.vcxproj.filters b/gui/mfc/src/bgslibrary_vs2013_mfc.vcxproj.filters
similarity index 100%
rename from gui_mfc/src/bgslibrary_vs2013_mfc.vcxproj.filters
rename to gui/mfc/src/bgslibrary_vs2013_mfc.vcxproj.filters
diff --git a/gui_mfc/src/bgslibrary_vs2013_mfc.vcxproj.user b/gui/mfc/src/bgslibrary_vs2013_mfc.vcxproj.user
similarity index 100%
rename from gui_mfc/src/bgslibrary_vs2013_mfc.vcxproj.user
rename to gui/mfc/src/bgslibrary_vs2013_mfc.vcxproj.user
diff --git a/gui_mfc/src/res/bgslibrary_vs2013_mfc.ico b/gui/mfc/src/res/bgslibrary_vs2013_mfc.ico
similarity index 100%
rename from gui_mfc/src/res/bgslibrary_vs2013_mfc.ico
rename to gui/mfc/src/res/bgslibrary_vs2013_mfc.ico
diff --git a/gui_mfc/src/res/bgslibrary_vs2013_mfc.rc2 b/gui/mfc/src/res/bgslibrary_vs2013_mfc.rc2
similarity index 100%
rename from gui_mfc/src/res/bgslibrary_vs2013_mfc.rc2
rename to gui/mfc/src/res/bgslibrary_vs2013_mfc.rc2
diff --git a/gui_mfc/src/resource.h b/gui/mfc/src/resource.h
similarity index 100%
rename from gui_mfc/src/resource.h
rename to gui/mfc/src/resource.h
diff --git a/gui_mfc/src/stdafx.cpp b/gui/mfc/src/stdafx.cpp
similarity index 100%
rename from gui_mfc/src/stdafx.cpp
rename to gui/mfc/src/stdafx.cpp
diff --git a/gui_mfc/src/stdafx.h b/gui/mfc/src/stdafx.h
similarity index 100%
rename from gui_mfc/src/stdafx.h
rename to gui/mfc/src/stdafx.h
diff --git a/gui_mfc/src/targetver.h b/gui/mfc/src/targetver.h
similarity index 100%
rename from gui_mfc/src/targetver.h
rename to gui/mfc/src/targetver.h
diff --git a/gui_qt/.gitignore b/gui/qt/.gitignore
similarity index 100%
rename from gui_qt/.gitignore
rename to gui/qt/.gitignore
diff --git a/gui_qt/CMakeLists.txt b/gui/qt/CMakeLists.txt
similarity index 90%
rename from gui_qt/CMakeLists.txt
rename to gui/qt/CMakeLists.txt
index f9b418d..07073e0 100644
--- a/gui_qt/CMakeLists.txt
+++ b/gui/qt/CMakeLists.txt
@@ -55,10 +55,10 @@ endif()
 
 file(GLOB main bgslibrary_gui.cpp mainwindow.cpp qt_utils.cpp texteditor.cpp)
 
-file(GLOB_RECURSE analysis_src ../package_analysis/*.cpp)
-file(GLOB_RECURSE analysis_inc ../package_analysis/*.h)
-file(GLOB_RECURSE bgs_src ../package_bgs/*.cpp ../package_bgs/*.c)
-file(GLOB_RECURSE bgs_inc ../package_bgs/*.h)
+file(GLOB_RECURSE analysis_src ../../src/package_analysis/*.cpp)
+file(GLOB_RECURSE analysis_inc ../../src/package_analysis/*.h)
+file(GLOB_RECURSE bgs_src ../../src/package_bgs/*.cpp ../../src/package_bgs/*.c)
+file(GLOB_RECURSE bgs_inc ../../src/package_bgs/*.h)
 
 include_directories(${CMAKE_SOURCE_DIR} ${OpenCV_INCLUDE_DIRS})
 
diff --git a/gui/qt/README.md b/gui/qt/README.md
new file mode 100644
index 0000000..29f41ea
--- /dev/null
+++ b/gui/qt/README.md
@@ -0,0 +1,118 @@
+## BGSLibrary v2.0.0 with QT GUI 
+
+* Download binaries for Windows (x86/x64):
+
+* * Download [bgslibrary2_qtgui_opencv320_x64.zip](https://github.com/andrewssobral/bgslibrary/releases/download/bgslib_qtgui_2.0.0/bgslibrary2_qtgui_opencv320_x64.zip)
+
+* * More info: https://github.com/andrewssobral/bgslibrary/releases/tag/bgslib_qtgui_2.0.0
+
+![BGSLibrary QT GUI](https://sites.google.com/site/andrewssobral/bgslibrary_qt_gui.png "BGSLibrary QT GUI")
+
+## Building QT GUI from scratch
+
+* Dependencies:
+
+* * OpenCV 2.x or 3.x (Tested with OpenCV 3.2.0)
+
+* * Qt 5 library (Tested with Qt 5.6.2)
+
+### On Windows (with CMAKE and Visual Studio 2015 x64)
+
+1) Click on 'Qt 5.6 64-bit for Desktop (MSVC 2015)'
+
+2) Go to **bgslibrary/gui_qt/build** folder.
+
+3) Set your OpenCV PATH:
+```
+set OpenCV_DIR=C:\OpenCV3.2.0\build
+```
+
+4) Launch CMAKE:
+```
+cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 14 Win64" ..
+```
+
+5) Include OpenCV binaries in the system path:
+```
+set PATH=%PATH%;%OpenCV_DIR%\x64\vc14\bin
+```
+
+6) Open the **bgslibrary_gui.sln** file in your Visual Studio and switch to **'RELEASE'** mode 
+
+7) Click on **'ALL_BUILD'** project and build!
+
+8) Go to **bgslibrary/gui_qt/build/Release** and copy **bgslibrary_gui.exe** to **bgslibrary/**.
+
+9) Run **bgslibrary_gui.exe** and enjoy! ;-)
+
+### On Linux or Mac OS X 
+
+* Installing dependencies on Mac OS X:
+```
+brew install opencv3 --with-ffmpeg --with-qt5 --HEAD
+brew link --overwrite --dry-run opencv3
+```
+
+* Step-by-step Instructions
+```
+git clone --recursive https://github.com/andrewssobral/bgslibrary.git
+
+cd bgslibrary/gui_qt/build
+cmake ..
+make
+
+cp bgslibrary_gui ../../ 
+
+./bgslibrary_gui 
+```
+
+
+![BGSLibrary QT GUI](https://sites.google.com/site/andrewssobral/bgslibrary2_qt_gui_osx.png "BGSLibrary QT GUI")
+
+### (Video) Build & Execute BGSLibrary QT GUI on MacOSX using CMake
+
+<p align="center"><a href=https://youtu.be/vl0c-mXWQEo>https://youtu.be/vl0c-mXWQEo</a></p>
+<p align="center">
+<a href="https://youtu.be/vl0c-mXWQEo" target="_blank">
+<img src="https://sites.google.com/site/andrewssobral/bgslib_qtgui_macosx.png?width=600" border="0" />
+</a>
+</p>
+
+
+
+
+* Possible issues:
+
+If you have something like this:
+```
+CMake Warning at CMakeLists.txt:33 (find_package):
+  By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
+  has asked CMake to find a package configuration file provided by
+  "Qt5Widgets", but CMake did not find one.
+
+  Could not find a package configuration file provided by "Qt5Widgets" with
+  any of the following names:
+
+    Qt5WidgetsConfig.cmake
+    qt5widgets-config.cmake
+
+  Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
+  "Qt5Widgets_DIR" to a directory containing one of the above files.  If
+  "Qt5Widgets" provides a separate development package or SDK, be sure it has
+  been installed.
+
+
+CMake Error at CMakeLists.txt:44 (QT5_ADD_RESOURCES):
+  Unknown CMake command "QT5_ADD_RESOURCES".
+
+
+-- Configuring incomplete, errors occurred!
+```
+
+You just need to specify the PATH of your QT installation, for example:
+
+On Linux:
+`cmake .. -DCMAKE_PREFIX_PATH=$HOME/Qt/5.12.1/gcc_64`
+
+On MacOS:
+`cmake .. -DCMAKE_PREFIX_PATH=$HOME/Qt/5.13.0/clang_64`
diff --git a/gui_qt/application.qrc b/gui/qt/application.qrc
similarity index 100%
rename from gui_qt/application.qrc
rename to gui/qt/application.qrc
diff --git a/gui_qt/bgslibrary_gui.cpp b/gui/qt/bgslibrary_gui.cpp
similarity index 54%
rename from gui_qt/bgslibrary_gui.cpp
rename to gui/qt/bgslibrary_gui.cpp
index e886262..ae2721f 100644
--- a/gui_qt/bgslibrary_gui.cpp
+++ b/gui/qt/bgslibrary_gui.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "mainwindow.h"
 
 int main(int argc, char *argv[])
diff --git a/gui/qt/bgslibrary_gui.pro b/gui/qt/bgslibrary_gui.pro
new file mode 100644
index 0000000..259a1d0
--- /dev/null
+++ b/gui/qt/bgslibrary_gui.pro
@@ -0,0 +1,255 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = bgslibrary_gui
+TEMPLATE = app
+
+# For Windows x64 + Visual Studio 2015 + OpenCV 3.1.0
+#INCLUDEPATH += C:/OpenCV3.1.0/build/include
+#LIBS += -LC:/OpenCV3.1.0/build/x64/vc14/lib -lopencv_world310
+
+# For Windows x64 + Visual Studio 2015 + OpenCV 3.2.0
+#INCLUDEPATH += C:/OpenCV3.2.0/build/include
+#LIBS += -LC:/OpenCV3.2.0/build/x64/vc14/lib -lopencv_world320
+
+# For Windows x64 + Visual Studio 2017 + OpenCV 3.4.2
+INCLUDEPATH += E:/OpenCV3.4.2/build/include
+INCLUDEPATH += E:/OpenCV3.4.2/build/include/opencv
+LIBS += -LE:/OpenCV3.4.2/build/x64/vc15/lib -lopencv_world342
+
+# For Linux
+# INCLUDEPATH += /usr/local/include/opencv
+# LIBS += -L/usr/local/lib
+
+RESOURCES = application.qrc
+
+SOURCES += bgslibrary_gui.cpp\
+    mainwindow.cpp \
+    qt_utils.cpp \
+    texteditor.cpp \
+    ../../src/package_analysis/ForegroundMaskAnalysis.cpp \
+    ../../src/package_analysis/PerformanceUtils.cpp \
+    ../../src/package_analysis/PixelUtils.cpp \
+    ../../src/package_bgs/_template_/Amber.cpp \
+    ../../src/package_bgs/_template_/MyBGS.cpp \
+    ../../src/package_bgs/dp/AdaptiveMedianBGS.cpp \
+    ../../src/package_bgs/dp/Eigenbackground.cpp \
+    ../../src/package_bgs/dp/Error.cpp \
+    ../../src/package_bgs/dp/GrimsonGMM.cpp \
+    ../../src/package_bgs/dp/Image.cpp \
+    ../../src/package_bgs/dp/MeanBGS.cpp \
+    ../../src/package_bgs/dp/PratiMediodBGS.cpp \
+    ../../src/package_bgs/dp/TextureBGS.cpp \
+    ../../src/package_bgs/dp/WrenGA.cpp \
+    ../../src/package_bgs/dp/ZivkovicAGMM.cpp \
+    ../../src/package_bgs/IMBS/IMBS.cpp \
+    ../../src/package_bgs/KDE/KernelTable.cpp \
+    ../../src/package_bgs/KDE/NPBGmodel.cpp \
+    ../../src/package_bgs/KDE/NPBGSubtractor.cpp \
+    ../../src/package_bgs/lb/BGModel.cpp \
+    ../../src/package_bgs/lb/BGModelFuzzyGauss.cpp \
+    ../../src/package_bgs/lb/BGModelFuzzySom.cpp \
+    ../../src/package_bgs/lb/BGModelGauss.cpp \
+    ../../src/package_bgs/lb/BGModelMog.cpp \
+    ../../src/package_bgs/lb/BGModelSom.cpp \
+    ../../src/package_bgs/LBP_MRF/graph.cpp \
+    ../../src/package_bgs/LBP_MRF/maxflow.cpp \
+    ../../src/package_bgs/LBP_MRF/MEDefs.cpp \
+    ../../src/package_bgs/LBP_MRF/MEHistogram.cpp \
+    ../../src/package_bgs/LBP_MRF/MEImage.cpp \
+    ../../src/package_bgs/LBP_MRF/MotionDetection.cpp \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp \
+    ../../src/package_bgs/LBSP/LBSP.cpp \
+    ../../src/package_bgs/LBSP/LBSP_.cpp \
+    ../../src/package_bgs/MultiLayer/blob.cpp \
+    ../../src/package_bgs/MultiLayer/BlobExtraction.cpp \
+    ../../src/package_bgs/MultiLayer/BlobResult.cpp \
+    ../../src/package_bgs/MultiLayer/CMultiLayerBGS.cpp \
+    ../../src/package_bgs/MultiLayer/LocalBinaryPattern.cpp \
+    ../../src/package_bgs/PBAS/PBAS.cpp \
+    ../../src/package_bgs/SigmaDelta/sdLaMa091.cpp \
+    ../../src/package_bgs/T2F/FuzzyUtils.cpp \
+    ../../src/package_bgs/T2F/MRF.cpp \
+    ../../src/package_bgs/T2F/T2FGMM.cpp \
+    ../../src/package_bgs/T2F/T2FMRF.cpp \
+    ../../src/package_bgs/TwoPoints/two_points.cpp \
+    ../../src/package_bgs/ViBe/vibe-background-sequential.cpp \
+    ../../src/package_bgs/VuMeter/TBackground.cpp \
+    ../../src/package_bgs/VuMeter/TBackgroundVuMeter.cpp \
+    ../../src/package_bgs/AdaptiveBackgroundLearning.cpp \
+    ../../src/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp \
+    ../../src/package_bgs/DPAdaptiveMedian.cpp \
+    ../../src/package_bgs/DPEigenbackground.cpp \
+    ../../src/package_bgs/DPGrimsonGMM.cpp \
+    ../../src/package_bgs/DPMean.cpp \
+    ../../src/package_bgs/DPPratiMediod.cpp \
+    ../../src/package_bgs/DPTexture.cpp \
+    ../../src/package_bgs/DPWrenGA.cpp \
+    ../../src/package_bgs/DPZivkovicAGMM.cpp \
+    ../../src/package_bgs/FrameDifference.cpp \
+    ../../src/package_bgs/FuzzyChoquetIntegral.cpp \
+    ../../src/package_bgs/FuzzySugenoIntegral.cpp \
+    ../../src/package_bgs/GMG.cpp \
+    ../../src/package_bgs/IndependentMultimodal.cpp \
+    ../../src/package_bgs/KDE.cpp \
+    ../../src/package_bgs/KNN.cpp \
+    ../../src/package_bgs/LBAdaptiveSOM.cpp \
+    ../../src/package_bgs/LBFuzzyAdaptiveSOM.cpp \
+    ../../src/package_bgs/LBFuzzyGaussian.cpp \
+    ../../src/package_bgs/LBMixtureOfGaussians.cpp \
+    ../../src/package_bgs/LBP_MRF.cpp \
+    ../../src/package_bgs/LBSimpleGaussian.cpp \
+    ../../src/package_bgs/LOBSTER.cpp \
+    ../../src/package_bgs/MixtureOfGaussianV1.cpp \
+    ../../src/package_bgs/MixtureOfGaussianV2.cpp \
+    ../../src/package_bgs/MultiCue.cpp \
+    ../../src/package_bgs/MultiLayer.cpp \
+    ../../src/package_bgs/PAWCS.cpp \
+    ../../src/package_bgs/PixelBasedAdaptiveSegmenter.cpp \
+    ../../src/package_bgs/SigmaDelta.cpp \
+    ../../src/package_bgs/StaticFrameDifference.cpp \
+    ../../src/package_bgs/SuBSENSE.cpp \
+    ../../src/package_bgs/T2FGMM_UM.cpp \
+    ../../src/package_bgs/T2FGMM_UV.cpp \
+    ../../src/package_bgs/T2FMRF_UM.cpp \
+    ../../src/package_bgs/T2FMRF_UV.cpp \
+    ../../src/package_bgs/TwoPoints.cpp \
+    ../../src/package_bgs/ViBe.cpp \
+    ../../src/package_bgs/VuMeter.cpp \
+    ../../src/package_bgs/WeightedMovingMean.cpp \
+    ../../src/package_bgs/WeightedMovingVariance.cpp \
+    ../../src/package_bgs/_template_/amber/amber.cpp \
+    ../../src/package_bgs/CodeBook.cpp
+
+HEADERS  += mainwindow.h \
+    qt_utils.h \
+    texteditor.h \
+    ../../src/package_analysis/ForegroundMaskAnalysis.h \
+    ../../src/package_analysis/PerformanceUtils.h \
+    ../../src/package_analysis/PixelUtils.h \
+    ../../src/package_bgs/_template_/amber/amber.h \
+    ../../src/package_bgs/_template_/Amber.h \
+    ../../src/package_bgs/_template_/MyBGS.h \
+    ../../src/package_bgs/dp/AdaptiveMedianBGS.h \
+    ../../src/package_bgs/dp/Bgs.h \
+    ../../src/package_bgs/dp/BgsParams.h \
+    ../../src/package_bgs/dp/Eigenbackground.h \
+    ../../src/package_bgs/dp/Error.h \
+    ../../src/package_bgs/dp/GrimsonGMM.h \
+    ../../src/package_bgs/dp/Image.h \
+    ../../src/package_bgs/dp/MeanBGS.h \
+    ../../src/package_bgs/dp/PratiMediodBGS.h \
+    ../../src/package_bgs/dp/TextureBGS.h \
+    ../../src/package_bgs/dp/WrenGA.h \
+    ../../src/package_bgs/dp/ZivkovicAGMM.h \
+    ../../src/package_bgs/IMBS/IMBS.hpp \
+    ../../src/package_bgs/KDE/KernelTable.h \
+    ../../src/package_bgs/KDE/NPBGmodel.h \
+    ../../src/package_bgs/KDE/NPBGSubtractor.h \
+    ../../src/package_bgs/lb/BGModel.h \
+    ../../src/package_bgs/lb/BGModelFuzzyGauss.h \
+    ../../src/package_bgs/lb/BGModelFuzzySom.h \
+    ../../src/package_bgs/lb/BGModelGauss.h \
+    ../../src/package_bgs/lb/BGModelMog.h \
+    ../../src/package_bgs/lb/BGModelSom.h \
+    ../../src/package_bgs/lb/Types.h \
+    ../../src/package_bgs/LBP_MRF/block.h \
+    ../../src/package_bgs/LBP_MRF/graph.h \
+    ../../src/package_bgs/LBP_MRF/MEDefs.hpp \
+    ../../src/package_bgs/LBP_MRF/MEHistogram.hpp \
+    ../../src/package_bgs/LBP_MRF/MEImage.hpp \
+    ../../src/package_bgs/LBP_MRF/MotionDetection.hpp \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorLBSP.h \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorLBSP_.h \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.h \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorPAWCS.h \
+    ../../src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h \
+    ../../src/package_bgs/LBSP/DistanceUtils.h \
+    ../../src/package_bgs/LBSP/LBSP.h \
+    ../../src/package_bgs/LBSP/LBSP_.h \
+    ../../src/package_bgs/LBSP/RandUtils.h \
+    ../../src/package_bgs/MultiLayer/BackgroundSubtractionAPI.h \
+    ../../src/package_bgs/MultiLayer/BGS.h \
+    ../../src/package_bgs/MultiLayer/blob.h \
+    ../../src/package_bgs/MultiLayer/BlobExtraction.h \
+    ../../src/package_bgs/MultiLayer/BlobLibraryConfiguration.h \
+    ../../src/package_bgs/MultiLayer/BlobResult.h \
+    ../../src/package_bgs/MultiLayer/CMultiLayerBGS.h \
+    ../../src/package_bgs/MultiLayer/LocalBinaryPattern.h \
+    ../../src/package_bgs/MultiLayer/OpenCvDataConversion.h \
+    ../../src/package_bgs/MultiLayer/OpenCvLegacyIncludes.h \
+    ../../src/package_bgs/PBAS/PBAS.h \
+    ../../src/package_bgs/SigmaDelta/sdLaMa091.h \
+    ../../src/package_bgs/T2F/FuzzyUtils.h \
+    ../../src/package_bgs/T2F/MRF.h \
+    ../../src/package_bgs/T2F/T2FGMM.h \
+    ../../src/package_bgs/T2F/T2FMRF.h \
+    ../../src/package_bgs/TwoPoints/two_points.h \
+    ../../src/package_bgs/ViBe/vibe-background-sequential.h \
+    ../../src/package_bgs/VuMeter/TBackground.h \
+    ../../src/package_bgs/VuMeter/TBackgroundVuMeter.h \
+    ../../src/package_bgs/AdaptiveBackgroundLearning.h \
+    ../../src/package_bgs/AdaptiveSelectiveBackgroundLearning.h \
+    ../../src/package_bgs/bgslibrary.h \
+    ../../src/package_bgs/DPAdaptiveMedian.h \
+    ../../src/package_bgs/DPEigenbackground.h \
+    ../../src/package_bgs/DPGrimsonGMM.h \
+    ../../src/package_bgs/DPMean.h \
+    ../../src/package_bgs/DPPratiMediod.h \
+    ../../src/package_bgs/DPTexture.h \
+    ../../src/package_bgs/DPWrenGA.h \
+    ../../src/package_bgs/DPZivkovicAGMM.h \
+    ../../src/package_bgs/FrameDifference.h \
+    ../../src/package_bgs/FuzzyChoquetIntegral.h \
+    ../../src/package_bgs/FuzzySugenoIntegral.h \
+    ../../src/package_bgs/GMG.h \
+    ../../src/package_bgs/IBGS.h \
+    ../../src/package_bgs/IndependentMultimodal.h \
+    ../../src/package_bgs/KDE.h \
+    ../../src/package_bgs/KNN.h \
+    ../../src/package_bgs/LBAdaptiveSOM.h \
+    ../../src/package_bgs/LBFuzzyAdaptiveSOM.h \
+    ../../src/package_bgs/LBFuzzyGaussian.h \
+    ../../src/package_bgs/LBMixtureOfGaussians.h \
+    ../../src/package_bgs/LBP_MRF.h \
+    ../../src/package_bgs/LBSimpleGaussian.h \
+    ../../src/package_bgs/LOBSTER.h \
+    ../../src/package_bgs/MixtureOfGaussianV1.h \
+    ../../src/package_bgs/MixtureOfGaussianV2.h \
+    ../../src/package_bgs/MultiCue.h \
+    ../../src/package_bgs/MultiLayer.h \
+    ../../src/package_bgs/PAWCS.h \
+    ../../src/package_bgs/PixelBasedAdaptiveSegmenter.h \
+    ../../src/package_bgs/SigmaDelta.h \
+    ../../src/package_bgs/StaticFrameDifference.h \
+    ../../src/package_bgs/SuBSENSE.h \
+    ../../src/package_bgs/T2FGMM_UM.h \
+    ../../src/package_bgs/T2FGMM_UV.h \
+    ../../src/package_bgs/T2FMRF_UM.h \
+    ../../src/package_bgs/T2FMRF_UV.h \
+    ../../src/package_bgs/TwoPoints.h \
+    ../../src/package_bgs/ViBe.h \
+    ../../src/package_bgs/VuMeter.h \
+    ../../src/package_bgs/WeightedMovingMean.h \
+    ../../src/package_bgs/WeightedMovingVariance.h \
+    ../../src/package_bgs/CodeBook.h
+
+FORMS    += mainwindow.ui
+
+DISTFILES += \
+    ../../src/package_bgs/LBSP/LBSP_16bits_dbcross_1ch.i \
+    ../../src/package_bgs/LBSP/LBSP_16bits_dbcross_3ch1t.i \
+    ../../src/package_bgs/LBSP/LBSP_16bits_dbcross_3ch3t.i \
+    ../../src/package_bgs/LBSP/LBSP_16bits_dbcross_s3ch.i \
+    ../../src/package_bgs/ViBe/LICENSE
diff --git a/wrapper_matlab/config/.gitignore b/gui/qt/build/.gitignore
similarity index 100%
rename from wrapper_matlab/config/.gitignore
rename to gui/qt/build/.gitignore
diff --git a/gui_qt/figs/copy.png b/gui/qt/figs/copy.png
similarity index 100%
rename from gui_qt/figs/copy.png
rename to gui/qt/figs/copy.png
diff --git a/gui_qt/figs/cut.png b/gui/qt/figs/cut.png
similarity index 100%
rename from gui_qt/figs/cut.png
rename to gui/qt/figs/cut.png
diff --git a/gui_qt/figs/new.png b/gui/qt/figs/new.png
similarity index 100%
rename from gui_qt/figs/new.png
rename to gui/qt/figs/new.png
diff --git a/gui_qt/figs/open.png b/gui/qt/figs/open.png
similarity index 100%
rename from gui_qt/figs/open.png
rename to gui/qt/figs/open.png
diff --git a/gui_qt/figs/paste.png b/gui/qt/figs/paste.png
similarity index 100%
rename from gui_qt/figs/paste.png
rename to gui/qt/figs/paste.png
diff --git a/gui_qt/figs/save.png b/gui/qt/figs/save.png
similarity index 100%
rename from gui_qt/figs/save.png
rename to gui/qt/figs/save.png
diff --git a/gui_qt/mainwindow.cpp b/gui/qt/mainwindow.cpp
similarity index 96%
rename from gui_qt/mainwindow.cpp
rename to gui/qt/mainwindow.cpp
index 5b11765..f02f3a0 100644
--- a/gui_qt/mainwindow.cpp
+++ b/gui/qt/mainwindow.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
diff --git a/gui_qt/mainwindow.h b/gui/qt/mainwindow.h
similarity index 73%
rename from gui_qt/mainwindow.h
rename to gui/qt/mainwindow.h
index a834882..4ed6d35 100644
--- a/gui_qt/mainwindow.h
+++ b/gui/qt/mainwindow.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <QApplication>
@@ -34,7 +18,7 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "qt_utils.h"
 #include "texteditor.h"
-#include "../package_bgs/bgslibrary.h"
+#include "../../src/package_bgs/bgslibrary.h"
 
 namespace bgslibrary
 {
diff --git a/gui_qt/mainwindow.ui b/gui/qt/mainwindow.ui
similarity index 100%
rename from gui_qt/mainwindow.ui
rename to gui/qt/mainwindow.ui
diff --git a/gui_qt/qt_utils.cpp b/gui/qt/qt_utils.cpp
similarity index 68%
rename from gui_qt/qt_utils.cpp
rename to gui/qt/qt_utils.cpp
index 2464d78..8acc6fe 100644
--- a/gui_qt/qt_utils.cpp
+++ b/gui/qt/qt_utils.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include "qt_utils.h"
 
 QImage GrayMat2QImage(cv::Mat const& src) {
diff --git a/gui_qt/qt_utils.h b/gui/qt/qt_utils.h
similarity index 78%
rename from gui_qt/qt_utils.h
rename to gui/qt/qt_utils.h
index 84128c5..2233f3c 100644
--- a/gui_qt/qt_utils.h
+++ b/gui/qt/qt_utils.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <sstream>
diff --git a/gui_qt/texteditor.cpp b/gui/qt/texteditor.cpp
similarity index 93%
rename from gui_qt/texteditor.cpp
rename to gui/qt/texteditor.cpp
index 80f45e1..57d3b33 100644
--- a/gui_qt/texteditor.cpp
+++ b/gui/qt/texteditor.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include <QtWidgets>
 
 #include "texteditor.h"
diff --git a/gui_qt/texteditor.h b/gui/qt/texteditor.h
similarity index 57%
rename from gui_qt/texteditor.h
rename to gui/qt/texteditor.h
index c0d5d8f..c039ab3 100644
--- a/gui_qt/texteditor.h
+++ b/gui/qt/texteditor.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #ifndef TEXTEDITOR_H
 #define TEXTEDITOR_H
 
diff --git a/gui_qt/ui_mainwindow.h b/gui/qt/ui_mainwindow.h
similarity index 100%
rename from gui_qt/ui_mainwindow.h
rename to gui/qt/ui_mainwindow.h
diff --git a/gui_qt/README.txt b/gui_qt/README.txt
deleted file mode 100644
index 41a4cd2..0000000
--- a/gui_qt/README.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-#-------------------------------------------------
-#
-# Project created with Qt 5.6.2
-#
-# Compiling BGSLibrary QT GUI with CMAKE
-#
-#-------------------------------------------------
-# Qt 5.x 64-bit for Desktop (MSVC 2015)
-#-------------------------------------------------
-
-mkdir build
-
-cd build
-
-set OpenCV_DIR=C:\OpenCV3.2.0\build
-
-cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 14 Win64" ..
diff --git a/gui_qt/bgslibrary_gui.pro b/gui_qt/bgslibrary_gui.pro
deleted file mode 100644
index ddfd5a5..0000000
--- a/gui_qt/bgslibrary_gui.pro
+++ /dev/null
@@ -1,255 +0,0 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator
-#
-#-------------------------------------------------
-
-QT       += core gui
-
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-
-TARGET = bgslibrary_gui
-TEMPLATE = app
-
-# For Windows x64 + Visual Studio 2015 + OpenCV 3.1.0
-#INCLUDEPATH += C:/OpenCV3.1.0/build/include
-#LIBS += -LC:/OpenCV3.1.0/build/x64/vc14/lib -lopencv_world310
-
-# For Windows x64 + Visual Studio 2015 + OpenCV 3.2.0
-#INCLUDEPATH += C:/OpenCV3.2.0/build/include
-#LIBS += -LC:/OpenCV3.2.0/build/x64/vc14/lib -lopencv_world320
-
-# For Windows x64 + Visual Studio 2017 + OpenCV 3.4.2
-INCLUDEPATH += E:/OpenCV3.4.2/build/include
-INCLUDEPATH += E:/OpenCV3.4.2/build/include/opencv
-LIBS += -LE:/OpenCV3.4.2/build/x64/vc15/lib -lopencv_world342
-
-# For Linux
-# INCLUDEPATH += /usr/local/include/opencv
-# LIBS += -L/usr/local/lib
-
-RESOURCES = application.qrc
-
-SOURCES += bgslibrary_gui.cpp\
-    mainwindow.cpp \
-    qt_utils.cpp \
-    texteditor.cpp \
-    ../package_analysis/ForegroundMaskAnalysis.cpp \
-    ../package_analysis/PerformanceUtils.cpp \
-    ../package_analysis/PixelUtils.cpp \
-    ../package_bgs/_template_/Amber.cpp \
-    ../package_bgs/_template_/MyBGS.cpp \
-    ../package_bgs/dp/AdaptiveMedianBGS.cpp \
-    ../package_bgs/dp/Eigenbackground.cpp \
-    ../package_bgs/dp/Error.cpp \
-    ../package_bgs/dp/GrimsonGMM.cpp \
-    ../package_bgs/dp/Image.cpp \
-    ../package_bgs/dp/MeanBGS.cpp \
-    ../package_bgs/dp/PratiMediodBGS.cpp \
-    ../package_bgs/dp/TextureBGS.cpp \
-    ../package_bgs/dp/WrenGA.cpp \
-    ../package_bgs/dp/ZivkovicAGMM.cpp \
-    ../package_bgs/IMBS/IMBS.cpp \
-    ../package_bgs/KDE/KernelTable.cpp \
-    ../package_bgs/KDE/NPBGmodel.cpp \
-    ../package_bgs/KDE/NPBGSubtractor.cpp \
-    ../package_bgs/lb/BGModel.cpp \
-    ../package_bgs/lb/BGModelFuzzyGauss.cpp \
-    ../package_bgs/lb/BGModelFuzzySom.cpp \
-    ../package_bgs/lb/BGModelGauss.cpp \
-    ../package_bgs/lb/BGModelMog.cpp \
-    ../package_bgs/lb/BGModelSom.cpp \
-    ../package_bgs/LBP_MRF/graph.cpp \
-    ../package_bgs/LBP_MRF/maxflow.cpp \
-    ../package_bgs/LBP_MRF/MEDefs.cpp \
-    ../package_bgs/LBP_MRF/MEHistogram.cpp \
-    ../package_bgs/LBP_MRF/MEImage.cpp \
-    ../package_bgs/LBP_MRF/MotionDetection.cpp \
-    ../package_bgs/LBSP/BackgroundSubtractorLBSP.cpp \
-    ../package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp \
-    ../package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp \
-    ../package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp \
-    ../package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp \
-    ../package_bgs/LBSP/LBSP.cpp \
-    ../package_bgs/LBSP/LBSP_.cpp \
-    ../package_bgs/MultiLayer/blob.cpp \
-    ../package_bgs/MultiLayer/BlobExtraction.cpp \
-    ../package_bgs/MultiLayer/BlobResult.cpp \
-    ../package_bgs/MultiLayer/CMultiLayerBGS.cpp \
-    ../package_bgs/MultiLayer/LocalBinaryPattern.cpp \
-    ../package_bgs/PBAS/PBAS.cpp \
-    ../package_bgs/SigmaDelta/sdLaMa091.cpp \
-    ../package_bgs/T2F/FuzzyUtils.cpp \
-    ../package_bgs/T2F/MRF.cpp \
-    ../package_bgs/T2F/T2FGMM.cpp \
-    ../package_bgs/T2F/T2FMRF.cpp \
-    ../package_bgs/TwoPoints/two_points.cpp \
-    ../package_bgs/ViBe/vibe-background-sequential.cpp \
-    ../package_bgs/VuMeter/TBackground.cpp \
-    ../package_bgs/VuMeter/TBackgroundVuMeter.cpp \
-    ../package_bgs/AdaptiveBackgroundLearning.cpp \
-    ../package_bgs/AdaptiveSelectiveBackgroundLearning.cpp \
-    ../package_bgs/DPAdaptiveMedian.cpp \
-    ../package_bgs/DPEigenbackground.cpp \
-    ../package_bgs/DPGrimsonGMM.cpp \
-    ../package_bgs/DPMean.cpp \
-    ../package_bgs/DPPratiMediod.cpp \
-    ../package_bgs/DPTexture.cpp \
-    ../package_bgs/DPWrenGA.cpp \
-    ../package_bgs/DPZivkovicAGMM.cpp \
-    ../package_bgs/FrameDifference.cpp \
-    ../package_bgs/FuzzyChoquetIntegral.cpp \
-    ../package_bgs/FuzzySugenoIntegral.cpp \
-    ../package_bgs/GMG.cpp \
-    ../package_bgs/IndependentMultimodal.cpp \
-    ../package_bgs/KDE.cpp \
-    ../package_bgs/KNN.cpp \
-    ../package_bgs/LBAdaptiveSOM.cpp \
-    ../package_bgs/LBFuzzyAdaptiveSOM.cpp \
-    ../package_bgs/LBFuzzyGaussian.cpp \
-    ../package_bgs/LBMixtureOfGaussians.cpp \
-    ../package_bgs/LBP_MRF.cpp \
-    ../package_bgs/LBSimpleGaussian.cpp \
-    ../package_bgs/LOBSTER.cpp \
-    ../package_bgs/MixtureOfGaussianV1.cpp \
-    ../package_bgs/MixtureOfGaussianV2.cpp \
-    ../package_bgs/MultiCue.cpp \
-    ../package_bgs/MultiLayer.cpp \
-    ../package_bgs/PAWCS.cpp \
-    ../package_bgs/PixelBasedAdaptiveSegmenter.cpp \
-    ../package_bgs/SigmaDelta.cpp \
-    ../package_bgs/StaticFrameDifference.cpp \
-    ../package_bgs/SuBSENSE.cpp \
-    ../package_bgs/T2FGMM_UM.cpp \
-    ../package_bgs/T2FGMM_UV.cpp \
-    ../package_bgs/T2FMRF_UM.cpp \
-    ../package_bgs/T2FMRF_UV.cpp \
-    ../package_bgs/TwoPoints.cpp \
-    ../package_bgs/ViBe.cpp \
-    ../package_bgs/VuMeter.cpp \
-    ../package_bgs/WeightedMovingMean.cpp \
-    ../package_bgs/WeightedMovingVariance.cpp \
-    ../package_bgs/_template_/amber/amber.cpp \
-    ../package_bgs/CodeBook.cpp
-
-HEADERS  += mainwindow.h \
-    qt_utils.h \
-    texteditor.h \
-    ../package_analysis/ForegroundMaskAnalysis.h \
-    ../package_analysis/PerformanceUtils.h \
-    ../package_analysis/PixelUtils.h \
-    ../package_bgs/_template_/amber/amber.h \
-    ../package_bgs/_template_/Amber.h \
-    ../package_bgs/_template_/MyBGS.h \
-    ../package_bgs/dp/AdaptiveMedianBGS.h \
-    ../package_bgs/dp/Bgs.h \
-    ../package_bgs/dp/BgsParams.h \
-    ../package_bgs/dp/Eigenbackground.h \
-    ../package_bgs/dp/Error.h \
-    ../package_bgs/dp/GrimsonGMM.h \
-    ../package_bgs/dp/Image.h \
-    ../package_bgs/dp/MeanBGS.h \
-    ../package_bgs/dp/PratiMediodBGS.h \
-    ../package_bgs/dp/TextureBGS.h \
-    ../package_bgs/dp/WrenGA.h \
-    ../package_bgs/dp/ZivkovicAGMM.h \
-    ../package_bgs/IMBS/IMBS.hpp \
-    ../package_bgs/KDE/KernelTable.h \
-    ../package_bgs/KDE/NPBGmodel.h \
-    ../package_bgs/KDE/NPBGSubtractor.h \
-    ../package_bgs/lb/BGModel.h \
-    ../package_bgs/lb/BGModelFuzzyGauss.h \
-    ../package_bgs/lb/BGModelFuzzySom.h \
-    ../package_bgs/lb/BGModelGauss.h \
-    ../package_bgs/lb/BGModelMog.h \
-    ../package_bgs/lb/BGModelSom.h \
-    ../package_bgs/lb/Types.h \
-    ../package_bgs/LBP_MRF/block.h \
-    ../package_bgs/LBP_MRF/graph.h \
-    ../package_bgs/LBP_MRF/MEDefs.hpp \
-    ../package_bgs/LBP_MRF/MEHistogram.hpp \
-    ../package_bgs/LBP_MRF/MEImage.hpp \
-    ../package_bgs/LBP_MRF/MotionDetection.hpp \
-    ../package_bgs/LBSP/BackgroundSubtractorLBSP.h \
-    ../package_bgs/LBSP/BackgroundSubtractorLBSP_.h \
-    ../package_bgs/LBSP/BackgroundSubtractorLOBSTER.h \
-    ../package_bgs/LBSP/BackgroundSubtractorPAWCS.h \
-    ../package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h \
-    ../package_bgs/LBSP/DistanceUtils.h \
-    ../package_bgs/LBSP/LBSP.h \
-    ../package_bgs/LBSP/LBSP_.h \
-    ../package_bgs/LBSP/RandUtils.h \
-    ../package_bgs/MultiLayer/BackgroundSubtractionAPI.h \
-    ../package_bgs/MultiLayer/BGS.h \
-    ../package_bgs/MultiLayer/blob.h \
-    ../package_bgs/MultiLayer/BlobExtraction.h \
-    ../package_bgs/MultiLayer/BlobLibraryConfiguration.h \
-    ../package_bgs/MultiLayer/BlobResult.h \
-    ../package_bgs/MultiLayer/CMultiLayerBGS.h \
-    ../package_bgs/MultiLayer/LocalBinaryPattern.h \
-    ../package_bgs/MultiLayer/OpenCvDataConversion.h \
-    ../package_bgs/MultiLayer/OpenCvLegacyIncludes.h \
-    ../package_bgs/PBAS/PBAS.h \
-    ../package_bgs/SigmaDelta/sdLaMa091.h \
-    ../package_bgs/T2F/FuzzyUtils.h \
-    ../package_bgs/T2F/MRF.h \
-    ../package_bgs/T2F/T2FGMM.h \
-    ../package_bgs/T2F/T2FMRF.h \
-    ../package_bgs/TwoPoints/two_points.h \
-    ../package_bgs/ViBe/vibe-background-sequential.h \
-    ../package_bgs/VuMeter/TBackground.h \
-    ../package_bgs/VuMeter/TBackgroundVuMeter.h \
-    ../package_bgs/AdaptiveBackgroundLearning.h \
-    ../package_bgs/AdaptiveSelectiveBackgroundLearning.h \
-    ../package_bgs/bgslibrary.h \
-    ../package_bgs/DPAdaptiveMedian.h \
-    ../package_bgs/DPEigenbackground.h \
-    ../package_bgs/DPGrimsonGMM.h \
-    ../package_bgs/DPMean.h \
-    ../package_bgs/DPPratiMediod.h \
-    ../package_bgs/DPTexture.h \
-    ../package_bgs/DPWrenGA.h \
-    ../package_bgs/DPZivkovicAGMM.h \
-    ../package_bgs/FrameDifference.h \
-    ../package_bgs/FuzzyChoquetIntegral.h \
-    ../package_bgs/FuzzySugenoIntegral.h \
-    ../package_bgs/GMG.h \
-    ../package_bgs/IBGS.h \
-    ../package_bgs/IndependentMultimodal.h \
-    ../package_bgs/KDE.h \
-    ../package_bgs/KNN.h \
-    ../package_bgs/LBAdaptiveSOM.h \
-    ../package_bgs/LBFuzzyAdaptiveSOM.h \
-    ../package_bgs/LBFuzzyGaussian.h \
-    ../package_bgs/LBMixtureOfGaussians.h \
-    ../package_bgs/LBP_MRF.h \
-    ../package_bgs/LBSimpleGaussian.h \
-    ../package_bgs/LOBSTER.h \
-    ../package_bgs/MixtureOfGaussianV1.h \
-    ../package_bgs/MixtureOfGaussianV2.h \
-    ../package_bgs/MultiCue.h \
-    ../package_bgs/MultiLayer.h \
-    ../package_bgs/PAWCS.h \
-    ../package_bgs/PixelBasedAdaptiveSegmenter.h \
-    ../package_bgs/SigmaDelta.h \
-    ../package_bgs/StaticFrameDifference.h \
-    ../package_bgs/SuBSENSE.h \
-    ../package_bgs/T2FGMM_UM.h \
-    ../package_bgs/T2FGMM_UV.h \
-    ../package_bgs/T2FMRF_UM.h \
-    ../package_bgs/T2FMRF_UV.h \
-    ../package_bgs/TwoPoints.h \
-    ../package_bgs/ViBe.h \
-    ../package_bgs/VuMeter.h \
-    ../package_bgs/WeightedMovingMean.h \
-    ../package_bgs/WeightedMovingVariance.h \
-    ../package_bgs/CodeBook.h
-
-FORMS    += mainwindow.ui
-
-DISTFILES += \
-    ../package_bgs/LBSP/LBSP_16bits_dbcross_1ch.i \
-    ../package_bgs/LBSP/LBSP_16bits_dbcross_3ch1t.i \
-    ../package_bgs/LBSP/LBSP_16bits_dbcross_3ch3t.i \
-    ../package_bgs/LBSP/LBSP_16bits_dbcross_s3ch.i \
-    ../package_bgs/ViBe/LICENSE
diff --git a/modules/pybind11 b/modules/pybind11
new file mode 160000
index 0000000..c9d32a8
--- /dev/null
+++ b/modules/pybind11
@@ -0,0 +1 @@
+Subproject commit c9d32a81f40ad540015814edf13b29980c63e39c
diff --git a/package_bgs/AdaptiveBackgroundLearning.h b/package_bgs/AdaptiveBackgroundLearning.h
deleted file mode 100644
index d18114b..0000000
--- a/package_bgs/AdaptiveBackgroundLearning.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class AdaptiveBackgroundLearning : public IBGS
-    {
-    private:
-      double alpha;
-      long limit;
-      long counter;
-      double minVal;
-      double maxVal;
-      bool enableThreshold;
-      int threshold;
-
-    public:
-      AdaptiveBackgroundLearning();
-      ~AdaptiveBackgroundLearning();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<AdaptiveBackgroundLearning> register_AdaptiveBackgroundLearning("AdaptiveBackgroundLearning");
-  }
-}
diff --git a/package_bgs/AdaptiveSelectiveBackgroundLearning.h b/package_bgs/AdaptiveSelectiveBackgroundLearning.h
deleted file mode 100644
index 5f9c98f..0000000
--- a/package_bgs/AdaptiveSelectiveBackgroundLearning.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class AdaptiveSelectiveBackgroundLearning : public IBGS
-    {
-    private:
-      double alphaLearn;
-      double alphaDetection;
-      long learningFrames;
-      long counter;
-      double minVal;
-      double maxVal;
-      int threshold;
-
-    public:
-      AdaptiveSelectiveBackgroundLearning();
-      ~AdaptiveSelectiveBackgroundLearning();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<AdaptiveSelectiveBackgroundLearning> register_AdaptiveSelectiveBackgroundLearning("AdaptiveSelectiveBackgroundLearning");
-  }
-}
diff --git a/package_bgs/FrameDifference.cpp b/package_bgs/FrameDifference.cpp
deleted file mode 100644
index 4d5c076..0000000
--- a/package_bgs/FrameDifference.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "FrameDifference.h"
-
-using namespace bgslibrary::algorithms;
-
-FrameDifference::FrameDifference() :
-  enableThreshold(true), threshold(15)
-{
-  std::cout << "FrameDifference()" << std::endl;
-  setup("./config/FrameDifference.xml");
-}
-
-FrameDifference::~FrameDifference()
-{
-  std::cout << "~FrameDifference()" << std::endl;
-}
-
-void FrameDifference::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  if (img_background.empty())
-  {
-    img_input.copyTo(img_background);
-    return;
-  }
-
-  cv::absdiff(img_background, img_input, img_foreground);
-
-  if (img_foreground.channels() == 3)
-    cv::cvtColor(img_foreground, img_foreground, CV_BGR2GRAY);
-
-  if (enableThreshold)
-    cv::threshold(img_foreground, img_foreground, threshold, 255, cv::THRESH_BINARY);
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-    cv::imshow("Frame Difference", img_foreground);
-#endif
-
-  img_foreground.copyTo(img_output);
-
-  img_input.copyTo(img_background);
-  img_background.copyTo(img_bgmodel);
-
-  firstTime = false;
-}
-
-void FrameDifference::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void FrameDifference::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/FrameDifference.h b/package_bgs/FrameDifference.h
deleted file mode 100644
index 74c22db..0000000
--- a/package_bgs/FrameDifference.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class FrameDifference : public IBGS
-    {
-    private:
-      bool enableThreshold;
-      int threshold;
-
-    public:
-      FrameDifference();
-      ~FrameDifference();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<FrameDifference> register_FrameDifference("FrameDifference");
-  }
-}
-
diff --git a/package_bgs/FuzzyChoquetIntegral.h b/package_bgs/FuzzyChoquetIntegral.h
deleted file mode 100644
index 000e031..0000000
--- a/package_bgs/FuzzyChoquetIntegral.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "T2F/FuzzyUtils.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class FuzzyChoquetIntegral : public IBGS
-    {
-    private:
-      long frameNumber;
-
-      int framesToLearn;
-      double alphaLearn;
-      double alphaUpdate;
-      int colorSpace;
-      int option;
-      bool smooth;
-      double threshold;
-
-      FuzzyUtils fu;
-      cv::Mat img_background_f3;
-
-    public:
-      FuzzyChoquetIntegral();
-      ~FuzzyChoquetIntegral();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<FuzzyChoquetIntegral> register_FuzzyChoquetIntegral("FuzzyChoquetIntegral");
-  }
-}
diff --git a/package_bgs/GMG.h b/package_bgs/GMG.h
deleted file mode 100644
index 40473a5..0000000
--- a/package_bgs/GMG.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "opencv2/core/version.hpp"
-#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
-
-#include "IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class GMG : public IBGS
-    {
-    private:
-      cv::Ptr<cv::BackgroundSubtractorGMG> fgbg;
-      int initializationFrames;
-      double decisionThreshold;
-      cv::Mat img_segmentation;
-
-    public:
-      GMG();
-      ~GMG();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<GMG> register_GMG("GMG");
-  }
-}
-
-#endif
diff --git a/package_bgs/IndependentMultimodal.h b/package_bgs/IndependentMultimodal.h
deleted file mode 100644
index 04eb774..0000000
--- a/package_bgs/IndependentMultimodal.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "IMBS/IMBS.hpp"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class IndependentMultimodal : public IBGS
-    {
-    private:
-      BackgroundSubtractorIMBS* pIMBS;
-      int fps;
-
-    public:
-      IndependentMultimodal();
-      ~IndependentMultimodal();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<IndependentMultimodal> register_IndependentMultimodal("IndependentMultimodal");
-  }
-}
diff --git a/package_bgs/KDE/KernelTable.cpp b/package_bgs/KDE/KernelTable.cpp
deleted file mode 100644
index bd9c368..0000000
--- a/package_bgs/KDE/KernelTable.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*
-* Copyright 2001 by Ahmed Elgammal All  rights reserved.
-*
-* Permission to use, copy,  or modify this software and  its documentation
-* for  educational  and  research purposes only and without fee  is hereby
-* granted, provided  that this copyright notice and the original authors's
-* name appear  on all copies and supporting documentation.  If individual
-* files are  separated from  this  distribution directory  structure, this
-* copyright notice must be included.  For any other uses of this software,
-* in original or  modified form, including but not limited to distribution
-* in whole or in  part, specific  prior permission  must be  obtained from
-* Author or UMIACS.  These programs shall not  be  used, rewritten, or
-* adapted as  the basis  of  a commercial  software  or  hardware product
-* without first obtaining appropriate licenses  from Author.
-* Other than these cases, no part of this software may be used or
-* distributed without written permission of the author.
-*
-* Neither the author nor UMIACS make any representations about the
-* suitability of this software for any purpose.  It is provided
-* "as is" without express or implied warranty.
-*
-* Ahmed Elgammal
-*
-* University of Maryland at College Park
-* UMIACS
-* A.V. Williams Bldg.
-* CollegePark, MD 20742
-* E-mail:  elgammal@umiacs.umd.edu
-*
-**/
-
-#include "KernelTable.h"
-#include <math.h>
-
-#define PI 3.14159
-
-KernelLUTable::KernelLUTable()
-{
-  std::cout << "KernelLUTable()" << std::endl;
-}
-
-KernelLUTable::~KernelLUTable()
-{
-  delete kerneltable;
-  delete kernelsums;
-  std::cout << "~KernelLUTable()" << std::endl;
-}
-
-KernelLUTable::KernelLUTable(int KernelHalfWidth, double Segmamin, double Segmamax, int Segmabins)
-{
-  std::cout << "KernelLUTable()" << std::endl;
-
-  double C1, C2, v, segma, sum;
-  int bin, b;
-
-  minsegma = Segmamin;
-  maxsegma = Segmamax;
-  segmabins = Segmabins;
-  tablehalfwidth = KernelHalfWidth;
-
-  // Generate the Kernel
-
-  // allocate memory for the Kernal Table
-  kerneltable = new double[segmabins*(2 * KernelHalfWidth + 1)];
-  kernelsums = new double[segmabins];
-
-  double segmastep = (maxsegma - minsegma) / segmabins;
-  double y;
-
-  for (segma = minsegma, bin = 0; bin < segmabins; segma += segmastep, bin++)
-  {
-    C1 = 1 / (sqrt(2 * PI)*segma);
-    C2 = -1 / (2 * segma*segma);
-
-    b = (2 * KernelHalfWidth + 1)*bin;
-    sum = 0;
-
-    for (int x = 0; x <= KernelHalfWidth; x++)
-    {
-      y = x / 1.0;
-      v = C1*exp(C2*y*y);
-      kerneltable[b + KernelHalfWidth + x] = v;
-      kerneltable[b + KernelHalfWidth - x] = v;
-      sum += 2 * v;
-    }
-
-    sum -= C1;
-
-    kernelsums[bin] = sum;
-
-    // Normailization
-    for (int x = 0; x <= KernelHalfWidth; x++)
-    {
-      v = kerneltable[b + KernelHalfWidth + x] / sum;
-      kerneltable[b + KernelHalfWidth + x] = v;
-      kerneltable[b + KernelHalfWidth - x] = v;
-    }
-  }
-}
diff --git a/package_bgs/KDE/KernelTable.h b/package_bgs/KDE/KernelTable.h
deleted file mode 100644
index 63a20dc..0000000
--- a/package_bgs/KDE/KernelTable.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*
-* Copyright 2001 by Ahmed Elgammal All  rights reserved.
-*
-* Permission to use, copy,  or modify this software and  its documentation
-* for  educational  and  research purposes only and without fee  is hereby
-* granted, provided  that this copyright notice and the original authors's
-* name appear  on all copies and supporting documentation.  If individual
-* files are  separated from  this  distribution directory  structure, this
-* copyright notice must be included.  For any other uses of this software,
-* in original or  modified form, including but not limited to distribution
-* in whole or in  part, specific  prior permission  must be  obtained from
-* Author or UMIACS.  These programs shall not  be  used, rewritten, or
-* adapted as  the basis  of  a commercial  software  or  hardware product
-* without first obtaining appropriate licenses  from Author.
-* Other than these cases, no part of this software may be used or
-* distributed without written permission of the author.
-*
-* Neither the author nor UMIACS make any representations about the
-* suitability of this software for any purpose.  It is provided
-* "as is" without express or implied warranty.
-*
-* Ahmed Elgammal
-*
-* University of Maryland at College Park
-* UMIACS
-* A.V. Williams Bldg.
-* CollegePark, MD 20742
-* E-mail:  elgammal@umiacs.umd.edu
-*
-**/
-#pragma once
-
-#include <iostream>
-
-class KernelLUTable
-{
-public:
-  double minsegma;
-  double maxsegma;
-  int segmabins;
-  int tablehalfwidth;
-  double *kerneltable;
-  double *kernelsums;
-
-public:
-  KernelLUTable();
-  ~KernelLUTable();
-
-  KernelLUTable(int KernelHalfWidth, double Segmamin, double Segmamax, int Segmabins);
-};
diff --git a/package_bgs/KDE/NPBGSubtractor.h b/package_bgs/KDE/NPBGSubtractor.h
deleted file mode 100644
index ce4bffc..0000000
--- a/package_bgs/KDE/NPBGSubtractor.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*
-* Copyright 2001 by Ahmed Elgammal All  rights reserved.
-*
-* Permission to use, copy,  or modify this software and  its documentation
-* for  educational  and  research purposes only and without fee  is hereby
-* granted, provided  that this copyright notice and the original authors's
-* name appear  on all copies and supporting documentation.  If individual
-* files are  separated from  this  distribution directory  structure, this
-* copyright notice must be included.  For any other uses of this software,
-* in original or  modified form, including but not limited to distribution
-* in whole or in  part, specific  prior permission  must be  obtained from
-* Author or UMIACS.  These programs shall not  be  used, rewritten, or
-* adapted as  the basis  of  a commercial  software  or  hardware product
-* without first obtaining appropriate licenses  from Author.
-* Other than these cases, no part of this software may be used or
-* distributed without written permission of the author.
-*
-* Neither the author nor UMIACS make any representations about the
-* suitability of this software for any purpose.  It is provided
-* "as is" without express or implied warranty.
-*
-* Ahmed Elgammal
-*
-* University of Maryland at College Park
-* UMIACS
-* A.V. Williams Bldg.
-* CollegePark, MD 20742
-* E-mail:  elgammal@umiacs.umd.edu
-*
-**/
-
-// NPBGSubtractor.h: interface for the NPBGSubtractor class.
-//
-//////////////////////////////////////////////////////////////////////
-#pragma once
-
-#include "NPBGmodel.h"
-#include "KernelTable.h"
-
-#define FALSE 0
-#define TRUE 1
-
-// kernal look up table settings
-#define 	KERNELHALFWIDTH 255
-#define 	SEGMAMAX 36.5
-#define	  SEGMAMIN 0.5
-#define		SEGMABINS 80
-#define		DEFAULTSEGMA 1.0
-
-typedef struct
-{
-  unsigned char *Hist;
-  unsigned char *MedianBins;
-  unsigned char *MedianFreq;
-  unsigned char *AccSum;
-  unsigned char histbins;
-  unsigned char histsum;
-  unsigned int  imagesize;
-} DynamicMedianHistogram;
-
-typedef struct
-{
-  unsigned int cnt;
-  unsigned int *List;
-} ImageIndex;
-
-class NPBGSubtractor
-{
-private:
-  unsigned int rows;
-  unsigned int cols;
-  unsigned int color_channels;
-  unsigned int imagesize;
-  // flags
-  unsigned char UpdateBGFlag;
-  unsigned char SdEstimateFlag;
-  unsigned char UseColorRatiosFlag;
-  unsigned char AdaptBGFlag;
-  unsigned char SubsetFlag;
-  //
-  int UpdateSDRate;
-  double Threshold;
-  double AlphaValue;
-  unsigned int TimeIndex;
-  ImageIndex  *imageindex;
-  unsigned char *tempFrame;
-  KernelLUTable *KernelTable;
-  NPBGmodel *BGModel;
-  DynamicMedianHistogram AbsDiffHist;
-  double *Pimage1;
-  double *Pimage2;
-  //
-  void NPBGSubtraction_Subset_Kernel(unsigned char * image, unsigned char * FGImage, unsigned char * FilteredFGImage);
-  void SequenceBGUpdate_Pairs(unsigned char * image, unsigned char * Mask);
-
-public:
-  NPBGSubtractor();
-  virtual ~NPBGSubtractor();
-  //~NPBGSubtractor();
-
-  int Intialize(unsigned int rows,
-    unsigned int cols,
-    unsigned int color_channels,
-    unsigned int SequenceLength,
-    unsigned int TimeWindowSize,
-    unsigned char SDEstimationFlag,
-    unsigned char UseColorRatiosFlag);
-
-  void AddFrame(unsigned char * ImageBuffer);
-
-  void Estimation();
-
-  void NBBGSubtraction(unsigned char *Frame,
-    unsigned char *FGImage,
-    unsigned char *FilteredFGImage,
-    unsigned char **DisplayBuffers);
-
-  void Update(unsigned char *);
-
-  void SetThresholds(double th, double alpha)
-  {
-    Threshold = th;
-    AlphaValue = alpha;
-  };
-
-  void SetUpdateFlag(unsigned int bgflag) {
-    UpdateBGFlag = bgflag;
-  };
-};
diff --git a/package_bgs/KDE/NPBGmodel.cpp b/package_bgs/KDE/NPBGmodel.cpp
deleted file mode 100644
index a79a7b4..0000000
--- a/package_bgs/KDE/NPBGmodel.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*
-* Copyright 2001 by Ahmed Elgammal All  rights reserved.
-*
-* Permission to use, copy,  or modify this software and  its documentation
-* for  educational  and  research purposes only and without fee  is hereby
-* granted, provided  that this copyright notice and the original authors's
-* name appear  on all copies and supporting documentation.  If individual
-* files are  separated from  this  distribution directory  structure, this
-* copyright notice must be included.  For any other uses of this software,
-* in original or  modified form, including but not limited to distribution
-* in whole or in  part, specific  prior permission  must be  obtained from
-* Author or UMIACS.  These programs shall not  be  used, rewritten, or
-* adapted as  the basis  of  a commercial  software  or  hardware product
-* without first obtaining appropriate licenses  from Author.
-* Other than these cases, no part of this software may be used or
-* distributed without written permission of the author.
-*
-* Neither the author nor UMIACS make any representations about the
-* suitability of this software for any purpose.  It is provided
-* "as is" without express or implied warranty.
-*
-* Ahmed Elgammal
-*
-* University of Maryland at College Park
-* UMIACS
-* A.V. Williams Bldg.
-* CollegePark, MD 20742
-* E-mail:  elgammal@umiacs.umd.edu
-*
-**/
-
-// NPBGmodel.cpp: implementation of the NPBGmodel class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "NPBGmodel.h"
-#include "memory.h"
-
-#ifdef _DEBUG
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-//#define new DEBUG_NEW
-#endif
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-NPBGmodel::NPBGmodel()
-{
-  std::cout << "NPBGmodel()" << std::endl;
-}
-
-NPBGmodel::~NPBGmodel()
-{
-  delete Sequence;
-  delete PixelQTop;
-  delete TemporalBuffer;
-  delete TemporalMask;
-  delete AccMask;
-  //delete SDbinsImage;
-  std::cout << "~NPBGmodel()" << std::endl;
-}
-
-NPBGmodel::NPBGmodel(unsigned int Rows,
-  unsigned int Cols,
-  unsigned int ColorChannels,
-  unsigned int Length,
-  unsigned int pTimeWindowSize,
-  unsigned int bg_suppression_time)
-{
-  std::cout << "NPBGmodel()" << std::endl;
-
-  imagesize = Rows*Cols*ColorChannels;
-
-  rows = Rows;
-  cols = Cols;
-  color_channels = ColorChannels;
-
-  SampleSize = Length;
-
-  TimeWindowSize = pTimeWindowSize;
-
-  Sequence = new unsigned char[imagesize*Length];
-  Top = 0;
-  memset(Sequence, 0, imagesize*Length);
-
-  PixelQTop = new unsigned char[rows*cols];
-
-  // temporalBuffer
-  TemporalBufferLength = (TimeWindowSize / Length > 2 ? TimeWindowSize / Length : 2);
-  TemporalBuffer = new unsigned char[imagesize*TemporalBufferLength];
-  TemporalMask = new unsigned char[rows*cols*TemporalBufferLength];
-
-  TemporalBufferTop = 0;
-
-  AccMask = new unsigned int[rows*cols];
-
-  ResetMaskTh = bg_suppression_time;
-}
-
-void NPBGmodel::AddFrame(unsigned char *ImageBuffer)
-{
-  memcpy(Sequence + Top*imagesize, ImageBuffer, imagesize);
-  Top = (Top + 1) % SampleSize;
-
-  memset(PixelQTop, (unsigned char)Top, rows*cols);
-
-  memcpy(TemporalBuffer, ImageBuffer, imagesize);
-}
diff --git a/package_bgs/KDE/NPBGmodel.h b/package_bgs/KDE/NPBGmodel.h
deleted file mode 100644
index ba4a927..0000000
--- a/package_bgs/KDE/NPBGmodel.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*
-* Copyright 2001 by Ahmed Elgammal All  rights reserved.
-*
-* Permission to use, copy,  or modify this software and  its documentation
-* for  educational  and  research purposes only and without fee  is hereby
-* granted, provided  that this copyright notice and the original authors's
-* name appear  on all copies and supporting documentation.  If individual
-* files are  separated from  this  distribution directory  structure, this
-* copyright notice must be included.  For any other uses of this software,
-* in original or  modified form, including but not limited to distribution
-* in whole or in  part, specific  prior permission  must be  obtained from
-* Author or UMIACS.  These programs shall not  be  used, rewritten, or
-* adapted as  the basis  of  a commercial  software  or  hardware product
-* without first obtaining appropriate licenses  from Author.
-* Other than these cases, no part of this software may be used or
-* distributed without written permission of the author.
-*
-* Neither the author nor UMIACS make any representations about the
-* suitability of this software for any purpose.  It is provided
-* "as is" without express or implied warranty.
-*
-* Ahmed Elgammal
-*
-* University of Maryland at College Park
-* UMIACS
-* A.V. Williams Bldg.
-* CollegePark, MD 20742
-* E-mail:  elgammal@umiacs.umd.edu
-*
-**/
-
-// NPBGmodel.h: interface for the NPBGmodel class.
-//
-//////////////////////////////////////////////////////////////////////
-#pragma once
-
-#include <iostream>
-
-class NPBGmodel
-{
-private:
-  unsigned char *Sequence;
-  unsigned int SampleSize;
-  unsigned int TimeWindowSize;
-
-  unsigned int rows, cols, color_channels;
-  unsigned int imagesize;
-
-  unsigned int Top;
-  unsigned char *PixelQTop;
-
-  //unsigned int *PixelUpdateCounter;
-
-  unsigned char *SDbinsImage;
-
-  unsigned char *TemporalBuffer;
-  unsigned char TemporalBufferLength;
-  unsigned char TemporalBufferTop;
-  unsigned char *TemporalBufferMask;
-
-  unsigned char *TemporalMask;
-  unsigned char TemporalMaskLength;
-  unsigned char TemporalMaskTop;
-
-  unsigned int *AccMask;
-  unsigned int ResetMaskTh;	// Max continous duration a pixel can be detected before
-  // it is forced to be updated...
-
-  double *weights;
-
-public:
-  NPBGmodel();
-  //~NPBGmodel();
-  virtual ~NPBGmodel();
-
-  NPBGmodel(unsigned int Rows,
-    unsigned int Cols,
-    unsigned int ColorChannels,
-    unsigned int Length,
-    unsigned int pTimeWindowSize,
-    unsigned int bg_suppression_time);
-
-  void AddFrame(unsigned char *ImageBuffer);
-
-  friend class NPBGSubtractor;
-};
diff --git a/package_bgs/LBAdaptiveSOM.cpp b/package_bgs/LBAdaptiveSOM.cpp
deleted file mode 100644
index 188e11d..0000000
--- a/package_bgs/LBAdaptiveSOM.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "LBAdaptiveSOM.h"
-
-using namespace bgslibrary::algorithms;
-
-LBAdaptiveSOM::LBAdaptiveSOM() :
-  sensitivity(75), trainingSensitivity(245), learningRate(62), trainingLearningRate(255), trainingSteps(55)
-{
-  std::cout << "LBAdaptiveSOM()" << std::endl;
-  setup("./config/LBAdaptiveSOM.xml");
-}
-
-LBAdaptiveSOM::~LBAdaptiveSOM()
-{
-  delete m_pBGModel;
-  std::cout << "~LBAdaptiveSOM()" << std::endl;
-}
-
-void LBAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  IplImage *frame = new IplImage(img_input);
-
-  if (firstTime)
-  {
-    int w = cvGetSize(frame).width;
-    int h = cvGetSize(frame).height;
-
-    m_pBGModel = new BGModelSom(w, h);
-    m_pBGModel->InitModel(frame);
-  }
-
-  m_pBGModel->setBGModelParameter(0, sensitivity);
-  m_pBGModel->setBGModelParameter(1, trainingSensitivity);
-  m_pBGModel->setBGModelParameter(2, learningRate);
-  m_pBGModel->setBGModelParameter(3, trainingLearningRate);
-  m_pBGModel->setBGModelParameter(5, trainingSteps);
-
-  m_pBGModel->UpdateModel(frame);
-
-  img_foreground = cv::cvarrToMat(m_pBGModel->GetFG());
-  img_background = cv::cvarrToMat(m_pBGModel->GetBG());
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-  {
-    cv::imshow("SOM Mask", img_foreground);
-    cv::imshow("SOM Model", img_background);
-  }
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-
-  delete frame;
-
-  firstTime = false;
-}
-
-void LBAdaptiveSOM::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "sensitivity", sensitivity);
-  cvWriteInt(fs, "trainingSensitivity", trainingSensitivity);
-  cvWriteInt(fs, "learningRate", learningRate);
-  cvWriteInt(fs, "trainingLearningRate", trainingLearningRate);
-  cvWriteInt(fs, "trainingSteps", trainingSteps);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void LBAdaptiveSOM::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  sensitivity = cvReadIntByName(fs, nullptr, "sensitivity", 75);
-  trainingSensitivity = cvReadIntByName(fs, nullptr, "trainingSensitivity", 245);
-  learningRate = cvReadIntByName(fs, nullptr, "learningRate", 62);
-  trainingLearningRate = cvReadIntByName(fs, nullptr, "trainingLearningRate", 255);
-  trainingSteps = cvReadIntByName(fs, nullptr, "trainingSteps", 55);
-  showOutput = cvReadIntByName(fs, 0, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/LBAdaptiveSOM.h b/package_bgs/LBAdaptiveSOM.h
deleted file mode 100644
index 25e782b..0000000
--- a/package_bgs/LBAdaptiveSOM.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "lb/BGModelSom.h"
-#include "IBGS.h"
-
-using namespace lb_library;
-using namespace lb_library::AdaptiveSOM;
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class LBAdaptiveSOM : public IBGS
-    {
-    private:
-      BGModel* m_pBGModel;
-      int sensitivity;
-      int trainingSensitivity;
-      int learningRate;
-      int trainingLearningRate;
-      int trainingSteps;
-
-    public:
-      LBAdaptiveSOM();
-      ~LBAdaptiveSOM();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<LBAdaptiveSOM> register_LBAdaptiveSOM("LBAdaptiveSOM");
-  }
-}
diff --git a/package_bgs/LBFuzzyAdaptiveSOM.cpp b/package_bgs/LBFuzzyAdaptiveSOM.cpp
deleted file mode 100644
index 73df1d7..0000000
--- a/package_bgs/LBFuzzyAdaptiveSOM.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "LBFuzzyAdaptiveSOM.h"
-
-using namespace bgslibrary::algorithms;
-
-LBFuzzyAdaptiveSOM::LBFuzzyAdaptiveSOM() :
-  sensitivity(90), trainingSensitivity(240), learningRate(38), trainingLearningRate(255), trainingSteps(81)
-{
-  std::cout << "LBFuzzyAdaptiveSOM()" << std::endl;
-  setup("./config/LBFuzzyAdaptiveSOM.xml");
-}
-
-LBFuzzyAdaptiveSOM::~LBFuzzyAdaptiveSOM()
-{
-  delete m_pBGModel;
-  std::cout << "~LBFuzzyAdaptiveSOM()" << std::endl;
-}
-
-void LBFuzzyAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  IplImage *frame = new IplImage(img_input);
-
-  if (firstTime)
-  {
-    int w = cvGetSize(frame).width;
-    int h = cvGetSize(frame).height;
-
-    m_pBGModel = new BGModelFuzzySom(w, h);
-    m_pBGModel->InitModel(frame);
-  }
-
-  m_pBGModel->setBGModelParameter(0, sensitivity);
-  m_pBGModel->setBGModelParameter(1, trainingSensitivity);
-  m_pBGModel->setBGModelParameter(2, learningRate);
-  m_pBGModel->setBGModelParameter(3, trainingLearningRate);
-  m_pBGModel->setBGModelParameter(5, trainingSteps);
-
-  m_pBGModel->UpdateModel(frame);
-
-  img_foreground = cv::cvarrToMat(m_pBGModel->GetFG());
-  img_background = cv::cvarrToMat(m_pBGModel->GetBG());
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-  {
-    cv::imshow("FSOM Mask", img_foreground);
-    cv::imshow("FSOM Model", img_background);
-  }
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-
-  delete frame;
-
-  firstTime = false;
-}
-
-void LBFuzzyAdaptiveSOM::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "sensitivity", sensitivity);
-  cvWriteInt(fs, "trainingSensitivity", trainingSensitivity);
-  cvWriteInt(fs, "learningRate", learningRate);
-  cvWriteInt(fs, "trainingLearningRate", trainingLearningRate);
-  cvWriteInt(fs, "trainingSteps", trainingSteps);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void LBFuzzyAdaptiveSOM::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  sensitivity = cvReadIntByName(fs, nullptr, "sensitivity", 90);
-  trainingSensitivity = cvReadIntByName(fs, nullptr, "trainingSensitivity", 240);
-  learningRate = cvReadIntByName(fs, nullptr, "learningRate", 38);
-  trainingLearningRate = cvReadIntByName(fs, nullptr, "trainingLearningRate", 255);
-  trainingSteps = cvReadIntByName(fs, nullptr, "trainingSteps", 81);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/LBFuzzyGaussian.h b/package_bgs/LBFuzzyGaussian.h
deleted file mode 100644
index 3954fdb..0000000
--- a/package_bgs/LBFuzzyGaussian.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "lb/BGModelFuzzyGauss.h"
-
-using namespace lb_library;
-using namespace lb_library::FuzzyGaussian;
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class LBFuzzyGaussian : public IBGS
-    {
-    private:
-      BGModel* m_pBGModel;
-      int sensitivity;
-      int bgThreshold;
-      int learningRate;
-      int noiseVariance;
-
-    public:
-      LBFuzzyGaussian();
-      ~LBFuzzyGaussian();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<LBFuzzyGaussian> register_LBFuzzyGaussian("LBFuzzyGaussian");
-  }
-}
diff --git a/package_bgs/LBMixtureOfGaussians.h b/package_bgs/LBMixtureOfGaussians.h
deleted file mode 100644
index 6de35d8..0000000
--- a/package_bgs/LBMixtureOfGaussians.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "lb/BGModelMog.h"
-
-using namespace lb_library;
-using namespace lb_library::MixtureOfGaussians;
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class LBMixtureOfGaussians : public IBGS
-    {
-    private:
-      BGModel* m_pBGModel;
-      int sensitivity;
-      int bgThreshold;
-      int learningRate;
-      int noiseVariance;
-
-    public:
-      LBMixtureOfGaussians();
-      ~LBMixtureOfGaussians();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<LBMixtureOfGaussians> register_LBMixtureOfGaussians("LBMixtureOfGaussians");
-  }
-}
-
diff --git a/package_bgs/LBP_MRF.h b/package_bgs/LBP_MRF.h
deleted file mode 100644
index 0479ddd..0000000
--- a/package_bgs/LBP_MRF.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "LBP_MRF/MotionDetection.hpp"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class LBP_MRF : public IBGS
-    {
-    private:
-      MotionDetection* Detector;
-      cv::Mat img_segmentation;
-
-    public:
-      LBP_MRF();
-      ~LBP_MRF();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<LBP_MRF> register_LBP_MRF("LBP_MRF");
-  }
-}
diff --git a/package_bgs/LBP_MRF/MEDefs.cpp b/package_bgs/LBP_MRF/MEDefs.cpp
deleted file mode 100644
index 95b8033..0000000
--- a/package_bgs/LBP_MRF/MEDefs.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-#include "MEDefs.hpp"
-
-#include <math.h>
-
-float MERound(float number)
-{
-  double FracPart = 0.0;
-  double IntPart = 0.0;
-  float Ret = 0.0;
-
-  FracPart = modf((double)number, &IntPart);
-  if (number >= 0)
-  {
-    Ret = (float)(FracPart >= 0.5 ? IntPart + 1 : IntPart);
-  }
-  else {
-    Ret = (float)(FracPart <= -0.5 ? IntPart - 1 : IntPart);
-  }
-  return Ret;
-}
diff --git a/package_bgs/LBP_MRF/MEDefs.hpp b/package_bgs/LBP_MRF/MEDefs.hpp
deleted file mode 100644
index a886ee9..0000000
--- a/package_bgs/LBP_MRF/MEDefs.hpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-#pragma once
-
- /// Pi value
-#ifndef ME_PI_VALUE
-#define ME_PI_VALUE 3.14159265
-#endif
-
-/*! Process state */
-typedef enum {
-  ps_Min = 0,                /*!< Minimum value */
-  ps_Uninitialized = ps_Min, /*!< Uninitialized state */
-  ps_Initialized,            /*!< Initialized state */
-  ps_InProgress,             /*!< In progress state */
-  ps_Successful,             /*!< Successful state */
-  ps_Max = ps_Successful     /*!< Maximum value */
-} MEProcessStateType;
-
-template <typename T>
-const T& MEMin(const T& a, const T& b)
-{
-  if (a < b)
-    return a;
-  return b;
-}
-
-template <typename T>
-const T& MEMax(const T& a, const T& b)
-{
-  if (a < b)
-    return b;
-  return a;
-}
-
-template <typename T>
-const T& MEBound(const T& min, const T& val, const T& max)
-{
-  return MEMax(min, MEMin(max, val));
-}
-
-/*!
- * @brief Round a float number
- *
- * @param number number to round
- *
- * @return New float number
- *
- * This method rounds a float number, if the fraction is .5 or lower
- * then it rounds down, otherwise up.
- *
- */
-
-float MERound(float number);
-
-/** @} */
diff --git a/package_bgs/LBP_MRF/block.h b/package_bgs/LBP_MRF/block.h
deleted file mode 100644
index bd1ab67..0000000
--- a/package_bgs/LBP_MRF/block.h
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* block.h */
-/*
-    Copyright 2001 Vladimir Kolmogorov (vnk@cs.cornell.edu), Yuri Boykov (yuri@csd.uwo.ca).
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-    */
-/*
-  Template classes Block and DBlock
-  Implement adding and deleting items of the same type in blocks.
-
-  If there there are many items then using Block or DBlock
-  is more efficient than using 'new' and 'delete' both in terms
-  of memory and time since
-  (1) On some systems there is some minimum amount of memory
-  that 'new' can allocate (e.g., 64), so if items are
-  small that a lot of memory is wasted.
-  (2) 'new' and 'delete' are designed for items of varying size.
-  If all items has the same size, then an algorithm for
-  adding and deleting can be made more efficient.
-  (3) All Block and DBlock functions are inline, so there are
-  no extra function calls.
-
-  Differences between Block and DBlock:
-  (1) DBlock allows both adding and deleting items,
-  whereas Block allows only adding items.
-  (2) Block has an additional operation of scanning
-  items added so far (in the order in which they were added).
-  (3) Block allows to allocate several consecutive
-  items at a time, whereas DBlock can add only a single item.
-
-  Note that no constructors or destructors are called for items.
-
-  Example usage for items of type 'MyType':
-
-  ///////////////////////////////////////////////////
-  #include "block.h"
-  #define BLOCK_SIZE 1024
-  typedef struct { int a, b; } MyType;
-  MyType *ptr, *array[10000];
-
-  ...
-
-  Block<MyType> *block = new Block<MyType>(BLOCK_SIZE);
-
-  // adding items
-  for (int i=0; i<sizeof(array); i++)
-  {
-  ptr = block -> New();
-  ptr -> a = ptr -> b = rand();
-  }
-
-  // reading items
-  for (ptr=block->ScanFirst(); ptr; ptr=block->ScanNext())
-  {
-  printf("%d %d\n", ptr->a, ptr->b);
-  }
-
-  delete block;
-
-  ...
-
-  DBlock<MyType> *dblock = new DBlock<MyType>(BLOCK_SIZE);
-
-  // adding items
-  for (int i=0; i<sizeof(array); i++)
-  {
-  array[i] = dblock -> New();
-  }
-
-  // deleting items
-  for (int i=0; i<sizeof(array); i+=2)
-  {
-  dblock -> Delete(array[i]);
-  }
-
-  // adding items
-  for (int i=0; i<sizeof(array); i++)
-  {
-  array[i] = dblock -> New();
-  }
-
-  delete dblock;
-
-  ///////////////////////////////////////////////////
-
-  Note that DBlock deletes items by marking them as
-  empty (i.e., by adding them to the list of free items),
-  so that this memory could be used for subsequently
-  added items. Thus, at each moment the memory allocated
-  is determined by the maximum number of items allocated
-  simultaneously at earlier moments. All memory is
-  deallocated only when the destructor is called.
-  */
-#pragma once
-
-#include <stdlib.h>
-#include <stdio.h>
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-namespace ck
-{
-template <class Type> class Block
-{
-public:
-  /* Constructor. Arguments are the block size and
-       (optionally) the pointer to the function which
-       will be called if allocation failed; the message
-       passed to this function is "Not enough memory!" */
-  Block(int size, void(*err_function)(char *) = NULL) { first = last = NULL; block_size = size; error_function = err_function; }
-
-  /* Destructor. Deallocates all items added so far */
-  ~Block() { while (first) { block *next = first->next; delete first; first = next; } }
-
-  /* Allocates 'num' consecutive items; returns pointer
-       to the first item. 'num' cannot be greater than the
-       block size since items must fit in one block */
-  Type *New(int num = 1)
-  {
-    Type *t;
-
-    if (!last || last->current + num > last->last)
-    {
-      if (last && last->next) last = last->next;
-      else
-      {
-        block *next = (block *) new char[sizeof(block) + (block_size - 1)*sizeof(Type)];
-        if (!next) { fprintf(stderr, "Not enough memory!"); exit(1); }
-        if (last) last->next = next;
-        else first = next;
-        last = next;
-        last->current = &(last->data[0]);
-        last->last = last->current + block_size;
-        last->next = NULL;
-      }
-    }
-
-    t = last->current;
-    last->current += num;
-    return t;
-  }
-
-  /* Returns the first item (or NULL, if no items were added) */
-  Type *ScanFirst()
-  {
-    scan_current_block = first;
-    if (!scan_current_block) return NULL;
-    scan_current_data = &(scan_current_block->data[0]);
-    return scan_current_data++;
-  }
-
-  /* Returns the next item (or NULL, if all items have been read)
-       Can be called only if previous ScanFirst() or ScanNext()
-       call returned not NULL. */
-  Type *ScanNext()
-  {
-    if (scan_current_data >= scan_current_block->current)
-    {
-      scan_current_block = scan_current_block->next;
-      if (!scan_current_block) return NULL;
-      scan_current_data = &(scan_current_block->data[0]);
-    }
-    return scan_current_data++;
-  }
-
-  /* Marks all elements as empty */
-  void Reset()
-  {
-    block *b;
-    if (!first) return;
-    for (b = first;; b = b->next)
-    {
-      b->current = &(b->data[0]);
-      if (b == last) break;
-    }
-    last = first;
-  }
-
-  /***********************************************************************/
-
-private:
-
-  typedef struct block_st
-  {
-    Type					*current, *last;
-    struct block_st			*next;
-    Type					data[1];
-  } block;
-
-  int		block_size;
-  block	*first;
-  block	*last;
-
-  block	*scan_current_block;
-  Type	*scan_current_data;
-
-  void(*error_function)(char *);
-};
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-template <class Type> class DBlock
-{
-public:
-  /* Constructor. Arguments are the block size and
-       (optionally) the pointer to the function which
-       will be called if allocation failed; the message
-       passed to this function is "Not enough memory!" */
-  DBlock(int size, void(*err_function)(char *) = NULL) { first = NULL; first_free = NULL; block_size = size; error_function = err_function; }
-
-  /* Destructor. Deallocates all items added so far */
-  ~DBlock() { while (first) { block *next = first->next; delete first; first = next; } }
-
-  /* Allocates one item */
-  Type *New()
-  {
-    block_item *item;
-
-    if (!first_free)
-    {
-      block *next = first;
-      first = (block *) new char[sizeof(block) + (block_size - 1)*sizeof(block_item)];
-      if (!first) { fprintf(stderr, "Not enough memory!"); exit(1); }
-      first_free = &(first->data[0]);
-      for (item = first_free; item < first_free + block_size - 1; item++)
-        item->next_free = item + 1;
-      item->next_free = NULL;
-      first->next = next;
-    }
-
-    item = first_free;
-    first_free = item->next_free;
-    return (Type *)item;
-  }
-
-  /* Deletes an item allocated previously */
-  void Delete(Type *t)
-  {
-    ((block_item *)t)->next_free = first_free;
-    first_free = (block_item *)t;
-  }
-
-  /***********************************************************************/
-
-private:
-
-  typedef union block_item_st
-  {
-    Type			t;
-    block_item_st	*next_free;
-  } block_item;
-
-  typedef struct block_st
-  {
-    struct block_st			*next;
-    block_item				data[1];
-  } block;
-
-  int			block_size;
-  block		*first;
-  block_item	*first_free;
-
-  void(*error_function)(char *);
-};
-}
diff --git a/package_bgs/LBP_MRF/graph.cpp b/package_bgs/LBP_MRF/graph.cpp
deleted file mode 100644
index 4db8829..0000000
--- a/package_bgs/LBP_MRF/graph.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* graph.cpp */
-/*
-    Copyright 2001 Vladimir Kolmogorov (vnk@cs.cornell.edu), Yuri Boykov (yuri@csd.uwo.ca).
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-    */
-
-
-#include <stdio.h>
-#include "graph.h"
-
-namespace ck
-{
-  Graph::Graph(void(*err_function)(char *))
-  {
-    error_function = err_function;
-    node_block = new Block<node>(NODE_BLOCK_SIZE, error_function);
-    arc_block = new Block<arc>(NODE_BLOCK_SIZE, error_function);
-    flow = 0;
-  }
-
-  Graph::~Graph()
-  {
-    delete node_block;
-    delete arc_block;
-  }
-
-  Graph::node_id Graph::add_node()
-  {
-    node *i = node_block->New();
-
-    i->first = NULL;
-    i->tr_cap = 0;
-
-    return (node_id)i;
-  }
-
-  void Graph::add_edge(node_id from, node_id to, captype cap, captype rev_cap)
-  {
-    arc *a, *a_rev;
-
-    a = arc_block->New(2);
-    a_rev = a + 1;
-
-    a->sister = a_rev;
-    a_rev->sister = a;
-    a->next = ((node*)from)->first;
-    ((node*)from)->first = a;
-    a_rev->next = ((node*)to)->first;
-    ((node*)to)->first = a_rev;
-    a->head = (node*)to;
-    a_rev->head = (node*)from;
-    a->r_cap = cap;
-    a_rev->r_cap = rev_cap;
-  }
-
-  void Graph::set_tweights(node_id i, captype cap_source, captype cap_sink)
-  {
-    flow += (cap_source < cap_sink) ? cap_source : cap_sink;
-    ((node*)i)->tr_cap = cap_source - cap_sink;
-  }
-
-  void Graph::add_tweights(node_id i, captype cap_source, captype cap_sink)
-  {
-    register captype delta = ((node*)i)->tr_cap; // 'register' storage class specifier is deprecated and incompatible with C++17
-    if (delta > 0) cap_source += delta;
-    else           cap_sink -= delta;
-    flow += (cap_source < cap_sink) ? cap_source : cap_sink;
-    ((node*)i)->tr_cap = cap_source - cap_sink;
-  }
-}
diff --git a/package_bgs/LBSimpleGaussian.h b/package_bgs/LBSimpleGaussian.h
deleted file mode 100644
index 4a9b2af..0000000
--- a/package_bgs/LBSimpleGaussian.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "lb/BGModelGauss.h"
-
-using namespace lb_library;
-using namespace lb_library::SimpleGaussian;
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class LBSimpleGaussian : public IBGS
-    {
-    private:
-      BGModel* m_pBGModel;
-      int sensitivity;
-      int noiseVariance;
-      int learningRate;
-
-    public:
-      LBSimpleGaussian();
-      ~LBSimpleGaussian();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<LBSimpleGaussian> register_LBSimpleGaussian("LBSimpleGaussian");
-  }
-}
diff --git a/package_bgs/LOBSTER.cpp b/package_bgs/LOBSTER.cpp
deleted file mode 100644
index dc48a63..0000000
--- a/package_bgs/LOBSTER.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "LOBSTER.h"
-
-using namespace bgslibrary::algorithms;
-
-LOBSTER::LOBSTER() :
-  pLOBSTER(nullptr),
-  fRelLBSPThreshold(BGSLOBSTER_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD),
-  nLBSPThresholdOffset(BGSLOBSTER_DEFAULT_LBSP_OFFSET_SIMILARITY_THRESHOLD),
-  nDescDistThreshold(BGSLOBSTER_DEFAULT_DESC_DIST_THRESHOLD),
-  nColorDistThreshold(BGSLOBSTER_DEFAULT_COLOR_DIST_THRESHOLD),
-  nBGSamples(BGSLOBSTER_DEFAULT_NB_BG_SAMPLES),
-  nRequiredBGSamples(BGSLOBSTER_DEFAULT_REQUIRED_NB_BG_SAMPLES)
-{
-  std::cout << "LOBSTER()" << std::endl;
-  setup("./config/LOBSTER.xml");
-}
-
-LOBSTER::~LOBSTER()
-{
-  if (pLOBSTER)
-    delete pLOBSTER;
-  std::cout << "~LOBSTER()" << std::endl;
-}
-
-void LOBSTER::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  if (firstTime)
-  {
-    pLOBSTER = new BackgroundSubtractorLOBSTER(
-      fRelLBSPThreshold, nLBSPThresholdOffset, nDescDistThreshold,
-      nColorDistThreshold, nBGSamples, nRequiredBGSamples);
-
-    pLOBSTER->initialize(img_input, cv::Mat(img_input.size(), CV_8UC1, cv::Scalar_<uchar>(255)));
-    firstTime = false;
-  }
-
-  pLOBSTER->apply(img_input, img_foreground);
-  pLOBSTER->getBackgroundImage(img_background);
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-  {
-    imshow("LOBSTER FG", img_foreground);
-    imshow("LOBSTER BG", img_background);
-  }
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-}
-
-void LOBSTER::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "fRelLBSPThreshold", fRelLBSPThreshold);
-  cvWriteInt(fs, "nLBSPThresholdOffset", nLBSPThresholdOffset);
-  cvWriteInt(fs, "nDescDistThreshold", nDescDistThreshold);
-  cvWriteInt(fs, "nColorDistThreshold", nColorDistThreshold);
-  cvWriteInt(fs, "nBGSamples", nBGSamples);
-  cvWriteInt(fs, "nRequiredBGSamples", nRequiredBGSamples);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void LOBSTER::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  fRelLBSPThreshold = cvReadRealByName(fs, nullptr, "fRelLBSPThreshold", BGSLOBSTER_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD);
-  nLBSPThresholdOffset = cvReadIntByName(fs, nullptr, "nLBSPThresholdOffset", BGSLOBSTER_DEFAULT_LBSP_OFFSET_SIMILARITY_THRESHOLD);
-  nDescDistThreshold = cvReadIntByName(fs, nullptr, "nDescDistThreshold", BGSLOBSTER_DEFAULT_DESC_DIST_THRESHOLD);
-  nColorDistThreshold = cvReadIntByName(fs, nullptr, "nColorDistThreshold", BGSLOBSTER_DEFAULT_COLOR_DIST_THRESHOLD);
-  nBGSamples = cvReadIntByName(fs, nullptr, "nBGSamples", BGSLOBSTER_DEFAULT_NB_BG_SAMPLES);
-  nRequiredBGSamples = cvReadIntByName(fs, nullptr, "nRequiredBGSamples", BGSLOBSTER_DEFAULT_REQUIRED_NB_BG_SAMPLES);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/LOBSTER.h b/package_bgs/LOBSTER.h
deleted file mode 100644
index 8f0de18..0000000
--- a/package_bgs/LOBSTER.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "LBSP/BackgroundSubtractorLOBSTER.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class LOBSTER : public IBGS
-    {
-    private:
-      BackgroundSubtractorLOBSTER* pLOBSTER;
-
-      float fRelLBSPThreshold;
-      size_t nLBSPThresholdOffset;
-      size_t nDescDistThreshold;
-      size_t nColorDistThreshold;
-      size_t nBGSamples;
-      size_t nRequiredBGSamples;
-
-    public:
-      LOBSTER();
-      ~LOBSTER();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<LOBSTER> register_LOBSTER("LOBSTER");
-  }
-}
diff --git a/package_bgs/MultiLayer/BlobExtraction.h b/package_bgs/MultiLayer/BlobExtraction.h
deleted file mode 100644
index d8bd1af..0000000
--- a/package_bgs/MultiLayer/BlobExtraction.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-//***********************************************************//
-//* Blob analysis package  8 August 2003                    *//
-//* Version 1.0                                             *//
-//* Input: IplImage* binary image                           *//
-//* Output: attributes of each connected region             *//
-//* Author: Dave Grossman                                   *//
-//* Email: dgrossman@cdr.stanford.edu                       *//
-//* Acknowledgement: the algorithm has been around > 20 yrs *//
-//***********************************************************//
-#pragma once
-
-namespace Blob
-{
-
-  //! Extreu els blobs d'una imatge
-  bool BlobAnalysis(IplImage* inputImage, uchar threshold, IplImage* maskImage,
-    bool borderColor, bool findmoments, blob_vector &RegionData);
-
-
-  // FUNCIONS AUXILIARS
-
-  //! Fusiona dos blobs
-  void Subsume(blob_vector &RegionData, int, int*, CBlob*, CBlob*, bool, int, int);
-  //! Reallocata el vector auxiliar de blobs subsumats
-  int *NewSubsume(int *SubSumedRegion, int elems_inbuffer);
-  //! Retorna el perimetre extern d'una run lenght
-  double GetExternPerimeter(int start, int end, int row, int width, int height, IplImage *maskImage);
-}
diff --git a/package_bgs/MultiLayer/BlobLibraryConfiguration.h b/package_bgs/MultiLayer/BlobLibraryConfiguration.h
deleted file mode 100644
index 0ba18fc..0000000
--- a/package_bgs/MultiLayer/BlobLibraryConfiguration.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-/************************************************************************
-BlobLibraryConfiguration.h
-
-FUNCIONALITAT: Configuració del comportament global de la llibreria
-AUTOR: Inspecta S.L.
-MODIFICACIONS (Modificació, Autor, Data):
-
-FUNCTIONALITY: Global configuration of the library
-AUTHOR: Inspecta S.L.
-MODIFICATIONS (Modification, Author, Date):
-
-**************************************************************************/
-#pragma once
-
-//! Indica si es volen fer servir les MatrixCV o no
-//! Use/Not use the MatrixCV class
-//#define MATRIXCV_ACTIU
-
-// Uses/not use the blob object factory
-//#define BLOB_OBJECT_FACTORY
-
diff --git a/package_bgs/MultiLayer/LocalBinaryPattern.h b/package_bgs/MultiLayer/LocalBinaryPattern.h
deleted file mode 100644
index 460f994..0000000
--- a/package_bgs/MultiLayer/LocalBinaryPattern.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-// LocalBinaryPattern.h: interface for the CLocalBinaryPattern class.
-//
-//////////////////////////////////////////////////////////////////////
-#pragma once
-
-#include "OpenCvLegacyIncludes.h"
-#include "BGS.h"
-
-
-/************************************************************************/
-/* two types of computing the LBP operators but currently GENERAL_LBP   */
-/* has been implemented.                                                */
-/************************************************************************/
-#define	GENERAL_LBP	0
-#define SYMMETRIC_LBP	1
-
-#include <cstdio>						// C I/O (for sscanf)
-#include "OpenCvDataConversion.h"
-
-
-class CLocalBinaryPattern
-{
-public:
-  void CalImageDifferenceMap(IplImage *cent_img, IplImage *neig_img, float *pattern, CvRect *roi = NULL);
-  void CalNeigPixelOffset(float radius, int tot_neig_pts_num, int neig_pt_idx, int &offset_x, int &offset_y);
-  void CalShiftedImage(IplImage *src, int offset_x, int offset_y, IplImage *dst, CvRect *roi = NULL);
-  void FreeMemories();
-  void ComputeLBP(PixelLBPStruct *PLBP, CvRect *roi = NULL);
-  void SetNewImages(IplImage **new_imgs);
-
-  IplImage** m_ppOrgImgs;			/* the original images used for computing the LBP operators */
-
-  void Initialization(IplImage **first_imgs, int imgs_num,
-    int level_num, float *radius, int *neig_pt_num,
-    float robust_white_noise = 3.0f, int type = GENERAL_LBP);
-
-  CLocalBinaryPattern();
-  virtual ~CLocalBinaryPattern();
-
-  float	m_fRobustWhiteNoise;		/* the robust noise value for computing the LBP operator in each channel */
-
-private:
-  void SetShiftedMeshGrid(CvSize img_size, float offset_x, float offset_y, CvMat *grid_map_x, CvMat *grid_map_y);
-
-  float*	m_pRadiuses;			/* the circle radiuses for the LBP operator */
-  //int	m_nLBPType;			/* the type of computing LBP operator */
-  int*	m_pNeigPointsNums;		/* the numbers of neighboring pixels on multi-level circles */
-  int	m_nImgsNum;			/* the number of multi-channel image */
-  int	m_nLBPLevelNum;			/* the number of multi-level LBP operator */
-  CvSize	m_cvImgSize;			/* the image size (width, height) */
-
-  CvPoint* m_pXYShifts;
-  CvPoint	m_nMaxShift;
-
-  IplImage* m_pShiftedImg;
-};
diff --git a/package_bgs/MultiLayer/OpenCvLegacyIncludes.h b/package_bgs/MultiLayer/OpenCvLegacyIncludes.h
deleted file mode 100644
index 9d30c0e..0000000
--- a/package_bgs/MultiLayer/OpenCvLegacyIncludes.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-// OpenCvLegacyIncludes.h: necessary includes to compile with OpenCV 3.
-//
-//////////////////////////////////////////////////////////////////////
-#pragma once
-
-#include "opencv2/core/core_c.h"
-#include "opencv2/core/types_c.h"
-#include "opencv2/imgproc/imgproc_c.h"
diff --git a/package_bgs/PAWCS.cpp b/package_bgs/PAWCS.cpp
deleted file mode 100644
index 908b3ae..0000000
--- a/package_bgs/PAWCS.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "PAWCS.h"
-
-using namespace bgslibrary::algorithms;
-
-PAWCS::PAWCS() : pPAWCS(nullptr),
-fRelLBSPThreshold(BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD),
-nDescDistThresholdOffset(BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET),
-nMinColorDistThreshold(BGSPAWCS_DEFAULT_MIN_COLOR_DIST_THRESHOLD),
-nMaxNbWords(BGSPAWCS_DEFAULT_MAX_NB_WORDS),
-nSamplesForMovingAvgs(BGSPAWCS_DEFAULT_N_SAMPLES_FOR_MV_AVGS)
-{
-  std::cout << "PAWCS()" << std::endl;
-  setup("./config/PAWCS.xml");
-}
-PAWCS::~PAWCS()
-{
-  if (pPAWCS)
-    delete pPAWCS;
-  std::cout << "~PAWCS()" << std::endl;
-}
-
-void PAWCS::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  if (firstTime)
-  {
-    pPAWCS = new BackgroundSubtractorPAWCS(
-      fRelLBSPThreshold, nDescDistThresholdOffset, nMinColorDistThreshold,
-      nMaxNbWords, nSamplesForMovingAvgs);
-
-    pPAWCS->initialize(img_input, cv::Mat(img_input.size(), CV_8UC1, cv::Scalar_<uchar>(255)));
-    firstTime = false;
-  }
-
-  pPAWCS->apply(img_input, img_foreground);
-  pPAWCS->getBackgroundImage(img_background);
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-  {
-    imshow("PAWCS FG", img_foreground);
-    imshow("PAWCS BG", img_background);
-  }
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-}
-
-void PAWCS::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "fRelLBSPThreshold", fRelLBSPThreshold);
-  cvWriteInt(fs, "nDescDistThresholdOffset", nDescDistThresholdOffset);
-  cvWriteInt(fs, "nMinColorDistThreshold", nMinColorDistThreshold);
-  cvWriteInt(fs, "nMaxNbWords", nMaxNbWords);
-  cvWriteInt(fs, "nSamplesForMovingAvgs", nSamplesForMovingAvgs);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void PAWCS::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  fRelLBSPThreshold = cvReadRealByName(fs, nullptr, "fRelLBSPThreshold", BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD);
-  nDescDistThresholdOffset = cvReadIntByName(fs, nullptr, "nDescDistThresholdOffset", BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET);
-  nMinColorDistThreshold = cvReadIntByName(fs, nullptr, "nMinColorDistThreshold", BGSPAWCS_DEFAULT_MIN_COLOR_DIST_THRESHOLD);
-  nMaxNbWords = cvReadIntByName(fs, nullptr, "nMaxNbWords", BGSPAWCS_DEFAULT_MAX_NB_WORDS);
-  nSamplesForMovingAvgs = cvReadIntByName(fs, nullptr, "nSamplesForMovingAvgs", BGSPAWCS_DEFAULT_N_SAMPLES_FOR_MV_AVGS);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/PAWCS.h b/package_bgs/PAWCS.h
deleted file mode 100644
index bf37891..0000000
--- a/package_bgs/PAWCS.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "LBSP/BackgroundSubtractorPAWCS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class PAWCS : public IBGS
-    {
-    private:
-      BackgroundSubtractorPAWCS* pPAWCS;
-
-      float fRelLBSPThreshold;
-      size_t nDescDistThresholdOffset;
-      size_t nMinColorDistThreshold;
-      size_t nMaxNbWords;
-      size_t nSamplesForMovingAvgs;
-
-    public:
-      PAWCS();
-      ~PAWCS();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<PAWCS> register_PAWCS("PAWCS");
-  }
-}
diff --git a/package_bgs/PixelBasedAdaptiveSegmenter.cpp b/package_bgs/PixelBasedAdaptiveSegmenter.cpp
deleted file mode 100644
index 8a3de97..0000000
--- a/package_bgs/PixelBasedAdaptiveSegmenter.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "PixelBasedAdaptiveSegmenter.h"
-
-using namespace bgslibrary::algorithms;
-
-PixelBasedAdaptiveSegmenter::PixelBasedAdaptiveSegmenter() :
-  enableInputBlur(true), enableOutputBlur(true),
-  alpha(7.0), beta(1.0), N(20), Raute_min(2), R_incdec(0.05), R_lower(18),
-  R_scale(5), T_dec(0.05), T_inc(1), T_init(18), T_lower(2), T_upper(200)
-{
-  std::cout << "PixelBasedAdaptiveSegmenter()" << std::endl;
-  setup("./config/PixelBasedAdaptiveSegmenter.xml");
-}
-
-PixelBasedAdaptiveSegmenter::~PixelBasedAdaptiveSegmenter()
-{
-  std::cout << "~PixelBasedAdaptiveSegmenter()" << std::endl;
-}
-
-void PixelBasedAdaptiveSegmenter::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  if (firstTime)
-  {
-    pbas.setAlpha(alpha);
-    pbas.setBeta(beta);
-    pbas.setN(N);
-    pbas.setRaute_min(Raute_min);
-    pbas.setR_incdec(R_incdec);
-    pbas.setR_lower(R_lower);
-    pbas.setR_scale(R_scale);
-    pbas.setT_dec(T_dec);
-    pbas.setT_inc(T_inc);
-    pbas.setT_init(T_init);
-    pbas.setT_lower(T_lower);
-    pbas.setT_upper(T_upper);
-  }
-
-  cv::Mat img_input_new;
-  if (enableInputBlur)
-    cv::GaussianBlur(img_input, img_input_new, cv::Size(5, 5), 1.5);
-  else
-    img_input.copyTo(img_input_new);
-
-  pbas.process(&img_input_new, &img_foreground);
-  img_background = cv::Mat::zeros(img_input.size(), img_input.type());
-
-  if (enableOutputBlur)
-    cv::medianBlur(img_foreground, img_foreground, 5);
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-    cv::imshow("PBAS", img_foreground);
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-
-  firstTime = false;
-}
-
-void PixelBasedAdaptiveSegmenter::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "enableInputBlur", enableInputBlur);
-  cvWriteInt(fs, "enableOutputBlur", enableOutputBlur);
-
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteReal(fs, "beta", beta);
-  cvWriteInt(fs, "N", N);
-  cvWriteInt(fs, "Raute_min", Raute_min);
-  cvWriteReal(fs, "R_incdec", R_incdec);
-  cvWriteInt(fs, "R_lower", R_lower);
-  cvWriteInt(fs, "R_scale", R_scale);
-  cvWriteReal(fs, "T_dec", T_dec);
-  cvWriteInt(fs, "T_inc", T_inc);
-  cvWriteInt(fs, "T_init", T_init);
-  cvWriteInt(fs, "T_lower", T_lower);
-  cvWriteInt(fs, "T_upper", T_upper);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void PixelBasedAdaptiveSegmenter::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  enableInputBlur = cvReadIntByName(fs, nullptr, "enableInputBlur", true);
-  enableOutputBlur = cvReadIntByName(fs, nullptr, "enableOutputBlur", true);
-
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 7.0);
-  beta = cvReadRealByName(fs, nullptr, "beta", 1.0);
-  N = cvReadIntByName(fs, nullptr, "N", 20);
-  Raute_min = cvReadIntByName(fs, nullptr, "Raute_min", 2);
-  R_incdec = cvReadRealByName(fs, nullptr, "R_incdec", 0.05);
-  R_lower = cvReadIntByName(fs, nullptr, "R_lower", 18);
-  R_scale = cvReadIntByName(fs, nullptr, "R_scale", 5);
-  T_dec = cvReadRealByName(fs, nullptr, "T_dec", 0.05);
-  T_inc = cvReadIntByName(fs, nullptr, "T_inc", 1);
-  T_init = cvReadIntByName(fs, nullptr, "T_init", 18);
-  T_lower = cvReadIntByName(fs, nullptr, "T_lower", 2);
-  T_upper = cvReadIntByName(fs, nullptr, "T_upper", 200);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/SigmaDelta.h b/package_bgs/SigmaDelta.h
deleted file mode 100644
index 5dd8a57..0000000
--- a/package_bgs/SigmaDelta.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-
-//extern "C" {
-#include "SigmaDelta/sdLaMa091.h"
-//}
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class SigmaDelta : public IBGS
-    {
-    private:
-      unsigned int ampFactor;
-      unsigned int minVar;
-      unsigned int maxVar;
-      sdLaMa091_t* algorithm;
-
-    public:
-      SigmaDelta();
-      ~SigmaDelta();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-      void applyParams();
-    };
-
-    static BGS_Register<SigmaDelta> register_SigmaDelta("SigmaDelta");
-  }
-}
diff --git a/package_bgs/StaticFrameDifference.cpp b/package_bgs/StaticFrameDifference.cpp
deleted file mode 100644
index 2faa40c..0000000
--- a/package_bgs/StaticFrameDifference.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "StaticFrameDifference.h"
-
-using namespace bgslibrary::algorithms;
-
-StaticFrameDifference::StaticFrameDifference() :
-  enableThreshold(true), threshold(15)
-{
-  std::cout << "StaticFrameDifference()" << std::endl;
-  setup("./config/StaticFrameDifference.xml");
-}
-
-StaticFrameDifference::~StaticFrameDifference()
-{
-  std::cout << "~StaticFrameDifference()" << std::endl;
-}
-
-void StaticFrameDifference::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  if (img_background.empty())
-    img_input.copyTo(img_background);
-
-  cv::absdiff(img_input, img_background, img_foreground);
-
-  if (img_foreground.channels() == 3)
-    cv::cvtColor(img_foreground, img_foreground, CV_BGR2GRAY);
-
-  if (enableThreshold)
-    cv::threshold(img_foreground, img_foreground, threshold, 255, cv::THRESH_BINARY);
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-    cv::imshow("Static Frame Difference", img_foreground);
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-
-  firstTime = false;
-}
-
-void StaticFrameDifference::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void StaticFrameDifference::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/StaticFrameDifference.h b/package_bgs/StaticFrameDifference.h
deleted file mode 100644
index 9fcb093..0000000
--- a/package_bgs/StaticFrameDifference.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class StaticFrameDifference : public IBGS
-    {
-    private:
-      bool enableThreshold;
-      int threshold;
-
-    public:
-      StaticFrameDifference();
-      ~StaticFrameDifference();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<StaticFrameDifference> register_StaticFrameDifference("StaticFrameDifference");
-  }
-}
diff --git a/package_bgs/SuBSENSE.cpp b/package_bgs/SuBSENSE.cpp
deleted file mode 100644
index c8a0e5d..0000000
--- a/package_bgs/SuBSENSE.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "SuBSENSE.h"
-
-using namespace bgslibrary::algorithms;
-
-SuBSENSE::SuBSENSE() :
-  pSubsense(0),
-  fRelLBSPThreshold(BGSSUBSENSE_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD),
-  nDescDistThresholdOffset(BGSSUBSENSE_DEFAULT_DESC_DIST_THRESHOLD_OFFSET),
-  nMinColorDistThreshold(BGSSUBSENSE_DEFAULT_MIN_COLOR_DIST_THRESHOLD),
-  nBGSamples(BGSSUBSENSE_DEFAULT_NB_BG_SAMPLES),
-  nRequiredBGSamples(BGSSUBSENSE_DEFAULT_REQUIRED_NB_BG_SAMPLES),
-  nSamplesForMovingAvgs(BGSSUBSENSE_DEFAULT_N_SAMPLES_FOR_MV_AVGS)
-{
-  std::cout << "SuBSENSE()" << std::endl;
-}
-
-SuBSENSE::~SuBSENSE() {
-  if (pSubsense)
-    delete pSubsense;
-  std::cout << "~SuBSENSE()" << std::endl;
-}
-
-void SuBSENSE::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
-{
-  init(img_input, img_output, img_bgmodel);
-
-  if (firstTime)
-  {
-    pSubsense = new BackgroundSubtractorSuBSENSE(
-      fRelLBSPThreshold, nDescDistThresholdOffset, nMinColorDistThreshold,
-      nBGSamples, nRequiredBGSamples, nSamplesForMovingAvgs);
-
-    pSubsense->initialize(img_input, cv::Mat(img_input.size(), CV_8UC1, cv::Scalar_<uchar>(255)));
-    firstTime = false;
-  }
-
-  pSubsense->apply(img_input, img_foreground);
-  pSubsense->getBackgroundImage(img_background);
-
-#ifndef MEX_COMPILE_FLAG
-  if (showOutput)
-  {
-    imshow("SuBSENSE FG", img_foreground);
-    imshow("SuBSENSE BG", img_background);
-  }
-#endif
-
-  img_foreground.copyTo(img_output);
-  img_background.copyTo(img_bgmodel);
-}
-
-void SuBSENSE::saveConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "fRelLBSPThreshold", fRelLBSPThreshold);
-  cvWriteInt(fs, "nDescDistThresholdOffset", nDescDistThresholdOffset);
-  cvWriteInt(fs, "nMinColorDistThreshold", nMinColorDistThreshold);
-  cvWriteInt(fs, "nBGSamples", nBGSamples);
-  cvWriteInt(fs, "nRequiredBGSamples", nRequiredBGSamples);
-  cvWriteInt(fs, "nSamplesForMovingAvgs", nSamplesForMovingAvgs);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
-}
-
-void SuBSENSE::loadConfig()
-{
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  fRelLBSPThreshold = cvReadRealByName(fs, nullptr, "fRelLBSPThreshold", BGSSUBSENSE_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD);
-  nDescDistThresholdOffset = cvReadIntByName(fs, nullptr, "nDescDistThresholdOffset", BGSSUBSENSE_DEFAULT_DESC_DIST_THRESHOLD_OFFSET);
-  nMinColorDistThreshold = cvReadIntByName(fs, nullptr, "nMinColorDistThreshold", BGSSUBSENSE_DEFAULT_MIN_COLOR_DIST_THRESHOLD);
-  nBGSamples = cvReadIntByName(fs, nullptr, "nBGSamples", BGSSUBSENSE_DEFAULT_NB_BG_SAMPLES);
-  nRequiredBGSamples = cvReadIntByName(fs, nullptr, "nRequiredBGSamples", BGSSUBSENSE_DEFAULT_REQUIRED_NB_BG_SAMPLES);
-  nSamplesForMovingAvgs = cvReadIntByName(fs, nullptr, "nSamplesForMovingAvgs", BGSSUBSENSE_DEFAULT_N_SAMPLES_FOR_MV_AVGS);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
-}
diff --git a/package_bgs/SuBSENSE.h b/package_bgs/SuBSENSE.h
deleted file mode 100644
index ff17209..0000000
--- a/package_bgs/SuBSENSE.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "LBSP/BackgroundSubtractorSuBSENSE.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class SuBSENSE : public IBGS
-    {
-    private:
-      BackgroundSubtractorSuBSENSE* pSubsense;
-
-      float fRelLBSPThreshold;
-      size_t nDescDistThresholdOffset;
-      size_t nMinColorDistThreshold;
-      size_t nBGSamples;
-      size_t nRequiredBGSamples;
-      size_t nSamplesForMovingAvgs;
-
-    public:
-      SuBSENSE();
-      ~SuBSENSE();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<SuBSENSE> register_SuBSENSE("SuBSENSE");
-  }
-}
diff --git a/package_bgs/TwoPoints.h b/package_bgs/TwoPoints.h
deleted file mode 100644
index 67176bc..0000000
--- a/package_bgs/TwoPoints.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "TwoPoints/two_points.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class TwoPoints : public IBGS
-    {
-    private:
-      static const int DEFAULT_MATCH_THRESH = 20;
-      static const int DEFAULT_UPDATE_FACTOR = 16;
-      int matchingThreshold;
-      int updateFactor;
-      twopointsModel_t* model;
-
-    public:
-      TwoPoints();
-      ~TwoPoints();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<TwoPoints> register_TwoPoints("TwoPoints");
-  }
-}
diff --git a/package_bgs/VuMeter.h b/package_bgs/VuMeter.h
deleted file mode 100644
index 3912e32..0000000
--- a/package_bgs/VuMeter.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-#include "VuMeter/TBackgroundVuMeter.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class VuMeter : public IBGS
-    {
-    private:
-      TBackgroundVuMeter bgs;
-
-      IplImage *frame;
-      IplImage *gray;
-      IplImage *background;
-      IplImage *mask;
-
-      bool enableFilter;
-      int binSize;
-      double alpha;
-      double threshold;
-
-    public:
-      VuMeter();
-      ~VuMeter();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<VuMeter> register_VuMeter("VuMeter");
-  }
-}
diff --git a/package_bgs/WeightedMovingMean.h b/package_bgs/WeightedMovingMean.h
deleted file mode 100644
index 7f3eefd..0000000
--- a/package_bgs/WeightedMovingMean.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include "IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class WeightedMovingMean : public IBGS
-    {
-    private:
-      cv::Mat img_input_prev_1;
-      cv::Mat img_input_prev_2;
-      bool enableWeight;
-      bool enableThreshold;
-      int threshold;
-
-    public:
-      WeightedMovingMean();
-      ~WeightedMovingMean();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<WeightedMovingMean> register_WeightedMovingMean("WeightedMovingMean");
-  }
-}
diff --git a/package_bgs/_template_/Amber.h b/package_bgs/_template_/Amber.h
deleted file mode 100644
index b66fa90..0000000
--- a/package_bgs/_template_/Amber.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <math.h>
-#include <sys/types.h>
-
-#include "../IBGS.h"
-#include "amber/amber.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class Amber : public IBGS
-    {
-    private:
-      amberModel* model;
-
-    public:
-      Amber();
-      ~Amber();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig();
-      void loadConfig();
-    };
-
-    static BGS_Register<Amber> register_Amber("Amber");
-  }
-}
diff --git a/package_bgs/_template_/MyBGS.h b/package_bgs/_template_/MyBGS.h
deleted file mode 100644
index e3ff7c5..0000000
--- a/package_bgs/_template_/MyBGS.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#pragma once
-
-#include <opencv2/opencv.hpp>
-
-#include "../IBGS.h"
-
-namespace bgslibrary
-{
-  namespace algorithms
-  {
-    class MyBGS : public IBGS
-    {
-    private:
-      cv::Mat img_previous;
-
-    public:
-      MyBGS();
-      ~MyBGS();
-
-      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
-
-    private:
-      void saveConfig() {}
-      void loadConfig() {}
-    };
-
-    static BGS_Register<MyBGS> register_MyBGS("MyBGS");
-  }
-}
diff --git a/package_bgs/bgslibrary.cpp b/package_bgs/bgslibrary.cpp
deleted file mode 100644
index 0334f6c..0000000
--- a/package_bgs/bgslibrary.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "bgslibrary.h"
diff --git a/package_bgs/dp/AdaptiveMedianBGS.h b/package_bgs/dp/AdaptiveMedianBGS.h
deleted file mode 100644
index 79a04b3..0000000
--- a/package_bgs/dp/AdaptiveMedianBGS.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* AdaptiveMedianBGS.hpp
-*
-* Purpose: Implementation of the simple adaptive median background
-*		  		 subtraction algorithm described in:
-*	  			 "Segmentation and tracking of piglets in images"
-* 						by McFarlane and Schofield
-*
-* Author: Donovan Parks, September 2007
-
-Example:
-    Algorithms::BackgroundSubtraction::AdaptiveMedianParams params;
-    params.SetFrameSize(width, height);
-    params.LowThreshold() = 40;
-    params.HighThreshold() = 2*params.LowThreshold();
-    params.SamplingRate() = 7;
-    params.LearningFrames() = 30;
-
-    Algorithms::BackgroundSubtraction::AdaptiveMedianBGS bgs;
-    bgs.Initalize(params);
-******************************************************************************/
-#pragma once
-
-#include "Bgs.h"
-
-namespace Algorithms
-{
-  namespace BackgroundSubtraction
-  {
-    // --- Parameters used by the Adaptive Median BGS algorithm ---
-    class AdaptiveMedianParams : public BgsParams
-    {
-    public:
-      unsigned char &LowThreshold() { return m_low_threshold; }
-      unsigned char &HighThreshold() { return m_high_threshold; }
-
-      int &SamplingRate() { return m_samplingRate; }
-      int &LearningFrames() { return m_learning_frames; }
-
-    private:
-      unsigned char m_low_threshold;
-      unsigned char m_high_threshold;
-
-      int m_samplingRate;
-      int m_learning_frames;
-    };
-
-
-    // --- Adaptive Median BGS algorithm ---
-    class AdaptiveMedianBGS : public Bgs
-    {
-    public:
-      virtual ~AdaptiveMedianBGS() {}
-
-      void Initalize(const BgsParams& param);
-
-      void InitModel(const RgbImage& data);
-      void Subtract(int frame_num, const RgbImage& data,
-        BwImage& low_threshold_mask, BwImage& high_threshold_mask);
-      void Update(int frame_num, const RgbImage& data, const BwImage& update_mask);
-
-      RgbImage* Background();
-
-    private:
-      void SubtractPixel(int r, int c, const RgbPixel& pixel,
-        unsigned char& low_threshold, unsigned char& high_threshold);
-
-      AdaptiveMedianParams m_params;
-
-      RgbImage m_median;
-    };
-  }
-}
diff --git a/package_bgs/dp/Bgs.h b/package_bgs/dp/Bgs.h
deleted file mode 100644
index 26fff70..0000000
--- a/package_bgs/dp/Bgs.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Bgs.hpp
-*
-* Purpose: Base class for BGS algorithms.
-*
-* Author: Donovan Parks, October 2007
-*
-******************************************************************************/
-#pragma once
-
-#include "Image.h"
-#include "BgsParams.h"
-
-namespace Algorithms
-{
-namespace BackgroundSubtraction
-{
-class Bgs
-{
-public:
-  static const int BACKGROUND = 0;
-  static const int FOREGROUND = 255;
-
-  virtual ~Bgs() {}
-
-  // Initialize any data required by the BGS algorithm. Should be called once before calling
-  // any of the following functions.
-  virtual void Initalize(const BgsParams& param) = 0;
-
-  // Initialize the background model. Typically, the background model is initialized using the first
-  // frame of the incoming video stream, but alternatives are possible.
-  virtual void InitModel(const RgbImage& data) = 0;
-
-  // Subtract the current frame from the background model and produce a binary foreground mask using
-  // both a low and high threshold value.
-  virtual void Subtract(int frame_num, const RgbImage& data,
-                        BwImage& low_threshold_mask, BwImage& high_threshold_mask) = 0;
-
-  // Update the background model. Only pixels set to background in update_mask are updated.
-  virtual void Update(int frame_num, const RgbImage& data,  const BwImage& update_mask) = 0;
-
-  // Return the current background model.
-  virtual RgbImage *Background() = 0;
-};
-}
-}
diff --git a/package_bgs/dp/BgsParams.h b/package_bgs/dp/BgsParams.h
deleted file mode 100644
index d2e7d29..0000000
--- a/package_bgs/dp/BgsParams.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* BgsParams.hpp
-*
-* Purpose: Base class for BGS parameters. Any parameters common to all BGS
-*					 algorithms should be specified directly in this class.
-*
-* Author: Donovan Parks, May 2008
-*
-******************************************************************************/
-#pragma once
-
-namespace Algorithms
-{
-namespace BackgroundSubtraction
-{
-class BgsParams
-{
-public:
-  virtual ~BgsParams() {}
-
-  virtual void SetFrameSize(unsigned int width, unsigned int height)
-  {
-    m_width = width;
-    m_height = height;
-    m_size = width*height;
-  }
-
-  unsigned int &Width() { return m_width; }
-  unsigned int &Height() { return m_height; }
-  unsigned int &Size() { return m_size; }
-
-protected:
-  unsigned int m_width;
-  unsigned int m_height;
-  unsigned int m_size;
-};
-}
-}
diff --git a/package_bgs/dp/Error.cpp b/package_bgs/dp/Error.cpp
deleted file mode 100644
index 1bd87db..0000000
--- a/package_bgs/dp/Error.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Error.cpp
-*
-* Purpose:  Error checking routines.
-*
-* Author: Donovan Parks, July 2007
-*
-******************************************************************************/
-
-#include <iostream> 
-#include <fstream>
-
-#include "Error.h"
-
-using namespace std;
-
-ofstream traceFile;
-
-bool Error(const char* msg, const char* code, int data)
-{
-  cerr << code << ": " << msg << endl;
-
-  return false;
-}
-
-bool TraceInit(const char* filename)
-{
-  traceFile.open(filename);
-  return traceFile.is_open();
-}
-
-void Trace(const char* msg)
-{
-  traceFile << msg << endl;
-}
-
-void TraceClose()
-{
-  traceFile.close();
-}
diff --git a/package_bgs/dp/Error.h b/package_bgs/dp/Error.h
deleted file mode 100644
index 81cbbeb..0000000
--- a/package_bgs/dp/Error.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Error.h
-*
-* Purpose:  Error checking routines.
-*
-* Author: Donovan Parks, July 2007
-*
-******************************************************************************/
-#pragma once
-
-bool Error(const char* msg, const char* code, int data);
-bool TraceInit(const char* filename);
-void Trace(const char* msg);
-void TraceClose();
diff --git a/package_bgs/lb/BGModel.cpp b/package_bgs/lb/BGModel.cpp
deleted file mode 100644
index 3c73b53..0000000
--- a/package_bgs/lb/BGModel.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-  BGModel.cpp
-
-  Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-#include "BGModel.h"
-
-namespace lb_library
-{
-  BGModel::BGModel(int width, int height) : m_width(width), m_height(height)
-  {
-    m_SrcImage = cvCreateImage(cvSize(m_width, m_height), IPL_DEPTH_8U, 3);
-    m_BGImage = cvCreateImage(cvSize(m_width, m_height), IPL_DEPTH_8U, 3);
-    m_FGImage = cvCreateImage(cvSize(m_width, m_height), IPL_DEPTH_8U, 3);
-
-    cvZero(m_SrcImage);
-    cvZero(m_BGImage);
-    cvZero(m_FGImage);
-  }
-
-  BGModel::~BGModel()
-  {
-    if (m_SrcImage != NULL) cvReleaseImage(&m_SrcImage);
-    if (m_BGImage != NULL) cvReleaseImage(&m_BGImage);
-    if (m_FGImage != NULL) cvReleaseImage(&m_FGImage);
-  }
-
-  IplImage* BGModel::GetSrc()
-  {
-    return m_SrcImage;
-  }
-
-  IplImage* BGModel::GetFG()
-  {
-    return m_FGImage;
-  }
-
-  IplImage* BGModel::GetBG()
-  {
-    return m_BGImage;
-  }
-
-  void BGModel::InitModel(IplImage* image)
-  {
-    cvCopy(image, m_SrcImage);
-    Init();
-    return;
-  }
-
-  void BGModel::UpdateModel(IplImage* image)
-  {
-    cvCopy(image, m_SrcImage);
-    Update();
-    return;
-  }
-}
diff --git a/package_bgs/lb/BGModel.h b/package_bgs/lb/BGModel.h
deleted file mode 100644
index 394a78c..0000000
--- a/package_bgs/lb/BGModel.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-  BGModel.h
-
-  Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include <opencv2/opencv.hpp>
-#include <math.h>
-#include <float.h>
-
-#include "Types.h"
-
-namespace lb_library
-{
-  class BGModel
-  {
-  public:
-
-    BGModel(int width, int height);
-    virtual ~BGModel();
-
-    void InitModel(IplImage* image);
-    void UpdateModel(IplImage* image);
-
-    virtual void setBGModelParameter(int id, int value) {};
-
-    virtual IplImage* GetSrc();
-    virtual IplImage* GetFG();
-    virtual IplImage* GetBG();
-
-  protected:
-
-    IplImage* m_SrcImage;
-    IplImage* m_BGImage;
-    IplImage* m_FGImage;
-
-    const unsigned int m_width;
-    const unsigned int m_height;
-
-    virtual void Init() = 0;
-    virtual void Update() = 0;
-  };
-}
diff --git a/package_bgs/lb/BGModelFuzzyGauss.h b/package_bgs/lb/BGModelFuzzyGauss.h
deleted file mode 100644
index a73b716..0000000
--- a/package_bgs/lb/BGModelFuzzyGauss.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelFuzzyGauss.h
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include "BGModel.h"
-
-namespace lb_library
-{
-  namespace FuzzyGaussian
-  {
-    const float ALPHAFUZZYGAUSS = 0.02f;
-    const float THRESHOLDFUZZYGAUSS = 3.5f;
-    const float THRESHOLDBG = 0.5f;
-    const float NOISEFUZZYGAUSS = 50.0f;
-    const float FUZZYEXP = -5.0f;
-
-    class BGModelFuzzyGauss : public BGModel
-    {
-    public:
-      BGModelFuzzyGauss(int width, int height);
-      ~BGModelFuzzyGauss();
-
-      void setBGModelParameter(int id, int value);
-
-    protected:
-      double m_alphamax;
-      double m_threshold;
-      double m_threshBG;
-      double m_noise;
-
-      DBLRGB* m_pMu;
-      DBLRGB* m_pVar;
-
-      void Init();
-      void Update();
-    };
-  }
-}
diff --git a/package_bgs/lb/BGModelFuzzySom.h b/package_bgs/lb/BGModelFuzzySom.h
deleted file mode 100644
index ed0bf21..0000000
--- a/package_bgs/lb/BGModelFuzzySom.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelFuzzySom.h
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include "BGModel.h"
-
-namespace lb_library
-{
-  namespace FuzzyAdaptiveSOM
-  {
-    // SOM parameters
-
-    const int M = 3;				// width SOM (per pixel)
-    const int N = 3;				// height SOM (per pixel)
-    const int KERNEL = 3; 	// size Gaussian kernel
-
-    const bool SPAN_NEIGHBORS = false; // true if update neighborhood spans different pixels			//
-    const int TRAINING_STEPS = 100;			// number of training steps
-
-    const double EPS1 = 100.0; // model match distance during training
-    const double EPS2 = 20.0;  // model match distance
-    const double C1 = 1.0;     // learning rate during training
-    const double C2 = 0.05;    // learning rate
-
-    const double FUZZYEXP = -5.0;
-    const double FUZZYTHRESH = 0.8;
-
-    class BGModelFuzzySom : public BGModel
-    {
-    public:
-      BGModelFuzzySom(int width, int height);
-      ~BGModelFuzzySom();
-
-      void setBGModelParameter(int id, int value);
-
-    protected:
-      int m_widthSOM;
-      int m_heightSOM;
-      int m_offset;
-      int m_pad;
-      int m_K;
-      int m_TSteps;
-
-      double m_Wmax;
-
-      double m_epsilon1;
-      double m_epsilon2;
-      double m_alpha1;
-      double m_alpha2;
-
-      DBLRGB** m_ppSOM;					// SOM grid
-      double** m_ppW;						// Weights
-
-      void Init();
-      void Update();
-    };
-  }
-}
diff --git a/package_bgs/lb/BGModelGauss.h b/package_bgs/lb/BGModelGauss.h
deleted file mode 100644
index 0af6efe..0000000
--- a/package_bgs/lb/BGModelGauss.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelGauss.h
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include "BGModel.h"
-
-namespace lb_library
-{
-  namespace SimpleGaussian
-  {
-    // Parameters
-    const double THRESHGAUSS = 2.5;   // Threshold
-    const double ALPHAGAUSS = 0.0001; // Learning rate
-    const double NOISEGAUSS = 50.0;   // Minimum variance (noise)
-
-    class BGModelGauss : public BGModel
-    {
-    public:
-      BGModelGauss(int width, int height);
-      ~BGModelGauss();
-
-      void setBGModelParameter(int id, int value);
-
-    protected:
-      double m_alpha;
-      double m_threshold;
-      double m_noise;
-
-      DBLRGB* m_pMu;
-      DBLRGB* m_pVar;
-
-      void Init();
-      void Update();
-    };
-  }
-}
diff --git a/package_bgs/lb/BGModelMog.h b/package_bgs/lb/BGModelMog.h
deleted file mode 100644
index c75d1fd..0000000
--- a/package_bgs/lb/BGModelMog.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelMog.h
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include "BGModel.h"
-
-namespace lb_library
-{
-  namespace MixtureOfGaussians
-  {
-    const unsigned int NUMBERGAUSSIANS = 3;
-    const float LEARNINGRATEMOG = 0.001f;
-    const float THRESHOLDMOG = 2.5f;
-    const float BGTHRESHOLDMOG = 0.5f;
-    const float INITIALVARMOG = 50.0f;
-
-    typedef struct tagMOGDATA
-    {
-      DBLRGB mu;
-      DBLRGB var;
-      double w;
-      double sortKey;
-    } MOGDATA;
-
-    class BGModelMog : public BGModel
-    {
-    public:
-      BGModelMog(int width, int height);
-      ~BGModelMog();
-
-      void setBGModelParameter(int id, int value);
-
-    protected:
-      double m_alpha;
-      double m_threshold;
-      double m_noise;
-      double m_T;
-
-      MOGDATA* m_pMOG;
-      int* m_pK;				// number of distributions per pixel
-
-      void Init();
-      void Update();
-    };
-  }
-}
diff --git a/package_bgs/lb/BGModelSom.h b/package_bgs/lb/BGModelSom.h
deleted file mode 100644
index 0975b0b..0000000
--- a/package_bgs/lb/BGModelSom.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelSom.h
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include "BGModel.h"
-
-namespace lb_library
-{
-  namespace AdaptiveSOM
-  {
-    // SOM parameters
-
-    const int M = 3;				// width SOM (per pixel)
-    const int N = 3;				// height SOM (per pixel)
-    const int KERNEL = 3; 	// size Gaussian kernel
-
-    const bool SPAN_NEIGHBORS = false; // true if update neighborhood spans different pixels			//
-    const int TRAINING_STEPS = 100;			// number of training steps
-
-    const float EPS1 = 100.0; // model match distance during training
-    const float EPS2 = 20.0;  // model match distance
-    const float C1 = 1.0;     // learning rate during training
-    const float C2 = 0.05f;    // learning rate
-
-    class BGModelSom : public BGModel
-    {
-    public:
-      BGModelSom(int width, int height);
-      ~BGModelSom();
-
-      void setBGModelParameter(int id, int value);
-
-    protected:
-      int m_widthSOM;
-      int m_heightSOM;
-      int m_offset;
-      int m_pad;
-      int m_K;
-      int m_TSteps;
-
-      double m_Wmax;
-
-      double m_epsilon1;
-      double m_epsilon2;
-      double m_alpha1;
-      double m_alpha2;
-
-      DBLRGB** m_ppSOM;					// SOM grid
-      double** m_ppW;						// Weights
-
-      void Init();
-      void Update();
-    };
-  }
-}
diff --git a/package_bgs/lb/Types.h b/package_bgs/lb/Types.h
deleted file mode 100644
index fd9e65b..0000000
--- a/package_bgs/lb/Types.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments  
-Types.h
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#pragma once
-
-#include <opencv2/opencv.hpp>
-#include <opencv2/core/core_c.h>
-
-namespace lb_library
-{
-template<class T> class Image
-{
-private:
-  IplImage* imgp;
-
-public:
-  Image(IplImage* img=0) {imgp=img;}
-  ~Image(){imgp=0;}
-  
-  void operator=(IplImage* img) {imgp=img;}
-  
-  inline T* operator[](const int rowIndx)
-  {
-    return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));
-  }
-};
-
-typedef struct{
-  unsigned char b,g,r;
-} RgbPixel;
-
-typedef struct{
-  unsigned char Blue,Green,Red;
-} BYTERGB;
-
-typedef struct{
-  unsigned int Blue,Green,Red;
-} INTRGB;
-
-typedef struct{
-  float b,g,r;
-}RgbPixelFloat;
-
-typedef struct{
-  double Blue,Green,Red;
-} DBLRGB;
-
-typedef Image<RgbPixel>       RgbImage;
-typedef Image<RgbPixelFloat>  RgbImageFloat;
-typedef Image<unsigned char>  BwImage;
-typedef Image<float>          BwImageFloat;
-
-/*
-  IplImage* img = cvCreateImage(cvSize(640,480), IPL_DEPTH_32F, 3);
-  RgbImageFloat imgA(img);
-  for(int i = 0; i < m_height; i++)
-    for(int j = 0; j < m_width; j++)
-      imgA[i][j].b = 111;
-      imgA[i][j].g = 111;
-      imgA[i][j].r = 111;
-  */
-}
diff --git a/pybind11 b/pybind11
deleted file mode 160000
index f7bc18f..0000000
--- a/pybind11
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit f7bc18f528bb35cd06c93d0a58c17e6eea3fa68c
diff --git a/run_demo.bat b/run_demo.bat
deleted file mode 100644
index 216799f..0000000
--- a/run_demo.bat
+++ /dev/null
@@ -1,3 +0,0 @@
-@echo off
-cls
-build\bgs_demo.exe dataset/video.avi
\ No newline at end of file
diff --git a/run_demo.sh b/run_demo.sh
deleted file mode 100755
index 2a7777d..0000000
--- a/run_demo.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-./build/bgs_demo dataset/video.avi
diff --git a/run_demo2.bat b/run_demo2.bat
deleted file mode 100644
index c7aba15..0000000
--- a/run_demo2.bat
+++ /dev/null
@@ -1,3 +0,0 @@
-@echo off
-cls
-build\bgs_demo2.exe
\ No newline at end of file
diff --git a/run_demo2.sh b/run_demo2.sh
deleted file mode 100755
index 910099c..0000000
--- a/run_demo2.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-./build/bgs_demo2
diff --git a/src/Config.h b/src/Config.h
new file mode 100644
index 0000000..c5b1b04
--- /dev/null
+++ b/src/Config.h
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace bgslibrary
+{
+  const int KEY_REPEAT = 'r';
+  const int KEY_SPACE = 32;
+  const int KEY_ESC = 27;
+  const int KEY_ESC2 = 'q';
+}
diff --git a/FrameProcessor.cpp b/src/FrameProcessor.cpp
similarity index 69%
rename from FrameProcessor.cpp
rename to src/FrameProcessor.cpp
index ca70d46..83f94c9 100644
--- a/FrameProcessor.cpp
+++ b/src/FrameProcessor.cpp
@@ -1,30 +1,15 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "FrameProcessor.h"
 #include <iomanip>
 
+#include "FrameProcessor.h"
+
 namespace bgslibrary
 {
-  FrameProcessor::FrameProcessor() : firstTime(true), frameNumber(0), duration(0), tictoc(""), frameToStop(0)
+  FrameProcessor::FrameProcessor() : 
+    firstTime(true), frameNumber(0), duration(0), 
+    tictoc(""), frameToStop(0)
   {
     std::cout << "FrameProcessor()" << std::endl;
-
-    loadConfig();
-    saveConfig();
+    setup("./config/FrameProcessor.xml");
   }
 
   FrameProcessor::~FrameProcessor()
@@ -49,16 +34,16 @@ namespace bgslibrary
     if (enableWeightedMovingVariance)
       weightedMovingVariance = new WeightedMovingVariance;
 
-#if CV_MAJOR_VERSION == 2
-    if (enableMixtureOfGaussianV1)
-      mixtureOfGaussianV1 = new MixtureOfGaussianV1;
-#endif
+    if (enableAdaptiveBackgroundLearning)
+      adaptiveBackgroundLearning = new AdaptiveBackgroundLearning;
 
     if (enableMixtureOfGaussianV2)
       mixtureOfGaussianV2 = new MixtureOfGaussianV2;
 
-    if (enableAdaptiveBackgroundLearning)
-      adaptiveBackgroundLearning = new AdaptiveBackgroundLearning;
+#if CV_MAJOR_VERSION == 2
+    if (enableMixtureOfGaussianV1)
+      mixtureOfGaussianV1 = new MixtureOfGaussianV1;
+#endif
 
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     if (enableGMG)
@@ -70,6 +55,7 @@ namespace bgslibrary
       knn = new KNN;
 #endif
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
     if (enableDPAdaptiveMedian)
       dpAdaptiveMedian = new DPAdaptiveMedian;
 
@@ -147,6 +133,7 @@ namespace bgslibrary
 
     if (enableMultiCue)
       multiCue = new MultiCue;
+#endif
 
     if (enableSigmaDelta)
       sigmaDelta = new SigmaDelta;
@@ -204,16 +191,16 @@ namespace bgslibrary
     if (enableWeightedMovingVariance)
       process("WeightedMovingVariance", weightedMovingVariance, img_preProcessor, img_weightedMovingVariance);
 
-#if CV_MAJOR_VERSION == 2
-    if (enableMixtureOfGaussianV1)
-      process("MixtureOfGaussianV1", mixtureOfGaussianV1, img_preProcessor, img_mixtureOfGaussianV1);
-#endif
+    if (enableAdaptiveBackgroundLearning)
+      process("AdaptiveBackgroundLearning", adaptiveBackgroundLearning, img_preProcessor, img_adaptiveBackgroundLearning);
 
     if (enableMixtureOfGaussianV2)
       process("MixtureOfGaussianV2", mixtureOfGaussianV2, img_preProcessor, img_mixtureOfGaussianV2);
 
-    if (enableAdaptiveBackgroundLearning)
-      process("AdaptiveBackgroundLearning", adaptiveBackgroundLearning, img_preProcessor, img_adaptiveBackgroundLearning);
+#if CV_MAJOR_VERSION == 2
+    if (enableMixtureOfGaussianV1)
+      process("MixtureOfGaussianV1", mixtureOfGaussianV1, img_preProcessor, img_mixtureOfGaussianV1);
+#endif
 
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     if (enableGMG)
@@ -225,6 +212,7 @@ namespace bgslibrary
       process("KNN", knn, img_preProcessor, img_knn);
 #endif
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
     if (enableDPAdaptiveMedian)
       process("DPAdaptiveMedian", dpAdaptiveMedian, img_preProcessor, img_dpAdaptiveMedian);
 
@@ -306,7 +294,8 @@ namespace bgslibrary
 
     if (enableMultiCue)
       process("MultiCue", multiCue, img_preProcessor, img_multiCue);
-
+#endif
+    
     if (enableSigmaDelta)
       process("SigmaDelta", sigmaDelta, img_preProcessor, img_sigmaDelta);
 
@@ -337,17 +326,22 @@ namespace bgslibrary
       foregroundMaskAnalysis->process(frameNumber, "StaticFrameDifference", img_staticFrameDifference);
       foregroundMaskAnalysis->process(frameNumber, "WeightedMovingMean", img_weightedMovingMean);
       foregroundMaskAnalysis->process(frameNumber, "WeightedMovingVariance", img_weightedMovingVariance);
+      foregroundMaskAnalysis->process(frameNumber, "AdaptiveBackgroundLearning", img_adaptiveBackgroundLearning);
+      foregroundMaskAnalysis->process(frameNumber, "MixtureOfGaussianV2", img_mixtureOfGaussianV2);
+
 #if CV_MAJOR_VERSION == 2
       foregroundMaskAnalysis->process(frameNumber, "MixtureOfGaussianV1", img_mixtureOfGaussianV1);
 #endif
-      foregroundMaskAnalysis->process(frameNumber, "MixtureOfGaussianV2", img_mixtureOfGaussianV2);
-      foregroundMaskAnalysis->process(frameNumber, "AdaptiveBackgroundLearning", img_adaptiveBackgroundLearning);
+
 #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
       foregroundMaskAnalysis->process(frameNumber, "KNN", img_knn);
 #endif
+      
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
       foregroundMaskAnalysis->process(frameNumber, "DPAdaptiveMedian", img_dpAdaptiveMedian);
       foregroundMaskAnalysis->process(frameNumber, "DPGrimsonGMM", img_dpGrimsonGMM);
       foregroundMaskAnalysis->process(frameNumber, "DPZivkovicAGMM", img_dpZivkovicAGMM);
@@ -374,6 +368,8 @@ namespace bgslibrary
       foregroundMaskAnalysis->process(frameNumber, "KDE", img_kde);
       foregroundMaskAnalysis->process(frameNumber, "IMBS", img_imbs);
       foregroundMaskAnalysis->process(frameNumber, "MultiCue", img_multiCue);
+#endif
+
       foregroundMaskAnalysis->process(frameNumber, "SigmaDelta", img_sigmaDelta);
       foregroundMaskAnalysis->process(frameNumber, "SuBSENSE", img_subSENSE);
       foregroundMaskAnalysis->process(frameNumber, "LOBSTER", img_lobster);
@@ -430,6 +426,7 @@ namespace bgslibrary
     if (enableSigmaDelta)
       delete sigmaDelta;
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
     if (enableMultiCue)
       delete multiCue;
 
@@ -507,6 +504,7 @@ namespace bgslibrary
 
     if (enableDPAdaptiveMedian)
       delete dpAdaptiveMedian;
+#endif
 
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
     if (enableGMG)
@@ -518,16 +516,16 @@ namespace bgslibrary
       delete knn;
 #endif
 
-    if (enableAdaptiveBackgroundLearning)
-      delete adaptiveBackgroundLearning;
-
-    if (enableMixtureOfGaussianV2)
-      delete mixtureOfGaussianV2;
-
 #if CV_MAJOR_VERSION == 2
     if (enableMixtureOfGaussianV1)
       delete mixtureOfGaussianV1;
 #endif
+    
+    if (enableMixtureOfGaussianV2)
+      delete mixtureOfGaussianV2;
+    
+    if (enableAdaptiveBackgroundLearning)
+      delete adaptiveBackgroundLearning;
 
     if (enableWeightedMovingVariance)
       delete weightedMovingVariance;
@@ -559,133 +557,134 @@ namespace bgslibrary
 
   void FrameProcessor::saveConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage("./config/FrameProcessor.xml", 0, CV_STORAGE_WRITE);
-
-    cvWriteString(fs, "tictoc", tictoc.c_str());
+    cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+
+    fs << "tictoc" << tictoc;
+    fs << "enablePreProcessor" << enablePreProcessor;
+    fs << "enableForegroundMaskAnalysis" << enableForegroundMaskAnalysis;
+    fs << "enableFrameDifference" << enableFrameDifference;
+    fs << "enableStaticFrameDifference" << enableStaticFrameDifference;
+    fs << "enableWeightedMovingMean" << enableWeightedMovingMean;
+    fs << "enableWeightedMovingVariance" << enableWeightedMovingVariance;
+    fs << "enableAdaptiveBackgroundLearning" << enableAdaptiveBackgroundLearning;
+    fs << "enableMixtureOfGaussianV2" << enableMixtureOfGaussianV2;
 
-    cvWriteInt(fs, "enablePreProcessor", enablePreProcessor);
-
-    cvWriteInt(fs, "enableForegroundMaskAnalysis", enableForegroundMaskAnalysis);
-
-    cvWriteInt(fs, "enableFrameDifference", enableFrameDifference);
-    cvWriteInt(fs, "enableStaticFrameDifference", enableStaticFrameDifference);
-    cvWriteInt(fs, "enableWeightedMovingMean", enableWeightedMovingMean);
-    cvWriteInt(fs, "enableWeightedMovingVariance", enableWeightedMovingVariance);
 #if CV_MAJOR_VERSION == 2
-    cvWriteInt(fs, "enableMixtureOfGaussianV1", enableMixtureOfGaussianV1);
+    fs << "enableMixtureOfGaussianV1" << enableMixtureOfGaussianV1;
 #endif
-    cvWriteInt(fs, "enableMixtureOfGaussianV2", enableMixtureOfGaussianV2);
-    cvWriteInt(fs, "enableAdaptiveBackgroundLearning", enableAdaptiveBackgroundLearning);
+    
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
-    cvWriteInt(fs, "enableGMG", enableGMG);
+    fs << "enableGMG" << enableGMG;
 #endif
+    
 #if CV_MAJOR_VERSION >= 3
-    cvWriteInt(fs, "enableKNN", enableKNN);
+    fs << "enableKNN" << enableKNN;
 #endif
 
-    cvWriteInt(fs, "enableDPAdaptiveMedian", enableDPAdaptiveMedian);
-    cvWriteInt(fs, "enableDPGrimsonGMM", enableDPGrimsonGMM);
-    cvWriteInt(fs, "enableDPZivkovicAGMM", enableDPZivkovicAGMM);
-    cvWriteInt(fs, "enableDPMean", enableDPMean);
-    cvWriteInt(fs, "enableDPWrenGA", enableDPWrenGA);
-    cvWriteInt(fs, "enableDPPratiMediod", enableDPPratiMediod);
-    cvWriteInt(fs, "enableDPEigenbackground", enableDPEigenbackground);
-    cvWriteInt(fs, "enableDPTexture", enableDPTexture);
-
-    cvWriteInt(fs, "enableT2FGMM_UM", enableT2FGMM_UM);
-    cvWriteInt(fs, "enableT2FGMM_UV", enableT2FGMM_UV);
-    cvWriteInt(fs, "enableT2FMRF_UM", enableT2FMRF_UM);
-    cvWriteInt(fs, "enableT2FMRF_UV", enableT2FMRF_UV);
-    cvWriteInt(fs, "enableFuzzySugenoIntegral", enableFuzzySugenoIntegral);
-    cvWriteInt(fs, "enableFuzzyChoquetIntegral", enableFuzzyChoquetIntegral);
-
-    cvWriteInt(fs, "enableLBSimpleGaussian", enableLBSimpleGaussian);
-    cvWriteInt(fs, "enableLBFuzzyGaussian", enableLBFuzzyGaussian);
-    cvWriteInt(fs, "enableLBMixtureOfGaussians", enableLBMixtureOfGaussians);
-    cvWriteInt(fs, "enableLBAdaptiveSOM", enableLBAdaptiveSOM);
-    cvWriteInt(fs, "enableLBFuzzyAdaptiveSOM", enableLBFuzzyAdaptiveSOM);
-
-    cvWriteInt(fs, "enableLbpMrf", enableLbpMrf);
-    cvWriteInt(fs, "enableMultiLayer", enableMultiLayer);
-    cvWriteInt(fs, "enablePBAS", enablePBAS);
-    cvWriteInt(fs, "enableVuMeter", enableVuMeter);
-    cvWriteInt(fs, "enableKDE", enableKDE);
-    cvWriteInt(fs, "enableIMBS", enableIMBS);
-    cvWriteInt(fs, "enableMultiCue", enableMultiCue);
-    cvWriteInt(fs, "enableSigmaDelta", enableSigmaDelta);
-    cvWriteInt(fs, "enableSuBSENSE", enableSuBSENSE);
-    cvWriteInt(fs, "enableLOBSTER", enableLOBSTER);
-    cvWriteInt(fs, "enablePAWCS", enablePAWCS);
-    cvWriteInt(fs, "enableTwoPoints", enableTwoPoints);
-    cvWriteInt(fs, "enableViBe", enableViBe);
-    cvWriteInt(fs, "enableCodeBook", enableCodeBook);
-
-    cvReleaseFileStorage(&fs);
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+    fs << "enableDPAdaptiveMedian" << enableDPAdaptiveMedian;
+    fs << "enableDPGrimsonGMM" << enableDPGrimsonGMM;
+    fs << "enableDPZivkovicAGMM" << enableDPZivkovicAGMM;
+    fs << "enableDPMean" << enableDPMean;
+    fs << "enableDPWrenGA" << enableDPWrenGA;
+    fs << "enableDPPratiMediod" << enableDPPratiMediod;
+    fs << "enableDPEigenbackground" << enableDPEigenbackground;
+    fs << "enableDPTexture" << enableDPTexture;
+    fs << "enableT2FGMM_UM" << enableT2FGMM_UM;
+    fs << "enableT2FGMM_UV" << enableT2FGMM_UV;
+    fs << "enableT2FMRF_UM" << enableT2FMRF_UM;
+    fs << "enableT2FMRF_UV" << enableT2FMRF_UV;
+    fs << "enableFuzzySugenoIntegral" << enableFuzzySugenoIntegral;
+    fs << "enableFuzzyChoquetIntegral" << enableFuzzyChoquetIntegral;
+    fs << "enableLBSimpleGaussian" << enableLBSimpleGaussian;
+    fs << "enableLBFuzzyGaussian" << enableLBFuzzyGaussian;
+    fs << "enableLBMixtureOfGaussians" << enableLBMixtureOfGaussians;
+    fs << "enableLBAdaptiveSOM" << enableLBAdaptiveSOM;
+    fs << "enableLBFuzzyAdaptiveSOM" << enableLBFuzzyAdaptiveSOM;
+    fs << "enableLbpMrf" << enableLbpMrf;
+    fs << "enableMultiLayer" << enableMultiLayer;
+    fs << "enablePBAS" << enablePBAS;
+    fs << "enableVuMeter" << enableVuMeter;
+    fs << "enableKDE" << enableKDE;
+    fs << "enableIMBS" << enableIMBS;
+    fs << "enableMultiCue" << enableMultiCue;
+#endif
+    
+    fs << "enableSigmaDelta" << enableSigmaDelta;
+    fs << "enableSuBSENSE" << enableSuBSENSE;
+    fs << "enableLOBSTER" << enableLOBSTER;
+    fs << "enablePAWCS" << enablePAWCS;
+    fs << "enableTwoPoints" << enableTwoPoints;
+    fs << "enableViBe" << enableViBe;
+    fs << "enableCodeBook" << enableCodeBook;
+
+    fs.release();
   }
 
   void FrameProcessor::loadConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage("./config/FrameProcessor.xml", 0, CV_STORAGE_READ);
-
-    tictoc = cvReadStringByName(fs, 0, "tictoc", "");
+    cv::FileStorage fs;
+    fs.open(config_xml, cv::FileStorage::READ);
+    
+    fs["tictoc"] >> tictoc;
+    fs["enablePreProcessor"] >> enablePreProcessor;
+    fs["enableForegroundMaskAnalysis"] >> enableForegroundMaskAnalysis;
+    fs["enableFrameDifference"] >> enableFrameDifference;
+    fs["enableStaticFrameDifference"] >> enableStaticFrameDifference;
+    fs["enableWeightedMovingMean"] >> enableWeightedMovingMean;
+    fs["enableWeightedMovingVariance"] >> enableWeightedMovingVariance;
+    fs["enableAdaptiveBackgroundLearning"] >> enableAdaptiveBackgroundLearning;
+    fs["enableMixtureOfGaussianV2"] >> enableMixtureOfGaussianV2;
 
-    enablePreProcessor = cvReadIntByName(fs, 0, "enablePreProcessor", true);
-
-    enableForegroundMaskAnalysis = cvReadIntByName(fs, 0, "enableForegroundMaskAnalysis", false);
-
-    enableFrameDifference = cvReadIntByName(fs, 0, "enableFrameDifference", false);
-    enableStaticFrameDifference = cvReadIntByName(fs, 0, "enableStaticFrameDifference", false);
-    enableWeightedMovingMean = cvReadIntByName(fs, 0, "enableWeightedMovingMean", false);
-    enableWeightedMovingVariance = cvReadIntByName(fs, 0, "enableWeightedMovingVariance", false);
 #if CV_MAJOR_VERSION == 2
-    enableMixtureOfGaussianV1 = cvReadIntByName(fs, 0, "enableMixtureOfGaussianV1", false);
+    fs["enableMixtureOfGaussianV1"] >> enableMixtureOfGaussianV1;
 #endif
-    enableMixtureOfGaussianV2 = cvReadIntByName(fs, 0, "enableMixtureOfGaussianV2", false);
-    enableAdaptiveBackgroundLearning = cvReadIntByName(fs, 0, "enableAdaptiveBackgroundLearning", false);
+    
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
-    enableGMG = cvReadIntByName(fs, 0, "enableGMG", false);
+    fs["enableGMG"] >> enableGMG;
 #endif
+    
 #if CV_MAJOR_VERSION >= 3
-    enableKNN = cvReadIntByName(fs, 0, "enableKNN", false);
+    fs["enableKNN"] >> enableKNN;
 #endif
 
-    enableDPAdaptiveMedian = cvReadIntByName(fs, 0, "enableDPAdaptiveMedian", false);
-    enableDPGrimsonGMM = cvReadIntByName(fs, 0, "enableDPGrimsonGMM", false);
-    enableDPZivkovicAGMM = cvReadIntByName(fs, 0, "enableDPZivkovicAGMM", false);
-    enableDPMean = cvReadIntByName(fs, 0, "enableDPMean", false);
-    enableDPWrenGA = cvReadIntByName(fs, 0, "enableDPWrenGA", false);
-    enableDPPratiMediod = cvReadIntByName(fs, 0, "enableDPPratiMediod", false);
-    enableDPEigenbackground = cvReadIntByName(fs, 0, "enableDPEigenbackground", false);
-    enableDPTexture = cvReadIntByName(fs, 0, "enableDPTexture", false);
-
-    enableT2FGMM_UM = cvReadIntByName(fs, 0, "enableT2FGMM_UM", false);
-    enableT2FGMM_UV = cvReadIntByName(fs, 0, "enableT2FGMM_UV", false);
-    enableT2FMRF_UM = cvReadIntByName(fs, 0, "enableT2FMRF_UM", false);
-    enableT2FMRF_UV = cvReadIntByName(fs, 0, "enableT2FMRF_UV", false);
-    enableFuzzySugenoIntegral = cvReadIntByName(fs, 0, "enableFuzzySugenoIntegral", false);
-    enableFuzzyChoquetIntegral = cvReadIntByName(fs, 0, "enableFuzzyChoquetIntegral", false);
-
-    enableLBSimpleGaussian = cvReadIntByName(fs, 0, "enableLBSimpleGaussian", false);
-    enableLBFuzzyGaussian = cvReadIntByName(fs, 0, "enableLBFuzzyGaussian", false);
-    enableLBMixtureOfGaussians = cvReadIntByName(fs, 0, "enableLBMixtureOfGaussians", false);
-    enableLBAdaptiveSOM = cvReadIntByName(fs, 0, "enableLBAdaptiveSOM", false);
-    enableLBFuzzyAdaptiveSOM = cvReadIntByName(fs, 0, "enableLBFuzzyAdaptiveSOM", false);
-
-    enableLbpMrf = cvReadIntByName(fs, 0, "enableLbpMrf", false);
-    enableMultiLayer = cvReadIntByName(fs, 0, "enableMultiLayer", false);
-    enablePBAS = cvReadIntByName(fs, 0, "enablePBAS", false);
-    enableVuMeter = cvReadIntByName(fs, 0, "enableVuMeter", false);
-    enableKDE = cvReadIntByName(fs, 0, "enableKDE", false);
-    enableIMBS = cvReadIntByName(fs, 0, "enableIMBS", false);
-    enableMultiCue = cvReadIntByName(fs, 0, "enableMultiCue", false);
-    enableSigmaDelta = cvReadIntByName(fs, 0, "enableSigmaDelta", false);
-    enableSuBSENSE = cvReadIntByName(fs, 0, "enableSuBSENSE", false);
-    enableLOBSTER = cvReadIntByName(fs, 0, "enableLOBSTER", false);
-    enablePAWCS = cvReadIntByName(fs, 0, "enablePAWCS", false);
-    enableTwoPoints = cvReadIntByName(fs, 0, "enableTwoPoints", false);
-    enableViBe = cvReadIntByName(fs, 0, "enableViBe", false);
-    enableCodeBook = cvReadIntByName(fs, 0, "enableCodeBook", false);
-
-    cvReleaseFileStorage(&fs);
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+    fs["enableDPAdaptiveMedian"] >> enableDPAdaptiveMedian;
+    fs["enableDPGrimsonGMM"] >> enableDPGrimsonGMM;
+    fs["enableDPZivkovicAGMM"] >> enableDPZivkovicAGMM;
+    fs["enableDPMean"] >> enableDPMean;
+    fs["enableDPWrenGA"] >> enableDPWrenGA;
+    fs["enableDPPratiMediod"] >> enableDPPratiMediod;
+    fs["enableDPEigenbackground"] >> enableDPEigenbackground;
+    fs["enableDPTexture"] >> enableDPTexture;
+    fs["enableT2FGMM_UM"] >> enableT2FGMM_UM;
+    fs["enableT2FGMM_UV"] >> enableT2FGMM_UV;
+    fs["enableT2FMRF_UM"] >> enableT2FMRF_UM;
+    fs["enableT2FMRF_UV"] >> enableT2FMRF_UV;
+    fs["enableFuzzySugenoIntegral"] >> enableFuzzySugenoIntegral;
+    fs["enableFuzzyChoquetIntegral"] >> enableFuzzyChoquetIntegral;
+    fs["enableLBSimpleGaussian"] >> enableLBSimpleGaussian;
+    fs["enableLBFuzzyGaussian"] >> enableLBFuzzyGaussian;
+    fs["enableLBMixtureOfGaussians"] >> enableLBMixtureOfGaussians;
+    fs["enableLBAdaptiveSOM"] >> enableLBAdaptiveSOM;
+    fs["enableLBFuzzyAdaptiveSOM"] >> enableLBFuzzyAdaptiveSOM;
+    fs["enableLbpMrf"] >> enableLbpMrf;
+    fs["enableMultiLayer"] >> enableMultiLayer;
+    fs["enablePBAS"] >> enablePBAS;
+    fs["enableVuMeter"] >> enableVuMeter;
+    fs["enableKDE"] >> enableKDE;
+    fs["enableIMBS"] >> enableIMBS;
+    fs["enableMultiCue"] >> enableMultiCue;
+#endif
+    
+    fs["enableSigmaDelta"] >> enableSigmaDelta;
+    fs["enableSuBSENSE"] >> enableSuBSENSE;
+    fs["enableLOBSTER"] >> enableLOBSTER;
+    fs["enablePAWCS"] >> enablePAWCS;
+    fs["enableTwoPoints"] >> enableTwoPoints;
+    fs["enableViBe"] >> enableViBe;
+    fs["enableCodeBook"] >> enableCodeBook;
+
+    fs.release();
   }
 }
diff --git a/FrameProcessor.h b/src/FrameProcessor.h
similarity index 87%
rename from FrameProcessor.h
rename to src/FrameProcessor.h
index 9f59f4f..4b40f24 100644
--- a/FrameProcessor.h
+++ b/src/FrameProcessor.h
@@ -1,32 +1,15 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 #pragma warning(disable : 4482)
 
 #include "IFrameProcessor.h"
 #include "PreProcessor.h"
 
-#include "package_bgs/IBGS.h"
 #include "package_bgs/bgslibrary.h"
 #include "package_analysis/ForegroundMaskAnalysis.h"
 
 namespace bgslibrary
 {
-  class FrameProcessor : public IFrameProcessor
+  class FrameProcessor : public IFrameProcessor, public ILoadSaveConfig
   {
   private:
     bool firstTime;
@@ -81,6 +64,7 @@ namespace bgslibrary
     bool enableKNN;
 #endif
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
     cv::Mat img_dpAdaptiveMedian;
     DPAdaptiveMedian* dpAdaptiveMedian;
     bool enableDPAdaptiveMedian;
@@ -156,7 +140,7 @@ namespace bgslibrary
     cv::Mat img_lbFuzzyAdaptiveSOM;
     LBFuzzyAdaptiveSOM* lbFuzzyAdaptiveSOM;
     bool enableLBFuzzyAdaptiveSOM;
-
+    
     cv::Mat img_lbpMrf;
     LBP_MRF* lbpMrf;
     bool enableLbpMrf;
@@ -184,6 +168,7 @@ namespace bgslibrary
     cv::Mat img_multiCue;
     MultiCue* multiCue;
     bool enableMultiCue;
+#endif
 
     cv::Mat img_sigmaDelta;
     SigmaDelta* sigmaDelta;
diff --git a/src/IFrameProcessor.h b/src/IFrameProcessor.h
new file mode 100644
index 0000000..2b26eb4
--- /dev/null
+++ b/src/IFrameProcessor.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <opencv2/opencv.hpp>
+
+namespace bgslibrary
+{
+  class IFrameProcessor
+  {
+  public:
+    virtual void process(const cv::Mat &input) = 0;
+    virtual ~IFrameProcessor(){}
+  };
+}
diff --git a/Main.cpp b/src/Main.cpp
similarity index 66%
rename from Main.cpp
rename to src/Main.cpp
index 94bf8dd..c8a8367 100644
--- a/Main.cpp
+++ b/src/Main.cpp
@@ -1,22 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+#include <iostream>
 
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "Config.h"
 #include "VideoAnalysis.h"
-#include <iostream>
 
 namespace bgslibrary
 {
@@ -31,8 +16,7 @@ namespace bgslibrary
       std::cout << "---------------------------------------------" << std::endl;
       std::cout << "Background Subtraction Library               " << std::endl;
       std::cout << "https://github.com/andrewssobral/bgslibrary  " << std::endl;
-      std::cout << "by:                                          " << std::endl;
-      std::cout << "Andrews Sobral (andrewssobral@gmail.com)     " << std::endl;
+      std::cout << "This software is under the MIT License       " << std::endl;
       std::cout << "---------------------------------------------" << std::endl;
       std::cout << "Using OpenCV version " << CV_VERSION << std::endl;
 
diff --git a/PreProcessor.cpp b/src/PreProcessor.cpp
similarity index 71%
rename from PreProcessor.cpp
rename to src/PreProcessor.cpp
index 4c13f7e..d1c3f8c 100644
--- a/PreProcessor.cpp
+++ b/src/PreProcessor.cpp
@@ -1,26 +1,12 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "PreProcessor.h"
 
 namespace bgslibrary
 {
-  PreProcessor::PreProcessor() : firstTime(true), equalizeHist(false), gaussianBlur(false)
+  PreProcessor::PreProcessor() : 
+    firstTime(true), equalizeHist(false), gaussianBlur(false)
   {
     std::cout << "PreProcessor()" << std::endl;
+    setup("./config/PreProcessor.xml");
   }
 
   PreProcessor::~PreProcessor()
@@ -71,11 +57,11 @@ namespace bgslibrary
       cv::GaussianBlur(img_output, img_output, cv::Size(7, 7), 1.5);
 
     if (enableShow)
-      cv::imshow("Pre Processor", img_output);
+      cv::imshow("PreProcessor", img_output);
 
     firstTime = false;
   }
-
+  /*
   void PreProcessor::rotate(const cv::Mat &img_input, cv::Mat &img_output, float angle)
   {
     IplImage* image = new IplImage(img_input);
@@ -102,7 +88,7 @@ namespace bgslibrary
     cvReleaseImage(&rotatedImage);
     cvReleaseMat(&mapMatrix);
   }
-
+  */
   void PreProcessor::applyCanny(const cv::Mat &img_input, cv::Mat &img_output)
   {
     if (img_input.empty())
@@ -127,23 +113,24 @@ namespace bgslibrary
 
   void PreProcessor::saveConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage("./config/PreProcessor.xml", 0, CV_STORAGE_WRITE);
+    cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-    cvWriteInt(fs, "equalizeHist", equalizeHist);
-    cvWriteInt(fs, "gaussianBlur", gaussianBlur);
-    cvWriteInt(fs, "enableShow", enableShow);
+    fs << "equalizeHist" << equalizeHist;
+    fs << "gaussianBlur" << gaussianBlur;
+    fs << "enableShow" << enableShow;
 
-    cvReleaseFileStorage(&fs);
+    fs.release();
   }
 
   void PreProcessor::loadConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage("./config/PreProcessor.xml", 0, CV_STORAGE_READ);
-
-    equalizeHist = cvReadIntByName(fs, 0, "equalizeHist", false);
-    gaussianBlur = cvReadIntByName(fs, 0, "gaussianBlur", false);
-    enableShow = cvReadIntByName(fs, 0, "enableShow", true);
-
-    cvReleaseFileStorage(&fs);
+    cv::FileStorage fs;
+    fs.open(config_xml, cv::FileStorage::READ);
+    
+    fs["equalizeHist"] >> equalizeHist;
+    fs["gaussianBlur"] >> gaussianBlur;
+    fs["enableShow"] >> enableShow;
+
+    fs.release();
   }
 }
diff --git a/PreProcessor.h b/src/PreProcessor.h
similarity index 53%
rename from PreProcessor.h
rename to src/PreProcessor.h
index 176dbca..ad2f534 100644
--- a/PreProcessor.h
+++ b/src/PreProcessor.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <iostream>
@@ -26,9 +10,11 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include <opencv2/imgproc/imgproc_c.h>
 #include <opencv2/highgui/highgui_c.h>
 
+#include "package_bgs/ILoadSaveConfig.h"
+
 namespace bgslibrary
 {
-  class PreProcessor
+  class PreProcessor : public ILoadSaveConfig
   {
   private:
     bool firstTime;
@@ -47,7 +33,7 @@ namespace bgslibrary
 
     void process(const cv::Mat &img_input, cv::Mat &img_output);
 
-    void rotate(const cv::Mat &img_input, cv::Mat &img_output, float angle);
+    //void rotate(const cv::Mat &img_input, cv::Mat &img_output, float angle);
     void applyCanny(const cv::Mat &img_input, cv::Mat &img_output);
 
   private:
diff --git a/VideoAnalysis.cpp b/src/VideoAnalysis.cpp
similarity index 85%
rename from VideoAnalysis.cpp
rename to src/VideoAnalysis.cpp
index 9ec0754..315cff4 100644
--- a/VideoAnalysis.cpp
+++ b/src/VideoAnalysis.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "VideoAnalysis.h"
 
 namespace bgslibrary
diff --git a/src/VideoAnalysis.h b/src/VideoAnalysis.h
new file mode 100644
index 0000000..02024a2
--- /dev/null
+++ b/src/VideoAnalysis.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <iostream>
+#include <sstream>
+
+#include "VideoCapture.h"
+#include "FrameProcessor.h"
+
+namespace bgslibrary
+{
+  class VideoAnalysis
+  {
+  private:
+    std::unique_ptr<VideoCapture> videoCapture;
+    std::shared_ptr<FrameProcessor> frameProcessor;
+    bool use_file;
+    std::string filename;
+    bool use_camera;
+    int cameraIndex;
+    bool use_comp;
+    long frameToStop;
+    std::string imgref;
+
+  public:
+    VideoAnalysis();
+    ~VideoAnalysis();
+
+    bool setup(int argc, const char **argv);
+    void start();
+  };
+}
diff --git a/VideoCapture.cpp b/src/VideoCapture.cpp
similarity index 68%
rename from VideoCapture.cpp
rename to src/VideoCapture.cpp
index 6c3a8f2..9fb004b 100644
--- a/VideoCapture.cpp
+++ b/src/VideoCapture.cpp
@@ -1,34 +1,26 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "VideoCapture.h"
-#include <opencv2/highgui/highgui_c.h>
+
+#if  CV_MAJOR_VERSION >= 4
+//#define CV_CAP_PROP_POS_FRAMES cv::CAP_PROP_POS_FRAMES
+//#define CV_CAP_PROP_FRAME_COUNT cv::CAP_PROP_FRAME_COUNT
+#define CV_CAP_PROP_FPS cv::CAP_PROP_FPS
+#define CV_EVENT_LBUTTONDOWN cv::EVENT_LBUTTONDOWN
+#define CV_EVENT_MOUSEMOVE cv::EVENT_MOUSEMOVE
+#define cvSetMouseCallback cv::setMouseCallback
+#endif
 
 namespace bgslibrary
 {
   namespace VC_ROI
   {
-    IplImage* img_input1 = 0;
-    IplImage* img_input2 = 0;
+    cv::Mat img_input1;
+    cv::Mat img_input2;
     int roi_x0 = 0;
     int roi_y0 = 0;
     int roi_x1 = 0;
     int roi_y1 = 0;
     int numOfRec = 0;
-    int startDraw = 0;
+    bool startDraw = false;
     bool roi_defined = false;
     bool use_roi = true;
     bool disable_event = false;
@@ -43,7 +35,7 @@ namespace bgslibrary
     {
       if (use_roi == false || disable_event == true)
         return;
-
+      
       if (evt == CV_EVENT_LBUTTONDOWN)
       {
         if (!startDraw)
@@ -65,10 +57,11 @@ namespace bgslibrary
       if (evt == CV_EVENT_MOUSEMOVE && startDraw)
       {
         //redraw ROI selection
-        img_input2 = cvCloneImage(img_input1);
-        cvRectangle(img_input2, cvPoint(roi_x0, roi_y0), cvPoint(x, y), CV_RGB(255, 0, 0), 1);
-        cvShowImage("Input", img_input2);
-        cvReleaseImage(&img_input2);
+        img_input1.copyTo(img_input2);
+        cv::Point pt1(roi_x0, roi_y0);
+        cv::Point pt2(roi_x1, roi_y1);
+        cv::rectangle(img_input2, pt1, pt2, cv::Scalar(255, 0, 0));
+        cv::imshow("Input", img_input2);
         //startDraw = false;
         //disable_event = true;
       }
@@ -77,9 +70,8 @@ namespace bgslibrary
 
   VideoCapture::VideoCapture() :
     key(0), start_time(0), delta_time(0), freq(0),
-    fps(0), frameNumber(0), stopAt(0), useCamera(false),
-    useVideo(false), input_resize_percent(100), showOutput(true),
-    enableFlip(false), cameraIndex(0)
+    fps(0), frameNumber(0), stopAt(0), useCamera(false), cameraIndex(0),
+    useVideo(false), input_resize_percent(100), showOutput(true), enableFlip(false)
   {
     std::cout << "VideoCapture()" << std::endl;
     setup("./config/VideoCapture.xml");
@@ -195,10 +187,10 @@ namespace bgslibrary
             cv::imshow("Input", img_input);
 
             std::cout << "Set ROI (press ESC to skip)" << std::endl;
-            VC_ROI::img_input1 = new IplImage(img_input);
+            //VC_ROI::img_input1 = new IplImage(img_input);
             cvSetMouseCallback("Input", VC_ROI::VideoCapture_on_mouse, NULL);
             key = cv::waitKey(0);
-            delete VC_ROI::img_input1;
+            //delete VC_ROI::img_input1;
           }
           else
             key = KEY_ESC;
@@ -236,10 +228,10 @@ namespace bgslibrary
 
       start_time = cv::getTickCount();
       frameProcessor->process(img_input);
-      int64 delta_time = cv::getTickCount() - start_time;
+      delta_time = cv::getTickCount() - start_time;
       freq = cv::getTickFrequency();
       fps = freq / delta_time;
-      //std::cout << "FPS: " << fps << std::endl;
+      std::cout << "FPS: " << fps << std::endl;
 
       //cvResetImageROI(frame);
 
@@ -263,37 +255,38 @@ namespace bgslibrary
 
   void VideoCapture::saveConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), 0, CV_STORAGE_WRITE);
-
-    cvWriteInt(fs, "stopAt", stopAt);
-    cvWriteInt(fs, "input_resize_percent", input_resize_percent);
-    cvWriteInt(fs, "enableFlip", enableFlip);
-    cvWriteInt(fs, "use_roi", VC_ROI::use_roi);
-    cvWriteInt(fs, "roi_defined", VC_ROI::roi_defined);
-    cvWriteInt(fs, "roi_x0", VC_ROI::roi_x0);
-    cvWriteInt(fs, "roi_y0", VC_ROI::roi_y0);
-    cvWriteInt(fs, "roi_x1", VC_ROI::roi_x1);
-    cvWriteInt(fs, "roi_y1", VC_ROI::roi_y1);
-    cvWriteInt(fs, "showOutput", showOutput);
-
-    cvReleaseFileStorage(&fs);
+    cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+    
+    fs << "stopAt" << stopAt;
+    fs << "input_resize_percent" << input_resize_percent;
+    fs << "enableFlip" << enableFlip;
+    fs << "use_roi" << VC_ROI::use_roi;
+    fs << "roi_defined" << VC_ROI::roi_defined;
+    fs << "roi_x0" << VC_ROI::roi_x0;
+    fs << "roi_y0" << VC_ROI::roi_y0;
+    fs << "roi_x1" << VC_ROI::roi_x1;
+    fs << "roi_y1" << VC_ROI::roi_y1;
+    fs << "showOutput" << showOutput;
+    
+    fs.release();
   }
 
   void VideoCapture::loadConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-    stopAt = cvReadIntByName(fs, nullptr, "stopAt", 0);
-    input_resize_percent = cvReadIntByName(fs, nullptr, "input_resize_percent", 100);
-    enableFlip = cvReadIntByName(fs, nullptr, "enableFlip", false);
-    VC_ROI::use_roi = cvReadIntByName(fs, nullptr, "use_roi", true);
-    VC_ROI::roi_defined = cvReadIntByName(fs, nullptr, "roi_defined", false);
-    VC_ROI::roi_x0 = cvReadIntByName(fs, nullptr, "roi_x0", 0);
-    VC_ROI::roi_y0 = cvReadIntByName(fs, nullptr, "roi_y0", 0);
-    VC_ROI::roi_x1 = cvReadIntByName(fs, nullptr, "roi_x1", 0);
-    VC_ROI::roi_y1 = cvReadIntByName(fs, nullptr, "roi_y1", 0);
-    showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-    cvReleaseFileStorage(&fs);
+    cv::FileStorage fs;
+    fs.open(config_xml, cv::FileStorage::READ);
+    
+    fs["stopAt"] >> stopAt;
+    fs["input_resize_percent"] >> input_resize_percent;
+    fs["enableFlip"] >> enableFlip;
+    fs["use_roi"] >> VC_ROI::use_roi;
+    fs["roi_defined"] >> VC_ROI::roi_defined;
+    fs["roi_x0"] >> VC_ROI::roi_x0;
+    fs["roi_y0"] >> VC_ROI::roi_y0;
+    fs["roi_x1"] >> VC_ROI::roi_x1;
+    fs["roi_y1"] >> VC_ROI::roi_y1;
+    fs["showOutput"] >> showOutput;
+    
+    fs.release();
   }
 }
diff --git a/src/VideoCapture.h b/src/VideoCapture.h
new file mode 100644
index 0000000..9a3bf82
--- /dev/null
+++ b/src/VideoCapture.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <iostream>
+#include <fstream>
+#include <memory>
+//#include <chrono>
+//#include <thread>
+#include <opencv2/opencv.hpp>
+//#include <opencv2/highgui/highgui_c.h>
+//#include <opencv2/imgproc/imgproc_c.h>
+//#include <opencv2/imgproc/types_c.h>
+
+#include "Config.h"
+#include "IFrameProcessor.h"
+#include "package_bgs/ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  class VideoCapture : public ILoadSaveConfig
+  {
+  private:
+    std::shared_ptr<IFrameProcessor> frameProcessor;
+    cv::VideoCapture capture;
+    cv::Mat frame;
+    int key;
+    int64 start_time;
+    int64 delta_time;
+    double freq;
+    double fps;
+    int frameNumber;
+    int stopAt;
+    bool useCamera;
+    int cameraIndex;
+    bool useVideo;
+    std::string videoFileName;
+    int input_resize_percent;
+    bool showOutput;
+    bool enableFlip;
+    double loopDelay = 33.333;
+    bool firstTime = true;
+
+  public:
+    VideoCapture();
+    ~VideoCapture();
+
+    void setFrameProcessor(std::shared_ptr<IFrameProcessor> frameProcessorPtr);
+    void setCamera(int cameraIndex);
+    void setVideo(std::string filename);
+    void start();
+
+  private:
+    void setUpCamera();
+    void setUpVideo();
+
+    void saveConfig();
+    void loadConfig();
+  };
+}
diff --git a/package_analysis/ForegroundMaskAnalysis.cpp b/src/package_analysis/ForegroundMaskAnalysis.cpp
similarity index 54%
rename from package_analysis/ForegroundMaskAnalysis.cpp
rename to src/package_analysis/ForegroundMaskAnalysis.cpp
index eddc908..d47ae83 100644
--- a/package_analysis/ForegroundMaskAnalysis.cpp
+++ b/src/package_analysis/ForegroundMaskAnalysis.cpp
@@ -1,26 +1,13 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "ForegroundMaskAnalysis.h"
 
 namespace bgslibrary
 {
-  ForegroundMaskAnalysis::ForegroundMaskAnalysis() : firstTime(true), showOutput(true), stopAt(0), img_ref_path("")
+  ForegroundMaskAnalysis::ForegroundMaskAnalysis() :
+    firstTime(true), showOutput(true),
+    stopAt(0), img_ref_path("")
   {
     std::cout << "ForegroundMaskAnalysis()" << std::endl;
+    setup("./config/ForegroundMaskAnalysis.xml");
   }
 
   ForegroundMaskAnalysis::~ForegroundMaskAnalysis()
@@ -84,21 +71,22 @@ namespace bgslibrary
 
   void ForegroundMaskAnalysis::saveConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage("./config/ForegroundMaskAnalysis.xml", 0, CV_STORAGE_WRITE);
-
-    cvWriteInt(fs, "stopAt", stopAt);
-    cvWriteString(fs, "img_ref_path", img_ref_path.c_str());
-
-    cvReleaseFileStorage(&fs);
+    cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+    
+    fs << "stopAt" << stopAt;
+    fs << "img_ref_path" << img_ref_path;
+    
+    fs.release();
   }
 
   void ForegroundMaskAnalysis::loadConfig()
   {
-    CvFileStorage* fs = cvOpenFileStorage("./config/ForegroundMaskAnalysis.xml", 0, CV_STORAGE_READ);
-
-    stopAt = cvReadIntByName(fs, 0, "stopAt", 0);
-    img_ref_path = cvReadStringByName(fs, 0, "img_ref_path", "");
-
-    cvReleaseFileStorage(&fs);
+    cv::FileStorage fs;
+    fs.open(config_xml, cv::FileStorage::READ);
+    
+    fs["stopAt"] >> stopAt;
+    fs["img_ref_path"] >> img_ref_path;
+    
+    fs.release();
   }
 }
diff --git a/package_analysis/ForegroundMaskAnalysis.h b/src/package_analysis/ForegroundMaskAnalysis.h
similarity index 50%
rename from package_analysis/ForegroundMaskAnalysis.h
rename to src/package_analysis/ForegroundMaskAnalysis.h
index 0a64ab2..92f43cb 100644
--- a/package_analysis/ForegroundMaskAnalysis.h
+++ b/src/package_analysis/ForegroundMaskAnalysis.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <iostream>
@@ -27,9 +11,11 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include <opencv2/imgproc/imgproc_c.h>
 #include <opencv2/highgui/highgui_c.h>
 
+#include "../package_bgs/ILoadSaveConfig.h"
+
 namespace bgslibrary
 {
-  class ForegroundMaskAnalysis
+  class ForegroundMaskAnalysis: public ILoadSaveConfig
   {
   private:
     bool firstTime;
@@ -39,7 +25,7 @@ namespace bgslibrary
     ForegroundMaskAnalysis();
     ~ForegroundMaskAnalysis();
 
-    long stopAt;
+    int stopAt;
     std::string img_ref_path;
 
     void process(const long &frameNumber, const std::string &name, const cv::Mat &img_input);
diff --git a/package_analysis/PerformanceUtils.cpp b/src/package_analysis/PerformanceUtils.cpp
similarity index 95%
rename from package_analysis/PerformanceUtils.cpp
rename to src/package_analysis/PerformanceUtils.cpp
index 6ad5e5f..85d34af 100644
--- a/package_analysis/PerformanceUtils.cpp
+++ b/src/package_analysis/PerformanceUtils.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "PerformanceUtils.h"
 //#include <opencv2/legacy/compat.hpp>
 //#include <opencv2/highgui/highgui_c.h>
diff --git a/package_analysis/PerformanceUtils.h b/src/package_analysis/PerformanceUtils.h
similarity index 60%
rename from package_analysis/PerformanceUtils.h
rename to src/package_analysis/PerformanceUtils.h
index 4be392f..064d3f1 100644
--- a/package_analysis/PerformanceUtils.h
+++ b/src/package_analysis/PerformanceUtils.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <stdio.h>
@@ -39,4 +23,3 @@ public:
   void ImageROC(IplImage *image, IplImage* ground_truth, bool saveResults = false, std::string filename = "");
   void PerformanceEvaluation(IplImage *image, IplImage *ground_truth, bool saveResults = false, std::string filename = "", bool debug = false);
 };
-
diff --git a/package_analysis/PixelUtils.cpp b/src/package_analysis/PixelUtils.cpp
similarity index 93%
rename from package_analysis/PixelUtils.cpp
rename to src/package_analysis/PixelUtils.cpp
index adce122..1f7e38f 100644
--- a/package_analysis/PixelUtils.cpp
+++ b/src/package_analysis/PixelUtils.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "PixelUtils.h"
 
 PixelUtils::PixelUtils(void) {}
diff --git a/package_analysis/PixelUtils.h b/src/package_analysis/PixelUtils.h
similarity index 68%
rename from package_analysis/PixelUtils.h
rename to src/package_analysis/PixelUtils.h
index 0ae6f73..b48866a 100644
--- a/package_analysis/PixelUtils.h
+++ b/src/package_analysis/PixelUtils.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <stdio.h>
diff --git a/package_bgs/AdaptiveBackgroundLearning.cpp b/src/package_bgs/AdaptiveBackgroundLearning.cpp
similarity index 60%
rename from package_bgs/AdaptiveBackgroundLearning.cpp
rename to src/package_bgs/AdaptiveBackgroundLearning.cpp
index d2cb8a0..3cace90 100644
--- a/package_bgs/AdaptiveBackgroundLearning.cpp
+++ b/src/package_bgs/AdaptiveBackgroundLearning.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "AdaptiveBackgroundLearning.h"
 
 using namespace bgslibrary::algorithms;
@@ -84,26 +68,27 @@ void AdaptiveBackgroundLearning::process(const cv::Mat &img_input, cv::Mat &img_
 
 void AdaptiveBackgroundLearning::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), 0, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "limit", limit);
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "alpha" << alpha;
+  fs << "limit" << limit;
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void AdaptiveBackgroundLearning::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.05);
-  limit = cvReadIntByName(fs, nullptr, "limit", -1);
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["alpha"] >> alpha;
+  fs["limit"] >> limit;
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
diff --git a/src/package_bgs/AdaptiveBackgroundLearning.h b/src/package_bgs/AdaptiveBackgroundLearning.h
new file mode 100644
index 0000000..c7b4572
--- /dev/null
+++ b/src/package_bgs/AdaptiveBackgroundLearning.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class AdaptiveBackgroundLearning : 
+      public IBGS, public ILoadSaveConfig
+    {
+    private:
+      double alpha;
+      int limit;
+      long counter;
+      double minVal;
+      double maxVal;
+      bool enableThreshold;
+      int threshold;
+
+    public:
+      AdaptiveBackgroundLearning();
+      ~AdaptiveBackgroundLearning();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<AdaptiveBackgroundLearning> 
+      register_AdaptiveBackgroundLearning("AdaptiveBackgroundLearning");
+  }
+}
diff --git a/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp b/src/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp
similarity index 67%
rename from package_bgs/AdaptiveSelectiveBackgroundLearning.cpp
rename to src/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp
index 2f6f9fe..45c85da 100644
--- a/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp
+++ b/src/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "AdaptiveSelectiveBackgroundLearning.h"
 
 using namespace bgslibrary::algorithms;
@@ -105,26 +89,27 @@ void AdaptiveSelectiveBackgroundLearning::process(const cv::Mat &img_input_, cv:
 
 void AdaptiveSelectiveBackgroundLearning::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "learningFrames", learningFrames);
-  cvWriteReal(fs, "alphaLearn", alphaLearn);
-  cvWriteReal(fs, "alphaDetection", alphaDetection);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "learningFrames" << learningFrames;
+  fs << "alphaLearn" << alphaLearn;
+  fs << "alphaDetection" << alphaDetection;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void AdaptiveSelectiveBackgroundLearning::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), 0, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  learningFrames = cvReadIntByName(fs, nullptr, "learningFrames", 90);
-  alphaLearn = cvReadRealByName(fs, nullptr, "alphaLearn", 0.05);
-  alphaDetection = cvReadRealByName(fs, nullptr, "alphaDetection", 0.05);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 25);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["learningFrames"] >> learningFrames;
+  fs["alphaLearn"] >> alphaLearn;
+  fs["alphaDetection"] >> alphaDetection;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
diff --git a/src/package_bgs/AdaptiveSelectiveBackgroundLearning.h b/src/package_bgs/AdaptiveSelectiveBackgroundLearning.h
new file mode 100644
index 0000000..468388f
--- /dev/null
+++ b/src/package_bgs/AdaptiveSelectiveBackgroundLearning.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class AdaptiveSelectiveBackgroundLearning : 
+      public IBGS, public ILoadSaveConfig
+    {
+    private:
+      double alphaLearn;
+      double alphaDetection;
+      int learningFrames;
+      long counter;
+      double minVal;
+      double maxVal;
+      int threshold;
+
+    public:
+      AdaptiveSelectiveBackgroundLearning();
+      ~AdaptiveSelectiveBackgroundLearning();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<AdaptiveSelectiveBackgroundLearning> 
+      sregister_AdaptiveSelectiveBackgroundLearning("AdaptiveSelectiveBackgroundLearning");
+  }
+}
diff --git a/package_bgs/CodeBook.cpp b/src/package_bgs/CodeBook.cpp
similarity index 77%
rename from package_bgs/CodeBook.cpp
rename to src/package_bgs/CodeBook.cpp
index 1ea0271..b5cf9c4 100644
--- a/package_bgs/CodeBook.cpp
+++ b/src/package_bgs/CodeBook.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "CodeBook.h"
 
 using namespace bgslibrary::algorithms;
@@ -200,24 +184,25 @@ void CodeBook::fg_cb(const cv::Mat& frame, cv::Mat& fg)
 
 void CodeBook::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "alpha", alpha);
-  cvWriteReal(fs, "beta", beta);
-  cvWriteInt(fs, "learningFrames", learningFrames);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "alpha" << alpha;
+  fs << "beta" << beta;
+  fs << "learningFrames" << learningFrames;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void CodeBook::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  alpha = cvReadIntByName(fs, nullptr, "alpha", DEFAULT_ALPHA);
-  beta = cvReadRealByName(fs, nullptr, "beta", DEFAULT_BETA);
-  learningFrames = cvReadIntByName(fs, nullptr, "learningFrames", DEFAULT_LEARNFRAMES);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["alpha"] >> alpha;
+  fs["beta"] >> beta;
+  fs["learningFrames"] >> learningFrames;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
diff --git a/package_bgs/CodeBook.h b/src/package_bgs/CodeBook.h
similarity index 61%
rename from package_bgs/CodeBook.h
rename to src/package_bgs/CodeBook.h
index 316600d..ba751ae 100644
--- a/package_bgs/CodeBook.h
+++ b/src/package_bgs/CodeBook.h
@@ -1,24 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <opencv2/opencv.hpp>
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 
 namespace bgslibrary
 {
@@ -34,7 +19,7 @@ namespace bgslibrary
       bool isStale;
     };
 
-    class CodeBook : public IBGS
+    class CodeBook : public IBGS, public ILoadSaveConfig
     {
     private:
       static const int Tdel = 200;
diff --git a/package_bgs/DPAdaptiveMedian.cpp b/src/package_bgs/DPAdaptiveMedian.cpp
similarity index 61%
rename from package_bgs/DPAdaptiveMedian.cpp
rename to src/package_bgs/DPAdaptiveMedian.cpp
index 0885580..2427fec 100644
--- a/package_bgs/DPAdaptiveMedian.cpp
+++ b/src/package_bgs/DPAdaptiveMedian.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPAdaptiveMedian.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPAdaptiveMedian::DPAdaptiveMedian() :
@@ -87,24 +73,27 @@ void DPAdaptiveMedian::process(const cv::Mat &img_input, cv::Mat &img_output, cv
 
 void DPAdaptiveMedian::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "samplingRate", samplingRate);
-  cvWriteInt(fs, "learningFrames", learningFrames);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "threshold" << threshold;
+  fs << "samplingRate" << samplingRate;
+  fs << "learningFrames" << learningFrames;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void DPAdaptiveMedian::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 40);
-  samplingRate = cvReadIntByName(fs, nullptr, "samplingRate", 7);
-  learningFrames = cvReadIntByName(fs, nullptr, "learningFrames", 30);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["threshold"] >> threshold;
+  fs["samplingRate"] >> samplingRate;
+  fs["learningFrames"] >> learningFrames;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPAdaptiveMedian.h b/src/package_bgs/DPAdaptiveMedian.h
similarity index 53%
rename from package_bgs/DPAdaptiveMedian.h
rename to src/package_bgs/DPAdaptiveMedian.h
index 990f048..6426c60 100644
--- a/package_bgs/DPAdaptiveMedian.h
+++ b/src/package_bgs/DPAdaptiveMedian.h
@@ -1,22 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "dp/AdaptiveMedianBGS.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +13,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPAdaptiveMedian : public IBGS
+    class DPAdaptiveMedian : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -53,3 +41,5 @@ namespace bgslibrary
     static BGS_Register<DPAdaptiveMedian> register_DPAdaptiveMedian("DPAdaptiveMedian");
   }
 }
+
+#endif
diff --git a/package_bgs/DPEigenbackground.cpp b/src/package_bgs/DPEigenbackground.cpp
similarity index 61%
rename from package_bgs/DPEigenbackground.cpp
rename to src/package_bgs/DPEigenbackground.cpp
index 75763ce..1b6cc34 100644
--- a/package_bgs/DPEigenbackground.cpp
+++ b/src/package_bgs/DPEigenbackground.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPEigenbackground.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPEigenbackground::DPEigenbackground() :
@@ -86,24 +72,27 @@ void DPEigenbackground::process(const cv::Mat &img_input, cv::Mat &img_output, c
 
 void DPEigenbackground::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "historySize", historySize);
-  cvWriteInt(fs, "embeddedDim", embeddedDim);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "threshold" << threshold;
+  fs << "historySize" << historySize;
+  fs << "embeddedDim" << embeddedDim;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void DPEigenbackground::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 225);
-  historySize = cvReadIntByName(fs, nullptr, "historySize", 20);
-  embeddedDim = cvReadIntByName(fs, nullptr, "embeddedDim", 10);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["threshold"] >> threshold;
+  fs["historySize"] >> historySize;
+  fs["embeddedDim"] >> embeddedDim;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPEigenbackground.h b/src/package_bgs/DPEigenbackground.h
similarity index 53%
rename from package_bgs/DPEigenbackground.h
rename to src/package_bgs/DPEigenbackground.h
index d962559..90efc7e 100644
--- a/package_bgs/DPEigenbackground.h
+++ b/src/package_bgs/DPEigenbackground.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/Eigenbackground.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +14,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPEigenbackground : public IBGS
+    class DPEigenbackground : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -55,3 +44,5 @@ namespace bgslibrary
     static BGS_Register<DPEigenbackground> register_DPEigenbackground("DPEigenbackground");
   }
 }
+
+#endif
diff --git a/package_bgs/DPGrimsonGMM.cpp b/src/package_bgs/DPGrimsonGMM.cpp
similarity index 60%
rename from package_bgs/DPGrimsonGMM.cpp
rename to src/package_bgs/DPGrimsonGMM.cpp
index c72b4d2..6978a90 100644
--- a/package_bgs/DPGrimsonGMM.cpp
+++ b/src/package_bgs/DPGrimsonGMM.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPGrimsonGMM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPGrimsonGMM::DPGrimsonGMM() :
@@ -85,24 +71,27 @@ void DPGrimsonGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Ma
 
 void DPGrimsonGMM::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "gaussians", gaussians);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "gaussians" << gaussians;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void DPGrimsonGMM::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 9.0);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.01);
-  gaussians = cvReadIntByName(fs, nullptr, "gaussians", 3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["gaussians"] >> gaussians;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPGrimsonGMM.h b/src/package_bgs/DPGrimsonGMM.h
similarity index 52%
rename from package_bgs/DPGrimsonGMM.h
rename to src/package_bgs/DPGrimsonGMM.h
index 954261f..82503b7 100644
--- a/package_bgs/DPGrimsonGMM.h
+++ b/src/package_bgs/DPGrimsonGMM.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/GrimsonGMM.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +14,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPGrimsonGMM : public IBGS
+    class DPGrimsonGMM : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -55,3 +44,5 @@ namespace bgslibrary
     static BGS_Register<DPGrimsonGMM> register_DPGrimsonGMM("DPGrimsonGMM");
   }
 }
+
+#endif
diff --git a/package_bgs/DPMean.cpp b/src/package_bgs/DPMean.cpp
similarity index 57%
rename from package_bgs/DPMean.cpp
rename to src/package_bgs/DPMean.cpp
index 3af1fb6..906b961 100644
--- a/package_bgs/DPMean.cpp
+++ b/src/package_bgs/DPMean.cpp
@@ -1,25 +1,12 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPMean.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPMean::DPMean() :
-  frameNumber(0), threshold(2700), alpha(1e-6f), learningFrames(30)
+  frameNumber(0), threshold(2700),
+  alpha(1e-6f), learningFrames(30)
 {
   std::cout << "DPMean()" << std::endl;
   setup("./config/DPMean.xml");
@@ -85,24 +72,27 @@ void DPMean::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img
 
 void DPMean::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "learningFrames", learningFrames);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "learningFrames" << learningFrames;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void DPMean::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 2700);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 1e-6f);
-  learningFrames = cvReadIntByName(fs, nullptr, "learningFrames", 30);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["learningFrames"] >> learningFrames;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPMean.h b/src/package_bgs/DPMean.h
similarity index 51%
rename from package_bgs/DPMean.h
rename to src/package_bgs/DPMean.h
index ad63762..1135673 100644
--- a/package_bgs/DPMean.h
+++ b/src/package_bgs/DPMean.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/MeanBGS.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +14,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPMean : public IBGS
+    class DPMean : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -55,3 +44,5 @@ namespace bgslibrary
     static BGS_Register<DPMean> register_DPMean("DPMean");
   }
 }
+
+#endif
diff --git a/package_bgs/DPPratiMediod.cpp b/src/package_bgs/DPPratiMediod.cpp
similarity index 59%
rename from package_bgs/DPPratiMediod.cpp
rename to src/package_bgs/DPPratiMediod.cpp
index d1942c5..037cd06 100644
--- a/package_bgs/DPPratiMediod.cpp
+++ b/src/package_bgs/DPPratiMediod.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPPratiMediod.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPPratiMediod::DPPratiMediod() :
@@ -87,26 +73,29 @@ void DPPratiMediod::process(const cv::Mat &img_input, cv::Mat &img_output, cv::M
 
 void DPPratiMediod::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "samplingRate", samplingRate);
-  cvWriteInt(fs, "historySize", historySize);
-  cvWriteInt(fs, "weight", weight);
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "threshold" << threshold;
+  fs << "samplingRate" << samplingRate;
+  fs << "historySize" << historySize;
+  fs << "weight" << weight;
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void DPPratiMediod::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 30);
-  samplingRate = cvReadIntByName(fs, nullptr, "samplingRate", 5);
-  historySize = cvReadIntByName(fs, nullptr, "historySize", 16);
-  weight = cvReadIntByName(fs, nullptr, "weight", 5);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
+  fs["threshold"] >> threshold;
+  fs["samplingRate"] >> samplingRate;
+  fs["historySize"] >> historySize;
+  fs["weight"] >> weight;
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPPratiMediod.h b/src/package_bgs/DPPratiMediod.h
similarity index 53%
rename from package_bgs/DPPratiMediod.h
rename to src/package_bgs/DPPratiMediod.h
index d71accc..cb70160 100644
--- a/package_bgs/DPPratiMediod.h
+++ b/src/package_bgs/DPPratiMediod.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/PratiMediodBGS.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +14,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPPratiMediod : public IBGS
+    class DPPratiMediod : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -56,3 +45,5 @@ namespace bgslibrary
     static BGS_Register<DPPratiMediod> register_DPPratiMediod("DPPratiMediod");
   }
 }
+
+#endif
diff --git a/package_bgs/DPTexture.cpp b/src/package_bgs/DPTexture.cpp
similarity index 74%
rename from package_bgs/DPTexture.cpp
rename to src/package_bgs/DPTexture.cpp
index 3285ccf..9f0b1bd 100644
--- a/package_bgs/DPTexture.cpp
+++ b/src/package_bgs/DPTexture.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPTexture.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPTexture::DPTexture()
@@ -138,22 +124,25 @@ void DPTexture::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
 void DPTexture::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  //cvWriteReal(fs, "alpha", alpha);
-  //cvWriteInt(fs, "enableFiltering", enableFiltering);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  //fs << "alpha" << alpha;
+  //fs << "enableFiltering" << enableFiltering;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void DPTexture::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  //alpha = cvReadRealByName(fs, nullptr, "alpha", 1e-6f);
-  //enableFiltering = cvReadIntByName(fs, nullptr, "enableFiltering", true);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  //fs["alpha"] >> alpha;
+  //fs["enableFiltering"] >> enableFiltering;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPTexture.h b/src/package_bgs/DPTexture.h
similarity index 57%
rename from package_bgs/DPTexture.h
rename to src/package_bgs/DPTexture.h
index 38321e4..ca73463 100644
--- a/package_bgs/DPTexture.h
+++ b/src/package_bgs/DPTexture.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/TextureBGS.h"
 //#include "ConnectedComponents.h"
 
@@ -24,7 +13,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPTexture : public IBGS
+    class DPTexture : public IBGS, public ILoadSaveConfig
     {
     private:
       int width;
@@ -59,3 +48,5 @@ namespace bgslibrary
     static BGS_Register<DPTexture> register_DPTextured("DPTexture");
   }
 }
+
+#endif
diff --git a/package_bgs/DPWrenGA.cpp b/src/package_bgs/DPWrenGA.cpp
similarity index 59%
rename from package_bgs/DPWrenGA.cpp
rename to src/package_bgs/DPWrenGA.cpp
index 7fc3313..9706785 100644
--- a/package_bgs/DPWrenGA.cpp
+++ b/src/package_bgs/DPWrenGA.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPWrenGA.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPWrenGA::DPWrenGA() :
@@ -84,24 +70,27 @@ void DPWrenGA::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &i
 
 void DPWrenGA::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "learningFrames", learningFrames);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "learningFrames" << learningFrames;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void DPWrenGA::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 12.25f);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.005f);
-  learningFrames = cvReadIntByName(fs, nullptr, "learningFrames", 30);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["learningFrames"] >> learningFrames;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPWrenGA.h b/src/package_bgs/DPWrenGA.h
similarity index 51%
rename from package_bgs/DPWrenGA.h
rename to src/package_bgs/DPWrenGA.h
index d708692..9116a20 100644
--- a/package_bgs/DPWrenGA.h
+++ b/src/package_bgs/DPWrenGA.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/WrenGA.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +14,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPWrenGA : public IBGS
+    class DPWrenGA : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -55,3 +44,5 @@ namespace bgslibrary
     static BGS_Register<DPWrenGA> register_DPWrenGA("DPWrenGA");
   }
 }
+
+#endif
diff --git a/package_bgs/DPZivkovicAGMM.cpp b/src/package_bgs/DPZivkovicAGMM.cpp
similarity index 60%
rename from package_bgs/DPZivkovicAGMM.cpp
rename to src/package_bgs/DPZivkovicAGMM.cpp
index a5a9735..0877cf1 100644
--- a/package_bgs/DPZivkovicAGMM.cpp
+++ b/src/package_bgs/DPZivkovicAGMM.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "DPZivkovicAGMM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 DPZivkovicAGMM::DPZivkovicAGMM() :
@@ -84,24 +70,27 @@ void DPZivkovicAGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::
 
 void DPZivkovicAGMM::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "gaussians", gaussians);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "gaussians" << gaussians;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void DPZivkovicAGMM::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 25.0f);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.001f);
-  gaussians = cvReadIntByName(fs, nullptr, "gaussians", 3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["gaussians"] >> gaussians;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/DPZivkovicAGMM.h b/src/package_bgs/DPZivkovicAGMM.h
similarity index 52%
rename from package_bgs/DPZivkovicAGMM.h
rename to src/package_bgs/DPZivkovicAGMM.h
index 25f4d4d..cdbc16f 100644
--- a/package_bgs/DPZivkovicAGMM.h
+++ b/src/package_bgs/DPZivkovicAGMM.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "dp/ZivkovicAGMM.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +14,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class DPZivkovicAGMM : public IBGS
+    class DPZivkovicAGMM : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -55,3 +44,5 @@ namespace bgslibrary
     static BGS_Register<DPZivkovicAGMM> register_DPZivkovicAGMM("DPZivkovicAGMM");
   }
 }
+
+#endif
diff --git a/src/package_bgs/FrameDifference.cpp b/src/package_bgs/FrameDifference.cpp
new file mode 100644
index 0000000..f2ac50c
--- /dev/null
+++ b/src/package_bgs/FrameDifference.cpp
@@ -0,0 +1,69 @@
+#include "FrameDifference.h"
+
+using namespace bgslibrary::algorithms;
+
+FrameDifference::FrameDifference() :
+  enableThreshold(true), threshold(15)
+{
+  std::cout << "FrameDifference()" << std::endl;
+  setup("./config/FrameDifference.xml");
+}
+
+FrameDifference::~FrameDifference()
+{
+  std::cout << "~FrameDifference()" << std::endl;
+}
+
+void FrameDifference::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  if (img_background.empty())
+  {
+    img_input.copyTo(img_background);
+    return;
+  }
+
+  cv::absdiff(img_background, img_input, img_foreground);
+
+  if (img_foreground.channels() == 3)
+    cv::cvtColor(img_foreground, img_foreground, CV_BGR2GRAY);
+
+  if (enableThreshold)
+    cv::threshold(img_foreground, img_foreground, threshold, 255, cv::THRESH_BINARY);
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+    cv::imshow("Frame Difference", img_foreground);
+#endif
+
+  img_foreground.copyTo(img_output);
+
+  img_input.copyTo(img_background);
+  img_background.copyTo(img_bgmodel);
+
+  firstTime = false;
+}
+
+void FrameDifference::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void FrameDifference::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
diff --git a/src/package_bgs/FrameDifference.h b/src/package_bgs/FrameDifference.h
new file mode 100644
index 0000000..b2bf439
--- /dev/null
+++ b/src/package_bgs/FrameDifference.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class FrameDifference : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      bool enableThreshold;
+      int threshold;
+
+    public:
+      FrameDifference();
+      ~FrameDifference();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<FrameDifference> register_FrameDifference("FrameDifference");
+  }
+}
+
diff --git a/package_bgs/FuzzyChoquetIntegral.cpp b/src/package_bgs/FuzzyChoquetIntegral.cpp
similarity index 77%
rename from package_bgs/FuzzyChoquetIntegral.cpp
rename to src/package_bgs/FuzzyChoquetIntegral.cpp
index 3d24126..ee8aac0 100644
--- a/package_bgs/FuzzyChoquetIntegral.cpp
+++ b/src/package_bgs/FuzzyChoquetIntegral.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "FuzzyChoquetIntegral.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 FuzzyChoquetIntegral::FuzzyChoquetIntegral() :
@@ -183,32 +169,35 @@ void FuzzyChoquetIntegral::process(const cv::Mat &img_input, cv::Mat &img_output
 
 void FuzzyChoquetIntegral::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-  cvWriteInt(fs, "framesToLearn", framesToLearn);
-  cvWriteReal(fs, "alphaLearn", alphaLearn);
-  cvWriteReal(fs, "alphaUpdate", alphaUpdate);
-  cvWriteInt(fs, "colorSpace", colorSpace);
-  cvWriteInt(fs, "option", option);
-  cvWriteInt(fs, "smooth", smooth);
-  cvWriteReal(fs, "threshold", threshold);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "framesToLearn" << framesToLearn;
+  fs << "alphaLearn" << alphaLearn;
+  fs << "alphaUpdate" << alphaUpdate;
+  fs << "colorSpace" << colorSpace;
+  fs << "option" << option;
+  fs << "smooth" << smooth;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void FuzzyChoquetIntegral::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-  framesToLearn = cvReadIntByName(fs, nullptr, "framesToLearn", 10);
-  alphaLearn = cvReadRealByName(fs, nullptr, "alphaLearn", 0.1);
-  alphaUpdate = cvReadRealByName(fs, nullptr, "alphaUpdate", 0.01);
-  colorSpace = cvReadIntByName(fs, nullptr, "colorSpace", 1);
-  option = cvReadIntByName(fs, nullptr, "option", 2);
-  smooth = cvReadIntByName(fs, nullptr, "smooth", true);
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 0.67);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["framesToLearn"] >> framesToLearn;
+  fs["alphaLearn"] >> alphaLearn;
+  fs["alphaUpdate"] >> alphaUpdate;
+  fs["colorSpace"] >> colorSpace;
+  fs["option"] >> option;
+  fs["smooth"] >> smooth;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/FuzzyChoquetIntegral.h b/src/package_bgs/FuzzyChoquetIntegral.h
new file mode 100644
index 0000000..9a57f30
--- /dev/null
+++ b/src/package_bgs/FuzzyChoquetIntegral.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "T2F/FuzzyUtils.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class FuzzyChoquetIntegral : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      long long frameNumber;
+      
+      int framesToLearn;
+      double alphaLearn;
+      double alphaUpdate;
+      int colorSpace;
+      int option;
+      bool smooth;
+      double threshold;
+
+      FuzzyUtils fu;
+      cv::Mat img_background_f3;
+
+    public:
+      FuzzyChoquetIntegral();
+      ~FuzzyChoquetIntegral();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<FuzzyChoquetIntegral> register_FuzzyChoquetIntegral("FuzzyChoquetIntegral");
+  }
+}
+
+#endif
diff --git a/package_bgs/FuzzySugenoIntegral.cpp b/src/package_bgs/FuzzySugenoIntegral.cpp
similarity index 77%
rename from package_bgs/FuzzySugenoIntegral.cpp
rename to src/package_bgs/FuzzySugenoIntegral.cpp
index e62fa02..e4b3cf2 100644
--- a/package_bgs/FuzzySugenoIntegral.cpp
+++ b/src/package_bgs/FuzzySugenoIntegral.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "FuzzySugenoIntegral.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 FuzzySugenoIntegral::FuzzySugenoIntegral() :
@@ -183,32 +169,35 @@ void FuzzySugenoIntegral::process(const cv::Mat &img_input, cv::Mat &img_output,
 
 void FuzzySugenoIntegral::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-  cvWriteInt(fs, "framesToLearn", framesToLearn);
-  cvWriteReal(fs, "alphaLearn", alphaLearn);
-  cvWriteReal(fs, "alphaUpdate", alphaUpdate);
-  cvWriteInt(fs, "colorSpace", colorSpace);
-  cvWriteInt(fs, "option", option);
-  cvWriteInt(fs, "smooth", smooth);
-  cvWriteReal(fs, "threshold", threshold);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "framesToLearn" << framesToLearn;
+  fs << "alphaLearn" << alphaLearn;
+  fs << "alphaUpdate" << alphaUpdate;
+  fs << "colorSpace" << colorSpace;
+  fs << "option" << option;
+  fs << "smooth" << smooth;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void FuzzySugenoIntegral::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-  framesToLearn = cvReadIntByName(fs, nullptr, "framesToLearn", 10);
-  alphaLearn = cvReadRealByName(fs, nullptr, "alphaLearn", 0.1);
-  alphaUpdate = cvReadRealByName(fs, nullptr, "alphaUpdate", 0.01);
-  colorSpace = cvReadIntByName(fs, nullptr, "colorSpace", 1);
-  option = cvReadIntByName(fs, nullptr, "option", 2);
-  smooth = cvReadIntByName(fs, nullptr, "smooth", true);
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 0.67);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["framesToLearn"] >> framesToLearn;
+  fs["alphaLearn"] >> alphaLearn;
+  fs["alphaUpdate"] >> alphaUpdate;
+  fs["colorSpace"] >> colorSpace;
+  fs["option"] >> option;
+  fs["smooth"] >> smooth;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/FuzzySugenoIntegral.h b/src/package_bgs/FuzzySugenoIntegral.h
similarity index 50%
rename from package_bgs/FuzzySugenoIntegral.h
rename to src/package_bgs/FuzzySugenoIntegral.h
index 1cd913f..7f42a11 100644
--- a/package_bgs/FuzzySugenoIntegral.h
+++ b/src/package_bgs/FuzzySugenoIntegral.h
@@ -1,29 +1,18 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "T2F/FuzzyUtils.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class FuzzySugenoIntegral : public IBGS
+    class FuzzySugenoIntegral : public IBGS, public ILoadSaveConfig
     {
     private:
       long long frameNumber;
@@ -53,3 +42,5 @@ namespace bgslibrary
     static BGS_Register<FuzzySugenoIntegral> register_FuzzySugenoIntegral("FuzzySugenoIntegral");
   }
 }
+
+#endif
diff --git a/package_bgs/GMG.cpp b/src/package_bgs/GMG.cpp
similarity index 53%
rename from package_bgs/GMG.cpp
rename to src/package_bgs/GMG.cpp
index 8fdc5a4..af66459 100644
--- a/package_bgs/GMG.cpp
+++ b/src/package_bgs/GMG.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "GMG.h"
 
 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
@@ -75,24 +59,25 @@ void GMG::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bg
 
 void GMG::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "initializationFrames", initializationFrames);
-  cvWriteReal(fs, "decisionThreshold", decisionThreshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "initializationFrames" << initializationFrames;
+  fs << "decisionThreshold" << decisionThreshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void GMG::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  initializationFrames = cvReadIntByName(fs, nullptr, "initializationFrames", 20);
-  decisionThreshold = cvReadRealByName(fs, nullptr, "decisionThreshold", 0.7);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["initializationFrames"] >> initializationFrames;
+  fs["decisionThreshold"] >> decisionThreshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
 
 #endif
diff --git a/src/package_bgs/GMG.h b/src/package_bgs/GMG.h
new file mode 100644
index 0000000..ebf8038
--- /dev/null
+++ b/src/package_bgs/GMG.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class GMG : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      cv::Ptr<cv::BackgroundSubtractorGMG> fgbg;
+      int initializationFrames;
+      double decisionThreshold;
+      cv::Mat img_segmentation;
+
+    public:
+      GMG();
+      ~GMG();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<GMG> register_GMG("GMG");
+  }
+}
+
+#endif
diff --git a/package_bgs/IBGS.h b/src/package_bgs/IBGS.h
similarity index 76%
rename from package_bgs/IBGS.h
rename to src/package_bgs/IBGS.h
index f08e4ee..a18a80a 100644
--- a/package_bgs/IBGS.h
+++ b/src/package_bgs/IBGS.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <iostream>
@@ -61,15 +45,6 @@ namespace bgslibrary
       bool showOutput = true;
       cv::Mat img_background;
       cv::Mat img_foreground;
-      std::string config_xml;
-      void setup(const std::string _config_xml) {
-        config_xml = _config_xml;
-        if (!config_xml.empty()) {
-          if (!std::ifstream(config_xml))
-            saveConfig();
-          loadConfig();
-        }
-      }
       void init(const cv::Mat &img_input, cv::Mat &img_outfg, cv::Mat &img_outbg) {
         assert(img_input.empty() == false);
         //img_outfg = cv::Mat::zeros(img_input.size(), img_input.type());
@@ -77,10 +52,6 @@ namespace bgslibrary
         img_outfg = cv::Mat::zeros(img_input.size(), CV_8UC1);
         img_outbg = cv::Mat::zeros(img_input.size(), CV_8UC3);
       }
-    
-    private:
-      virtual void saveConfig() = 0;
-      virtual void loadConfig() = 0;
     };
 
     class BGS_Factory
diff --git a/src/package_bgs/ILoadSaveConfig.h b/src/package_bgs/ILoadSaveConfig.h
new file mode 100644
index 0000000..1eaf002
--- /dev/null
+++ b/src/package_bgs/ILoadSaveConfig.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <iostream>
+#include <fstream>
+#include <string>
+
+namespace bgslibrary
+{
+  class ILoadSaveConfig
+  {
+  public:
+    virtual ~ILoadSaveConfig() {}
+
+  protected:
+    std::string config_xml;
+    void setup(const std::string _config_xml) {
+      config_xml = _config_xml;
+      if (!config_xml.empty()) {
+        if (!std::ifstream(config_xml))
+          saveConfig();
+        loadConfig();
+      }
+    }
+
+  private:
+    virtual void saveConfig() = 0;
+    virtual void loadConfig() = 0;
+  };
+}
diff --git a/package_bgs/IMBS/IMBS.cpp b/src/package_bgs/IMBS/IMBS.cpp
similarity index 94%
rename from package_bgs/IMBS/IMBS.cpp
rename to src/package_bgs/IMBS/IMBS.cpp
index 8319fd9..acf3c5b 100644
--- a/package_bgs/IMBS/IMBS.cpp
+++ b/src/package_bgs/IMBS/IMBS.cpp
@@ -1,40 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  IMBS Background Subtraction Library
-*
-*  This file imbs.hpp contains the C++ OpenCV based implementation for
-*  IMBS algorithm described in
-*  D. D. Bloisi and L. Iocchi
-*  "Independent Multimodal Background Subtraction"
-*  In Proc. of the Third Int. Conf. on Computational Modeling of Objects
-*  Presented in Images: Fundamentals, Methods and Applications, pp. 39-44, 2012.
-*  Please, cite the above paper if you use IMBS.
-*
-*  This software is provided without any warranty about its usability.
-*  It is for educational purposes and should be regarded as such.
-*
-*  Written by Domenico D. Bloisi
-*
-*  Please, report suggestions/comments/bugs to
-*  domenico.bloisi@gmail.com
-*
-*/
-
 #include "IMBS.hpp"
 
 using namespace std;
diff --git a/package_bgs/IMBS/IMBS.hpp b/src/package_bgs/IMBS/IMBS.hpp
similarity index 77%
rename from package_bgs/IMBS/IMBS.hpp
rename to src/package_bgs/IMBS/IMBS.hpp
index 808b63a..4f5d066 100644
--- a/package_bgs/IMBS/IMBS.hpp
+++ b/src/package_bgs/IMBS/IMBS.hpp
@@ -1,42 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  IMBS Background Subtraction Library
-*
-*  This file imbs.hpp contains the C++ OpenCV based implementation for
-*  IMBS algorithm described in
-*  D. D. Bloisi and L. Iocchi
-*  "Independent Multimodal Background Subtraction"
-*  In Proc. of the Third Int. Conf. on Computational Modeling of Objects
-*  Presented in Images: Fundamentals, Methods and Applications, pp. 39-44, 2012.
-*  Please, cite the above paper if you use IMBS.
-*
-*  This software is provided without any warranty about its usability.
-*  It is for educational purposes and should be regarded as such.
-*
-*  Written by Domenico D. Bloisi
-*
-*  Please, report suggestions/comments/bugs to
-*  domenico.bloisi@gmail.com
-*
-*/
 #pragma once
 
-//OPENCV
+#include <iostream>
+#include <vector>
+
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
@@ -44,9 +10,6 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include <opencv2/imgproc/types_c.h>
 #include <opencv2/imgproc/imgproc_c.h>
 #include <opencv2/highgui/highgui_c.h>
-//C++
-#include <iostream>
-#include <vector>
 
 using namespace cv;
 using namespace std;
diff --git a/package_bgs/IndependentMultimodal.cpp b/src/package_bgs/IndependentMultimodal.cpp
similarity index 51%
rename from package_bgs/IndependentMultimodal.cpp
rename to src/package_bgs/IndependentMultimodal.cpp
index 7b4de4c..2ba7786 100644
--- a/package_bgs/IndependentMultimodal.cpp
+++ b/src/package_bgs/IndependentMultimodal.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "IndependentMultimodal.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 IndependentMultimodal::IndependentMultimodal() : fps(10)
@@ -57,18 +43,21 @@ void IndependentMultimodal::process(const cv::Mat &img_input, cv::Mat &img_outpu
 
 void IndependentMultimodal::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void IndependentMultimodal::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/IndependentMultimodal.h b/src/package_bgs/IndependentMultimodal.h
new file mode 100644
index 0000000..1b78f9a
--- /dev/null
+++ b/src/package_bgs/IndependentMultimodal.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "IMBS/IMBS.hpp"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class IndependentMultimodal : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BackgroundSubtractorIMBS* pIMBS;
+      int fps;
+
+    public:
+      IndependentMultimodal();
+      ~IndependentMultimodal();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<IndependentMultimodal> register_IndependentMultimodal("IndependentMultimodal");
+  }
+}
+
+#endif
diff --git a/package_bgs/KDE.cpp b/src/package_bgs/KDE.cpp
similarity index 60%
rename from package_bgs/KDE.cpp
rename to src/package_bgs/KDE.cpp
index 28564a0..c481d46 100644
--- a/package_bgs/KDE.cpp
+++ b/src/package_bgs/KDE.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "KDE.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 KDE::KDE() :
@@ -102,32 +88,35 @@ void KDE::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bg
 
 void KDE::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "framesToLearn", framesToLearn);
-  cvWriteInt(fs, "SequenceLength", SequenceLength);
-  cvWriteInt(fs, "TimeWindowSize", TimeWindowSize);
-  cvWriteInt(fs, "SDEstimationFlag", SDEstimationFlag);
-  cvWriteInt(fs, "lUseColorRatiosFlag", lUseColorRatiosFlag);
-  cvWriteReal(fs, "th", th);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "framesToLearn" << framesToLearn;
+  fs << "SequenceLength" << SequenceLength;
+  fs << "TimeWindowSize" << TimeWindowSize;
+  fs << "SDEstimationFlag" << SDEstimationFlag;
+  fs << "lUseColorRatiosFlag" << lUseColorRatiosFlag;
+  fs << "th" << th;
+  fs << "alpha" << alpha;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void KDE::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  framesToLearn = cvReadIntByName(fs, nullptr, "framesToLearn", 10);
-  SequenceLength = cvReadIntByName(fs, nullptr, "SequenceLength", 50);
-  TimeWindowSize = cvReadIntByName(fs, nullptr, "TimeWindowSize", 100);
-  SDEstimationFlag = cvReadIntByName(fs, nullptr, "SDEstimationFlag", 1);
-  lUseColorRatiosFlag = cvReadIntByName(fs, nullptr, "lUseColorRatiosFlag", 1);
-  th = cvReadRealByName(fs, nullptr, "th", 10e-8);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["framesToLearn"] >> framesToLearn;
+  fs["SequenceLength"] >> SequenceLength;
+  fs["TimeWindowSize"] >> TimeWindowSize;
+  fs["SDEstimationFlag"] >> SDEstimationFlag;
+  fs["lUseColorRatiosFlag"] >> lUseColorRatiosFlag;
+  fs["th"] >> th;
+  fs["alpha"] >> alpha;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/KDE.h b/src/package_bgs/KDE.h
similarity index 53%
rename from package_bgs/KDE.h
rename to src/package_bgs/KDE.h
index 1589b69..87dd741 100644
--- a/package_bgs/KDE.h
+++ b/src/package_bgs/KDE.h
@@ -1,29 +1,18 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "KDE/NPBGSubtractor.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class KDE : public IBGS
+    class KDE : public IBGS, public ILoadSaveConfig
     {
     private:
       NPBGSubtractor *p;
@@ -57,3 +46,5 @@ namespace bgslibrary
     static BGS_Register<KDE> register_KDE("KDE");
   }
 }
+
+#endif
diff --git a/src/package_bgs/KDE/KernelTable.cpp b/src/package_bgs/KDE/KernelTable.cpp
new file mode 100644
index 0000000..0ab243b
--- /dev/null
+++ b/src/package_bgs/KDE/KernelTable.cpp
@@ -0,0 +1,69 @@
+#include <math.h>
+
+#include "KernelTable.h"
+
+#define PI 3.14159
+
+KernelLUTable::KernelLUTable()
+{
+  std::cout << "KernelLUTable()" << std::endl;
+}
+
+KernelLUTable::~KernelLUTable()
+{
+  delete kerneltable;
+  delete kernelsums;
+  std::cout << "~KernelLUTable()" << std::endl;
+}
+
+KernelLUTable::KernelLUTable(int KernelHalfWidth, double Segmamin, double Segmamax, int Segmabins)
+{
+  std::cout << "KernelLUTable()" << std::endl;
+
+  double C1, C2, v, segma, sum;
+  int bin, b;
+
+  minsegma = Segmamin;
+  maxsegma = Segmamax;
+  segmabins = Segmabins;
+  tablehalfwidth = KernelHalfWidth;
+
+  // Generate the Kernel
+
+  // allocate memory for the Kernal Table
+  kerneltable = new double[segmabins*(2 * KernelHalfWidth + 1)];
+  kernelsums = new double[segmabins];
+
+  double segmastep = (maxsegma - minsegma) / segmabins;
+  double y;
+
+  for (segma = minsegma, bin = 0; bin < segmabins; segma += segmastep, bin++)
+  {
+    C1 = 1 / (sqrt(2 * PI)*segma);
+    C2 = -1 / (2 * segma*segma);
+
+    b = (2 * KernelHalfWidth + 1)*bin;
+    sum = 0;
+
+    for (int x = 0; x <= KernelHalfWidth; x++)
+    {
+      y = x / 1.0;
+      v = C1*exp(C2*y*y);
+      kerneltable[b + KernelHalfWidth + x] = v;
+      kerneltable[b + KernelHalfWidth - x] = v;
+      sum += 2 * v;
+    }
+
+    sum -= C1;
+
+    kernelsums[bin] = sum;
+
+    // Normailization
+    for (int x = 0; x <= KernelHalfWidth; x++)
+    {
+      v = kerneltable[b + KernelHalfWidth + x] / sum;
+      kerneltable[b + KernelHalfWidth + x] = v;
+      kerneltable[b + KernelHalfWidth - x] = v;
+    }
+  }
+}
diff --git a/src/package_bgs/KDE/KernelTable.h b/src/package_bgs/KDE/KernelTable.h
new file mode 100644
index 0000000..cf18a3e
--- /dev/null
+++ b/src/package_bgs/KDE/KernelTable.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <iostream>
+
+class KernelLUTable
+{
+public:
+  double minsegma;
+  double maxsegma;
+  int segmabins;
+  int tablehalfwidth;
+  double *kerneltable;
+  double *kernelsums;
+
+public:
+  KernelLUTable();
+  ~KernelLUTable();
+
+  KernelLUTable(int KernelHalfWidth, double Segmamin, double Segmamax, int Segmabins);
+};
diff --git a/package_bgs/KDE/NPBGSubtractor.cpp b/src/package_bgs/KDE/NPBGSubtractor.cpp
similarity index 92%
rename from package_bgs/KDE/NPBGSubtractor.cpp
rename to src/package_bgs/KDE/NPBGSubtractor.cpp
index ddacaad..bcc4b09 100644
--- a/package_bgs/KDE/NPBGSubtractor.cpp
+++ b/src/package_bgs/KDE/NPBGSubtractor.cpp
@@ -1,60 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*
-* Copyright 2001 by Ahmed Elgammal All  rights reserved.
-*
-* Permission to use, copy,  or modify this software and  its documentation
-* for  educational  and  research purposes only and without fee  is hereby
-* granted, provided  that this copyright notice and the original authors's
-* name appear  on all copies and supporting documentation.  If individual
-* files are  separated from  this  distribution directory  structure, this
-* copyright notice must be included.  For any other uses of this software,
-* in original or  modified form, including but not limited to distribution
-* in whole or in  part, specific  prior permission  must be  obtained from
-* Author or UMIACS.  These programs shall not  be  used, rewritten, or
-* adapted as  the basis  of  a commercial  software  or  hardware product
-* without first obtaining appropriate licenses  from Author.
-* Other than these cases, no part of this software may be used or
-* distributed without written permission of the author.
-*
-* Neither the author nor UMIACS make any representations about the
-* suitability of this software for any purpose.  It is provided
-* "as is" without express or implied warranty.
-*
-* Ahmed Elgammal
-*
-* University of Maryland at College Park
-* UMIACS
-* A.V. Williams Bldg.
-* CollegePark, MD 20742
-* E-mail:  elgammal@umiacs.umd.edu
-*
-**/
-
-// NPBGSubtractor.cpp: implementation of the NPBGSubtractor class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "NPBGSubtractor.h"
 #include <assert.h>
 #include <math.h>
 #include <string.h>
 
+#include "NPBGSubtractor.h"
+
 //#ifdef _DEBUG
 //#undef THIS_FILE
 //static char THIS_FILE[]=__FILE__;
diff --git a/src/package_bgs/KDE/NPBGSubtractor.h b/src/package_bgs/KDE/NPBGSubtractor.h
new file mode 100644
index 0000000..fbe8664
--- /dev/null
+++ b/src/package_bgs/KDE/NPBGSubtractor.h
@@ -0,0 +1,95 @@
+#pragma once
+
+#include "NPBGmodel.h"
+#include "KernelTable.h"
+
+#define FALSE 0
+#define TRUE 1
+
+// kernal look up table settings
+#define 	KERNELHALFWIDTH 255
+#define 	SEGMAMAX 36.5
+#define	  SEGMAMIN 0.5
+#define		SEGMABINS 80
+#define		DEFAULTSEGMA 1.0
+
+typedef struct
+{
+  unsigned char *Hist;
+  unsigned char *MedianBins;
+  unsigned char *MedianFreq;
+  unsigned char *AccSum;
+  unsigned char histbins;
+  unsigned char histsum;
+  unsigned int  imagesize;
+} DynamicMedianHistogram;
+
+typedef struct
+{
+  unsigned int cnt;
+  unsigned int *List;
+} ImageIndex;
+
+class NPBGSubtractor
+{
+private:
+  unsigned int rows;
+  unsigned int cols;
+  unsigned int color_channels;
+  unsigned int imagesize;
+  // flags
+  unsigned char UpdateBGFlag;
+  unsigned char SdEstimateFlag;
+  unsigned char UseColorRatiosFlag;
+  unsigned char AdaptBGFlag;
+  unsigned char SubsetFlag;
+  //
+  int UpdateSDRate;
+  double Threshold;
+  double AlphaValue;
+  unsigned int TimeIndex;
+  ImageIndex  *imageindex;
+  unsigned char *tempFrame;
+  KernelLUTable *KernelTable;
+  NPBGmodel *BGModel;
+  DynamicMedianHistogram AbsDiffHist;
+  double *Pimage1;
+  double *Pimage2;
+  //
+  void NPBGSubtraction_Subset_Kernel(unsigned char * image, unsigned char * FGImage, unsigned char * FilteredFGImage);
+  void SequenceBGUpdate_Pairs(unsigned char * image, unsigned char * Mask);
+
+public:
+  NPBGSubtractor();
+  virtual ~NPBGSubtractor();
+  //~NPBGSubtractor();
+
+  int Intialize(unsigned int rows,
+    unsigned int cols,
+    unsigned int color_channels,
+    unsigned int SequenceLength,
+    unsigned int TimeWindowSize,
+    unsigned char SDEstimationFlag,
+    unsigned char UseColorRatiosFlag);
+
+  void AddFrame(unsigned char * ImageBuffer);
+
+  void Estimation();
+
+  void NBBGSubtraction(unsigned char *Frame,
+    unsigned char *FGImage,
+    unsigned char *FilteredFGImage,
+    unsigned char **DisplayBuffers);
+
+  void Update(unsigned char *);
+
+  void SetThresholds(double th, double alpha)
+  {
+    Threshold = th;
+    AlphaValue = alpha;
+  };
+
+  void SetUpdateFlag(unsigned int bgflag) {
+    UpdateBGFlag = bgflag;
+  };
+};
diff --git a/src/package_bgs/KDE/NPBGmodel.cpp b/src/package_bgs/KDE/NPBGmodel.cpp
new file mode 100644
index 0000000..f4bd272
--- /dev/null
+++ b/src/package_bgs/KDE/NPBGmodel.cpp
@@ -0,0 +1,72 @@
+#include "memory.h"
+
+#include "NPBGmodel.h"
+
+#ifdef _DEBUG
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+//#define new DEBUG_NEW
+#endif
+
+NPBGmodel::NPBGmodel()
+{
+  std::cout << "NPBGmodel()" << std::endl;
+}
+
+NPBGmodel::~NPBGmodel()
+{
+  delete Sequence;
+  delete PixelQTop;
+  delete TemporalBuffer;
+  delete TemporalMask;
+  delete AccMask;
+  //delete SDbinsImage;
+  std::cout << "~NPBGmodel()" << std::endl;
+}
+
+NPBGmodel::NPBGmodel(unsigned int Rows,
+  unsigned int Cols,
+  unsigned int ColorChannels,
+  unsigned int Length,
+  unsigned int pTimeWindowSize,
+  unsigned int bg_suppression_time)
+{
+  std::cout << "NPBGmodel()" << std::endl;
+
+  imagesize = Rows*Cols*ColorChannels;
+
+  rows = Rows;
+  cols = Cols;
+  color_channels = ColorChannels;
+
+  SampleSize = Length;
+
+  TimeWindowSize = pTimeWindowSize;
+
+  Sequence = new unsigned char[imagesize*Length];
+  Top = 0;
+  memset(Sequence, 0, imagesize*Length);
+
+  PixelQTop = new unsigned char[rows*cols];
+
+  // temporalBuffer
+  TemporalBufferLength = (TimeWindowSize / Length > 2 ? TimeWindowSize / Length : 2);
+  TemporalBuffer = new unsigned char[imagesize*TemporalBufferLength];
+  TemporalMask = new unsigned char[rows*cols*TemporalBufferLength];
+
+  TemporalBufferTop = 0;
+
+  AccMask = new unsigned int[rows*cols];
+
+  ResetMaskTh = bg_suppression_time;
+}
+
+void NPBGmodel::AddFrame(unsigned char *ImageBuffer)
+{
+  memcpy(Sequence + Top*imagesize, ImageBuffer, imagesize);
+  Top = (Top + 1) % SampleSize;
+
+  memset(PixelQTop, (unsigned char)Top, rows*cols);
+
+  memcpy(TemporalBuffer, ImageBuffer, imagesize);
+}
diff --git a/src/package_bgs/KDE/NPBGmodel.h b/src/package_bgs/KDE/NPBGmodel.h
new file mode 100644
index 0000000..fc95adf
--- /dev/null
+++ b/src/package_bgs/KDE/NPBGmodel.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <iostream>
+
+class NPBGmodel
+{
+private:
+  unsigned char *Sequence;
+  unsigned int SampleSize;
+  unsigned int TimeWindowSize;
+
+  unsigned int rows, cols, color_channels;
+  unsigned int imagesize;
+
+  unsigned int Top;
+  unsigned char *PixelQTop;
+
+  //unsigned int *PixelUpdateCounter;
+
+  unsigned char *SDbinsImage;
+
+  unsigned char *TemporalBuffer;
+  unsigned char TemporalBufferLength;
+  unsigned char TemporalBufferTop;
+  unsigned char *TemporalBufferMask;
+
+  unsigned char *TemporalMask;
+  unsigned char TemporalMaskLength;
+  unsigned char TemporalMaskTop;
+
+  unsigned int *AccMask;
+  unsigned int ResetMaskTh;	// Max continous duration a pixel can be detected before
+  // it is forced to be updated...
+
+  double *weights;
+
+public:
+  NPBGmodel();
+  //~NPBGmodel();
+  virtual ~NPBGmodel();
+
+  NPBGmodel(unsigned int Rows,
+    unsigned int Cols,
+    unsigned int ColorChannels,
+    unsigned int Length,
+    unsigned int pTimeWindowSize,
+    unsigned int bg_suppression_time);
+
+  void AddFrame(unsigned char *ImageBuffer);
+
+  friend class NPBGSubtractor;
+};
diff --git a/package_bgs/KNN.cpp b/src/package_bgs/KNN.cpp
similarity index 51%
rename from package_bgs/KNN.cpp
rename to src/package_bgs/KNN.cpp
index e0877b5..5c58ca2 100644
--- a/package_bgs/KNN.cpp
+++ b/src/package_bgs/KNN.cpp
@@ -1,19 +1,3 @@
-/*
- This file is part of BGSLibrary.
-
- BGSLibrary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BGSLibrary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
 #include "KNN.h"
 
 #if CV_MAJOR_VERSION >= 3
@@ -78,34 +62,35 @@ void KNN::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bg
 
 void KNN::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "history", history);
-  cvWriteInt(fs, "nSamples", nSamples);
-  cvWriteReal(fs, "dist2Threshold", dist2Threshold);
-  cvWriteInt(fs, "knnSamples", knnSamples);
-  cvWriteInt(fs, "doShadowDetection", doShadowDetection);
-  cvWriteInt(fs, "shadowValue", shadowValue);
-  cvWriteReal(fs, "shadowThreshold", shadowThreshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "history" << history;
+  fs << "nSamples" << nSamples;
+  fs << "dist2Threshold" << dist2Threshold;
+  fs << "knnSamples" << knnSamples;
+  fs << "doShadowDetection" << doShadowDetection;
+  fs << "shadowValue" << shadowValue;
+  fs << "shadowThreshold" << shadowThreshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void KNN::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  history = cvReadIntByName(fs, nullptr, "history", 500);
-  nSamples = cvReadIntByName(fs, nullptr, "nSamples", 7);
-  dist2Threshold = cvReadRealByName(fs, nullptr, "dist2Threshold", 20.0f * 20.0f);
-  knnSamples = cvReadIntByName(fs, nullptr, "knnSamples", 0);
-  doShadowDetection = cvReadIntByName(fs, nullptr, "doShadowDetection", 1);
-  shadowValue = cvReadIntByName(fs, nullptr, "shadowValue", 127);
-  shadowThreshold = cvReadRealByName(fs, nullptr, "shadowThreshold", 0.5f);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["history"] >> history;
+  fs["nSamples"] >> nSamples;
+  fs["dist2Threshold"] >> dist2Threshold;
+  fs["knnSamples"] >> knnSamples;
+  fs["doShadowDetection"] >> doShadowDetection;
+  fs["shadowValue"] >> shadowValue;
+  fs["shadowThreshold"] >> shadowThreshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
 
 #endif
diff --git a/package_bgs/KNN.h b/src/package_bgs/KNN.h
similarity index 52%
rename from package_bgs/KNN.h
rename to src/package_bgs/KNN.h
index c732901..4591544 100644
--- a/package_bgs/KNN.h
+++ b/src/package_bgs/KNN.h
@@ -1,35 +1,21 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include <iostream>
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
 #include "opencv2/core/version.hpp"
 #if CV_MAJOR_VERSION >= 3
 
-#include <iostream>
 #include <opencv2/opencv.hpp>
 #include <opencv2/video/background_segm.hpp>
 
-#include "IBGS.h"
-
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class KNN : public IBGS
+    class KNN : public IBGS, public ILoadSaveConfig
     {
     private:
       cv::Ptr<cv::BackgroundSubtractorKNN> knn;
diff --git a/src/package_bgs/LBAdaptiveSOM.cpp b/src/package_bgs/LBAdaptiveSOM.cpp
new file mode 100644
index 0000000..7d9a0a0
--- /dev/null
+++ b/src/package_bgs/LBAdaptiveSOM.cpp
@@ -0,0 +1,93 @@
+#include "LBAdaptiveSOM.h"
+
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+using namespace bgslibrary::algorithms;
+
+LBAdaptiveSOM::LBAdaptiveSOM() :
+  sensitivity(75), trainingSensitivity(245),
+  learningRate(62), trainingLearningRate(255),
+  trainingSteps(55)
+{
+  std::cout << "LBAdaptiveSOM()" << std::endl;
+  setup("./config/LBAdaptiveSOM.xml");
+}
+
+LBAdaptiveSOM::~LBAdaptiveSOM()
+{
+  delete m_pBGModel;
+  std::cout << "~LBAdaptiveSOM()" << std::endl;
+}
+
+void LBAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  IplImage *frame = new IplImage(img_input);
+
+  if (firstTime)
+  {
+    int w = cvGetSize(frame).width;
+    int h = cvGetSize(frame).height;
+
+    m_pBGModel = new BGModelSom(w, h);
+    m_pBGModel->InitModel(frame);
+  }
+
+  m_pBGModel->setBGModelParameter(0, sensitivity);
+  m_pBGModel->setBGModelParameter(1, trainingSensitivity);
+  m_pBGModel->setBGModelParameter(2, learningRate);
+  m_pBGModel->setBGModelParameter(3, trainingLearningRate);
+  m_pBGModel->setBGModelParameter(5, trainingSteps);
+
+  m_pBGModel->UpdateModel(frame);
+
+  img_foreground = cv::cvarrToMat(m_pBGModel->GetFG());
+  img_background = cv::cvarrToMat(m_pBGModel->GetBG());
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+  {
+    cv::imshow("SOM Mask", img_foreground);
+    cv::imshow("SOM Model", img_background);
+  }
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+
+  delete frame;
+
+  firstTime = false;
+}
+
+void LBAdaptiveSOM::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "sensitivity" << sensitivity;
+  fs << "trainingSensitivity" << trainingSensitivity;
+  fs << "learningRate" << learningRate;
+  fs << "trainingLearningRate" << trainingLearningRate;
+  fs << "trainingSteps" << trainingSteps;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void LBAdaptiveSOM::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["sensitivity"] >> sensitivity;
+  fs["trainingSensitivity"] >> trainingSensitivity;
+  fs["learningRate"] >> learningRate;
+  fs["trainingLearningRate"] >> trainingLearningRate;
+  fs["trainingSteps"] >> trainingSteps;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
+
+#endif
diff --git a/src/package_bgs/LBAdaptiveSOM.h b/src/package_bgs/LBAdaptiveSOM.h
new file mode 100644
index 0000000..c4add4b
--- /dev/null
+++ b/src/package_bgs/LBAdaptiveSOM.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "lb/BGModelSom.h"
+
+using namespace lb_library;
+using namespace lb_library::AdaptiveSOM;
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class LBAdaptiveSOM : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BGModel* m_pBGModel;
+      int sensitivity;
+      int trainingSensitivity;
+      int learningRate;
+      int trainingLearningRate;
+      int trainingSteps;
+
+    public:
+      LBAdaptiveSOM();
+      ~LBAdaptiveSOM();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<LBAdaptiveSOM> register_LBAdaptiveSOM("LBAdaptiveSOM");
+  }
+}
+
+#endif
diff --git a/src/package_bgs/LBFuzzyAdaptiveSOM.cpp b/src/package_bgs/LBFuzzyAdaptiveSOM.cpp
new file mode 100644
index 0000000..b163d65
--- /dev/null
+++ b/src/package_bgs/LBFuzzyAdaptiveSOM.cpp
@@ -0,0 +1,91 @@
+#include "LBFuzzyAdaptiveSOM.h"
+
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+using namespace bgslibrary::algorithms;
+
+LBFuzzyAdaptiveSOM::LBFuzzyAdaptiveSOM() :
+  sensitivity(90), trainingSensitivity(240), learningRate(38), trainingLearningRate(255), trainingSteps(81)
+{
+  std::cout << "LBFuzzyAdaptiveSOM()" << std::endl;
+  setup("./config/LBFuzzyAdaptiveSOM.xml");
+}
+
+LBFuzzyAdaptiveSOM::~LBFuzzyAdaptiveSOM()
+{
+  delete m_pBGModel;
+  std::cout << "~LBFuzzyAdaptiveSOM()" << std::endl;
+}
+
+void LBFuzzyAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  IplImage *frame = new IplImage(img_input);
+
+  if (firstTime)
+  {
+    int w = cvGetSize(frame).width;
+    int h = cvGetSize(frame).height;
+
+    m_pBGModel = new BGModelFuzzySom(w, h);
+    m_pBGModel->InitModel(frame);
+  }
+
+  m_pBGModel->setBGModelParameter(0, sensitivity);
+  m_pBGModel->setBGModelParameter(1, trainingSensitivity);
+  m_pBGModel->setBGModelParameter(2, learningRate);
+  m_pBGModel->setBGModelParameter(3, trainingLearningRate);
+  m_pBGModel->setBGModelParameter(5, trainingSteps);
+
+  m_pBGModel->UpdateModel(frame);
+
+  img_foreground = cv::cvarrToMat(m_pBGModel->GetFG());
+  img_background = cv::cvarrToMat(m_pBGModel->GetBG());
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+  {
+    cv::imshow("FSOM Mask", img_foreground);
+    cv::imshow("FSOM Model", img_background);
+  }
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+
+  delete frame;
+
+  firstTime = false;
+}
+
+void LBFuzzyAdaptiveSOM::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "sensitivity" << sensitivity;
+  fs << "trainingSensitivity" << trainingSensitivity;
+  fs << "learningRate" << learningRate;
+  fs << "trainingLearningRate" << trainingLearningRate;
+  fs << "trainingSteps" << trainingSteps;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void LBFuzzyAdaptiveSOM::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["sensitivity"] >> sensitivity;
+  fs["trainingSensitivity"] >> trainingSensitivity;
+  fs["learningRate"] >> learningRate;
+  fs["trainingLearningRate"] >> trainingLearningRate;
+  fs["trainingSteps"] >> trainingSteps;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
+
+#endif
diff --git a/package_bgs/LBFuzzyAdaptiveSOM.h b/src/package_bgs/LBFuzzyAdaptiveSOM.h
similarity index 50%
rename from package_bgs/LBFuzzyAdaptiveSOM.h
rename to src/package_bgs/LBFuzzyAdaptiveSOM.h
index 4a59e4c..7169976 100644
--- a/package_bgs/LBFuzzyAdaptiveSOM.h
+++ b/src/package_bgs/LBFuzzyAdaptiveSOM.h
@@ -1,22 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "lb/BGModelFuzzySom.h"
 
 using namespace lb_library;
@@ -26,7 +15,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class LBFuzzyAdaptiveSOM : public IBGS
+    class LBFuzzyAdaptiveSOM : public IBGS, public ILoadSaveConfig
     {
     private:
       BGModel* m_pBGModel;
@@ -50,3 +39,5 @@ namespace bgslibrary
     static BGS_Register<LBFuzzyAdaptiveSOM> register_LBFuzzyAdaptiveSOM("LBFuzzyAdaptiveSOM");
   }
 }
+
+#endif
diff --git a/package_bgs/LBFuzzyGaussian.cpp b/src/package_bgs/LBFuzzyGaussian.cpp
similarity index 50%
rename from package_bgs/LBFuzzyGaussian.cpp
rename to src/package_bgs/LBFuzzyGaussian.cpp
index b161026..e112767 100644
--- a/package_bgs/LBFuzzyGaussian.cpp
+++ b/src/package_bgs/LBFuzzyGaussian.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "LBFuzzyGaussian.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 LBFuzzyGaussian::LBFuzzyGaussian() :
@@ -74,26 +60,29 @@ void LBFuzzyGaussian::process(const cv::Mat &img_input, cv::Mat &img_output, cv:
 
 void LBFuzzyGaussian::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "sensitivity", sensitivity);
-  cvWriteInt(fs, "bgThreshold", bgThreshold);
-  cvWriteInt(fs, "learningRate", learningRate);
-  cvWriteInt(fs, "noiseVariance", noiseVariance);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "sensitivity" << sensitivity;
+  fs << "bgThreshold" << bgThreshold;
+  fs << "learningRate" << learningRate;
+  fs << "noiseVariance" << noiseVariance;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void LBFuzzyGaussian::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  sensitivity = cvReadIntByName(fs, nullptr, "sensitivity", 72);
-  bgThreshold = cvReadIntByName(fs, nullptr, "bgThreshold", 162);
-  learningRate = cvReadIntByName(fs, nullptr, "learningRate", 49);
-  noiseVariance = cvReadIntByName(fs, nullptr, "noiseVariance", 195);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["sensitivity"] >> sensitivity;
+  fs["bgThreshold"] >> bgThreshold;
+  fs["learningRate"] >> learningRate;
+  fs["noiseVariance"] >> noiseVariance;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/LBFuzzyGaussian.h b/src/package_bgs/LBFuzzyGaussian.h
new file mode 100644
index 0000000..3d8c054
--- /dev/null
+++ b/src/package_bgs/LBFuzzyGaussian.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "lb/BGModelFuzzyGauss.h"
+
+using namespace lb_library;
+using namespace lb_library::FuzzyGaussian;
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class LBFuzzyGaussian : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BGModel* m_pBGModel;
+      int sensitivity;
+      int bgThreshold;
+      int learningRate;
+      int noiseVariance;
+
+    public:
+      LBFuzzyGaussian();
+      ~LBFuzzyGaussian();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<LBFuzzyGaussian> register_LBFuzzyGaussian("LBFuzzyGaussian");
+  }
+}
+
+#endif
diff --git a/package_bgs/LBMixtureOfGaussians.cpp b/src/package_bgs/LBMixtureOfGaussians.cpp
similarity index 51%
rename from package_bgs/LBMixtureOfGaussians.cpp
rename to src/package_bgs/LBMixtureOfGaussians.cpp
index 6cd9c91..a18dad1 100644
--- a/package_bgs/LBMixtureOfGaussians.cpp
+++ b/src/package_bgs/LBMixtureOfGaussians.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "LBMixtureOfGaussians.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 LBMixtureOfGaussians::LBMixtureOfGaussians() :
@@ -74,26 +60,29 @@ void LBMixtureOfGaussians::process(const cv::Mat &img_input, cv::Mat &img_output
 
 void LBMixtureOfGaussians::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "sensitivity", sensitivity);
-  cvWriteInt(fs, "bgThreshold", bgThreshold);
-  cvWriteInt(fs, "learningRate", learningRate);
-  cvWriteInt(fs, "noiseVariance", noiseVariance);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "sensitivity" << sensitivity;
+  fs << "bgThreshold" << bgThreshold;
+  fs << "learningRate" << learningRate;
+  fs << "noiseVariance" << noiseVariance;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void LBMixtureOfGaussians::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  sensitivity = cvReadIntByName(fs, nullptr, "sensitivity", 81);
-  bgThreshold = cvReadIntByName(fs, nullptr, "bgThreshold", 83);
-  learningRate = cvReadIntByName(fs, nullptr, "learningRate", 59);
-  noiseVariance = cvReadIntByName(fs, nullptr, "noiseVariance", 206);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["sensitivity"] >> sensitivity;
+  fs["bgThreshold"] >> bgThreshold;
+  fs["learningRate"] >> learningRate;
+  fs["noiseVariance"] >> noiseVariance;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/LBMixtureOfGaussians.h b/src/package_bgs/LBMixtureOfGaussians.h
new file mode 100644
index 0000000..a78d3bb
--- /dev/null
+++ b/src/package_bgs/LBMixtureOfGaussians.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "lb/BGModelMog.h"
+
+using namespace lb_library;
+using namespace lb_library::MixtureOfGaussians;
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class LBMixtureOfGaussians : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BGModel* m_pBGModel;
+      int sensitivity;
+      int bgThreshold;
+      int learningRate;
+      int noiseVariance;
+
+    public:
+      LBMixtureOfGaussians();
+      ~LBMixtureOfGaussians();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<LBMixtureOfGaussians> register_LBMixtureOfGaussians("LBMixtureOfGaussians");
+  }
+}
+
+#endif
diff --git a/package_bgs/LBP_MRF.cpp b/src/package_bgs/LBP_MRF.cpp
similarity index 52%
rename from package_bgs/LBP_MRF.cpp
rename to src/package_bgs/LBP_MRF.cpp
index b9e6bbe..2f4945b 100644
--- a/package_bgs/LBP_MRF.cpp
+++ b/src/package_bgs/LBP_MRF.cpp
@@ -1,25 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-
-Csaba, Kertész: Texture-Based Foreground Detection, International Journal of Signal Processing,
-Image Processing and Pattern Recognition (IJSIP), Vol. 4, No. 4, 2011.
-
-*/
 #include "LBP_MRF.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 LBP_MRF::LBP_MRF() :
@@ -67,18 +49,21 @@ void LBP_MRF::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &im
 
 void LBP_MRF::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void LBP_MRF::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/LBP_MRF.h b/src/package_bgs/LBP_MRF.h
new file mode 100644
index 0000000..216b148
--- /dev/null
+++ b/src/package_bgs/LBP_MRF.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "LBP_MRF/MotionDetection.hpp"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class LBP_MRF : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      MotionDetection* Detector;
+      cv::Mat img_segmentation;
+
+    public:
+      LBP_MRF();
+      ~LBP_MRF();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<LBP_MRF> register_LBP_MRF("LBP_MRF");
+  }
+}
+
+#endif
diff --git a/src/package_bgs/LBP_MRF/MEDefs.cpp b/src/package_bgs/LBP_MRF/MEDefs.cpp
new file mode 100644
index 0000000..07486dc
--- /dev/null
+++ b/src/package_bgs/LBP_MRF/MEDefs.cpp
@@ -0,0 +1,20 @@
+#include <math.h>
+
+#include "MEDefs.hpp"
+
+float MERound(float number)
+{
+  double FracPart = 0.0;
+  double IntPart = 0.0;
+  float Ret = 0.0;
+
+  FracPart = modf((double)number, &IntPart);
+  if (number >= 0)
+  {
+    Ret = (float)(FracPart >= 0.5 ? IntPart + 1 : IntPart);
+  }
+  else {
+    Ret = (float)(FracPart <= -0.5 ? IntPart - 1 : IntPart);
+  }
+  return Ret;
+}
diff --git a/src/package_bgs/LBP_MRF/MEDefs.hpp b/src/package_bgs/LBP_MRF/MEDefs.hpp
new file mode 100644
index 0000000..0c955e1
--- /dev/null
+++ b/src/package_bgs/LBP_MRF/MEDefs.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+ /// Pi value
+#ifndef ME_PI_VALUE
+#define ME_PI_VALUE 3.14159265
+#endif
+
+/*! Process state */
+typedef enum {
+  ps_Min = 0,                /*!< Minimum value */
+  ps_Uninitialized = ps_Min, /*!< Uninitialized state */
+  ps_Initialized,            /*!< Initialized state */
+  ps_InProgress,             /*!< In progress state */
+  ps_Successful,             /*!< Successful state */
+  ps_Max = ps_Successful     /*!< Maximum value */
+} MEProcessStateType;
+
+template <typename T>
+const T& MEMin(const T& a, const T& b)
+{
+  if (a < b)
+    return a;
+  return b;
+}
+
+template <typename T>
+const T& MEMax(const T& a, const T& b)
+{
+  if (a < b)
+    return b;
+  return a;
+}
+
+template <typename T>
+const T& MEBound(const T& min, const T& val, const T& max)
+{
+  return MEMax(min, MEMin(max, val));
+}
+
+/*!
+ * @brief Round a float number
+ *
+ * @param number number to round
+ *
+ * @return New float number
+ *
+ * This method rounds a float number, if the fraction is .5 or lower
+ * then it rounds down, otherwise up.
+ *
+ */
+
+float MERound(float number);
+
+/** @} */
diff --git a/package_bgs/LBP_MRF/MEHistogram.cpp b/src/package_bgs/LBP_MRF/MEHistogram.cpp
similarity index 86%
rename from package_bgs/LBP_MRF/MEHistogram.cpp
rename to src/package_bgs/LBP_MRF/MEHistogram.cpp
index 5b4e56f..ec5ce1a 100644
--- a/package_bgs/LBP_MRF/MEHistogram.cpp
+++ b/src/package_bgs/LBP_MRF/MEHistogram.cpp
@@ -1,52 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- *  Some histogram stretch codes are based on how Gimp does it, the same
- *  GPL 2 license applies for the following authors:
- *
- *  The GIMP -- an image manipulation program
- *  Copyright (C) 1995 Spencer Kimball and Peter Mattis
- *
- */
-
-#include "MEHistogram.hpp"
-
 #include <opencv2/opencv.hpp>
 #include <opencv2/core/core_c.h>
 #include <opencv2/imgproc/types_c.h>
 #include <opencv2/imgproc/imgproc_c.h>
+
+#include "MEHistogram.hpp"
 #include "MEDefs.hpp"
 #include "MEImage.hpp"
 
@@ -55,18 +12,15 @@ MEHistogram::MEHistogram()
   Clear();
 }
 
-
 MEHistogram::~MEHistogram()
 {
 }
 
-
 void MEHistogram::Clear()
 {
   memset(&HistogramData, 0, 256 * sizeof(int));
 }
 
-
 bool MEHistogram::operator==(MEHistogram& histogram) const
 {
   bool ret = true;
@@ -82,7 +36,6 @@ bool MEHistogram::operator==(MEHistogram& histogram) const
   return ret;
 }
 
-
 void MEHistogram::Calculate(MEImage& image, int channel, HistogramType mode)
 {
   int Channel = (channel < 1) ? 1 : ((channel > image.GetLayers()) ? image.GetLayers() : channel);
@@ -105,7 +58,6 @@ void MEHistogram::Calculate(MEImage& image, int channel, HistogramType mode)
   }
 }
 
-
 void MEHistogram::Calculate(MEImage& image, HistogramType mode)
 {
   if (mode == h_Overwrite)
@@ -127,7 +79,6 @@ void MEHistogram::Calculate(MEImage& image, HistogramType mode)
   }
 }
 
-
 void MEHistogram::Calculate(MEImage& image, int channel, int x0, int y0, int x1, int y1)
 {
   int Channel = (channel < 1) ? 1 : ((channel > image.GetLayers()) ? image.GetLayers() : channel);
@@ -159,7 +110,6 @@ void MEHistogram::Calculate(MEImage& image, int channel, int x0, int y0, int x1,
   }
 }
 
-
 int MEHistogram::GetPeakIndex() const
 {
   int PeakIndex = 0;
@@ -176,7 +126,6 @@ int MEHistogram::GetPeakIndex() const
   return PeakIndex;
 }
 
-
 int MEHistogram::GetLowestLimitIndex(int threshold) const
 {
   int MinIndex = 0;
@@ -192,7 +141,6 @@ int MEHistogram::GetLowestLimitIndex(int threshold) const
   return MinIndex;
 }
 
-
 int MEHistogram::GetHighestLimitIndex(int threshold) const
 {
   int MaxIndex = 255;
@@ -208,7 +156,6 @@ int MEHistogram::GetHighestLimitIndex(int threshold) const
   return MaxIndex;
 }
 
-
 int MEHistogram::GetPowerAmount(int minindex, int maxindex) const
 {
   int ValueAmount = 0;
@@ -229,7 +176,6 @@ int MEHistogram::GetPowerAmount(int minindex, int maxindex) const
   return ValueAmount;
 }
 
-
 int MEHistogram::GetCentroidIndex() const
 {
   int ValueAmount = GetPowerAmount(0, 255);
@@ -246,7 +192,6 @@ int MEHistogram::GetCentroidIndex() const
   return CentroidIndex;
 }
 
-
 bool MEHistogram::Stretch(StretchType mode)
 {
   int MinIndex = -1;
@@ -355,25 +300,21 @@ bool MEHistogram::Stretch(StretchType mode)
   return Ret;
 }
 
-
 MEHistogramTransform::MEHistogramTransform() : ChannelMode(p_SeparateChannels),
 StretchMode(MEHistogram::s_GimpMode), DiscreteStretchingDone(false)
 {
 }
 
-
 MEHistogramTransform::~MEHistogramTransform()
 {
 }
 
-
 void MEHistogramTransform::HistogramStretch(MEImage& image)
 {
   SetStretchProcessingMode(p_SeparateChannels, MEHistogram::s_GimpMode);
   HistogramStretch(image, t_Continuous);
 }
 
-
 void MEHistogramTransform::HistogramStretch(MEImage& image, TransformType time_mode)
 {
   if (time_mode == t_Continuous)
@@ -443,7 +384,6 @@ void MEHistogramTransform::HistogramStretch(MEImage& image, TransformType time_m
     }
 }
 
-
 void MEHistogramTransform::HistogramEqualize(MEImage& image)
 {
   DiscreteStretchingDone = false;
@@ -487,7 +427,6 @@ void MEHistogramTransform::HistogramEqualize(MEImage& image)
   }
 }
 
-
 void MEHistogramTransform::SetStretchProcessingMode(ProcessingType new_channel_mode,
   MEHistogram::StretchType new_stretch_mode)
 {
diff --git a/package_bgs/LBP_MRF/MEHistogram.hpp b/src/package_bgs/LBP_MRF/MEHistogram.hpp
similarity index 85%
rename from package_bgs/LBP_MRF/MEHistogram.hpp
rename to src/package_bgs/LBP_MRF/MEHistogram.hpp
index 0b2fb0d..be8453e 100644
--- a/package_bgs/LBP_MRF/MEHistogram.hpp
+++ b/src/package_bgs/LBP_MRF/MEHistogram.hpp
@@ -1,46 +1,5 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
 #pragma once
 
- /**
-  *  @addtogroup mindeye
-  *  @{
-  */
-
 class MEImage;
 
 /**
@@ -356,5 +315,3 @@ private:
   /// Continuous histogram stretch is done already
   bool DiscreteStretchingDone;
 };
-
-/** @} */
diff --git a/package_bgs/LBP_MRF/MEImage.cpp b/src/package_bgs/LBP_MRF/MEImage.cpp
similarity index 96%
rename from package_bgs/LBP_MRF/MEImage.cpp
rename to src/package_bgs/LBP_MRF/MEImage.cpp
index a917bc8..71d66de 100644
--- a/package_bgs/LBP_MRF/MEImage.cpp
+++ b/src/package_bgs/LBP_MRF/MEImage.cpp
@@ -1,46 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-#include "MEImage.hpp"
-
 #include <opencv2/opencv.hpp>
 #include <opencv2/imgproc/types_c.h>
 #include <opencv2/imgproc/imgproc_c.h>
 
+#include "MEImage.hpp"
 #include "MEDefs.hpp"
 
 #define ME_CAST_TO_IPLIMAGE(image_ptr) ((IplImage*)image_ptr)
@@ -65,13 +27,11 @@ MEImage::MEImage(int width, int height, int layers) : cvImg(NULL)
   _Init(width, height, layers);
 }
 
-
 MEImage::MEImage(const MEImage& other) : cvImg(NULL)
 {
   _Copy(other);
 }
 
-
 MEImage::~MEImage()
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg))
@@ -80,13 +40,11 @@ MEImage::~MEImage()
   }
 }
 
-
 void MEImage::Clear()
 {
   cvSetZero(ME_CAST_TO_IPLIMAGE(cvImg));
 }
 
-
 void MEImage::GetLayer(MEImage& new_layer, int layer_number) const
 {
   int LayerNumber = layer_number;
@@ -115,7 +73,6 @@ void MEImage::GetLayer(MEImage& new_layer, int layer_number) const
   cvSetImageCOI(ME_CAST_TO_IPLIMAGE(cvImg), 0);
 }
 
-
 void MEImage::SetLayer(MEImage& layer, int layer_number)
 {
   int LayerNumber = layer_number;
@@ -150,19 +107,16 @@ void MEImage::SetLayer(MEImage& layer, int layer_number)
   cvSetImageCOI(ME_CAST_TO_IPLIMAGE(cvImg), 0);
 }
 
-
 void MEImage::CopyImageData(unsigned char* data)
 {
   memcpy(ME_CAST_TO_IPLIMAGE(cvImg)->imageData, data, ME_CAST_TO_IPLIMAGE(cvImg)->width*ME_CAST_TO_IPLIMAGE(cvImg)->height*ME_CAST_TO_IPLIMAGE(cvImg)->nChannels);
 }
 
-
 void* MEImage::GetIplImage() const
 {
   return (void*)ME_CAST_TO_IPLIMAGE(cvImg);
 }
 
-
 void MEImage::SetIplImage(void* image)
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg))
@@ -178,19 +132,16 @@ void MEImage::SetIplImage(void* image)
   }
 }
 
-
 bool MEImage::operator==(const MEImage& image)
 {
   return Equal(image);
 }
 
-
 bool MEImage::operator!=(const MEImage& image)
 {
   return !operator==(image);
 }
 
-
 MEImage& MEImage::operator=(const MEImage& other_image)
 {
   if (&other_image == this)
@@ -200,43 +151,36 @@ MEImage& MEImage::operator=(const MEImage& other_image)
   return *this;
 }
 
-
 int MEImage::GetWidth() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? ME_CAST_TO_IPLIMAGE(cvImg)->width : 0;
 }
 
-
 int MEImage::GetRowWidth() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? ME_CAST_TO_IPLIMAGE(cvImg)->widthStep : 0;
 }
 
-
 int MEImage::GetHeight() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? ME_CAST_TO_IPLIMAGE(cvImg)->height : 0;
 }
 
-
 int MEImage::GetLayers() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? ME_CAST_TO_IPLIMAGE(cvImg)->nChannels : 0;
 }
 
-
 int MEImage::GetPixelDataNumber() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? GetWidth()*GetHeight()*GetLayers() : 0;
 }
 
-
 unsigned char* MEImage::GetImageData() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? (unsigned char*)ME_CAST_TO_IPLIMAGE(cvImg)->imageData : NULL;
 }
 
-
 void MEImage::SetData(unsigned char* image_data, int width, int height, int channels)
 {
   _Init(width, height, channels);
@@ -250,25 +194,21 @@ void MEImage::SetData(unsigned char* image_data, int width, int height, int chan
   }
 }
 
-
 float MEImage::GetRatio() const
 {
   return ME_CAST_TO_IPLIMAGE(cvImg) ? (float)ME_CAST_TO_IPLIMAGE(cvImg)->height / (float)ME_CAST_TO_IPLIMAGE(cvImg)->width : 0.0;
 }
 
-
 void MEImage::Realloc(int width, int height)
 {
   Realloc(width, height, ME_CAST_TO_IPLIMAGE(cvImg)->nChannels);
 }
 
-
 void MEImage::Realloc(int width, int height, int layers)
 {
   _Init(width, height, layers);
 }
 
-
 void MEImage::Resize(int new_width, int new_height)
 {
   if (new_height < 1)
@@ -299,7 +239,6 @@ void MEImage::ResizeScaleX(int new_width)
   Resize(new_width, (int)((float)new_width*GetRatio()));
 }
 
-
 void MEImage::ResizeScaleY(int new_height)
 {
   if (new_height < 1)
@@ -310,19 +249,16 @@ void MEImage::ResizeScaleY(int new_height)
   Resize((int)((float)new_height * 1 / GetRatio()), new_height);
 }
 
-
 void MEImage::MirrorHorizontal()
 {
   cvFlip(ME_CAST_TO_IPLIMAGE(cvImg), NULL, 1);
 }
 
-
 void MEImage::MirrorVertical()
 {
   cvFlip(ME_CAST_TO_IPLIMAGE(cvImg), NULL, 0);
 }
 
-
 void MEImage::Crop(int x1, int y1, int x2, int y2)
 {
   int NewX1 = x1;
@@ -358,7 +294,6 @@ void MEImage::Crop(int x1, int y1, int x2, int y2)
   cvImg = TempImg;
 }
 
-
 void MEImage::CopyImageInside(int x, int y, MEImage& source_image)
 {
   int NewX = x;
@@ -400,7 +335,6 @@ void MEImage::CopyImageInside(int x, int y, MEImage& source_image)
   cvResetImageROI(ME_CAST_TO_IPLIMAGE(cvImg));
 }
 
-
 void MEImage::Erode(int iterations)
 {
   IplImage* TempImg = cvCreateImage(cvSize(ME_CAST_TO_IPLIMAGE(cvImg)->width,
@@ -412,7 +346,6 @@ void MEImage::Erode(int iterations)
   cvImg = TempImg;
 }
 
-
 void MEImage::Dilate(int iterations)
 {
   IplImage* TempImg = cvCreateImage(cvSize(ME_CAST_TO_IPLIMAGE(cvImg)->width,
@@ -424,13 +357,11 @@ void MEImage::Dilate(int iterations)
   cvImg = TempImg;
 }
 
-
 void MEImage::Smooth()
 {
   SmoothAdvanced(s_Median, 3);
 }
 
-
 void MEImage::SmoothAdvanced(SmoothType filtermode, int filtersize)
 {
   IplImage* TempImg = cvCreateImage(cvSize(ME_CAST_TO_IPLIMAGE(cvImg)->width, ME_CAST_TO_IPLIMAGE(cvImg)->height), 8,
@@ -455,7 +386,6 @@ void MEImage::SmoothAdvanced(SmoothType filtermode, int filtersize)
   cvImg = TempImg;
 }
 
-
 void MEImage::Canny()
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels > 1)
@@ -470,7 +400,6 @@ void MEImage::Canny()
   cvImg = TempImg;
 }
 
-
 void MEImage::Laplace()
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels != 1)
@@ -485,7 +414,6 @@ void MEImage::Laplace()
   ME_RELEASE_IPLIMAGE(cvImg);
 }
 
-
 void MEImage::Quantize(int levels)
 {
   if (levels <= 0)
@@ -506,7 +434,6 @@ void MEImage::Quantize(int levels)
   }
 }
 
-
 void MEImage::Threshold(int threshold_limit)
 {
   if (threshold_limit < 0)
@@ -530,7 +457,6 @@ void MEImage::Threshold(int threshold_limit)
   }
 }
 
-
 void MEImage::AdaptiveThreshold()
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels != 1)
@@ -545,7 +471,6 @@ void MEImage::AdaptiveThreshold()
   cvImg = TempImg;
 }
 
-
 void MEImage::ThresholdByMask(MEImage& mask_image)
 {
   if (mask_image.GetWidth() != ME_CAST_TO_IPLIMAGE(cvImg)->width ||
@@ -570,7 +495,6 @@ void MEImage::ThresholdByMask(MEImage& mask_image)
   }
 }
 
-
 void MEImage::ColorSpace(ColorSpaceConvertType mode)
 {
   IplImage* TempImg = NULL;
@@ -705,7 +629,6 @@ void MEImage::ColorSpace(ColorSpaceConvertType mode)
   }
 }
 
-
 void MEImage::ConvertToGrayscale(GrayscaleType grayscale_mode)
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels == 1)
@@ -743,7 +666,6 @@ void MEImage::ConvertToGrayscale(GrayscaleType grayscale_mode)
   }
 }
 
-
 void MEImage::ConvertGrayscaleToRGB()
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels != 1)
@@ -757,7 +679,6 @@ void MEImage::ConvertGrayscaleToRGB()
   cvImg = TempImg;
 }
 
-
 void MEImage::ConvertBGRToRGB()
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels != 3)
@@ -767,7 +688,6 @@ void MEImage::ConvertBGRToRGB()
   cvCvtColor(ME_CAST_TO_IPLIMAGE(cvImg), ME_CAST_TO_IPLIMAGE(cvImg), CV_RGB2BGR);
 }
 
-
 void MEImage::LBP(LBPType mode)
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels > 1)
@@ -837,7 +757,6 @@ void MEImage::LBP(LBPType mode)
   cvImg = TempImg;
 }
 
-
 void MEImage::Binarize(int threshold)
 {
   unsigned char* ImageData = (unsigned char*)ME_CAST_TO_IPLIMAGE(cvImg)->imageData;
@@ -854,7 +773,6 @@ void MEImage::Binarize(int threshold)
   }
 }
 
-
 void MEImage::Subtract(MEImage& source, SubtractModeType mode)
 {
   if (source.GetWidth() != ME_CAST_TO_IPLIMAGE(cvImg)->width ||
@@ -910,7 +828,6 @@ void MEImage::Subtract(MEImage& source, SubtractModeType mode)
   }
 }
 
-
 void MEImage::Multiple(MEImage& source, MultiplicationType mode)
 {
   if (source.GetWidth() != ME_CAST_TO_IPLIMAGE(cvImg)->width ||
@@ -985,7 +902,6 @@ void MEImage::Multiple(MEImage& source, MultiplicationType mode)
   }
 }
 
-
 void MEImage::Addition(MEImage& source, AdditionType mode)
 {
   if (source.GetWidth() != ME_CAST_TO_IPLIMAGE(cvImg)->width ||
@@ -1022,7 +938,6 @@ void MEImage::Addition(MEImage& source, AdditionType mode)
   }
 }
 
-
 void MEImage::EliminateSinglePixels()
 {
   IplImage* TempImg = cvCreateImage(cvSize(ME_CAST_TO_IPLIMAGE(cvImg)->width, ME_CAST_TO_IPLIMAGE(cvImg)->height), 8,
@@ -1068,7 +983,6 @@ void MEImage::EliminateSinglePixels()
   cvImg = TempImg;
 }
 
-
 float MEImage::DifferenceAreas(MEImage& reference, int difference) const
 {
   if (reference.GetWidth() != GetWidth() ||
@@ -1098,7 +1012,6 @@ float MEImage::DifferenceAreas(MEImage& reference, int difference) const
   return PixelDiff;
 }
 
-
 int MEImage::AverageDifference(MEImage& reference) const
 {
   if (reference.GetWidth() != GetWidth() ||
@@ -1126,7 +1039,6 @@ int MEImage::AverageDifference(MEImage& reference) const
   return Difference;
 }
 
-
 void MEImage::Minimum(MEImage& image)
 {
   if (image.GetWidth() != ME_CAST_TO_IPLIMAGE(cvImg)->width ||
@@ -1152,7 +1064,6 @@ void MEImage::Minimum(MEImage& image)
   }
 }
 
-
 float MEImage::AverageBrightnessLevel() const
 {
   unsigned char* ImageData = (unsigned char*)ME_CAST_TO_IPLIMAGE(cvImg)->imageData;
@@ -1171,13 +1082,11 @@ float MEImage::AverageBrightnessLevel() const
   return BrightnessLevel / (GetWidth()*GetHeight()*GetLayers());
 }
 
-
 bool MEImage::Equal(const MEImage& reference) const
 {
   return Equal(reference, 1);
 }
 
-
 bool MEImage::Equal(const MEImage& reference, int maxabsdiff) const
 {
   bool Ret = true;
@@ -1209,7 +1118,6 @@ bool MEImage::Equal(const MEImage& reference, int maxabsdiff) const
   return Ret;
 }
 
-
 unsigned char MEImage::GrayscalePixel(int x, int y) const
 {
   int NewX = x;
@@ -1231,7 +1139,6 @@ unsigned char MEImage::GrayscalePixel(int x, int y) const
   return (unsigned char)(Sum);
 }
 
-
 int MEImage::NeighbourhoodCounter(int startx, int starty,
   NeighbourhoodType neighbourhood) const
 {
@@ -1299,7 +1206,6 @@ int MEImage::NeighbourhoodCounter(int startx, int starty,
   return Counter;
 }
 
-
 void MEImage::GradientVector(bool smooth, int x, int y, int mask_size, int& result_x, int& result_y)
 {
   int Results[8];
@@ -1331,7 +1237,6 @@ void MEImage::GradientVector(bool smooth, int x, int y, int mask_size, int& resu
     DiagonalMaskSize*Results[5] - DiagonalMaskSize*Results[7]) / 256;
 }
 
-
 void MEImage::GradientVisualize(int vector_x, int vector_y)
 {
   if (vector_x <= 0)
@@ -1374,7 +1279,6 @@ void MEImage::GradientVisualize(int vector_x, int vector_y)
     }
 }
 
-
 bool MEImage::_Copy(const MEImage& other_image)
 {
   if (&other_image == this)
@@ -1388,7 +1292,6 @@ bool MEImage::_Copy(const MEImage& other_image)
   return true;
 }
 
-
 void MEImage::_Init(int width, int height, int layers)
 {
   if (width < 1)
@@ -1414,7 +1317,6 @@ void MEImage::_Init(int width, int height, int layers)
   cvImg = cvCreateImage(cvSize(width, height), 8, layers);
 }
 
-
 void MEImage::ComputeColorSpace(ColorSpaceConvertType mode)
 {
   if (ME_CAST_TO_IPLIMAGE(cvImg)->nChannels != 3)
diff --git a/package_bgs/LBP_MRF/MEImage.hpp b/src/package_bgs/LBP_MRF/MEImage.hpp
similarity index 94%
rename from package_bgs/LBP_MRF/MEImage.hpp
rename to src/package_bgs/LBP_MRF/MEImage.hpp
index 3a52a77..7094912 100644
--- a/package_bgs/LBP_MRF/MEImage.hpp
+++ b/src/package_bgs/LBP_MRF/MEImage.hpp
@@ -1,50 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
 #pragma once
 
- /**
-  *  @addtogroup mindeye
-  *  @{
-  */
-
-  /**
-   * MEImage
-   * @brief Basic image functions
-   */
+/**
+ * MEImage
+ * @brief Basic image functions
+ */
 class MEImage
 {
 public:
@@ -1007,5 +966,3 @@ private:
   /// The OpenCV image which contains the image data
   void* cvImg;
 };
-
-/** @} */
diff --git a/package_bgs/LBP_MRF/MotionDetection.cpp b/src/package_bgs/LBP_MRF/MotionDetection.cpp
similarity index 96%
rename from package_bgs/LBP_MRF/MotionDetection.cpp
rename to src/package_bgs/LBP_MRF/MotionDetection.cpp
index f729e61..59dde15 100644
--- a/package_bgs/LBP_MRF/MotionDetection.cpp
+++ b/src/package_bgs/LBP_MRF/MotionDetection.cpp
@@ -1,53 +1,16 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  This file is part of the AiBO+ project
-*
-*  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
-*
-*  AiBO+ is free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  AiBO+ is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-*  GNU General Public License for more details.
-*
-*  You should have received a copy of the GNU General Public License
-*  along with this program; if not, write to the Free Software
-*  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
-*
-*  Paper: Csaba, Kertész: Texture-Based Foreground Detection, International Journal of Signal Processing,
-*  Image Processing and Pattern Recognition (IJSIP), Vol. 4, No. 4, 2011.
-*/
+#include <opencv2/opencv.hpp>
+#include <opencv2/imgproc.hpp>
 
 #include "MotionDetection.hpp"
 
-#include "graph.h"
-using namespace ck;
-
-#include <opencv2/opencv.hpp>
-#include <opencv2/imgproc.hpp>
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
 
+#include "graph.h"
 #include "MEHistogram.hpp"
 #include "MEImage.hpp"
 
+using namespace ck;
+
 // Pyramid picture for the tracking
 IplImage *HUOFPyramid;
 // Pyramid picture for the tracking
@@ -82,7 +45,6 @@ MotionDetection::MotionDetection(DetectorType mode) :
   SetMode(mode);
 }
 
-
 MotionDetection::~MotionDetection()
 {
   if (MDMode != md_NotDefined)
@@ -91,7 +53,6 @@ MotionDetection::~MotionDetection()
   }
 }
 
-
 void MotionDetection::SetMode(DetectorType newmode)
 {
   if (MDMode != md_NotDefined && MDMode != newmode)
@@ -120,7 +81,6 @@ void MotionDetection::SetMode(DetectorType newmode)
   }
 }
 
-
 float MotionDetection::GetParameter(ParametersType param) const
 {
   float ret = 0.0;
@@ -177,7 +137,6 @@ float MotionDetection::GetParameter(ParametersType param) const
   return ret;
 }
 
-
 void MotionDetection::SetParameter(ParametersType param, float value)
 {
   switch (param)
@@ -231,7 +190,6 @@ void MotionDetection::SetParameter(ParametersType param, float value)
   }
 }
 
-
 void MotionDetection::DetectMotions(MEImage& image)
 {
   switch (MDMode)
@@ -246,7 +204,6 @@ void MotionDetection::DetectMotions(MEImage& image)
   }
 }
 
-
 void MotionDetection::GetMotionsMask(MEImage& mask_image)
 {
   if (ReadyMask)
@@ -269,7 +226,6 @@ void MotionDetection::GetMotionsMask(MEImage& mask_image)
   mask_image = MaskImage;
 }
 
-
 void MotionDetection::CalculateResults(MEImage& referenceimage, int& tnegatives, int& tpositives,
   int& ttnegatives, int& ttpositives)
 {
@@ -334,7 +290,6 @@ void MotionDetection::CalculateResults(MEImage& referenceimage, int& tnegatives,
   ttpositives = TotalTruePositives;
 }
 
-
 void MotionDetection::ReleaseData()
 {
   if (MDMode == md_LBPHistograms || MDMode == md_DLBPHistograms)
@@ -343,7 +298,6 @@ void MotionDetection::ReleaseData()
   }
 }
 
-
 void MotionDetection::InitHUData(int imagewidth, int imageheight)
 {
   if ((HUImageWidth != imagewidth - HUHistogramArea + 1) ||
@@ -399,7 +353,6 @@ void MotionDetection::InitHUData(int imagewidth, int imageheight)
   }
 }
 
-
 void MotionDetection::InitHUOFData(int imagewidth, int imageheight)
 {
   if (HUOFDataState != ps_Uninitialized)
@@ -417,7 +370,6 @@ void MotionDetection::InitHUOFData(int imagewidth, int imageheight)
   }
 }
 
-
 void MotionDetection::ReleaseHUData()
 {
   if (MDDataState != ps_Uninitialized)
@@ -462,7 +414,6 @@ void MotionDetection::ReleaseHUData()
   }
 }
 
-
 void MotionDetection::ReleaseHUOFData()
 {
   if (MDDataState != ps_Uninitialized)
@@ -491,7 +442,6 @@ void MotionDetection::ReleaseHUOFData()
   }
 }
 
-
 void MotionDetection::ClearHUData()
 {
   if (MDDataState != ps_Uninitialized)
@@ -513,7 +463,6 @@ void MotionDetection::ClearHUData()
   }
 }
 
-
 void MotionDetection::DetectMotionsHU(MEImage& image)
 {
   unsigned char *ImgData = NULL;
@@ -613,7 +562,6 @@ void MotionDetection::DetectMotionsHU(MEImage& image)
   ReadyMask = false;
 }
 
-
 void MotionDetection::UpdateModelHU(MEImage& image, MEPixelDataType*** model)
 {
   float *CurrentHistogram = new float[HUHistogramBins];
@@ -815,7 +763,6 @@ void MotionDetection::UpdateModelHU(MEImage& image, MEPixelDataType*** model)
   delete[] CurrentHistogram2;
 }
 
-
 void MotionDetection::UpdateHUPixelData(MEPixelDataType* PixelData, const float *histogram)
 {
   int MaxIndex = 0;
@@ -962,7 +909,6 @@ void MotionDetection::UpdateHUPixelData(MEPixelDataType* PixelData, const float
   delete[] Weights;
 }
 
-
 void MotionDetection::OpticalFlowCorrection()
 {
   IplImage *PreviousGray = NULL, *CurrentGray = NULL;
@@ -1265,7 +1211,6 @@ void MotionDetection::OpticalFlowCorrection()
   delete[] Distances;
 }
 
-
 void MotionDetection::GetMotionsMaskHU(MEImage& mask_image)
 {
   if (MDDataState != ps_Successful)
@@ -1378,7 +1323,6 @@ void MotionDetection::GetMotionsMaskHU(MEImage& mask_image)
   delete[] Nodes;
 }
 
-
 void MotionDetection::SetSampleMaskHU(SampleMaskType mask_type, int desiredarea)
 {
   if (HUMaskColumnAddDel == NULL || HUMaskRowAddDel == NULL)
@@ -1514,3 +1458,5 @@ void MotionDetection::SetSampleMaskHU(SampleMaskType mask_type, int desiredarea)
     delete[] CalculationMask[i];
   delete[] CalculationMask;
 }
+
+#endif
diff --git a/package_bgs/LBP_MRF/MotionDetection.hpp b/src/package_bgs/LBP_MRF/MotionDetection.hpp
similarity index 86%
rename from package_bgs/LBP_MRF/MotionDetection.hpp
rename to src/package_bgs/LBP_MRF/MotionDetection.hpp
index cd98597..ff47011 100644
--- a/package_bgs/LBP_MRF/MotionDetection.hpp
+++ b/src/package_bgs/LBP_MRF/MotionDetection.hpp
@@ -1,45 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- *  This file is part of the AiBO+ project
- *
- *  Copyright (C) 2005-2013 Csaba Kertész (csaba.kertesz@gmail.com)
- *
- *  AiBO+ is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  AiBO+ is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
 #pragma once
 
- /**
-  *  @addtogroup mindeye
-  *  @{
-  */
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
 
 #include "MEDefs.hpp"
 #include "MEImage.hpp"
@@ -410,4 +372,4 @@ private:
   bool HUOFCamMovement;
 };
 
-/** @} */
+#endif
diff --git a/src/package_bgs/LBP_MRF/block.h b/src/package_bgs/LBP_MRF/block.h
new file mode 100644
index 0000000..16c86b7
--- /dev/null
+++ b/src/package_bgs/LBP_MRF/block.h
@@ -0,0 +1,172 @@
+#pragma once
+
+#include <stdlib.h>
+#include <stdio.h>
+
+namespace ck
+{
+  template <class Type> class Block
+  {
+  public:
+    /* Constructor. Arguments are the block size and
+         (optionally) the pointer to the function which
+         will be called if allocation failed; the message
+         passed to this function is "Not enough memory!" */
+    Block(int size, void(*err_function)(char *) = NULL) { first = last = NULL; block_size = size; error_function = err_function; }
+
+    /* Destructor. Deallocates all items added so far */
+    ~Block() { while (first) { block *next = first->next; delete first; first = next; } }
+
+    /* Allocates 'num' consecutive items; returns pointer
+         to the first item. 'num' cannot be greater than the
+         block size since items must fit in one block */
+    Type *New(int num = 1)
+    {
+      Type *t;
+
+      if (!last || last->current + num > last->last)
+      {
+        if (last && last->next) last = last->next;
+        else
+        {
+          block *next = (block *) new char[sizeof(block) + (block_size - 1)*sizeof(Type)];
+          if (!next) { fprintf(stderr, "Not enough memory!"); exit(1); }
+          if (last) last->next = next;
+          else first = next;
+          last = next;
+          last->current = &(last->data[0]);
+          last->last = last->current + block_size;
+          last->next = NULL;
+        }
+      }
+
+      t = last->current;
+      last->current += num;
+      return t;
+    }
+
+    /* Returns the first item (or NULL, if no items were added) */
+    Type *ScanFirst()
+    {
+      scan_current_block = first;
+      if (!scan_current_block) return NULL;
+      scan_current_data = &(scan_current_block->data[0]);
+      return scan_current_data++;
+    }
+
+    /* Returns the next item (or NULL, if all items have been read)
+         Can be called only if previous ScanFirst() or ScanNext()
+         call returned not NULL. */
+    Type *ScanNext()
+    {
+      if (scan_current_data >= scan_current_block->current)
+      {
+        scan_current_block = scan_current_block->next;
+        if (!scan_current_block) return NULL;
+        scan_current_data = &(scan_current_block->data[0]);
+      }
+      return scan_current_data++;
+    }
+
+    /* Marks all elements as empty */
+    void Reset()
+    {
+      block *b;
+      if (!first) return;
+      for (b = first;; b = b->next)
+      {
+        b->current = &(b->data[0]);
+        if (b == last) break;
+      }
+      last = first;
+    }
+
+    /***********************************************************************/
+
+  private:
+
+    typedef struct block_st
+    {
+      Type					*current, *last;
+      struct block_st			*next;
+      Type					data[1];
+    } block;
+
+    int		block_size;
+    block	*first;
+    block	*last;
+
+    block	*scan_current_block;
+    Type	*scan_current_data;
+
+    void(*error_function)(char *);
+  };
+
+  /***********************************************************************/
+  /***********************************************************************/
+  /***********************************************************************/
+
+  template <class Type> class DBlock
+  {
+  public:
+    /* Constructor. Arguments are the block size and
+         (optionally) the pointer to the function which
+         will be called if allocation failed; the message
+         passed to this function is "Not enough memory!" */
+    DBlock(int size, void(*err_function)(char *) = NULL) { first = NULL; first_free = NULL; block_size = size; error_function = err_function; }
+
+    /* Destructor. Deallocates all items added so far */
+    ~DBlock() { while (first) { block *next = first->next; delete first; first = next; } }
+
+    /* Allocates one item */
+    Type *New()
+    {
+      block_item *item;
+
+      if (!first_free)
+      {
+        block *next = first;
+        first = (block *) new char[sizeof(block) + (block_size - 1)*sizeof(block_item)];
+        if (!first) { fprintf(stderr, "Not enough memory!"); exit(1); }
+        first_free = &(first->data[0]);
+        for (item = first_free; item < first_free + block_size - 1; item++)
+          item->next_free = item + 1;
+        item->next_free = NULL;
+        first->next = next;
+      }
+
+      item = first_free;
+      first_free = item->next_free;
+      return (Type *)item;
+    }
+
+    /* Deletes an item allocated previously */
+    void Delete(Type *t)
+    {
+      ((block_item *)t)->next_free = first_free;
+      first_free = (block_item *)t;
+    }
+
+    /***********************************************************************/
+
+  private:
+
+    typedef union block_item_st
+    {
+      Type			t;
+      block_item_st	*next_free;
+    } block_item;
+
+    typedef struct block_st
+    {
+      struct block_st			*next;
+      block_item				data[1];
+    } block;
+
+    int			block_size;
+    block		*first;
+    block_item	*first_free;
+
+    void(*error_function)(char *);
+  };
+}
diff --git a/src/package_bgs/LBP_MRF/graph.cpp b/src/package_bgs/LBP_MRF/graph.cpp
new file mode 100644
index 0000000..cdc1379
--- /dev/null
+++ b/src/package_bgs/LBP_MRF/graph.cpp
@@ -0,0 +1,65 @@
+#include <stdio.h>
+
+#include "graph.h"
+
+namespace ck
+{
+  Graph::Graph(void(*err_function)(char *))
+  {
+    error_function = err_function;
+    node_block = new Block<node>(NODE_BLOCK_SIZE, error_function);
+    arc_block = new Block<arc>(NODE_BLOCK_SIZE, error_function);
+    flow = 0;
+  }
+
+  Graph::~Graph()
+  {
+    delete node_block;
+    delete arc_block;
+  }
+
+  Graph::node_id Graph::add_node()
+  {
+    node *i = node_block->New();
+
+    i->first = NULL;
+    i->tr_cap = 0;
+
+    return (node_id)i;
+  }
+
+  void Graph::add_edge(node_id from, node_id to, captype cap, captype rev_cap)
+  {
+    arc *a, *a_rev;
+
+    a = arc_block->New(2);
+    a_rev = a + 1;
+
+    a->sister = a_rev;
+    a_rev->sister = a;
+    a->next = ((node*)from)->first;
+    ((node*)from)->first = a;
+    a_rev->next = ((node*)to)->first;
+    ((node*)to)->first = a_rev;
+    a->head = (node*)to;
+    a_rev->head = (node*)from;
+    a->r_cap = cap;
+    a_rev->r_cap = rev_cap;
+  }
+
+  void Graph::set_tweights(node_id i, captype cap_source, captype cap_sink)
+  {
+    flow += (cap_source < cap_sink) ? cap_source : cap_sink;
+    ((node*)i)->tr_cap = cap_source - cap_sink;
+  }
+
+  void Graph::add_tweights(node_id i, captype cap_source, captype cap_sink)
+  {
+    //register
+    captype delta = ((node*)i)->tr_cap; // 'register' storage class specifier is deprecated and incompatible with C++17
+    if (delta > 0) cap_source += delta;
+    else           cap_sink -= delta;
+    flow += (cap_source < cap_sink) ? cap_source : cap_sink;
+    ((node*)i)->tr_cap = cap_source - cap_sink;
+  }
+}
diff --git a/package_bgs/LBP_MRF/graph.h b/src/package_bgs/LBP_MRF/graph.h
similarity index 63%
rename from package_bgs/LBP_MRF/graph.h
rename to src/package_bgs/LBP_MRF/graph.h
index e7b83c7..a30e938 100644
--- a/package_bgs/LBP_MRF/graph.h
+++ b/src/package_bgs/LBP_MRF/graph.h
@@ -1,67 +1,12 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* graph.h */
-/*
-  This software library implements the maxflow algorithm
-  described in
-
-  An Experimental Comparison of Min-Cut/Max-Flow Algorithms
-  for Energy Minimization in Vision.
-  Yuri Boykov and Vladimir Kolmogorov.
-  In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI),
-  September 2004
-
-  This algorithm was developed by Yuri Boykov and Vladimir Kolmogorov
-  at Siemens Corporate Research. To make it available for public use,
-  it was later reimplemented by Vladimir Kolmogorov based on open publications.
-
-  If you use this software for research purposes, you should cite
-  the aforementioned paper in any resulting publication.
-  */
-  /*
-    Copyright 2001 Vladimir Kolmogorov (vnk@cs.cornell.edu), Yuri Boykov (yuri@csd.uwo.ca).
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-    */
-    /*
-      For description, example usage, discussion of graph representation
-      and memory usage see README.TXT.
-      */
 #pragma once
 
 #include "block.h"
 
-      /*
-        Nodes, arcs and pointers to nodes are
-        added in blocks for memory and time efficiency.
-        Below are numbers of items in blocks
-        */
+/*
+  Nodes, arcs and pointers to nodes are
+  added in blocks for memory and time efficiency.
+  Below are numbers of items in blocks
+  */
 #define NODE_BLOCK_SIZE 512
 #define ARC_BLOCK_SIZE 1024
 #define NODEPTR_BLOCK_SIZE 128
diff --git a/package_bgs/LBP_MRF/maxflow.cpp b/src/package_bgs/LBP_MRF/maxflow.cpp
similarity index 84%
rename from package_bgs/LBP_MRF/maxflow.cpp
rename to src/package_bgs/LBP_MRF/maxflow.cpp
index 6ddec50..05b3cef 100644
--- a/package_bgs/LBP_MRF/maxflow.cpp
+++ b/src/package_bgs/LBP_MRF/maxflow.cpp
@@ -1,62 +1,29 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* maxflow.cpp */
-/*
-    Copyright 2001 Vladimir Kolmogorov (vnk@cs.cornell.edu), Yuri Boykov (yuri@csd.uwo.ca).
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-    */
 #include <stdio.h>
+
 #include "graph.h"
 
-    /*
-      special constants for node->parent
-      */
+/*
+special constants for node->parent
+*/
 #define TERMINAL ( (arc *) 1 )		/* to terminal */
 #define ORPHAN   ( (arc *) 2 )		/* orphan */
 
 #define INFINITE_D 1000000000		/* infinite distance to the terminal */
 
-      /***********************************************************************/
+/***********************************************************************/
 
-      /*
-        Functions for processing active list.
-        i->next points to the next node in the list
-        (or to i, if i is the last node in the list).
-        If i->next is NULL iff i is not in the list.
-
-        There are two queues. Active nodes are added
-        to the end of the second queue and read from
-        the front of the first queue. If the first queue
-        is empty, it is replaced by the second queue
-        (and the second queue becomes empty).
-        */
+/*
+Functions for processing active list.
+i->next points to the next node in the list
+(or to i, if i is the last node in the list).
+If i->next is NULL iff i is not in the list.
+
+There are two queues. Active nodes are added
+to the end of the second queue and read from
+the front of the first queue. If the first queue
+is empty, it is replaced by the second queue
+(and the second queue becomes empty).
+*/
 namespace ck
 {
   inline void Graph::set_active(node *i)
diff --git a/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp b/src/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp
similarity index 74%
rename from package_bgs/LBSP/BackgroundSubtractorLBSP.cpp
rename to src/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp
index 2865a30..6344b6d 100644
--- a/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp
+++ b/src/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp
@@ -1,27 +1,13 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+#include <iostream>
+#include <iomanip>
+#include <exception>
 
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
 
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "BackgroundSubtractorLBSP.h"
 #include "DistanceUtils.h"
 #include "RandUtils.h"
-#include <iostream>
-#include <opencv2/imgproc/imgproc.hpp>
-#include <opencv2/highgui/highgui.hpp>
-#include <iomanip>
-#include <exception>
 
 #ifndef SIZE_MAX
 # if __WORDSIZE == 64
diff --git a/package_bgs/LBSP/BackgroundSubtractorLBSP.h b/src/package_bgs/LBSP/BackgroundSubtractorLBSP.h
similarity index 85%
rename from package_bgs/LBSP/BackgroundSubtractorLBSP.h
rename to src/package_bgs/LBSP/BackgroundSubtractorLBSP.h
index ef0576c..e22a10a 100644
--- a/package_bgs/LBSP/BackgroundSubtractorLBSP.h
+++ b/src/package_bgs/LBSP/BackgroundSubtractorLBSP.h
@@ -1,23 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <opencv2/features2d/features2d.hpp>
 #include <opencv2/video/background_segm.hpp>
+
 #include "LBSP.h"
 
 /*!
diff --git a/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp b/src/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp
similarity index 73%
rename from package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp
rename to src/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp
index 4e5d4a6..d5324bd 100644
--- a/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp
+++ b/src/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp
@@ -1,27 +1,13 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+#include <iostream>
+#include <iomanip>
+#include <exception>
 
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
 
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "BackgroundSubtractorLBSP_.h"
 #include "DistanceUtils.h"
 #include "RandUtils.h"
-#include <iostream>
-#include <opencv2/imgproc/imgproc.hpp>
-#include <opencv2/highgui/highgui.hpp>
-#include <iomanip>
-#include <exception>
 
 // local define used to determine the default median blur kernel size
 #define DEFAULT_MEDIAN_BLUR_KERNEL_SIZE (9)
diff --git a/package_bgs/LBSP/BackgroundSubtractorLBSP_.h b/src/package_bgs/LBSP/BackgroundSubtractorLBSP_.h
similarity index 86%
rename from package_bgs/LBSP/BackgroundSubtractorLBSP_.h
rename to src/package_bgs/LBSP/BackgroundSubtractorLBSP_.h
index 861f78a..d828e10 100644
--- a/package_bgs/LBSP/BackgroundSubtractorLBSP_.h
+++ b/src/package_bgs/LBSP/BackgroundSubtractorLBSP_.h
@@ -1,23 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <opencv2/features2d/features2d.hpp>
 #include <opencv2/video/background_segm.hpp>
+
 #include "LBSP_.h"
 
 /*!
diff --git a/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp b/src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp
similarity index 96%
rename from package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp
rename to src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp
index 9648c5c..1b67ae6 100644
--- a/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp
+++ b/src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp
@@ -1,26 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+#include <iostream>
+#include <iomanip>
 
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
 
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "BackgroundSubtractorLOBSTER.h"
-#include "DistanceUtils.h"
 #include "RandUtils.h"
-#include <iostream>
-#include <opencv2/imgproc/imgproc.hpp>
-#include <opencv2/highgui/highgui.hpp>
-#include <iomanip>
 
 BackgroundSubtractorLOBSTER::BackgroundSubtractorLOBSTER(float fRelLBSPThreshold
   , size_t nLBSPThresholdOffset
diff --git a/package_bgs/LBSP/BackgroundSubtractorLOBSTER.h b/src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.h
similarity index 85%
rename from package_bgs/LBSP/BackgroundSubtractorLOBSTER.h
rename to src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.h
index d69fd1c..d229e52 100644
--- a/package_bgs/LBSP/BackgroundSubtractorLOBSTER.h
+++ b/src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "BackgroundSubtractorLBSP.h"
diff --git a/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp b/src/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp
similarity index 99%
rename from package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp
rename to src/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp
index 6c48df3..8a1415d 100644
--- a/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp
+++ b/src/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp
@@ -1,26 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+#include <iostream>
+#include <iomanip>
 
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
 
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "BackgroundSubtractorPAWCS.h"
-#include "DistanceUtils.h"
 #include "RandUtils.h"
-#include <iostream>
-#include <opencv2/imgproc/imgproc.hpp>
-#include <opencv2/highgui/highgui.hpp>
-#include <iomanip>
 
 /*
  *
diff --git a/package_bgs/LBSP/BackgroundSubtractorPAWCS.h b/src/package_bgs/LBSP/BackgroundSubtractorPAWCS.h
similarity index 92%
rename from package_bgs/LBSP/BackgroundSubtractorPAWCS.h
rename to src/package_bgs/LBSP/BackgroundSubtractorPAWCS.h
index cafa48c..b32d5b7 100644
--- a/package_bgs/LBSP/BackgroundSubtractorPAWCS.h
+++ b/src/package_bgs/LBSP/BackgroundSubtractorPAWCS.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "BackgroundSubtractorLBSP_.h"
diff --git a/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp b/src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp
similarity index 98%
rename from package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp
rename to src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp
index 3dcc1b8..f965b04 100644
--- a/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp
+++ b/src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp
@@ -1,26 +1,11 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+#include <iostream>
+#include <iomanip>
 
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
 
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "BackgroundSubtractorSuBSENSE.h"
-#include "DistanceUtils.h"
 #include "RandUtils.h"
-#include <iostream>
-#include <opencv2/imgproc/imgproc.hpp>
-#include <opencv2/highgui/highgui.hpp>
-#include <iomanip>
 
 /*
  *
diff --git a/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h b/src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h
similarity index 91%
rename from package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h
rename to src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h
index 9950ea4..48c0a0d 100644
--- a/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h
+++ b/src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "BackgroundSubtractorLBSP.h"
diff --git a/package_bgs/LBSP/DistanceUtils.h b/src/package_bgs/LBSP/DistanceUtils.h
similarity index 95%
rename from package_bgs/LBSP/DistanceUtils.h
rename to src/package_bgs/LBSP/DistanceUtils.h
index 9eabca4..124d4bc 100644
--- a/package_bgs/LBSP/DistanceUtils.h
+++ b/src/package_bgs/LBSP/DistanceUtils.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <opencv2/core/types_c.h>
diff --git a/package_bgs/LBSP/LBSP.cpp b/src/package_bgs/LBSP/LBSP.cpp
similarity index 95%
rename from package_bgs/LBSP/LBSP.cpp
rename to src/package_bgs/LBSP/LBSP.cpp
index 4ec17b9..5f5a57a 100644
--- a/package_bgs/LBSP/LBSP.cpp
+++ b/src/package_bgs/LBSP/LBSP.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "LBSP.h"
 
 LBSP::LBSP(size_t nThreshold)
diff --git a/package_bgs/LBSP/LBSP.h b/src/package_bgs/LBSP/LBSP.h
similarity index 92%
rename from package_bgs/LBSP/LBSP.h
rename to src/package_bgs/LBSP/LBSP.h
index c908eaa..cab6a60 100644
--- a/package_bgs/LBSP/LBSP.h
+++ b/src/package_bgs/LBSP/LBSP.h
@@ -1,24 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <opencv2/core/core.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 #include <opencv2/features2d/features2d.hpp>
+
 #include "DistanceUtils.h"
 
 /*!
diff --git a/package_bgs/LBSP/LBSP_.cpp b/src/package_bgs/LBSP/LBSP_.cpp
similarity index 95%
rename from package_bgs/LBSP/LBSP_.cpp
rename to src/package_bgs/LBSP/LBSP_.cpp
index ff5c8e8..2cf2eb6 100644
--- a/package_bgs/LBSP/LBSP_.cpp
+++ b/src/package_bgs/LBSP/LBSP_.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "LBSP_.h"
 
 LBSP_::LBSP_(size_t nThreshold)
diff --git a/package_bgs/LBSP/LBSP_.h b/src/package_bgs/LBSP/LBSP_.h
similarity index 92%
rename from package_bgs/LBSP/LBSP_.h
rename to src/package_bgs/LBSP/LBSP_.h
index 819174a..25fd831 100644
--- a/package_bgs/LBSP/LBSP_.h
+++ b/src/package_bgs/LBSP/LBSP_.h
@@ -1,24 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <opencv2/core/core.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 #include <opencv2/features2d/features2d.hpp>
+
 #include "DistanceUtils.h"
 
 /*!
diff --git a/package_bgs/LBSP/LBSP_16bits_dbcross_1ch.i b/src/package_bgs/LBSP/LBSP_16bits_dbcross_1ch.i
similarity index 100%
rename from package_bgs/LBSP/LBSP_16bits_dbcross_1ch.i
rename to src/package_bgs/LBSP/LBSP_16bits_dbcross_1ch.i
diff --git a/package_bgs/LBSP/LBSP_16bits_dbcross_3ch1t.i b/src/package_bgs/LBSP/LBSP_16bits_dbcross_3ch1t.i
similarity index 100%
rename from package_bgs/LBSP/LBSP_16bits_dbcross_3ch1t.i
rename to src/package_bgs/LBSP/LBSP_16bits_dbcross_3ch1t.i
diff --git a/package_bgs/LBSP/LBSP_16bits_dbcross_3ch3t.i b/src/package_bgs/LBSP/LBSP_16bits_dbcross_3ch3t.i
similarity index 100%
rename from package_bgs/LBSP/LBSP_16bits_dbcross_3ch3t.i
rename to src/package_bgs/LBSP/LBSP_16bits_dbcross_3ch3t.i
diff --git a/package_bgs/LBSP/LBSP_16bits_dbcross_s3ch.i b/src/package_bgs/LBSP/LBSP_16bits_dbcross_s3ch.i
similarity index 100%
rename from package_bgs/LBSP/LBSP_16bits_dbcross_s3ch.i
rename to src/package_bgs/LBSP/LBSP_16bits_dbcross_s3ch.i
diff --git a/package_bgs/LBSP/RandUtils.h b/src/package_bgs/LBSP/RandUtils.h
similarity index 86%
rename from package_bgs/LBSP/RandUtils.h
rename to src/package_bgs/LBSP/RandUtils.h
index f676ca0..69f4432 100644
--- a/package_bgs/LBSP/RandUtils.h
+++ b/src/package_bgs/LBSP/RandUtils.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 /*// gaussian 3x3 pattern, based on 'floor(fspecial('gaussian', 3, 1)*256)'
diff --git a/package_bgs/LBSimpleGaussian.cpp b/src/package_bgs/LBSimpleGaussian.cpp
similarity index 51%
rename from package_bgs/LBSimpleGaussian.cpp
rename to src/package_bgs/LBSimpleGaussian.cpp
index 9ce071c..0ce5d93 100644
--- a/package_bgs/LBSimpleGaussian.cpp
+++ b/src/package_bgs/LBSimpleGaussian.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "LBSimpleGaussian.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 LBSimpleGaussian::LBSimpleGaussian() :
@@ -73,24 +59,27 @@ void LBSimpleGaussian::process(const cv::Mat &img_input, cv::Mat &img_output, cv
 
 void LBSimpleGaussian::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "sensitivity", sensitivity);
-  cvWriteInt(fs, "noiseVariance", noiseVariance);
-  cvWriteInt(fs, "learningRate", learningRate);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "sensitivity" << sensitivity;
+  fs << "noiseVariance" << noiseVariance;
+  fs << "learningRate" << learningRate;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void LBSimpleGaussian::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  sensitivity = cvReadIntByName(fs, nullptr, "sensitivity", 66);
-  noiseVariance = cvReadIntByName(fs, nullptr, "noiseVariance", 162);
-  learningRate = cvReadIntByName(fs, nullptr, "learningRate", 18);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["sensitivity"] >> sensitivity;
+  fs["noiseVariance"] >> noiseVariance;
+  fs["learningRate"] >> learningRate;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/LBSimpleGaussian.h b/src/package_bgs/LBSimpleGaussian.h
new file mode 100644
index 0000000..27eec9e
--- /dev/null
+++ b/src/package_bgs/LBSimpleGaussian.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "lb/BGModelGauss.h"
+
+using namespace lb_library;
+using namespace lb_library::SimpleGaussian;
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class LBSimpleGaussian : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BGModel* m_pBGModel;
+      int sensitivity;
+      int noiseVariance;
+      int learningRate;
+
+    public:
+      LBSimpleGaussian();
+      ~LBSimpleGaussian();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<LBSimpleGaussian> register_LBSimpleGaussian("LBSimpleGaussian");
+  }
+}
+
+#endif
diff --git a/src/package_bgs/LOBSTER.cpp b/src/package_bgs/LOBSTER.cpp
new file mode 100644
index 0000000..6b8178d
--- /dev/null
+++ b/src/package_bgs/LOBSTER.cpp
@@ -0,0 +1,83 @@
+#include "LOBSTER.h"
+
+using namespace bgslibrary::algorithms;
+
+LOBSTER::LOBSTER() :
+  pLOBSTER(nullptr),
+  fRelLBSPThreshold(BGSLOBSTER_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD),
+  nLBSPThresholdOffset(BGSLOBSTER_DEFAULT_LBSP_OFFSET_SIMILARITY_THRESHOLD),
+  nDescDistThreshold(BGSLOBSTER_DEFAULT_DESC_DIST_THRESHOLD),
+  nColorDistThreshold(BGSLOBSTER_DEFAULT_COLOR_DIST_THRESHOLD),
+  nBGSamples(BGSLOBSTER_DEFAULT_NB_BG_SAMPLES),
+  nRequiredBGSamples(BGSLOBSTER_DEFAULT_REQUIRED_NB_BG_SAMPLES)
+{
+  std::cout << "LOBSTER()" << std::endl;
+  setup("./config/LOBSTER.xml");
+}
+
+LOBSTER::~LOBSTER()
+{
+  if (pLOBSTER)
+    delete pLOBSTER;
+  std::cout << "~LOBSTER()" << std::endl;
+}
+
+void LOBSTER::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  if (firstTime)
+  {
+    pLOBSTER = new BackgroundSubtractorLOBSTER(
+      fRelLBSPThreshold, nLBSPThresholdOffset, nDescDistThreshold,
+      nColorDistThreshold, nBGSamples, nRequiredBGSamples);
+
+    pLOBSTER->initialize(img_input, cv::Mat(img_input.size(), CV_8UC1, cv::Scalar_<uchar>(255)));
+    firstTime = false;
+  }
+
+  pLOBSTER->apply(img_input, img_foreground);
+  pLOBSTER->getBackgroundImage(img_background);
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+  {
+    imshow("LOBSTER FG", img_foreground);
+    imshow("LOBSTER BG", img_background);
+  }
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+}
+
+void LOBSTER::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "fRelLBSPThreshold" << fRelLBSPThreshold;
+  fs << "nLBSPThresholdOffset" << nLBSPThresholdOffset;
+  fs << "nDescDistThreshold" << nDescDistThreshold;
+  fs << "nColorDistThreshold" << nColorDistThreshold;
+  fs << "nBGSamples" << nBGSamples;
+  fs << "nRequiredBGSamples" << nRequiredBGSamples;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void LOBSTER::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["fRelLBSPThreshold"] >> fRelLBSPThreshold;
+  fs["nLBSPThresholdOffset"] >> nLBSPThresholdOffset;
+  fs["nDescDistThreshold"] >> nDescDistThreshold;
+  fs["nColorDistThreshold"] >> nColorDistThreshold;
+  fs["nBGSamples"] >> nBGSamples;
+  fs["nRequiredBGSamples"] >> nRequiredBGSamples;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
diff --git a/src/package_bgs/LOBSTER.h b/src/package_bgs/LOBSTER.h
new file mode 100644
index 0000000..36e39d6
--- /dev/null
+++ b/src/package_bgs/LOBSTER.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+#include "LBSP/BackgroundSubtractorLOBSTER.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class LOBSTER : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BackgroundSubtractorLOBSTER* pLOBSTER;
+
+      float fRelLBSPThreshold;
+      int nLBSPThresholdOffset;
+      int nDescDistThreshold;
+      int nColorDistThreshold;
+      int nBGSamples;
+      int nRequiredBGSamples;
+
+    public:
+      LOBSTER();
+      ~LOBSTER();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<LOBSTER> register_LOBSTER("LOBSTER");
+  }
+}
diff --git a/package_bgs/MixtureOfGaussianV1.cpp b/src/package_bgs/MixtureOfGaussianV1.cpp
similarity index 60%
rename from package_bgs/MixtureOfGaussianV1.cpp
rename to src/package_bgs/MixtureOfGaussianV1.cpp
index e56609a..4094f39 100644
--- a/package_bgs/MixtureOfGaussianV1.cpp
+++ b/src/package_bgs/MixtureOfGaussianV1.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "MixtureOfGaussianV1.h"
 
 #if CV_MAJOR_VERSION == 2
@@ -76,25 +60,27 @@ void MixtureOfGaussianV1::process(const cv::Mat &img_input, cv::Mat &img_output,
 
 void MixtureOfGaussianV1::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "alpha" << alpha;
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void MixtureOfGaussianV1::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.05);
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["alpha"] >> alpha;
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
 #endif
diff --git a/package_bgs/MixtureOfGaussianV1.h b/src/package_bgs/MixtureOfGaussianV1.h
similarity index 50%
rename from package_bgs/MixtureOfGaussianV1.h
rename to src/package_bgs/MixtureOfGaussianV1.h
index edf8b6d..8c2ba86 100644
--- a/package_bgs/MixtureOfGaussianV1.h
+++ b/src/package_bgs/MixtureOfGaussianV1.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "opencv2/core/version.hpp"
@@ -24,12 +8,13 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include <opencv2/video/background_segm.hpp>
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class MixtureOfGaussianV1 : public IBGS
+    class MixtureOfGaussianV1 : public IBGS, public ILoadSaveConfig
     {
     private:
       cv::BackgroundSubtractorMOG mog;
diff --git a/package_bgs/MixtureOfGaussianV2.cpp b/src/package_bgs/MixtureOfGaussianV2.cpp
similarity index 66%
rename from package_bgs/MixtureOfGaussianV2.cpp
rename to src/package_bgs/MixtureOfGaussianV2.cpp
index 7aa1075..a68e495 100644
--- a/package_bgs/MixtureOfGaussianV2.cpp
+++ b/src/package_bgs/MixtureOfGaussianV2.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "MixtureOfGaussianV2.h"
 
 using namespace bgslibrary::algorithms;
@@ -84,24 +68,25 @@ void MixtureOfGaussianV2::process(const cv::Mat &img_input, cv::Mat &img_output,
 
 void MixtureOfGaussianV2::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "alpha" << alpha;
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void MixtureOfGaussianV2::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.05);
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["alpha"] >> alpha;
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
diff --git a/package_bgs/MixtureOfGaussianV2.h b/src/package_bgs/MixtureOfGaussianV2.h
similarity index 52%
rename from package_bgs/MixtureOfGaussianV2.h
rename to src/package_bgs/MixtureOfGaussianV2.h
index c359f20..7d60729 100644
--- a/package_bgs/MixtureOfGaussianV2.h
+++ b/src/package_bgs/MixtureOfGaussianV2.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <iostream>
@@ -21,12 +5,13 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include <opencv2/video/background_segm.hpp>
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class MixtureOfGaussianV2 : public IBGS
+    class MixtureOfGaussianV2 : public IBGS, public ILoadSaveConfig
     {
     private:
 #if CV_MAJOR_VERSION == 2
diff --git a/package_bgs/MultiCue.cpp b/src/package_bgs/MultiCue.cpp
similarity index 95%
rename from package_bgs/MultiCue.cpp
rename to src/package_bgs/MultiCue.cpp
index fd04ed1..de5016d 100644
--- a/package_bgs/MultiCue.cpp
+++ b/src/package_bgs/MultiCue.cpp
@@ -1,28 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-//------------------------------------------------------------------------------------------------------------------------------------//
-//									A BGS Method Using Multiple Color, Texture, Appearance Cues in the Scene						  //
-//																																	  //
-//  - Paper: A New Framework for Background Subtraction Using Multiple Cues (ACCV2012)												  //
-//  - Code by: SeungJon Noh																											  //
-//------------------------------------------------------------------------------------------------------------------------------------//
-//#include "StdAfx.h"
 #include "MultiCue.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms::libMultiCue;
 using namespace bgslibrary::algorithms;
 
@@ -119,50 +98,47 @@ void MultiCue::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &i
 
 void MultiCue::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-  cvWriteReal(fs, "g_fLearningRate", g_fLearningRate);
-  cvWriteInt(fs, "g_iAbsortionPeriod", g_iAbsortionPeriod);
-  cvWriteInt(fs, "g_iC_ModelThreshold", g_iC_ModelThreshold);
-  cvWriteInt(fs, "g_iT_ModelThreshold", g_iT_ModelThreshold);
-
-  cvWriteInt(fs, "g_iBackClearPeriod", g_iBackClearPeriod);
-  cvWriteInt(fs, "g_iCacheClearPeriod", g_iCacheClearPeriod);
-  cvWriteInt(fs, "g_nNeighborNum", g_nNeighborNum);
-  cvWriteInt(fs, "g_nRadius", g_nRadius);
-
-  cvWriteInt(fs, "g_nTextureTrainVolRange", g_nTextureTrainVolRange);
-  cvWriteInt(fs, "g_bAbsorptionEnable", g_bAbsorptionEnable);
-  cvWriteInt(fs, "g_iTrainingPeriod", g_iTrainingPeriod);
-  cvWriteInt(fs, "g_iRWidth", g_iRWidth);
-  cvWriteInt(fs, "g_iRHeight", g_iRHeight);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "g_fLearningRate" << g_fLearningRate;
+  fs << "g_iAbsortionPeriod" << g_iAbsortionPeriod;
+  fs << "g_iC_ModelThreshold" << g_iC_ModelThreshold;
+  fs << "g_iT_ModelThreshold" << g_iT_ModelThreshold;
+  fs << "g_iBackClearPeriod" << g_iBackClearPeriod;
+  fs << "g_iCacheClearPeriod" << g_iCacheClearPeriod;
+  fs << "g_nNeighborNum" << g_nNeighborNum;
+  fs << "g_nRadius" << g_nRadius;
+  fs << "g_nTextureTrainVolRange" << g_nTextureTrainVolRange;
+  fs << "g_bAbsorptionEnable" << g_bAbsorptionEnable;
+  fs << "g_iTrainingPeriod" << g_iTrainingPeriod;
+  fs << "g_iRWidth" << g_iRWidth;
+  fs << "g_iRHeight" << g_iRHeight;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void MultiCue::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-  g_fLearningRate = cvReadRealByName(fs, nullptr, "g_fLearningRate", g_fLearningRate);
-  g_iAbsortionPeriod = cvReadIntByName(fs, nullptr, "g_iAbsortionPeriod", g_iAbsortionPeriod);
-  g_iC_ModelThreshold = cvReadIntByName(fs, nullptr, "g_iC_ModelThreshold", g_iC_ModelThreshold);
-  g_iT_ModelThreshold = cvReadIntByName(fs, nullptr, "g_iT_ModelThreshold", g_iT_ModelThreshold);
-
-  g_iBackClearPeriod = cvReadIntByName(fs, nullptr, "g_iBackClearPeriod", g_iBackClearPeriod);
-  g_iCacheClearPeriod = cvReadIntByName(fs, nullptr, "g_iCacheClearPeriod", g_iCacheClearPeriod);
-  g_nNeighborNum = cvReadIntByName(fs, nullptr, "g_nNeighborNum", g_nNeighborNum);
-  g_nRadius = cvReadIntByName(fs, nullptr, "g_nRadius", g_nRadius);
-
-  g_nTextureTrainVolRange = cvReadIntByName(fs, nullptr, "g_nTextureTrainVolRange", g_nTextureTrainVolRange);
-  g_bAbsorptionEnable =  cvReadIntByName(fs, nullptr, "g_bAbsorptionEnable", g_bAbsorptionEnable);
-  g_iTrainingPeriod = cvReadIntByName(fs, nullptr, "g_iTrainingPeriod", g_iTrainingPeriod);
-  g_iRWidth = cvReadIntByName(fs, nullptr, "g_iRWidth", g_iRWidth);
-  g_iRHeight = cvReadIntByName(fs, nullptr, "g_iRHeight", g_iRHeight);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["g_fLearningRate"] >> g_fLearningRate;
+  fs["g_iAbsortionPeriod"] >> g_iAbsortionPeriod;
+  fs["g_iC_ModelThreshold"] >> g_iC_ModelThreshold;
+  fs["g_iT_ModelThreshold"] >> g_iT_ModelThreshold;
+  fs["g_iBackClearPeriod"] >> g_iBackClearPeriod;
+  fs["g_iCacheClearPeriod"] >> g_iCacheClearPeriod;
+  fs["g_nNeighborNum"] >> g_nNeighborNum;
+  fs["g_nRadius"] >> g_nRadius;
+  fs["g_nTextureTrainVolRange"] >> g_nTextureTrainVolRange;
+  fs["g_bAbsorptionEnable"] >> g_bAbsorptionEnable;
+  fs["g_iTrainingPeriod"] >> g_iTrainingPeriod;
+  fs["g_iRWidth"] >> g_iRWidth;
+  fs["g_iRHeight"] >> g_iRHeight;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
 
 //-----------------------------------------------------------------------------------------------------------------------------------------//
@@ -2097,3 +2073,5 @@ void MultiCue::C_Absorption(int iAbsorbCnt, point pos, short** aContinuCnt, shor
   pCache->m_Codewords = pTempCache;
   pCache->m_iNumEntries = k;
 }
+
+#endif
diff --git a/package_bgs/MultiCue.h b/src/package_bgs/MultiCue.h
similarity index 93%
rename from package_bgs/MultiCue.h
rename to src/package_bgs/MultiCue.h
index 47403a5..08900ab 100644
--- a/package_bgs/MultiCue.h
+++ b/src/package_bgs/MultiCue.h
@@ -1,21 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #define MIN3(x,y,z)  ((y) <= (z) ? ((x) <= (y) ? (x) : (y)) : ((x) <= (z) ? (x) : (z)))
 #define MAX3(x,y,z)  ((y) >= (z) ? ((x) >= (y) ? (x) : (y)) : ((x) >= (z) ? (x) : (z)))
 
@@ -43,6 +30,7 @@ typedef int BOOL;
 #include <opencv2/opencv.hpp>
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 
 //------------------------------------Structure Lists-------------------------------------//
 namespace bgslibrary
@@ -121,7 +109,7 @@ namespace bgslibrary
   {
     using namespace bgslibrary::algorithms::libMultiCue;
 
-    class MultiCue : public IBGS
+    class MultiCue : public IBGS, public ILoadSaveConfig
     {
     private:
       void saveConfig();
@@ -254,3 +242,5 @@ namespace bgslibrary
     static BGS_Register<MultiCue> register_MultiCue("MultiCue");
   }
 }
+
+#endif
diff --git a/package_bgs/MultiLayer.cpp b/src/package_bgs/MultiLayer.cpp
similarity index 57%
rename from package_bgs/MultiLayer.cpp
rename to src/package_bgs/MultiLayer.cpp
index 180d88d..caf409c 100644
--- a/package_bgs/MultiLayer.cpp
+++ b/src/package_bgs/MultiLayer.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "MultiLayer.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 MultiLayer::MultiLayer() :
@@ -249,82 +235,83 @@ void MultiLayer::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat
 
 void MultiLayer::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteString(fs, "preloadModel", bg_model_preload.c_str());
-  cvWriteInt(fs, "saveModel", saveModel);
-  cvWriteInt(fs, "detectAfter", detectAfter);
-  cvWriteInt(fs, "disableDetectMode", disableDetectMode);
-  cvWriteInt(fs, "disableLearningInDetecMode", disableLearning);
-  cvWriteInt(fs, "loadDefaultParams", loadDefaultParams);
-
-  cvWriteInt(fs, "max_mode_num", max_mode_num);
-  cvWriteReal(fs, "weight_updating_constant", weight_updating_constant);
-  cvWriteReal(fs, "texture_weight", texture_weight);
-  cvWriteReal(fs, "bg_mode_percent", bg_mode_percent);
-  cvWriteInt(fs, "pattern_neig_half_size", pattern_neig_half_size);
-  cvWriteReal(fs, "pattern_neig_gaus_sigma", pattern_neig_gaus_sigma);
-  cvWriteReal(fs, "bg_prob_threshold", bg_prob_threshold);
-  cvWriteReal(fs, "bg_prob_updating_threshold", bg_prob_updating_threshold);
-  cvWriteInt(fs, "robust_LBP_constant", robust_LBP_constant);
-  cvWriteReal(fs, "min_noised_angle", min_noised_angle);
-  cvWriteReal(fs, "shadow_rate", shadow_rate);
-  cvWriteReal(fs, "highlight_rate", highlight_rate);
-  cvWriteReal(fs, "bilater_filter_sigma_s", bilater_filter_sigma_s);
-  cvWriteReal(fs, "bilater_filter_sigma_r", bilater_filter_sigma_r);
-
-  cvWriteReal(fs, "frame_duration", frame_duration);
-
-  cvWriteReal(fs, "learn_mode_learn_rate_per_second", learn_mode_learn_rate_per_second);
-  cvWriteReal(fs, "learn_weight_learn_rate_per_second", learn_weight_learn_rate_per_second);
-  cvWriteReal(fs, "learn_init_mode_weight", learn_init_mode_weight);
-
-  cvWriteReal(fs, "detect_mode_learn_rate_per_second", detect_mode_learn_rate_per_second);
-  cvWriteReal(fs, "detect_weight_learn_rate_per_second", detect_weight_learn_rate_per_second);
-  cvWriteReal(fs, "detect_init_mode_weight", detect_init_mode_weight);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "preloadModel" << bg_model_preload;
+  fs << "saveModel" << saveModel;
+  fs << "detectAfter" << detectAfter;
+  fs << "disableDetectMode" << showOutput;
+  fs << "disableLearningInDetecMode" << disableLearning;
+  fs << "loadDefaultParams" << loadDefaultParams;
+  fs << "frame_duration" << frame_duration;
+  
+  fs << "max_mode_num" << max_mode_num;
+  fs << "weight_updating_constant" << weight_updating_constant;
+  fs << "texture_weight" << texture_weight;
+  fs << "bg_mode_percent" << bg_mode_percent;
+  fs << "pattern_neig_half_size" << pattern_neig_half_size;
+  fs << "pattern_neig_gaus_sigma" << pattern_neig_gaus_sigma;
+  fs << "bg_prob_threshold" << bg_prob_threshold;
+  fs << "bg_prob_updating_threshold" << bg_prob_updating_threshold;
+  fs << "robust_LBP_constant" << robust_LBP_constant;
+  fs << "min_noised_angle" << min_noised_angle;
+  fs << "shadow_rate" << shadow_rate;
+  fs << "highlight_rate" << highlight_rate;
+  fs << "bilater_filter_sigma_s" << bilater_filter_sigma_s;
+  fs << "bilater_filter_sigma_r" << bilater_filter_sigma_r;
+  
+  fs << "learn_mode_learn_rate_per_second" << learn_mode_learn_rate_per_second;
+  fs << "learn_weight_learn_rate_per_second" << learn_weight_learn_rate_per_second;
+  fs << "learn_init_mode_weight" << learn_init_mode_weight;
+  
+  fs << "detect_mode_learn_rate_per_second" << detect_mode_learn_rate_per_second;
+  fs << "detect_weight_learn_rate_per_second" << detect_weight_learn_rate_per_second;
+  fs << "detect_init_mode_weight" << detect_init_mode_weight;
+  
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void MultiLayer::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  bg_model_preload = cvReadStringByName(fs, nullptr, "preloadModel", "");
-  saveModel = cvReadIntByName(fs, nullptr, "saveModel", false);
-  detectAfter = cvReadIntByName(fs, nullptr, "detectAfter", 0);
-  disableDetectMode = cvReadIntByName(fs, nullptr, "disableDetectMode", true);
-  disableLearning = cvReadIntByName(fs, nullptr, "disableLearningInDetecMode", false);
-  loadDefaultParams = cvReadIntByName(fs, nullptr, "loadDefaultParams", true);
-
-  max_mode_num = cvReadIntByName(fs, nullptr, "max_mode_num", 5);
-  weight_updating_constant = cvReadRealByName(fs, 0, "weight_updating_constant", 5.0);
-  texture_weight = cvReadRealByName(fs, nullptr, "texture_weight", 0.5);
-  bg_mode_percent = cvReadRealByName(fs, nullptr, "bg_mode_percent", 0.6);
-  pattern_neig_half_size = cvReadIntByName(fs, nullptr, "pattern_neig_half_size", 4);
-  pattern_neig_gaus_sigma = cvReadRealByName(fs, nullptr, "pattern_neig_gaus_sigma", 3.0);
-  bg_prob_threshold = cvReadRealByName(fs, nullptr, "bg_prob_threshold", 0.2);
-  bg_prob_updating_threshold = cvReadRealByName(fs, nullptr, "bg_prob_updating_threshold", 0.2);
-  robust_LBP_constant = cvReadIntByName(fs, nullptr, "robust_LBP_constant", 3);
-  min_noised_angle = cvReadRealByName(fs, nullptr, "min_noised_angle", 0.01768);
-  shadow_rate = cvReadRealByName(fs, nullptr, "shadow_rate", 0.6);
-  highlight_rate = cvReadRealByName(fs, nullptr, "highlight_rate", 1.2);
-  bilater_filter_sigma_s = cvReadRealByName(fs, nullptr, "bilater_filter_sigma_s", 3.0);
-  bilater_filter_sigma_r = cvReadRealByName(fs, nullptr, "bilater_filter_sigma_r", 0.1);
-
-  frame_duration = cvReadRealByName(fs, nullptr, "frame_duration", 0.1);
-
-  learn_mode_learn_rate_per_second = cvReadRealByName(fs, nullptr, "learn_mode_learn_rate_per_second", 0.5);
-  learn_weight_learn_rate_per_second = cvReadRealByName(fs, nullptr, "learn_weight_learn_rate_per_second", 0.5);
-  learn_init_mode_weight = cvReadRealByName(fs, nullptr, "learn_init_mode_weight", 0.05);
-
-  detect_mode_learn_rate_per_second = cvReadRealByName(fs, nullptr, "detect_mode_learn_rate_per_second", 0.01);
-  detect_weight_learn_rate_per_second = cvReadRealByName(fs, nullptr, "detect_weight_learn_rate_per_second", 0.01);
-  detect_init_mode_weight = cvReadRealByName(fs, nullptr, "detect_init_mode_weight", 0.001);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["preloadModel"] >> bg_model_preload;
+  fs["saveModel"] >> saveModel;
+  fs["detectAfter"] >> detectAfter;
+  fs["disableDetectMode"] >> disableDetectMode;
+  fs["disableLearningInDetecMode"] >> disableLearning;
+  fs["loadDefaultParams"] >> loadDefaultParams;
+  fs["frame_duration"] >> frame_duration;
+  
+  fs["max_mode_num"] >> max_mode_num;
+  fs["weight_updating_constant"] >> weight_updating_constant;
+  fs["texture_weight"] >> texture_weight;
+  fs["bg_mode_percent"] >> bg_mode_percent;
+  fs["pattern_neig_half_size"] >> pattern_neig_half_size;
+  fs["pattern_neig_gaus_sigma"] >> pattern_neig_gaus_sigma;
+  fs["bg_prob_threshold"] >> bg_prob_threshold;
+  fs["bg_prob_updating_threshold"] >> bg_prob_updating_threshold;
+  fs["robust_LBP_constant"] >> robust_LBP_constant;
+  fs["min_noised_angle"] >> min_noised_angle;
+  fs["shadow_rate"] >> shadow_rate;
+  fs["highlight_rate"] >> highlight_rate;
+  fs["bilater_filter_sigma_s"] >> bilater_filter_sigma_s;
+  fs["bilater_filter_sigma_r"] >> bilater_filter_sigma_r;
+  
+  fs["learn_mode_learn_rate_per_second"] >> learn_mode_learn_rate_per_second;
+  fs["learn_weight_learn_rate_per_second"] >> learn_weight_learn_rate_per_second;
+  fs["learn_init_mode_weight"] >> learn_init_mode_weight;
+  
+  fs["detect_mode_learn_rate_per_second"] >> detect_mode_learn_rate_per_second;
+  fs["detect_weight_learn_rate_per_second"] >> detect_weight_learn_rate_per_second;
+  fs["detect_init_mode_weight"] >> detect_init_mode_weight;
+  
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/MultiLayer.h b/src/package_bgs/MultiLayer.h
similarity index 74%
rename from package_bgs/MultiLayer.h
rename to src/package_bgs/MultiLayer.h
index 86da592..0acc79f 100644
--- a/package_bgs/MultiLayer.h
+++ b/src/package_bgs/MultiLayer.h
@@ -1,29 +1,17 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "MultiLayer/CMultiLayerBGS.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class MultiLayer : public IBGS
+    class MultiLayer : public IBGS, public ILoadSaveConfig
     {
     public:
       enum Status
@@ -99,3 +87,5 @@ namespace bgslibrary
     static BGS_Register<MultiLayer> register_MultiLayer("MultiLayer");
   }
 }
+
+#endif
diff --git a/package_bgs/MultiLayer/BGS.h b/src/package_bgs/MultiLayer/BGS.h
similarity index 72%
rename from package_bgs/MultiLayer/BGS.h
rename to src/package_bgs/MultiLayer/BGS.h
index ad2129b..f1a478a 100644
--- a/package_bgs/MultiLayer/BGS.h
+++ b/src/package_bgs/MultiLayer/BGS.h
@@ -1,69 +1,17 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
 #pragma once
 
 #include "OpenCvLegacyIncludes.h"
 
-
-// TODO check these defines are not used (or not redundant with real params)
 #define MAX_LBP_MODE_NUM	5
-
 #define ROBUST_COLOR_OFFSET	6.0f
-
 #define LOW_INITIAL_MODE_WEIGHT	0.01f
-
 #define MODE_UPDATING_LEARN_RATE	0.01f
 #define WEIGHT_UPDATING_LEARN_RATE	0.01f
-
 #define COLOR_MAX_MIN_OFFSET		5
-
 #define BACKGROUND_MODEL_PERCENT	0.6f
-
 #define PATTERN_COLOR_DIST_BACKGROUND_THRESHOLD	0.2f
-
 #define PATTERN_DIST_SMOOTH_NEIG_HALF_SIZE	6
 #define PATTERN_DIST_CONV_GAUSSIAN_SIGMA	2.5f
-
 #define ROBUST_SHADOW_RATE	0.6f
 #define ROBUST_HIGHLIGHT_RATE	1.20f
 
diff --git a/package_bgs/MultiLayer/BackgroundSubtractionAPI.h b/src/package_bgs/MultiLayer/BackgroundSubtractionAPI.h
similarity index 56%
rename from package_bgs/MultiLayer/BackgroundSubtractionAPI.h
rename to src/package_bgs/MultiLayer/BackgroundSubtractionAPI.h
index 409fa40..0462d40 100644
--- a/package_bgs/MultiLayer/BackgroundSubtractionAPI.h
+++ b/src/package_bgs/MultiLayer/BackgroundSubtractionAPI.h
@@ -1,65 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-//////////////////////////////////////////////////////////////////////
-//
-// BackgroundSubtractionAPI.h: 
-//   interface for the BackgroundSubtractionAPI class.
-//
-// A background subtraction algorithm takes as input
-// an RGB image and provide as ouput a Binary mask
-// with a value of 0 for points belonging to the 
-// background, and non zero for points belonging
-// to the foreground.
-//
-//
-//
-// To add:
-//  - a function indicating the valid input and ouput
-//    images 
-//     e.g. RGB  image (default) or greylevel image for the input
-//          char image for the output
-//
-//////////////////////////////////////////////////////////////////////
 #pragma once
 
 #include "OpenCvLegacyIncludes.h"
diff --git a/package_bgs/MultiLayer/BlobExtraction.cpp b/src/package_bgs/MultiLayer/BlobExtraction.cpp
similarity index 94%
rename from package_bgs/MultiLayer/BlobExtraction.cpp
rename to src/package_bgs/MultiLayer/BlobExtraction.cpp
index 7aecd65..97d1e9a 100644
--- a/package_bgs/MultiLayer/BlobExtraction.cpp
+++ b/src/package_bgs/MultiLayer/BlobExtraction.cpp
@@ -1,57 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-//***********************************************************//
-//* Blob analysis package  8 August 2003                    *//
-//* Version 1.0                                             *//
-//* Input: IplImage* binary image                           *//
-//* Output: attributes of each connected region             *//
-//* Author: Dave Grossman                                   *//
-//* Modifications: Francesc Pinyol and Ricard Borras		*//
-//* Email: dgrossman@cdr.stanford.edu                       *//
-//* Email: fpinyol@cvc.uab.es rborras@cvc.uab.es            *//
-//* Acknowledgement: the algorithm has been around > 20 yrs *//
-//***********************************************************//
-
 //! Indica si la connectivitat es a 8 (si es desactiva es a 4)
 #define B_CONNECTIVITAT_8
 
@@ -67,14 +13,12 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 // color dels píxels de la màscara per ser exteriors
 #define PIXEL_EXTERIOR 0
 
-
 #include "BlobResult.h"
 #include "BlobExtraction.h"
 #include "OpenCvLegacyIncludes.h"
 
 namespace Blob
 {
-
   /**
     - FUNCIÓ: BlobAnalysis
     - FUNCIONALITAT: Extreu els blobs d'una imatge d'un sol canal
@@ -285,7 +229,7 @@ namespace Blob
               // pixels al sud de l'actual
               if (iRow < imatgePerimetreExtern->height - 1)
               {
-                if ((*(pMask + maskImage->widthStep) == PIXEL_EXTERIOR)) perimeter++;
+                if (*(pMask + maskImage->widthStep) == PIXEL_EXTERIOR) perimeter++;
               }
 
               *pPerimetre = perimeter;
diff --git a/src/package_bgs/MultiLayer/BlobExtraction.h b/src/package_bgs/MultiLayer/BlobExtraction.h
new file mode 100644
index 0000000..6a9dc94
--- /dev/null
+++ b/src/package_bgs/MultiLayer/BlobExtraction.h
@@ -0,0 +1,17 @@
+#pragma once
+
+namespace Blob
+{
+  //! Extreu els blobs d'una imatge
+  bool BlobAnalysis(IplImage* inputImage, uchar threshold, IplImage* maskImage,
+    bool borderColor, bool findmoments, blob_vector &RegionData);
+
+  // FUNCIONS AUXILIARS
+
+  //! Fusiona dos blobs
+  void Subsume(blob_vector &RegionData, int, int*, CBlob*, CBlob*, bool, int, int);
+  //! Reallocata el vector auxiliar de blobs subsumats
+  int *NewSubsume(int *SubSumedRegion, int elems_inbuffer);
+  //! Retorna el perimetre extern d'una run lenght
+  double GetExternPerimeter(int start, int end, int row, int width, int height, IplImage *maskImage);
+}
diff --git a/src/package_bgs/MultiLayer/BlobLibraryConfiguration.h b/src/package_bgs/MultiLayer/BlobLibraryConfiguration.h
new file mode 100644
index 0000000..7c7454e
--- /dev/null
+++ b/src/package_bgs/MultiLayer/BlobLibraryConfiguration.h
@@ -0,0 +1,9 @@
+#pragma once
+
+//! Indica si es volen fer servir les MatrixCV o no
+//! Use/Not use the MatrixCV class
+//#define MATRIXCV_ACTIU
+
+// Uses/not use the blob object factory
+//#define BLOB_OBJECT_FACTORY
+
diff --git a/package_bgs/MultiLayer/BlobResult.cpp b/src/package_bgs/MultiLayer/BlobResult.cpp
similarity index 91%
rename from package_bgs/MultiLayer/BlobResult.cpp
rename to src/package_bgs/MultiLayer/BlobResult.cpp
index 1ec60e3..f5b2f75 100644
--- a/package_bgs/MultiLayer/BlobResult.cpp
+++ b/src/package_bgs/MultiLayer/BlobResult.cpp
@@ -1,58 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-/************************************************************************
-BlobResult.cpp
-
-FUNCIONALITAT: Implementació de la classe CBlobResult
-AUTOR: Inspecta S.L.
-MODIFICACIONS (Modificació, Autor, Data):
-
-**************************************************************************/
-
 #include <limits.h>
 #include <stdio.h>
 #include <functional>
 #include <algorithm>
+
 #include "BlobResult.h"
 #include "BlobExtraction.h"
 
@@ -62,7 +12,6 @@ Constructors / Destructors
 
 namespace Blob
 {
-
   /**
     - FUNCIÓ: CBlobResult
     - FUNCIONALITAT: Constructor estandard.
diff --git a/package_bgs/MultiLayer/BlobResult.h b/src/package_bgs/MultiLayer/BlobResult.h
similarity index 62%
rename from package_bgs/MultiLayer/BlobResult.h
rename to src/package_bgs/MultiLayer/BlobResult.h
index aa3e37b..5ce3bd2 100644
--- a/package_bgs/MultiLayer/BlobResult.h
+++ b/src/package_bgs/MultiLayer/BlobResult.h
@@ -1,64 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
- * Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
- */
- /************************************************************************
-         BlobResult.h
-
-         FUNCIONALITAT: Definició de la classe CBlobResult
-         AUTOR: Inspecta S.L.
-         MODIFICACIONS (Modificació, Autor, Data):
-
-         FUNCTIONALITY: Definition of the CBlobResult class
-         AUTHOR: Inspecta S.L.
-         MODIFICATIONS (Modification, Author, Date):
-
-         **************************************************************************/
 #pragma once
 
-#include "BlobLibraryConfiguration.h"
 #include <math.h>
-         //#include "cxcore.h"
 #include <vector>
 #include <functional>
+
+#include "BlobLibraryConfiguration.h"
 #include "OpenCvLegacyIncludes.h"
 #include "blob.h"
 
diff --git a/package_bgs/MultiLayer/CMultiLayerBGS.cpp b/src/package_bgs/MultiLayer/CMultiLayerBGS.cpp
similarity index 96%
rename from package_bgs/MultiLayer/CMultiLayerBGS.cpp
rename to src/package_bgs/MultiLayer/CMultiLayerBGS.cpp
index b34cd0f..0708e57 100644
--- a/package_bgs/MultiLayer/CMultiLayerBGS.cpp
+++ b/src/package_bgs/MultiLayer/CMultiLayerBGS.cpp
@@ -1,58 +1,12 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-// BackgroundSubtraction.cpp: implementation of the CMultiLayerBGS class.
-//
-//////////////////////////////////////////////////////////////////////
+#include <ctime>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <cmath>
+#include <iostream>
 
 #include "CMultiLayerBGS.h"
-
-#include <ctime>						// clock
-#include <cstdlib>						// C standard library
-#include <cstdio>						// C I/O (for sscanf)
-#include <cstring>						// string manipulation
-#include <fstream>						// file I/O
-#include <cmath>						// math includes
-#include <iostream>                                             // I/O streams
 #include "OpenCvLegacyIncludes.h"
 
 using namespace Blob;
diff --git a/package_bgs/MultiLayer/CMultiLayerBGS.h b/src/package_bgs/MultiLayer/CMultiLayerBGS.h
similarity index 81%
rename from package_bgs/MultiLayer/CMultiLayerBGS.h
rename to src/package_bgs/MultiLayer/CMultiLayerBGS.h
index d9c2fb7..3043a80 100644
--- a/package_bgs/MultiLayer/CMultiLayerBGS.h
+++ b/src/package_bgs/MultiLayer/CMultiLayerBGS.h
@@ -1,48 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-// BackgroundSubtraction.h: interface for the CBackgroundSubtraction class.
-//
-//////////////////////////////////////////////////////////////////////
 #pragma once
 
 /*
@@ -50,30 +5,32 @@ Since the used fast cross bilateral filter codes can not be compiled under Windo
 we don't use the bilateral filter to remove the noise in the foreground detection
 step. If you compile it under Linux, please uncomment it.
 */
+
 //#define LINUX_BILATERAL_FILTER
-#include <opencv2/imgproc.hpp>
-#include "LocalBinaryPattern.h"
-#include "BGS.h"
+
 #include <stdio.h>
 #include <stdarg.h>
+#include <ctime>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <cmath>
+#include <iostream>
+
+#include <opencv2/imgproc.hpp>
+
+#include "LocalBinaryPattern.h"
 #include "BlobResult.h"
 #include "OpenCvDataConversion.h"
 
 #include "BackgroundSubtractionAPI.h"
 
 #ifdef LINUX_BILATERAL_FILTER
-#include "CrossBilateralFilter.h"				// cross bilateral filter
+#include "CrossBilateralFilter.h"
 #endif
 
-#include <ctime>						// clock
-#include <cstdlib>						// C standard library
-#include <cstdio>						// C I/O (for sscanf)
-#include <cstring>						// string manipulation
-#include <fstream>						// file I/O
-#include <cmath>						// math includes
-#include <iostream>						// I/O streams
-
-using namespace std;						// make std:: accessible
+using namespace std;
 
 class CMultiLayerBGS : public CBackgroundSubtractionAPI
 {
diff --git a/package_bgs/MultiLayer/LocalBinaryPattern.cpp b/src/package_bgs/MultiLayer/LocalBinaryPattern.cpp
similarity index 75%
rename from package_bgs/MultiLayer/LocalBinaryPattern.cpp
rename to src/package_bgs/MultiLayer/LocalBinaryPattern.cpp
index 060b9ea..d781d4e 100644
--- a/package_bgs/MultiLayer/LocalBinaryPattern.cpp
+++ b/src/package_bgs/MultiLayer/LocalBinaryPattern.cpp
@@ -1,49 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-// LocalBinaryPattern.cpp: implementation of the CLocalBinaryPattern class.
-//
-//////////////////////////////////////////////////////////////////////
-
 #include "LocalBinaryPattern.h"
 
 //////////////////////////////////////////////////////////////////////
diff --git a/src/package_bgs/MultiLayer/LocalBinaryPattern.h b/src/package_bgs/MultiLayer/LocalBinaryPattern.h
new file mode 100644
index 0000000..d02aa67
--- /dev/null
+++ b/src/package_bgs/MultiLayer/LocalBinaryPattern.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include <cstdio>
+
+#include "BGS.h"
+#include "OpenCvDataConversion.h"
+
+/************************************************************************/
+/* two types of computing the LBP operators but currently GENERAL_LBP   */
+/* has been implemented.                                                */
+/************************************************************************/
+#define	GENERAL_LBP	0
+#define SYMMETRIC_LBP	1
+
+class CLocalBinaryPattern
+{
+public:
+  void CalImageDifferenceMap(IplImage *cent_img, IplImage *neig_img, float *pattern, CvRect *roi = NULL);
+  void CalNeigPixelOffset(float radius, int tot_neig_pts_num, int neig_pt_idx, int &offset_x, int &offset_y);
+  void CalShiftedImage(IplImage *src, int offset_x, int offset_y, IplImage *dst, CvRect *roi = NULL);
+  void FreeMemories();
+  void ComputeLBP(PixelLBPStruct *PLBP, CvRect *roi = NULL);
+  void SetNewImages(IplImage **new_imgs);
+
+  IplImage** m_ppOrgImgs;			/* the original images used for computing the LBP operators */
+
+  void Initialization(IplImage **first_imgs, int imgs_num,
+    int level_num, float *radius, int *neig_pt_num,
+    float robust_white_noise = 3.0f, int type = GENERAL_LBP);
+
+  CLocalBinaryPattern();
+  virtual ~CLocalBinaryPattern();
+
+  float	m_fRobustWhiteNoise;		/* the robust noise value for computing the LBP operator in each channel */
+
+private:
+  void SetShiftedMeshGrid(CvSize img_size, float offset_x, float offset_y, CvMat *grid_map_x, CvMat *grid_map_y);
+
+  float*	m_pRadiuses;			/* the circle radiuses for the LBP operator */
+  //int	m_nLBPType;			/* the type of computing LBP operator */
+  int*	m_pNeigPointsNums;		/* the numbers of neighboring pixels on multi-level circles */
+  int	m_nImgsNum;			/* the number of multi-channel image */
+  int	m_nLBPLevelNum;			/* the number of multi-level LBP operator */
+  CvSize	m_cvImgSize;			/* the image size (width, height) */
+
+  CvPoint* m_pXYShifts;
+  CvPoint	m_nMaxShift;
+
+  IplImage* m_pShiftedImg;
+};
diff --git a/package_bgs/MultiLayer/OpenCvDataConversion.h b/src/package_bgs/MultiLayer/OpenCvDataConversion.h
similarity index 67%
rename from package_bgs/MultiLayer/OpenCvDataConversion.h
rename to src/package_bgs/MultiLayer/OpenCvDataConversion.h
index 18371b3..660443c 100644
--- a/package_bgs/MultiLayer/OpenCvDataConversion.h
+++ b/src/package_bgs/MultiLayer/OpenCvDataConversion.h
@@ -1,52 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-// OpencvDataConversion.h: interface for the COpencvDataConversion class.
-//
-//////////////////////////////////////////////////////////////////////
 #pragma once
 
-#include "OpenCvLegacyIncludes.h"
 #include <stdio.h>
+#include "OpenCvLegacyIncludes.h"
 
 template <class TI, class TM>		/* class TI - the type of image data, class TM - the type of matrix data */
 class COpencvDataConversion
diff --git a/src/package_bgs/MultiLayer/OpenCvLegacyIncludes.h b/src/package_bgs/MultiLayer/OpenCvLegacyIncludes.h
new file mode 100644
index 0000000..32151c2
--- /dev/null
+++ b/src/package_bgs/MultiLayer/OpenCvLegacyIncludes.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "opencv2/core/core_c.h"
+#include "opencv2/core/types_c.h"
+#include "opencv2/imgproc/imgproc_c.h"
diff --git a/package_bgs/MultiLayer/blob.cpp b/src/package_bgs/MultiLayer/blob.cpp
similarity index 92%
rename from package_bgs/MultiLayer/blob.cpp
rename to src/package_bgs/MultiLayer/blob.cpp
index 5e0fa45..62e879a 100644
--- a/package_bgs/MultiLayer/blob.cpp
+++ b/src/package_bgs/MultiLayer/blob.cpp
@@ -1,67 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-/************************************************************************
-Blob.cpp
-
-- FUNCIONALITAT: Implementació de la classe CBlob
-- AUTOR: Inspecta S.L.
-MODIFICACIONS (Modificació, Autor, Data):
-
-
-FUNCTIONALITY: Implementation of the CBlob class and some helper classes to perform
-some calculations on it
-AUTHOR: Inspecta S.L.
-MODIFICATIONS (Modification, Author, Date):
-
-**************************************************************************/
-
-
 #include <limits.h>
 #include "blob.h"
 
 namespace Blob
 {
-
   /**
     - FUNCIÓ: CBlob
     - FUNCIONALITAT: Constructor estàndard
diff --git a/package_bgs/MultiLayer/blob.h b/src/package_bgs/MultiLayer/blob.h
similarity index 88%
rename from package_bgs/MultiLayer/blob.h
rename to src/package_bgs/MultiLayer/blob.h
index b7d5fe1..624f177 100644
--- a/package_bgs/MultiLayer/blob.h
+++ b/src/package_bgs/MultiLayer/blob.h
@@ -1,72 +1,17 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/* --- --- ---
-* Copyright (C) 2008--2010 Idiap Research Institute (.....@idiap.ch)
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-*    notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-*    notice, this list of conditions and the following disclaimer in the
-*    documentation and/or other materials provided with the distribution.
-* 3. The name of the author may not be used to endorse or promote products
-*    derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-*/
-/************************************************************************
-Blob.h
-
-FUNCIONALITAT: Definició de la classe CBlob
-AUTOR: Inspecta S.L.
-MODIFICACIONS (Modificació, Autor, Data):
-
-FUNCTIONALITY: Definition of the CBlob class and some helper classes to perform
-some calculations on it
-AUTHOR: Inspecta S.L.
-MODIFICATIONS (Modification, Author, Date):
-
-**************************************************************************/
 #pragma once
 
-//#include "cxcore.h"
-#include "BlobLibraryConfiguration.h"
 #include <functional>
 #include <vector>
 #include <algorithm>
+
+#include "BlobLibraryConfiguration.h"
 #include "OpenCvLegacyIncludes.h"
+
 //! Factor de conversió de graus a radians
 #define DEGREE2RAD		(CV_PI / 180.0)
 
 namespace Blob
 {
-
   /**
     Classe que representa un blob, entés com un conjunt de pixels del
     mateix color contigus en una imatge binaritzada.
diff --git a/src/package_bgs/PAWCS.cpp b/src/package_bgs/PAWCS.cpp
new file mode 100644
index 0000000..8456b2b
--- /dev/null
+++ b/src/package_bgs/PAWCS.cpp
@@ -0,0 +1,78 @@
+#include "PAWCS.h"
+
+using namespace bgslibrary::algorithms;
+
+PAWCS::PAWCS() : pPAWCS(nullptr),
+fRelLBSPThreshold(BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD),
+nDescDistThresholdOffset(BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET),
+nMinColorDistThreshold(BGSPAWCS_DEFAULT_MIN_COLOR_DIST_THRESHOLD),
+nMaxNbWords(BGSPAWCS_DEFAULT_MAX_NB_WORDS),
+nSamplesForMovingAvgs(BGSPAWCS_DEFAULT_N_SAMPLES_FOR_MV_AVGS)
+{
+  std::cout << "PAWCS()" << std::endl;
+  setup("./config/PAWCS.xml");
+}
+PAWCS::~PAWCS()
+{
+  if (pPAWCS)
+    delete pPAWCS;
+  std::cout << "~PAWCS()" << std::endl;
+}
+
+void PAWCS::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  if (firstTime)
+  {
+    pPAWCS = new BackgroundSubtractorPAWCS(
+      fRelLBSPThreshold, nDescDistThresholdOffset, nMinColorDistThreshold,
+      nMaxNbWords, nSamplesForMovingAvgs);
+
+    pPAWCS->initialize(img_input, cv::Mat(img_input.size(), CV_8UC1, cv::Scalar_<uchar>(255)));
+    firstTime = false;
+  }
+
+  pPAWCS->apply(img_input, img_foreground);
+  pPAWCS->getBackgroundImage(img_background);
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+  {
+    imshow("PAWCS FG", img_foreground);
+    imshow("PAWCS BG", img_background);
+  }
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+}
+
+void PAWCS::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "fRelLBSPThreshold" << fRelLBSPThreshold;
+  fs << "nDescDistThresholdOffset" << nDescDistThresholdOffset;
+  fs << "nMinColorDistThreshold" << nMinColorDistThreshold;
+  fs << "nMaxNbWords" << nMaxNbWords;
+  fs << "nSamplesForMovingAvgs" << nSamplesForMovingAvgs;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void PAWCS::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["fRelLBSPThreshold"] >> fRelLBSPThreshold;
+  fs["nDescDistThresholdOffset"] >> nDescDistThresholdOffset;
+  fs["nMinColorDistThreshold"] >> nMinColorDistThreshold;
+  fs["nMaxNbWords"] >> nMaxNbWords;
+  fs["nSamplesForMovingAvgs"] >> nSamplesForMovingAvgs;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
diff --git a/src/package_bgs/PAWCS.h b/src/package_bgs/PAWCS.h
new file mode 100644
index 0000000..5644de7
--- /dev/null
+++ b/src/package_bgs/PAWCS.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+#include "LBSP/BackgroundSubtractorPAWCS.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class PAWCS : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BackgroundSubtractorPAWCS* pPAWCS;
+
+      float fRelLBSPThreshold;
+      int nDescDistThresholdOffset;
+      int nMinColorDistThreshold;
+      int nMaxNbWords;
+      int nSamplesForMovingAvgs;
+
+    public:
+      PAWCS();
+      ~PAWCS();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<PAWCS> register_PAWCS("PAWCS");
+  }
+}
diff --git a/package_bgs/PBAS/PBAS.cpp b/src/package_bgs/PBAS/PBAS.cpp
similarity index 95%
rename from package_bgs/PBAS/PBAS.cpp
rename to src/package_bgs/PBAS/PBAS.cpp
index bc3ad40..36ed459 100644
--- a/package_bgs/PBAS/PBAS.cpp
+++ b/src/package_bgs/PBAS/PBAS.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "PBAS.h"
 
 PBAS::PBAS(void) : N(20), R_lower(18), Raute_min(2), T_lower(2), T_upper(200), R_scale(5), R_incdec(0.05), T_dec(0.05), T_inc(1)
diff --git a/package_bgs/PBAS/PBAS.h b/src/package_bgs/PBAS/PBAS.h
similarity index 73%
rename from package_bgs/PBAS/PBAS.h
rename to src/package_bgs/PBAS/PBAS.h
index c05ba12..d58dceb 100644
--- a/package_bgs/PBAS/PBAS.h
+++ b/src/package_bgs/PBAS/PBAS.h
@@ -1,56 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-//Implementation of the PBAS from:
-//
-//M. Hofmann, P. Tiefenbacher, G. Rigoll 
-//"Background Segmentation with Feedback: The Pixel-Based Adaptive Segmenter", 
-//in proc of IEEE Workshop on Change Detection, 2012
-//
-//Note: some changes, to improve the speed and memory requirements, were achieved in comparison to the 
-//described PBAS algorithm in the paper above.
-//
-//Example usage:
-// //Somewhere during initalization:
-// #include "PBAS.h"
-// #include <opencv2/opencv.hpp>
-// PBAS pbas;
-//
-// //you might want to change some parameters of the PBAS here...
-// ....
-//
-// //repeat for each frame
-// //make gaussian blur for reducing image noise
-//cv::Mat bluredImage;
-//cv::Mat pbastResult;
-//cv::GaussianBlur(singleFrame, bluredImage, cv::Size(5,5), 1.5);
-// 
-// //process image and receive segmentation in pbasResult
-//pbas.process(&bluredImage, &pbasResult);
-//
-// //make medianBlur on the result to reduce "salt and pepper noise"
-// //of the per pixel wise segmentation
-//cv::medianBlur(pbasResult, pbasResult, 5);
-//
-//
-//
-//Author: P.Tiefenbacher, https://sites.google.com/site/pbassegmenter/
-//Technische Universität München, Germany
-//Date: 22-May-2012, Version:0.1
-///////////
 #pragma once
 
 #include <iostream>
@@ -79,7 +26,6 @@ public:
 
   bool isMovement();
 
-
 private:
   void calculateFeatures(std::vector<cv::Mat>* feature, cv::Mat* inputImage);
   void checkValid(int *x, int *y);
@@ -201,7 +147,5 @@ private:
 
   //#####################################################################################
 
-
   cv::Mat sobelX, sobelY;
 };
-
diff --git a/src/package_bgs/PixelBasedAdaptiveSegmenter.cpp b/src/package_bgs/PixelBasedAdaptiveSegmenter.cpp
new file mode 100644
index 0000000..90860de
--- /dev/null
+++ b/src/package_bgs/PixelBasedAdaptiveSegmenter.cpp
@@ -0,0 +1,109 @@
+#include "PixelBasedAdaptiveSegmenter.h"
+
+using namespace bgslibrary::algorithms;
+
+PixelBasedAdaptiveSegmenter::PixelBasedAdaptiveSegmenter() :
+  enableInputBlur(true), enableOutputBlur(true),
+  alpha(7.0), beta(1.0), N(20), Raute_min(2), R_incdec(0.05), R_lower(18),
+  R_scale(5), T_dec(0.05), T_inc(1), T_init(18), T_lower(2), T_upper(200)
+{
+  std::cout << "PixelBasedAdaptiveSegmenter()" << std::endl;
+  setup("./config/PixelBasedAdaptiveSegmenter.xml");
+}
+
+PixelBasedAdaptiveSegmenter::~PixelBasedAdaptiveSegmenter()
+{
+  std::cout << "~PixelBasedAdaptiveSegmenter()" << std::endl;
+}
+
+void PixelBasedAdaptiveSegmenter::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  if (firstTime)
+  {
+    pbas.setAlpha(alpha);
+    pbas.setBeta(beta);
+    pbas.setN(N);
+    pbas.setRaute_min(Raute_min);
+    pbas.setR_incdec(R_incdec);
+    pbas.setR_lower(R_lower);
+    pbas.setR_scale(R_scale);
+    pbas.setT_dec(T_dec);
+    pbas.setT_inc(T_inc);
+    pbas.setT_init(T_init);
+    pbas.setT_lower(T_lower);
+    pbas.setT_upper(T_upper);
+  }
+
+  cv::Mat img_input_new;
+  if (enableInputBlur)
+    cv::GaussianBlur(img_input, img_input_new, cv::Size(5, 5), 1.5);
+  else
+    img_input.copyTo(img_input_new);
+
+  pbas.process(&img_input_new, &img_foreground);
+  img_background = cv::Mat::zeros(img_input.size(), img_input.type());
+
+  if (enableOutputBlur)
+    cv::medianBlur(img_foreground, img_foreground, 5);
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+    cv::imshow("PBAS", img_foreground);
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+
+  firstTime = false;
+}
+
+void PixelBasedAdaptiveSegmenter::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "enableInputBlur" << enableInputBlur;
+  fs << "enableOutputBlur" << enableOutputBlur;
+  
+  fs << "alpha" << alpha;
+  fs << "beta" << beta;
+  fs << "N" << N;
+  fs << "Raute_min" << Raute_min;
+  fs << "R_incdec" << R_incdec;
+  fs << "R_lower" << R_lower;
+  fs << "R_scale" << R_scale;
+  fs << "T_dec" << T_dec;
+  fs << "T_inc" << T_inc;
+  fs << "T_init" << T_init;
+  fs << "T_lower" << T_lower;
+  fs << "T_upper" << T_upper;
+  
+  fs << "showOutput" << showOutput;
+}
+
+void PixelBasedAdaptiveSegmenter::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["enableInputBlur"] >> enableInputBlur;
+  fs["enableOutputBlur"] >> enableOutputBlur;
+  
+  fs["alpha"] >> alpha;
+  fs["beta"] >> beta;
+  fs["N"] >> N;
+  fs["Raute_min"] >> Raute_min;
+  fs["R_incdec"] >> R_incdec;
+  fs["R_lower"] >> R_lower;
+  fs["R_scale"] >> R_scale;
+  fs["T_dec"] >> T_dec;
+  fs["T_inc"] >> T_inc;
+  fs["T_init"] >> T_init;
+  fs["T_lower"] >> T_lower;
+  fs["T_upper"] >> T_upper;
+  
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
diff --git a/package_bgs/PixelBasedAdaptiveSegmenter.h b/src/package_bgs/PixelBasedAdaptiveSegmenter.h
similarity index 53%
rename from package_bgs/PixelBasedAdaptiveSegmenter.h
rename to src/package_bgs/PixelBasedAdaptiveSegmenter.h
index acafc90..9e072bf 100644
--- a/package_bgs/PixelBasedAdaptiveSegmenter.h
+++ b/src/package_bgs/PixelBasedAdaptiveSegmenter.h
@@ -1,29 +1,14 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "PBAS/PBAS.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class PixelBasedAdaptiveSegmenter : public IBGS
+    class PixelBasedAdaptiveSegmenter : public IBGS, public ILoadSaveConfig
     {
     private:
       PBAS pbas;
diff --git a/package_bgs/SigmaDelta.cpp b/src/package_bgs/SigmaDelta.cpp
similarity index 56%
rename from package_bgs/SigmaDelta.cpp
rename to src/package_bgs/SigmaDelta.cpp
index d305226..65a94b6 100644
--- a/package_bgs/SigmaDelta.cpp
+++ b/src/package_bgs/SigmaDelta.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "SigmaDelta.h"
 
 using namespace bgslibrary::algorithms;
@@ -69,28 +53,29 @@ void SigmaDelta::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat
 
 void SigmaDelta::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "ampFactor", ampFactor);
-  cvWriteInt(fs, "minVar", minVar);
-  cvWriteInt(fs, "maxVar", maxVar);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "ampFactor" << ampFactor;
+  fs << "minVar" << minVar;
+  fs << "maxVar" << maxVar;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void SigmaDelta::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  ampFactor = cvReadIntByName(fs, nullptr, "ampFactor", 1);
-  minVar = cvReadIntByName(fs, nullptr, "minVar", 15);
-  maxVar = cvReadIntByName(fs, nullptr, "maxVar", 255);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["ampFactor"] >> ampFactor;
+  fs["minVar"] >> minVar;
+  fs["maxVar"] >> maxVar;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+  
   applyParams();
-
-  cvReleaseFileStorage(&fs);
 }
 
 void SigmaDelta::applyParams()
diff --git a/src/package_bgs/SigmaDelta.h b/src/package_bgs/SigmaDelta.h
new file mode 100644
index 0000000..6ddd35d
--- /dev/null
+++ b/src/package_bgs/SigmaDelta.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+//extern "C" {
+#include "SigmaDelta/sdLaMa091.h"
+//}
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class SigmaDelta : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      int ampFactor;
+      int minVar;
+      int maxVar;
+      sdLaMa091_t* algorithm;
+
+    public:
+      SigmaDelta();
+      ~SigmaDelta();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+      void applyParams();
+    };
+
+    static BGS_Register<SigmaDelta> register_SigmaDelta("SigmaDelta");
+  }
+}
diff --git a/package_bgs/SigmaDelta/sdLaMa091.cpp b/src/package_bgs/SigmaDelta/sdLaMa091.cpp
similarity index 95%
rename from package_bgs/SigmaDelta/sdLaMa091.cpp
rename to src/package_bgs/SigmaDelta/sdLaMa091.cpp
index 286556b..6a8c9a5 100644
--- a/package_bgs/SigmaDelta/sdLaMa091.cpp
+++ b/src/package_bgs/SigmaDelta/sdLaMa091.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include "sdLaMa091.h"
 
 #define DEFAULT_N 1
diff --git a/package_bgs/SigmaDelta/sdLaMa091.h b/src/package_bgs/SigmaDelta/sdLaMa091.h
similarity index 67%
rename from package_bgs/SigmaDelta/sdLaMa091.h
rename to src/package_bgs/SigmaDelta/sdLaMa091.h
index cf9e777..996c1b9 100644
--- a/package_bgs/SigmaDelta/sdLaMa091.h
+++ b/src/package_bgs/SigmaDelta/sdLaMa091.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <errno.h>
diff --git a/src/package_bgs/StaticFrameDifference.cpp b/src/package_bgs/StaticFrameDifference.cpp
new file mode 100644
index 0000000..df46e6e
--- /dev/null
+++ b/src/package_bgs/StaticFrameDifference.cpp
@@ -0,0 +1,64 @@
+#include "StaticFrameDifference.h"
+
+using namespace bgslibrary::algorithms;
+
+StaticFrameDifference::StaticFrameDifference() :
+  enableThreshold(true), threshold(15)
+{
+  std::cout << "StaticFrameDifference()" << std::endl;
+  setup("./config/StaticFrameDifference.xml");
+}
+
+StaticFrameDifference::~StaticFrameDifference()
+{
+  std::cout << "~StaticFrameDifference()" << std::endl;
+}
+
+void StaticFrameDifference::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  if (img_background.empty())
+    img_input.copyTo(img_background);
+
+  cv::absdiff(img_input, img_background, img_foreground);
+
+  if (img_foreground.channels() == 3)
+    cv::cvtColor(img_foreground, img_foreground, CV_BGR2GRAY);
+
+  if (enableThreshold)
+    cv::threshold(img_foreground, img_foreground, threshold, 255, cv::THRESH_BINARY);
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+    cv::imshow("Static Frame Difference", img_foreground);
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+
+  firstTime = false;
+}
+
+void StaticFrameDifference::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void StaticFrameDifference::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
diff --git a/src/package_bgs/StaticFrameDifference.h b/src/package_bgs/StaticFrameDifference.h
new file mode 100644
index 0000000..a08c8a1
--- /dev/null
+++ b/src/package_bgs/StaticFrameDifference.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class StaticFrameDifference : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      bool enableThreshold;
+      int threshold;
+
+    public:
+      StaticFrameDifference();
+      ~StaticFrameDifference();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<StaticFrameDifference> register_StaticFrameDifference("StaticFrameDifference");
+  }
+}
diff --git a/src/package_bgs/SuBSENSE.cpp b/src/package_bgs/SuBSENSE.cpp
new file mode 100644
index 0000000..fe3aeac
--- /dev/null
+++ b/src/package_bgs/SuBSENSE.cpp
@@ -0,0 +1,81 @@
+#include "SuBSENSE.h"
+
+using namespace bgslibrary::algorithms;
+
+SuBSENSE::SuBSENSE() :
+  pSubsense(0),
+  fRelLBSPThreshold(BGSSUBSENSE_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD),
+  nDescDistThresholdOffset(BGSSUBSENSE_DEFAULT_DESC_DIST_THRESHOLD_OFFSET),
+  nMinColorDistThreshold(BGSSUBSENSE_DEFAULT_MIN_COLOR_DIST_THRESHOLD),
+  nBGSamples(BGSSUBSENSE_DEFAULT_NB_BG_SAMPLES),
+  nRequiredBGSamples(BGSSUBSENSE_DEFAULT_REQUIRED_NB_BG_SAMPLES),
+  nSamplesForMovingAvgs(BGSSUBSENSE_DEFAULT_N_SAMPLES_FOR_MV_AVGS)
+{
+  std::cout << "SuBSENSE()" << std::endl;
+}
+
+SuBSENSE::~SuBSENSE() {
+  if (pSubsense)
+    delete pSubsense;
+  std::cout << "~SuBSENSE()" << std::endl;
+}
+
+void SuBSENSE::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
+{
+  init(img_input, img_output, img_bgmodel);
+
+  if (firstTime)
+  {
+    pSubsense = new BackgroundSubtractorSuBSENSE(
+      fRelLBSPThreshold, nDescDistThresholdOffset, nMinColorDistThreshold,
+      nBGSamples, nRequiredBGSamples, nSamplesForMovingAvgs);
+
+    pSubsense->initialize(img_input, cv::Mat(img_input.size(), CV_8UC1, cv::Scalar_<uchar>(255)));
+    firstTime = false;
+  }
+
+  pSubsense->apply(img_input, img_foreground);
+  pSubsense->getBackgroundImage(img_background);
+
+#ifndef MEX_COMPILE_FLAG
+  if (showOutput)
+  {
+    imshow("SuBSENSE FG", img_foreground);
+    imshow("SuBSENSE BG", img_background);
+  }
+#endif
+
+  img_foreground.copyTo(img_output);
+  img_background.copyTo(img_bgmodel);
+}
+
+void SuBSENSE::saveConfig()
+{
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "fRelLBSPThreshold" << fRelLBSPThreshold;
+  fs << "nDescDistThresholdOffset" << nDescDistThresholdOffset;
+  fs << "nMinColorDistThreshold" << nMinColorDistThreshold;
+  fs << "nBGSamples" << nBGSamples;
+  fs << "nRequiredBGSamples" << nRequiredBGSamples;
+  fs << "nSamplesForMovingAvgs" << nSamplesForMovingAvgs;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
+}
+
+void SuBSENSE::loadConfig()
+{
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["fRelLBSPThreshold"] >> fRelLBSPThreshold;
+  fs["nDescDistThresholdOffset"] >> nDescDistThresholdOffset;
+  fs["nMinColorDistThreshold"] >> nMinColorDistThreshold;
+  fs["nBGSamples"] >> nBGSamples;
+  fs["nRequiredBGSamples"] >> nRequiredBGSamples;
+  fs["nSamplesForMovingAvgs"] >> nSamplesForMovingAvgs;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
+}
diff --git a/src/package_bgs/SuBSENSE.h b/src/package_bgs/SuBSENSE.h
new file mode 100644
index 0000000..754072e
--- /dev/null
+++ b/src/package_bgs/SuBSENSE.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+#include "LBSP/BackgroundSubtractorSuBSENSE.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class SuBSENSE : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      BackgroundSubtractorSuBSENSE* pSubsense;
+
+      float fRelLBSPThreshold;
+      int nDescDistThresholdOffset;
+      int nMinColorDistThreshold;
+      int nBGSamples;
+      int nRequiredBGSamples;
+      int nSamplesForMovingAvgs;
+
+    public:
+      SuBSENSE();
+      ~SuBSENSE();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<SuBSENSE> register_SuBSENSE("SuBSENSE");
+  }
+}
diff --git a/package_bgs/T2F/FuzzyUtils.cpp b/src/package_bgs/T2F/FuzzyUtils.cpp
similarity index 96%
rename from package_bgs/T2F/FuzzyUtils.cpp
rename to src/package_bgs/T2F/FuzzyUtils.cpp
index a151136..8728f86 100644
--- a/package_bgs/T2F/FuzzyUtils.cpp
+++ b/src/package_bgs/T2F/FuzzyUtils.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "FuzzyUtils.h"
 
 FuzzyUtils::FuzzyUtils(void) {}
diff --git a/package_bgs/T2F/FuzzyUtils.h b/src/package_bgs/T2F/FuzzyUtils.h
similarity index 62%
rename from package_bgs/T2F/FuzzyUtils.h
rename to src/package_bgs/T2F/FuzzyUtils.h
index 9a53a83..608b01d 100644
--- a/package_bgs/T2F/FuzzyUtils.h
+++ b/src/package_bgs/T2F/FuzzyUtils.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "../../package_analysis/PixelUtils.h"
diff --git a/package_bgs/T2F/MRF.cpp b/src/package_bgs/T2F/MRF.cpp
similarity index 91%
rename from package_bgs/T2F/MRF.cpp
rename to src/package_bgs/T2F/MRF.cpp
index 291a846..aeaa0d1 100644
--- a/package_bgs/T2F/MRF.cpp
+++ b/src/package_bgs/T2F/MRF.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "MRF.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 //init the basic MRF
@@ -336,3 +322,5 @@ void MRF_TC::ICM2()
     OnIterationOver2();
   } while (K < 2);
 }
+
+#endif
diff --git a/package_bgs/T2F/MRF.h b/src/package_bgs/T2F/MRF.h
similarity index 77%
rename from package_bgs/T2F/MRF.h
rename to src/package_bgs/T2F/MRF.h
index 1276a30..82fd283 100644
--- a/package_bgs/T2F/MRF.h
+++ b/src/package_bgs/T2F/MRF.h
@@ -1,21 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "T2FMRF.h"
 
 namespace Algorithms
@@ -102,3 +89,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/package_bgs/T2F/T2FGMM.cpp b/src/package_bgs/T2F/T2FGMM.cpp
similarity index 89%
rename from package_bgs/T2F/T2FGMM.cpp
rename to src/package_bgs/T2F/T2FGMM.cpp
index 6ff9997..abba712 100644
--- a/package_bgs/T2F/T2FGMM.cpp
+++ b/src/package_bgs/T2F/T2FGMM.cpp
@@ -1,31 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* T2FGMM.cpp
-*
-* Purpose: Implementation of the T2 Fuzzy Gaussian Mixture Models (T2GMMs)
-* "Modeling of Dynamic Backgrounds by Type-2 Fuzzy Gaussians Mixture Models"
-* Author: Fida El Baf, Thierry Bouwmans, September 2008.
-
-******************************************************************************/
-
 #include "T2FGMM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 int compareT2FGMM(const void* _gmm1, const void* _gmm2)
@@ -334,3 +310,5 @@ void T2FGMM::Subtract(int frame_num, const RgbImage& data, BwImage& low_threshol
     }
   }
 }
+
+#endif
diff --git a/package_bgs/T2F/T2FGMM.h b/src/package_bgs/T2F/T2FGMM.h
similarity index 73%
rename from package_bgs/T2F/T2FGMM.h
rename to src/package_bgs/T2F/T2FGMM.h
index 203c350..5c13069 100644
--- a/package_bgs/T2F/T2FGMM.h
+++ b/src/package_bgs/T2F/T2FGMM.h
@@ -1,34 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* T2FGMM.h
-*
-* Purpose: Implementation of the T2 Fuzzy Gaussian Mixture Models (T2GMMs)
-* "Modeling of Dynamic Backgrounds by Type-2 Fuzzy Gaussians Mixture Models"
-* Author: Fida El Baf, Thierry Bouwmans, September 2008
-*
-* This code is based on code by Z. Zivkovic's written for his enhanced GMM
-* background subtraction algorithm:
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-******************************************************************************/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "../dp/Bgs.h"
 #include "../dp/GrimsonGMM.h"
 
@@ -129,3 +103,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/package_bgs/T2F/T2FMRF.cpp b/src/package_bgs/T2F/T2FMRF.cpp
similarity index 90%
rename from package_bgs/T2F/T2FMRF.cpp
rename to src/package_bgs/T2F/T2FMRF.cpp
index e722d02..417aa27 100644
--- a/package_bgs/T2F/T2FMRF.cpp
+++ b/src/package_bgs/T2F/T2FMRF.cpp
@@ -1,35 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* T2FMRF.cpp
-*
-* Purpose: Implementation of the T2 Fuzzy Gaussian Mixture Models (T2GMMs)
-* "Modeling of Dynamic Backgrounds by Type-2 Fuzzy Gaussians Mixture Models"
-* Author: Fida El Baf, Thierry Bouwmans, September 2008
-*
-* This code is based on code by Z. Zivkovic's written for his enhanced GMM
-* background subtraction algorithm:
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-******************************************************************************/
-
 #include "T2FMRF.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 int compareT2FMRF(const void* _gmm1, const void* _gmm2)
@@ -429,3 +401,5 @@ void T2FMRF::Subtract(int frame_num, const RgbImage& data,
     }
   }
 }
+
+#endif
diff --git a/package_bgs/T2F/T2FMRF.h b/src/package_bgs/T2F/T2FMRF.h
similarity index 77%
rename from package_bgs/T2F/T2FMRF.h
rename to src/package_bgs/T2F/T2FMRF.h
index 1015426..a3a3a17 100644
--- a/package_bgs/T2F/T2FMRF.h
+++ b/src/package_bgs/T2F/T2FMRF.h
@@ -1,34 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* T2FMRF.h
-*
-* Purpose: Implementation of the T2 Fuzzy Gaussian Mixture Models (T2GMMs)
-* "Modeling of Dynamic Backgrounds by Type-2 Fuzzy Gaussians Mixture Models"
-* Author: Fida El Baf, Thierry Bouwmans, September 2008
-*
-* This code is based on code by Z. Zivkovic's written for his enhanced GMM
-* background subtraction algorithm:
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-******************************************************************************/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "../dp/Bgs.h"
 #include "../dp/GrimsonGMM.h"
 
@@ -158,3 +132,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/package_bgs/T2FGMM_UM.cpp b/src/package_bgs/T2FGMM_UM.cpp
similarity index 58%
rename from package_bgs/T2FGMM_UM.cpp
rename to src/package_bgs/T2FGMM_UM.cpp
index ad1b40e..b9526f9 100644
--- a/package_bgs/T2FGMM_UM.cpp
+++ b/src/package_bgs/T2FGMM_UM.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "T2FGMM_UM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 T2FGMM_UM::T2FGMM_UM() :
@@ -86,28 +72,31 @@ void T2FGMM_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
 void T2FGMM_UM::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteReal(fs, "km", km);
-  cvWriteReal(fs, "kv", kv);
-  cvWriteInt(fs, "gaussians", gaussians);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "km" << km;
+  fs << "kv" << kv;
+  fs << "gaussians" << gaussians;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void T2FGMM_UM::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 9.0);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.01);
-  km = cvReadRealByName(fs, nullptr, "km", 1.5);
-  kv = cvReadRealByName(fs, nullptr, "kv", 0.6);
-  gaussians = cvReadIntByName(fs, nullptr, "gaussians", 3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["km"] >> km;
+  fs["kv"] >> kv;
+  fs["gaussians"] >> gaussians;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/T2FGMM_UM.h b/src/package_bgs/T2FGMM_UM.h
similarity index 52%
rename from package_bgs/T2FGMM_UM.h
rename to src/package_bgs/T2FGMM_UM.h
index e8b4166..8cf40bb 100644
--- a/package_bgs/T2FGMM_UM.h
+++ b/src/package_bgs/T2FGMM_UM.h
@@ -1,22 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "T2F/T2FGMM.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +13,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class T2FGMM_UM : public IBGS
+    class T2FGMM_UM : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -57,3 +45,5 @@ namespace bgslibrary
     static BGS_Register<T2FGMM_UM> register_T2FGMM_UM("T2FGMM_UM");
   }
 }
+
+#endif
diff --git a/package_bgs/T2FGMM_UV.cpp b/src/package_bgs/T2FGMM_UV.cpp
similarity index 58%
rename from package_bgs/T2FGMM_UV.cpp
rename to src/package_bgs/T2FGMM_UV.cpp
index 4e9708f..56e9dad 100644
--- a/package_bgs/T2FGMM_UV.cpp
+++ b/src/package_bgs/T2FGMM_UV.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "T2FGMM_UV.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 T2FGMM_UV::T2FGMM_UV() :
@@ -86,28 +72,31 @@ void T2FGMM_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
 void T2FGMM_UV::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteReal(fs, "km", km);
-  cvWriteReal(fs, "kv", kv);
-  cvWriteInt(fs, "gaussians", gaussians);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "km" << km;
+  fs << "kv" << kv;
+  fs << "gaussians" << gaussians;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void T2FGMM_UV::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 9.0);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.01);
-  km = cvReadRealByName(fs, nullptr, "km", 1.5);
-  kv = cvReadRealByName(fs, nullptr, "kv", 0.6);
-  gaussians = cvReadIntByName(fs, nullptr, "gaussians", 3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["km"] >> km;
+  fs["kv"] >> kv;
+  fs["gaussians"] >> gaussians;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/T2FGMM_UV.h b/src/package_bgs/T2FGMM_UV.h
similarity index 52%
rename from package_bgs/T2FGMM_UV.h
rename to src/package_bgs/T2FGMM_UV.h
index a8dab79..5dcc83a 100644
--- a/package_bgs/T2FGMM_UV.h
+++ b/src/package_bgs/T2FGMM_UV.h
@@ -1,22 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "T2F/T2FGMM.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +13,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class T2FGMM_UV : public IBGS
+    class T2FGMM_UV : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -57,3 +45,5 @@ namespace bgslibrary
     static BGS_Register<T2FGMM_UV> register_T2FGMM_UV("T2FGMM_UV");
   }
 }
+
+#endif
diff --git a/package_bgs/T2FMRF_UM.cpp b/src/package_bgs/T2FMRF_UM.cpp
similarity index 67%
rename from package_bgs/T2FMRF_UM.cpp
rename to src/package_bgs/T2FMRF_UM.cpp
index e0e6dae..a81cf37 100644
--- a/package_bgs/T2FMRF_UM.cpp
+++ b/src/package_bgs/T2FMRF_UM.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "T2FMRF_UM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 T2FMRF_UM::T2FMRF_UM() :
@@ -114,28 +100,31 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
 void T2FMRF_UM::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteReal(fs, "km", km);
-  cvWriteReal(fs, "kv", kv);
-  cvWriteInt(fs, "gaussians", gaussians);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "km" << km;
+  fs << "kv" << kv;
+  fs << "gaussians" << gaussians;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void T2FMRF_UM::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 9.0);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.01);
-  km = cvReadRealByName(fs, nullptr, "km", 2);
-  kv = cvReadRealByName(fs, nullptr, "kv", 0.9);
-  gaussians = cvReadIntByName(fs, nullptr, "gaussians", 3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["km"] >> km;
+  fs["kv"] >> kv;
+  fs["gaussians"] >> gaussians;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/T2FMRF_UM.h b/src/package_bgs/T2FMRF_UM.h
similarity index 55%
rename from package_bgs/T2FMRF_UM.h
rename to src/package_bgs/T2FMRF_UM.h
index 8d324f4..bab22b0 100644
--- a/package_bgs/T2FMRF_UM.h
+++ b/src/package_bgs/T2FMRF_UM.h
@@ -1,22 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "T2F/MRF.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +13,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class T2FMRF_UM : public IBGS
+    class T2FMRF_UM : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -64,3 +52,5 @@ namespace bgslibrary
     static BGS_Register<T2FMRF_UM> register_T2FMRF_UM("T2FMRF_UM");
   }
 }
+
+#endif
diff --git a/package_bgs/T2FMRF_UV.cpp b/src/package_bgs/T2FMRF_UV.cpp
similarity index 67%
rename from package_bgs/T2FMRF_UV.cpp
rename to src/package_bgs/T2FMRF_UV.cpp
index 7f43c02..0d3e637 100644
--- a/package_bgs/T2FMRF_UV.cpp
+++ b/src/package_bgs/T2FMRF_UV.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "T2FMRF_UV.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 T2FMRF_UV::T2FMRF_UV() :
@@ -114,28 +100,31 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
 void T2FMRF_UV::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteReal(fs, "threshold", threshold);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteReal(fs, "km", km);
-  cvWriteReal(fs, "kv", kv);
-  cvWriteInt(fs, "gaussians", gaussians);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "threshold" << threshold;
+  fs << "alpha" << alpha;
+  fs << "km" << km;
+  fs << "kv" << kv;
+  fs << "gaussians" << gaussians;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void T2FMRF_UV::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 9.0);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.01);
-  km = cvReadRealByName(fs, nullptr, "km", 2);
-  kv = cvReadRealByName(fs, nullptr, "kv", 0.9);
-  gaussians = cvReadIntByName(fs, nullptr, "gaussians", 3);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["threshold"] >> threshold;
+  fs["alpha"] >> alpha;
+  fs["km"] >> km;
+  fs["kv"] >> kv;
+  fs["gaussians"] >> gaussians;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/package_bgs/T2FMRF_UV.h b/src/package_bgs/T2FMRF_UV.h
similarity index 55%
rename from package_bgs/T2FMRF_UV.h
rename to src/package_bgs/T2FMRF_UV.h
index 8fd4611..4ffd7c1 100644
--- a/package_bgs/T2FMRF_UV.h
+++ b/src/package_bgs/T2FMRF_UV.h
@@ -1,22 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "T2F/MRF.h"
 
 using namespace Algorithms::BackgroundSubtraction;
@@ -25,7 +13,7 @@ namespace bgslibrary
 {
   namespace algorithms
   {
-    class T2FMRF_UV : public IBGS
+    class T2FMRF_UV : public IBGS, public ILoadSaveConfig
     {
     private:
       long frameNumber;
@@ -64,3 +52,5 @@ namespace bgslibrary
     static BGS_Register<T2FMRF_UV> register_T2FMRF_UV("T2FMRF_UV");
   }
 }
+
+#endif
diff --git a/package_bgs/TwoPoints.cpp b/src/package_bgs/TwoPoints.cpp
similarity index 61%
rename from package_bgs/TwoPoints.cpp
rename to src/package_bgs/TwoPoints.cpp
index aee4684..ba8b1f1 100644
--- a/package_bgs/TwoPoints.cpp
+++ b/src/package_bgs/TwoPoints.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include "TwoPoints.h"
 
 using namespace bgslibrary::algorithms;
@@ -91,22 +74,23 @@ void TwoPoints::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
 void TwoPoints::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "matchingThreshold", matchingThreshold);
-  cvWriteInt(fs, "updateFactor", updateFactor);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "matchingThreshold" << matchingThreshold;
+  fs << "updateFactor" << updateFactor;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void TwoPoints::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  matchingThreshold = cvReadRealByName(fs, nullptr, "matchingThreshold", DEFAULT_MATCH_THRESH);
-  updateFactor = cvReadRealByName(fs, nullptr, "updateFactor", DEFAULT_UPDATE_FACTOR);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", false);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["matchingThreshold"] >> matchingThreshold;
+  fs["updateFactor"] >> updateFactor;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
diff --git a/src/package_bgs/TwoPoints.h b/src/package_bgs/TwoPoints.h
new file mode 100644
index 0000000..133c160
--- /dev/null
+++ b/src/package_bgs/TwoPoints.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+#include "TwoPoints/two_points.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class TwoPoints : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      static const int DEFAULT_MATCH_THRESH = 20;
+      static const int DEFAULT_UPDATE_FACTOR = 16;
+      int matchingThreshold;
+      int updateFactor;
+      twopointsModel_t* model;
+
+    public:
+      TwoPoints();
+      ~TwoPoints();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<TwoPoints> register_TwoPoints("TwoPoints");
+  }
+}
diff --git a/package_bgs/TwoPoints/two_points.cpp b/src/package_bgs/TwoPoints/two_points.cpp
similarity index 94%
rename from package_bgs/TwoPoints/two_points.cpp
rename to src/package_bgs/TwoPoints/two_points.cpp
index d8ee86b..1c0c121 100644
--- a/package_bgs/TwoPoints/two_points.cpp
+++ b/src/package_bgs/TwoPoints/two_points.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include <assert.h>
 
 #include "two_points.h"
diff --git a/package_bgs/TwoPoints/two_points.h b/src/package_bgs/TwoPoints/two_points.h
similarity index 57%
rename from package_bgs/TwoPoints/two_points.h
rename to src/package_bgs/TwoPoints/two_points.h
index a64152a..ecf8b6f 100644
--- a/package_bgs/TwoPoints/two_points.h
+++ b/src/package_bgs/TwoPoints/two_points.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <stdlib.h>
diff --git a/package_bgs/ViBe.cpp b/src/package_bgs/ViBe.cpp
similarity index 51%
rename from package_bgs/ViBe.cpp
rename to src/package_bgs/ViBe.cpp
index 0d3125f..c72f818 100644
--- a/package_bgs/ViBe.cpp
+++ b/src/package_bgs/ViBe.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include "ViBe.h"
 
 using namespace bgslibrary::algorithms;
@@ -73,26 +56,27 @@ void ViBe::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_b
 
 void ViBe::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  //cvWriteInt(fs, "numberOfSamples", numberOfSamples);
-  cvWriteInt(fs, "matchingThreshold", matchingThreshold);
-  cvWriteInt(fs, "matchingNumber", matchingNumber);
-  cvWriteInt(fs, "updateFactor", updateFactor);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  //fs << "numberOfSamples" << numberOfSamples;
+  fs << "matchingThreshold" << matchingThreshold;
+  fs << "matchingNumber" << matchingNumber;
+  fs << "updateFactor" << updateFactor;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void ViBe::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  //numberOfSamples = cvReadIntByName(fs, nullptr, "numberOfSamples", DEFAULT_NUM_SAMPLES);
-  matchingThreshold = cvReadRealByName(fs, nullptr, "matchingThreshold", DEFAULT_MATCH_THRESH);
-  matchingNumber = cvReadRealByName(fs, nullptr, "matchingNumber", DEFAULT_MATCH_NUM);
-  updateFactor = cvReadRealByName(fs, nullptr, "updateFactor", DEFAULT_UPDATE_FACTOR);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", false);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  //fs["numberOfSamples"] >> numberOfSamples;
+  fs["matchingThreshold"] >> matchingThreshold;
+  fs["matchingNumber"] >> matchingNumber;
+  fs["updateFactor"] >> updateFactor;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
diff --git a/package_bgs/ViBe.h b/src/package_bgs/ViBe.h
similarity index 53%
rename from package_bgs/ViBe.h
rename to src/package_bgs/ViBe.h
index dbe0e8f..0b38852 100644
--- a/package_bgs/ViBe.h
+++ b/src/package_bgs/ViBe.h
@@ -1,29 +1,14 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 #include "ViBe/vibe-background-sequential.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class ViBe : public IBGS
+    class ViBe : public IBGS, public ILoadSaveConfig
     {
     private:
       static const int DEFAULT_NUM_SAMPLES = 20;
diff --git a/package_bgs/ViBe/LICENSE b/src/package_bgs/ViBe/LICENSE
similarity index 100%
rename from package_bgs/ViBe/LICENSE
rename to src/package_bgs/ViBe/LICENSE
diff --git a/package_bgs/ViBe/vibe-background-sequential.cpp b/src/package_bgs/ViBe/vibe-background-sequential.cpp
similarity index 97%
rename from package_bgs/ViBe/vibe-background-sequential.cpp
rename to src/package_bgs/ViBe/vibe-background-sequential.cpp
index 5bf33a6..78c8fe3 100644
--- a/package_bgs/ViBe/vibe-background-sequential.cpp
+++ b/src/package_bgs/ViBe/vibe-background-sequential.cpp
@@ -1,25 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/**
-@file vibe-background-sequential.c
-@brief Implementation of vibe-background-sequential.h
-@author Marc Van Droogenbroeck
-@date May 2014
-*/
 #include <assert.h>
 #include <time.h>
 
diff --git a/package_bgs/ViBe/vibe-background-sequential.h b/src/package_bgs/ViBe/vibe-background-sequential.h
similarity index 81%
rename from package_bgs/ViBe/vibe-background-sequential.h
rename to src/package_bgs/ViBe/vibe-background-sequential.h
index 068c7d1..c119be4 100644
--- a/package_bgs/ViBe/vibe-background-sequential.h
+++ b/src/package_bgs/ViBe/vibe-background-sequential.h
@@ -1,53 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/**
-  @file vibe-background-sequential.h
-  @brief Interface for the ViBe library
-  @author Marc Van Droogenbroeck
-  @date July 2014
-  @details
-
-  Full documentation is available online at:
-     http://www.ulg.ac.be/telecom/research/vibe/doc
-
-  All technical details are available in the following paper:
-<em>O. Barnich and M. Van Droogenbroeck. ViBe: A universal background subtraction algorithm for video sequences. IEEE Transactions on Image Processing, 20(6):1709-1724, June 2011.</em>
-
-\verbatim
-BiBTeX information
-
-  @article{Barnich2011ViBe,
-  title = {{ViBe}: A universal background subtraction algorithm for video sequences},
-  author = {O. Barnich and M. {Van Droogenbroeck}},
-  journal = {IEEE Transactions on Image Processing},
-  volume = {20},
-  number = {6},
-  pages = {1709-1724},
-  month = {June},
-  year = {2011},
-  keywords = {ViBe, Background, Background subtraction, Segmentation, Motion, Motion detection},
-  pdf = {http://orbi.ulg.ac.be/bitstream/2268/145853/1/Barnich2011ViBe.pdf},
-  doi = {10.1109/TIP.2010.2101613},
-  url = {http://hdl.handle.net/2268/145853}
-  }
-\endverbatim
-See
-\cite Barnich2011ViBe
-*/
 #pragma once
 
 #include <stdlib.h>
diff --git a/package_bgs/VuMeter.cpp b/src/package_bgs/VuMeter.cpp
similarity index 53%
rename from package_bgs/VuMeter.cpp
rename to src/package_bgs/VuMeter.cpp
index 99baee9..d080b39 100644
--- a/package_bgs/VuMeter.cpp
+++ b/src/package_bgs/VuMeter.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "VuMeter.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace bgslibrary::algorithms;
 
 VuMeter::VuMeter() :
@@ -84,30 +70,29 @@ void VuMeter::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &im
 
 void VuMeter::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "enableFilter", enableFilter);
-
-  cvWriteInt(fs, "binSize", binSize);
-  cvWriteReal(fs, "alpha", alpha);
-  cvWriteReal(fs, "threshold", threshold);
-
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "enableFilter" << enableFilter;
+  fs << "binSize" << binSize;
+  fs << "alpha" << alpha;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void VuMeter::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  enableFilter = cvReadIntByName(fs, nullptr, "enableFilter", true);
-
-  binSize = cvReadIntByName(fs, nullptr, "binSize", 8);
-  alpha = cvReadRealByName(fs, nullptr, "alpha", 0.995);
-  threshold = cvReadRealByName(fs, nullptr, "threshold", 0.03);
-
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["enableFilter"] >> enableFilter;
+  fs["binSize"] >> binSize;
+  fs["alpha"] >> alpha;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
+
+#endif
diff --git a/src/package_bgs/VuMeter.h b/src/package_bgs/VuMeter.h
new file mode 100644
index 0000000..6cb67ff
--- /dev/null
+++ b/src/package_bgs/VuMeter.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+#include "VuMeter/TBackgroundVuMeter.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class VuMeter : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      TBackgroundVuMeter bgs;
+
+      IplImage *frame;
+      IplImage *gray;
+      IplImage *background;
+      IplImage *mask;
+
+      bool enableFilter;
+      int binSize;
+      double alpha;
+      double threshold;
+
+    public:
+      VuMeter();
+      ~VuMeter();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<VuMeter> register_VuMeter("VuMeter");
+  }
+}
+
+#endif
diff --git a/package_bgs/VuMeter/TBackground.cpp b/src/package_bgs/VuMeter/TBackground.cpp
similarity index 80%
rename from package_bgs/VuMeter/TBackground.cpp
rename to src/package_bgs/VuMeter/TBackground.cpp
index 76d18c7..e961ee8 100644
--- a/package_bgs/VuMeter/TBackground.cpp
+++ b/src/package_bgs/VuMeter/TBackground.cpp
@@ -1,30 +1,5 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  TBackground.cpp
-*  Framework
-*
-*  Created by Robinault Lionel on 07/12/11.
-*
-*/
-
 #include "TBackground.h"
 
-
 TBackground::TBackground(void)
 {
   std::cout << "TBackground()" << std::endl;
diff --git a/package_bgs/VuMeter/TBackground.h b/src/package_bgs/VuMeter/TBackground.h
similarity index 54%
rename from package_bgs/VuMeter/TBackground.h
rename to src/package_bgs/VuMeter/TBackground.h
index 61925a2..b2f4ebd 100644
--- a/package_bgs/VuMeter/TBackground.h
+++ b/src/package_bgs/VuMeter/TBackground.h
@@ -1,26 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  TBackground.h
-*  Framework
-*
-*  Created by Robinault Lionel on 07/12/11.
-*
-*/
 #pragma once
 
 #include <iostream>
diff --git a/package_bgs/VuMeter/TBackgroundVuMeter.cpp b/src/package_bgs/VuMeter/TBackgroundVuMeter.cpp
similarity index 90%
rename from package_bgs/VuMeter/TBackgroundVuMeter.cpp
rename to src/package_bgs/VuMeter/TBackgroundVuMeter.cpp
index c4fd7a7..b0a0d4c 100644
--- a/package_bgs/VuMeter/TBackgroundVuMeter.cpp
+++ b/src/package_bgs/VuMeter/TBackgroundVuMeter.cpp
@@ -1,26 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  TBackgroundVuMeter.cpp
-*  Framework
-*
-*  Created by Robinault Lionel on 07/12/11.
-*
-*/
 #include "TBackgroundVuMeter.h"
 
 #define PROCESS_PAR_COUNT 3
diff --git a/package_bgs/VuMeter/TBackgroundVuMeter.h b/src/package_bgs/VuMeter/TBackgroundVuMeter.h
similarity index 65%
rename from package_bgs/VuMeter/TBackgroundVuMeter.h
rename to src/package_bgs/VuMeter/TBackgroundVuMeter.h
index 36fe0d0..1d63aec 100644
--- a/package_bgs/VuMeter/TBackgroundVuMeter.h
+++ b/src/package_bgs/VuMeter/TBackgroundVuMeter.h
@@ -1,26 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
-*  TBackgroundVuMeter.h
-*  Framework
-*
-*  Created by Robinault Lionel on 07/12/11.
-*
-*/
 #pragma once
 
 #include "TBackground.h"
diff --git a/package_bgs/WeightedMovingMean.cpp b/src/package_bgs/WeightedMovingMean.cpp
similarity index 62%
rename from package_bgs/WeightedMovingMean.cpp
rename to src/package_bgs/WeightedMovingMean.cpp
index 3a427fc..fcbe38d 100644
--- a/package_bgs/WeightedMovingMean.cpp
+++ b/src/package_bgs/WeightedMovingMean.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "WeightedMovingMean.h"
 
 using namespace bgslibrary::algorithms;
@@ -92,24 +76,25 @@ void WeightedMovingMean::process(const cv::Mat &img_input, cv::Mat &img_output,
 
 void WeightedMovingMean::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "enableWeight", enableWeight);
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "enableWeight" << enableWeight;
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void WeightedMovingMean::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  enableWeight = cvReadIntByName(fs, nullptr, "enableWeight", true);
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["enableWeight"] >> enableWeight;
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
diff --git a/src/package_bgs/WeightedMovingMean.h b/src/package_bgs/WeightedMovingMean.h
new file mode 100644
index 0000000..90309dc
--- /dev/null
+++ b/src/package_bgs/WeightedMovingMean.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "IBGS.h"
+#include "ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class WeightedMovingMean : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      cv::Mat img_input_prev_1;
+      cv::Mat img_input_prev_2;
+      bool enableWeight;
+      bool enableThreshold;
+      int threshold;
+
+    public:
+      WeightedMovingMean();
+      ~WeightedMovingMean();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<WeightedMovingMean> register_WeightedMovingMean("WeightedMovingMean");
+  }
+}
diff --git a/package_bgs/WeightedMovingVariance.cpp b/src/package_bgs/WeightedMovingVariance.cpp
similarity index 73%
rename from package_bgs/WeightedMovingVariance.cpp
rename to src/package_bgs/WeightedMovingVariance.cpp
index 2855a92..a3cbcb3 100644
--- a/package_bgs/WeightedMovingVariance.cpp
+++ b/src/package_bgs/WeightedMovingVariance.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "WeightedMovingVariance.h"
 
 using namespace bgslibrary::algorithms;
@@ -129,24 +113,25 @@ cv::Mat WeightedMovingVariance::computeWeightedVariance(const cv::Mat &img_input
 
 void WeightedMovingVariance::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
-
-  cvWriteInt(fs, "enableWeight", enableWeight);
-  cvWriteInt(fs, "enableThreshold", enableThreshold);
-  cvWriteInt(fs, "threshold", threshold);
-  cvWriteInt(fs, "showOutput", showOutput);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
+  
+  fs << "enableWeight" << enableWeight;
+  fs << "enableThreshold" << enableThreshold;
+  fs << "threshold" << threshold;
+  fs << "showOutput" << showOutput;
+  
+  fs.release();
 }
 
 void WeightedMovingVariance::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
-
-  enableWeight = cvReadIntByName(fs, nullptr, "enableWeight", true);
-  enableThreshold = cvReadIntByName(fs, nullptr, "enableThreshold", true);
-  threshold = cvReadIntByName(fs, nullptr, "threshold", 15);
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", true);
-
-  cvReleaseFileStorage(&fs);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
+  
+  fs["enableWeight"] >> enableWeight;
+  fs["enableThreshold"] >> enableThreshold;
+  fs["threshold"] >> threshold;
+  fs["showOutput"] >> showOutput;
+  
+  fs.release();
 }
diff --git a/package_bgs/WeightedMovingVariance.h b/src/package_bgs/WeightedMovingVariance.h
similarity index 50%
rename from package_bgs/WeightedMovingVariance.h
rename to src/package_bgs/WeightedMovingVariance.h
index 791fd77..f7a0aac 100644
--- a/package_bgs/WeightedMovingVariance.h
+++ b/src/package_bgs/WeightedMovingVariance.h
@@ -1,28 +1,13 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 
 namespace bgslibrary
 {
   namespace algorithms
   {
-    class WeightedMovingVariance : public IBGS
+    class WeightedMovingVariance : public IBGS, public ILoadSaveConfig
     {
     private:
       cv::Mat img_input_prev_1;
diff --git a/package_bgs/_template_/Amber.cpp b/src/package_bgs/_template_/Amber.cpp
similarity index 68%
rename from package_bgs/_template_/Amber.cpp
rename to src/package_bgs/_template_/Amber.cpp
index c843283..10ce09c 100644
--- a/package_bgs/_template_/Amber.cpp
+++ b/src/package_bgs/_template_/Amber.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include "Amber.h"
 
 using namespace bgslibrary::algorithms;
@@ -95,18 +78,19 @@ void Amber::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_
 
 void Amber::saveConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_WRITE);
+  cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
 
-  cvWriteInt(fs, "showOutput", showOutput);
+  fs << "showOutput" << showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
 
 void Amber::loadConfig()
 {
-  CvFileStorage* fs = cvOpenFileStorage(config_xml.c_str(), nullptr, CV_STORAGE_READ);
+  cv::FileStorage fs;
+  fs.open(config_xml, cv::FileStorage::READ);
 
-  showOutput = cvReadIntByName(fs, nullptr, "showOutput", false);
+  fs["showOutput"] >> showOutput;
 
-  cvReleaseFileStorage(&fs);
+  fs.release();
 }
diff --git a/src/package_bgs/_template_/Amber.h b/src/package_bgs/_template_/Amber.h
new file mode 100644
index 0000000..b0af865
--- /dev/null
+++ b/src/package_bgs/_template_/Amber.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <math.h>
+#include <sys/types.h>
+
+#include "../IBGS.h"
+#include "../ILoadSaveConfig.h"
+#include "amber/amber.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class Amber : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      amberModel* model;
+
+    public:
+      Amber();
+      ~Amber();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig();
+      void loadConfig();
+    };
+
+    static BGS_Register<Amber> register_Amber("Amber");
+  }
+}
diff --git a/package_bgs/_template_/MyBGS.cpp b/src/package_bgs/_template_/MyBGS.cpp
similarity index 50%
rename from package_bgs/_template_/MyBGS.cpp
rename to src/package_bgs/_template_/MyBGS.cpp
index 10d5588..5a7adec 100644
--- a/package_bgs/_template_/MyBGS.cpp
+++ b/src/package_bgs/_template_/MyBGS.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "MyBGS.h"
 
 using namespace bgslibrary::algorithms;
diff --git a/src/package_bgs/_template_/MyBGS.h b/src/package_bgs/_template_/MyBGS.h
new file mode 100644
index 0000000..5fdf726
--- /dev/null
+++ b/src/package_bgs/_template_/MyBGS.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <opencv2/opencv.hpp>
+
+#include "../IBGS.h"
+#include "../ILoadSaveConfig.h"
+
+namespace bgslibrary
+{
+  namespace algorithms
+  {
+    class MyBGS : public IBGS, public ILoadSaveConfig
+    {
+    private:
+      cv::Mat img_previous;
+
+    public:
+      MyBGS();
+      ~MyBGS();
+
+      void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
+
+    private:
+      void saveConfig() {}
+      void loadConfig() {}
+    };
+
+    static BGS_Register<MyBGS> register_MyBGS("MyBGS");
+  }
+}
diff --git a/package_bgs/_template_/amber/amber.cpp b/src/package_bgs/_template_/amber/amber.cpp
similarity index 64%
rename from package_bgs/_template_/amber/amber.cpp
rename to src/package_bgs/_template_/amber/amber.cpp
index b48b980..956c041 100644
--- a/package_bgs/_template_/amber/amber.cpp
+++ b/src/package_bgs/_template_/amber/amber.cpp
@@ -1,20 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 #include "amber.h"
 
 #define COLOR_BACKGROUND   0
@@ -73,8 +56,3 @@ int32_t libamberModelFree(amberModel* model)
 
   return(0);
 }
-
-/* For compilation with g++ */
-//#ifdef __cplusplus
-//}
-//#endif
diff --git a/package_bgs/_template_/amber/amber.h b/src/package_bgs/_template_/amber/amber.h
similarity index 61%
rename from package_bgs/_template_/amber/amber.h
rename to src/package_bgs/_template_/amber/amber.h
index 0206179..1ebda54 100644
--- a/package_bgs/_template_/amber/amber.h
+++ b/src/package_bgs/_template_/amber/amber.h
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <stdlib.h>
diff --git a/src/package_bgs/bgslibrary.cpp b/src/package_bgs/bgslibrary.cpp
new file mode 100644
index 0000000..cbc2e7d
--- /dev/null
+++ b/src/package_bgs/bgslibrary.cpp
@@ -0,0 +1 @@
+#include "bgslibrary.h"
diff --git a/package_bgs/bgslibrary.h b/src/package_bgs/bgslibrary.h
similarity index 68%
rename from package_bgs/bgslibrary.h
rename to src/package_bgs/bgslibrary.h
index f97f162..93d00ec 100644
--- a/package_bgs/bgslibrary.h
+++ b/src/package_bgs/bgslibrary.h
@@ -1,22 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include "IBGS.h"
+#include "ILoadSaveConfig.h"
 
 #include "FrameDifference.h"
 #include "StaticFrameDifference.h"
diff --git a/package_bgs/dp/AdaptiveMedianBGS.cpp b/src/package_bgs/dp/AdaptiveMedianBGS.cpp
similarity index 73%
rename from package_bgs/dp/AdaptiveMedianBGS.cpp
rename to src/package_bgs/dp/AdaptiveMedianBGS.cpp
index da1add9..231a6b5 100644
--- a/package_bgs/dp/AdaptiveMedianBGS.cpp
+++ b/src/package_bgs/dp/AdaptiveMedianBGS.cpp
@@ -1,38 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* AdaptiveMedianBGS.cpp
-*
-* Purpose: Implementation of the simple adaptive median background
-*		  		 subtraction algorithm described in:
-*	  			 "Segmentation and tracking of piglets in images"
-* 						by McFarlane and Schofield
-*
-* Author: Donovan Parks, September 2007
-*
-******************************************************************************/
-
-#include <iostream>
-#include <stdlib.h>
-#include <cmath>
-
 #include "AdaptiveMedianBGS.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 void AdaptiveMedianBGS::Initalize(const BgsParams& param)
@@ -138,3 +107,4 @@ void AdaptiveMedianBGS::Subtract(int frame_num, const RgbImage& data,
   }
 }
 
+#endif
diff --git a/src/package_bgs/dp/AdaptiveMedianBGS.h b/src/package_bgs/dp/AdaptiveMedianBGS.h
new file mode 100644
index 0000000..55a6819
--- /dev/null
+++ b/src/package_bgs/dp/AdaptiveMedianBGS.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include <iostream>
+#include <stdlib.h>
+#include <cmath>
+
+#include "Bgs.h"
+
+namespace Algorithms
+{
+  namespace BackgroundSubtraction
+  {
+    // --- Parameters used by the Adaptive Median BGS algorithm ---
+    class AdaptiveMedianParams : public BgsParams
+    {
+    public:
+      unsigned char &LowThreshold() { return m_low_threshold; }
+      unsigned char &HighThreshold() { return m_high_threshold; }
+
+      int &SamplingRate() { return m_samplingRate; }
+      int &LearningFrames() { return m_learning_frames; }
+
+    private:
+      unsigned char m_low_threshold;
+      unsigned char m_high_threshold;
+
+      int m_samplingRate;
+      int m_learning_frames;
+    };
+
+
+    // --- Adaptive Median BGS algorithm ---
+    class AdaptiveMedianBGS : public Bgs
+    {
+    public:
+      virtual ~AdaptiveMedianBGS() {}
+
+      void Initalize(const BgsParams& param);
+
+      void InitModel(const RgbImage& data);
+      void Subtract(int frame_num, const RgbImage& data,
+        BwImage& low_threshold_mask, BwImage& high_threshold_mask);
+      void Update(int frame_num, const RgbImage& data, const BwImage& update_mask);
+
+      RgbImage* Background();
+
+    private:
+      void SubtractPixel(int r, int c, const RgbPixel& pixel,
+        unsigned char& low_threshold, unsigned char& high_threshold);
+
+      AdaptiveMedianParams m_params;
+
+      RgbImage m_median;
+    };
+  }
+}
+
+#endif
diff --git a/src/package_bgs/dp/Bgs.h b/src/package_bgs/dp/Bgs.h
new file mode 100644
index 0000000..b083d5f
--- /dev/null
+++ b/src/package_bgs/dp/Bgs.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
+#include "Image.h"
+#include "BgsParams.h"
+
+namespace Algorithms
+{
+  namespace BackgroundSubtraction
+  {
+    class Bgs
+    {
+    public:
+      static const int BACKGROUND = 0;
+      static const int FOREGROUND = 255;
+
+      virtual ~Bgs() {}
+
+      // Initialize any data required by the BGS algorithm. Should be called once before calling
+      // any of the following functions.
+      virtual void Initalize(const BgsParams& param) = 0;
+
+      // Initialize the background model. Typically, the background model is initialized using the first
+      // frame of the incoming video stream, but alternatives are possible.
+      virtual void InitModel(const RgbImage& data) = 0;
+
+      // Subtract the current frame from the background model and produce a binary foreground mask using
+      // both a low and high threshold value.
+      virtual void Subtract(int frame_num, const RgbImage& data,
+                            BwImage& low_threshold_mask, BwImage& high_threshold_mask) = 0;
+
+      // Update the background model. Only pixels set to background in update_mask are updated.
+      virtual void Update(int frame_num, const RgbImage& data,  const BwImage& update_mask) = 0;
+
+      // Return the current background model.
+      virtual RgbImage *Background() = 0;
+    };
+  }
+}
+
+#endif
diff --git a/src/package_bgs/dp/BgsParams.h b/src/package_bgs/dp/BgsParams.h
new file mode 100644
index 0000000..79539b7
--- /dev/null
+++ b/src/package_bgs/dp/BgsParams.h
@@ -0,0 +1,29 @@
+#pragma once
+
+namespace Algorithms
+{
+  namespace BackgroundSubtraction
+  {
+    class BgsParams
+    {
+    public:
+      virtual ~BgsParams() {}
+
+      virtual void SetFrameSize(unsigned int width, unsigned int height)
+      {
+        m_width = width;
+        m_height = height;
+        m_size = width*height;
+      }
+
+      unsigned int &Width() { return m_width; }
+      unsigned int &Height() { return m_height; }
+      unsigned int &Size() { return m_size; }
+
+    protected:
+      unsigned int m_width;
+      unsigned int m_height;
+      unsigned int m_size;
+    };
+  }
+}
diff --git a/package_bgs/dp/Eigenbackground.cpp b/src/package_bgs/dp/Eigenbackground.cpp
similarity index 80%
rename from package_bgs/dp/Eigenbackground.cpp
rename to src/package_bgs/dp/Eigenbackground.cpp
index dceb4cd..c207fbb 100644
--- a/package_bgs/dp/Eigenbackground.cpp
+++ b/src/package_bgs/dp/Eigenbackground.cpp
@@ -1,35 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Eigenbackground.cpp
-*
-* Purpose: Implementation of the Eigenbackground background subtraction
-*					 algorithm developed by Oliver et al.
-*
-* Author: Donovan Parks, September 2007
-*
-* "A Bayesian Computer Vision System for Modeling Human Interactions"
-*   Nuria Oliver, Barbara Rosario, Alex P. Pentland 2000
-*
-******************************************************************************/
-
 #include "Eigenbackground.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 Eigenbackground::Eigenbackground()
@@ -188,3 +160,5 @@ void Eigenbackground::UpdateHistory(int frame_num, const RgbImage& new_frame)
     cvCopy(new_frame.Ptr(), &src_row);
   }
 }
+
+#endif
diff --git a/package_bgs/dp/Eigenbackground.h b/src/package_bgs/dp/Eigenbackground.h
similarity index 51%
rename from package_bgs/dp/Eigenbackground.h
rename to src/package_bgs/dp/Eigenbackground.h
index 10ed189..4808493 100644
--- a/package_bgs/dp/Eigenbackground.h
+++ b/src/package_bgs/dp/Eigenbackground.h
@@ -1,44 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Eigenbackground.hpp
-*
-* Purpose: Implementation of the Eigenbackground background subtraction
-*					 algorithm developed by Oliver et al.
-*
-* Author: Donovan Parks, September 2007
-*
-* "A Bayesian Computer Vision System for Modeling Human Interactions"
-*   Nuria Oliver, Barbara Rosario, Alex P. Pentland 2000
-
-Example:
-Algorithms::BackgroundSubtraction::EigenbackgroundParams params;
-params.SetFrameSize(width, height);
-params.LowThreshold() = 15*15;
-params.HighThreshold() = 2*params.LowThreshold();	// Note: high threshold is used by post-processing
-params.HistorySize() = 100;
-params.EmbeddedDim() = 20;
-
-Algorithms::BackgroundSubtraction::Eigenbackground bgs;
-bgs.Initalize(params);
-******************************************************************************/
 #pragma once
 
+#include "opencv2/core/version.hpp"
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 #include "Bgs.h"
 
 namespace Algorithms
@@ -95,3 +59,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/src/package_bgs/dp/Error.cpp b/src/package_bgs/dp/Error.cpp
new file mode 100644
index 0000000..0ccb180
--- /dev/null
+++ b/src/package_bgs/dp/Error.cpp
@@ -0,0 +1,31 @@
+#include <iostream> 
+#include <fstream>
+
+#include "Error.h"
+
+using namespace std;
+
+ofstream traceFile;
+
+bool Error(const char* msg, const char* code, int data)
+{
+  cerr << code << ": " << msg << endl;
+
+  return false;
+}
+
+bool TraceInit(const char* filename)
+{
+  traceFile.open(filename);
+  return traceFile.is_open();
+}
+
+void Trace(const char* msg)
+{
+  traceFile << msg << endl;
+}
+
+void TraceClose()
+{
+  traceFile.close();
+}
diff --git a/src/package_bgs/dp/Error.h b/src/package_bgs/dp/Error.h
new file mode 100644
index 0000000..a499e00
--- /dev/null
+++ b/src/package_bgs/dp/Error.h
@@ -0,0 +1,6 @@
+#pragma once
+
+bool Error(const char* msg, const char* code, int data);
+bool TraceInit(const char* filename);
+void Trace(const char* msg);
+void TraceClose();
diff --git a/package_bgs/dp/GrimsonGMM.cpp b/src/package_bgs/dp/GrimsonGMM.cpp
similarity index 82%
rename from package_bgs/dp/GrimsonGMM.cpp
rename to src/package_bgs/dp/GrimsonGMM.cpp
index 4cf6f35..b60e0f6 100644
--- a/package_bgs/dp/GrimsonGMM.cpp
+++ b/src/package_bgs/dp/GrimsonGMM.cpp
@@ -1,48 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* GrimsonGMM.cpp
-*
-* Purpose: Implementation of the Gaussian mixture model (GMM) background
-*		  		 subtraction described in:
-*	  			 "Adaptive background mixture models for real-time tracking"
-* 						by Chris Stauffer and W.E.L Grimson
-*
-* Author: Donovan Parks, September 2007
-*
-* This code is based on code by Z. Zivkovic's written for his enhanced GMM
-* background subtraction algorithm:
-*
-*	"Improved adaptive Gausian mixture model for background subtraction"
-*		Z.Zivkovic
-*		International Conference Pattern Recognition, UK, August, 2004
-*
-*
-* "Efficient Adaptive Density Estimapion per Image Pixel for the
-*			Task of Background Subtraction"
-*		Z.Zivkovic, F. van der Heijden
-*		Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-******************************************************************************/
-
 #include "GrimsonGMM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 int compareGMM(const void* _gmm1, const void* _gmm2)
@@ -329,3 +288,4 @@ void GrimsonGMM::Subtract(int frame_num, const RgbImage& data,
   }
 }
 
+#endif
diff --git a/package_bgs/dp/GrimsonGMM.h b/src/package_bgs/dp/GrimsonGMM.h
similarity index 61%
rename from package_bgs/dp/GrimsonGMM.h
rename to src/package_bgs/dp/GrimsonGMM.h
index 2c0f772..d07e4da 100644
--- a/package_bgs/dp/GrimsonGMM.h
+++ b/src/package_bgs/dp/GrimsonGMM.h
@@ -1,60 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* GrimsonGMM.cpp
-*
-* Purpose: Implementation of the Gaussian mixture model (GMM) background
-*		  		 subtraction described in:
-*	  			 "Adaptive background mixture models for real-time tracking"
-* 						by Chris Stauffer and W.E.L Grimson
-*
-* Author: Donovan Parks, September 2007
-*
-* This code is based on code by Z. Zivkovic's written for his enhanced GMM
-* background subtraction algorithm:
-*
-*	"Improved adaptive Gausian mixture model for background subtraction"
-*		Z.Zivkovic
-*		International Conference Pattern Recognition, UK, August, 2004
-*
-*
-* "Efficient Adaptive Density Estimapion per Image Pixel for the
-*			Task of Background Subtraction"
-*		Z.Zivkovic, F. van der Heijden
-*		Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-
-Example:
-    Algorithms::BackgroundSubtraction::GrimsonParams params;
-    params.SetFrameSize(width, height);
-    params.LowThreshold() = 3.0f*3.0f;
-    params.HighThreshold() = 2*params.LowThreshold();	// Note: high threshold is used by post-processing
-    params.Alpha() = 0.001f;
-    params.MaxModes() = 3;
-
-    Algorithms::BackgroundSubtraction::GrimsonGMM bgs;
-    bgs.Initalize(params);
-******************************************************************************/
 #pragma once
 
 #include "Bgs.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 namespace Algorithms
 {
   namespace BackgroundSubtraction
@@ -144,3 +93,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/package_bgs/dp/Image.cpp b/src/package_bgs/dp/Image.cpp
similarity index 50%
rename from package_bgs/dp/Image.cpp
rename to src/package_bgs/dp/Image.cpp
index 92119c2..d54587e 100644
--- a/package_bgs/dp/Image.cpp
+++ b/src/package_bgs/dp/Image.cpp
@@ -1,34 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Image.hpp
-*
-* Purpose:  C++ wrapper for OpenCV IplImage which supports simple and
-*						efficient access to the image data
-*
-* Author: Donovan Parks, September 2007
-*
-* Based on code from:
-*  http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.hpptml
-******************************************************************************/
-
 #include "Image.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 ImageBase::~ImageBase()
 {
   if (imgp != NULL && m_bReleaseMemory)
@@ -74,3 +47,5 @@ void DensityFilter(BwImage& image, BwImage& filtered, int minDensity, unsigned c
     }
   }
 }
+
+#endif
diff --git a/package_bgs/dp/Image.h b/src/package_bgs/dp/Image.h
similarity index 85%
rename from package_bgs/dp/Image.h
rename to src/package_bgs/dp/Image.h
index 554d0c7..de20d42 100644
--- a/package_bgs/dp/Image.h
+++ b/src/package_bgs/dp/Image.h
@@ -1,35 +1,8 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* Image.h
-*
-* Purpose:  C++ wrapper for OpenCV IplImage which supports simple and
-*						efficient access to the image data
-*
-* Author: Donovan Parks, September 2007
-*
-* Based on code from:
-*  http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
-******************************************************************************/
 #pragma once
 
 #include <opencv2/opencv.hpp>
-// --- Image Iterator ---------------------------------------------------------
+
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
 
 template <class T>
 class ImageIterator
@@ -62,7 +35,6 @@ public:
     nch = image->nChannels;
   }
 
-
   /* has next ? */
   bool operator!() const { return j < nl; }
 
@@ -356,3 +328,5 @@ public:
 // --- Image Functions --------------------------------------------------------
 
 void DensityFilter(BwImage& image, BwImage& filtered, int minDensity, unsigned char fgValue);
+
+#endif
diff --git a/package_bgs/dp/MeanBGS.cpp b/src/package_bgs/dp/MeanBGS.cpp
similarity index 75%
rename from package_bgs/dp/MeanBGS.cpp
rename to src/package_bgs/dp/MeanBGS.cpp
index 5178158..95aa72f 100644
--- a/package_bgs/dp/MeanBGS.cpp
+++ b/src/package_bgs/dp/MeanBGS.cpp
@@ -1,32 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* MeanBGS.h
-*
-* Purpose: Implementation of a simple temporal mean background
-*		  		 subtraction algorithm.
-*
-* Author: Donovan Parks, September 2007
-*
-******************************************************************************/
-
 #include "MeanBGS.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 void MeanBGS::Initalize(const BgsParams& param)
@@ -125,3 +100,5 @@ void MeanBGS::Subtract(int frame_num, const RgbImage& data,
     }
   }
 }
+
+#endif
diff --git a/package_bgs/dp/MeanBGS.h b/src/package_bgs/dp/MeanBGS.h
similarity index 52%
rename from package_bgs/dp/MeanBGS.h
rename to src/package_bgs/dp/MeanBGS.h
index 306af1a..7ed8baf 100644
--- a/package_bgs/dp/MeanBGS.h
+++ b/src/package_bgs/dp/MeanBGS.h
@@ -1,49 +1,13 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* MeanBGS.hpp
-*
-* Purpose: Implementation of a simple temporal mean background
-*		  		 subtraction algorithm.
-*
-* Author: Donovan Parks, September 2007
-*
-
-Example:
-Algorithms::BackgroundSubtraction::MeanParams params;
-params.SetFrameSize(width, height);
-params.LowThreshold() = 3*30*30;
-params.HighThreshold() = 2*params.LowThreshold();	// Note: high threshold is used by post-processing
-params.Alpha() = 1e-6f;
-params.LearningFrames() = 30;
-
-Algorithms::BackgroundSubtraction::MeanBGS bgs;
-bgs.Initalize(params);
-******************************************************************************/
 #pragma once
 
 #include "Bgs.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 namespace Algorithms
 {
   namespace BackgroundSubtraction
   {
-
     // --- Parameters used by the Mean BGS algorithm ---
     class MeanParams : public BgsParams
     {
@@ -89,6 +53,7 @@ namespace Algorithms
       RgbImageFloat m_mean;
       RgbImage m_background;
     };
-
   }
 }
+
+#endif
diff --git a/package_bgs/dp/PratiMediodBGS.cpp b/src/package_bgs/dp/PratiMediodBGS.cpp
similarity index 84%
rename from package_bgs/dp/PratiMediodBGS.cpp
rename to src/package_bgs/dp/PratiMediodBGS.cpp
index 5a15cec..984240c 100644
--- a/package_bgs/dp/PratiMediodBGS.cpp
+++ b/src/package_bgs/dp/PratiMediodBGS.cpp
@@ -1,41 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* PratiMediodBGS.h
-*
-* Purpose: Implementation of the temporal median background
-*		  		 subtraction algorithm described in:
-*
-* [1] "Detecting Moving Objects, Shosts, and Shadows in Video Stream"
-* 			by R. Cucchiara et al (2003)
-*
-* [2] "Reliable Background Suppression for Complex Scenes"
-*				by S. Calderara et al (2006)
-*
-* Author: Donovan Parks, September 2007
-*
-* Please note that this is not an implementation of the complete system
-* given in the above papers. It simply implements the temporal media background
-* subtraction algorithm.
-******************************************************************************/
-
 #include "PratiMediodBGS.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 PratiMediodBGS::PratiMediodBGS()
@@ -270,6 +236,4 @@ void PratiMediodBGS::Subtract(int frame_num, const RgbImage& data,
   Combine(m_mask_low_threshold, m_mask_high_threshold, high_threshold_mark);
 }
 
-
-
-
+#endif
diff --git a/package_bgs/dp/PratiMediodBGS.h b/src/package_bgs/dp/PratiMediodBGS.h
similarity index 61%
rename from package_bgs/dp/PratiMediodBGS.h
rename to src/package_bgs/dp/PratiMediodBGS.h
index 6bc8f92..8a38515 100644
--- a/package_bgs/dp/PratiMediodBGS.h
+++ b/src/package_bgs/dp/PratiMediodBGS.h
@@ -1,55 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* PratiMediodBGS.hpp
-*
-* Purpose: Implementation of the temporal median background
-*		  		 subtraction algorithm described in:
-*
-* [1] "Detecting Moving Objects, Shosts, and Shadows in Video Stream"
-* 			by R. Cucchiara et al (2003)
-*
-* [2] "Reliable Background Suppression for Complex Scenes"
-*				by S. Calderara et al (2006)
-*
-* Author: Donovan Parks, September 2007
-*
-* Please note that this is not an implementation of the complete system
-* given in the above papers. It simply implements the temporal media background
-* subtraction algorithm.
-
-Example:
-Algorithms::BackgroundSubtraction::PratiParams params;
-params.SetFrameSize(width, height);
-params.LowThreshold() = 30;
-params.HighThreshold() = 2*params.LowThreshold();	// Note: high threshold is used by post-processing
-params.SamplingRate() = 5;
-params.HistorySize() = 16;
-params.Weight() = 5;
-
-Algorithms::BackgroundSubtraction::PratiMediodBGS bgs;
-bgs.Initalize(params);
-******************************************************************************/
 #pragma once
 
 #include <vector>
 #include "Bgs.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 namespace Algorithms
 {
   namespace BackgroundSubtraction
@@ -127,6 +82,7 @@ namespace Algorithms
       BwImage m_mask_low_threshold;
       BwImage m_mask_high_threshold;
     };
-
   }
 }
+
+#endif
diff --git a/package_bgs/dp/TextureBGS.cpp b/src/package_bgs/dp/TextureBGS.cpp
similarity index 86%
rename from package_bgs/dp/TextureBGS.cpp
rename to src/package_bgs/dp/TextureBGS.cpp
index 920f140..faa466a 100644
--- a/package_bgs/dp/TextureBGS.cpp
+++ b/src/package_bgs/dp/TextureBGS.cpp
@@ -1,21 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include "TextureBGS.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 TextureBGS::TextureBGS() {}
 TextureBGS::~TextureBGS() {}
 
@@ -151,3 +137,5 @@ void TextureBGS::UpdateModel(BwImage& fgMask, TextureArray* bgModel,
     }
   }
 }
+
+#endif
diff --git a/package_bgs/dp/TextureBGS.h b/src/package_bgs/dp/TextureBGS.h
similarity index 69%
rename from package_bgs/dp/TextureBGS.h
rename to src/package_bgs/dp/TextureBGS.h
index 2650f04..93328b5 100644
--- a/package_bgs/dp/TextureBGS.h
+++ b/src/package_bgs/dp/TextureBGS.h
@@ -1,24 +1,10 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <math.h>
 #include "Image.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 const int REGION_R = 5;			// Note: the code currently assumes this value is <= 7
 const int TEXTURE_POINTS = 6;	// Note: the code currently assumes this value is 6
 const int TEXTURE_R = 2;		// Note: the code currently assumes this value is 2
@@ -55,3 +41,5 @@ public:
   void UpdateModel(BwImage& fgMask, TextureArray* bgModel,
     TextureHistogram* curTextureHist, unsigned char* modeArray);
 };
+
+#endif
diff --git a/package_bgs/dp/WrenGA.cpp b/src/package_bgs/dp/WrenGA.cpp
similarity index 75%
rename from package_bgs/dp/WrenGA.cpp
rename to src/package_bgs/dp/WrenGA.cpp
index 80a9e27..17a67b7 100644
--- a/package_bgs/dp/WrenGA.cpp
+++ b/src/package_bgs/dp/WrenGA.cpp
@@ -1,37 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* WrenGA.h
-*
-* Purpose: Implementation of the running Gaussian average background
-*		  		 subtraction algorithm described in:
-*	  			 "Pfinder: real-time tracking of the human body"
-* 						by C. Wren et al (1997)
-*
-* Author: Donovan Parks, September 2007
-*
-* Please note that this is not an implementation of Pfinder. It implements
-* a simple background subtraction algorithm where each pixel is represented
-* by a single Gaussian and update using a simple weighting function.
-******************************************************************************/
-
 #include "WrenGA.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 WrenGA::WrenGA()
@@ -171,3 +141,4 @@ void WrenGA::Subtract(int frame_num, const RgbImage& data,
   }
 }
 
+#endif
diff --git a/package_bgs/dp/WrenGA.h b/src/package_bgs/dp/WrenGA.h
similarity index 50%
rename from package_bgs/dp/WrenGA.h
rename to src/package_bgs/dp/WrenGA.h
index 97e97ee..dc3d70f 100644
--- a/package_bgs/dp/WrenGA.h
+++ b/src/package_bgs/dp/WrenGA.h
@@ -1,49 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* WrenGA.hpp
-*
-* Purpose: Implementation of the running Gaussian average background
-*		  		 subtraction algorithm described in:
-*	  			 "Pfinder: real-time tracking of the human body"
-* 						by C. Wren et al (1997)
-*
-* Author: Donovan Parks, September 2007
-*
-* Please note that this is not an implementation of Pfinder. It implements
-* a simple background subtraction algorithm where each pixel is represented
-* by a single Gaussian and update using a simple weighting function.
-
-Example:
-Algorithms::BackgroundSubtraction::WrenParams params;
-params.SetFrameSize(width, height);
-params.LowThreshold() = 3.5f*3.5f;
-params.HighThreshold() = 2*params.LowThreshold();	// Note: high threshold is used by post-processing
-params.Alpha() = 0.005f;
-params.LearningFrames() = 30;
-
-Algorithms::BackgroundSubtraction::WrenGA bgs;
-bgs.Initalize(params);
-******************************************************************************/
 #pragma once
 
 #include "Bgs.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 namespace Algorithms
 {
   namespace BackgroundSubtraction
@@ -68,7 +28,6 @@ namespace Algorithms
       int m_learning_frames;
     };
 
-
     // --- Mean BGS algorithm ---
     class WrenGA : public Bgs
     {
@@ -108,3 +67,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/package_bgs/dp/ZivkovicAGMM.cpp b/src/package_bgs/dp/ZivkovicAGMM.cpp
similarity index 86%
rename from package_bgs/dp/ZivkovicAGMM.cpp
rename to src/package_bgs/dp/ZivkovicAGMM.cpp
index f73d5a1..bcbc827 100644
--- a/package_bgs/dp/ZivkovicAGMM.cpp
+++ b/src/package_bgs/dp/ZivkovicAGMM.cpp
@@ -1,47 +1,7 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* ZivkovicAGMM.cpp
-*
-* Purpose: Implementation of the Gaussian mixture model (GMM) background
-*		  		 subtraction algorithm developed by Z. Zivkovic.
-*
-* Author: Donovan Parks, September 2007
-*
-* This code is based on code by Z. Zivkovic's. I have changed it from a pure
-* C implementation to a cleaner (IMHO) C++ implementation. It is based on the
-* following papers:
-*
-*	"Improved adaptive Gausian mixture model for background subtraction"
-*		Z.Zivkovic
-*		International Conference Pattern Recognition, UK, August, 2004
-*
-*
-* "Efficient Adaptive Density Estimapion per Image Pixel for the
-*			Task of Background Subtraction"
-*		Z.Zivkovic, F. van der Heijden
-*		Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-******************************************************************************/
-
 #include "ZivkovicAGMM.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 using namespace Algorithms::BackgroundSubtraction;
 
 ZivkovicAGMM::ZivkovicAGMM()
@@ -406,3 +366,4 @@ void ZivkovicAGMM::Subtract(int frame_num, const RgbImage& data,
   }
 }
 
+#endif
diff --git a/package_bgs/dp/ZivkovicAGMM.h b/src/package_bgs/dp/ZivkovicAGMM.h
similarity index 62%
rename from package_bgs/dp/ZivkovicAGMM.h
rename to src/package_bgs/dp/ZivkovicAGMM.h
index 07da9c3..9566d01 100644
--- a/package_bgs/dp/ZivkovicAGMM.h
+++ b/src/package_bgs/dp/ZivkovicAGMM.h
@@ -1,59 +1,9 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/****************************************************************************
-*
-* ZivkovicAGMM.hpp
-*
-* Purpose: Implementation of the Gaussian mixture model (GMM) background
-*		  		 subtraction algorithm developed by Z. Zivkovic.
-*
-* Author: Donovan Parks, September 2007
-*
-* This code is based on code by Z. Zivkovic's. I have changed it from a pure
-* C implementation to a cleaner (IMHO) C++ implementation. It is based on the
-* following papers:
-*
-*	"Improved adaptive Gausian mixture model for background subtraction"
-*		Z.Zivkovic
-*		International Conference Pattern Recognition, UK, August, 2004
-*
-*
-* "Efficient Adaptive Density Estimapion per Image Pixel for the
-*			Task of Background Subtraction"
-*		Z.Zivkovic, F. van der Heijden
-*		Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.
-*
-* Zivkovic's code can be obtained at: www.zoranz.net
-
-Example:
-Algorithms::BackgroundSubtraction::ZivkovicParams params;
-params.SetFrameSize(width, height);
-params.LowThreshold() = 5.0f*5.0f;
-params.HighThreshold() = 2*params.LowThreshold();	// Note: high threshold is used by post-processing
-params.Alpha() = 0.001f;
-params.MaxModes() = 3;
-
-Algorithms::BackgroundSubtraction::ZivkovicAGMM bgs;
-bgs.Initalize(params);
-******************************************************************************/
 #pragma once
 
 #include "Bgs.h"
 
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+
 namespace Algorithms
 {
   namespace BackgroundSubtraction
@@ -148,3 +98,5 @@ namespace Algorithms
     };
   }
 }
+
+#endif
diff --git a/src/package_bgs/lb/BGModel.cpp b/src/package_bgs/lb/BGModel.cpp
new file mode 100644
index 0000000..26d9712
--- /dev/null
+++ b/src/package_bgs/lb/BGModel.cpp
@@ -0,0 +1,51 @@
+#include "BGModel.h"
+
+namespace lb_library
+{
+  BGModel::BGModel(int width, int height) : m_width(width), m_height(height)
+  {
+    m_SrcImage = cvCreateImage(cvSize(m_width, m_height), IPL_DEPTH_8U, 3);
+    m_BGImage = cvCreateImage(cvSize(m_width, m_height), IPL_DEPTH_8U, 3);
+    m_FGImage = cvCreateImage(cvSize(m_width, m_height), IPL_DEPTH_8U, 3);
+
+    cvZero(m_SrcImage);
+    cvZero(m_BGImage);
+    cvZero(m_FGImage);
+  }
+
+  BGModel::~BGModel()
+  {
+    if (m_SrcImage != NULL) cvReleaseImage(&m_SrcImage);
+    if (m_BGImage != NULL) cvReleaseImage(&m_BGImage);
+    if (m_FGImage != NULL) cvReleaseImage(&m_FGImage);
+  }
+
+  IplImage* BGModel::GetSrc()
+  {
+    return m_SrcImage;
+  }
+
+  IplImage* BGModel::GetFG()
+  {
+    return m_FGImage;
+  }
+
+  IplImage* BGModel::GetBG()
+  {
+    return m_BGImage;
+  }
+
+  void BGModel::InitModel(IplImage* image)
+  {
+    cvCopy(image, m_SrcImage);
+    Init();
+    return;
+  }
+
+  void BGModel::UpdateModel(IplImage* image)
+  {
+    cvCopy(image, m_SrcImage);
+    Update();
+    return;
+  }
+}
diff --git a/src/package_bgs/lb/BGModel.h b/src/package_bgs/lb/BGModel.h
new file mode 100644
index 0000000..abe43af
--- /dev/null
+++ b/src/package_bgs/lb/BGModel.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <math.h>
+#include <float.h>
+
+#include <opencv2/opencv.hpp>
+
+#include "Types.h"
+
+namespace lb_library
+{
+  class BGModel
+  {
+  public:
+
+    BGModel(int width, int height);
+    virtual ~BGModel();
+
+    void InitModel(IplImage* image);
+    void UpdateModel(IplImage* image);
+
+    virtual void setBGModelParameter(int id, int value) {};
+
+    virtual IplImage* GetSrc();
+    virtual IplImage* GetFG();
+    virtual IplImage* GetBG();
+
+  protected:
+
+    IplImage* m_SrcImage;
+    IplImage* m_BGImage;
+    IplImage* m_FGImage;
+
+    const unsigned int m_width;
+    const unsigned int m_height;
+
+    virtual void Init() = 0;
+    virtual void Update() = 0;
+  };
+}
diff --git a/package_bgs/lb/BGModelFuzzyGauss.cpp b/src/package_bgs/lb/BGModelFuzzyGauss.cpp
similarity index 73%
rename from package_bgs/lb/BGModelFuzzyGauss.cpp
rename to src/package_bgs/lb/BGModelFuzzyGauss.cpp
index 9f9202d..46c793f 100644
--- a/package_bgs/lb/BGModelFuzzyGauss.cpp
+++ b/src/package_bgs/lb/BGModelFuzzyGauss.cpp
@@ -1,39 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelFuzzyGauss.cpp
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
 #include "BGModelFuzzyGauss.h"
 
 namespace lb_library
diff --git a/src/package_bgs/lb/BGModelFuzzyGauss.h b/src/package_bgs/lb/BGModelFuzzyGauss.h
new file mode 100644
index 0000000..0d473b2
--- /dev/null
+++ b/src/package_bgs/lb/BGModelFuzzyGauss.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "BGModel.h"
+
+namespace lb_library
+{
+  namespace FuzzyGaussian
+  {
+    const float ALPHAFUZZYGAUSS = 0.02f;
+    const float THRESHOLDFUZZYGAUSS = 3.5f;
+    const float THRESHOLDBG = 0.5f;
+    const float NOISEFUZZYGAUSS = 50.0f;
+    const float FUZZYEXP = -5.0f;
+
+    class BGModelFuzzyGauss : public BGModel
+    {
+    public:
+      BGModelFuzzyGauss(int width, int height);
+      ~BGModelFuzzyGauss();
+
+      void setBGModelParameter(int id, int value);
+
+    protected:
+      double m_alphamax;
+      double m_threshold;
+      double m_threshBG;
+      double m_noise;
+
+      DBLRGB* m_pMu;
+      DBLRGB* m_pVar;
+
+      void Init();
+      void Update();
+    };
+  }
+}
diff --git a/package_bgs/lb/BGModelFuzzySom.cpp b/src/package_bgs/lb/BGModelFuzzySom.cpp
similarity index 80%
rename from package_bgs/lb/BGModelFuzzySom.cpp
rename to src/package_bgs/lb/BGModelFuzzySom.cpp
index 52aa482..2d85c50 100644
--- a/package_bgs/lb/BGModelFuzzySom.cpp
+++ b/src/package_bgs/lb/BGModelFuzzySom.cpp
@@ -1,39 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelFuzzySom.cpp
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
 #include "BGModelFuzzySom.h"
 
 namespace lb_library
diff --git a/src/package_bgs/lb/BGModelFuzzySom.h b/src/package_bgs/lb/BGModelFuzzySom.h
new file mode 100644
index 0000000..c77255b
--- /dev/null
+++ b/src/package_bgs/lb/BGModelFuzzySom.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "BGModel.h"
+
+namespace lb_library
+{
+  namespace FuzzyAdaptiveSOM
+  {
+    // SOM parameters
+
+    const int M = 3;				// width SOM (per pixel)
+    const int N = 3;				// height SOM (per pixel)
+    const int KERNEL = 3; 	// size Gaussian kernel
+
+    const bool SPAN_NEIGHBORS = false; // true if update neighborhood spans different pixels			//
+    const int TRAINING_STEPS = 100;			// number of training steps
+
+    const double EPS1 = 100.0; // model match distance during training
+    const double EPS2 = 20.0;  // model match distance
+    const double C1 = 1.0;     // learning rate during training
+    const double C2 = 0.05;    // learning rate
+
+    const double FUZZYEXP = -5.0;
+    const double FUZZYTHRESH = 0.8;
+
+    class BGModelFuzzySom : public BGModel
+    {
+    public:
+      BGModelFuzzySom(int width, int height);
+      ~BGModelFuzzySom();
+
+      void setBGModelParameter(int id, int value);
+
+    protected:
+      int m_widthSOM;
+      int m_heightSOM;
+      int m_offset;
+      int m_pad;
+      int m_K;
+      int m_TSteps;
+
+      double m_Wmax;
+
+      double m_epsilon1;
+      double m_epsilon2;
+      double m_alpha1;
+      double m_alpha2;
+
+      DBLRGB** m_ppSOM;					// SOM grid
+      double** m_ppW;						// Weights
+
+      void Init();
+      void Update();
+    };
+  }
+}
diff --git a/package_bgs/lb/BGModelGauss.cpp b/src/package_bgs/lb/BGModelGauss.cpp
similarity index 71%
rename from package_bgs/lb/BGModelGauss.cpp
rename to src/package_bgs/lb/BGModelGauss.cpp
index 9784af4..6a4b423 100644
--- a/package_bgs/lb/BGModelGauss.cpp
+++ b/src/package_bgs/lb/BGModelGauss.cpp
@@ -1,39 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelGauss.cpp
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
 #include "BGModelGauss.h"
 
 namespace lb_library
diff --git a/src/package_bgs/lb/BGModelGauss.h b/src/package_bgs/lb/BGModelGauss.h
new file mode 100644
index 0000000..5dffa09
--- /dev/null
+++ b/src/package_bgs/lb/BGModelGauss.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "BGModel.h"
+
+namespace lb_library
+{
+  namespace SimpleGaussian
+  {
+    // Parameters
+    const double THRESHGAUSS = 2.5;   // Threshold
+    const double ALPHAGAUSS = 0.0001; // Learning rate
+    const double NOISEGAUSS = 50.0;   // Minimum variance (noise)
+
+    class BGModelGauss : public BGModel
+    {
+    public:
+      BGModelGauss(int width, int height);
+      ~BGModelGauss();
+
+      void setBGModelParameter(int id, int value);
+
+    protected:
+      double m_alpha;
+      double m_threshold;
+      double m_noise;
+
+      DBLRGB* m_pMu;
+      DBLRGB* m_pVar;
+
+      void Init();
+      void Update();
+    };
+  }
+}
diff --git a/package_bgs/lb/BGModelMog.cpp b/src/package_bgs/lb/BGModelMog.cpp
similarity index 81%
rename from package_bgs/lb/BGModelMog.cpp
rename to src/package_bgs/lb/BGModelMog.cpp
index 634565c..e52c6fb 100644
--- a/package_bgs/lb/BGModelMog.cpp
+++ b/src/package_bgs/lb/BGModelMog.cpp
@@ -1,39 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelMog.cpp
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
 #include "BGModelMog.h"
 
 namespace lb_library
diff --git a/src/package_bgs/lb/BGModelMog.h b/src/package_bgs/lb/BGModelMog.h
new file mode 100644
index 0000000..6fd6e90
--- /dev/null
+++ b/src/package_bgs/lb/BGModelMog.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "BGModel.h"
+
+namespace lb_library
+{
+  namespace MixtureOfGaussians
+  {
+    const unsigned int NUMBERGAUSSIANS = 3;
+    const float LEARNINGRATEMOG = 0.001f;
+    const float THRESHOLDMOG = 2.5f;
+    const float BGTHRESHOLDMOG = 0.5f;
+    const float INITIALVARMOG = 50.0f;
+
+    typedef struct tagMOGDATA
+    {
+      DBLRGB mu;
+      DBLRGB var;
+      double w;
+      double sortKey;
+    } MOGDATA;
+
+    class BGModelMog : public BGModel
+    {
+    public:
+      BGModelMog(int width, int height);
+      ~BGModelMog();
+
+      void setBGModelParameter(int id, int value);
+
+    protected:
+      double m_alpha;
+      double m_threshold;
+      double m_noise;
+      double m_T;
+
+      MOGDATA* m_pMOG;
+      int* m_pK;				// number of distributions per pixel
+
+      void Init();
+      void Update();
+    };
+  }
+}
diff --git a/package_bgs/lb/BGModelSom.cpp b/src/package_bgs/lb/BGModelSom.cpp
similarity index 80%
rename from package_bgs/lb/BGModelSom.cpp
rename to src/package_bgs/lb/BGModelSom.cpp
index e57e15d..e19b8eb 100644
--- a/package_bgs/lb/BGModelSom.cpp
+++ b/src/package_bgs/lb/BGModelSom.cpp
@@ -1,39 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-/*  Scene 1.0.1 -- Background subtraction and object tracking for complex environments
-BGModelSom.cpp
-
-Copyright (C) 2011 Laurence Bender <lbender@untref.edu.ar>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
 #include "BGModelSom.h"
 
 namespace lb_library
diff --git a/src/package_bgs/lb/BGModelSom.h b/src/package_bgs/lb/BGModelSom.h
new file mode 100644
index 0000000..b3bf5f9
--- /dev/null
+++ b/src/package_bgs/lb/BGModelSom.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "BGModel.h"
+
+namespace lb_library
+{
+  namespace AdaptiveSOM
+  {
+    // SOM parameters
+
+    const int M = 3;				// width SOM (per pixel)
+    const int N = 3;				// height SOM (per pixel)
+    const int KERNEL = 3; 	// size Gaussian kernel
+
+    const bool SPAN_NEIGHBORS = false; // true if update neighborhood spans different pixels			//
+    const int TRAINING_STEPS = 100;			// number of training steps
+
+    const float EPS1 = 100.0; // model match distance during training
+    const float EPS2 = 20.0;  // model match distance
+    const float C1 = 1.0;     // learning rate during training
+    const float C2 = 0.05f;    // learning rate
+
+    class BGModelSom : public BGModel
+    {
+    public:
+      BGModelSom(int width, int height);
+      ~BGModelSom();
+
+      void setBGModelParameter(int id, int value);
+
+    protected:
+      int m_widthSOM;
+      int m_heightSOM;
+      int m_offset;
+      int m_pad;
+      int m_K;
+      int m_TSteps;
+
+      double m_Wmax;
+
+      double m_epsilon1;
+      double m_epsilon2;
+      double m_alpha1;
+      double m_alpha2;
+
+      DBLRGB** m_ppSOM;					// SOM grid
+      double** m_ppW;						// Weights
+
+      void Init();
+      void Update();
+    };
+  }
+}
diff --git a/src/package_bgs/lb/Types.h b/src/package_bgs/lb/Types.h
new file mode 100644
index 0000000..b6f5ccd
--- /dev/null
+++ b/src/package_bgs/lb/Types.h
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <opencv2/opencv.hpp>
+#include <opencv2/core/core_c.h>
+
+namespace lb_library
+{
+template<class T> class Image
+{
+private:
+  IplImage* imgp;
+
+public:
+  Image(IplImage* img=0) {imgp=img;}
+  ~Image(){imgp=0;}
+  
+  void operator=(IplImage* img) {imgp=img;}
+  
+  inline T* operator[](const int rowIndx)
+  {
+    return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));
+  }
+};
+
+typedef struct{
+  unsigned char b,g,r;
+} RgbPixel;
+
+typedef struct{
+  unsigned char Blue,Green,Red;
+} BYTERGB;
+
+typedef struct{
+  unsigned int Blue,Green,Red;
+} INTRGB;
+
+typedef struct{
+  float b,g,r;
+}RgbPixelFloat;
+
+typedef struct{
+  double Blue,Green,Red;
+} DBLRGB;
+
+typedef Image<RgbPixel>       RgbImage;
+typedef Image<RgbPixelFloat>  RgbImageFloat;
+typedef Image<unsigned char>  BwImage;
+typedef Image<float>          BwImageFloat;
+
+/*
+  IplImage* img = cvCreateImage(cvSize(640,480), IPL_DEPTH_32F, 3);
+  RgbImageFloat imgA(img);
+  for(int i = 0; i < m_height; i++)
+    for(int j = 0; j < m_width; j++)
+      imgA[i][j].b = 111;
+      imgA[i][j].g = 111;
+      imgA[i][j].r = 111;
+  */
+}
diff --git a/fet/FG/1.png b/tools/fet/FG/1.png
similarity index 100%
rename from fet/FG/1.png
rename to tools/fet/FG/1.png
diff --git a/fet/FG/10.png b/tools/fet/FG/10.png
similarity index 100%
rename from fet/FG/10.png
rename to tools/fet/FG/10.png
diff --git a/fet/FG/11.png b/tools/fet/FG/11.png
similarity index 100%
rename from fet/FG/11.png
rename to tools/fet/FG/11.png
diff --git a/fet/FG/12.png b/tools/fet/FG/12.png
similarity index 100%
rename from fet/FG/12.png
rename to tools/fet/FG/12.png
diff --git a/fet/FG/13.png b/tools/fet/FG/13.png
similarity index 100%
rename from fet/FG/13.png
rename to tools/fet/FG/13.png
diff --git a/fet/FG/14.png b/tools/fet/FG/14.png
similarity index 100%
rename from fet/FG/14.png
rename to tools/fet/FG/14.png
diff --git a/fet/FG/15.png b/tools/fet/FG/15.png
similarity index 100%
rename from fet/FG/15.png
rename to tools/fet/FG/15.png
diff --git a/fet/FG/16.png b/tools/fet/FG/16.png
similarity index 100%
rename from fet/FG/16.png
rename to tools/fet/FG/16.png
diff --git a/fet/FG/17.png b/tools/fet/FG/17.png
similarity index 100%
rename from fet/FG/17.png
rename to tools/fet/FG/17.png
diff --git a/fet/FG/18.png b/tools/fet/FG/18.png
similarity index 100%
rename from fet/FG/18.png
rename to tools/fet/FG/18.png
diff --git a/fet/FG/19.png b/tools/fet/FG/19.png
similarity index 100%
rename from fet/FG/19.png
rename to tools/fet/FG/19.png
diff --git a/fet/FG/2.png b/tools/fet/FG/2.png
similarity index 100%
rename from fet/FG/2.png
rename to tools/fet/FG/2.png
diff --git a/fet/FG/20.png b/tools/fet/FG/20.png
similarity index 100%
rename from fet/FG/20.png
rename to tools/fet/FG/20.png
diff --git a/fet/FG/21.png b/tools/fet/FG/21.png
similarity index 100%
rename from fet/FG/21.png
rename to tools/fet/FG/21.png
diff --git a/fet/FG/22.png b/tools/fet/FG/22.png
similarity index 100%
rename from fet/FG/22.png
rename to tools/fet/FG/22.png
diff --git a/fet/FG/23.png b/tools/fet/FG/23.png
similarity index 100%
rename from fet/FG/23.png
rename to tools/fet/FG/23.png
diff --git a/fet/FG/24.png b/tools/fet/FG/24.png
similarity index 100%
rename from fet/FG/24.png
rename to tools/fet/FG/24.png
diff --git a/fet/FG/25.png b/tools/fet/FG/25.png
similarity index 100%
rename from fet/FG/25.png
rename to tools/fet/FG/25.png
diff --git a/fet/FG/26.png b/tools/fet/FG/26.png
similarity index 100%
rename from fet/FG/26.png
rename to tools/fet/FG/26.png
diff --git a/fet/FG/27.png b/tools/fet/FG/27.png
similarity index 100%
rename from fet/FG/27.png
rename to tools/fet/FG/27.png
diff --git a/fet/FG/28.png b/tools/fet/FG/28.png
similarity index 100%
rename from fet/FG/28.png
rename to tools/fet/FG/28.png
diff --git a/fet/FG/29.png b/tools/fet/FG/29.png
similarity index 100%
rename from fet/FG/29.png
rename to tools/fet/FG/29.png
diff --git a/fet/FG/3.png b/tools/fet/FG/3.png
similarity index 100%
rename from fet/FG/3.png
rename to tools/fet/FG/3.png
diff --git a/fet/FG/30.png b/tools/fet/FG/30.png
similarity index 100%
rename from fet/FG/30.png
rename to tools/fet/FG/30.png
diff --git a/fet/FG/31.png b/tools/fet/FG/31.png
similarity index 100%
rename from fet/FG/31.png
rename to tools/fet/FG/31.png
diff --git a/fet/FG/4.png b/tools/fet/FG/4.png
similarity index 100%
rename from fet/FG/4.png
rename to tools/fet/FG/4.png
diff --git a/fet/FG/5.png b/tools/fet/FG/5.png
similarity index 100%
rename from fet/FG/5.png
rename to tools/fet/FG/5.png
diff --git a/fet/FG/6.png b/tools/fet/FG/6.png
similarity index 100%
rename from fet/FG/6.png
rename to tools/fet/FG/6.png
diff --git a/fet/FG/7.png b/tools/fet/FG/7.png
similarity index 100%
rename from fet/FG/7.png
rename to tools/fet/FG/7.png
diff --git a/fet/FG/8.png b/tools/fet/FG/8.png
similarity index 100%
rename from fet/FG/8.png
rename to tools/fet/FG/8.png
diff --git a/fet/FG/9.png b/tools/fet/FG/9.png
similarity index 100%
rename from fet/FG/9.png
rename to tools/fet/FG/9.png
diff --git a/fet/GT/1.png b/tools/fet/GT/1.png
similarity index 100%
rename from fet/GT/1.png
rename to tools/fet/GT/1.png
diff --git a/fet/GT/10.png b/tools/fet/GT/10.png
similarity index 100%
rename from fet/GT/10.png
rename to tools/fet/GT/10.png
diff --git a/fet/GT/11.png b/tools/fet/GT/11.png
similarity index 100%
rename from fet/GT/11.png
rename to tools/fet/GT/11.png
diff --git a/fet/GT/12.png b/tools/fet/GT/12.png
similarity index 100%
rename from fet/GT/12.png
rename to tools/fet/GT/12.png
diff --git a/fet/GT/13.png b/tools/fet/GT/13.png
similarity index 100%
rename from fet/GT/13.png
rename to tools/fet/GT/13.png
diff --git a/fet/GT/14.png b/tools/fet/GT/14.png
similarity index 100%
rename from fet/GT/14.png
rename to tools/fet/GT/14.png
diff --git a/fet/GT/15.png b/tools/fet/GT/15.png
similarity index 100%
rename from fet/GT/15.png
rename to tools/fet/GT/15.png
diff --git a/fet/GT/16.png b/tools/fet/GT/16.png
similarity index 100%
rename from fet/GT/16.png
rename to tools/fet/GT/16.png
diff --git a/fet/GT/17.png b/tools/fet/GT/17.png
similarity index 100%
rename from fet/GT/17.png
rename to tools/fet/GT/17.png
diff --git a/fet/GT/18.png b/tools/fet/GT/18.png
similarity index 100%
rename from fet/GT/18.png
rename to tools/fet/GT/18.png
diff --git a/fet/GT/19.png b/tools/fet/GT/19.png
similarity index 100%
rename from fet/GT/19.png
rename to tools/fet/GT/19.png
diff --git a/fet/GT/2.png b/tools/fet/GT/2.png
similarity index 100%
rename from fet/GT/2.png
rename to tools/fet/GT/2.png
diff --git a/fet/GT/20.png b/tools/fet/GT/20.png
similarity index 100%
rename from fet/GT/20.png
rename to tools/fet/GT/20.png
diff --git a/fet/GT/21.png b/tools/fet/GT/21.png
similarity index 100%
rename from fet/GT/21.png
rename to tools/fet/GT/21.png
diff --git a/fet/GT/22.png b/tools/fet/GT/22.png
similarity index 100%
rename from fet/GT/22.png
rename to tools/fet/GT/22.png
diff --git a/fet/GT/23.png b/tools/fet/GT/23.png
similarity index 100%
rename from fet/GT/23.png
rename to tools/fet/GT/23.png
diff --git a/fet/GT/24.png b/tools/fet/GT/24.png
similarity index 100%
rename from fet/GT/24.png
rename to tools/fet/GT/24.png
diff --git a/fet/GT/25.png b/tools/fet/GT/25.png
similarity index 100%
rename from fet/GT/25.png
rename to tools/fet/GT/25.png
diff --git a/fet/GT/26.png b/tools/fet/GT/26.png
similarity index 100%
rename from fet/GT/26.png
rename to tools/fet/GT/26.png
diff --git a/fet/GT/27.png b/tools/fet/GT/27.png
similarity index 100%
rename from fet/GT/27.png
rename to tools/fet/GT/27.png
diff --git a/fet/GT/28.png b/tools/fet/GT/28.png
similarity index 100%
rename from fet/GT/28.png
rename to tools/fet/GT/28.png
diff --git a/fet/GT/29.png b/tools/fet/GT/29.png
similarity index 100%
rename from fet/GT/29.png
rename to tools/fet/GT/29.png
diff --git a/fet/GT/3.png b/tools/fet/GT/3.png
similarity index 100%
rename from fet/GT/3.png
rename to tools/fet/GT/3.png
diff --git a/fet/GT/30.png b/tools/fet/GT/30.png
similarity index 100%
rename from fet/GT/30.png
rename to tools/fet/GT/30.png
diff --git a/fet/GT/31.png b/tools/fet/GT/31.png
similarity index 100%
rename from fet/GT/31.png
rename to tools/fet/GT/31.png
diff --git a/fet/GT/4.png b/tools/fet/GT/4.png
similarity index 100%
rename from fet/GT/4.png
rename to tools/fet/GT/4.png
diff --git a/fet/GT/5.png b/tools/fet/GT/5.png
similarity index 100%
rename from fet/GT/5.png
rename to tools/fet/GT/5.png
diff --git a/fet/GT/6.png b/tools/fet/GT/6.png
similarity index 100%
rename from fet/GT/6.png
rename to tools/fet/GT/6.png
diff --git a/fet/GT/7.png b/tools/fet/GT/7.png
similarity index 100%
rename from fet/GT/7.png
rename to tools/fet/GT/7.png
diff --git a/fet/GT/8.png b/tools/fet/GT/8.png
similarity index 100%
rename from fet/GT/8.png
rename to tools/fet/GT/8.png
diff --git a/fet/GT/9.png b/tools/fet/GT/9.png
similarity index 100%
rename from fet/GT/9.png
rename to tools/fet/GT/9.png
diff --git a/fet/README.txt b/tools/fet/README.txt
similarity index 100%
rename from fet/README.txt
rename to tools/fet/README.txt
diff --git a/fet/SC/1.png b/tools/fet/SC/1.png
similarity index 100%
rename from fet/SC/1.png
rename to tools/fet/SC/1.png
diff --git a/fet/SC/10.png b/tools/fet/SC/10.png
similarity index 100%
rename from fet/SC/10.png
rename to tools/fet/SC/10.png
diff --git a/fet/SC/11.png b/tools/fet/SC/11.png
similarity index 100%
rename from fet/SC/11.png
rename to tools/fet/SC/11.png
diff --git a/fet/SC/12.png b/tools/fet/SC/12.png
similarity index 100%
rename from fet/SC/12.png
rename to tools/fet/SC/12.png
diff --git a/fet/SC/13.png b/tools/fet/SC/13.png
similarity index 100%
rename from fet/SC/13.png
rename to tools/fet/SC/13.png
diff --git a/fet/SC/14.png b/tools/fet/SC/14.png
similarity index 100%
rename from fet/SC/14.png
rename to tools/fet/SC/14.png
diff --git a/fet/SC/15.png b/tools/fet/SC/15.png
similarity index 100%
rename from fet/SC/15.png
rename to tools/fet/SC/15.png
diff --git a/fet/SC/16.png b/tools/fet/SC/16.png
similarity index 100%
rename from fet/SC/16.png
rename to tools/fet/SC/16.png
diff --git a/fet/SC/17.png b/tools/fet/SC/17.png
similarity index 100%
rename from fet/SC/17.png
rename to tools/fet/SC/17.png
diff --git a/fet/SC/18.png b/tools/fet/SC/18.png
similarity index 100%
rename from fet/SC/18.png
rename to tools/fet/SC/18.png
diff --git a/fet/SC/19.png b/tools/fet/SC/19.png
similarity index 100%
rename from fet/SC/19.png
rename to tools/fet/SC/19.png
diff --git a/fet/SC/2.png b/tools/fet/SC/2.png
similarity index 100%
rename from fet/SC/2.png
rename to tools/fet/SC/2.png
diff --git a/fet/SC/20.png b/tools/fet/SC/20.png
similarity index 100%
rename from fet/SC/20.png
rename to tools/fet/SC/20.png
diff --git a/fet/SC/21.png b/tools/fet/SC/21.png
similarity index 100%
rename from fet/SC/21.png
rename to tools/fet/SC/21.png
diff --git a/fet/SC/22.png b/tools/fet/SC/22.png
similarity index 100%
rename from fet/SC/22.png
rename to tools/fet/SC/22.png
diff --git a/fet/SC/23.png b/tools/fet/SC/23.png
similarity index 100%
rename from fet/SC/23.png
rename to tools/fet/SC/23.png
diff --git a/fet/SC/24.png b/tools/fet/SC/24.png
similarity index 100%
rename from fet/SC/24.png
rename to tools/fet/SC/24.png
diff --git a/fet/SC/25.png b/tools/fet/SC/25.png
similarity index 100%
rename from fet/SC/25.png
rename to tools/fet/SC/25.png
diff --git a/fet/SC/26.png b/tools/fet/SC/26.png
similarity index 100%
rename from fet/SC/26.png
rename to tools/fet/SC/26.png
diff --git a/fet/SC/27.png b/tools/fet/SC/27.png
similarity index 100%
rename from fet/SC/27.png
rename to tools/fet/SC/27.png
diff --git a/fet/SC/28.png b/tools/fet/SC/28.png
similarity index 100%
rename from fet/SC/28.png
rename to tools/fet/SC/28.png
diff --git a/fet/SC/29.png b/tools/fet/SC/29.png
similarity index 100%
rename from fet/SC/29.png
rename to tools/fet/SC/29.png
diff --git a/fet/SC/3.png b/tools/fet/SC/3.png
similarity index 100%
rename from fet/SC/3.png
rename to tools/fet/SC/3.png
diff --git a/fet/SC/30.png b/tools/fet/SC/30.png
similarity index 100%
rename from fet/SC/30.png
rename to tools/fet/SC/30.png
diff --git a/fet/SC/31.png b/tools/fet/SC/31.png
similarity index 100%
rename from fet/SC/31.png
rename to tools/fet/SC/31.png
diff --git a/fet/SC/4.png b/tools/fet/SC/4.png
similarity index 100%
rename from fet/SC/4.png
rename to tools/fet/SC/4.png
diff --git a/fet/SC/5.png b/tools/fet/SC/5.png
similarity index 100%
rename from fet/SC/5.png
rename to tools/fet/SC/5.png
diff --git a/fet/SC/6.png b/tools/fet/SC/6.png
similarity index 100%
rename from fet/SC/6.png
rename to tools/fet/SC/6.png
diff --git a/fet/SC/7.png b/tools/fet/SC/7.png
similarity index 100%
rename from fet/SC/7.png
rename to tools/fet/SC/7.png
diff --git a/fet/SC/8.png b/tools/fet/SC/8.png
similarity index 100%
rename from fet/SC/8.png
rename to tools/fet/SC/8.png
diff --git a/fet/SC/9.png b/tools/fet/SC/9.png
similarity index 100%
rename from fet/SC/9.png
rename to tools/fet/SC/9.png
diff --git a/fet/fet.py b/tools/fet/fet.py
similarity index 100%
rename from fet/fet.py
rename to tools/fet/fet.py
diff --git a/wrapper_java/.gitignore b/wrapper/java/.gitignore
similarity index 100%
rename from wrapper_java/.gitignore
rename to wrapper/java/.gitignore
diff --git a/wrapper_java/CMakeLists.txt b/wrapper/java/CMakeLists.txt
similarity index 91%
rename from wrapper_java/CMakeLists.txt
rename to wrapper/java/CMakeLists.txt
index 88b9845..7058660 100644
--- a/wrapper_java/CMakeLists.txt
+++ b/wrapper/java/CMakeLists.txt
@@ -58,10 +58,10 @@ if (OpenCV_FOUND)
   message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
 endif()
 
-file(GLOB_RECURSE analysis_src ../package_analysis/*.cpp)
-file(GLOB_RECURSE analysis_inc ../package_analysis/*.h)
-file(GLOB_RECURSE bgs_src ../package_bgs/*.cpp package_bgs/*.c)
-file(GLOB_RECURSE bgs_inc ../package_bgs/*.h)
+file(GLOB_RECURSE analysis_src ../../src/package_analysis/*.cpp)
+file(GLOB_RECURSE analysis_inc ../../src/package_analysis/*.h)
+file(GLOB_RECURSE bgs_src ../../src/package_bgs/*.cpp ../../src/package_bgs/*.c)
+file(GLOB_RECURSE bgs_inc ../../src/package_bgs/*.h)
 
 include_directories(${CMAKE_SOURCE_DIR} ${JNI_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
 
diff --git a/wrapper_java/README.md b/wrapper/java/README.md
similarity index 89%
rename from wrapper_java/README.md
rename to wrapper/java/README.md
index bd1a595..cce6960 100644
--- a/wrapper_java/README.md
+++ b/wrapper/java/README.md
@@ -2,7 +2,7 @@
 
 * Running CMAKE with Visual Studio 2015 and OpenCV 3.2.0 (x64)
 
-* * Working directory: **bgslibrary\wrapper_java**
+* * Working directory: **bgslibrary\wrapper\java**
 
 ```
 :: Set OpenCV env
@@ -23,7 +23,7 @@ cd ..
 
 * Click on **ALL_BUILD** and build
 
-* Copy **libbgs_java_module.dll** to **bgslibrary\wrapper_java**
+* Copy **libbgs_java_module.dll** to **bgslibrary\wrapper\java**
 
 * Compile Java source
 
diff --git a/wrapper_java/bgslibrary_java_module.cpp b/wrapper/java/bgslibrary_java_module.cpp
similarity index 94%
rename from wrapper_java/bgslibrary_java_module.cpp
rename to wrapper/java/bgslibrary_java_module.cpp
index 2b63e4b..e7f2a57 100644
--- a/wrapper_java/bgslibrary_java_module.cpp
+++ b/wrapper/java/bgslibrary_java_module.cpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #include <iostream>
 #include <opencv2/opencv.hpp>
 
diff --git a/wrapper_java/bgslibrary_java_module.hpp b/wrapper/java/bgslibrary_java_module.hpp
similarity index 52%
rename from wrapper_java/bgslibrary_java_module.hpp
rename to wrapper/java/bgslibrary_java_module.hpp
index 9f40255..b2d46ea 100644
--- a/wrapper_java/bgslibrary_java_module.hpp
+++ b/wrapper/java/bgslibrary_java_module.hpp
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
 #pragma once
 
 #include <iostream>
@@ -22,7 +6,7 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include <string>
 
 #include "src/bgslibrary_BgsLib.h"
-#include "../package_bgs/bgslibrary.h"
+#include "../../src/package_bgs/bgslibrary.h"
 
 bool constructObject(std::string algorithm);
 void computeForegroundMask(const cv::Mat &img_input, cv::Mat &img_output);
diff --git a/demos/linux_ubuntu/config/.gitignore b/wrapper/java/config/.gitignore
similarity index 83%
rename from demos/linux_ubuntu/config/.gitignore
rename to wrapper/java/config/.gitignore
index 8ee04a0..4e2a98b 100644
--- a/demos/linux_ubuntu/config/.gitignore
+++ b/wrapper/java/config/.gitignore
@@ -1,4 +1,4 @@
 # Ignore everything in this directory
 *
 # Except these files
-!.gitignore
\ No newline at end of file
+!.gitignore
diff --git a/wrapper_java/images/320x240.gif b/wrapper/java/images/320x240.gif
similarity index 100%
rename from wrapper_java/images/320x240.gif
rename to wrapper/java/images/320x240.gif
diff --git a/wrapper_java/images/640x480.png b/wrapper/java/images/640x480.png
similarity index 100%
rename from wrapper_java/images/640x480.png
rename to wrapper/java/images/640x480.png
diff --git a/wrapper_java/libs/README.md b/wrapper/java/libs/README.md
similarity index 100%
rename from wrapper_java/libs/README.md
rename to wrapper/java/libs/README.md
diff --git a/wrapper_java/libs/opencv-320.jar b/wrapper/java/libs/opencv-320.jar
similarity index 100%
rename from wrapper_java/libs/opencv-320.jar
rename to wrapper/java/libs/opencv-320.jar
diff --git a/wrapper_java/src/bgslibrary/.gitignore b/wrapper/java/src/bgslibrary/.gitignore
similarity index 100%
rename from wrapper_java/src/bgslibrary/.gitignore
rename to wrapper/java/src/bgslibrary/.gitignore
diff --git a/wrapper_java/src/bgslibrary/BgsLib.java b/wrapper/java/src/bgslibrary/BgsLib.java
similarity index 67%
rename from wrapper_java/src/bgslibrary/BgsLib.java
rename to wrapper/java/src/bgslibrary/BgsLib.java
index c9b4608..fc24e30 100644
--- a/wrapper_java/src/bgslibrary/BgsLib.java
+++ b/wrapper/java/src/bgslibrary/BgsLib.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
 package bgslibrary;
 
 import org.opencv.core.Core;
diff --git a/wrapper_java/src/bgslibrary/ImagePanel.java b/wrapper/java/src/bgslibrary/ImagePanel.java
similarity index 100%
rename from wrapper_java/src/bgslibrary/ImagePanel.java
rename to wrapper/java/src/bgslibrary/ImagePanel.java
diff --git a/wrapper_java/src/bgslibrary/Main.java b/wrapper/java/src/bgslibrary/Main.java
similarity index 87%
rename from wrapper_java/src/bgslibrary/Main.java
rename to wrapper/java/src/bgslibrary/Main.java
index 10489ec..f613199 100644
--- a/wrapper_java/src/bgslibrary/Main.java
+++ b/wrapper/java/src/bgslibrary/Main.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
 package bgslibrary;
 
 import java.awt.BorderLayout;
diff --git a/wrapper_java/src/bgslibrary/Utils.java b/wrapper/java/src/bgslibrary/Utils.java
similarity index 78%
rename from wrapper_java/src/bgslibrary/Utils.java
rename to wrapper/java/src/bgslibrary/Utils.java
index fd59447..8a321af 100644
--- a/wrapper_java/src/bgslibrary/Utils.java
+++ b/wrapper/java/src/bgslibrary/Utils.java
@@ -1,19 +1,3 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
 package bgslibrary;
 
 import java.awt.FlowLayout;
diff --git a/wrapper_java/src/bgslibrary_BgsLib.h b/wrapper/java/src/bgslibrary_BgsLib.h
similarity index 100%
rename from wrapper_java/src/bgslibrary_BgsLib.h
rename to wrapper/java/src/bgslibrary_BgsLib.h
diff --git a/wrapper_matlab/.gitignore b/wrapper/matlab/.gitignore
similarity index 100%
rename from wrapper_matlab/.gitignore
rename to wrapper/matlab/.gitignore
diff --git a/wrapper_matlab/README.txt b/wrapper/matlab/README.txt
similarity index 100%
rename from wrapper_matlab/README.txt
rename to wrapper/matlab/README.txt
diff --git a/wrapper_matlab/README_visionopencv.txt b/wrapper/matlab/README_visionopencv.txt
similarity index 100%
rename from wrapper_matlab/README_visionopencv.txt
rename to wrapper/matlab/README_visionopencv.txt
diff --git a/wrapper_matlab/backgroundSubtractor.m b/wrapper/matlab/backgroundSubtractor.m
similarity index 74%
rename from wrapper_matlab/backgroundSubtractor.m
rename to wrapper/matlab/backgroundSubtractor.m
index e431766..859d796 100644
--- a/wrapper_matlab/backgroundSubtractor.m
+++ b/wrapper/matlab/backgroundSubtractor.m
@@ -1,21 +1,3 @@
-%{
-/*
- * This file is part of BGSLibrary.
- *
- * BGSLibrary is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * BGSLibrary is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
-%}
 classdef backgroundSubtractor
   %backgroundSubtractor Wrapper class for BGSLibrary
   %   obj = backgroundSubtractor(algorithm)
diff --git a/wrapper_matlab/backgroundSubtractor_wrapper.cpp b/wrapper/matlab/backgroundSubtractor_wrapper.cpp
similarity index 94%
rename from wrapper_matlab/backgroundSubtractor_wrapper.cpp
rename to wrapper/matlab/backgroundSubtractor_wrapper.cpp
index 63880e4..ac956a4 100644
--- a/wrapper_matlab/backgroundSubtractor_wrapper.cpp
+++ b/wrapper/matlab/backgroundSubtractor_wrapper.cpp
@@ -1,23 +1,5 @@
-/*
- * This file is part of BGSLibrary.
- *
- * BGSLibrary is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * BGSLibrary is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
-
 #include "opencvmex.hpp"
- // On some platforms, the following include is needed for "placement new".
- // For more information see: http://en.wikipedia.org/wiki/Placement_syntax
+
 #include <memory>
 
 #include <typeinfo>
diff --git a/wrapper/matlab/compile.m b/wrapper/matlab/compile.m
new file mode 100644
index 0000000..644464e
--- /dev/null
+++ b/wrapper/matlab/compile.m
@@ -0,0 +1,95 @@
+%% Compile
+clc;
+mexOpenCV -v -DMEX_COMPILE_FLAG -I"../../src/package_bgs" backgroundSubtractor_wrapper.cpp ...
+  "../../src/package_bgs/FrameDifference.cpp" ...
+  "../../src/package_bgs/StaticFrameDifference.cpp" ...
+  "../../src/package_bgs/WeightedMovingMean.cpp" ...
+  "../../src/package_bgs/WeightedMovingVariance.cpp" ...
+  "../../src/package_bgs/MixtureOfGaussianV1.cpp" ...
+  "../../src/package_bgs/MixtureOfGaussianV2.cpp" ...
+  "../../src/package_bgs/AdaptiveBackgroundLearning.cpp" ...
+  "../../src/package_bgs/AdaptiveSelectiveBackgroundLearning.cpp" ...
+  "../../src/package_bgs/GMG.cpp" ...
+  "../../src/package_bgs/KNN.cpp" ...
+  "../../src/package_bgs/DPAdaptiveMedian.cpp" ...
+  "../../src/package_bgs/DPGrimsonGMM.cpp" ...
+  "../../src/package_bgs/DPZivkovicAGMM.cpp" ...
+  "../../src/package_bgs/DPMean.cpp" ...
+  "../../src/package_bgs/DPWrenGA.cpp" ...
+  "../../src/package_bgs/DPPratiMediod.cpp" ...
+  "../../src/package_bgs/DPEigenbackground.cpp" ...
+  "../../src/package_bgs/DPTexture.cpp" ...
+  "../../src/package_bgs/dp/AdaptiveMedianBGS.cpp" ...
+  "../../src/package_bgs/dp/Image.cpp" ...
+  "../../src/package_bgs/dp/Error.cpp" ...
+  "../../src/package_bgs/dp/GrimsonGMM.cpp" ...
+  "../../src/package_bgs/dp/ZivkovicAGMM.cpp" ...
+  "../../src/package_bgs/dp/MeanBGS.cpp" ...
+  "../../src/package_bgs/dp/WrenGA.cpp"  ...
+  "../../src/package_bgs/dp/PratiMediodBGS.cpp" ...
+  "../../src/package_bgs/dp/Eigenbackground.cpp" ...
+  "../../src/package_bgs/dp/TextureBGS.cpp" ...
+  "../../src/package_bgs/T2FGMM_UM.cpp" ...
+  "../../src/package_bgs/T2FGMM_UV.cpp" ...
+  "../../src/package_bgs/T2FMRF_UM.cpp" ...
+  "../../src/package_bgs/T2FMRF_UV.cpp" ...
+  "../../src/package_bgs/FuzzyChoquetIntegral.cpp" ...
+  "../../src/package_bgs/FuzzySugenoIntegral.cpp" ...
+  "../../src/package_bgs/T2F/T2FGMM.cpp" ...
+  "../../src/package_bgs/T2F/T2FMRF.cpp" ...
+  "../../src/package_bgs/T2F/MRF.cpp" ...
+  "../../src/package_bgs/T2F/FuzzyUtils.cpp" ...
+  "../../src/package_analysis/PixelUtils.cpp" ...
+  "../../src/package_bgs/MultiLayer.cpp" ...
+  "../../src/package_bgs/MultiLayer/CMultiLayerBGS.cpp" ...
+  "../../src/package_bgs/MultiLayer/LocalBinaryPattern.cpp" ...
+  "../../src/package_bgs/MultiLayer/BlobResult.cpp" ...
+  "../../src/package_bgs/MultiLayer/BlobExtraction.cpp" ...
+  "../../src/package_bgs/MultiLayer/blob.cpp" ...
+  "../../src/package_bgs/LBSimpleGaussian.cpp" ...
+  "../../src/package_bgs/LBFuzzyGaussian.cpp" ...
+  "../../src/package_bgs/LBMixtureOfGaussians.cpp" ...
+  "../../src/package_bgs/LBAdaptiveSOM.cpp" ...
+  "../../src/package_bgs/LBFuzzyAdaptiveSOM.cpp" ...
+  "../../src/package_bgs/lb/BGModel.cpp" ...
+  "../../src/package_bgs/lb/BGModelFuzzyGauss.cpp" ...
+  "../../src/package_bgs/lb/BGModelFuzzySom.cpp" ...
+  "../../src/package_bgs/lb/BGModelGauss.cpp" ...
+  "../../src/package_bgs/lb/BGModelMog.cpp" ...
+  "../../src/package_bgs/lb/BGModelSom.cpp" ...
+  "../../src/package_bgs/LBP_MRF.cpp" ...
+  "../../src/package_bgs/LBP_MRF/MotionDetection.cpp" ...
+  "../../src/package_bgs/LBP_MRF/MEImage.cpp" ...
+  "../../src/package_bgs/LBP_MRF/MEHistogram.cpp" ...
+  "../../src/package_bgs/LBP_MRF/MEDefs.cpp" ...
+  "../../src/package_bgs/LBP_MRF/maxflow.cpp" ...
+  "../../src/package_bgs/LBP_MRF/graph.cpp" ...
+  "../../src/package_bgs/PixelBasedAdaptiveSegmenter.cpp" ...
+  "../../src/package_bgs/PBAS/PBAS.cpp" ...
+  "../../src/package_bgs/VuMeter.cpp" ...
+  "../../src/package_bgs/VuMeter/TBackgroundVuMeter.cpp" ...
+  "../../src/package_bgs/VuMeter/TBackground.cpp" ...
+  "../../src/package_bgs/KDE.cpp" ...
+  "../../src/package_bgs/KDE/NPBGSubtractor.cpp" ...
+  "../../src/package_bgs/KDE/NPBGmodel.cpp" ...
+  "../../src/package_bgs/KDE/KernelTable.cpp" ...
+  "../../src/package_bgs/IndependentMultimodal.cpp" ...
+  "../../src/package_bgs/IMBS/IMBS.cpp" ...
+  "../../src/package_bgs/MultiCue.cpp" ...
+  "../../src/package_bgs/SigmaDelta.cpp" ...
+  "../../src/package_bgs/SigmaDelta/sdLaMa091.cpp" ...
+  "../../src/package_bgs/SuBSENSE.cpp" ...
+  "../../src/package_bgs/LOBSTER.cpp" ...
+  "../../src/package_bgs/PAWCS.cpp" ...
+  "../../src/package_bgs/LBSP/LBSP.cpp" ...
+  "../../src/package_bgs/LBSP/LBSP_.cpp" ...
+  "../../src/package_bgs/LBSP/BackgroundSubtractorLBSP.cpp" ...
+  "../../src/package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp" ...
+  "../../src/package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp" ...
+  "../../src/package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp" ...
+  "../../src/package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp" ...
+  "../../src/package_bgs/ViBe.cpp" ...
+  "../../src/package_bgs/ViBe/vibe-background-sequential.cpp" ...
+  "../../src/package_bgs/TwoPoints.cpp" ...
+  "../../src/package_bgs/TwoPoints/two_points.cpp" ...
+  "../../src/package_bgs/CodeBook.cpp"
diff --git a/demos/macosx/config/.gitignore b/wrapper/matlab/config/.gitignore
similarity index 83%
rename from demos/macosx/config/.gitignore
rename to wrapper/matlab/config/.gitignore
index 8ee04a0..4e2a98b 100644
--- a/demos/macosx/config/.gitignore
+++ b/wrapper/matlab/config/.gitignore
@@ -1,4 +1,4 @@
 # Ignore everything in this directory
 *
 # Except these files
-!.gitignore
\ No newline at end of file
+!.gitignore
diff --git a/wrapper_matlab/demo.m b/wrapper/matlab/demo.m
similarity index 62%
rename from wrapper_matlab/demo.m
rename to wrapper/matlab/demo.m
index 942e457..f40dc8a 100644
--- a/wrapper_matlab/demo.m
+++ b/wrapper/matlab/demo.m
@@ -1,21 +1,3 @@
-%{
-/*
- * This file is part of BGSLibrary.
- *
- * BGSLibrary is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * BGSLibrary is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
- */
-%}
 % Example:
 % demo('FrameDifference')
 % demo('StaticFrameDifference')
@@ -27,7 +9,7 @@ end
 
 % Create video reader object
 %filename = 'visiontraffic.avi';
-filename = '../dataset/demo.avi';
+filename = '../../dataset/demo.avi';
 hsrc = vision.VideoFileReader(filename, ...
                               'ImageColorSpace', 'RGB', ...
                               'VideoOutputDataType', 'uint8');
diff --git a/wrapper_matlab/mxarray.h b/wrapper/matlab/mxarray.h
similarity index 100%
rename from wrapper_matlab/mxarray.h
rename to wrapper/matlab/mxarray.h
diff --git a/wrapper_matlab/mxtypes.h b/wrapper/matlab/mxtypes.h
similarity index 100%
rename from wrapper_matlab/mxtypes.h
rename to wrapper/matlab/mxtypes.h
diff --git a/wrapper_matlab/opencvinterface.mlpkginstall b/wrapper/matlab/opencvinterface.mlpkginstall
similarity index 100%
rename from wrapper_matlab/opencvinterface.mlpkginstall
rename to wrapper/matlab/opencvinterface.mlpkginstall
diff --git a/wrapper_matlab/run_demo.m b/wrapper/matlab/run_demo.m
similarity index 100%
rename from wrapper_matlab/run_demo.m
rename to wrapper/matlab/run_demo.m
diff --git a/wrapper/python/bgslibrary_module.cpp b/wrapper/python/bgslibrary_module.cpp
new file mode 100644
index 0000000..5cf2f6e
--- /dev/null
+++ b/wrapper/python/bgslibrary_module.cpp
@@ -0,0 +1,309 @@
+#include <pybind11/pybind11.h>
+#include <exception>
+
+#include <opencv2/opencv.hpp>
+
+#include "ndarray_converter.h"
+#include "../../src/package_bgs/bgslibrary.h"
+
+#if CV_MAJOR_VERSION >= 4
+#define CV_LOAD_IMAGE_COLOR cv::IMREAD_COLOR
+#endif
+
+namespace py = pybind11;
+
+cv::Mat transpose_image(const cv::Mat& image)
+{
+  std::cerr << "Input size: " << image.size() << std::endl;
+  std::cerr << "Returning the image transpose" << std::endl;
+  return image.t();
+}
+
+void show_image(const cv::Mat& image)
+{
+  cv::imshow("Image", image);
+  cv::waitKey(0);
+}
+
+cv::Mat read_image(std::string image_name)
+{
+  cv::Mat image = cv::imread(image_name, CV_LOAD_IMAGE_COLOR);
+  return image;
+}
+
+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"));
+  m.def("transpose_image", &transpose_image, "A function that transpose an image", py::arg("image"));
+
+  py::class_<FrameDifference>(m, "FrameDifference")
+  .def(py::init<>())
+  .def("apply", &FrameDifference::apply)
+  .def("getBackgroundModel", &FrameDifference::getBackgroundModel)
+  ;
+
+  py::class_<StaticFrameDifference>(m, "StaticFrameDifference")
+    .def(py::init<>())
+    .def("apply", &StaticFrameDifference::apply)
+    .def("getBackgroundModel", &StaticFrameDifference::getBackgroundModel)
+    ;
+
+  py::class_<WeightedMovingMean>(m, "WeightedMovingMean")
+    .def(py::init<>())
+    .def("apply", &WeightedMovingMean::apply)
+    .def("getBackgroundModel", &WeightedMovingMean::getBackgroundModel)
+    ;
+
+  py::class_<WeightedMovingVariance>(m, "WeightedMovingVariance")
+    .def(py::init<>())
+    .def("apply", &WeightedMovingVariance::apply)
+    .def("getBackgroundModel", &WeightedMovingVariance::getBackgroundModel)
+    ;
+
+  py::class_<AdaptiveBackgroundLearning>(m, "AdaptiveBackgroundLearning")
+    .def(py::init<>())
+    .def("apply", &AdaptiveBackgroundLearning::apply)
+    .def("getBackgroundModel", &AdaptiveBackgroundLearning::getBackgroundModel)
+    ;
+
+  py::class_<AdaptiveSelectiveBackgroundLearning>(m, "AdaptiveSelectiveBackgroundLearning")
+    .def(py::init<>())
+    .def("apply", &AdaptiveSelectiveBackgroundLearning::apply)
+    .def("getBackgroundModel", &AdaptiveSelectiveBackgroundLearning::getBackgroundModel)
+    ;
+
+  py::class_<MixtureOfGaussianV2>(m, "MixtureOfGaussianV2")
+    .def(py::init<>())
+    .def("apply", &MixtureOfGaussianV2::apply)
+    .def("getBackgroundModel", &MixtureOfGaussianV2::getBackgroundModel)
+    ;
+
+#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
+  py::class_<MixtureOfGaussianV1>(m, "MixtureOfGaussianV1")
+    .def(py::init<>())
+    .def("apply", &MixtureOfGaussianV1::apply)
+    .def("getBackgroundModel", &MixtureOfGaussianV1::getBackgroundModel)
+    ;
+#endif
+
+#if CV_MAJOR_VERSION == 2
+  py::class_<GMG>(m, "GMG")
+    .def(py::init<>())
+    .def("apply", &GMG::apply)
+    .def("getBackgroundModel", &GMG::getBackgroundModel)
+    ;
+#endif
+
+#if CV_MAJOR_VERSION >= 3
+  py::class_<KNN>(m, "KNN")
+    .def(py::init<>())
+    .def("apply", &KNN::apply)
+    .def("getBackgroundModel", &KNN::getBackgroundModel)
+    ;
+#endif
+
+#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
+  py::class_<DPAdaptiveMedian>(m, "DPAdaptiveMedian")
+    .def(py::init<>())
+    .def("apply", &DPAdaptiveMedian::apply)
+    .def("getBackgroundModel", &DPAdaptiveMedian::getBackgroundModel)
+    ;
+
+  py::class_<DPGrimsonGMM>(m, "DPGrimsonGMM")
+    .def(py::init<>())
+    .def("apply", &DPGrimsonGMM::apply)
+    .def("getBackgroundModel", &DPGrimsonGMM::getBackgroundModel)
+    ;
+
+  py::class_<DPZivkovicAGMM>(m, "DPZivkovicAGMM")
+    .def(py::init<>())
+    .def("apply", &DPZivkovicAGMM::apply)
+    .def("getBackgroundModel", &DPZivkovicAGMM::getBackgroundModel)
+    ;
+
+  py::class_<DPMean>(m, "DPMean")
+    .def(py::init<>())
+    .def("apply", &DPMean::apply)
+    .def("getBackgroundModel", &DPMean::getBackgroundModel)
+    ;
+
+  py::class_<DPWrenGA>(m, "DPWrenGA")
+    .def(py::init<>())
+    .def("apply", &DPWrenGA::apply)
+    .def("getBackgroundModel", &DPWrenGA::getBackgroundModel)
+    ;
+
+  py::class_<DPPratiMediod>(m, "DPPratiMediod")
+    .def(py::init<>())
+    .def("apply", &DPPratiMediod::apply)
+    .def("getBackgroundModel", &DPPratiMediod::getBackgroundModel)
+    ;
+
+  py::class_<DPEigenbackground>(m, "DPEigenbackground")
+    .def(py::init<>())
+    .def("apply", &DPEigenbackground::apply)
+    .def("getBackgroundModel", &DPEigenbackground::getBackgroundModel)
+    ;
+
+  py::class_<DPTexture>(m, "DPTexture")
+    .def(py::init<>())
+    .def("apply", &DPTexture::apply)
+    .def("getBackgroundModel", &DPTexture::getBackgroundModel)
+    ;
+
+  py::class_<T2FGMM_UM>(m, "T2FGMM_UM")
+    .def(py::init<>())
+    .def("apply", &T2FGMM_UM::apply)
+    .def("getBackgroundModel", &T2FGMM_UM::getBackgroundModel)
+    ;
+
+  py::class_<T2FGMM_UV>(m, "T2FGMM_UV")
+    .def(py::init<>())
+    .def("apply", &T2FGMM_UV::apply)
+    .def("getBackgroundModel", &T2FGMM_UV::getBackgroundModel)
+    ;
+
+  py::class_<T2FMRF_UM>(m, "T2FMRF_UM")
+    .def(py::init<>())
+    .def("apply", &T2FMRF_UM::apply)
+    .def("getBackgroundModel", &T2FMRF_UM::getBackgroundModel)
+    ;
+
+  py::class_<T2FMRF_UV>(m, "T2FMRF_UV")
+    .def(py::init<>())
+    .def("apply", &T2FMRF_UV::apply)
+    .def("getBackgroundModel", &T2FMRF_UV::getBackgroundModel)
+    ;
+
+  py::class_<FuzzySugenoIntegral>(m, "FuzzySugenoIntegral")
+    .def(py::init<>())
+    .def("apply", &FuzzySugenoIntegral::apply)
+    .def("getBackgroundModel", &FuzzySugenoIntegral::getBackgroundModel)
+    ;
+
+  py::class_<FuzzyChoquetIntegral>(m, "FuzzyChoquetIntegral")
+    .def(py::init<>())
+    .def("apply", &FuzzyChoquetIntegral::apply)
+    .def("getBackgroundModel", &FuzzyChoquetIntegral::getBackgroundModel)
+    ;
+
+  py::class_<LBSimpleGaussian>(m, "LBSimpleGaussian")
+    .def(py::init<>())
+    .def("apply", &LBSimpleGaussian::apply)
+    .def("getBackgroundModel", &LBSimpleGaussian::getBackgroundModel)
+    ;
+
+  py::class_<LBFuzzyGaussian>(m, "LBFuzzyGaussian")
+    .def(py::init<>())
+    .def("apply", &LBFuzzyGaussian::apply)
+    .def("getBackgroundModel", &LBFuzzyGaussian::getBackgroundModel)
+    ;
+
+  py::class_<LBMixtureOfGaussians>(m, "LBMixtureOfGaussians")
+    .def(py::init<>())
+    .def("apply", &LBMixtureOfGaussians::apply)
+    .def("getBackgroundModel", &LBMixtureOfGaussians::getBackgroundModel)
+    ;
+
+  py::class_<LBAdaptiveSOM>(m, "LBAdaptiveSOM")
+    .def(py::init<>())
+    .def("apply", &LBAdaptiveSOM::apply)
+    .def("getBackgroundModel", &LBAdaptiveSOM::getBackgroundModel)
+    ;
+
+  py::class_<LBFuzzyAdaptiveSOM>(m, "LBFuzzyAdaptiveSOM")
+    .def(py::init<>())
+    .def("apply", &LBFuzzyAdaptiveSOM::apply)
+    .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)
+    .def("getBackgroundModel", &VuMeter::getBackgroundModel)
+    ;
+
+  py::class_<KDE>(m, "KDE")
+    .def(py::init<>())
+    .def("apply", &KDE::apply)
+    .def("getBackgroundModel", &KDE::getBackgroundModel)
+    ;
+
+  py::class_<IndependentMultimodal>(m, "IndependentMultimodal")
+    .def(py::init<>())
+    .def("apply", &IndependentMultimodal::apply)
+    .def("getBackgroundModel", &IndependentMultimodal::getBackgroundModel)
+    ;
+
+  py::class_<MultiCue>(m, "MultiCue")
+    .def(py::init<>())
+    .def("apply", &MultiCue::apply)
+    .def("getBackgroundModel", &MultiCue::getBackgroundModel)
+    ;
+#endif
+
+  py::class_<SigmaDelta>(m, "SigmaDelta")
+    .def(py::init<>())
+    .def("apply", &SigmaDelta::apply)
+    .def("getBackgroundModel", &SigmaDelta::getBackgroundModel)
+    ;
+
+  py::class_<SuBSENSE>(m, "SuBSENSE")
+    .def(py::init<>())
+    .def("apply", &SuBSENSE::apply)
+    .def("getBackgroundModel", &SuBSENSE::getBackgroundModel)
+    ;
+
+  py::class_<LOBSTER>(m, "LOBSTER")
+    .def(py::init<>())
+    .def("apply", &LOBSTER::apply)
+    .def("getBackgroundModel", &LOBSTER::getBackgroundModel)
+    ;
+
+  py::class_<PAWCS>(m, "PAWCS")
+    .def(py::init<>())
+    .def("apply", &PAWCS::apply)
+    .def("getBackgroundModel", &PAWCS::getBackgroundModel)
+    ;
+
+  py::class_<TwoPoints>(m, "TwoPoints")
+    .def(py::init<>())
+    .def("apply", &TwoPoints::apply)
+    .def("getBackgroundModel", &TwoPoints::getBackgroundModel)
+    ;
+
+  py::class_<ViBe>(m, "ViBe")
+    .def(py::init<>())
+    .def("apply", &ViBe::apply)
+    .def("getBackgroundModel", &ViBe::getBackgroundModel)
+    ;
+
+  py::class_<CodeBook>(m, "CodeBook")
+    .def(py::init<>())
+    .def("apply", &CodeBook::apply)
+    .def("getBackgroundModel", &CodeBook::getBackgroundModel)
+    ;
+}
diff --git a/wrapper_python/ndarray_converter.cpp b/wrapper/python/ndarray_converter.cpp
similarity index 96%
rename from wrapper_python/ndarray_converter.cpp
rename to wrapper/python/ndarray_converter.cpp
index 3b95a72..e229c6f 100644
--- a/wrapper_python/ndarray_converter.cpp
+++ b/wrapper/python/ndarray_converter.cpp
@@ -1,6 +1,3 @@
-// borrowed in spirit from https://github.com/yati-sagade/opencv-ndarray-conversion
-// MIT License
-
 #include "ndarray_converter.h"
 
 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@@ -102,7 +99,11 @@ public:
         return u;
     }
 
+#if CV_MAJOR_VERSION < 4
     UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const
+#else
+    UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const
+#endif
     {
         if( data != 0 )
         {
@@ -131,7 +132,11 @@ public:
         return allocate(o, dims0, sizes, type, step);
     }
 
+#if CV_MAJOR_VERSION < 4
     bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const
+#else
+    bool allocate(UMatData* u, AccessFlag accessFlags, UMatUsageFlags usageFlags) const
+#endif
     {
         return stdAllocator->allocate(u, accessFlags, usageFlags);
     }
diff --git a/wrapper_python/ndarray_converter.h b/wrapper/python/ndarray_converter.h
similarity index 99%
rename from wrapper_python/ndarray_converter.h
rename to wrapper/python/ndarray_converter.h
index da5ea16..2a1dc5a 100644
--- a/wrapper_python/ndarray_converter.h
+++ b/wrapper/python/ndarray_converter.h
@@ -4,7 +4,6 @@
 #include <Python.h>
 #include <opencv2/core/core.hpp>
 
-
 class NDArrayConverter {
 public:
     // must call this first, or the other routines don't work!
diff --git a/wrapper_matlab/compile.m b/wrapper_matlab/compile.m
deleted file mode 100644
index 36ddf84..0000000
--- a/wrapper_matlab/compile.m
+++ /dev/null
@@ -1,95 +0,0 @@
-%% Compile
-clc;
-mexOpenCV -v -DMEX_COMPILE_FLAG -I"../package_bgs" backgroundSubtractor_wrapper.cpp ...
-  "../package_bgs/FrameDifference.cpp" ...
-  "../package_bgs/StaticFrameDifference.cpp" ...
-  "../package_bgs/WeightedMovingMean.cpp" ...
-  "../package_bgs/WeightedMovingVariance.cpp" ...
-  "../package_bgs/MixtureOfGaussianV1.cpp" ...
-  "../package_bgs/MixtureOfGaussianV2.cpp" ...
-  "../package_bgs/AdaptiveBackgroundLearning.cpp" ...
-  "../package_bgs/AdaptiveSelectiveBackgroundLearning.cpp" ...
-  "../package_bgs/GMG.cpp" ...
-  "../package_bgs/KNN.cpp" ...
-  "../package_bgs/DPAdaptiveMedian.cpp" ...
-  "../package_bgs/DPGrimsonGMM.cpp" ...
-  "../package_bgs/DPZivkovicAGMM.cpp" ...
-  "../package_bgs/DPMean.cpp" ...
-  "../package_bgs/DPWrenGA.cpp" ...
-  "../package_bgs/DPPratiMediod.cpp" ...
-  "../package_bgs/DPEigenbackground.cpp" ...
-  "../package_bgs/DPTexture.cpp" ...
-  "../package_bgs/dp/AdaptiveMedianBGS.cpp" ...
-  "../package_bgs/dp/Image.cpp" ...
-  "../package_bgs/dp/Error.cpp" ...
-  "../package_bgs/dp/GrimsonGMM.cpp" ...
-  "../package_bgs/dp/ZivkovicAGMM.cpp" ...
-  "../package_bgs/dp/MeanBGS.cpp" ...
-  "../package_bgs/dp/WrenGA.cpp"  ...
-  "../package_bgs/dp/PratiMediodBGS.cpp" ...
-  "../package_bgs/dp/Eigenbackground.cpp" ...
-  "../package_bgs/dp/TextureBGS.cpp" ...
-  "../package_bgs/T2FGMM_UM.cpp" ...
-  "../package_bgs/T2FGMM_UV.cpp" ...
-  "../package_bgs/T2FMRF_UM.cpp" ...
-  "../package_bgs/T2FMRF_UV.cpp" ...
-  "../package_bgs/FuzzyChoquetIntegral.cpp" ...
-  "../package_bgs/FuzzySugenoIntegral.cpp" ...
-  "../package_bgs/T2F/T2FGMM.cpp" ...
-  "../package_bgs/T2F/T2FMRF.cpp" ...
-  "../package_bgs/T2F/MRF.cpp" ...
-  "../package_bgs/T2F/FuzzyUtils.cpp" ...
-  "../package_analysis/PixelUtils.cpp" ...
-  "../package_bgs/MultiLayer.cpp" ...
-  "../package_bgs/MultiLayer/CMultiLayerBGS.cpp" ...
-  "../package_bgs/MultiLayer/LocalBinaryPattern.cpp" ...
-  "../package_bgs/MultiLayer/BlobResult.cpp" ...
-  "../package_bgs/MultiLayer/BlobExtraction.cpp" ...
-  "../package_bgs/MultiLayer/blob.cpp" ...
-  "../package_bgs/LBSimpleGaussian.cpp" ...
-  "../package_bgs/LBFuzzyGaussian.cpp" ...
-  "../package_bgs/LBMixtureOfGaussians.cpp" ...
-  "../package_bgs/LBAdaptiveSOM.cpp" ...
-  "../package_bgs/LBFuzzyAdaptiveSOM.cpp" ...
-  "../package_bgs/lb/BGModel.cpp" ...
-  "../package_bgs/lb/BGModelFuzzyGauss.cpp" ...
-  "../package_bgs/lb/BGModelFuzzySom.cpp" ...
-  "../package_bgs/lb/BGModelGauss.cpp" ...
-  "../package_bgs/lb/BGModelMog.cpp" ...
-  "../package_bgs/lb/BGModelSom.cpp" ...
-  "../package_bgs/LBP_MRF.cpp" ...
-  "../package_bgs/LBP_MRF/MotionDetection.cpp" ...
-  "../package_bgs/LBP_MRF/MEImage.cpp" ...
-  "../package_bgs/LBP_MRF/MEHistogram.cpp" ...
-  "../package_bgs/LBP_MRF/MEDefs.cpp" ...
-  "../package_bgs/LBP_MRF/maxflow.cpp" ...
-  "../package_bgs/LBP_MRF/graph.cpp" ...
-  "../package_bgs/PixelBasedAdaptiveSegmenter.cpp" ...
-  "../package_bgs/PBAS/PBAS.cpp" ...
-  "../package_bgs/VuMeter.cpp" ...
-  "../package_bgs/VuMeter/TBackgroundVuMeter.cpp" ...
-  "../package_bgs/VuMeter/TBackground.cpp" ...
-  "../package_bgs/KDE.cpp" ...
-  "../package_bgs/KDE/NPBGSubtractor.cpp" ...
-  "../package_bgs/KDE/NPBGmodel.cpp" ...
-  "../package_bgs/KDE/KernelTable.cpp" ...
-  "../package_bgs/IndependentMultimodal.cpp" ...
-  "../package_bgs/IMBS/IMBS.cpp" ...
-  "../package_bgs/MultiCue.cpp" ...
-  "../package_bgs/SigmaDelta.cpp" ...
-  "../package_bgs/SigmaDelta/sdLaMa091.cpp" ...
-  "../package_bgs/SuBSENSE.cpp" ...
-  "../package_bgs/LOBSTER.cpp" ...
-  "../package_bgs/PAWCS.cpp" ...
-  "../package_bgs/LBSP/LBSP.cpp" ...
-  "../package_bgs/LBSP/LBSP_.cpp" ...
-  "../package_bgs/LBSP/BackgroundSubtractorLBSP.cpp" ...
-  "../package_bgs/LBSP/BackgroundSubtractorLBSP_.cpp" ...
-  "../package_bgs/LBSP/BackgroundSubtractorLOBSTER.cpp" ...
-  "../package_bgs/LBSP/BackgroundSubtractorPAWCS.cpp" ...
-  "../package_bgs/LBSP/BackgroundSubtractorSuBSENSE.cpp" ...
-  "../package_bgs/ViBe.cpp" ...
-  "../package_bgs/ViBe/vibe-background-sequential.cpp" ...
-  "../package_bgs/TwoPoints.cpp" ...
-  "../package_bgs/TwoPoints/two_points.cpp" ...
-  "../package_bgs/CodeBook.cpp"
diff --git a/wrapper_python/bgslibrary_module.cpp b/wrapper_python/bgslibrary_module.cpp
deleted file mode 100644
index ef09aae..0000000
--- a/wrapper_python/bgslibrary_module.cpp
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
-This file is part of BGSLibrary.
-
-BGSLibrary is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-BGSLibrary is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include <pybind11/pybind11.h>
-#include <exception>
-
-#include <opencv2/opencv.hpp>
-
-#include "ndarray_converter.h"
-#include "../package_bgs/bgslibrary.h"
-
-namespace py = pybind11;
-
-cv::Mat transpose_image(const cv::Mat& image)
-{
-	std::cerr << "Input size: " << image.size() << std::endl;
-	std::cerr << "Returning the image transpose" << std::endl;
-	return image.t();
-}
-
-void show_image(const cv::Mat& image)
-{
-	cv::imshow("Image", image);
-	cv::waitKey(0);
-}
-
-cv::Mat read_image(std::string image_name)
-{
-	cv::Mat image = cv::imread(image_name, CV_LOAD_IMAGE_COLOR);
-	return image;
-}
-
-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"));
-	m.def("transpose_image", &transpose_image, "A function that transpose an image", py::arg("image"));
-
-	py::class_<FrameDifference>(m, "FrameDifference")
-	.def(py::init<>())
-	.def("apply", &FrameDifference::apply)
-	.def("getBackgroundModel", &FrameDifference::getBackgroundModel)
-	;
-
-	py::class_<StaticFrameDifference>(m, "StaticFrameDifference")
-    .def(py::init<>())
-		.def("apply", &StaticFrameDifference::apply)
-		.def("getBackgroundModel", &StaticFrameDifference::getBackgroundModel)
-		;
-
-	py::class_<AdaptiveBackgroundLearning>(m, "AdaptiveBackgroundLearning")
-    .def(py::init<>())
-		.def("apply", &AdaptiveBackgroundLearning::apply)
-		.def("getBackgroundModel", &AdaptiveBackgroundLearning::getBackgroundModel)
-		;
-
-	py::class_<AdaptiveSelectiveBackgroundLearning>(m, "AdaptiveSelectiveBackgroundLearning")
-    .def(py::init<>())
-		.def("apply", &AdaptiveSelectiveBackgroundLearning::apply)
-		.def("getBackgroundModel", &AdaptiveSelectiveBackgroundLearning::getBackgroundModel)
-		;
-
-	py::class_<DPAdaptiveMedian>(m, "DPAdaptiveMedian")
-    .def(py::init<>())
-		.def("apply", &DPAdaptiveMedian::apply)
-		.def("getBackgroundModel", &DPAdaptiveMedian::getBackgroundModel)
-		;
-
-	py::class_<DPEigenbackground>(m, "DPEigenbackground")
-    .def(py::init<>())
-		.def("apply", &DPEigenbackground::apply)
-		.def("getBackgroundModel", &DPEigenbackground::getBackgroundModel)
-		;
-
-	py::class_<DPGrimsonGMM>(m, "DPGrimsonGMM")
-    .def(py::init<>())
-		.def("apply", &DPGrimsonGMM::apply)
-		.def("getBackgroundModel", &DPGrimsonGMM::getBackgroundModel)
-		;
-
-	py::class_<DPMean>(m, "DPMean")
-    .def(py::init<>())
-		.def("apply", &DPMean::apply)
-		.def("getBackgroundModel", &DPMean::getBackgroundModel)
-		;
-
-	py::class_<DPPratiMediod>(m, "DPPratiMediod")
-    .def(py::init<>())
-		.def("apply", &DPPratiMediod::apply)
-		.def("getBackgroundModel", &DPPratiMediod::getBackgroundModel)
-		;
-
-	py::class_<DPTexture>(m, "DPTexture")
-    .def(py::init<>())
-		.def("apply", &DPTexture::apply)
-		.def("getBackgroundModel", &DPTexture::getBackgroundModel)
-		;
-
-	py::class_<DPWrenGA>(m, "DPWrenGA")
-    .def(py::init<>())
-		.def("apply", &DPWrenGA::apply)
-		.def("getBackgroundModel", &DPWrenGA::getBackgroundModel)
-		;
-
-	py::class_<DPZivkovicAGMM>(m, "DPZivkovicAGMM")
-    .def(py::init<>())
-		.def("apply", &DPZivkovicAGMM::apply)
-		.def("getBackgroundModel", &DPZivkovicAGMM::getBackgroundModel)
-		;
-
-	py::class_<FuzzyChoquetIntegral>(m, "FuzzyChoquetIntegral")
-    .def(py::init<>())
-		.def("apply", &FuzzyChoquetIntegral::apply)
-		.def("getBackgroundModel", &FuzzyChoquetIntegral::getBackgroundModel)
-		;
-
-	py::class_<FuzzySugenoIntegral>(m, "FuzzySugenoIntegral")
-    .def(py::init<>())
-		.def("apply", &FuzzySugenoIntegral::apply)
-		.def("getBackgroundModel", &FuzzySugenoIntegral::getBackgroundModel)
-		;
-
-#if CV_MAJOR_VERSION == 2
-	py::class_<GMG>(m, "GMG")
-    .def(py::init<>())
-		.def("apply", &GMG::apply)
-		.def("getBackgroundModel", &GMG::getBackgroundModel)
-		;
-#endif
-
-	py::class_<IndependentMultimodal>(m, "IndependentMultimodal")
-    .def(py::init<>())
-		.def("apply", &IndependentMultimodal::apply)
-		.def("getBackgroundModel", &IndependentMultimodal::getBackgroundModel)
-		;
-
-	py::class_<KDE>(m, "KDE")
-    .def(py::init<>())
-		.def("apply", &KDE::apply)
-		.def("getBackgroundModel", &KDE::getBackgroundModel)
-		;
-
-#if CV_MAJOR_VERSION >= 3
-	py::class_<KNN>(m, "KNN")
-    .def(py::init<>())
-		.def("apply", &KNN::apply)
-		.def("getBackgroundModel", &KNN::getBackgroundModel)
-		;
-#endif
-
-	py::class_<LBAdaptiveSOM>(m, "LBAdaptiveSOM")
-    .def(py::init<>())
-		.def("apply", &LBAdaptiveSOM::apply)
-		.def("getBackgroundModel", &LBAdaptiveSOM::getBackgroundModel)
-		;
-
-	py::class_<LBFuzzyAdaptiveSOM>(m, "LBFuzzyAdaptiveSOM")
-    .def(py::init<>())
-		.def("apply", &LBFuzzyAdaptiveSOM::apply)
-		.def("getBackgroundModel", &LBFuzzyAdaptiveSOM::getBackgroundModel)
-		;
-
-	py::class_<LBFuzzyGaussian>(m, "LBFuzzyGaussian")
-    .def(py::init<>())
-		.def("apply", &LBFuzzyGaussian::apply)
-		.def("getBackgroundModel", &LBFuzzyGaussian::getBackgroundModel)
-		;
-
-	py::class_<LBMixtureOfGaussians>(m, "LBMixtureOfGaussians")
-    .def(py::init<>())
-		.def("apply", &LBMixtureOfGaussians::apply)
-		.def("getBackgroundModel", &LBMixtureOfGaussians::getBackgroundModel)
-		;
-
-	py::class_<LBSimpleGaussian>(m, "LBSimpleGaussian")
-    .def(py::init<>())
-		.def("apply", &LBSimpleGaussian::apply)
-		.def("getBackgroundModel", &LBSimpleGaussian::getBackgroundModel)
-		;
-
-	py::class_<LBP_MRF>(m, "LBP_MRF")
-    .def(py::init<>())
-		.def("apply", &LBP_MRF::apply)
-		.def("getBackgroundModel", &LBP_MRF::getBackgroundModel)
-		;
-
-	py::class_<LOBSTER>(m, "LOBSTER")
-    .def(py::init<>())
-		.def("apply", &LOBSTER::apply)
-		.def("getBackgroundModel", &LOBSTER::getBackgroundModel)
-		;
-
-#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
-	py::class_<MixtureOfGaussianV1>(m, "MixtureOfGaussianV1")
-    .def(py::init<>())
-		.def("apply", &MixtureOfGaussianV1::apply)
-		.def("getBackgroundModel", &MixtureOfGaussianV1::getBackgroundModel)
-		;
-#endif
-
-	py::class_<MixtureOfGaussianV2>(m, "MixtureOfGaussianV2")
-    .def(py::init<>())
-		.def("apply", &MixtureOfGaussianV2::apply)
-		.def("getBackgroundModel", &MixtureOfGaussianV2::getBackgroundModel)
-		;
-
-	py::class_<MultiCue>(m, "MultiCue")
-    .def(py::init<>())
-		.def("apply", &MultiCue::apply)
-		.def("getBackgroundModel", &MultiCue::getBackgroundModel)
-		;
-
-	py::class_<MultiLayer>(m, "MultiLayer")
-    .def(py::init<>())
-		.def("apply", &MultiLayer::apply)
-		.def("getBackgroundModel", &MultiLayer::getBackgroundModel)
-		;
-
-	py::class_<PAWCS>(m, "PAWCS")
-    .def(py::init<>())
-		.def("apply", &PAWCS::apply)
-		.def("getBackgroundModel", &PAWCS::getBackgroundModel)
-		;
-
-	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)
-		.def("getBackgroundModel", &SigmaDelta::getBackgroundModel)
-		;
-
-	py::class_<SuBSENSE>(m, "SuBSENSE")
-    .def(py::init<>())
-		.def("apply", &SuBSENSE::apply)
-		.def("getBackgroundModel", &SuBSENSE::getBackgroundModel)
-		;
-
-	py::class_<T2FGMM_UM>(m, "T2FGMM_UM")
-    .def(py::init<>())
-		.def("apply", &T2FGMM_UM::apply)
-		.def("getBackgroundModel", &T2FGMM_UM::getBackgroundModel)
-		;
-
-	py::class_<T2FGMM_UV>(m, "T2FGMM_UV")
-    .def(py::init<>())
-		.def("apply", &T2FGMM_UV::apply)
-		.def("getBackgroundModel", &T2FGMM_UV::getBackgroundModel)
-		;
-
-	py::class_<T2FMRF_UM>(m, "T2FMRF_UM")
-    .def(py::init<>())
-		.def("apply", &T2FMRF_UM::apply)
-		.def("getBackgroundModel", &T2FMRF_UM::getBackgroundModel)
-		;
-
-	py::class_<T2FMRF_UV>(m, "T2FMRF_UV")
-    .def(py::init<>())
-		.def("apply", &T2FMRF_UV::apply)
-		.def("getBackgroundModel", &T2FMRF_UV::getBackgroundModel)
-		;
-
-	py::class_<VuMeter>(m, "VuMeter")
-    .def(py::init<>())
-		.def("apply", &VuMeter::apply)
-		.def("getBackgroundModel", &VuMeter::getBackgroundModel)
-		;
-
-	py::class_<WeightedMovingMean>(m, "WeightedMovingMean")
-    .def(py::init<>())
-		.def("apply", &WeightedMovingMean::apply)
-		.def("getBackgroundModel", &WeightedMovingMean::getBackgroundModel)
-		;
-
-	py::class_<WeightedMovingVariance>(m, "WeightedMovingVariance")
-    .def(py::init<>())
-		.def("apply", &WeightedMovingVariance::apply)
-		.def("getBackgroundModel", &WeightedMovingVariance::getBackgroundModel)
-		;
-
-	py::class_<TwoPoints>(m, "TwoPoints")
-    .def(py::init<>())
-		.def("apply", &TwoPoints::apply)
-		.def("getBackgroundModel", &TwoPoints::getBackgroundModel)
-		;
-
-	py::class_<ViBe>(m, "ViBe")
-    .def(py::init<>())
-		.def("apply", &ViBe::apply)
-		.def("getBackgroundModel", &ViBe::getBackgroundModel)
-		;
-
-	py::class_<CodeBook>(m, "CodeBook")
-    .def(py::init<>())
-		.def("apply", &CodeBook::apply)
-		.def("getBackgroundModel", &CodeBook::getBackgroundModel)
-		;
-}
-- 
GitLab