OpenCv 2.4.11 - 图片不会显示

时间:2015-05-29 15:21:17

标签: c++ opencv imread

我一直在尝试使用VS 2013中的OpenCV 2.4.11(调试)加载和显示图片。问题是图片不会显示,我无法弄清楚。显示的只是填充灰色的空窗口。我尝试显示大量图像,更改图片加载等属性,并在线查找相同的问题。这是代码:

static Mat read_sample(const string& samplePath, int &label, char separator = ';')
{
    Mat sample;
    //sample = imread(samplePath, 1);
    sample = imread("C:/Users/honzik/Desktop/kotel.jpg", CV_LOAD_IMAGE_COLOR);
    waitKey(0);
    label = 777;

    if (sample.empty())
    {
        cout << "Error loading sample!" << endl;
        exit(1);
    }

    //namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
    imshow("MyWindow", sample);


    //Mat graySample;
    //cvtColor(sample, graySample, CV_BGR2GRAY);
    //imshow("gray sample", graySample);

    Mat resizedSample;
    resize(sample, resizedSample, Size(92, 112), 1.0, 1.0, INTER_CUBIC);
    imshow("resized sample", resizedSample);

    return resizedSample;

    /*
    IplImage* img = cvLoadImage("C:/Users/honzik/Desktop/kotel.jpg");
    cvNamedWindow("Test", 10);
    cvShowImage("Test", img);
    Mat mat = Mat(img);

    return mat;*/
}

0 个答案:

没有答案