loading...
  1. (Step by Step) Install OpenCV 3.3 with Visual Studio 2015 on Windows 10 x64 (2017 DIY)

(Step by Step) Install OpenCV 3.3 with Visual Studio 2015 on Windows 10 x64 (2017 DIY)

Hey Friends,

I am starting my own blog series on OpenCV Development Tutorials and this being my first post. As many of you may have wondered, the most difficult and frustrating part of working on any programming language is not to learn how to code but how to correctly setup your environment. Over the years of my programming experience, i have always hated scenario’s where i am troubleshooting or diagnosing environment build issues from setting up the environment variables to correctly building the libraries from source. My intention using blog as a medium of communication is to *NOT WASTE* anymore precious time of yours and get you up and running smoothly.

First thing first, it is very important to note that for OpenCV there are two options available as a part of build process.

a) Using the Pre-Built Libraries

b) Compiling from the Source

While, the former used to be my favorite approach uptill version 2.10, i later realized that latter should be your approach because 1) Pre-built libraries won’t work straight out visual studio 2015 and 2)  it gives you more clarity with your build environment and also makes you feel more comfortable with the technology when you start things from scratch.

Without any further delay, let’s start the process. In this blog post, we’ll focus on #b.

I. Pre-Requisites

  • Visual Studio 2015 (Community or Professional or Express)
  • OpenCV 3.3 Libraries (Download Here)

It has two folders:
Build – this contains the includes; also the prebuilt libs and dlls that work with a particular version of Visual Studio.
Sources – source code for OpenCV; also contains sample code and data

II. Installation

  1. Validate Visual Studio 2015

First, make sure you have a working Visual Studio 2015 setup. In order to test everything works out, you can try to run below sample program and confirm that the compiler doesn’t have any issues. This would avoid long time struggle of identifying if it’s the issue with OpenCV or Visual Studio.

  • From top menu of Visual Studio, File –> New –> Project. You get a pop up window, New Project.
  • Under Visual C++ , Select Win32 -> Win32 Console Application.
  • Click Next and Select “Empty Project” and Finish
  • Right click the “Source Files” and Select “ADD” and click “New Item”
  • Select “C++ File” and give it  a name “test”
  • Paste the below code in the file and hit F5 or Ctrl + F5
1
2
3
4
5
6
7
8
#include "stdafx.h"
#include "iostream"
using namespace std;

int main(){
cout "Hello World\n";
return 0;
}

If you are able to successfully run the code, then everything is good up till here. In rare scenarios and where Windows Software Development Kit for Windows 10 is not installed, the code would fail complaining that it didn’t find the C++ Compiler, go ahead and install the required dependencies and you should be good.

2. Extract the OpenCV binaries into a folder under c:\opencv_git

3.  Install CMake and open the CMake-GUI from the Start Menu and configure it in the following way:

  • Source Code will be your extracted directory = C:/opencv_git
  • Build the binaries= C:/opencv_git/mybuild (create a new folder)
  • Hit the configure button.
  • Specify the Generator for the project, the default “Visual Studio 14 2015 Win64” in our case (remember to use Win64 for x64 built of binaries)
  • Use default native compilers, Click Finish button.
  • At this point you will see log being generated in the bottom box of the CMake tool. If all goes well, you should see a configuration success message.
  • You should see a long list of items with red-pink background.
  • Accept the default selections without any modifications.
  • Finally click on the Generate button and you should see contents in your build directory once, it finishes.

 

                                      

 Ok, so we are half way through, stay put, 80% job is done, and we just need to do one more step to get this up and running.

4. Compile CMake generated binaries using Visual Studio Compiler

  • Open the Build Folder where we created the Half-baked OpenCV binaries and you should see a file named as “OpenCV.sln”. This is visual studio 2015 file, so double click on it and you should see visual studio 2015 popping up for you.
  • The goal here is to get both Debug and Release binaries and libraries built. First, we’ll use the Debug configuration, so make sure Debug is selected from the configuration manager.

 

  • Right Click the “ALL_BUILD” selection in Solution Explorer and click “BUILD”. It is going to take some time, and here is chance for you to grab that coffee or drink that you have been waiting for. This will build the appropriate xxxxx330d.lib, xxxxx330d.exp and xxxxx330d.pdb files.
  • Once, this is done, swap configurations (Debug <–> Release) so Release is selected, then Right Click on ALL_BUILD again and select Build. Time for the washroom break after that drink that you had previously. This will build all xxxxx330.lib, xxxxx330.exp and xxxxx330.dll files.
  • After both sets of builds are complete, Expand the “CMakeTargets” folder within Solution Explorer and Right click on “INSTALL” and then Build once more. This will join both Debug and Release libraries into a single “lib” and “bin” folder. This would save tons of extra work for your reverse build environments.

  • Hurray, this completed the Compilation process and you should see compiled binaries and libraries under C:\opencv_git\mybuild\install\x86\vc14\bin and C:\opencv_git\mybuild\install\x86\vc14\lib respectively.

 

5. Validate OpenCV Windows 10 build Environment

  • Now, that we have built the OpenCV binaries and libraries, it’s time to get into action and run a demo program for which we did all the hardwork. Let’s get that to work.

Note: For any OpenCV project, you have to tell the C/C++ compiler where the OpenCV header files are, and you have to tell the Linker system where the compiled OpenCV library files are located. This should be your first step while working on any OpenCV projects, otherwise you will get annoying “File Not Found” error messages.

  • If you haven’t closed your Visual Studio instance, create a New Empty Project and add a new Source.cpp file to Sources.
  • Select the configuration mode as “Release”.
  • In the Solution Explorer, right click the project title and open the Properties.

  • On the Configuration Properties, C/C++, General settings for Additional Include Directories, enter “C:\opencv_git\mybuild\install\include\”
  • On the Configuration Properties, Linker, General settings for Additional Library Directories, enter “C:\opencv_git\mybuild\install\x86\vc14\lib”
  • On the Configuration Properties, Linker, Input, Additional Dependencies, add the following libraries:
    opencv_core330.lib
    opencv_highgui330.lib
    opencv_imgproc330.lib
    opencv_imgcodecs330.lib
    opencv_video330.lib
    opencv_videoio330.lib
  • NOTE: There are SEPARATE Property entries, depending on if you are in Debug or Release mode.
  • And finally, you have to add the .dll library locations to the Environment Variables / System Variables PATH. In this case I’ve added both C:\opencv_git\mybuild\install\x86\vc14\bin and C:\opencv_git\mybuild\install\x86\vc14\lib to Path entry.

Note: Visual Studio 2015 contains VC14 compiler which is used with OpenCV thus we are going to use vc14 folder from OpenCV installation.

Here is the test code, that i wrote which will simply open up your webcam and display live feed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
#include "opencv2/opencv.hpp"
 
#include "opencv2/opencv.hpp"
 
#include "opencv\highgui.h"
 
using namespace cv;
 
int main()
 
{
 
Mat image;          //Create Matrix to store image
 
VideoCapture cap;          //initialize capture
 
cap.open(0);
 
namedWindow("window", 1);          //create window to show image
 
while (1)
 
{
 
cap >> image;          //copy webcam stream to image
 
imshow("window", image);          //print image to screen
 
waitKey(30);          //delay 30ms
 
}
 
return 0;
 
}

OpenCV 2.4 & 3.0 Cheatsheet and Differences (C++)




16 thoughts on “(Step by Step) Install OpenCV 3.3 with Visual Studio 2015 on Windows 10 x64 (2017 DIY)”

  1. sap dejq says:

    Dear, I’m following your instalation but my cMake is not recognized and the opencv_world330d.lib is not recognized by the system.

    what wrong?

    1. Editor says:

      can you elaborate at what process your cMake is not recognized? are not able to install it properly or you are not able to launch it from the start menu? Also, you wouldn’t use opencv_world file unless you are using pre-complied opencv version. As per the blog post, you should have different Library files such as :
      opencv_core330.lib
      opencv_highgui330.lib
      opencv_imgproc330.lib
      opencv_hal330.lib
      opencv_imgcodecs330.lib
      opencv_video330.lib
      opencv_videoio330.lib

  2. sap says:

    Hi, the problem is here : when I want to reconfigure the cmake

    CMake Error: The source directory “C:/OpenCV/opencv” does not appear to contain CMakeLists.txt.
    Specify –help for usage, or press the help button on the CMake GUI.

    Regards

    1. Editor says:

      Ok, so you have to use the “sources” folder in the first section. Let’s say you have extracted the opencv zip under “C:\opencv\3.2\opencv\” (pay attention to the folder structure), then you have to enter the “C:/opencv/3.2/opencv/sources” as the “Where is the source” in CMake-GUI. If you open that folder, you should see a CMakeList file there.

  3. Editor says:

    In your case, i think it should be : C:/OpenCV/opencv/sources , make sure sources folder has the “CMakeLists.txt” file in it. That should work

  4. Flo says:

    Hi, I’m following all the steps but at the end I have this error: Error LNK1181 cannot open input file ‘opencv_hal330.lib’. and when I look in my build folder mybuild\install\x64\vc14\lib I don’t find this library. Have i to restart a step or restart since the beginning?

    Thank you for your help

    1. Editor says:

      opencv_hal330.lib is a typo, you can ignore it and we don’t need it for fully functioning. Hal.cpp is already a part of core.h include. Safely remove it.

  5. Hi,I check your blogs named “(Step by Step) Install OpenCV 3.3 with Visual Studio 2015 on Windows 10 x64 (2017 DIY) | World of OpenCV, AI, Computer Vision and Robotics Examples and Tutorials” daily.Your story-telling style is witty, keep up the good work!

    1. Editor says:

      Thank you for the feedback.

  6. Dfs says:

    Hey, thank you very much for this tutorial, it is really great and easy to do the step by step.
    However, when I try to run the test code, it says “cannot open input file ‘opencv_core330.lib'”. Any idea what might be wrong?

  7. JustADude says:

    Hey, thank you very much for this tutorial, it is really great and easy to do the step by step.
    However, when I try to run the test code, it says “cannot open input file ‘opencv_core330.lib'”. Any idea what might be wrong?

    1. Editor says:

      can you navigate to “C:\opencv_git\mybuild\install\x86\vc14\lib” and check what all Lib files you have in there? Do you see any file with core in it?

Leave a Reply

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

Welcome to OpenCV World !! Come as a Guest, stay as a Family