ubuntu 编译opencv
时间: 2023-09-18 18:12:27 浏览: 134
在Ubuntu上编译OpenCV,您可以按照以下步骤进行操作。
首先,确保您的Ubuntu版本至少是18.04。然后,安装必要的编译环境和依赖项。使用以下命令安装gcc、g++、cmake、wget和unzip:
```
sudo apt-get install gcc g++ cmake wget unzip
```
接下来,安装OpenCV的依赖项。使用以下命令安装所需的库:
```
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev libgtk2.0-dev pkg-config
```
完成安装后,您可以开始编译OpenCV。您可以使用您引用的两个示例编译命令之一。请注意,这些命令假定您已经下载了OpenCV源代码并将其解压到指定的路径:
```
g++ main.cpp -std=c++11 -I /home/ljy/Desktop/opencv/install/include/opencv4/ -L /home/ljy/Desktop/opencv/install/lib/ -lopencv_stitching -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
```
或者
```
g++ main.cpp -std=c++11 -I /home/lhy/Desktop/opencv-master/install/include/opencv4/ -L /home/lhy/Desktop/opencv-master/install/lib/ -lopencv_stitching -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
```
这些命令将编译名为main.cpp的源代码文件,并链接所需的OpenCV库。请确保您的源代码文件名正确,并且库的路径与您的实际安装路径匹配。编译成功后,您将获得一个可执行文件。
希望这可以帮助您在Ubuntu上成功编译OpenCV!<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Ubuntu下编译OpenCV](https://blog.csdn.net/lookingyee/article/details/120945283)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Ubuntu下编译Opencv](https://blog.csdn.net/m0_63228448/article/details/120945279)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Ubuntu 安装编译 opencv](https://blog.csdn.net/m0_59161987/article/details/127780662)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文