Fitting an image to screen using imshow opencv

BetterEnglish picture BetterEnglish · Jul 19, 2014 · Viewed 58.3k times · Source

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.

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

Answer

Temak picture Temak · Apr 14, 2015

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.

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