-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sergionr2/c-extension
C++ extension
- Loading branch information
Showing
28 changed files
with
1,239 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ lib/ | |
__pycache__/ | ||
*.x | ||
build/ | ||
tmp/ | ||
*.png | ||
*.jpg | ||
*.pyc | ||
|
@@ -18,3 +19,4 @@ render/ | |
*.mp4 | ||
*.pkl | ||
*.pth | ||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
project(fast_image_processing) | ||
|
||
#************************************************************************************************** | ||
# General cMake settings | ||
#************************************************************************************************** | ||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) | ||
|
||
#************************************************************************************************** | ||
# Find Package ************************************************************************************************** | ||
find_package(OpenCV 3 REQUIRED) | ||
MESSAGE( STATUS "OpenCV_INCLUDE_DIRS : " ${OpenCV_INCLUDE_DIRS} ) | ||
MESSAGE( STATUS "OpenCV_LIB_DIRS : " ${OpenCV_LIB_DIRS} ) | ||
MESSAGE( STATUS "OpenCV_LIBS : " ${OpenCV_LIBS} ) | ||
|
||
find_package(PythonLibs REQUIRED) | ||
MESSAGE( STATUS "PYTHON_INCLUDE_DIRS : " ${PYTHON_INCLUDE_DIRS} ) | ||
MESSAGE( STATUS "PYTHON_LIBRARIES : " ${PYTHON_LIBRARIES} ) | ||
|
||
find_package(Eigen3 REQUIRED) | ||
|
||
find_package(NumPy REQUIRED) | ||
|
||
set(PYBIND11_CPP_STANDARD -std=c++14) | ||
find_package(pybind11 REQUIRED) | ||
|
||
#************************************************************************************************** | ||
# Include ************************************************************************************************** | ||
include_directories(${PYTHON_INCLUDE_DIRS}) | ||
include_directories(${EIGEN3_INCLUDE_DIRS}) | ||
include_directories(${OpenCV_INCLUDE_DIRS}) | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||
include_directories(${NUMPY_INCLUDE_DIRS}) | ||
include_directories(${PYBIND11_INCLUDE_DIRS}) | ||
|
||
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/pybind11/include) | ||
|
||
#************************************************************************************************** | ||
# Set variable ************************************************************************************************** | ||
SET(SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/fast_image_processing.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/ndarray_converter.cpp | ||
) | ||
|
||
#************************************************************************************************** | ||
# Set compiler ************************************************************************************************** | ||
SET(CMAKE_CXX_FLAGS "-std=c++14 -Wall -O3 -fPIC") | ||
|
||
#************************************************************************************************** | ||
# Linker ************************************************************************************************** | ||
LINK_DIRECTORIES( | ||
${OpenCV_LIB_DIR} | ||
) | ||
|
||
#************************************************************************************************** | ||
# Make configuration | ||
#************************************************************************************************** | ||
add_library(fast_image_processing SHARED ${SOURCES}) | ||
target_link_libraries(fast_image_processing ${PYTHON_LIBRARIES} ${OpenCV_LIBS} ${Eigen3_LIBS}) | ||
SET_TARGET_PROPERTIES(fast_image_processing PROPERTIES PREFIX "") | ||
|
||
install(TARGETS fast_image_processing DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# C++ extension for fast image processing | ||
|
||
It is based on [pybind11_opencv_numpy](https://github.com/edmBernard/pybind11_opencv_numpy). | ||
that allows interpolation between cv::Mat <-> np.array. | ||
|
||
Depending on the resize strategy (nearest neighbors or bilinear), the speedup compare to pure python + numpy is between x2 and x6. | ||
|
||
## Dependencies | ||
|
||
- [PyBind11 2.2.1](https://github.com/pybind/pybind11) | ||
- OpenCV 3 with Eigen support | ||
- [Eigen 3.3](http://eigen.tuxfamily.org/index.php?title=Main_Page) | ||
|
||
### Compile with CMake | ||
|
||
#### On the rapsberry pi | ||
``` | ||
./pi_cmake.sh | ||
``` | ||
|
||
#### On the Laptop | ||
```bash | ||
mkdir build && cd build | ||
# configure make | ||
cmake .. | ||
# generate the fast_image_processing.so library | ||
make | ||
# move fast_image_processing.so library in current folder | ||
make install | ||
``` | ||
|
||
### Compile with setup.py | ||
WARNING: you have to manually edit the path to OpenCV + Eigen | ||
``` | ||
./compile.sh | ||
``` | ||
|
||
### Run | ||
To run the test, you need to copy `mlp_model.npz` in this folder and have an image named `test_sun.jpg` (ideally taken from the raspicam). | ||
```bash | ||
python test.py | ||
``` |
Oops, something went wrong.