C++ openCV 中的 imshow 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15473055/
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
imshow function in openCV
提问by Aayman Khalid
I am using imshow function to display images in OpenCV. It works fine, there is just a little thing though: the title I write for the image is not correctly displayed.
我正在使用 imshow 函数在 OpenCV 中显示图像。它工作正常,但只有一点:我为图像编写的标题未正确显示。
For example, when I write "Original" or "inverted" they are displayed with some extra and unintelligible data in the beginning. However, when I write "thresholded Image" a long line of unintelligible words is displayed instead of the title...
例如,当我写“Original”或“inverted”时,它们在开始时会显示一些额外且难以理解的数据。但是,当我写“阈值图像”时,会显示一长串难以理解的单词而不是标题......
It does not effect anything else but it seems queer to me. Do you have any idea why that happens?
它不会影响其他任何东西,但对我来说似乎很奇怪。你知道为什么会这样吗?
Here is my code:
这是我的代码:
IplImage* image=cvLoadImage("Black&White.jpg");
Mat image1;
image1=Mat(image,false);
imshow("Image",image1);
cvWaitKey(0);
回答by MattTheHack
First of all, you are using the C and C++ libraries interchangeably - IpIImage belongs to C and Mat belongs to C++, this could be the source of your problem. Instead, try just using the C++ interface and your code will be as follows :
首先,您可以互换使用 C 和 C++ 库 - IpIImage 属于 C 而 Mat 属于 C++,这可能是您问题的根源。相反,尝试只使用 C++ 接口,您的代码将如下所示:
Mat image = imread("Black&White.jpg");
imshow("Image",image);
waitKey(0);
That should fix your problem, if not, try using the C interface
那应该可以解决您的问题,如果没有,请尝试使用 C 接口
IplImage* image = cvLoadImage("Black&White.jpg");
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
cvShowImage("Image", image);
cvWaitKey(0);
回答by Floris
Have you really checked that you used the proper link to the file? In my case, I usually check it by doing:
您是否真的检查过是否使用了正确的文件链接?就我而言,我通常通过执行以下操作来检查它:
image = imread( "C:\\CloudStation\\Bestanden\\VisualStudio2010\\Projects\\TMerger\\Debug\\black_and_white.tif")
So in my case, I have to use a double backward slash.
所以就我而言,我必须使用双反斜杠。
Hope it helps.
希望能帮助到你。
greetings, Floris.
问候,弗洛里斯。