小弟最近想用VS Code 建置Open CV(C++)環境,但是爬了很多文卻一直架不起來,希望能有大大能幫助我。希望能回答的愈詳細越好,包括:
在fysh711426大大的幫助下,本問題已解決。
本人的配置方法:https://github.com/chenyus0609/opencv-configuration-with-vscode
目前測試結果(失敗)
C:\MinGW\bin
和 C:\opencv\bin
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"C:\\MinGW\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++",
"C:\\opencv\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=5",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++",
"C:\\opencv\\include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
tasks.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}.exe",
"-I","C:\\opencv\\include",
"-L","C:\\opencv\\bin",
"-llibopencv_calib3d341",
"-llibopencv_core341",
"-llibopencv_dnn341",
"-llibopencv_features2d341",
"-llibopencv_flann341",
"-llibopencv_highgui341",
"-llibopencv_imgcodecs341",
"-llibopencv_imgproc341",
"-llibopencv_ml341",
"-llibopencv_objdetect341",
"-llibopencv_photo341",
"-llibopencv_shape341",
"-llibopencv_stitching341",
"-llibopencv_superres341",
"-llibopencv_video341",
"-llibopencv_videoio341",
"-llibopencv_videostab341"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
不過還是失敗了,雖然有編譯成功,但執行會出錯。
我試了你的方法了,好像抓的到<opencv2/opencv.hpp>,
因為intellisense 有提示出來,開心~
但是沒有編譯成功QQ
dll file not recognized file format not recognized
上網查了一下,如果把tasks.json 中的這部分:
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe"
]
改成
"args": [
"-c", //change!!
"${file}",
"-o",
"${fileBasenameNoExtension}.exe"
]
則會變成:
還是不行
我最後成功了,謝謝您!
以下是我的配置方法:https://github.com/chenyus0609/opencv-configuration-with-vscode
原來要安裝 MinGW-64,MinGW 缺少了一些 dll。libwinpthread-1.dll