問題
JupyterでOpenCVを使うときにcv2.destroyAllWindows()すると固まってしまう
環境
- macOS High Sierra
- Jupyter notebook
- OpenCV2
解決
cv2.startWindowThread()
cv2.imshow('image', img)
key = cv2.waitKey(0)
if key == ord('q'): #qを押した時の処理
cv2.waitKey(1)
cv2.destroyAllWindows()
cv2.waitKey(1)
まとめ
- imshowの前にstartWindowThread()を入れる
- destroyAllWindows()をwaitKey()で挟む