Ask Your Question
0

example compilation error

asked Feb 10 '14

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

Preview: (hide)

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 (Feb 11 '14)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 :)

4 answers

Sort by » oldest newest most voted
0

answered Feb 11 '14

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`
Preview: (hide)
0

answered Feb 11 '14

updated Feb 11 '14

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 :)

Preview: (hide)

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 (Feb 11 '14)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

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 (Feb 12 '14)edit
0

answered Feb 11 '14

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

include_directories(${OpenCV_INCLUDE_DIR})
Preview: (hide)
-1

answered Feb 10 '14

updated Feb 11 '14

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 :)

Preview: (hide)

Question Tools

Stats

Asked: Feb 10 '14

Seen: 1,544 times

Last updated: Feb 11 '14