VSCode configuration opencv4.4.0 under win10 (super detailed tutorial, pro-test effective)

As a lightweight programming software, VSCode outperforms VS in terms of interface, memory usage and speed. But using vscode to write opencv code requires you to compile OpenCV yourself (if you install opencv in VS, you don't need to compile opencv yourself, because there are compiled files on the official website of opencv), mainly using MinGW-w64 and CMake tools. After tossing for a long time, I finally set up the opencv environment and wrote a blog, one is to fear that I will forget it, and to learn again, and the other is to share my experience. Mainly refer to two blogs:

https://www.cnblogs.com/kensporger/archive/2020/02/19/12320622.html

https://blog.csdn.net/zhaiax672/article/details/88971248

1. Install MinGW-w64

MinGW-w64 download address

https://github.com/huihut/OpenCV-MinGW-Build

(Reference blog: https://www.cnblogs.com/kensporger/archive/2020/02/19/12320622.html )

Configure environment variables

2. Install CMake

CMake download address:

https://cmake.org/download/

Configure environment variables

Remember to restart the computer to make the 3 environment variables take effect

3. Generate MakeFiles

You need to go to the official website to download the source files of OpenCV. If the download is too slow, you can find Baidu Netdisk or a domestic mirror website

https://www.bzblog.online/wordpress/index.php/2020/03/09/opencvdownload/

Note: It is to download the source source file corresponding to opencv.
Open CMake-gui.exe and click configure. There will be some problems, mainly because it will be stuck in downloading the ffmpge file. You need to change the host file. At this time, you can only wait patiently. Click configure again, and click generate when finished.

Cmake failed to download the file once, then do it again

4. Compile opencv

CMD to the folder where MakeFiles is located (shift+right click, select powershell to open), execute the minGW32-make command, or use the multi-threaded minGW32-make -j 4 command:

Various errors may appear during the compilation process, don't worry, the main thing is to go back to the third step, remove the check, and click configure, generate again.

Okay, opencv was compiled successfully, and in the end only opencv was configured in VSCode (Boys, not far from the final victory, hold on)

After compiling, remember to enter minGW32-make install to complete the loading, so that the Install folder will be generated.

5.VSCode configuration

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "win",
            "includePath": [
                "${workspaceFolder}/**",
                "D:\\OpenCV4.4.0\\build\\x64\\mingw\\install\\include", 
                "D:\\OpenCV4.4.0\\build\\x64\\mingw\\install\\include\\opencv2"          
            ],
            "defines": [],
            "compilerPath": "C:/Users/chong/Downloads/mingw64/bin/gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

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",
            "miDebuggerPath": "C:/Users/chong/Downloads/mingw64/bin/gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}

tasks.json

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g", 
        "-std=c++11", 
        "${file}", 
        "-o", 
        "${fileBasenameNoExtension}.o",  
        "-I",  "D:\\OpenCV4.4.0\\build\\x64\\mingw\\install\\include",
        "-I",  "D:\\OpenCV4.4.0\\build\\x64\\mingw\\install\\include\\opencv2",
    
        "-L", "D:\\OpenCV4.4.0\\build\\x64\\mingw\\lib",
        "-l", "libopencv_calib3d440",
        "-l", "libopencv_core440",
        "-l", "libopencv_dnn440",
        "-l", "libopencv_features2d440",
        "-l", "libopencv_flann440",
        "-l", "libopencv_gapi440",
        "-l", "libopencv_highgui440",
        "-l", "libopencv_imgcodecs440",
        "-l", "libopencv_imgproc440",
        "-l", "libopencv_ml440",
        "-l", "libopencv_objdetect440",
        "-l", "libopencv_photo440",
        "-l", "libopencv_stitching440",
        "-l", "libopencv_video440",
        "-l", "libopencv_videoio440"
        
  
    ],// 编译命令参数
    "problemMatcher":{
        "owner": "cpp",
        "fileLocation":[
            "relative",
            "${workspaceFolder}"
        ],
        "pattern":[
            {
                "regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
                "file": 1,
                "location": 2,
                "message": 3
            }
        ]
    },
    "group": {
        "kind": "build",
        "isDefault": true
    }
    
 }

The configuration is successful, remember to like it! ! !

Guess you like

Origin blog.csdn.net/Xiao_Xue_Seng/article/details/108552346