When I run the provided code, a imshow() opens a window but it is just an empty gray window. The code executes successfully (doesn't trigger the !image.data check.) The imwrite() function does successfully write the image to a file so I don't think it is a problem with reading the image.
I also tried opening a named window first, and then calling imshow to that window, but that also didn't help.
It seems like there are a few other people having this issue on this site. I browsed the answers and tried the solutions but nothing worked. Also I could not find anyone using opencv 4.0 with c++.
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace std;
using namespace cv;
int main() {
Mat image;
image = imread("./887.jpg");
if (!image.data)
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
imwrite("test.jpg", image);
waitKey(1);
imshow("Display window", image); // Show our image inside it.
waitKey(0);
return 0;
}
I expect the image to show up in a window titled "Display window", the window does show up but it is just an empty gray box.
!image.data. I think it is better to use empty!image.empty(). If you manage to save an image then it probably is ok.... You can always try to show an image created by you, likecv::Mat example(600, 800, CV_8UC3, cv::scalar(0,0,255));which is a red image - api55image.empty(), but it is the same check. - Elvis Oric