1

I have a similar problem as this When I use cv2.imshow the image is bigger than my screen.

What to do? I tried several of the answers without success until I tried the answer dealing with cv2.resizeWindow

However I got some surprising result. Even when I use the above function to resize it to the same height and width of the original (so no resize) the window is resized and I can see the entire image

Why is this happening?

Edit: just in case, I used cv2.namedWindow("Original",cv2.WINDOW_NORMAL)

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150

1 Answers1

0

The reason you can see the entire image now is because of the cv2.WINDOW_NORMAL flag you passed into the cv2.namedWindow() function.

This displays the image, cropped if it is too big to fit into the screen:

import cv2

img = cv2.imread("image.png")
cv2.imshow("Image", img)
cv2.waitKey(0)

This displays the image, scaled down to a convenient size (and the window can be resized):

import cv2

img = cv2.imread("image.png")

cv2.namedWindow("Image", cv2.WINDOW_NORMAL)
cv2.imshow("Image", img)
cv2.waitKey(0)

This displays the image, scaled down to the specified size... if the specified size can be fit into your screen; else, it will scale the image to be the size of your screen (and the window can be resized):

import cv2

img = cv2.imread("image.png")
h, w, _ = img.shape
cv2.namedWindow("Image", cv2.WINDOW_NORMAL)
cv2.imshow("Image", img)
cv2.resizeWindow("Image", w, h)

cv2.waitKey(0)

So basically,

it is impossible for the window to be bigger than your screen, but the cv2.WINDOW_NORMAL flag made it so that instead of having the image cropped to fit the screen, it got scaled to fit the screen.

Red
  • 26,798
  • 7
  • 36
  • 58