C++ OpenCV imshow() 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19565262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV imshow() does not work
提问by Armin Mustafa
I have written an openCV code and my code has following statement:
我写了一个 openCV 代码,我的代码有以下语句:
cv::imshow("Matches", matchesImg);
cv::waitKey(0);
When I run the code either in Debug or Release I am not able to see window which shows me the output.
当我在 Debug 或 Release 中运行代码时,我看不到显示输出的窗口。
And this is happening for every project I create.
这发生在我创建的每个项目中。
Not able to figure out the reason, Can someone please guide me on this?
无法弄清楚原因,有人可以指导我吗?
I am coding on Windows 7 and Visual studio 2010, with opencv version of 2.4.6
我在 Windows 7 和 Visual Studio 2010 上编码,opencv 版本为 2.4.6
采纳答案by CTZStef
As I mentioned in the comments, you have to create a window first, using namedWindow
with the same window name as in imshow
See this tutorialfor details.
正如我在评论中提到的,您必须先创建一个窗口,使用namedWindow
与imshow
查看本教程中相同的窗口名称以获取详细信息。
EDIT
编辑
Thisstrongly suggest that you have to create the window beforehand. Some may argue that it didn't work this way for previous versions of OpenCV. Then, let's say this solution apply at least to OpenCV 2.4.6, which is the version of concern here (and it solved the problem).
这强烈建议您必须事先创建窗口。有些人可能会争辩说,它不适用于以前版本的 OpenCV。然后,假设这个解决方案至少适用于 OpenCV 2.4.6,这是这里关注的版本(它解决了问题)。