按照网上的一篇文章配置opencv的环境,文章链接是https://my.oschina.net/u/4313733/blog/4585043
opencv都编译了(但是编译过程有报一些warning,但好像还是可以进行)
于是到了VScode配置的部分,按教程是配置launch,tasks,c_cpp_properties三个json文件,可能就是其中我的路径写的不对,但我也不知道怎么改,希望大神们可以帮我看看
这是我写的代码:
#include <opencv2\calib3d.hpp>
#include <opencv2\highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat img=imread("man.jpg");
imshow("image",img);
waitKey();
return 0;
}
但是编译似乎不成功:
提示我:fatal error: opencv2\calib3d.hpp: No such file or directory
而我的三个json文件代码如下:
launch.json:
{
"name": "opencv4.5.4 debuge",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\VSCode\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "opencv4.5.4 compile task"
},
tasks.json:
{
"type": "shell",
"label": "opencv4.5.4 compile task",
"command": "D:\\VSCode\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"D:\\opencv\\build\\x64\\mingw\\bin\\libopencv_world454.dll",
"-I",
"D:\\opencv\\build\\include",
"-I",
"D:\\opencv\\build\\include\\opencv2",
"-I",
"",
],
"options": {
"cwd": "D:\\VSCode\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "MinGW64",
"intelliSenseMode": "gcc-x64",
"compilerPath": "D:\\VSCode\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"includePath": [
"${workspaceFolder}",
"D:\\opencv\\build\\include",
"D:\\opencv\\build\\include\\opencv2"
],
"cppStandard": "c++17"
}
],
"version": 4
}
其中D:\VSCode\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe是我g++编译器的位置,位置应该是没有问题的,我写一般的c++程序都没有问题
而我在用Cmake-gui的时候源文件路径和MakeFiles保存路径选择如图:
而路径"D:\opencv\build\include\opencv2"下可以找到需要的c++头文件:
所以不知道json文件要怎么改
求大神指点
opencv安装了吗?
这个报错的hpp文件找一下,有没有,在哪个目录
tasks.json文件里"D:\opencv\build\x64\mingw\bin\libopencv_world454.dll"的上一行少了一个"-I"。