简体   繁体   English

OpenCv图像未显示

[英]OpenCv image is not getting displayed

Please have a look at the following code 请查看以下代码

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.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;
}

When I run this code, I do not get the image displayed. 当我运行此代码时,我没有显示图像。 Instead, a blank image is displayed. 而是显示空白图像。 Why is that? 这是为什么? Please help. 请帮忙。

You need to let the window refresh. 你需要刷新窗口。 system("pause") does not do it. 系统(“暂停”)不这样做。 The opencv equivalent is waitKey(0); opencv等价物是waitKey(0);

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

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