Ask Your Question
0

example compilation error

asked 2014-02-10 11:43:55 -0600

Hi

I have installed the opencv successfully and then i tried to compile the very first example that came along with the tutorial on the website. I am getting the following error:

/////////////////////////////////////////////// sajjad@sajjad-G74Sx:~/Documents/test/opencv/first$ cmake . -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: /home/sajjad/Documents/test/opencv/first sajjad@sajjad-G74Sx:~/Documents/test/opencv/first$ make Scanning dependencies of target DisplayImage [100%] Building CXX object CMakeFiles/DisplayImage.dir/main.cpp.o /home/sajjad/Documents/test/opencv/first/main.cpp: In function ‘int main(int, char)’: /home/sajjad/Documents/test/opencv/first/main.cpp:17:33: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope make[2]: [CMakeFiles/DisplayImage.dir/main.cpp.o] Error 1 make[1]: [CMakeFiles/DisplayImage.dir/all] Error 2 make: * [all] Error 2

///////////////////////////////////////////////

Do i have to set any LD_LIBRARY_PATH and environment variable path after installation ?

Thanks

edit retag flag offensive close merge delete

Comments

did you get the opencv code from github ? any chance , you're compiling against the master(3.0) branch ?

it's cv::WINDOW_AUTOSIZE there.

berak gravatar imageberak ( 2014-02-11 04:20:46 -0600 )edit

Sorry sajis997,by mistake i typed a slightly wrong command of compiling,but i edited it now,also i have posted other anwer,if still the problem doesn't go off please share your code,I will be happy to look to help you out :)

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-11 04:58:59 -0600 )edit

4 answers

Sort by » oldest newest most voted
0

answered 2014-02-11 04:54:28 -0600

I assume the code used by you is this:

#include <stdio.h>
#include <opencv2/opencv.hpp>

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

And I compiled it successfully with this command:

g++ -ggdb `pkg-config --cflags opencv` -o `basename test.cpp .cpp` test.cpp `pkg-config --libs opencv`
edit flag offensive delete link more
0

answered 2014-02-11 09:05:52 -0600

updated 2014-02-11 10:31:25 -0600

If you want to go with the cmake compilation follow the steps

Open a terminal and type:

a)

sudo gedit /etc/ld.so.conf.d/opencv.conf

b)in that paste :

usr/local/lib

c)save and close and then open a terminal and type:

pkg-config --cflags opencv

Result:

-I/usr/local/include/opencv -I/usr/local/include

And then tpye:

pkg-config --libs opencv

Result:

/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so

Also try

In the CMakeLists.txt add this line too:

include_directories(${OpenCV_INCLUDE_DIR})

Then you can continue with the cmake tpye compilation

Hope this helps you :)

edit flag offensive delete link more

Comments

Do i really need to all these. These are not mentioned inside the tutorial at all. I already tried

pkg-config --cflags opencv

And the output i got is as follows:

-I/usr/local/include/opencv -I/usr/local/include

Then i tried pkg-config --libs opencv and got the similar outout.

sajis997 gravatar imagesajis997 ( 2014-02-11 09:55:28 -0600 )edit

1)Just try doing that for once. 2)Check the code once again,the correct code is the answer just below this comment. 3)Then try doing sudo make instead of make. 4)Another reason for such error is when you install an unstable version of opencv.Try installing an older stable version

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-11 10:20:37 -0600 )edit

Thanks Abhishek for your your effort ! Unfortunately, the problem persists. It would be nice if you share your email address with me so that i can attach my source and you can run it own your end.

sajis997 gravatar imagesajis997 ( 2014-02-12 17:47:03 -0600 )edit
Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-13 00:09:51 -0600 )edit
0

answered 2014-02-11 10:19:37 -0600

1)In the CMakeLists.txt add this line too:

include_directories(${OpenCV_INCLUDE_DIR})
edit flag offensive delete link more
-1

answered 2014-02-10 13:34:31 -0600

updated 2014-02-11 09:09:59 -0600

One way of compiling:- 1)chmod +x FILENAME.cpp

2)

g++ -ggdb `pkg-config --cflags opencv` -o `basename FILENAME.cpp .cpp` FILENAME.cpp `pkg-config --libs opencv'

3)./FILENAME image.Ext

And now for the CV_WINDOW_AUTOSIZE error: include the hihgui.h(or highgui.hpp for c++),then cv.h

SAMPLE CODE:

#include <highgui.h>

int main( int argc,char** argv)
{
    IplImage* img = cvLoadImage(argv[1]);
    cvNamedWindow("example1" ,CV_WINDOW_AUTOSIZE);
    cvShowImage("example1",img);
    cvWaitKey(0);
    cvReleaseImage( &img);
    cvDestroyWindow("example1");
}

AGAIN if problem still persists,here's a way of installing opencv

LINK 1: http://abhishek4273.wordpress.com/2014/02/05/install-opencv/

LINK 2:http://answers.opencv.org/question/21275/make-errors-when-building-opencv-under-ubuntu/#27780

Hope this helps you :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-10 11:43:55 -0600

Seen: 1,455 times

Last updated: Feb 11 '14