简体   繁体   中英

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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