From cfc8b46ab596b2d7fc6f6b9e1f71e9e4f8855896 Mon Sep 17 00:00:00 2001 From: Solan Shang Date: Fri, 15 Mar 2019 18:39:30 +0800 Subject: [PATCH] build static and shared libraries --- CMakeLists.txt | 44 +++++++++++++++++++++++++++------- README.md | 52 +++++++++++++++++++++++++++++++---------- aarch64-toolchain.cmake | 5 ++++ src/facedetectcnn.h | 2 +- 4 files changed, 81 insertions(+), 22 deletions(-) mode change 100755 => 100644 CMakeLists.txt create mode 100644 aarch64-toolchain.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index e6308c0..8cef017 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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} ) diff --git a/README.md b/README.md index a138b9a..db1f024 100644 --- a/README.md +++ b/README.md @@ -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 | |--------------------|--------------|-------------|--------------|-------------| @@ -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 | |--------------------|--------------|-------------|--------------|-------------| @@ -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, -Contributors -------------- +## Contributors * Jia Wu * Shengyin Wu * Dong Xu -Acknowledgment -------------- +## Acknowledgment The work is partly supported by the Science Foundation of Shenzhen (Grant No. JCYJ20150324141711699). diff --git a/aarch64-toolchain.cmake b/aarch64-toolchain.cmake new file mode 100644 index 0000000..40d7f6d --- /dev/null +++ b/aarch64-toolchain.cmake @@ -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") diff --git a/src/facedetectcnn.h b/src/facedetectcnn.h index 702780d..1b934b0 100644 --- a/src/facedetectcnn.h +++ b/src/facedetectcnn.h @@ -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