Download OpenCV from link (choose Win Pack, latest version). Extract anywhere on hard drive, in this example I am using ("C:\OCV4").
Start Visual Studio and create new project.
Recommended Visual Studio extension: Image Watch
Choose 'Windows Console Application' under 'Visual C++', give your project a name and confirm 'OK'
Open configuration manager, and open edit menu for active platform.
Select and delete x86 configuration by clicking 'Remove'
Right click on project name and choose 'Properties'
In configuration combo box, choose 'All configurations'
Under configuration property 'VC++ Directories' change include and library directories
Include: LOCAL_OPENCV_FOLDER\opencv\build\include
Library: LOCAL_OPENCV_FOLDER\opencv\build\x64\vc15\lib
Remember to append each path with semicolon(';')
Change configuration to 'Debug', under Linker -> Input, insert additional dependency 'opencv_world401d.lib'
Change configuration to 'Release' and insert additional dependency 'opencv_world401.lib'
Paste following code into your entry point CPP file and build solution (F7). You should now be able to build both in Debug and Release configuration.
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat image = cv::Mat(100, 500, CV_8UC3, cv::Scalar(0));
cv::putText(image, "Hello world !", cv::Point(50, 50), cv::FONT_HERSHEY_PLAIN,
1.0, cv::Scalar(0, 255, 0));
cv::imshow("image", image);
cv::waitKey();
return 0;
}
In runtime your executable will depend on Open CV DLLs, so they need to be copied to the output directory.
DLLs location: LOCAL_OPENCV_FOLDER\opencv\build\x64\vc15\bin (C:\OCV4\opencv\build\x64\vc15\bin)
For Debug: copy 'opencv_world401d.dll' -> SOLUTION_DIRECTORY\x64\Debug
For Release: copy 'opencv_world401.dll' -> SOLUTION_DIRECTORY\x64\Release
Now you should be able to run your project (F5) in both configurations.