第一步:准备工作
安装依赖
- 基本库安装
sudo apt install cmake qt5-default gcc g++ libxslt1-dev libffi-dev \
at-spi2-core libavresample-dev libavresample4 python3 \
python3-dev python3-numpy python3-pip -y
sudo ln -s .
- 安装libjasper
# 方法1:不推荐
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev -y
# 方法2:手动编译
git clone https://github.com/jasper-software/jasper.git -b version-3.0.6
cd jasper/build
sudo ln -s /usr/bin/python3 /usr/bin/python
./build --release --install-dir /usr/local
cd ../tmp_cmake/build
# 然后将/usr/local/lib添加到系统环境,例如
sudo vim /etc/ld.so.conf.d/jasper.conf
# 内容如下:
/usr/local/lib
- 基本依赖安装
sudo apt install build-essential libncursesw5-dev libgdbm-dev libc6-dev \
zlib1g-dev libsqlite3-dev tk-dev \
libssl-dev openssl libffi-dev \
libblas-dev liblapack-dev gfortran \
build-essential git libgtk2.0-dev pkg-config libavcodec-dev \
libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev \
libpng-dev libtiff-dev libdc1394-22-dev -y
- 基本依赖安装
sudo apt install nasm libtool libgtk-3-dev libgtk2.0-dev \
libavutil-dev libswscale-dev libasound2-dev libspeex-dev \
v4l-utils libopenexr-dev libavcodec-dev libavformat-dev \
libswscale-dev libgstreamer-plugins-base1.0-dev \
libgstreamer1.0-dev -y
- 安装openjpeg。
git clone https://github.com/uclouvain/openjpeg
cd openjpeg
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
sudo make install
安装工作
-
下载源码(直接下载git是预览版,去releases下载是正式版)。opencv,opencv_contrib
-
解压到你想要的任意文件夹,但是建议两个文件夹解压后放同级路径。
- 修改一下opencv下面的CMakeLists.txt
文件,开头加入下面这句,防止可能发生的找不到系统so文件。
shell~~ ~~set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu")~~ ~~
安装OpenCV到系统环境
- 如果要把opencv安装到系统环境,默认安装路径为/usr/local。默认安装到Python2,当然我们需要用它安装到python3。下面以python3.9为例。
- 建议先把conda环境deactive,防止误识别。
- 直接用apt安装python3 python3-pip python3-numpy