Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV in eclipse

I am trying to setup opencv in eclipse Luna. I have written a sample application as follows :

#include <cv.h>
#include <highgui.h>
#include<iostream>

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;
}

In my project properties i have included /usr/local/include/opencv in (Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Compiler -> Includes -> Include Paths. )

and /usr/local/lib in (Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Linker -> Libraries -> Library Search Path. )

My output of the command pkg-config --cflags opencv is -I/usr/local/include/opencv -I/usr/local/include

and the output of pkg-config --libs opencv is

 -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_viz -lopencv_adas -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_face -lopencv_latentsvm -lopencv_objdetect -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_ml -lopencv_flann -lopencv_xobjdetect -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core -lopencv_hal

When I tried building my project i got the following errors.

‘imread’ was not declared in this scope 
‘imshow’ was not declared in this scope 
‘namedWindow’ was not declared in this scope    
‘waitKey’ was not declared in this scope    
Function 'imread' could not be resolved 
Function 'imshow' could not be resolved 
Function 'namedWindow' could not be resolved
Function 'waitKey' could not be resolved    

Can anyone help me fixing the problem and explain what is that I was missing.

like image 883
Minions Avatar asked Aug 22 '15 11:08

Minions


People also ask

How do I import OpenCV into eclipse?

Set up OpenCV for Java in EclipseFrom the menu navigate under Java > Build Path > User Libraries and choose New... . Enter a name for the library (e.g., opencv) and select the newly created user library. Choose Add External JARs... , browse to select opencv-3xx. jar from your computer.

Can I use OpenCV with Java?

4, OpenCV supports desktop Java development using nearly the same interface as for Android development. This guide will help you to create your first Java (or Scala) application using OpenCV.

What is OpenCV for Java?

OpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture and analysis including features like face detection and object detection.

Can I use OpenCV in Visual Studio?

Summary. In this post, we learned how to configure a Visual Studio project to use OpenCV. First we set the Additional Include Directories, which is required for the #include commands- this tells the compiler how the OpenCV library looks.


1 Answers

Try to change:

#include <cv.h>
#include <highgui.h>

To this:

#include <opencv2/opencv.hpp>

You also need to link the Libraries (GCC C++ Linker » Libraries):

opencv_core
opencv_imgcodecs
opencv_highgui

You didn't say which version you are using, but as you have -lopencv_imgcodecs, you are probably using OpenCV 3. If you prefer, follow the instructions here. Also change from CV_WINDOW_AUTOSIZE to WINDOW_AUTOSIZE.

like image 85
Berriel Avatar answered Oct 01 '22 18:10

Berriel