目录
- 1.下载源码,我提供的链接如下:
- 1.1文件上传的路径位置,注意ymck是我自己的用户名(你们自己换成你们自己相对应的就行)
- 2.解压文件
- 3.安装依赖
- 4.增加swap交换内存
- 4.1临时增加交换内存swap
- 4.2永久增加swap
- 5.安装opencv4.4(里面是有contrib这个的)
- 5.1创建目录
- 5.2安装配置cmake选项
- 5.3编译!!一定要增大swap否则会报错!!!!!
- 5.3.1报错,一条cuda,一条内存不足,导致报错,所以大家一定要增大swap交换内存!!!!!!!!!!!,
- 5.3.2解决问题
- 5.4开始安装
- 5.4.1waning解释,这是对开发者的一个警告,对咱们来说没啥问题我解释一下
- 6.复制编译过程中的文件到自己在虚拟环境中的dist-packages,这样你就可以导入这个cv2了
- 7.查看opencv版本
- 8.安装过程
系统:jetson-nano-jp451-sd-card-image
ubuntu 18.04
(总共编译得2-3个多小时,大家耐心吧,时间相较于其它的已经很短了)
注意:!!make -j8以后千万别在动了,还有就是开始前把那些后台啥的都关掉,千万别在make -j8期间操作,要不然报错。
ps:如果你们编译其它的版本,我在这提供11个文件,你们得放到/opencv-contrib/modules/xfeatures2d/src/这个里面。
你们还得下载opencv和opencv-contrib的包,官网给你们放着,编译步骤参考我这个原理是一样的,得注意,他们两个的版本应该一样的。
官网:https://github.com/opencv/
链接:https://pan.baidu.com/s/1Jcu6g80qlp-5A3FrZ6VO8Q?pwd=0lzt
提取码:0lzt
1.下载源码,我提供的链接如下:
链接:https://pan.baidu.com/s/1QsrI67HmHXV59k6RetSMUQ?pwd=55d4
提取码:55d4
1.1文件上传的路径位置,注意ymck是我自己的用户名(你们自己换成你们自己相对应的就行)
2.解压文件
unzip opencv4.4.zip
3.安装依赖
#1.
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-build==0.11.1
##注意,必须是这个版本,否则会报错,调试好久。。。#里面有些处理视频和图像的我就不在这单独说明了
#2.
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
#3.
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
#4.
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
#5.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
#6.
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
#7.
sudo apt-get install cmake libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libpng-dev libtiff-dev libtiff5-dev libswscale-dev libcurl4-openssl-dev libtbb2 libdc1394-22-dev
4.增加swap交换内存
下面这个swap可以操作,也可以不操作,最好选一个吧。
4.1临时增加交换内存swap
sudo fallocate -l 4G /var/swapfile
sudo chmod 600 /var/swapfile #600是root权限,644是普通用户也行
sudo mkswap /var/swapfile
sudo swapon /var/swapfile
4.2永久增加swap
sudo fallocate -l 4G /var/swapfile
sudo chmod 600 /var/swapfile
sudo mkswap /var/swapfile
sudo swapon /var/swapfile
sudo bash -c 'echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab'
5.安装opencv4.4(里面是有contrib这个的)
5.1创建目录
#1.
cd opencv4.4/opencv-4.4.0/
#2.
mkdir build
#3.
cd build
5.2安装配置cmake选项
注意,里面ymck是我的用户名,大家自行修改,换成你们自己的!
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_TESTS=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_V4L=ON \
-D WITH_OPENEXR=OFF \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D CMAKE_CXX_FLAGS="-W -Wall -Werror=return-type" \
-D BUILD_PNG=ON \
-D BUILD_TIFF=ON \
-D BUILD_TBB=OFF \
-D BUILD_JPEG=ON \
-D BUILD_JASPER=OFF \
-D BUILD_ZLIB=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D WITH_OPENCL=OFF \
-D WITH_OPENMP=OFF \
-D WITH_GSTREAMER_0_10=OFF \
-D WITH_CUDA=ON \
-D WITH_GTK=ON \
-D WITH_VTK=OFF \
-D WITH_1394=OFF \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/ymck/opencv4.4/opencv_contrib-4.4.0/modules \
-D PYTHON3_EXECUTABLE=/home/ymck/archiconda3/envs/dc39/bin/python \
-D PYTHON3_INCLUDE_DIR=/home/ymck/archiconda3/envs/dc39/include/python3.9 \
-D PYTHON_DEFAULT_EXECUTABLE=$(which python3) \
-D PYTHON3_LIBRARY=/home/ymck/archiconda3/envs/dc39/lib/libpython3.9.so \
..
大家可以看我的结果(如果buidl目录被玩坏了,可以新建一个其它的在进行cmake,我把这个结果放到最后面:),大家往下看,一定这几个得出现,要不然弄了可能找不到opencv4.4,虽然不报错也能安装成功,但是你导入cv2,会报错,而且你也找不到这个包,
which python
你们可以用这个代码查找相应的路径,一般和我这个路径差不多
#####################################
#这里面的代码不是运行的
#这里面的代码是让你们对照自己的camke是否正确的
-- Python 3:
-- Interpreter: /home/ymck/archiconda3/envs/dc39/bin/python (ver 3.9.13)
-- Libraries: /home/ymck/archiconda3/envs/dc39/lib/libpython3.9.so (ver 3.9.13)
-- numpy: /home/ymck/archiconda3/envs/dc39/lib/python3.9/site-packages/numpy/core/include (ver 1.26.4)
-- install path: lib/python3.9/site-packages/cv2/python-3.9
--
-- Python (for build): /home/ymck/archiconda3/envs/dc39/bin/python3
#####################################
5.3编译!!一定要增大swap否则会报错!!!!!
make -j8
5.3.1报错,一条cuda,一条内存不足,导致报错,所以大家一定要增大swap交换内存!!!!!!!!!!!,
5.3.2解决问题
增大swap,之前是1.9G,现在是5.9G,reboot以后即可恢复
现在未报错,可以看到swap的确跑到2.5G了,说明的确有点费swap
5.4开始安装
sudo make install
运行结果如下:
5.4.1waning解释,这是对开发者的一个警告,对咱们来说没啥问题我解释一下
CMake提醒开发者,它默认的FindCUDA模块已经被移除,会影响到之前依赖这个模块的构建脚本。这不会影响到项目的构建过程,只是作为一个提醒开发者进行代码维护的提示。
6.复制编译过程中的文件到自己在虚拟环境中的dist-packages,这样你就可以导入这个cv2了
这个python中的python3.9就是你编译过程中产生的
cp /usr/local/lib/python3.9/site-packages/cv2/python-3.9/cv2.cpython-39-aarch64-linux-gnu.so /home/ymck/archiconda3/envs/dc39/lib/python3.9/site-packages/
复制完成以后结果如下:
7.查看opencv版本
#1.
python
#2.
import cv2
#3.
print(cv2.__version__)
到这就说明大家成功编译完成啦,祝大家都成功呀!!!
8.安装过程
如下图:
大家可以看我的结果(如果buidl目录被玩坏了,可以新建一个其它的在进行cmake,我把这个结果放到最后面:
#这个是cmake以后的输出的结果:
# 大家可以自己对照一下,有些实在安装不上(java啥的,比较ubuntu18实在太老了。
#如果你们用的版本高,你们运行前面安装依赖的话,应该不会出现我下面这些no found。
#还有就是,一些warning,因为我升级了cmake版本,这些对咱们没啥影响,#warning不影响,那些warning是对开发者的一些提醒,遇见了不用在意。
-- CUDA detected: 10.2
-- CUDA: Using CUDA_ARCH_BIN=5.3
-- CUDA NVCC target flags: -gencode;arch=compute_53,code=sm_53;-D_FORCE_INLINES
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY)
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT JVM)
CMake Deprecation Warning at 3rdparty/carotene/hal/CMakeLists.txt:1 (cmake_minimum_required):Compatibility with CMake < 3.5 will be removed from a future version ofCMake.Update the VERSION argument <min> value or use a ...<max> suffix to tellCMake that the project does not need compatibility with older versions.CMake Deprecation Warning at 3rdparty/carotene/CMakeLists.txt:1 (cmake_minimum_required):Compatibility with CMake < 3.5 will be removed from a future version ofCMake.Update the VERSION argument <min> value or use a ...<max> suffix to tellCMake that the project does not need compatibility with older versions.-- OpenCV Python: during development append to PYTHONPATH: /home/ymck/opencv4.4/opencv-4.4.0/build1/python_loader
-- Caffe: NO
-- Protobuf: NO
-- Glog: NO
-- freetype2: YES (ver 21.0.15)
-- harfbuzz: YES (ver 1.7.2)
-- Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found version "")
-- Julia not found. Not compiling Julia Bindings.
-- Module opencv_ovis disabled because OGRE3D was not found
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
-- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
-- Module opencv_sfm disabled because the following dependencies are not found: Glog/Gflags
-- Checking for module 'tesseract'
-- No package 'tesseract' found
-- Tesseract: NO
-- Allocator metrics storage type: 'int'
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse3.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.ssse3.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse4_1.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse4_2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin512.avx512_skx.cpp
-- Excluding from source files list: modules/imgproc/src/corner.avx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.sse4_1.cpp
-- Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/resize.sse4_1.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/ymck/opencv4.4/opencv-4.4.0/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out ocl4dnn source code
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
-- Excluding from source files list: modules/features2d/src/fast.avx2.cpp
--
-- General configuration for OpenCV 4.4.0 =====================================
-- Version control: unknown
--
-- Extra modules:
-- Location (extra): /home/ymck/opencv4.4/opencv_contrib-4.4.0/modules
-- Version control (extra): unknown
--
-- Platform:
-- Timestamp: 2024-03-03T06:54:55Z
-- Host: Linux 4.9.201-tegra aarch64
-- CMake: 3.28.3
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: RELEASE
--
-- CPU/HW features:
-- Baseline: NEON FP16
-- required: NEON
-- disabled: VFPV3
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ standard: 11
-- C++ Compiler: /usr/bin/c++ (ver 7.5.0)
-- C++ flags (Release): -W -Wall -Werror=return-type -fsigned-char -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 -Winit-self -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 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -W -Wall -Werror=return-type -fsigned-char -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 -Winit-self -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 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -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 -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -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 -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release): -Wl,--gc-sections -Wl,--as-needed
-- Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed
-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: m pthread cudart_static dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda-10.2/lib64 -L/usr/lib/aarch64-linux-gnu
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor 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 xfeatures2d ximgproc xobjdetect xphoto
-- Disabled: python2 world
-- Disabled by dependency: -
-- Unavailable: cnn_3dobj cvv hdf java js julia matlab ovis sfm viz
-- Applications: tests perf_tests apps
-- Documentation: NO
-- Non-free algorithms: YES
--
-- GUI:
-- GTK+: YES (ver 3.22.30)
-- GThread : YES (ver 2.56.4)
-- GtkGlExt: NO
--
-- Media I/O:
-- ZLib: /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
-- JPEG: build-libjpeg-turbo (ver 2.0.5-62)
-- WEBP: build (ver encoder: 0x020f)
-- PNG: build (ver 1.6.37)
-- TIFF: build (ver 42 - 4.0.10)
-- JPEG 2000: build Jasper (ver 1.900.1)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- FFMPEG: YES
-- avcodec: YES (57.107.100)
-- avformat: YES (57.83.100)
-- avutil: YES (55.78.100)
-- swscale: YES (4.8.100)
-- avresample: YES (3.7.0)
-- GStreamer: YES (1.14.5)
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Lapack: NO
-- Eigen: YES (ver 3.3.4)
-- Custom HAL: YES (carotene (ver 0.0.1))
-- Protobuf: build (3.5.1)
--
-- NVIDIA CUDA: YES (ver 10.2, CUFFT CUBLAS)
-- NVIDIA GPU arch: 53
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 8.0.0)
--
-- Python 3:
-- Interpreter: /home/ymck/archiconda3/envs/dc39/bin/python (ver 3.9.13)
-- Libraries: /home/ymck/archiconda3/envs/dc39/lib/libpython3.9.so (ver 3.9.13)
-- numpy: /home/ymck/archiconda3/envs/dc39/lib/python3.9/site-packages/numpy/core/include (ver 1.26.4)
-- install path: lib/python3.9/site-packages/cv2/python-3.9
--
-- Python (for build): /home/ymck/archiconda3/envs/dc39/bin/python3
--
-- Java:
-- ant: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done (13.4s)
-- Generating done (3.2s)
-- Build files have been written to: /home/ymck/opencv4.4/opencv-4.4.0/build1
(dc39) ymck@ymck-desktop:~/opencv4.4/opencv-4.4.0/build1$