欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > Ubuntu20.04安装opencv3.1.0(包含详细解决报错方法)

Ubuntu20.04安装opencv3.1.0(包含详细解决报错方法)

2024/11/30 10:52:13 来源:https://blog.csdn.net/m0_69253695/article/details/138570701  浏览:    关键词:Ubuntu20.04安装opencv3.1.0(包含详细解决报错方法)

我的环境是cuda10.1

cmake是3.16.5

第一步骤:下载安装包

第二步骤:编译环境安装

第三步骤:解压opencv安装包,并且在opencv文件夹内新建build文件夹

第四步骤:打开cmake-gui,

第五步骤:进行编译

总结:

报错解决方法汇总:

ICV: Failed to download ICV package:ippicv_linux_20151201.tgz

 /usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

 error: ‘NppiGraphcutState’ has not been declared typedef NppStatus (sudo make compile )

Note: Class l has more than 1 base class (not supported by Python C extensions)Bases: cv::a, cv:😒, cv:😒, cv::A, cv::l, cv::g, cv:😮, cv::r, cv::i, cv::t, cv::h, cv::mOnly the first base class will be usedGenerator error: constant l_MAGIC_VAL (cname=cv::l::MAGIC_VAL) already exists

#error -- unsupported GNU version! gcc versions later than 8 are not supported!

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.Please set them or make sure they are set and tested correctly in the CMake files:CUDA_nppi_LIBRARY (ADVANCED)

linked by target “opencv_cudev“ in directory /home/davidhopper/opencv/opencv-3.1.0/

nvcc fatal   : Unsupported gpu architecture 'compute_20'CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:206 (message):  Error generating  /home/danalelixin/Desktop/opencv-3.2.0/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1313:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope         c->flags |= CODEC_FLAG_GLOBAL_HEADER;

opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1525:35: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope


第一步骤:下载安装包

安装包名字为opencv-3.1.0.zip

opencv的安装链接看这个(内有cmake下载地址)https://blog.csdn.net/m0_69253695/article/details/136314667?spm=1001.2014.3001.5502

第二步骤:编译环境安装

sudo apt-get install build-essential

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev

第三步骤:解压opencv安装包,并且在opencv文件夹内新建build文件夹

第四步骤:打开cmake-gui,

点configure,当没有出现红色报错后,即可点击generate

在build文件夹下点击鼠标右键,在终端中输入下面的命令也可以(但不建议这样,因为cmake的时候会有报错,需要在可视化界面内进行修改,比较方便,要不然还要修改命令就很麻烦)

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

第五步骤:进行编译

然后在build文件夹下右键,选择终端,然后输入下面这个命令

sudo make -j8

等到100%之后再输入下面这个命令,就完成安装了

sudo make install

总结:

安装opencv3.1.0这种老版本的opencv与新版本的opencv步骤是一样的,安装步骤不是重点,重点是安装过程中遇到的报错该怎么解决,会遇到很多不兼容的报错。详细的安装步骤可以看下面的连接https://blog.csdn.net/public669/article/details/99044895

报错解决方法汇总:

ICV: Failed to download ICV package:ippicv_linux_20151201.tgz

解决办法是下载ippicv_linux_20151201.tgz包,并将包拷贝到下面这个文件夹内
opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e

下面是下载的链接,下图中第一个包

https://codeload.github.com/opencv/opencv_3rdparty/zip/refs/heads/ippicv/master_20151201 

 /usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

解决办法是在/build目录下的cmake中添加指令-D ENABLE_PRECOMPILED_HEADERS=OFF

或者在cmake-gui界面中将ENABLE_PRECOMPILED_HEADERS取消勾选

 error: ‘NppiGraphcutState’ has not been declared typedef NppStatus (sudo make compile )

解决方法是打开下面的.cpp文件

/home/lvv/Downloads/opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp

将#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)

改为:

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

 修改后如下图

Note: Class l has more than 1 base class (not supported by Python C extensions)
Bases: cv::a, cv:😒, cv:😒, cv::A, cv::l, cv::g, cv:😮, cv::r, cv::i, cv::t, cv::h, cv::m
Only the first base class will be used
Generator error: constant l_MAGIC_VAL (cname=cv::l::MAGIC_VAL) already exists

解决方法是在/build目录下的cmake中添加指令 -DBUILD_opencv_python2=OFF -DBUILD_opencv_pyhton3=OFF

或者在cmake-gui界面中将BUILD_opencv_python2和BUILD_opencv_pyhton3取消勾选

#error -- unsupported GNU version! gcc versions later than 8 are not supported!

这个报错意思是gcc版本不能高于8

所以安装gcc-8及g++-8

sudo apt-get install g++-8
sudo apt-get install gcc-8

安装成功后设置gcc与g++各版本的优先级,数字越小优先级越高,默认的优先级为50,故设置的比50小即可,这里选择20:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 20

通过sudo update-alternatives --config gcc

sudo update-alternatives --config g++

可查看电脑上gcc与g++的可供选择版本,也可以通过上述命令手动选择编译所用版本

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)

linked by target “opencv_cudev“ in directory /home/davidhopper/opencv/opencv-3.1.0/

解决办法看这个链接https://blog.csdn.net/m0_69253695/article/details/143068384?spm=1001.2014.3001.5502

nvcc fatal   : Unsupported gpu architecture 'compute_20'
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:206 (message):
  Error generating
  /home/danalelixin/Desktop/opencv-3.2.0/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

老毛病,还是cuda9不支持2.0架构了。/build目录下的cmake中添加指令

D CUDA_GENERATION=Kepler

opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1313:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
         c->flags |= CODEC_FLAG_GLOBAL_HEADER;

opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1525:35: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope

就是ffmpeg新版本对老版本中的一些关键字的支持变了。
打开文件opencv/modules/videoio/src/cap_ffmpeg_impl.hpp ,在里面添加

#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020

重新cmake,有的时候添加语句后,还是没用,可能是添加在文件中的位置不对,换一个位置就好了,建议放在.hpp的最开头

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com