Configuring OpenCV 3.1 and Visual Studio 2015

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

  1. Assume that you’ve installed VS2015
  2. Download the newest OpenCV library from here. In my case version 3.1 in .exe format.
  3. Extract the .exe file by clicking it.
  4. Copy the extracted file into C:// drive
  5. Configure the windows environment variable (System Properties -> Advances system settings -> Environment Variable…):
    1. Add new variable OPENCV_DIR with Value the directory of VC14 bin (C:\opencv\build\x64\vc14\bin)
    2. 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.

  1. Create Property Sheet for OpenCV 3.1
    1. Click View -> Other Windows -> Property Manager
    2. Right Click in the Project Name -> Add New Project Property Sheet
    3. Give it name, for me OpenCV3.1
  2. Setting VC++ Directories
    1. Include Directories : C:\opencv\build\include
    2. Library Directories: C:\opencv\build\x64\vc14\lib
  3. Setting Linker
    1. 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

 

One thought on “Configuring OpenCV 3.1 and Visual Studio 2015

  1. Sanne

    If we just started treating the PETA people like the terrorists they are, a lot of this would go away.I propose a bill making every PETA member and financial contributor a mandatory organ donor, with the organs to be harvested at any time convenient before or after death, and mandatory volunteers for medical expnnimertatioe. Think of all the rabbits we could save by doing cancer research on live PETA members.We could then eat the rabbits. They are quiite tasty.

Leave a Reply

Your email address will not be published. Required fields are marked *