python3-opencv and python-opencv 安装
For most people, the easiest way to install OpenCV on Ubuntu is to install it using the apt package management tool. If you want to install the latest stable version of OpenCV from source, scroll down to the Installing OpenCV from the Source section of this tutorial.
对于大多数人而言,在 Ubuntu 上安装 OpenCV 的最简单方法是使用 apt 软件包管理工具进行安装。如果要从源代码安装最新的稳定版 OpenCV,请从本教程的源代码部分向下滚动到安装 OpenCV。
1. Install OpenCV from the Ubuntu Repository
- Refresh the packages index and install the OpenCV package by typing:
Python3
sudo apt update
sudo apt install python3-opencv
Python2
sudo apt update
sudo apt install python-opencv
The command above will install all packages necessary to run OpenCV.
- To verify the installation, import the
cv2
module and print the OpenCV version:
python3 -c "import cv2; print(cv2.__version__)"
python2 -c "import cv2; print(cv2.__version__)"
2. Installing OpenCV from the Source
Building the OpenCV library from source is the recommended way of installing OpenCV. It will be optimized for your particular system and you will have complete control over the build options.
从源代码构建 OpenCV 库是安装 OpenCV 的推荐方法。它将针对您的特定系统进行优化,并且您将完全控制构建选项。
mkdir ~/opencv_build && cd ~/opencv_build
References
https://www.docs.opencv.org/4.2.0/d7/d9f/tutorial_linux_install.html
https://linuxize.com/post/how-to-install-opencv-on-ubuntu-18-04/