OpenCV cv :: Mat显示空的灰色图像?找不到原因 [英] OpenCV cv::Mat displays empty gray images? Cant find the reason

查看:483
本文介绍了OpenCV cv :: Mat显示空的灰色图像?找不到原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在c ++项目中使用opencv库在将来的过程中显示此"img1.jpg"图像,但它仅显示一个空的灰色窗口.这是什么原因.这段代码有错误吗?请帮忙!

I just want to display this "img1.jpg" image in a c++ project with using opencv libs for future processes, but it only displays an empty gray window. What is the reason of this. Is there a mistake in this code? please help!

这是代码;

 Mat img1;
 char imagePath[256] = "img1.jpg";
 img1 = imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE);
 namedWindow("result", 1);
 imshow("result", img1);

谢谢...

推荐答案

我遇到了同样的问题,并解决了将waitKey(1);放在imshow()之后的问题. OpenCV文档解释了原因:

I had the same problem and solved putting waitKey(1); after imshow(). The OpenCV documentation explains why:

此函数是HighGUI中唯一可以获取和处理的方法 事件,因此对于正常事件需要定期调用 处理,除非在需要以下操作的某些环境中使用HighGUI 关心事件处理.

This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing, unless HighGUI is used within some environment that takes care of event processing.

这篇关于OpenCV cv :: Mat显示空的灰色图像?找不到原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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