Skip to content

Commit

Permalink
BGSLibrary 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewssobral committed Mar 18, 2017
1 parent 60f37c7 commit d27d1e2
Show file tree
Hide file tree
Showing 551 changed files with 27,350 additions and 21,312 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
etc/
build_*/
binaries/
dataset_*/
binaries*/
java_gui/dist/
java_gui/build/
java_gui/bgslibrary.exe
Expand All @@ -9,4 +10,5 @@ qt_gui/
fet/etc/
*.exe
*.pdb
*.suo
*.suo
*.dll
103 changes: 78 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,44 @@ cmake_minimum_required(VERSION 2.8)

project(bgslibrary)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
# cmake -D BGS_PYTHON_SUPPORT=ON ..
if(NOT DEFINED BGS_PYTHON_SUPPORT)
set(BGS_PYTHON_SUPPORT OFF)
elseif()
# add_definitions(-DBGS_PYTHON_SUPPORT)
endif()
message(STATUS "BGSLIBRARY WITH PYTHON SUPPORT: ${BGS_PYTHON_SUPPORT}")

if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
endif(UNIX)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)

set( bgs_out_dir "." )
# compilation mode setup
set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_BUILD_TYPE Debug)

if(WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
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} )
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)
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)

Expand All @@ -30,42 +50,75 @@ IF(UNIX)
#ADD_DEFINITIONS(-Wconversion -Wfloat-equal)
endif(UNIX)

set(OpenCV_STATIC OFF)
find_package(OpenCV REQUIRED)

message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

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_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 sources FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp)
file(GLOB main Main.cpp)
if(BGS_PYTHON_SUPPORT)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost REQUIRED COMPONENTS python)
find_package(PythonLibs REQUIRED)

message(STATUS "Boost library status:")
message(STATUS " version: ${Boost_VERSION}")
message(STATUS " libraries: ${Boost_LIBRARIES}")
message(STATUS " include path: ${Boost_INCLUDE_DIRS}")

message(STATUS "Python library status:")
message(STATUS " version: ${PYTHON_VERSION}")
message(STATUS " libraries: ${PYTHON_LIBRARIES}")
message(STATUS " include path: ${PYTHON_INCLUDE_DIRS}")
endif()

#file(GLOB sources FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp)
file(GLOB main Main.cpp FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp VideoCapture.cpp)
file(GLOB demo Demo.cpp)
file(GLOB demo2 Demo2.cpp)

# list(REMOVE_ITEM sources ${demo} ${demo2})

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)
if(BGS_PYTHON_SUPPORT)
file(GLOB_RECURSE bgs_src package_bgs/*.cpp package_bgs/*.c wrapper_python/*.cpp)
file(GLOB_RECURSE bgs_include package_bgs/*.h wrapper_python/*.h)
include_directories(${CMAKE_SOURCE_DIR} ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
else()
file(GLOB_RECURSE bgs_src package_bgs/*.cpp package_bgs/*.c)
file(GLOB_RECURSE bgs_include package_bgs/*.h)
include_directories(${CMAKE_SOURCE_DIR} ${OpenCV_INCLUDE_DIRS})
endif()

# GMG is not available in older OpenCV versions
if(${OpenCV_VERSION} VERSION_LESS 2.4.3)
file(GLOB gmg package_bgs/GMG.cpp)
list(REMOVE_ITEM bgs_src ${gmg})
endif()

include_directories(${CMAKE_SOURCE_DIR})

add_library(libbgs STATIC ${sources} ${bgs_src} ${analysis_src})
target_link_libraries(libbgs ${OpenCV_LIBS})
if(BGS_PYTHON_SUPPORT)
#add_library(libbgs SHARED ${sources} ${bgs_src} ${analysis_src})
add_library(libbgs SHARED ${bgs_src} ${analysis_src})
target_link_libraries(libbgs ${OpenCV_LIBS} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_compile_definitions(libbgs PRIVATE BGS_PYTHON_SUPPORT=1)
else()
#add_library(libbgs STATIC ${sources} ${bgs_src} ${analysis_src})
add_library(libbgs STATIC ${bgs_src} ${analysis_src})
target_link_libraries(libbgs ${OpenCV_LIBS})
endif()
set_property(TARGET libbgs PROPERTY PUBLIC_HEADER ${bgs_include})
if(WIN32)
# set_property(TARGET libbgs PROPERTY SUFFIX ".lib")
Expand All @@ -83,7 +136,7 @@ target_link_libraries(bgs_demo ${OpenCV_LIBS} libbgs)
add_executable(bgs_demo2 ${demo2})
target_link_libraries(bgs_demo2 ${OpenCV_LIBS} libbgs)

INSTALL(TARGETS libbgs
install(TARGETS libbgs
bgslibrary
RUNTIME DESTINATION bin COMPONENT app
LIBRARY DESTINATION lib COMPONENT runtime
Expand Down
158 changes: 39 additions & 119 deletions Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,178 +17,98 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include <opencv2/opencv.hpp>


#include "package_bgs/FrameDifferenceBGS.h"
#include "package_bgs/StaticFrameDifferenceBGS.h"
#include "package_bgs/WeightedMovingMeanBGS.h"
#include "package_bgs/WeightedMovingVarianceBGS.h"
#include "package_bgs/MixtureOfGaussianV1BGS.h"
#include "package_bgs/MixtureOfGaussianV2BGS.h"
#include "package_bgs/AdaptiveBackgroundLearning.h"
#include "package_bgs/AdaptiveSelectiveBackgroundLearning.h"

#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
#include "package_bgs/GMG.h"
#endif

#include "package_bgs/dp/DPAdaptiveMedianBGS.h"
#include "package_bgs/dp/DPGrimsonGMMBGS.h"
#include "package_bgs/dp/DPZivkovicAGMMBGS.h"
#include "package_bgs/dp/DPMeanBGS.h"
#include "package_bgs/dp/DPWrenGABGS.h"
#include "package_bgs/dp/DPPratiMediodBGS.h"
#include "package_bgs/dp/DPEigenbackgroundBGS.h"
#include "package_bgs/dp/DPTextureBGS.h"

#include "package_bgs/tb/T2FGMM_UM.h"
#include "package_bgs/tb/T2FGMM_UV.h"
#include "package_bgs/tb/T2FMRF_UM.h"
#include "package_bgs/tb/T2FMRF_UV.h"
#include "package_bgs/tb/FuzzySugenoIntegral.h"
#include "package_bgs/tb/FuzzyChoquetIntegral.h"

#include "package_bgs/lb/LBSimpleGaussian.h"
#include "package_bgs/lb/LBFuzzyGaussian.h"
#include "package_bgs/lb/LBMixtureOfGaussians.h"
#include "package_bgs/lb/LBAdaptiveSOM.h"
#include "package_bgs/lb/LBFuzzyAdaptiveSOM.h"

#include "package_bgs/ck/LbpMrf.h"
#include "package_bgs/jmo/MultiLayerBGS.h"
// The PBAS algorithm was removed from BGSLibrary because it is
// based on patented algorithm ViBE
// http://www2.ulg.ac.be/telecom/research/vibe/
//#include "package_bgs/pt/PixelBasedAdaptiveSegmenter.h"
#include "package_bgs/av/VuMeter.h"
#include "package_bgs/ae/KDE.h"
#include "package_bgs/db/IndependentMultimodalBGS.h"
#include "package_bgs/sjn/SJN_MultiCueBGS.h"
#include "package_bgs/bl/SigmaDeltaBGS.h"

#include "package_bgs/pl/SuBSENSE.h"
#include "package_bgs/pl/LOBSTER.h"
#include "package_bgs/bgslibrary.h"

int main(int argc, char **argv)
{
std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;

CvCapture *capture = 0;
int resize_factor = 100;
VideoCapture capture;

if(argc > 1)
if (argc > 1)
{
std::cout << "Openning: " << argv[1] << std::endl;
capture = cvCaptureFromAVI(argv[1]);
capture.open(argv[1]);
}
else
{
capture = cvCaptureFromCAM(0);
resize_factor = 50; // set size = 50% of original image
}
capture.open(0);

if(!capture)
if (!capture.isOpened())
{
std::cerr << "Cannot initialize video!" << std::endl;
return -1;
}

IplImage *frame_aux = cvQueryFrame(capture);
IplImage *frame = cvCreateImage(cvSize((int)((frame_aux->width*resize_factor)/100) , (int)((frame_aux->height*resize_factor)/100)), frame_aux->depth, frame_aux->nChannels);
cvResize(frame_aux, frame);

/* Background Subtraction Methods */
IBGS *bgs;

/*** Default Package ***/
bgs = new FrameDifferenceBGS;
//bgs = new StaticFrameDifferenceBGS;
//bgs = new WeightedMovingMeanBGS;
//bgs = new WeightedMovingVarianceBGS;
//bgs = new MixtureOfGaussianV1BGS;
//bgs = new MixtureOfGaussianV2BGS;
bgs = new FrameDifference;
//bgs = new StaticFrameDifference;
//bgs = new WeightedMovingMean;
//bgs = new WeightedMovingVariance;
//bgs = new MixtureOfGaussianV1; // only on OpenCV 2.x
//bgs = new MixtureOfGaussianV2;
//bgs = new AdaptiveBackgroundLearning;
//bgs = new AdaptiveSelectiveBackgroundLearning;
//bgs = new GMG;

/*** DP Package (thanks to Donovan Parks) ***/
//bgs = new DPAdaptiveMedianBGS;
//bgs = new DPGrimsonGMMBGS;
//bgs = new DPZivkovicAGMMBGS;
//bgs = new DPMeanBGS;
//bgs = new DPWrenGABGS;
//bgs = new DPPratiMediodBGS;
//bgs = new DPEigenbackgroundBGS;
//bgs = new DPTextureBGS;

/*** TB Package (thanks to Thierry Bouwmans, Fida EL BAF and Zhenjie Zhao) ***/
//bgs = new GMG; // only on OpenCV 2.x
//bgs = new KNN; // only on OpenCV 3.x
//bgs = new DPAdaptiveMedian;
//bgs = new DPGrimsonGMM;
//bgs = new DPZivkovicAGMM;
//bgs = new DPMean;
//bgs = new DPWrenGA;
//bgs = new DPPratiMediod;
//bgs = new DPEigenbackground;
//bgs = new DPTexture;
//bgs = new T2FGMM_UM;
//bgs = new T2FGMM_UV;
//bgs = new T2FMRF_UM;
//bgs = new T2FMRF_UV;
//bgs = new FuzzySugenoIntegral;
//bgs = new FuzzyChoquetIntegral;

/*** JMO Package (thanks to Jean-Marc Odobez) ***/
//bgs = new MultiLayerBGS;

/*** PT Package (thanks to Martin Hofmann, Philipp Tiefenbacher and Gerhard Rigoll) ***/
//bgs = new MultiLayer;
//bgs = new PixelBasedAdaptiveSegmenter;

/*** LB Package (thanks to Laurence Bender) ***/
//bgs = new LBSimpleGaussian;
//bgs = new LBFuzzyGaussian;
//bgs = new LBMixtureOfGaussians;
//bgs = new LBAdaptiveSOM;
//bgs = new LBFuzzyAdaptiveSOM;

/*** LBP-MRF Package (thanks to Csaba Kertész) ***/
//bgs = new LbpMrf;

/*** AV Package (thanks to Lionel Robinault and Antoine Vacavant) ***/
//bgs = new LBP_MRF;
//bgs = new VuMeter;

/*** EG Package (thanks to Ahmed Elgammal) ***/
//bgs = new KDE;

/*** DB Package (thanks to Domenico Daniele Bloisi) ***/
//bgs = new IndependentMultimodalBGS;

/*** SJN Package (thanks to SeungJong Noh) ***/
//bgs = new SJN_MultiCueBGS;

/*** BL Package (thanks to Benjamin Laugraud) ***/
//bgs = new SigmaDeltaBGS;

/*** PL Package (thanks to Pierre-Luc) ***/
//bgs = new SuBSENSEBGS();
//bgs = new LOBSTERBGS();
//bgs = new IndependentMultimodal;
//bgs = new MultiCue;
//bgs = new SigmaDelta;
//bgs = new SuBSENSE;
//bgs = new LOBSTER;
//bgs = new PAWCS;
//bgs = new TwoPoints;
//bgs = new ViBe;

int key = 0;
while(key != 'q')
cv::Mat img_input;
while (key != 'q')
{
frame_aux = cvQueryFrame(capture);
if(!frame_aux) break;
capture >> img_input;
if (img_input.empty()) break;

cvResize(frame_aux, frame);

cv::Mat img_input(frame);
cv::imshow("input", img_input);

cv::Mat img_mask;
cv::Mat img_bkgmodel;
bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image

//if(!img_mask.empty())
// cv::imshow("Foreground", img_mask);
// do something

key = cvWaitKey(33);
}

delete bgs;

capture.release();
cvDestroyAllWindows();
cvReleaseCapture(&capture);

return 0;
}
Loading

3 comments on commit d27d1e2

@ShaninAndrey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In file vibe-background-sequential.cpp on line 595 comments aren't match with code.

@ShaninAndrey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When SDEstimationFlag is False, in NPBGSubtractor.cpp in KDE algorithm DynamicMedianHistogram can't delete anything, because it doesn't init (NPBGSubtractor::~NPBGSubtractor())

@ShaninAndrey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In KDE algorithm when
if (frameNumber == framesToLearn) (line 78 in KDE.cpp)
"SequenceLength", "framesToLearn" - parameters, which algorithm is read (line KDE.cpp, KDE::loadConfig())
NPBGSubtractor analise all "SequenceLength" frames, but now we have only "framesToLearn" frames. (line 179 NPBGSubtractor.cpp, BuildAbsDiffHist())
Other ("SequenceLength" - "framesToLearn") frames could be randomly.

Please sign in to comment.