This error means that you are trying to show a blank image. When you upload an image using imshow , this is usually caused by:
- The path of your image is incorrect (directory separators are duplicated twice in Windows, for example
imread("C:\path\to\image.png") should be: imread("C:\\path\\to\\image.png") or imread("C:/path/to/image.png") ); - Incorrect image extension. (for example, ".jpg" is different from ".jpeg");
- You do not have permission to access the folder.
A simple workaround to eliminate other problems is to place the image in the project directory and simply go to imread the file name ( imread("image.png") ).
Remember to add waitKey(); otherwise you will not see anything.
You can check if the image is loaded correctly, for example:
#include <opencv2\opencv.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; }
source share