Skip to content

Commit

Permalink
Added Java Wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewssobral committed Mar 31, 2017
1 parent 1299c13 commit 209a2ff
Show file tree
Hide file tree
Showing 17 changed files with 958 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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-Python%2C%20MATLAB-orange.svg)](https://github.com/andrewssobral/bgslibrary/wiki/Build-status) [![Algorithms](https://img.shields.io/badge/Algorithms-40-red.svg)](https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms)
[![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)

[![bgslibrary](http://i.giphy.com/5A94AZahSIVOw.gif)](https://youtu.be/_UbERwuQ0OU)

Page Update: **18/03/2017**
Page Update: **01/04/2017**

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)

The **BGSLibrary** was developed by [Andrews Sobral](http://andrewssobral.wixsite.com/home) and provides an easy-to-use C++ framework based on [OpenCV](http://www.opencv.org/) to perform foreground-background separation in videos. The bgslibrary is compatible with OpenCV 2.x and 3.x, and compiles under Windows, Linux, and Mac OS X. Currently the library contains **40** algorithms. The source code is available under [GNU GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html), the library is free and open source for academic purposes.
The **BGSLibrary** was developed by [Andrews Sobral](http://andrewssobral.wixsite.com/home) and provides an easy-to-use C++ framework based on [OpenCV](http://www.opencv.org/) to perform foreground-background separation in videos. The bgslibrary is compatible with OpenCV 2.x and 3.x, 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 free and open source for academic purposes.

* [List of available algorithms](https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms)
* [Algorithms benchmark](https://github.com/andrewssobral/bgslibrary/wiki/Algorithms-benchmark)
Expand All @@ -32,6 +32,7 @@ The **BGSLibrary** was developed by [Andrews Sobral](http://andrewssobral.wixsit

* * [Python](https://github.com/andrewssobral/bgslibrary/wiki/Wrapper:-Python) ***(NEW)***
* * [MATLAB](https://github.com/andrewssobral/bgslibrary/wiki/Wrapper:-MATLAB) ***(NEW)***
* * [Java](https://github.com/andrewssobral/bgslibrary/wiki/Wrapper:-Java) ***(NEW)***

* [Docker images](https://github.com/andrewssobral/bgslibrary/wiki/Docker-images)
* [How to integrate BGSLibrary in your own CPP code](https://github.com/andrewssobral/bgslibrary/wiki/How-to-integrate-BGSLibrary-in-your-own-CPP-code)
Expand Down
9 changes: 9 additions & 0 deletions wrapper_java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nbproject/
build.xml
build/
dist/
build_*/
*.dll
*.bat
*.sh
*.lib
85 changes: 85 additions & 0 deletions wrapper_java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
cmake_minimum_required(VERSION 2.8)
project(libbgs_java_module)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=gnu++0x")
set(CMAKE_MACOSX_RPATH 1)
endif(UNIX)

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_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})
# 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)

find_package(JNI REQUIRED)
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()

set(OpenCV_STATIC OFF)
find_package(OpenCV REQUIRED)
if (OpenCV_FOUND)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
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)

include_directories(${CMAKE_SOURCE_DIR} ${JNI_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})

add_library(libbgs STATIC ${bgs_src} ${analysis_src})
target_link_libraries(libbgs ${OpenCV_LIBS})
set_property(TARGET libbgs PROPERTY PUBLIC_HEADER ${bgs_inc} ${analysis_inc})
if(WIN32)
# set_property(TARGET libbgs PROPERTY SUFFIX ".lib")
else()
set_property(TARGET libbgs PROPERTY OUTPUT_NAME "bgs")
endif()

set(SOURCE_FILES bgslibrary_java_module.cpp)
add_library(libbgs_java_module SHARED ${SOURCE_FILES})
set_target_properties(libbgs_java_module PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(libbgs_java_module libbgs ${OpenCV_LIBS})
if(WIN32)
# set_property(TARGET libbgs_java_module PROPERTY SUFFIX ".lib")
else()
set_property(TARGET libbgs_java_module PROPERTY OUTPUT_NAME "bgs_java_module")
endif()
55 changes: 55 additions & 0 deletions wrapper_java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
### For Windows users

* Running CMAKE with Visual Studio 2015 and OpenCV 3.2.0 (x64)

* * Working directory: **bgslibrary\wrapper_java**

```
:: Set OpenCV env
echo "Setting up OpenCV env"
set OpenCV_DIR=C:\OpenCV3.2.0\build
set PATH=%PATH%;%OpenCV_DIR%\x64\vc14\bin
:: Run CMake
echo "Running CMake"
rmdir /S /Q build_cmake
if not exist "build_cmake" mkdir build_cmake
cd build_cmake
cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 14 Win64" ..
cd ..
```

* Open **libbgs_java_module.sln** in your Visual Studio IDE and switch to **RELEASE** mode

* Click on **ALL_BUILD** and build

* Copy **libbgs_java_module.dll** to **bgslibrary\wrapper_java**

* Compile Java source

```
:: Compile
echo "Compiling"
javac -cp .;src/;libs/opencv-320.jar src/bgslibrary/Main.java
```

* Run

```
:: Run
echo "Running Main class"
java -cp .;src/;libs/opencv-320.jar -Djava.library.path=. bgslibrary.Main
```

[![bgslibrary](https://sites.google.com/site/andrewssobral/bgslib_java_wrapper_screen.png)]()


#### Generating JNI files (optional)

```
:: Generate JNI
cd src
echo "Generating JNI"
javah -cp .;../libs/opencv-320.jar bgslibrary.Main
cd ..
```
Loading

0 comments on commit 209a2ff

Please sign in to comment.