Ask Your Question

cannot run compile opencv program

asked 2014-07-21 21:45:39 -0600

Nabeel gravatar image

Hi Everyone,

I had OpenCV 2.4 on Ubuntu 12.04. My C++ codes were working fine.

Now, I installed OpenCV 2.4.9 today on the computer. My codes are now giving me errors.

For example, I run the following basic command in C++:

Mat image1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);

And I get following errors:

src/main.cpp:25:37: error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope src/main.cpp:25:60: error: ‘imread’ was not declared in this scope

But I can create OpenCV Mat objects without any problem.

I also checked the outputs by running pkg-config opencv --libs and pkg-config opencv --cflags commands. Outputs are:

-I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/lib /usr/local/lib/ /usr/local/lib/ /usr/local/lib/ /usr/local/lib/ .......

I don't know what's going wrong. Everything was fine before.

I suspect something to do with opencv2 module, which cannot be loaded.

Please help me out.


edit retag flag offensive close merge delete



did you get the code from github ? did you do a 'git checkout 2.4' before building it ?

it looks like you've build the master(3.0) version, those flags changed there

berak gravatar imageberak ( 2014-07-21 23:44:39 -0600 )edit

3 answers

Sort by » oldest newest most voted

answered 2014-07-22 01:25:17 -0600

jamesnzt gravatar image

updated 2014-07-22 04:52:02 -0600

since you didn't mention the program, i will tell some solution which i got working with it

  1. you have to specify the image file name and location while running the program eg ./program image1.jpg

  2. If any error in specifying color/ grayscale, just specify as imread(argv[1]); cvtcolor(src,dst,CV_BGR2GRAY)

  3. just specify imread(argv[1],0)

or otherwise you may have to include <opencv2 highgui="" highgui.hpp="">

edit flag offensive delete link more


Thanks Mr. berak I corrected it.

jamesnzt gravatar imagejamesnzt ( 2014-07-22 04:53:25 -0600 )edit

answered 2014-07-23 01:59:08 -0600

jamesnzt gravatar image

updated 2014-07-23 03:37:37 -0600

include the correct header files using the following commands

edit flag offensive delete link more

answered 2014-07-22 07:45:28 -0600

JewelCV gravatar image


encountered the same error. if i do a git checkout what would happen? would opencv 2.4.9 based codes run on it?

edit flag offensive delete link more


"what would happen?"

  • you would switch to the 2.4.9 code version. (git checkout master gets you back to 3.0)

    after rebuilding the libs with cmake, your code above would work as expected.

berak gravatar imageberak ( 2014-07-22 08:31:15 -0600 )edit

but it dint make a difference the newly installed file system still dint contain any file with imread declaration.

JewelCV gravatar imageJewelCV ( 2014-07-22 11:04:17 -0600 )edit

it did. thanks @berak ! :)

JewelCV gravatar imageJewelCV ( 2014-07-23 06:53:54 -0600 )edit

Question Tools


Asked: 2014-07-21 21:45:39 -0600

Seen: 4,675 times

Last updated: Jul 23 '14