opencv3.4.2 ubuntu16.04安装

Posted blueridge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv3.4.2 ubuntu16.04安装相关的知识,希望对你有一定的参考价值。

最近需要用用opencv。在阿里云服务器ubuntu16.04上安装部署了下。

 

没啥好说的,下载最新opencv-3.4.2 

文件准备

1.opencv-3.4.2.zip 
2. opencv_contrib-3.4.2.zip

(我是放在/home/myname/download/下)然后

wget https://github.com/Itseez/opencv/archive/3.4.2.zip

wget https://github.com/opencv/opencv_contrib/archive/3.4.2.zip

准备

先安装以下依赖包

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 libtiff-dev libjasper-dev libdc1394-22-dev  

sudo apt-get install build-essential qt5-default ccache libv4l-dev libavresample-dev  libgphoto2-dev libopenblas-base libopenblas-dev doxygen  openjdk-8-jdk pylint libvtk6-dev

sudo apt-get install pkg-config

1.解压下载好的包:(我是放在/home/myname/download/下)然后

unzip opencv-3.4.2.zip
unzip opencv_contrib-3.4.2.zip

2.解压完后需要将opencv_contrib.zip提取到opencv目录下,同时在该目录下新建一个文件夹build:

cp -r opencv_contrib-3.4.2 opencv-3.2.2  #复制opencv_contrib到opencv目录下

cd opencv-3.4.2

mkdir build                              #新建文件夹build

编译

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.2/modules -D PYTHON_EXECUTABLE=/usr/bin/python3 -D BUILD_EXAMPLES=ON ..

 

make时出现错误:

 /usr/local/include/tesseract/baseapi.h: In member function ‘int tesseract::TessBaseAPI::Init(const char*, const char*)’:
/usr/local/include/tesseract/baseapi.h:235:50: error: ‘nullptr’ was not declared in this scope
     return Init(datapath, language, OEM_DEFAULT, nullptr, 0, nullptr, nullptr, false);
                                                  ^
/usr/local/include/tesseract/baseapi.h: In member function ‘Boxa* tesseract::TessBaseAPI::GetTextlines(Pixa**, int**)’:
/usr/local/include/tesseract/baseapi.h:413:51: error: ‘nullptr’ was not declared in this scope
     return GetTextlines(false, 0, pixa, blockids, nullptr);
                                                   ^
/usr/local/include/tesseract/baseapi.h: In member function ‘Boxa* tesseract::TessBaseAPI::GetComponentImages(tesseract::PageIteratorLevel, bool, Pixa**, int**)’:
/usr/local/include/tesseract/baseapi.h:464:75: error: ‘nullptr’ was not declared in this scope
     return GetComponentImages(level, text_only, false, 0, pixa, blockids, nullptr);
                                                                           ^
modules/text/CMakeFiles/opencv_text_pch_dephelp.dir/build.make:62: recipe for target \'modules/text/CMakeFiles/opencv_text_pch_dephelp.dir/opencv_text_pch_dephelp.cxx.o\' failed
make[2]: *** [modules/text/CMakeFiles/opencv_text_pch_dephelp.dir/opencv_text_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:13717: recipe for target \'modules/text/CMakeFiles/opencv_text_pch_dephelp.dir/all\' failed
make[1]: *** [modules/text/CMakeFiles/opencv_text_pch_dephelp.dir/all] Error 2
Makefile:160: recipe for target \'all\' failed
make: *** [all] Error 2
 
 
原因是C11选项未打开。修改
 opencv-3.4.2目录下面CMakeLists.txt 参考上图,添加一行即可。从新CMake


然后 编译:
make
然后:
sudo make install

完事!

打赏:

 




 
 

以上是关于opencv3.4.2 ubuntu16.04安装的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu系统---安NVIDIA 驱动后 CUDA+cuDNN 安装

Win7+VS2017+OpenCV3.4.2无痛安装,Win10应该也差不多

ubuntu-16.04 详细安装教程(图文)附下载地址

opencv3 学习 一

ubuntu 16.04 安装 phpmyadmin 404

ubuntu16.04快速安装LNMP