如何在opencv中保持图像窗口的长宽比?

kai*_*046 5 python opencv

documantation,它说我们可以通过CV_WINDOW_KEEPRATIO来保持图像比例,但是在调整窗口后,窗口仍然失去了宽高比。有人可以帮忙吗?

示例代码:

import cv2

# load the image, clone it, and setup the mouse callback function
image = cv2.imread('1.jpg')
cv2.namedWindow('image', cv2.WINDOW_KEEPRATIO)
# keep looping until the 'q' key is pressed
while True:
    # display the image and wait for a keypress
    cv2.imshow('image', image)
    key = cv2.waitKey()

    if key == 27:
        break

# close all open windows
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

Nic*_*k M 0

这可能是显示本身的问题。假设您的显示窗口默认很大。在上面的代码片段中,我没有看到宽高比发生任何变化。检查这里