-1

This code cannot read image. it compiles correctly, runs but can not load image.

int main(int /*argc*/, char** /*argv*/)
{
  Mat image;
  image = imread("lena.jpg", 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;
  }

  namedWindow("Display window", CV_WINDOW_AUTOSIZE);// Create a window for display.
  imshow("Display window", image);                   // Show our image inside it.

  waitKey(0);
  cv::waitKey(50000);
  getchar();
  return 0;
}
smamran
  • 741
  • 2
  • 14
  • 20
  • 1
    How about give the complete path of the image in your program. image = imread("/path/of/lena.jpg", CV_LOAD_IMAGE_COLOR); – maythe4thbewithu Apr 04 '14 at 16:41
  • either what maythe4thbewithu suggested. or make sure you are running the application in the same directory the lena.jpg is. – Nadim Farhat Apr 04 '14 at 17:19
  • I used both @Nadim Farhat & maythe4thbewithu tips. but not working. My os is windows 8 & compiler vc2013. Is there a problem working with imread with windows? However it worked by this: IplImage *img = cvLoadImage("lena.jpg"); Mat image(img); – smamran Apr 04 '14 at 18:34
  • Add OpenCV bin folder to environmental path. – guneykayim Apr 05 '14 at 20:21

1 Answers1

-1

There are possibilities that these images are locked by some properties. Just use any tool like snipping tool to make a copy of the original image and try reading with imread. It will work for sure.

These kind of problems generally occur when you download the image from internet.

MOHIT.A Jain
  • 74
  • 1
  • 10