最近需要用用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.3.1 opencv-3.3.1 #复制opencv_contrib到opencv目录下
cd opencv-3.4.21
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
完事!
原文地址:https://www.cnblogs.com/blueridge/p/9510177.html