0

请看下面的代码

#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;
}

当我运行此代码时,我没有显示图像。而是显示空白图像。这是为什么?请帮忙。

4

1 回答 1

2

您需要让窗口刷新。system("pause") 不这样做。opencv 的等价物是 waitKey(0);

于 2013-04-08T15:38:12.503 回答