Browse Source

allow examples building with simpleocv

tags/20210720
nihui 4 years ago
parent
commit
b8e03ced3c
22 changed files with 167 additions and 47 deletions
  1. +57
    -45
      examples/CMakeLists.txt
  2. +4
    -0
      examples/fasterrcnn.cpp
  3. +4
    -0
      examples/mobilenetssd.cpp
  4. +4
    -0
      examples/mobilenetv2ssdlite.cpp
  5. +4
    -0
      examples/mobilenetv3ssdlite.cpp
  6. +4
    -0
      examples/nanodet.cpp
  7. +4
    -0
      examples/peleenetssd_seg.cpp
  8. +4
    -0
      examples/retinaface.cpp
  9. +4
    -0
      examples/rfcn.cpp
  10. +4
    -0
      examples/scrfd.cpp
  11. +4
    -0
      examples/shufflenetv2.cpp
  12. +4
    -0
      examples/simplepose.cpp
  13. +4
    -0
      examples/squeezenet.cpp
  14. +4
    -0
      examples/squeezenet_c_api.cpp
  15. +4
    -0
      examples/squeezenetssd.cpp
  16. +4
    -0
      examples/yolact.cpp
  17. +4
    -0
      examples/yolov2.cpp
  18. +4
    -0
      examples/yolov3.cpp
  19. +5
    -0
      examples/yolov5.cpp
  20. +13
    -0
      src/simpleocv.cpp
  21. +19
    -0
      src/simpleocv.h
  22. +5
    -2
      toolchains/c906.toolchain.cmake

+ 57
- 45
examples/CMakeLists.txt View File

@@ -1,56 +1,68 @@
macro(ncnn_add_example name)
add_executable(${name} ${name}.cpp)
target_include_directories(${name} PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${name} PRIVATE ncnn ${OpenCV_LIBS})
if(OpenCV_FOUND)
target_include_directories(${name} PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${name} PRIVATE ncnn ${OpenCV_LIBS})
elseif(NCNN_SIMPLEOCV)
target_compile_definitions(${name} PUBLIC USE_NCNN_SIMPLEOCV)
target_link_libraries(${name} PRIVATE ncnn)
endif()

# add test to a virtual project group
set_property(TARGET ${name} PROPERTY FOLDER "examples")
endmacro()

find_package(OpenCV QUIET COMPONENTS opencv_world)
# for opencv 2.4 on ubuntu 16.04, there is no opencv_world but OpenCV_FOUND will be TRUE
if("${OpenCV_LIBS}" STREQUAL "")
set(OpenCV_FOUND FALSE)
endif()
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs videoio)
endif()
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc)
endif()
if(NCNN_PIXEL)
find_package(OpenCV QUIET COMPONENTS opencv_world)
# for opencv 2.4 on ubuntu 16.04, there is no opencv_world but OpenCV_FOUND will be TRUE
if("${OpenCV_LIBS}" STREQUAL "")
set(OpenCV_FOUND FALSE)
endif()
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs videoio)
endif()
if(NOT OpenCV_FOUND)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc)
endif()

if(NOT OpenCV_FOUND)
message(WARNING "OpenCV not found, examples won't be built")
elseif(NOT NCNN_PIXEL)
message(WARNING "NCNN_PIXEL not enabled, examples won't be built")
else()
message(STATUS "OpenCV library: ${OpenCV_INSTALL_PATH}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(OpenCV_FOUND OR NCNN_SIMPLEOCV)
if(OpenCV_FOUND)
message(STATUS "OpenCV library: ${OpenCV_INSTALL_PATH}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

if(${OpenCV_VERSION_MAJOR} GREATER 3)
set(CMAKE_CXX_STANDARD 11)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)
if(${OpenCV_VERSION_MAJOR} GREATER 3)
set(CMAKE_CXX_STANDARD 11)
endif()
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)

ncnn_add_example(squeezenet)
ncnn_add_example(squeezenet_c_api)
ncnn_add_example(fasterrcnn)
ncnn_add_example(rfcn)
ncnn_add_example(yolov2)
ncnn_add_example(yolov3)
ncnn_add_example(yolov4)
ncnn_add_example(yolov5)
ncnn_add_example(mobilenetv2ssdlite)
ncnn_add_example(mobilenetssd)
ncnn_add_example(squeezenetssd)
ncnn_add_example(shufflenetv2)
ncnn_add_example(peleenetssd_seg)
ncnn_add_example(simplepose)
ncnn_add_example(retinaface)
ncnn_add_example(yolact)
ncnn_add_example(nanodet)
ncnn_add_example(scrfd)
ncnn_add_example(squeezenet)
ncnn_add_example(squeezenet_c_api)
ncnn_add_example(fasterrcnn)
ncnn_add_example(rfcn)
ncnn_add_example(yolov2)
ncnn_add_example(yolov3)
if(OpenCV_FOUND)
ncnn_add_example(yolov4)
endif()
ncnn_add_example(yolov5)
ncnn_add_example(mobilenetv2ssdlite)
ncnn_add_example(mobilenetssd)
ncnn_add_example(squeezenetssd)
ncnn_add_example(shufflenetv2)
ncnn_add_example(peleenetssd_seg)
ncnn_add_example(simplepose)
ncnn_add_example(retinaface)
ncnn_add_example(yolact)
ncnn_add_example(nanodet)
ncnn_add_example(scrfd)
else()
message(WARNING "OpenCV not found and NCNN_SIMPLEOCV disabled, examples won't be built")
endif()
else()
message(WARNING "NCNN_PIXEL not enabled, examples won't be built")
endif()

+ 4
- 0
examples/fasterrcnn.cpp View File

@@ -15,9 +15,13 @@
#include "net.h"

#include <math.h>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>

struct Object


+ 4
- 0
examples/mobilenetssd.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/mobilenetv2ssdlite.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/mobilenetv3ssdlite.cpp View File

@@ -15,9 +15,13 @@
#include "net.h"
#include "platform.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>
#if NCNN_VULKAN


+ 4
- 0
examples/nanodet.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdlib.h>
#include <float.h>
#include <stdio.h>


+ 4
- 0
examples/peleenetssd_seg.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/retinaface.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/rfcn.cpp View File

@@ -15,9 +15,13 @@
#include "net.h"

#include <math.h>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>

struct Object


+ 4
- 0
examples/scrfd.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/shufflenetv2.cpp View File

@@ -15,8 +15,12 @@
#include "net.h"

#include <algorithm>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/simplepose.cpp View File

@@ -15,9 +15,13 @@
#include "net.h"

#include <algorithm>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/squeezenet.cpp View File

@@ -15,8 +15,12 @@
#include "net.h"

#include <algorithm>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/squeezenet_c_api.cpp View File

@@ -15,8 +15,12 @@
#include "c_api.h"

#include <algorithm>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/squeezenetssd.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/yolact.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/yolov2.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 4
- 0
examples/yolov3.cpp View File

@@ -14,9 +14,13 @@

#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <stdio.h>
#include <vector>



+ 5
- 0
examples/yolov5.cpp View File

@@ -15,9 +15,14 @@
#include "layer.h"
#include "net.h"

#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#else
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#include <float.h>
#include <stdio.h>
#include <vector>



+ 13
- 0
src/simpleocv.cpp View File

@@ -211,6 +211,19 @@ bool imwrite(const std::string& path, const Mat& m, const std::vector<int>& para
return success;
}

void imshow(const std::string& name, const Mat& m)
{
NCNN_LOGE("imshow save image to %s.png", name.c_str());

imwrite(name + ".png", m);
}

int waitKey(int delay)
{
NCNN_LOGE("waitKey stub");
return -1;
}

#if NCNN_PIXEL
void resize(const Mat& src, Mat& dst, const Size& size, float sw, float sh, int flags)
{


+ 19
- 0
src/simpleocv.h View File

@@ -124,6 +124,11 @@ struct Point_
{
}

template<typename _Tp2> operator Point_<_Tp2>() const
{
return Point_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y));
}

_Tp x;
_Tp y;
};
@@ -143,6 +148,11 @@ struct Size_
{
}

template<typename _Tp2> operator Size_<_Tp2>() const
{
return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
}

_Tp width;
_Tp height;
};
@@ -166,6 +176,11 @@ struct Rect_
{
}

template<typename _Tp2> operator Rect_<_Tp2>() const
{
return Rect_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
}

_Tp x;
_Tp y;
_Tp width;
@@ -437,6 +452,10 @@ enum ImwriteFlags

NCNN_EXPORT bool imwrite(const std::string& path, const Mat& m, const std::vector<int>& params = std::vector<int>());

NCNN_EXPORT void imshow(const std::string& name, const Mat& m);

NCNN_EXPORT int waitKey(int delay = 0);

#if NCNN_PIXEL
NCNN_EXPORT void resize(const Mat& src, Mat& dst, const Size& size, float sw = 0.f, float sh = 0.f, int flags = 0);
#endif // NCNN_PIXEL


+ 5
- 2
toolchains/c906.toolchain.cmake View File

@@ -15,9 +15,12 @@ set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-g++")

set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-linux-gnu")

set(CMAKE_SYSROOT "${RISCV_ROOT_PATH}/sysroot")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_C_FLAGS "-march=rv64gcvxtheadc -mabi=lp64d -mtune=c906 -DRVV_SPEC_0_7 -D__riscv_zfh=1 -static")
set(CMAKE_CXX_FLAGS "-march=rv64gcvxtheadc -mabi=lp64d -mtune=c906 -DRVV_SPEC_0_7 -D__riscv_zfh=1 -static")
@@ -26,5 +29,5 @@ set(CMAKE_CXX_FLAGS "-march=rv64gcvxtheadc -mabi=lp64d -mtune=c906 -DRVV_SPEC_0_
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")

# export RISCV_ROOT_PATH=/home/nihui/osd/riscv64-linux-x86_64-20210329
# cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906.toolchain.cmake -DCMAKE_BUILD_TYPE=relwithdebinfo -DNCNN_BUILD_TESTS=ON -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=ON ..
# export RISCV_ROOT_PATH=/home/nihui/osd/riscv64-linux-x86_64-20210512
# cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906.toolchain.cmake -DCMAKE_BUILD_TYPE=relwithdebinfo -DNCNN_BUILD_TESTS=ON -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON ..

Loading…
Cancel
Save