This error means that you are trying to show an empty image. When you load the image with imshow
, this is usually caused by:
- The path of your image is wrong (in Windows escape twice directory delimiters, e.g.
imread("C:pathoimage.png")
should be: imread("C:\path\to\image.png")
, or imread("C:/path/to/image.png")
);
- The image extension is wrong. (e.g. ".jpg" is different from ".jpeg");
- You don't have the rights to access the folder.
A simple workaround to exclude other problems is to put the image in your project dir, and simply pass to imread
the filename (imread("image.png")
).
Remember to add waitKey();
, otherwise you won't see anything.
You can check if an image has been loaded correctly like:
#include <opencv2opencv.hpp>
#include <iostream>
using namespace cv;
int main()
{
Mat3b img = imread("path_to_image");
if (!img.data)
{
std::cout << "Image not loaded";
return -1;
}
imshow("img", img);
waitKey();
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…