Skip to content

Commit

Permalink
修正了窗口显示的bug
Browse files Browse the repository at this point in the history
cv2.waitKey(0)会导致第一个窗口一直显示,关闭该窗口之后程序还在堵塞状态,第二个窗口也无法正常显示。改用循环语句和条件语句结合来控制窗口的显示和关闭。
  • Loading branch information
Zpadger committed Dec 3, 2019
1 parent 8b17a30 commit 509b1b2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Question_11_20/answers_py/answer_14.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 509b1b2

Please sign in to comment.