OpenCv图像没有显示

OpenCv image is not getting displayed

本文关键字:显示 图像 OpenCv      更新时间:2023-10-16

请看下面的代码

#include <opencv2corecore.hpp>
#include <opencv2highguihighgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
    Mat image;
    try
    {
        image = imread("C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg");
        if(!image.data)
        {
            throw 1;
        }
        cout << "Height: " << image.size().height << " Width: " << image.size().width << endl;
    }
    catch(int error)
    {
        cout << "This message does not exists" << endl;
        exit(0);
    }
    namedWindow("Image 1");
    imshow("Image 1",image);

    system("pause");
    return 0;
}

当我运行这段代码时,我没有得到图像显示。相反,将显示一个空白图像。为什么呢?请帮助。

您需要让窗口刷新。系统("pause")不执行此操作。与opencv等价的是waitKey (0);