简体   繁体   English

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

[英]Fitting an image to screen using imshow opencv

I want to display an image using opencv on Mac os X 13'. 我想在Mac OS X 13'上使用opencv显示图像。 The image size is 1920 × 1080. When I run this code, I see just a part of an image. 图像大小为1920×1080。当我运行此代码时,我只看到图像的一部分。 I need to fit the image to the screen. 我需要将图像适合屏幕。

#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
}

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

Passing CV_WINDOW_AUTOSIZE to namedWindow() will make the window size automatically adjust to fit the displayed image. 传递CV_WINDOW_AUTOSIZEnamedWindow()将使窗口大小自动调整以适合显示的图像。 And you see part of the image is probably because the image is too large for your screen. 而且你看到部分图像可能是因为图像太大而不适合你的屏幕。

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);

您需要将CV_WINDOW_OPENGL改为CV_WINDOW_AUTOSIZE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM