OpenCV搭建时密钥过期
创建配置文件来禁用 APT 签名验证
创建一个新的配置文件来禁用 APT 的签名验证:
sudo nano /etc/apt/apt.conf.d/99disable-signature-verification
在文件中添加以下内容:
Acquire::AllowInsecureRepositories "true"; Acquire::AllowDowngradeToInsecureRepositories "true"; APT::Get::AllowUnauthenticated "true";
保存并退出 (Ctrl + X
,然后按 Y
,最后按 Enter
)。
随后更新软件源
sudo apt-get update
安装替代软件包
sudo apt-get install libjpeg62-turbo-dev libtiff4-dev libpng-dev
编译安装OpenCV
# 下载 OpenCV 和 OpenCV_contrib
cd ~
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
# 创建构建目录并编译 OpenCV
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..
make -j4
# 安装 OpenCV
sudo make install
sudo ldconfig
最后验证
import cv2
print(cv2.__version__)