在linux下安装OpenCV已经在之前的笔记写过了,这里再附上官网教程:https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
由于从windows那里过来,终端下使用vi+gcc去调试代码臣妾实在做不到,然而巨硬为我们带来了漂亮简单的vscode。
vscode去编译opencv很简单,如果选用c++去编写源文件的话需下载C/C++组件。
然后在文件夹里添加.cpp文件,调试选择GDB/C++,vscode会自动生成task.json,launch.json
对于launch.json的编写如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.o",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
${workspaceFolder}表示当前工作目录,{fileBasenameNoExtension}表示当前文件名,不包括扩展
"program": "${workspaceFolder}/${fileBasenameNoExtension}.o",表示生成的执行文件在当前目录下,和当前文件同名,只是扩展为.o;例如本教程会生成opencv_test.o执行文件。
"preLaunchTask": "build",是默认launch.json中没有的,表示执行文件前需要的编译任务。具体的任务内容我们在task.json中定义。
${workspaceFolder} :表示当前workspace文件夹路径,也即C:\Users\admin\Desktop\test
${workspaceRootFolderName}:表示workspace的文件夹名,也即test
${file}:文件自身的绝对路径,也即C:\Users\admin\Desktop\test\.vscode\launch.json
${relativeFile}:文件在workspace中的路径,也即.vscode\launch.json
${fileBasenameNoExtension}:当前文件的文件名,不带后缀,也即launch
${fileBasename}:当前文件的文件名,launch.json
${fileDirname}:文件所在的文件夹路径,也即C:\Users\admin\Desktop\test\.vscode
${fileExtname}:当前文件的后缀,也即.json
${lineNumber}:当前文件光标所在的行号
${env:PATH}:系统中的环境变量
task.json配置如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [ "-g", "${file}","-o","${fileBasenameNoExtension}.o",
"-I","/usr/local/include",
"-I","/usr/local/include/opnecv",
"-I","/usr/local/include/opnecv2",
"-L","/usr/local/lib",
"-l","opencv_core",
"-l","opencv_highgui",
"-l","opencv_imgproc",
"-l","opencv_imgcodecs"
]
}
]
}
"label": "build"表示以下是名为build的任务配置
"command": "g++",表示调用的编译器是g++
args表示command的命令,其中“-I”表示包含目录,"-L"表示库目录路径,"-l"表示库文件,
转载于:https://www.jianshu.com/p/c919cfba8f7e