Configure OpenCV with Vscode under Windows 10 (unpacked and ready-to-use version)

Configure OpenCV with Vscode under Windows 10 (unpacked and ready-to-use version)

Wikipedia:

  The full name of OpenCV is Open Source Computer Vision Library, which is a cross-platform computer vision library. OpenCV is initiated and participated in the development by Intel Corporation. It is released under the BSD license and can be used free of charge in commercial and research fields. OpenCV can be used to develop real-time image processing, computer vision, and pattern recognition programs. The library can also use Intel's IPP for accelerated processing.

Foreword:

  This article is mainly used to record the whole process of using vscode to configure opencv. The tools needed in the whole process include vscode installation package, MinGW-w64 and opencv source code. It is relatively simple to configure opencv in vs studio. The opencv library compiled with the vs studio compiler is already available on the opencv official website. But for vscode, you cannot directly use the opencv library compiled with the vs studio compiler, so you need to recompile the opencv source code with the help of MinGW-w64 and CMake tools. This recompilation process can be said to be full of pits, so this article is equipped with a finished product compiled by the author, and readers can unpack it and use it immediately.

  Then there is the relatively large and heavy vs studio. The lightweight vs code is undoubtedly not a better choice. We can flexibly configure it as our own pertinent development platform according to our needs.

  

1. Preliminary document preparation

download vscode

官网下载即可,就不叙述了,win10选择x86版本,一路next即可
本文vscode安装到了D盘,这个路径无关紧要

Vscode runs opencv (C++) in win10 environment (uncompressed and ready to use)-package No. 1

.vscode.zip  为vscode配置文件
MinGw.zip    vscode为编辑器,并没有编译功能,所以要借助MinGW中的GCC/G++编译C/C++程序
dll.zip      为.exe文件运行时的依赖文件

Vscode runs opencv (C++) in win10 environment (uncompressed and ready to use)-package No. 2

opencv  环境已生成的最终版————解包即用
  • Unzip the two packages
  • The resources are directly uploaded to CSDN, and the author set 0 credits to download , but it seems that it can only be downloaded automatically once during the test, and the second time needs to complete the platform task, but you can choose a simple task to complete and get the download code, so it is not necessary to a minute. ——The download speed of the main CSDN resources is not limited, unlike some cloud, if you don’t eat it, you really won’t let people download it.

  

Two, MinGw.zip and opencv

  After decompressing MinGw.zip and opencv , put it in the root directory of F drive. (The author strongly recommends that this path is consistent with this article, so that subsequent configuration files do not need to be modified, and can be used directly)

insert image description here

Add environment variables

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

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

F:\MinGw\bin

Note: Finally, don’t forget to click OK for each step

insert image description here

  

Three, vscode configuration

  • Open vscode and install the plugin. Note: You may be asked to restart the software during the installation process, just do it

insert image description here

  • Cancel the automatic update of vscode, because its update will overwrite (restore) the installation directory, and the programs and configuration files we will write in the future will be placed in the installation directory. If you want to update vscode in the future, you will need to back up and update manually. (personal habit)

insert image description here

  • Now we can create a new folder in the installation directory, such as OpenCVused as a workspace directory.

insert image description here

  • Then .vscodecopy the files to it, and create a new cppand Debuggerfolder to store the source program and .exe and dependent files we wrote respectively.

insert image description here

  • Then dll.zipcopy the decompressed dependent files Debuggerto

insert image description here

  • Finally, in vscode, file -> open folder - select OpenCV.

insert image description here

  

4. Test

We cppcreate a new source program in the directory. Here is a sample of calling the camera and a sample of displaying pictures, which can be tested by yourself.

F5run

  • Camera sample
#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;
}

insert image description here

  • image sample
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main() {
    
    
    Mat img = imread("D:\\Microsoft VS Code\\OpenCV\\cpp\\G.png");
    resize(img, img, Size(500, 500));
    imshow("img", img);
    waitKey(0);
    system("pause");
    return 0;
}

insert image description here

  • If the program keeps running, the terminal does not pop up, or the parameter error is displayed: Then comment settings.json. This is also a pitfall that the author encountered in the new version of vscode. If these two lines are not commented out, the program will not run without results.

insert image description here

insert image description here

Don't forget to save after commenting

If you feel this article is helpful to you, please like and support

Guess you like

Origin blog.csdn.net/qq_40342400/article/details/128379016
Recommended