Ask Your Question

Release 2.5.4 tutorial example errors

asked 2013-06-09 06:19:56 -0500

wildpossum gravatar image

I have tried both the CLI and the Eclipse development environments, but each give me the same problems with the errors of:

In function ‘int main(int, char**)’: error: ‘loadImage’ was not declared in this scope; error: ‘showImage’ was not declared in this scope; error: ‘releaseImage’ was not declared in this scope;

I have the following include directives: '#include "cv.h"' '#include "highgui.h"' and I have the exported environmental $LD_LIBRARY_PATH="/usr/local/lib" which is correct as it contains opencv & opencv2 directories.

A> What include files are I missing, but surely the cv.h (aka cv.hpp) should have taken care of the declarations themselves?

B> Do I have to do a "nm <library_name>" to get the includes from each library or is there a easier way to get what header file prototypes are within which library ?

C> Could you advise what I need to do to fix the problems with the 2.5.4 release examples. Actually to assist newbies to CV, it would be a good idea to have all the tutorial examples tested under each new release so it doesn't turn newbies off, as they consider it all too hard just trying to break into OpenCV.


edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-06-13 09:19:30 -0500

wildpossum gravatar image

The following answers my predictament exactly.

IplImage* img = cvLoadImage( argv[1] );
cv::namedWindow( "Test3-Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Test3-Example1", img );
cvReleaseImage( &img );
cv::destroyWindow( "Test3-Example1" );
return 0;

LoadImage, ShowImage and ReleaseImage needed to have pre-appended "cv" with the third character capitalised.

I found this out by just trying different combinations of function calls from the CV library headers.

edit flag offensive delete link more

answered 2013-06-09 06:41:44 -0500

Guanta gravatar image

A> Since the includes are below the opencv2 folder you need to specify those, too. Also please use the newer include-modules, i.e.:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

Also note that it is not necessary to set the LD_LIBRARY_PATH to /usr/local/lib! However don't forget to link against the libraries (if you search for Makefile in this Q&A forum you will also find several examples for working Makefiles).

B> You can see at the top of each documentation page ( to which module each method belongs to.

C> The most examples should run out-of-the box and can be build via cmake (or ccmake). But you are right, it can happen that an example doesn't work. I am not quite sure if they are tested via buildbot ( or not, seems like only the tests were built and run and not the example-module. Thus, please report if you find an example which doesn't build by submitting an issue ticket ( so that it can be fixed for the next release.

edit flag offensive delete link more


Hi Guanta; Thanks for your suggestions. I have tried them but unfortunately I ended up with the same "not declared in this scope" errors. I have gone as far as having modified each include statement to reflect the actual include address i.e.: #include "/usr/local/include/opencv2/<include filename>" but again without any change to the make errors.

I forgot to let you know that I did a "cmake ./" which did printout correctly the location of the opencv libraries, and complete without any errors, I followed by a "make".

Any further suggestions. Grahame

wildpossum gravatar imagewildpossum ( 2013-06-10 11:22:30 -0500 )edit

Do you actually use the correct functions and namespace? E.g. it is cv::imread("path") not imread("path") and so on (you can omit the namespace if you write at the beginning using namespace cv;

Guanta gravatar imageGuanta ( 2013-06-11 05:36:11 -0500 )edit

I am sure I have correct name-space.

Herein is the test program in full (excluding the #include statements as there is not enough room to fit here).

gmk@Brushtail:~/test3$ cat test3.cpp

// From top-of-page Page 17 of the OpenCV book

using namespace cv;

include "my_includes.hpp"

int main(int argc, char** argv) {

IplImage* img = loadImage( argv[1] );

namedWindow( "Test3-Example1", CV_WINDOW_AUTOSIZE );
showImage( "Test3-Example1", img );
releaseImage( &amp;img );
destroyWindow( "Test3-Example1" );
return 0;


In "my_include.hpp" header file I have all header files from opencv and opencv2, in an effort to over these problems.

Maybe I need to load/run OpenCV on a different Linux distribution (currently Ubuntu 12.04.2 LTS). Any further thoughts?

wildpossum gravatar imagewildpossum ( 2013-06-11 09:59:09 -0500 )edit

Don't worry about your system. OpenCV 2.4.5 should work with no problem. Can you please try:

int main(int argc, char* argv) { cv::Mat img = cv::imread(argv[1]); cv::imshow( "Test3-Example1", img ); cv::waitKey(0); return 0; }

with the includes as in my first post.

Guanta gravatar imageGuanta ( 2013-06-11 11:09:48 -0500 )edit

[100%] Building CXX object CMakeFiles/test3.dir/test3.cpp.o Linking CXX executable test3 [100%] Built target test3

It all compiled and more importantly Linked includes correctly.

Is this a bug?

./test3 ../cat.jpg read correctly without problems.

Thanks for your sustained help. G.

wildpossum gravatar imagewildpossum ( 2013-06-12 10:46:26 -0500 )edit

You are welcome! Great I could help. Please mark the answer as correct, so that it appears solved.

Guanta gravatar imageGuanta ( 2013-06-13 02:21:22 -0500 )edit

Before I mark this as answered, what do I do with the original cv::calls such as showImage, loadImage, releaseImage which exists in the documentation but I am unable to get its header file to play ball? My original problem with the examples, not correlating with the header files still stands.

As I am new here, how do I mark a answer as correct?

wildpossum gravatar imagewildpossum ( 2013-06-13 09:04:24 -0500 )edit

You have to differentiate between C and C++. I recomment to stick to the C++ functionality and use these calls since current development is working at C++. You can however compile the C examples, too with gcc or by marking the headers of the C-library as extern "C" ( . You can mark an answer as correct by clicking on the small hook below the voting-number (if you hover your mouse above it, it will also tell you that) - see also the FAQ:

Guanta gravatar imageGuanta ( 2013-06-14 11:49:03 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-06-09 06:19:56 -0500

Seen: 1,300 times

Last updated: Jun 13 '13