Jetson Nano是非常常用的nvidia深度学习开开发板,其已经配置了opencv4.1.1,并已经安装了VSCode,由于项目需要本人必须应用VSCode中进行C++的编译。
Jetson Nano自带的系统中opencv的安装位置与网上常用的VSCode中都不相同,造成了很大的困扰。经过不断的尝试终于配置好了相关的环境,为了避免各位踩坑,本文给出自己的配置过程,并给出配置需要的文件,将其展现出来供大家参考。
首先,配置C++的编译环境。
第二,新建文件夹编写代码,用vs code打开。
第三、编写launch.json
vscode左侧方的debug按钮–Debug -> Open Configurations -> 打开备选框 -> C++(GDB/LLDB) -> g++ build and debug active file。打开launch.json文件并且修改为:
{
"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
}
]
}
]
}
第四、编写tasks.json
按键ctrl+shift+P,输入选择Configure Task,在备选框中选择C/C++:cpp build active file选项,则新建一个tasks.json文件。
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g", "-std=c++11", "${file}", "-o", "${fileBasenameNoExtension}.o",
"-I", "/usr/include/opencv4/opencv2",
"-I", "/usr/include/opencv4",
"-L", "/usr/lib/aarch64-linux-gnu",
"-l", "opencv_core",
"-l", "opencv_imgproc",
"-l", "opencv_imgcodecs",
"-l", "opencv_video",
"-l", "opencv_ml",
"-l", "opencv_highgui",
"-l", "opencv_objdetect",
"-l", "opencv_flann",
"-l", "opencv_imgcodecs",
"-l", "opencv_photo",
"-l", "opencv_videoio"
],// 编译命令参数
}
]
}
第五、编写c_cpp_properties.json
Ctrl + Shift + P 打开搜索框,键入c++,会出现备选项目,选择图示Edit configurations (JSON),并且将c_cpp_properties.json修改为:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/opencv4", //opencv2头文件夹安装在这个目录
"/usr/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
最后,结束语
其实,配置Jetson Nano中Ubuntu环境下VScode OpenCV的C++开发环境最重要的是opencv的安装路径,大家可以自己去查询,并更改上述文件中的路径。