[英]Open cv is not reading image
Here is my piece of code.这是我的一段代码。 But every time it shows data cannot be read.
但是每次都显示无法读取数据。 I have tried multiple formates of writing path to image but that did not worked.
我尝试了多种写入图像路径的格式,但没有奏效。 Any one else facing same problem?
还有其他人面临同样的问题吗?
#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/opencv.hpp>
#include <vector>
using namespace cv;
int main()
{
Mat source = imread("C:\\Untitled.jpg");
namedWindow("My Image");
waitKey(0);
if (!source.data)
{
std::cout << "Data cannot be read" << std::endl;
return -1;
}
imshow("My Image", source);
destroyAllWindows();
return 0;
}
imshow()
must be followed by waitKey()
or you can never see the named window. imshow()
必须跟在waitKey()
之后,否则您永远看不到命名的 window。
imshow("My Image", source);
waitKey(0); // should be here.
destroyAllWindows();
The note for imshow()
in OpenCV 2.4 says: OpenCV 2.4 中
imshow()
的注释说:
This function should be followed by waitKey function which displays the image for specified milliseconds.
这个 function 应该跟在 waitKey function 之后,它显示指定毫秒的图像。 Otherwise, it won't display the image.
否则,它不会显示图像。 ...
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.