1
我剛剛開始學習用於Raspberry Pi 3的Python OpenCV。 我爲namedWindow()編寫了一個簡單的代碼。問題是destroyWindow()不能像我期望的那樣工作。 「測試」窗口仍然存在。下面的代碼有什麼問題?cv2.destroyWindow()不能按預期工作
import cv2
import sys
if __name__ == '__main__':
cv2.namedWindow("TEST")
while True:
key = cv2.waitKey(5)
if key == 27:
print "ESC pressed..."
cv2.destroyWindow("TEST")
break
sys.exit()
你可能想看看[這個鏈接](http://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv)。 – Aenimated1
將destroyWindow(「TEST」)移出循環。 –
當我最後一次使用'destroyWindow'時,我不得不在'destroyWindow'前後兩次調用'waitKey'(前兩個,後五個),我還必須啓動一個'cvWindowThread'就在我創建'namedWindow'之前。然後,我在末尾調用了'std :: terminate()',因爲線程沒有正確關閉(注意,這是在C++中,python可能更好地處理線程)。 –