Create OpenCV property sheets in Visual Studio to store properties



OpenCV is a very famous open source image processing library. Most of the Windows users are using OpenCV on Visual Studio IDE which provides C/C++ coding. Anyway You have to set some properties in each and every Visual Studio project, if you need to use OpenCV. This is very hard to me :). Because we have to set number of properties each and every times when you are creating a new project.

The solution for this is "Create a property sheet which can hold all the OpenCV properties". Following steps will describes How to create an OpenCV property sheet in Visual Studio 2013.


Step 1 - Create a new C++ project

You can follow normal steps to create a new C++ project. File --> New --> Project

Step 2 - Create new property sheet

First you have to open "Property Manager" window to manage all the property sheets for this project. Click on View --> Other Window --> Property Manager.

Then you will see a window similar to following window.
Here we have to create 2 property sheets for Debug and Release. Also If your project is 64 bit then you will have another 2 items as "Debug | x64" and "Release | x64", then you have to create two 64 bit property sheets separately. Anyway this article will guide you to create 32 bit property sheets.

Now Right click on "Debug | Win32" and select "Add New Project Property Sheet..." and give a name for your property sheet (Here I am using OpenCVDebug as the name).
Then you will see your new property sheet on Property Manager.

Step 3 - Set OpenCV properties (Debug)

Now we are going to set all the opencv properties for Debug mode. Right click on your new Property sheet and select Properties. There are 3 things that you have to set in here.
  1. OpenCV include directory
  2. OpenCV library directory
  3. OpenCV libraries

1. Setting OpenCV include directories

Go to General tab under C/C++ and click on Edit  under Additional Include Directories. Now set the directory path of your opencv include directory. (You can find this directory under build folder in opencv folder)

2. Setting OpenCV library directory

Go to General tab under Linker and add a new directory path for the Additional Library Directories as the library directory which includes 32bit lib files for your compiler version. Here I am using Visual Studio 2013 therefore I have to select vc12 and x86 since I am crating 32bit application.

3. Setting OpenCV libraries

Go to Input tab under Linker to set libraries for the opencv. Click Edit on Additional Dependencies and enter all the lib files' names which are ended with d (for an example opencv_core2410d.lib) inside your lib directory that you mentioned on "Setting Opencv library directory" step. Here stands for Debug.
Now all the properties have set to build an opencv project in Debug mode. If you need to build in Release mode you have to create a new separate property sheet under Release | Win32  and follow same steps as I mentioned above to set properties except 3rd step. Here you have to enter all the lib file names which are not ended with d (for an example opencv_core2410.lib)

Step 4 - Save and reuse Property sheets

Now click on Save button on the Property Manager to save your property sheets. Then you can find your property sheets where you saved (Here project folder).
Now assume that you have created a new Visual Studio OpenCV project, then you don't need to set all these properties again and again. You just needed to import these properties from these saved property sheets by clicking on "Add Existing Property Sheet..". So all the properties will be automatically set for your project. This is too easier than just setting these properties repeatably.
Thanks for reading this article and hope this will increase your developing speed !


Continue Reading...