简体   繁体   English

Python打开CV2代码不起作用

[英]Python open CV2 code not working

i was trying to replicate python CV2 code to extract text from a image file, it runs without errors but i still cannot get any output. 我试图复制python CV2代码以从图像文件中提取文本,它运行时没有错误,但我仍然无法获得任何输出。

Here is my code 这是我的代码

>>> import cv2
>>> import numpy as np
>>> from matplotlib import pyplot as plt
/Users/upendrakumardevisetty/anaconda/lib/python2.7/site-packages/PIL/Image.py:81: RuntimeWarning: The _imaging extension was built for another version of Pillow or PIL
warnings.warn(str(v), RuntimeWarning)
>>> img = cv2.imread('road.png', 0)
>>> plt.imshow(img, cmap='gray', interpolation='bicubic')
<matplotlib.image.AxesImage object at 0x1099c6150>
>>> plt.xticks([]), plt.yticks([])
(([], <a list of 0 Text xticklabel objects>), ([], <a list of 0 Text yticklabel objects>))
>>> plt.show()

What am i doing wrong here? 我在这里做错了什么?

You are exiting your program before you give it a chance to show. 您正在退出程序,然后再显示它。 You should add one more line to your script after plt.show() : 您应该在plt.show()之后plt.show()添加一行plt.show()

cv2.waitKey(0)

Then you can force the window to close by typing any key. 然后,您可以通过键入任何键来强制关闭窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM