Qt中的OpenCV中没有显示图像

时间:2016-09-07 19:00:52

标签: c++ image qt opencv image-processing

我是OpenCV的新手并在Qt Creator中使用它。我想要显示图像。我的代码是:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <iostream>
#include <string>

using namespace cv;
using namespace std;

int main( )
{
    Mat image=imread("C:/Users/richa/Desktop/IMG-20150324-WA0001.jpg",CV_LOAD_IMAGE_COLOR); // Read the file


    if( image.empty() )                      // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow("Image",WINDOW_AUTOSIZE); // Create a window for display.
    imshow( "Image", image );                // Show our image inside it.

    waitKey(); // Wait for a keystroke in the window
    return 0;
}

输出只是一个没有图像的控制台窗口。该程序也以代码-1073741511退出。为什么没有在新窗口中加载图像? 截图: enter image description here

1 个答案:

答案 0 :(得分:0)

尝试:

int main( )
{
    Mat image=imread("C:/Users/richa/Desktop/IMG-20150324-WA0001.jpg",CV_LOAD_IMAGE_COLOR); // Read the file


    if( image.empty() )                      // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow("Image",WINDOW_AUTOSIZE); // Create a window for display.

    for(;;)//infinite loop
    {
    imshow( "Image", image );                // Show our image inside it.

    char c=waitKey(10); // Wait for a keystroke in the window for 10ms, then move on
    if(c=='b' || c=='B')//if b is pressed
    break;
    }
    return 0;
}