centOS7下vscode怎么调用opencv
时间: 2023-08-18 22:59:38 浏览: 116
在CentOS 7下,你可以按照以下步骤配置VSCode来调用OpenCV:
1. 安装OpenCV库:在CentOS 7系统中,可以使用以下命令安装OpenCV库:
```
sudo yum install opencv opencv-devel
```
2. 安装VSCode:在官网上下载VSCode的Linux版本,然后解压缩到指定目录。
3. 安装C++插件:打开VSCode,点击左侧的扩展图标(或者按下Ctrl+Shift+X),搜索并安装C++插件。
4. 配置编译器:打开一个C++文件,按下Ctrl+Shift+B,选择“配置任务”,然后选择“C++编译器”,在弹出的窗口中输入以下内容:
```
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/usr/include/opencv4",
"-L/usr/lib64",
"-lopencv_core",
"-lopencv_highgui",
"-lopencv_imgproc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
```
5. 配置OpenCV库:打开一个C++文件,按下Ctrl+Shift+P,选择“C++: Edit Configurations”,在弹出的窗口中输入以下内容:
```
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/opencv4"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
```
6. 编写代码:在VSCode中打开一个C++文件,然后编写OpenCV代码,例如:
```cpp
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
Mat img = imread("test.jpg");
imshow("Image", img);
waitKey();
return 0;
}
```
7. 编译运行:在VSCode中按下Ctrl+Shift+B,选择“build”,然后在终端中输入以下命令运行程序:
```
./test
```
以上就是在CentOS 7下使用VSCode配置OpenCV的步骤。
阅读全文