opencv4.0 WSL ubuntu 18.04安装

  • 参考知乎文章 (INDEMIND带你玩转OpenCV 4.0)
步骤如下:
  1. 下载opencv source code到本地,解压;
  2. 安装opencv依赖项:
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

如果出现libjasper-dev无法安装提示,可以参考 (stackoverflow)中的提示手动添加 apt repository

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
  1. 进入opencv目录,里面需要有CMakeList文件,执行以下代码,就可以安装完成
mkdir build_dir
rm ./CMakeCache.txt
cd build_dir
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
  1. 下载示例,然后执行编译和运行,查看安装是否正确
g++ -std=c++11 removeRedEyes.cpp `pkg-config --libs --cflags opencv` -o removeRedEyes
./removeRedEyes
  1. 对于wsl的opencv,需要强制命名显示的window名称,否则会出现图片一闪而过的情况
    // Display Result
    namedWindow("Results",CV_WINDOW_AUTOSIZE);
    imshow("Results",imgOut);
    waitKey(0);
    return 0;
  • 备注:参考资料有 learning opencv, ubuntu18.04安装opencv

你可能感兴趣的:(编程)