1. 路径;
2. for 循环批量读取图片;
3. 生成直方图并且显示
import cv2 from matplotlib import pyplot as plt import os import numpy as np path = r'D:/cut_photo' # 图像保存路径 def image_hist_demo(path): for filename in os.listdir(path): img = cv2.imdecode(np.fromfile(path + "/" + filename,dtype=np.uint8),-1) for i in range(1,665): # 设置读取数量 plt.hist(img[i].ravel(), 256) plt.show() # 显示直方图 cv2.imshow("original_image", img) # 显示原图 cv2.waitKey() cv2.destroyAllWindows() print("run successful!") if __name__ == "__main__": image_hist_demo(path)
欢迎交流!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)