Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV on eclipse on windows

Tags:

c++

opencv

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

like image 400
Mohamed Wagdy Khorshid Avatar asked Nov 30 '22 01:11

Mohamed Wagdy Khorshid


2 Answers

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

like image 156
lastjeef Avatar answered Dec 04 '22 04:12

lastjeef


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

#include <opencv2/opencv.hpp>
like image 35
Tobias Hermann Avatar answered Dec 04 '22 06:12

Tobias Hermann