ImportError:无法导入名称“ imshow”

时间:2018-10-14 20:28:00

标签: python opencv computer-vision

不幸的是,我没有找到解决此问题的方法。

from imgutils import imshow
import cv2

img3 = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

plt.figure(figsize=(20,10))

plt.subplot(1,2,1); imshow(img)
plt.subplot(1,2,2); imshow(img3)

我得到以下回溯:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-31-8006396b3a04> in <module>
----> 1 from imgutils import imshow
      2 
      3 img3 = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
      4 
      5 plt.figure(figsize=(20,10))

ImportError: cannot import name 'imshow'

我正在使用anaconda环境python 3.5在Mac OS X 10.11上工作。

我已经在网上搜索了imgutils模块,但没有一个具有imshow功能的模块。

有什么建议吗?


更新

from cv2 import imshow

img3 = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

plt.figure(figsize=(20,10))

plt.subplot(1,2,1); imshow(img)
plt.subplot(1,2,2); imshow(img3)

追踪

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-d01b4c235975> in <module>
      5 plt.figure(figsize=(20,10))
      6 
----> 7 plt.subplot(1,2,1); imshow(img)
      8 plt.subplot(1,2,2); imshow(img3)

TypeError: Required argument 'mat' (pos 2) not found

1 个答案:

答案 0 :(得分:1)

imgutils似乎不包含import matplotlib.pyplot as plt # Create the figure fig = plt.figure( figsize=(10,10) ) ax = fig.add_subplot(1, 1, 1, title='TSNE, clustering' ) # Create the scatter ax.scatter( x=df_tsne['x-tsne'], y=df_tsne['y-tsne'], c=df_tsne['label'], s=30, cmap=plt.cm.get_cmap('Paired'), alpha=0.8) plt.show() 属性(因此绝对不是函数)。它不包含imshow子模块,也不在imshow文件中导入imshow函数:基本上像这样从子模块重新导入元素,但是快速搜索不会产生{ {1}}功能。

您可能希望使用__init__.py模块中的imshow,因此应该替换:

imshow

具有:

matplotlib.pyplot

然后导入cv2.imshow [pyplot-doc]函数。