yuxiaoyuan0406 / JetsonInstruction

An instraction for coding and other shit on Jetson nano
3 stars 0 forks source link

Create a build enviorment for ncnn #6

Open yuxiaoyuan0406 opened 2 years ago

yuxiaoyuan0406 commented 2 years ago

Build opencv from source to special need

Need to install build tools and dependencies for opencv in the conda env.

yuxiaoyuan0406 commented 2 years ago

We are not using cuda for this env. Using this command to generate.

#!/bin/sh
# set which env to install
CONDA_PREFIX=/home/vip/miniforge-pypy3/envs/ncnn
OPENCV_SRC_PREFIX=~/opencv-4.5.4
OPENCV_CONTRIB_SRC_PREFIX=~/opencv_contrib-4.5.4
mkdir -p ${OPENCV_SRC_PREFIX}/build
rm ${OPENCV_SRC_PREFIX}/build/* -rf
cd ${OPENCV_SRC_PREFIX}/build
# run cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=${CONDA_PREFIX} \
-D OPENCV_EXTRA_MODULES_PATH=${OPENCV_CONTRIB_SRC_PREFIX}/modules \
-D EIGEN_INCLUDE_PATH=${CONDA_PREFIX}/include/eigen3 \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=TRUE \
-D PYTHON_DEFAULT_EXECUTABLE=${CONDA_PREFIX}/bin/python3 \
-D PYTHON3_LIBRARIES=${CONDA_PREFIX}/lib/python3.8 \
-D PYTHON3_INCLUDE_DIR=${CONDA_PREFIX}/include/python3.8 \
-D PYTHON3_EXECUTABLE=${CONDA_PREFIX}/bin/python \
-D PYTHON3_PACKAGES_PATH=${CONDA_PREFIX}/lib/python3.8/site-packages \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=OFF \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=OFF \
-D WITH_CUBLAS=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=OFF \
-D OPENCV_DNN_CUDA=OFF \
-D ENABLE_NEON=ON \
-D WITH_QT=OFF \
-D WITH_OPENMP=ON \
-D WITH_OPENGL=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON ..

Using which command to find out which cmake, gcc, gxx, make you are using. Cmake will check the dependencies for you, so it might have some errors at first few tries. After you fix each missing libs, you should be good to go. Out put will be something like this.

General configuration for OpenCV 4.5.4 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /home/vip/opencv_contrib-4.5.4/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2021-12-14T07:36:19Z
    Host:                        Linux 4.9.201-tegra aarch64
    CMake:                       3.21.3
    CMake generator:             Unix Makefiles
    CMake build tool:            /home/vip/miniforge-pypy3/envs/ncnn/bin/make
    Configuration:               RELEASE

  CPU/HW features:
    Baseline:                    NEON FP16
      required:                  NEON

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /home/vip/miniforge-pypy3/envs/ncnn/bin/aarch64-conda-linux-gnu-c++  (ver 7.5.0)
    C++ flags (Release):         -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -pipe -isystem /home/vip/miniforge-pypy3/envs/ncnn/include   -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fopenmp -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -pipe -isystem /home/vip/miniforge-pypy3/envs/ncnn/include   -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fopenmp -g  -DDEBUG -D_DEBUG
    C Compiler:                  /home/vip/miniforge-pypy3/envs/ncnn/bin/aarch64-conda-linux-gnu-cc
    C flags (Release):           -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -pipe -isystem /home/vip/miniforge-pypy3/envs/ncnn/include   -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fopenmp -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -pipe -isystem /home/vip/miniforge-pypy3/envs/ncnn/include   -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fopenmp -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/home/vip/miniforge-pypy3/envs/ncnn/lib -Wl,-rpath-link,/home/vip/miniforge-pypy3/envs/ncnn/lib -L/home/vip/miniforge-pypy3/envs/ncnn/lib  -Wl,--gc-sections -Wl,--as-needed
    Linker flags (Debug):        -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/home/vip/miniforge-pypy3/envs/ncnn/lib -Wl,-rpath-link,/home/vip/miniforge-pypy3/envs/ncnn/lib -L/home/vip/miniforge-pypy3/envs/ncnn/lib  -Wl,--gc-sections -Wl,--as-needed
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis python2 sfm viz
    Applications:                perf_tests examples apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI:                           GTK3
    GTK+:                        YES (ver 3.24.24)
      GThread :                  YES (ver 2.66.3)
      GtkGlExt:                  NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O:
    ZLib:                        /home/vip/miniforge-pypy3/envs/ncnn/lib/libz.so (ver 1.2.11)
    JPEG:                        /home/vip/miniforge-pypy3/envs/ncnn/lib/libjpeg.so (ver 90)
    WEBP:                        /home/vip/miniforge-pypy3/envs/ncnn/lib/libwebp.so (ver encoder: 0x020f)
    PNG:                         /home/vip/miniforge-pypy3/envs/ncnn/lib/libpng.so (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    FFMPEG:                      YES
      avcodec:                   YES (58.91.100)
      avformat:                  YES (58.45.100)
      avutil:                    YES (56.51.100)
      swscale:                   YES (5.7.100)
      avresample:                YES (4.0.0)
    GStreamer:                   YES (1.18.2)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2020.2 interface 11102)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  Python 3:
    Interpreter:                 /home/vip/miniforge-pypy3/envs/ncnn/bin/python (ver 3.8)
    Libraries:                   /home/vip/miniforge-pypy3/envs/ncnn/lib/python3.8 (ver 3.8.0)
    numpy:                       /home/vip/miniforge-pypy3/envs/ncnn/lib/python3.8/site-packages/numpy/core/include (ver 1.19.4)
    install path:                /home/vip/miniforge-pypy3/envs/ncnn/lib/python3.8/site-packages/cv2/python-3.8

  Python (for build):            /home/vip/miniforge-pypy3/envs/ncnn/bin/python3

  Java:
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /home/vip/miniforge-pypy3/envs/ncnn
-----------------------------------------------------------------
yuxiaoyuan0406 commented 2 years ago

Build vulkan header for conda

yuxiaoyuan0406 commented 2 years ago

First clone the repo.

git clone https://github.com/KhronosGroup/Vulkan-Loader.git

Remeber where you put the source code. Use the following command to generate.

#!/bin/bash
VULKAN_SRC_DIR=/home/vip/Downloads/Vulkan-Loader
CONDA_PREFIX=/home/vip/miniforge-pypy3/envs/ncnn
mkdir -p ${VULKAN_SRC_DIR}/build
cd ${VULKAN_SRC_DIR}/build

rm CMakeCache.txt

cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} \
-DVULKAN_HEADERS_INSTALL_DIR=$(pwd)/Vulkan-Headers/build/install \
-DBUILD_WSI_WAYLAND_SUPPORT=FALSE \
-DCMAKE_C_COMPILER=`which gcc` \
-DCMAKE_CXX_COMPILER=`which g++` \
-DBUILD_WSI_XLIB_SUPPORT=FALSE ..

Then run make -j4 && make install.
Finally, copy the header files to include directory cp /path/to/Vulkan-Loader/build/Vulkan-Headers/include/* ${CONDA_PREFIX}/include/ -r