打开简历不读取图像

问题描述

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

#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(),否则您将永远看不到命名窗口。

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

OpenCV 2.4中imshow()的注释说:

此函数后应带有waitKey函数,该函数将显示指定毫秒的图像。否则,它将不会显示图像。 ...

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...