cv2.imshow() 函数正在打开一个总是说没有响应的窗口 - python opencv [英] cv2.imshow() function is opening a window that always says not responding - python opencv

查看:50
本文介绍了cv2.imshow() 函数正在打开一个总是说没有响应的窗口 - python opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个非常简单的程序.打开和 jpg 文件并使用 python 的 opencv 库显示它.最初一切正常,但现在它只是打开一个不显示图像但显示无响应"的窗口.我需要去任务管理器关闭它!

I am trying to run a very simple program. To open and jpg file and display it using the opencv library for python. Initially it all worked fine but now it just opens a window which doesn't show the image but says 'not responding'. I need to go to the task manager and close it!

from numpy import *
import matplotlib as plt
import cv2

img = cv2.imread('amandapeet.jpg')
print img.shape

cv2.imshow('Amanda', img)

推荐答案

你又错过了一行:

cv2.waitKey(0)

然后窗口显示图像,直到您按下键盘上的任意键.或者您可以通过以下方式传递:

Then the window shows the image until you press any key on keyboard. Or you can pass as following:

cv2.waitKey(1000)
cv2.destroyAllWindows()

此处,窗口显示图像 1000 毫秒或 1 秒.之后,窗口将自行消失.但在某些情况下,它不会.所以你可以使用 cv2.destroyAllWindows()

Here, window shows image for 1000 ms, or 1 second. After that, the window would disappear itself. But in some cases, it won't. So you can forcefully destroy it using cv2.destroyAllWindows()

请先阅读更多教程:http://docs.opencv.org/trunk/doc/py_tutorials/py_tutorials.html

这篇关于cv2.imshow() 函数正在打开一个总是说没有响应的窗口 - python opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆