Ask Your Question
0

Error in function imread() - cannot read image

asked 2014-02-24 15:15:34 -0600

Millinia gravatar image

I am just starting to work in the OpenCV library coding in C++. I am using CMake v2.8.3(which I have never used before) to build and compile my project on an ubuntu 11.04 distribution.

I have the source code LearnImgProcess1.cpp and the CMakeLists.txt in "/home/ubuntu/ImgProcessing/Example1"

CMakeLists.txt


cmake_minimum_required(VERSION 2.8)
Project(Example1)
find_package( OpenCV REQUIRED)
add_executable(Example1 LearnImgProcess1.cpp)
target_link_libaries(Example1 ${OpenCV_LIBS})

LearnImgProcess.cpp


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

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
Mat img = imread(argv[1], -1);

if(img.empty())
{
cout<<"image not found or read!<<endl; <="" br=""> return -1;
}

namedWindow("Picture Displayer", WINDOW_AUTOSIZE);
imshow("Picture Displayer", img);
waitkey(0);
destroyWindow("Picture Displayer");

return 0;

}


I compile in the terminal, in the same directory as before, by entering "cmake ." followed by "make"
In the terminal, in the current "/home/ubuntu/ImgProcessing/Example1" directory
I then type in " ./Example1 sample.jpg "

I then recieve my "image not found or read!" error.

The image is located in the same directory as the source code :
"/home/ubuntu/ImgProcessing/Example1"

I have tried running with " ./Example1 "/home/ubuntu/ImgProcessing/Example1/sample.jpg" "
and "/.Example1 "..sample.jpg" "

I have tried different file formats.

I have placed copy images in "/home/ubuntu/ImgProcessing/Example1/CMakeFiles/Example1.dir/sample.jpg" thinking that maybe it was trying to get an image from that directory.

I have been looking on forums for the past couple of days trying to figure it out, but have had no luck. Any help would be appreciated.

It is entirely possible that this might be a CMake issue, as I don't fully understand how to use it. I have also tried approaching the problem from that end. However if that is the case, if anyone knows how to fix it from that end and wouldn't mind giving some insight, that would also be appreciated.

edit retag flag offensive close merge delete

Comments

1

since you get a runtime error, it all compiled and linked fine. i think, you can rule out cmake issues here.

but make a quick test:

cerr << cv::getBuildInformation() << endl;

and see, if i.e jpeg or png support got compiled in (when building the opencv libs)

berak gravatar imageberak ( 2014-02-24 15:27:42 -0600 )edit

when i attempted to use the function getBuildInformation() it said that the function is not a part of the library :-/ Any ideas?

Millinia gravatar imageMillinia ( 2014-03-03 10:54:42 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-24 21:55:08 -0600

Error 1: in the line

cout<<"image not found or read!<<endl; <="" br=""> return -1;

before the ; a " should be there.

Like

 cout<<"image not found or read!<<endl; <="" br=""> return -1";

Error 2: there is nothing called as waitkey,it is waitKey

Error 3:The line #include < iostream > is incorrect,there should be no spaces in between,its like

#include <iostream>

The code(revised):

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

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
Mat img = imread(argv[1], -1);

if(img.empty())
{
cout<<"image not found or read!<<endl; <="" br=""> return -1";
}

namedWindow("Picture Displayer", WINDOW_AUTOSIZE);
imshow("Picture Displayer", img);
waitKey(0);
destroyWindow("Picture Displayer");

return 0;

}

Hope this helps you :)

edit flag offensive delete link more

Comments

Sorry about the code typos, my code is correct in comparing the two, I had just transcribed it wrong. It compiles without any errors. I am working on a the beagleboard xm microprocessor and didn't port over the code to my laptop to paste the code. Which probably doesn't help in getting my problem resolved. Again sorry for the confusion.

Millinia gravatar imageMillinia ( 2014-02-24 23:00:05 -0600 )edit

I have never used beagleboard xm microprocessor,but I think this link could help you :

http://coherentmusings.wordpress.com/2012/06/24/getting-started-with-opencv-on-beagleboard-xm/

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-24 23:24:18 -0600 )edit

Question Tools

Stats

Asked: 2014-02-24 15:15:34 -0600

Seen: 10,173 times

Last updated: Feb 24 '14