Installing OpenCV and building an example application

Hi,

I’ve searched for tutorials explaining how to install and configure OpenCV 2.4.9 with Cmake, using Visual Studio 2013, but I haven’t found any good ones. As a result, I’ve decided to create my own tutorial, where I explain how to build the OpenCV solution using Cmake and how to create applications in Visual Studio 2013 that use OpenCV. Note that my laptop is running Windwos 8.1.

Here is the tutorial:

The tutorial summarizes the following steps:

  1. Downloading and extracting OpenCV.
  2. Downloading and installing Cmake.
  3. Building OpenCV using Cmake.
  4. Creating applications in Visual Studio 2013 that use OpenCV.

As promised, I’ve uploaded the sample code that I used as an example application:

#include “stdafx.h”
#include “opencv2/highgui/highgui.hpp”
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0

if (!cap.isOpened()) // if not success, exit program
{
cout << “Cannot open the video file” << endl;
return -1;
}

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

cout << “Frame size : ” << dWidth << ” x ” << dHeight << endl;

namedWindow(“MyVideo”, CV_WINDOW_AUTOSIZE); //create a window called “MyVideo”
Mat frame;

while (1)
{
bool bSuccess = cap.read(frame); // read a new frame from video

if (!bSuccess) //if not success, break loop
{
cout << “Cannot read a frame from video file” << endl;
break;
}

imshow(“MyVideo”, frame); //show the frame in “MyVideo” window

if (waitKey(30) == 27) //wait for ‘esc’ key press for 30ms. If ‘esc’ key is pressed, break loop
{
cout << “esc key is pressed by user” << endl;
break;
}
}
return 0;
}

 

If you have any question, please comment on this post and I’ll be glad to help.

 

Gil.

 

18 thoughts on “Installing OpenCV and building an example application

  1. jen

    i have a windows 8 and the system properties said its a 64 bit but when i ran your program, visual studio is giving me this error:

    Error 1 error LNK1112: module machine type ‘x64’ conflicts with target machine type ‘X86’

    also, im using visual studio community 2013. thanks!

    Reply
    1. gillevicv Post author

      Hi Jen,

      In VS there’s a toolbar with a button that says “Local Windows Debugger”. Next to it, there are two menus – in the first you select between release and debug and in the second you select between architectures (x64 and x86). Have you changed the architecture to x64?

      If you problem persists, please send me a screenshot to gil.levi100@gmail.com and I’ll try to help.

      Best,
      Gil.

      Reply
  2. Zahra

    Hi,
    I get the same error as Sounhi
    LINK : fatal error LNK1181: cannot open input file ‘opencv_highgui2411.obj’

    Could you please help me.

    Thanks,

    Reply
  3. Abdulaziz

    Hi ,
    Thank you so much for your tutorial and excellent explanations.

    I’m doing a project of using markerless (Natural Image) for Augmented reality Coloring Book apps for mobiles.
    My question is which features descriptors you suggest for me to use?
    Thanks in advance.
    Aziz

    Reply
    1. gillevicv Post author

      Hi,

      Thank you for your interest in my blog.

      It would be easier to answer if you could send me some example images to my mail and explain the application and running time/memory requirements.

      You can mail me at gil.levi100@gmail.com.

      Best,
      Gil.

      Reply
  4. Luiz Arão

    Hello how are you?
    I’m having problems with the C code … when I copy and paste the visual studios it appears with several errors. The commands are underlined in red.
    Could you pass me the code as a file or somehow that it is avoided?
    thank you
    Note: I am Brazilian and this tutorial is helping me a lot

    Reply
  5. Daniel Larsen

    Hi i have a question, I do not have nearly the same amount of .dll and .lib files as shown on your video; particularly the OPENCV_HIGHGUI.

    Also the portion of the video where you changed a directory and the errors on the code disappeared, that did not work for me.

    Please help if you can.

    My email is danlarsen@live.com

    Reply
  6. Jessie

    Excellent video.. Thank you so much,,,

    I am starting an image processing application and I can’t decide between using c++ or c#.. It’s basically image enhancements and classifications.. I have basic c++ knowledge.. Never dealt with pointers or memory management.. Any advice much much appreciated..

    Reply
    1. gillevicv Post author

      Hi,

      Thank you for your interest in my blog.

      What about Python? it’s super easy, development is much faster (you don’t have to worry about memory management), it’s cross platform and there are many available machine learning and deep learning packages available in Python.

      Best,
      Gil

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s