为什么cv2.destroyAllWindows无法在if结构中运行?

时间:2019-02-09 20:16:01

标签: python image opencv processing cv2

我想通过cv2.destroyAllWindows()销毁python中的所有窗口。这是由flowint 5 cv2.wiatKey()工作的,但是当我在结构中使用cv2.destroyAllWindows()时,它将无法工作...

这是可以破坏寡妇的第一个代码:        导入cv2        将numpy导入为np

   img = cv2.imread('test.png',-1)
   cv2.namedWindow('image',cv2.WINDOW_AUTOSIZE)
   cv2.imshow('image',img)
   cv2.imwrite('image.png',img)
   k = cv2.waitKey(0)
   cv2.destroyAllWindows()
   for i in range(5):    # maybe 5 or more
   cv2.waitKey(1)

这是第二条无法摧毁寡妇的代码:        导入cv2        将numpy导入为np

   img = cv2.imread('test.png',-1)
   cv2.namedWindow('image',cv2.WINDOW_AUTOSIZE)
   cv2.imshow('image',img)
   cv2.imwrite('image.png',img)
   k = cv2.waitKey(0)

if k == 27 :
      cv2.destroyAllWindows()
      for i in range(10):    # maybe 5 or more
          cv2.waitKey(1)
elif k == ord('s') :
      cv2.imwrite('image.png',img)
      cv2.destroyAllWindows()
      for i in range(10):    # maybe 5 or more
          cv2.waitKey(1)

0 个答案:

没有答案