This is not a new thing actually, and as far as I remember this is my second time configuring this. However, I found problem on myself 😐 I keep forgeting how to configure and connect openCV library with VS2015, especially in C++ language. As we know the environment is different than C# environment. So I decided to create one post for my own documentation. Because everytime I tried new installation, I keep facing the similar error but I forgot how to solve it and ended up with googling over the same problem so many time.
Configuring OpenCV 3.1 with VS2015
- Assume that you’ve installed VS2015
- Download the newest OpenCV library from here. In my case version 3.1 in .exe format.
- Extract the .exe file by clicking it.
- Copy the extracted file into C:// drive
- Configure the windows environment variable (System Properties -> Advances system settings -> Environment Variable…):
- Add new variable OPENCV_DIR with Value the directory of VC14 bin (C:\opencv\build\x64\vc14\bin)
- Add value to “Path” variable with C:\opencv\build\x64\vc14\bin
Calling the openCV library from VS2015 IDE
If you decide to use C++, you have to setting the properties everytime you create new project. To make it easy, create property sheet so that you can import it for other project.
- Create Property Sheet for OpenCV 3.1
- Click View -> Other Windows -> Property Manager
- Right Click in the Project Name -> Add New Project Property Sheet
- Give it name, for me OpenCV3.1
- Setting VC++ Directories
- Include Directories : C:\opencv\build\include
- Library Directories: C:\opencv\build\x64\vc14\lib
- Setting Linker
- Click Input -> Additional Dependencies -> Add opencv_world310d.lib (for Debug)
Testing OpenCV Hello World
Write following code to test whether it has been linked or not. Put your tested image into your project folder to make it easy, or change the imread directory as per your image location.
#include "stdafx.h"
#include <opencv2\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include
int main(int argc, char** argv)
{
cv::Mat image;
image = cv::imread("takanyan.jpg");
cv::imshow("testing",image);
cvWaitKey(0);
return 0;
}
Voila~ done.
TroubleShooting
- Cannot find or open the PDB file
Change the Setting of Microsoft Symbol. Tools -> Options -> Debugging -> Symbols and check “Microsoft Symbol Servers”
- Target Platform related error
Change the target platform into x64