【问题标题】:How to show resized image OpenCV imshow()如何显示调整大小的图像 OpenCV imshow()
【发布时间】:2021-08-19 10:29:48
【问题描述】:

我有一个 3000x4000 的图像,我正在使用以下代码:

import cv2 as cv
im = cv.imread ('we.jpg', cv.IMREAD_IGNORE_ORIENTATION) # So the image appears in horizontal
cv.imshow ("", im)

图像打开到一个真实的比例,这使我无法完整地看到它(只有一部分图像是可见的)。

有什么方法可以查看缩放后的图像,使其可以按照其尺寸进行操作,但在查看时,它看起来是完整的?提前致谢!

【问题讨论】:

  • 当你想查看图像时复制它 & resize the copy prior to showning it
  • 是的,我当然这样做了,但问题是我必须在显示后对该图像做一些其他事情,所以我需要保持真实尺寸。
  • 只是重新复制结果以显示每次你的东西。

标签: python opencv imshow


【解决方案1】:

只需说:cv.namedWindow("thewindow", cv.WINDOW_NORMAL)(在相应的 imshow 调用之前)

这使得窗口可以调整大小。

如果您希望窗口使用线性插值(可能会或可能不会识别伽马...),请添加 WINDOW_OPENGL 标志。一些 GUI 后端通常使用最近邻“插值”(例如 win32)。

【讨论】:

  • 这很棒:)
【解决方案2】:

也许你可以这样做:

import sys
import cv2
import numpy as np

down_scale = 4

dir = sys.path[0]
original = cv2.imread(dir+'/im.png')
h, w = original.shape[:2]

small = cv2.resize(original.copy(), (w//down_scale, h//down_scale))
cv2.imshow('Small Image', small)

# Do whatever you like here.
# For example, you found the coordinates on
# the small image and now you want to find
# it on the big image.

positionOnSmallImage = (10, 10)
positionOnLargeImage = (10*down_scale, 10*down_scale)

cv2.waitKey(0)

【讨论】:

    猜你喜欢
    • 2020-01-29
    • 2014-07-21
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多