jetson nano——编译安装opencv==4.4

系统: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 of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake 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 of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake 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$ 
  • 8
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
opencv-4.4.0-vc14_vc15.exe 版本:4.4.0 2020年7月 OpenCV 4.x的夏季更新已发布 :晴天: 此版本的亮点: SIFT(尺度不变特征变换)算法已移至主存储库(SIFT的专利已过期) DNN模块: 改进的图层/激活/支持更多模型: 最新的Yolo v4检测器:#17148。为[yolo]层(Yolo v3和Yolo v4)禁用了每层NMS,因为它们是不正确的-用于cv::dnn::NMSBoxes所有检测。 ONNX:添加对Resnet_backbone(Torchvision)的支持#16887 EfficientDet模型支持:#17384 新样本/演示: 添加文本识别示例:C ++ / Python FlowNet2光流:#16575 英特尔®推理引擎后端(OpenVINO™): 增加了对OpenVINO 2020.3 LTS / 2020.4版本的支持 计划在下一版本中删除对NN Builder API的支持 CUDA后端中的许多修复和优化(感谢@YashasSamaga):PR G-API模块: 在OpenCV后端引入了用于状态内核的新API :GAPI_OCV_KERNEL_ST。有状态内核在各个图执行(标准中更多)或流的视频帧之间(以流模式)保留其状态。 在G-API推出更多面向视频的操作:goodFeaturesToTrack,buildOpticalFlowPyramid,calcOpicalFlowPyrLK。 添加了更多的图像处理内核:Laplacian和双边过滤器。 修复了G-API的OpenCL后端中的潜在崩溃。 OpenCV社区的许多其他伟大贡献,包括但不限于: Obj-C / Swift绑定:#17165 (opencv_contrib)Julia绑定是正在进行的GSoC项目的一部分:#2547 (opencv_contrib)BIMEF:生物启发的多重曝光融合框架,用于弱光图像增强: #2448 为CV_16UC1图像启用Otsu阈值:#16640 为文本检测添加笔划宽度变换算法:#2464 计划在Apache 2许可证上进行下一版本OE-32的 迁移#17491
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ymchuangke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值