Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV & Python - Image too big to display

I have an image that is 6400 × 3200, while my screen is 1280 x 800. Therefore, the image needs to be resized for display only. I am using Python and OpenCV 2.4.9. According to OpenCV Documentation,

If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow.

That is what I am doing, but the image is not fitted to the screen, only a portion is shown because it's too big. I've also tried with cv2.resizeWindow, but it doesn't make any difference.

import cv2 cv2.namedWindow("output", cv2.WINDOW_NORMAL)        # Create window with freedom of dimensions # cv2.resizeWindow("output", 400, 300)              # Resize window to specified dimensions im = cv2.imread("earth.jpg")                        # Read image cv2.imshow("output", im)                            # Show image cv2.waitKey(0)                                      # Display the image infinitely until any keypress 
like image 499
Zynk Avatar asked Feb 03 '16 15:02

Zynk


People also ask

What is OpenCV used for?

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products.

Is OpenCV a C++ or Python?

Python-OpenCV is just a wrapper around the original C/C++ code. It is normally used for combining best features of both the languages, Performance of C/C++ & Simplicity of Python. So when you call a function in OpenCV from Python, what actually run is underlying C/C++ source.

Is OpenCV a Python?

OpenCV-Python is a library of Python bindings designed to solve computer vision problems. Python is a general purpose programming language started by Guido van Rossum that became very popular very quickly, mainly because of its simplicity and code readability.


1 Answers

Although I was expecting an automatic solution (fitting to the screen automatically), resizing solves the problem as well.

import cv2 cv2.namedWindow("output", cv2.WINDOW_NORMAL)    # Create window with freedom of dimensions im = cv2.imread("earth.jpg")                    # Read image imS = cv2.resize(im, (960, 540))                # Resize image cv2.imshow("output", imS)                       # Show image cv2.waitKey(0)                                  # Display the image infinitely until any keypress 
like image 109
Zynk Avatar answered Sep 20 '22 19:09

Zynk