下载链接: https://opencv.org/releases.html
//软件源更新
sudo apt-get update
sudo apt-get install build-essential
查看 gcc 版本 然后安装 统一版本的 g++
gcc --version
安装 g++
sudo apt-get install g++-4.4
查看 g++ 版本
g++ --version
//安装cmake、git和pkg-config
sudo apt-get install cmake git pkg-config
//安装jpeg格式图像工具包
sudo apt-get install libjpeg8-dev
//安装tif格式图像工具包
sudo apt-get install libtiff5-dev
//安装JPEG-2000图像工具包
sudo apt-get install libjasper-dev
//安装png图像工具包
sudo apt-get install libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
~$ cd /home/nic/opencv-3.4.2/Release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
如果以下错误:
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
执行以下指令:
sudo apt-get install qt5-default
sudo make
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
#打开后可能是空文件,在文件内容最后添加
/usr/local/lib
sudo ldconfig
sudo gedit /etc/bash.bashrc
# 在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc
# 激活配置然后更新database
sudo updatedb
cmake_minimum_required(VERSION 3.10)
project(demo)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
add_executable(demo main.cpp)
target_link_libraries( demo ${OpenCV_LIBS} )
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat image;
# 必须使用绝对路径
image = imread("/home/nic/20171125154428073.png");
if ( image.empty() )
{
cout<<"No image data!"<< endl;
return -1;
}
namedWindow("Display Image");
imshow("Display Image", image);
waitKey(0);
return 0;
}