Jetson Nano configuration process (4)

Jetson Nano configuration process (4)

This article writes down the process of compiling and installing opencv 4.1.1 under nano, and some filling holes.

1. Uninstall the old version of opencv in the system

sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update

2. Install dependencies

sudo apt-get install build-essential

sudo apt-get install libglew-dev libtiff5-dev zlib1g-dev libjpeg-dev\ 
	libavcodec-dev libavformat-dev libavutil-dev libpostproc-dev\
	libswscale-dev libeigen3-dev libtbb-dev libgtk2.0-dev pkg-config libpng-dev
	
sudo apt-get install libatlas-base-dev gfortran
sudo apt update
sudo apt upgrade

3. Download the source code and compile

After downloading the source code, decompress OpenCV-4.1.1 and OpenCV_contirb-4.1.1 and place them in the same main directory opencv4.
Enter the opencv-4.1.1 directory and run the following command:

Post the modified opencv source file here :

https://pan.baidu.com/s/1FUWfLriHrqMSDr7l61tBBQ File code: s7ty

mkdir build
cd build

cmake \

-DCMAKE_BUILD_TYPE=Release \
-DBUILD_PNG=OFF \
-DBUILD_TIFF=OFF \
-DBUILD_TBB=OFF \
-DBUILD_JPEG=OFF \
-DBUILD_JASPER=OFF \
-DBUILD_ZLIB=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=ON \
-DENABLE_PRECOMPILED_HEADERS=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENMP=OFF \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=OFF \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_CUDA=ON \
-DWITH_GTK=ON \
-DWITH_VTK=OFF \
-DWITH_TBB=ON \
-DWITH_1394=OFF \
-DWITH_OPENEXR=OFF \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0 \
-DCUDA_ARCH_BIN=5.3 \
-DCUDA_ARCH_PTX="" \
-DINSTALL_C_EXAMPLES=OFF \
-DOPENCV_ENABLE_NONFREE=ON \
-DINSTALL_TESTS=OFF \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules \

..
sudo make -j4
sudo make install

The following are errors that occurred during the compilation process, which have been modified in the source code package:

1.需要将如vgg_generated_48.i、face_landmark_model.dat等,由于是外网的原因,
这些文件会出现超时下载不成功的现象,虽然这里下载不成功,不会出现红色的error报错,
但会影响到后面的make操作,因此必须要确保下载成功。我将我编译时需要下载的文件放在了上面的百度云链接中,需要的同学可以自取。

将这些文件下载好放置在随意目录如/home/ryu/Documents/opencv4/installFile中,
然后更改opencv_contrib-4.1.1/modules/xfeatures2d/cmake/download_vgg.cmake和opencv_contrib-4.1.1/modules/face/CMakeLists.txt中的URL地址,
具体修改如下:(installfile为自己创建)

 "file:///home/djj/opencv-4.1.1/installfile/"
 #"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${OPENCV_3RDPARTY_COMMIT}/"

//
编译68%会报错

需要将上述文件拷贝到  opencv_contrib-4.1.1/modules/xfeatures2d/src/

***********************************************************************************
2.#头文件会报错 #include "features2d/test/test_detectors_regression.impl.hpp"

将opencv-4.1.1/modules/features2d/test/文件下的:
test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp

拷贝到opencv_contrib-4.1.1/modules/xfeatures2d/test/文件下。
同时,将opencv_contrib-4.1.1/modules/xfeatures2d/test/test_features2d.cpp文件下的:

#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"
改为:
#include "test_detectors_regression.impl.hpp"
#include "test_descriptors_regression.impl.hpp"

将opencv_contrib-4.1.1/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp文件下的:

#include "features2d/test/test_detectors_invariance.impl.hpp" 
#include "features2d/test/test_descriptors_invariance.impl.hpp"
改为:
#include "test_detectors_invariance.impl.hpp"
#include "test_descriptors_invariance.impl.hpp"

*********************************************************
3.修改:
opencv-4.1.1/samples/gpu/surf_keypoint_matcher.cpp下:
#incloud"opencv2/cuda.hpp"
改为绝对路径
#incloud"/home/djj/../../../opencv2/cuda.hpp"
**********************************************************
4.opencv-4.1.1/samples/gpu/CMakeLists.txt
修改成以下代码:
 foreach(sample_filename ${all_samples})
  ocv_define_sample(tgt ${sample_filename} gpu)
  ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS})
 if(HAVE_CUDA AND NOT ANDROID)
  ocv_target_link_libraries(${tgt} ${CUDA_CUDA_LIBRARY})
 endif()
  if(HAVE_opencv_xfeatures2d)
   ocv_target_link_libraries(${tgt} opencv_xfeatures2d)
  endif()

reference:

Jetson nano-compile and install OpenCV4.1.1 and OpenCV_contirb-4.1.1 (supplement to avoid pits)

Jetson nano compile and install OpenCV4.1.1 and OpenCV_contirb-4.1.1

Guess you like

Origin blog.csdn.net/djj199301111/article/details/107774229