20

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
}
herohuyongtao
  • 45,575
  • 23
  • 118
  • 159
BetterEnglish
  • 1,009
  • 2
  • 20
  • 38

3 Answers3

33

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

Temak
  • 2,571
  • 30
  • 45
  • 6
    I add it is crucial the 2nd argument of namedWindow is set to WINDOW_NORMAL (as opposed to WINDOW_AUTOSIZE). Otherwise, the window will not be resized. – tagoma Sep 13 '15 at 19:11
7

Passing CV_WINDOW_AUTOSIZE to 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.

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);
herohuyongtao
  • 45,575
  • 23
  • 118
  • 159
  • 2
    Using WINDOW_NORMAL did not scale the image to fit the window or screen. I had to resize the image, as this answer says. – redcurry Mar 04 '16 at 01:17
0

You need put CV_WINDOW_OPENGL instead CV_WINDOW_AUTOSIZE

ARCAON
  • 61
  • 1
  • 6