【问题标题】:Image is not being shown in OpenCV in QtQt 的 OpenCV 中未显示图像
【发布时间】:2016-09-07 19:00:52
【问题描述】:

我是 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 退出。为什么图像没有在新窗口中加载? 截屏:

【问题讨论】:

  • 问题可能是您在外部终端中运行程序。只需将您的 QtCreator 配置为在 Check Projects -&gt; Run Settings -&gt; Run in terminal 中禁用它。

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


【解决方案1】:

试试:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 2012-12-24
    • 2020-05-11
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多