python 的执行

lcqqcllcqqcl 2018-02-02 10:36:31
问题如下:
我画了一条线,而且想让矩形在线所在的窗口关闭后才出现,但为什么矩形所在的窗口会在线所在的窗口还没被破坏时,就出现了呢?


代码如下:
# -*- coding:utf-8 -*-
import cv2
import numpy
from cv2 import LINE_8 #线的类型
from cv2 import LINE_AA #线的类型
img=numpy.zeros((512,512,3),numpy.uint8)
cv2.line(img,pt1=(0,0),pt2=(511,50),color=(255,255,255),thickness=5,lineType=LINE_AA)
cv2.imshow('Line',img)
while True:
if cv2.waitKey(1)!=-1:
break
cv2.destroyWindow('line')
img=numpy.ones((512,512,3),numpy.uint8)
img*=255
cv2.rectangle(img,pt1=(50,50),pt2=(130,200),color=(0,255,255),thickness=5)
cv2.imshow('Rectangle',img)
while True:
if cv2.waitKey(1)!=-1:
break
cv2.destroyWindow('rectangle')

结果如下:

请指点
...全文
764 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
陈年椰子 2018-02-04
  • 打赏
  • 举报
回复
试试这样
while True:
    if cv2.waitKey(0)!=-1:
        break

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧