From 509b1b2462bd7d2c72c5078c59d53339fa52cb96 Mon Sep 17 00:00:00 2001 From: Zpadger <31385823+Zpadger@users.noreply.github.com> Date: Tue, 3 Dec 2019 16:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cv2.waitKey(0)会导致第一个窗口一直显示,关闭该窗口之后程序还在堵塞状态,第二个窗口也无法正常显示。改用循环语句和条件语句结合来控制窗口的显示和关闭。 --- Question_11_20/answers_py/answer_14.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Question_11_20/answers_py/answer_14.py b/Question_11_20/answers_py/answer_14.py index 334b2176..a74a3de0 100644 --- a/Question_11_20/answers_py/answer_14.py +++ b/Question_11_20/answers_py/answer_14.py @@ -58,10 +58,17 @@ def different_filter(img, K_size=3): # Save result cv2.imwrite("out_v.jpg", out_v) -cv2.imshow("result", out_v) -cv2.waitKey(0) +cv2.imshow("result_v", out_v) +while cv2.waitKey(100) != 27:# loop if not get ESC + if cv2.getWindowProperty('result_v',cv2.WND_PROP_VISIBLE) <= 0: + break +cv2.destroyWindow('result_v') cv2.imwrite("out_h.jpg", out_h) -cv2.imshow("result", out_h) -cv2.waitKey(0) +cv2.imshow("result_h", out_h) +# loop if not get ESC or click x +while cv2.waitKey(100) != 27: + if cv2.getWindowProperty('result_h',cv2.WND_PROP_VISIBLE) <= 0: + break +cv2.destroyWindow('result_h') cv2.destroyAllWindows()