提取直方图
#pip install matplotlib
from matplotlib import pyplot as plt
import cv2 as cv
def plot_demo(image):
plt.hist(image.ravel(),256,[0,256])#hist(src,bin,[,])
plt.show("直方图")
def image_demo(image):
color=('blue','green','red')
for i,color in enumerate(color):
hist=cv.calcHist([image],[i],None,[256],[0,256])
plt.plot(hist,color=color)
plt.xlim([0,256])#x轴区间
plt.show()
src=cv.imread("D:/Study/opencv/code/1.jpg")
cv.imshow('src',src)
plot_demo(src)
image_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()