Saturday, 8 August 2015

How to install OpenCV 3.0 and Opencv_contrib in Visual Studio 2012: From Source



Hey guys, if you’ve read my previous post, I installed OpenCV from prebuilt binaries. But the modules in OpenCV 3.0 are limited and if you want to use other features (which you will eventually) like the face module for face recognition you’ll need the opencv_contrib as well.  I didn’t find any reliable sources showing how to install opencv_contrib so after working it out for a lot of time I finally figured it out. The opencv_contrib has many modules and you won’t need all of the features. It takes a lot of memory anyway (and time to install). In this post I’ll show you how to build OpenCV from source and add specific modules from the opencv_contrib which you need.


I suggest you read my previous post and install OpenCV from prebuilt binaries and try a few sample programs before you build from source so you understand the difference. For some reason a lot of my code didn’t work before and threw an exception when I tried debugging it, but it worked in Release mode. I wasted a lot of time trying to figure out why it did. But after I built from source, it worked fine in Debug and Release mode as well. If you have time, go ahead and try it out yourself.



So let’s begin. Download the word file and follow the instructions while watching the video or you can just read it from here and then try it out yourself.








Step 1: Downloading and Installing

Step 2: Building and compiling

  • Go to the Opencv folder you extracted. There are two folders inside, ‘Build’ and ‘sources’. Delete everything inside the build folder. Copy everything from the ‘sources’ folder and paste it outside. Note: Opencv3 is the folder where I extracted opencv for this demonstration. You can extract it directly and it’ll save your folder as opencv by default.
  • If you extracted opencv-master, create a new folder build inside it.
  • Go to the opencv_contrib, from the ‘modules’ folder inside it, choose the modules you want and copy paste them in the Opencv ‘modules’ folder. 
  • Open Cmake. Browse source to the main folder you extracted Opencv 3.0 and browse build to the build folder inside it.

  • Click on configure. It’ll open a new window to select the compiler. If you’re using VS 2012 choose ‘Visual Studio 11’

  • Click on configure
  • Wait for the analysis to be done.
  • After it’s done. Mark appropriate fields as show below.





















  • After you've marked everything, click Generate.
  • This will create an 'OpenCV.sln' file in your build folder. Open it with Visual Studio.
  • In the solution explorer, right click on ALL_BUILD and build. This will take time. Once it's built, change the build mode to RELEASE and repeat the same step 
  • After that, right click on INSTALL and build it, Once it's built, again change the build mode to DEBUG and repeat the same step. 
  • Everything will be created in the 'install' folder.


Step 3: Creating a system variable:
  • Variable name: OPENCV_BUILD
  • Value: C:\opencv3\build
  • Path: C:\opencv3\build\install\x86\vc11\bin


Step 4: Configuration to test a sample project
  •  Open Visual Studio and create a Console Application
  • Right click on the file and click properties
  • Choose Configuration Manager and add x64 platform if your system is x64 (only if your system is x64)
  • At configuration field, choose all configurations
  • At Configuration Properties -> C/C++ -> Additional Include Directories, add opencv include folders

Additional Include Directories:
  • C:\opencv3\build\install\include
  • C:\opencv3\build\install\include\opencv
  • C:\opencv3\build\install\include\opencv2

Note: opencv3 is the folder in which I extracted the files (Check your folder name and folder location)

  • At Configuration Properties -> Linker -> Additional Library Directories, add opencv library folder


Additional Library Directories:
  • C:\opencv\build\install\x86\vc11\lib


  • At configuration field, choose Debug mode
  • At Configuration Properties -> Linker-> Additional dependencies -> add dependence libraries



Additional libraries
opencv_calib3d300d.lib
opencv_core300d.lib
opencv_face300d.lib
opencv_features2d300d.lib
opencv_flann300d.lib
opencv_hal300d.lib
opencv_highgui300d.lib
opencv_imgcodecs300d.lib
opencv_imgproc300d.lib
opencv_ml300d.lib
opencv_objdetect300d.lib
opencv_photo300d.lib
opencv_shape300d.lib
opencv_stitching300d.lib
opencv_superres300d.lib
opencv_ts300d.lib
opencv_video300d.lib
opencv_videoio300d.lib
opencv_videostab300d.lib

Note: These libraries are in the folder- C:\opencv\build\install\x86\vc11\lib
and if you've installed extra modules you'll have to include those libraries as well. This list contains the default libs and the extra 'opencv_face300d.lib' from the face module. 

  • At configuration field, choose Release mode
  • At Configuration Properties -> Linker -> Additional dependencies -> add dependence libraries

Additional libraries
opencv_calib3d300.lib
opencv_core300.lib
opencv_face300.lib
opencv_features2d300.lib
opencv_flann300.lib
opencv_hal300.lib
opencv_highgui300.lib
opencv_imgcodecs300.lib
opencv_imgproc300.lib
opencv_ml300.lib
opencv_objdetect300.lib
opencv_photo300.lib
opencv_shape300.lib
opencv_stitching300.lib
opencv_superres300.lib
opencv_ts300.lib
opencv_video300.lib
opencv_videoio300.lib
opencv_videostab300.lib

Note: These libraries are in the folder- C:\opencv\build\install\x86\vc11\lib
Include extra libraries of the modules you've installed. 

Step 4: Build and Debug




I hope this helps. 



Files for downloading 

Monday, 6 July 2015

How to install OpenCV 3.0.0 in Windows and create a sample program in Visual Studio 2012



Hello!

OpenCV libraries are a great way to get started in Computer Vision and Image processing applications. Plus its FREE!

 It has C++, C , Python and Java interfaces and supports Windows, Mac OS, Linux , iOS and Android. You can check it out here : http://opencv.org/

Installing it can be a little confusing to some people. This is a complete guide which includes a step by step process on how to install it and run a simple code in Visual Studio 2012. 


You can watch the Video on YouTube and Follow the steps below:








Step 1: Downloading and installing


· Download OpenCV 3.0 at: http://opencv.org/downloads.html

· Download Visual studio 2012 at: http://www.microsoft.com/en-in/download/details.aspx?id=34673

· Install Visual studio 2012 and Log in with your Microsoft account if you already have one or you can sign up and register. The software is available for FREE

· Click on Opencv 3.0 and Extract the files to a location






Step 2: Create a system variable:


· Variable name: OPENCV_BUILD

· Value: C:\opencv3\build

· Path: C:\opencv3\build\x86\vc12\bin






Step 3: Configuration


1. Open Visual Studio and create a Console Application

2. Right click on the file and click properties

3. Choose Configuration Manager and add x64 platform if your system is x64 (only if your system is x64)

4. At configuration field, choose all configurations

5. At Configuration Properties - C/C++ - Additional Include Directories, add opencv include folders


Additional Include Directories:


· C:\opencv3\build\include


· C:\opencv3\build\include\opencv


· C:\opencv3\build\include\opencv2


Note: opencv3 is the folder in which I extracted the files (Check your folder name and folder location)









6. At Configuration Properties - Linker- Additional Library Directories, add opencv library folder


Additional Library Directories:

C:\opencv3\build\x86\vc12\lib



7. At configuration field, choose Debug mode


8. At Configuration Properties - Linker- Additional dependencies- add dependence libraries


Additional libraries


opencv_ts300.lib


opencv_ts300d.lib


opencv_world300.lib


opencv_world300d.lib


Note: These libraries are in the folder- C:\opencv3\build\x86\vc12\lib



9. At configuration field, choose Release mode


10. At Configuration Properties -Linker - Additional dependencies - add dependence libraries


Additional libraries


opencv_ts300.lib


opencv_ts300d.lib


opencv_world300.lib


opencv_world300d.lib


Note: These libraries are in the folder- C:\opencv3\build\x86\vc12\lib




Step 4: Build and Debug


· I have given a sample code.


· Copy -paste it and build it. And debug.




Note: In case there is an error like the '.Dll' file is missing,  Go to Environmental variables and check the path again and restart your computer.

It should work. 


If you want to use extra features available in the contrib_module , then you'll need to build the extra modules from source using cmake. I'll be writing another post showing how to do that.  
If  this was helpful please subscribe and If you have any questions feel free to comment or you can mail me