问题描述:

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.

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():

cv2.waitKey(0)

Then you can force the window to close by typing any key.

相关阅读:
Top