gpt4 book ai didi

python - 导入错误 : No module named pyplot - Opencv

转载 作者:太空宇宙 更新时间:2023-11-03 21:52:31 25 4
gpt4 key购买 nike

我正在尝试执行以下代码:

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('Paw01.png',0)
img = cv2.medianBlur(img,5)

ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)
titles = ['Original Image', 'Global Thresholding (v = 127)',
'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
images = [img, th1, th2, th3]
for i in xrange(4):
plt.subplot(2,2,i+1),plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()`

但是,它返回错误:

Traceback (most recent call last): File "/home/lrcorre/Desktop/Paper SIBGRAPI/OpenCV_Programs/Thresholding.py", line 3, in import matplotlib.pyplot as plt File "/home/lrcorre/Desktop/Paper SIBGRAPI/OpenCV_Programs/matplotlib.py", line 3, in import matplotlib.pyplot as plt ImportError: No module named pyplot

我已经安装了 matplotlibOpencvpython 2.7。任何人都知道我该如何解决这个问题并继续?

最佳答案

matplotlib 是python绘图库的目录名。在那个目录下有一个像这样的文件pylot.py。

/dir1/dir2/.../site-packages/matplotlib/pyplot.py

在您的情况下,您在 PYTHONPATH 目录的某处定义了 matplotlib.py。

 /home/lrcorre/Desktop/PaperSIBGRAPI/OpenCV_Programs/matplotlib.py

这禁止导入你想要的pyplot.py文件。因此,将文件名更改为不同的名称。

关于python - 导入错误 : No module named pyplot - Opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36243239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com