Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error in function imread() - cannot read 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.