目錄
- 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$