imread not working in opencv2.4.13 on centos6.5
Hello All
I built opencv2.4.13 from source in RELEASE mode like so:
I created a directory named 'build' inside the folder and from inside the 'build' ran cmake :
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/ssomesh/usr/local/opencv -D WITH_CUDA=ON ..
This I followed with
make; sudo make install
When I run the sample code provided in the 'samples' folder by openCV, it is able to read and display images. However when I compile my program, the imread() function does not seem to work.
Here's the code that is throwing error:
#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" using namespace cv; using namespace std; int main( int argc, char** argv ) { if( argc != 2) { printf(" Usage: display_image ImageToLoadAndDisplay\n"); return -1; } Mat image; image = imread(argv[1], CV_LOAD_IMAGE_UNCHANGED); // Read the fileif( image.empty() ) // Check for invalid input { cout << "Could not open or find the image" << std::endl ; return -1; } namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display. imshow( "Display window", image ); // Show our image inside it. waitKey(0); // Wait for a keystroke in the window return 0;
}
I compile my code like this:
g++ read-display-images.cpp -o read-display-images `pkg-config opencv --cflags --libs`
The code compiles fine. But every time I run it, it exits and displays
Could not open or find the image
The image is in the same folder as the source and the executable.
I want help in resolving the issue. Is there a problem with the configuration during the build, or else am I not setting some flags correctly?
Any help is greatly appreciated.
Thanks.
"Is there a problem with the configuration during the build ?"
you can check py printing
cv::getBuildInformation()
(or looking at the cmake output again)wat kind of image are you loading ? try some others. really, usually it's jsu a path problem. make sure to start your program, where the image is, or try an absolute path.
Thanks for your suggestions. I tried what you suggested, but it did not work. Is there a possibility that there are issues with opencv2.4.13 with cpp interface? I was loading a jpg image. I also tried png, but it shows the same error. As an aside, could you please point me to some resource that talks about configuration during build, if possible? Also, it will be helpful if there is some easy workaround for this problem.
again, occams razor: if the samples work, but not your prog, ...
Hey, I did a fresh build from scratch and got it working. However, imread() is not able to read a .jpg image although it reads .png image. I have libpng.so and libjpeg.so both installed in the same directory, which I add to the LD_LIBRARY_PATH. Also, the output of cmake is:
Could you pl. help me make imread() read a .jpg image? Which other library do I need to install, if any?
Thanks.