Python 是否可以多次打开和关闭同一cv2车窗?
我的程序是关于在python上用OpenCV2显示来自照相机的图像 用户可以多次打开和关闭同一窗口(按窗口名称) 用户第一次尝试关闭所有内容时运行正常,但第二次尝试关闭时,python冻结 我正在使用Python 是否可以多次打开和关闭同一cv2车窗?,python,python-3.x,opencv,Python,Python 3.x,Opencv,我的程序是关于在python上用OpenCV2显示来自照相机的图像 用户可以多次打开和关闭同一窗口(按窗口名称) 用户第一次尝试关闭所有内容时运行正常,但第二次尝试关闭时,python冻结 我正在使用cv2.destroyWindow(windowName),但我尝试了cv2.destroyAllWindows(),cv2.waitKey(1)在销毁之前,这些都不起作用 我在Windows操作系统上,我看到这个问题在MAC操作系统上很常见 用户选择: s1 = View() while is_
cv2.destroyWindow(windowName)
,但我尝试了cv2.destroyAllWindows()
,cv2.waitKey(1)
在销毁之前,这些都不起作用
我在Windows操作系统上,我看到这个问题在MAC操作系统上很常见
用户选择:
s1 = View()
while is_true:
print("1 -> Start Camera")
print("2 -> Close Camera")
print("3 -> End")
usr_input = input()
if usr_input == "1":
s1.show("topic1", frame) #frame is the image from camera"
elif usr_input == "2":
s1.close("topic1")
elif usr_input == "3":
is_true = False
else:
print("Invalid month")
视图类:
class View:
def show(self, name, frame):
cv2.imshow(name, frame)
cv2.waitKey(1)
def close(self, name):
cv2.destroyWindow(name)
cv2.waitKey(1)
请给出您的代码的最小示例。谢谢。我已经更新了问题,谢谢!我不确定混合使用
input()
和waitKey()
是否是个好主意-它们处理键盘的方式非常不同。我也不确定您是否应该在关闭所有窗口后使用waitKey()
waitKey()
实际上使用了它的插槽来重新绘制窗口。老实说,我只是看到我必须使用它,而且它正在工作(为了显示图像,这是我想要的唯一工作方式)更好地创建最小的工作示例,我们可以复制并运行它。