C++ 使用 imshow opencv 将图像拟合到屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24842382/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:49:49  来源:igfitidea点击:

Fitting an image to screen using imshow opencv

c++opencvimshow

提问by BetterEnglish

I want to display an image using opencv on Mac os X 13'. The image size is 1920?×?1080. When I run this code, I see just a part of an image. I need to fit the image to the screen.

我想在 Mac os X 13' 上使用 opencv 显示图像。图像尺寸为 1920××1080。当我运行此代码时,我只看到图像的一部分。我需要使图像适合屏幕。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include<string.h>
using namespace cv;
using namespace std;

int main()
{
   Mat image=imread("/Users/rafikgouiaa/Qt/projects/MakeVideo/build-MakeVideo-    Desktop_Qt_5_0_2_clang_64bit-Debug/im.jpg");
   namedWindow( "Display frame",CV_WINDOW_AUTOSIZE);
   imshow("Display frame", image);
   waitKey(0);
   return 0
}

回答by Temak

If you need to show an image that is bigger than the screen resolution, you will need to call

如果您需要显示大于屏幕分辨率的图像,则需要调用

namedWindow("Display frame", WINDOW_NORMAL)

before the imshow.

在 imshow 之前。

To set desirable size of the window call please

要设置所需的窗口调用大小,请

cv::resizeWindow("Display frame", WIDTH, HEIGHT);

For more details see http://docs.opencv.org/modules/highgui/doc/user_interface.html#imshow

有关更多详细信息,请参阅http://docs.opencv.org/modules/highgui/doc/user_interface.html#imshow

回答by herohuyongtao

Passing CV_WINDOW_AUTOSIZEto namedWindow()will make the window size automatically adjust to fit the displayed image. And you see part of the image is probably because the image is too large for your screen.

传递CV_WINDOW_AUTOSIZEnamedWindow()将使窗口大小自动调整以适合显示的图像。您看到的部分图像可能是因为图像对于您的屏幕来说太大了。

To work out, you can first resize the image to smaller size. Like this:

要解决这个问题,您可以先将图像调整为较小的尺寸。像这样:

Mat image=imread("...");
resize(image, image, Size(image.cols/2, image.rows/2)); // to half size or even smaller
namedWindow( "Display frame",CV_WINDOW_AUTOSIZE);
imshow("Display frame", image);

回答by ARCAON

You need put CV_WINDOW_OPENGL instead CV_WINDOW_AUTOSIZE

你需要把 CV_WINDOW_OPENGL 而不是 CV_WINDOW_AUTOSIZE