Search code examples
python-2.7opencvubunturaspbianraspberry-pi3

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


I running this command

python tes4.py

and it causes this error:

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

My program like this

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

What should i do??


Solution

  • np.ravel(gray_img) not gray_img.ravel(). You can also use gray_img.flatten(), but flatten creates a copy so keeping with ravel() is probably best.

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