Search code examples
c++visual-studioopencvimread

imread couldn't find image


I use visual studio 2013 and opencv. I run a simple code that reads a image and shows it. I add the image to resource files of my project from Donloads file. When I run below code, image.data is empty.

  #include "stdafx.h"
   #include <opencv2\core\core.hpp>
  #include <opencv2\highgui\highgui.hpp>
 #include <opencv2\opencv.hpp>


int _tmain(int argc, _TCHAR* argv[])
{

cv::Mat image;
image = cv::imread("im.png", CV_LOAD_IMAGE_COLOR);   // Read the file

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

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

cv::waitKey(0);                                          // Wait for a keystroke in the window
return 0;

}


Solution

  • Try : C:\\Users\\pr\\Downloads\\im.png that should work if the path is correct.