Vscode configuration opencv (simple)

1. Preparation:

Resource
extraction code: iemf

Mingw, compilation tool
Opencv software
insert image description here

1. Unzip MinGw.zip, opencv.zip F (unzip, remember the location) I am F here
insert image description here

2. Add environment variables

​ F:\opencv\build\x64\vc15\bin

F:\opencv\build\x64\MinGw\bin

F:\MinGw\bin

​ The F here changes its own pathinsert image description here

Two, vscode configuration

1、launch.json

(self-configured property: miDebuggerPath)

{

    "version": "0.2.0",
    "configurations": [
        {
            "name": "opencv debuge",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\Debugger\\${fileBasenameNoExtension}.exe",
            //上面这个Debugger是我自己定义的,为了方便放置生成的exe文件
            "args": [],
            "stopAtEntry": false, //这里如果为 false,则说明调试直接运行。(反之则停止)
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//是否调用外部cmd
            "MIMode": "gdb",
            "miDebuggerPath": "F:\\MinGw\\bin\\gdb.exe",//自己进行设置
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "opencv3.5.2"
        }
    ]
}

2、c_cpp_properties.json

The first one of includePath should not be changed, and the latter should be set as your own path.

{
    "configurations": [
        {
            "name": "win",
            "includePath": [
                "${workspaceFolder}/**",
                "F:/opencv/build/x64/mingw/install/include",
                "F:/opencv/build/x64/mingw/install/include/opencv2"
            ],
            "defines": [],
            "compilerPath": "F:MinGw/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

3、tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "opencv3.5.2",
            "command": "F:/MinGw/bin/g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}\\Debugger\\${fileBasenameNoExtension}.exe",
                //上面这个Debugger是我自己定义的,为了方便放置生成的exe文件
                "F:/opencv/build/x64/mingw/bin/libopencv_world452.dll",
                "-I",
                "F:/opencv/build/x64/mingw/install/include",
                "-I",
                "F:/opencv/build/x64/mingw/install/include/opencv2",
            ],
            "options": {
                "cwd": "F:/MinGw/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

For the .vscode in the article, students who decompress it under F can use it directly, and those
who decompress it in other paths need to modify it
insert image description here

3. Test

We have to create the Debugger folder in the file just now. The automatically generated exe file will be placed inside.
The execution of exe files requires dependent files. We also need to put the dependent files in this folder, so that the dependencies can be called without error when generating the exe file. Without this dependency, the exe file cannot be generated.

Find the dependency file: There are two ddl files in
F:\opencv\build\x64\MinGw\install\x64\mingw\bin :

( You can also use the ddl file in the file )

libopencv_world452.dll
opencv_videoio_ffmpeg452_64.dll

Readers also go to a similar directory to find, and then copy the file to the Debugger directory.

Then create a test file: (call the camera)
If the reader has an opencv foundation, you can test it yourself. I provide a cpp file for testing the camera.


#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    VideoCapture cap(0);
    Mat img;

    while (1)
    {
        cap >> img;
        if (img.empty())
            break;
        namedWindow("img", WINDOW_NORMAL);
        imshow("img", img);
        if (27 == waitKey(20))
            break;
    }

    return 0;
}

Press F5 to run

If you don't understand, you can watch this

Vscode configuration opencv full version

Guess you like

Origin blog.csdn.net/qq_45022687/article/details/120949170