4

I'm trying to install opencv on windows, here are my steps:

  • downloaded opencv 2.4.3 from website
  • run the exe, extracted the folder in the same path
  • opened eclipse (with MinGW previously set and configured)
  • created new project XYZ
  • added new folder "src"
  • added new class "main.cpp"
  • added the following code:

    hash include <cv.h>
    hash include <highgui.h>

    using namespace cv;
    int main(int argc, char** argv) {
    
    Mat image;
    image = imread(argv[1], 1);
    
    if (argc != 2 || !image.data) {
        printf("No image data \n");
        return -1;
    }
    
    namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
    imshow("Display Image", image);
    
    waitKey(0);
    
    return 0;
    }
    
  • added the two paths

    • "E:\Sources\opencv\build\include"
    • "E:\Sources\opencv\build\include\opencv"
  • got the compilation error "Symbol 'cv' could not be resolved"

Please advice if any step is missing

steo
  • 4,586
  • 2
  • 33
  • 64

2 Answers2

17

you gonna need the latest stable version of openCV 2.4.3 .

Eclipse Juno ! (Eclipse IDE for C/C++ Developers ) And MinGW - Minimalist GNU for Windows

we will ignore x86/64 choice, since we gonna work with a 32 compiler / and 32 openCV build, even though the system is a 64 one !

Step 1 : Download and Install

Eclipse

Download Eclipse from and decompress the archive . ( I assumed that you already have JRE on your computer , if not ! download and install it ) .

MinGW

Download MinGW . the installer will lead you through the process ! you might have to add the bin directory to the path ! (Default path : C/MinGW/bin )

OpenCV

Download openCV exe from the link , extract the files (in the C:/ directory in this tutorial ) . Make sure you have the file structure below .

don't forget to add the bin directory => Path !

As I mentioned earlier ! I'll use x86 build even if i have a 64 OS to avoid compiler problems and to keep this tutorial open to x86 OS users !

Step 2 : Create and Configure

  • Open the Eclipse IDE !
  • Create a new C++ project : File > New > C++ Project
  • Choose a Hello Word Project to have a pre structured one ! Don't forget to select the MinGW toolchains

Click Finish and let's get to work !

Now that you have you first Hello word project ! replace the Code in the Soure file .cpp by the code below

///////////////CODE///////////

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
  Mat im = imread(argc == 2 ? argv[1] : "lenna.png", 1);
  if (im.empty())
  {
    cout << "Cannot open image!" << endl;
    return -1;
  }
  imshow("image", im);
  waitKey(0);
  return 0;
}

///////////////CODE///////////

Obviously there are multiple errors on the code , yes ! we have to link the libraries !

Now go to Properties >> C/C++ Build >> Settings on the Tool Setting tab >> GCC C++ Compiler >> Includes and include opencv path ! [opencvDir\build\include]

Now scroll to MinGW C++ Linker >> Libraries and add the Library search path [opencvDIR\build\x86\mingw\lib]

in the Libraries part ! we add as much librarie as we need for the project ! here I added 4 libraries just for tutorial sake even if well need only the highgui one for our test code to work ! The libraries names can be found on the [opencvDIR\build\x86\mingw\lib] Example ! for libopencv_video243.dll.a wee add opencv_video243 in the linker !

click OK !

Now we can build our first project ! You figured that you have to add a picture to the project as implied in the source code "lenna.png" Use lenna for good luck

Build and Run the project ! If you see the beautiful lady :) Congrats :)

have a look here for snapshots! opencveclipse-on-windows

lastjeef
  • 166
  • 2
  • 11
  • 1
    Nice instructions. A little more detail would help around the libraries part. For example, it took me a few minutes to realise that I should add `opencv_video245` in my project since the opencv version is different. Other than that, this was very helpful. – Plasty Grove Jun 23 '13 at 12:22
  • Thank you a lot, it helped me.. opencv tutorials on their site aren't up-to-date :x – Mariusz Oct 09 '13 at 19:10
  • This tutorial left out the part about using CMAKE to build the files and then MINGW to compile them, Check out this page with more on how to complete these steps before moving on to your IDE. http://kevinhughes.ca/tutorials/opencv-install-on-windows-with-codeblocks-and-mingw/ – Greg Mar 28 '16 at 01:58
5

cv.h is for the old C API. To use the Cpp API try the following:

#include <opencv2/opencv.hpp>
Tobias Hermann
  • 9,936
  • 6
  • 61
  • 134