问题
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
}
回答1:
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
回答2:
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);
回答3:
You need put CV_WINDOW_OPENGL instead CV_WINDOW_AUTOSIZE
来源:https://stackoverflow.com/questions/24842382/fitting-an-image-to-screen-using-imshow-opencv