ubuntu安装c++版的opencv
时间: 2024-10-07 18:07:20 浏览: 27
Ubuntu22.04安装教程以及Ubuntu下C++环境配置
在Ubuntu系统上安装C++版本的OpenCV通常需要几个步骤。首先,确保已经更新了系统的软件包列表并安装必要的依赖项:
1. 打开终端(Ctrl+Alt+T):
```sh
sudo apt update && sudo apt upgrade
```
2. 安装基本的开发工具和库(包括build-essential git cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev x264 v4l-utils libgtk-3-dev libatlas-base-dev gfortran python3-dev python3-numpy
```
3. 添加OpenCV的官方ppa(Personal Package Archive):
```sh
sudo add-apt-repository ppa:ubuntu-opencv/unstable -y
```
4. 更新软件源并安装OpenCV:
```sh
sudo apt update
sudo apt install libopencv-dev opencv-contrib-dev
```
5. 验证安装(可以创建一个简单的Hello World程序来检查是否成功):
```cpp
#include <opencv2/opencv.hpp>
int main() {
cv::Mat img = cv::imread("path_to_your_image.jpg");
if (img.empty()) {
std::cout << "Failed to load image!" << std::endl;
} else {
std::cout << "Image loaded successfully!" << std::endl;
}
return 0;
}
```
阅读全文