1

I have started learning OpenCV. I am working on linux. From their documentation page I was able to compile this http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage

However after that I got lost in trying to declare a new mat and it's constructors. SO I decided to go with this book http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134 However I am not able to compile the very first program from this book. The program is here :

#include "highgui.h"
int main(int argc, char** argv)
{
    IplImage* img = cvLoadImage (argv[1]);
    cvNamedWindow("Example1", CV_WINODW_AUTOSIZE);
    cvShowImage("Example1",img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("Example1");
}

I saved this in a file named load.c

Then I created a CMakeLists.txt file and put this in it :

project( load )
find_package( OpenCV REQUIRED )
add_executable( load load )
target_link_libraries( load ${OpenCV_LIBS} )

when running "cmake ." from terminal it is succesful. But when I am running "make" it gives me this error :

Scanning dependencies of target load
[100%] Building C object CMakeFiles/load.dir/load.o
/home/ishan/load/load.c: In function ‘main’:
/home/ishan/load/load.c:4:2: error: too few arguments to function ‘cvLoadImage’
/usr/local/include/opencv2/highgui/highgui_c.h:212:18: note: declared here
/home/ishan/load/load.c:5:28: error: ‘CV_WINODW_AUTOSIZE’ undeclared (first use in this  function)
/home/ishan/load/load.c:5:28: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/load.dir/load.o] Error 1
make[1]: *** [CMakeFiles/load.dir/all] Error 2
make: *** [all] Error 2

I think it is because this example in the book is for OpenCV 1.x while I am currently running 2.4.3, however I believe there must be a way to run this program and the subsequent program that are in the book. I think the problem lies with linking the header files properly. I would like to first read from the book and using reference from documentation and then switch to documentation fully. But for now I wish to learn from the book as learning from the book is far easier to me than documentation. Plus I bought this book for approx 3000 INR and got it just today, I don't want to see it go to waste. I want to learn from it.

Please help me out.

1 Answer 1

2

CV_WINODW_AUTOSIZE is mispelled. The correct constant is CV_WINDOW_AUTOSIZE

cvLoadImage (argv[1]); should be cvLoadImage (argv[1], 1); (for loading a color image) because the C standard does not support default arguments.

By the way, if you're using OpenCV 2.0+, I recommend learning the C++ API. It's a lot less convoluted than the C API and performance is comparable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.