Visual Studio 2019 configures OpenCV

Add the include directory where include is located

D:\Program\OpenCV\build\include
D:\Program\OpenCV\build\include\opencv2

Add library directory

  • The 2015 version of VS selects vc14, the 2017 version of VS selects vc15, the 2019 version of VS selects vc16, the 2022 version of VS selects vc17,
D:\Program\OpenCV\build\x64\vc16
D:\Program\OpenCV\build\x64\vc16\lib 

add dependencies

  • Properties - Linker - Input - Additional Dependencies

  • Find the version of OpenCV in the path of D:\Program\OpenCV\build\x64\vc16\lib,
  • "Additional dependencies" fill in "opencv_world470.lib", use it in Debug mode with d.lib, use it in Release model without d.lib, I use release directly, so choose the one without d, copy the file name opencv_world470.lib, paste here

  • The above opencv environment configuration is completed, pay attention to select Debug x64 when programming

Finally use the following code to test

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
    Mat image;
    image = imread("D:/VScode/luna.jpg", IMREAD_COLOR); // Read the file
    if (image.empty()) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }
    namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image); // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}


n 0;
}

- [外链图片转存中...(img-vDV4aVEi-1686379503455)] 
## 

Guess you like

Origin blog.csdn.net/u014723479/article/details/131141939