AttributeError:'module'对象没有属性'popall'

时间:2017-04-27 08:16:27

标签: python-2.7 opencv ubuntu raspbian raspberry-pi3

我正在运行此命令

python tes4.py

并导致此错误:

AttributeError: 'module' object has no attribute 'popall'

我的节目就像这样

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

gray_img = cv2.imread('lena.jpg', cv2.IMREAD_GRAYSCALE)
cv2.imshow('GoldenGate',gray_img)
#hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
hist,bins = np.histogram(gray_img,256,[0,256])

plt.hist(gray_img.ravel(),256,[0,256])
plt.title('Histogram for gray scale picture')
plt.show()

while True:
    k = cv2.waitKey(0) & 0xFF     
    if k == 27: break             # ESC key to exit
cv2.destroyAllWindows()

我该怎么办?

1 个答案:

答案 0 :(得分:0)

np.ravel(gray_img)不是gray_img.ravel()。您也可以使用gray_img.flatten(),但flatten会创建一个副本,因此与ravel()保持一致可能是最好的。

https://docs.scipy.org/doc/numpy-1.10.4/reference/generated/numpy.ravel.html
https://docs.scipy.org/doc/numpy-1.10.4/reference/generated/numpy.ndarray.flatten.html