Ask Your Question
0

cannot run compile opencv program

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

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/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_highgui.so .......

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.

Thanks

edit retag flag offensive close merge delete

Comments

2

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 -0500 )edit

3 answers

Sort by » oldest newest most voted
0

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

jamesnzt gravatar image

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

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

Comments

Thanks Mr. berak I corrected it.

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

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

jamesnzt gravatar image

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

include the correct header files using the following commands

include"opencv2/imgproc/imgproc.hpp"
include"opencv2/core/core.hpp"
include"opencv2/highgui/highgui.hpp"
edit flag offensive delete link more
0

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

JewelCV gravatar image

@berak

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

Comments

"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 -0500 )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 -0500 )edit

it did. thanks @berak ! :)

JewelCV gravatar imageJewelCV ( 2014-07-23 06:53:54 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

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

Seen: 3,559 times

Last updated: Jul 23 '14