Amadeus
Amadeus

Reputation: 352

OpenCV cannot load image

While I was working on a project, I noticed that I am not able to load images. Here is the simple code that I used to check:

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

using namespace cv;
using namespace std; 

int main( int argc, char** argv )
{ 
    if( argc != 2) 
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    } 

    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    Mat gray_image;
    cv::cvtColor(image, gray_image, CV_RGB2GRAY);

    imwrite("Gray_Image.jpg",gray_image);

    return 0;
}

Here is its output when I execute it:

root@beaglebone:~# ./tryit lena.jpg 
Could not open or find the image

I tried to directly use the address of the image ("/home/root/lena.jpg") instead of argv[1] but nothing changed.

What can be the problem?

ps: I am cross-compiling this OpenCV program and then running it on my BeagleBone which has Angstrom Linux installed on it. Can this problem related to it?

Upvotes: 2

Views: 2576

Answers (2)

Prasanth Louis
Prasanth Louis

Reputation: 5056

Try saving the image with a png extension and then opening it. For some reason, files with a png extension work better than other extensions like jpg/gif.

Upvotes: 0

Amadeus
Amadeus

Reputation: 352

I solved my problem by deleting existing OpenCV libraries on my angstrom image and replacing them with the working ones.

Upvotes: 1

Related Questions