Skip to content

Commit

Permalink
build static and shared libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Solan Shang committed Mar 15, 2019
1 parent ce2d068 commit cfc8b46
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 22 deletions.
44 changes: 35 additions & 9 deletions CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# CMakeLists for libfacedetectcnn

project(facedetection)

cmake_minimum_required(VERSION 2.8)

option(ENABLE_INT8 "use int8" OFF)
option(ENABLE_AVX2 "use avx2" OFF)
option(ENABLE_NEON "whether use neon, if use arm please set it on" OFF)
option(DEMO "build the demo" OFF)

SET(fdt_base_dir ${PROJECT_SOURCE_DIR})
SET(fdt_src_dir ${fdt_base_dir}/src)
SET(fdt_inc_dir ${fdt_base_dir}/src)

SET(fdt_lib_name facedetection)
SET(fdt_lib_static ${fdt_lib_name})
SET(fdt_lib_shared ${fdt_lib_name}_shared)

FILE(GLOB_RECURSE fdt_source_files ${fdt_src_dir}/*.cpp)
LIST(SORT fdt_source_files)

if(ENABLE_INT8)
message("using int8")
Expand All @@ -26,13 +40,25 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(WIN32)
set(OpenCV_DIR "D:/opencv343/build")
INCLUDE_DIRECTORIES(${fdt_inc_dir})

# Create a static library (.a)
ADD_LIBRARY(${fdt_lib_static} STATIC ${fdt_source_files})

# Create a shared library (.so)
ADD_LIBRARY(${fdt_lib_shared} SHARED ${fdt_source_files})
SET_TARGET_PROPERTIES(${fdt_lib_shared} PROPERTIES OUTPUT_NAME "${fdt_lib_name}")
SET_TARGET_PROPERTIES(${fdt_lib_shared} PROPERTIES PREFIX "lib")

# Create demo. OpenCV is requred.
if (DEMO)
#if(WIN32)
# set(OpenCV_DIR "D:/opencv343/build") # TODO
#endif()
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

set(fdt_demo_files ${fdt_base_dir}/example/libfacedetectcnn-example.cpp)
add_executable(fdt_demo ${fdt_demo_files})
target_link_libraries(fdt_demo ${fdt_lib_static} ${OpenCV_LIBS})
endif()
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS})
include_directories(src)
AUX_SOURCE_DIRECTORY(src LIB_SRC)
AUX_SOURCE_DIRECTORY(example EXAMPLE_SRC)
add_executable(demo ${LIB_SRC} ${EXAMPLE_SRC})
target_link_libraries(demo ${OpenCV_LIBS} )
52 changes: 40 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,45 @@ examples/libfacedetectcnn-example.cpp shows how to use the library.

![Examples](/images/cnnresult.png "Detection example")

How to Compile
-------------
## How to Compile

* Please add -O3 to turn on optimizations when you compile the source code using g++.
* Please choose 'Maximize Speed/-O2' when you compile the source code using Microsoft Visual Studio.

CNN-based Face Detection on Windows
-------------
Create a folder build

```
mkdir -p build; cd build; rm -rf *;
```

### Cross build for aarch64
1. set cross compiler for aarch64 (please refer to aarch64-toolchain.cmake)
2. set opencv path since the example code depends on opencv

```
cmake \
-DENABLE_INT8=ON \
-DENABLE_NEON=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_TOOLCHAIN_FILE=../aarch64-toolchain.cmake \
..
make
```

### Native build for avx2
```
cmake \
-DENABLE_INT8=ON \
-DENABLE_AVX2=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DDEMO=ON \
..
make
```

## CNN-based Face Detection on Windows

| Method |Time | FPS |Time | FPS |
|--------------------|--------------|-------------|--------------|-------------|
Expand All @@ -33,8 +65,7 @@ CNN-based Face Detection on Windows
* Minimal face size ~12x12
* Intel(R) Core(TM) i7-7700 CPU @ 3.6GHz.

CNN-based Face Detection on ARM Linux (Raspberry Pi 3 B+)
-------------
## CNN-based Face Detection on ARM Linux (Raspberry Pi 3 B+)

| Method |Time | FPS |Time | FPS |
|--------------------|--------------|-------------|--------------|-------------|
Expand All @@ -49,16 +80,13 @@ CNN-based Face Detection on ARM Linux (Raspberry Pi 3 B+)
* Raspberry Pi 3 B+, Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz


Author
-------------
## Author
* Shiqi Yu, <[email protected]>

Contributors
-------------
## Contributors
* Jia Wu
* Shengyin Wu
* Dong Xu

Acknowledgment
-------------
## Acknowledgment
The work is partly supported by the Science Foundation of Shenzhen (Grant No. JCYJ20150324141711699).
5 changes: 5 additions & 0 deletions aarch64-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_CXX_COMPILER "/opt/linaro/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++")
set(CMAKE_C_COMPILER "/opt/linaro/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc")
2 changes: 1 addition & 1 deletion src/facedetectcnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ the use of this software, even if advised of the possibility of such damage.

#pragma once

#define _ENABLE_AVX2 //Please enable it if X64 CPU
//#define _ENABLE_AVX2 //Please enable it if X64 CPU
//#define _ENABLE_NEON //Please enable it if ARM CPU


Expand Down

0 comments on commit cfc8b46

Please sign in to comment.