I am newbie to OPENCV. Now I am trying to display an image using imread(), but imread() doesn't work(keep returning empty mat.) But when I try to draw lines, circles and so on by imread(), it works well.
So I thought there would be something wrong with addressing. And I tried everything I can but it still doesn't work. And I also have googled a lot of things to solve it, but I can't get any answer to this problem.
What should I do? Is there something wrong I have missed?
I currently use Windows 10, Visual Studio 2017, and openCV 4.0.0 alpha.
Here is my code.
#include <iostream>
#include <opencv2/opencv.hpp>
#ifdef _DEBUG
#pragma comment(lib,"opencv_world400d.lib")
#else
#pragma comment(lib,"opencv_world400.lib")
#endif
using namespace std;
using namespace cv;
int main()
{
Mat image;
image =imread("C:/Users/ymin/source/repos/Project1/Project1/BENZ.bmp",IMREAD_ANYCOLOR);
if (image.empty())
{std::cerr << "Could not open file" << std::endl; return (1);}
imshow("image", image);
waitKey();
return 0;
}
From the OpenCV documentation for imread:
If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix.
This indicates that the file is not there (maybe typo?), you don't have permission to read it, it is in a format not recognized by OpenCV, or it is corrupted.
Make sure the file is where you think it is, and that it is readable, and that OpenCV is compiled to support whatever format the file is in.
(Note that the file extension does not determine its format, you can take a JPEG file and rename it to have a .bmp extension, but it is still a JPEG file.)