本文介绍了Python OpenCV-waitKey(0)没有响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ubuntu 12.04上使用opencv 2.4.7.我正在用python编程,运行此脚本时出现问题:

I'm using opencv 2.4.7 on ubuntu 12.04. I'm programming with python and I have a problem when i run this script:

import cv2

img = cv2.imread('347620923614738322_233985812.jpg')
cv2.namedWindow("window")
cv2.imshow("window", img)
cv2.waitKey(0)

问题是关闭图像时脚本不会停止.我搜索了有关waitKey的信息,发现使用cv2.waitKey(0)是正确的.

The problem is that the script doesn't stop when I close the image. I searched information about waitKey and I found that using cv2.waitKey(0) is correct.

我不明白,问题出在哪里?

推荐答案

此代码适用于IDLE:

This code works for me from IDLE:

# -*- coding: utf-8 -*-

# Objectif : découvrir le fonctionnement d'opencv-python
# http://opencv-python-tutroals.readthedocs.org/en/latest/index.html


import numpy as np
import cv2

# Load an color image in grayscale
img = cv2.imread('Lena.tiff',0)
WINDOW_NAME = 'Image de Lena'
cv2.namedWindow(WINDOW_NAME, cv2.CV_WINDOW_AUTOSIZE)
cv2.startWindowThread()

# Display an image
cv2.imshow(WINDOW_NAME,img)
cv2.waitKey(0) 


cv2.destroyAllWindows()

希望这对将来的读者有所帮助.

Hope this helps for future readers.

这篇关于Python OpenCV-waitKey(0)没有响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:42