为什么 cv2.destroyAllWindows() 在 Mac 上不起作用?

问题描述 投票:0回答:1

我正在尝试学习 python3 上的 OpenCV 框架,当我想销毁打开的图像时,什么也没有发生,关闭窗口的唯一方法是“强制退出”。我尝试了一些解决方案,例如u200d

cv2.startWindowThread()
,但它对我不起作用。这是我的代码:

import cv2
import numpy as np
import matplotlib as plt
img = cv2.imread('image.jpg')
cv2.startWindowThread()
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

版本:

python -> 3.6.0

OpenCV -> 3.3.0

macOS High Sierra -> 10.13.6


更新:

我试图在 jupyter-notebook 中运行代码,当我尝试在 Pycharm 中运行它时,我没有更多问题。

python macos opencv macos-high-sierra
1个回答
2
投票

我不确定为什么对我来说以下解决方法有效:

cv2.imshow(name, img)
cv2.startWindowThread()
print(cv2.waitKey(0))
cv2.destroyAllWindows()
for i in range(2):
    cv2.waitKey(1)

基于这个答案

© www.soinside.com 2019 - 2024. All rights reserved.