繁体   English   中英

Open cv is not reading 图像

[英]Open cv is not reading image

这是我的一段代码。 但是每次都显示无法读取数据。 我尝试了多种写入图像路径的格式,但没有奏效。 还有其他人面临同样的问题吗?

#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()必须跟在waitKey()之后,否则您永远看不到命名的 window。

imshow("My Image", source);
waitKey(0);  // should be here.
destroyAllWindows();

OpenCV 2.4 中imshow()的注释说:

这个 function 应该跟在 waitKey function 之后,它显示指定毫秒的图像。 否则,它不会显示图像。 ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM