openCV imshow无法在屏幕上呈现图像 [英] openCV imshow not rendering image on screen

查看:343
本文介绍了openCV imshow无法在屏幕上呈现图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是openCV的新手,最近获得了openCV 2.4.7的预编译版本,并成功地将其与Visual Studio 2010集成.

I am new to openCV, have recently obtained a pre-compiled version of openCV 2.4.7 and was successfully able to integrate it with visual studio 2010.

显然,库似乎可以正常工作,但是当我尝试使用imshow显示图像时,它会显示窗口,但不会在其中显示图像.

Apparently library seems to work fine, but when I'm trying to display image using imshow it displays the window but doesn't display image in it.

{
    cv::Mat image = cv::imread("F:/office_Renzym/test3.jpg",CV_LOAD_IMAGE_UNCHANGED);

    if(image.empty())
    {
        cout<<"image not loaded";
    }
    else
    {
        cv::namedWindow( "test", CV_WINDOW_AUTOSIZE );
        cv::imshow("test",image);
    }   
}

任何帮助将不胜感激.

推荐答案

您必须具有:

cv::waitKey(0);

代替:

system("pause");

后者根本不起作用. OpenCV需要泵送消息以显示和更新窗口,而waitKey函数内部是执行此操作的所有机制.

The latter just doesn't work. OpenCV needs to pump messages to get the window displayed and updated, and inside that waitKey function is all of the mechanism to do so.

正如文档所述,waitKey仅在打开HighGUI窗口的情况下才有效,因此在代码中,您可能需要执行以下操作:

As the documentation says, waitKey only works if you have a HighGUI window open, so in your code, you probably need to do this:

cv::Mat image = cv::imread("F:/office_Renzym/test3.jpg",CV_LOAD_IMAGE_UNCHANGED);

if(image.empty())
{
    cout<<"image not loaded";
}
else
{
    cv::namedWindow( "test", CV_WINDOW_AUTOSIZE );
    cv::imshow("test",image);
    cv::waitKey(0);
}   

如果图像格式有问题,您可以尝试像这样加载:

In case there's a problem with the image format, you might try loading like this:

cv::Mat image = cv::imread("F:/office_Renzym/test3.jpg",CV_LOAD_IMAGE_COLOR);

这篇关于openCV imshow无法在屏幕上呈现图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆