- 在树莓派上连好网,安装好vscode,安装好opencv4
- 打开vscode安装扩展,C/C++, c++Intellisense,C/C++Extension Pack
- 创建一个项目文件夹在vscode里打开
- ctrl+shift+P 添加配置任务tasks.json
{ //> 编译多个文件 "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++ build active file", "command": "g++", "args": [ "-g","-std=c++11", "${fileDirname}/*.cpp", "-o", "${fileDirname}/${fileBasenameNoExtension}", "`pkg-config", "--cflags", "--libs", "opencv`", ], "options": { "cwd": "/usr/bin" }, "problemMatcher": [ "$gcc" ], "group": "build" } ] }
这里主要添加了 "`pkg-config", "--cflags", "--libs", "opencv`",
- 再ctrl+shift+P配置任务
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "/usr/local/include/opencv4" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "gnu17", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-arm" } ], "version": 4 }
添加了 opencv4的目录
-
点击配置或调试添加launch.json
{ "version": "0.2.0", "configurations": [ { "name": "g++ build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] }
-
好了,写段代码测试一下
#include <iostream> #include <opencv2/opencv.hpp> #include <string> using namespace std; using namespace cv; int main() { cout << "Hello" << endl; Mat img = imread("mm.jpg"); imshow("Test OpenCV", img); waitKey(0); destroyAllWindows(); return 0; }
-
对了,还要在项目文件夹存一张图。
-
结束
PI vscode opencv c++
最新推荐文章于 2023-06-02 15:36:22 发布