import cv2
import os
import numpy as np
path_dir = "/data_1/everyday/20221014/pic/18-19-20/"
list_img = os.listdir(path_dir)
cnt = 0
contrast = 0
brightness = 0
saturation = 0
for name in list_img:
path_img = path_dir + name
img = cv2.imread(path_img)
if img is None:
continue
cnt += 1
print(cnt, " ", path_img)
print(path_img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# means_gray = np.mean(gray)
means_gray1, var_gray = cv2.meanStdDev(gray)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
means_hsv = np.mean(hsv)
contrast += var_gray
brightness += means_gray1
saturation += means_hsv
# print("means_gray=", means_gray)
print("means_gray1=", means_gray1, "var_gray=",var_gray)
print("means_hsv=", means_hsv)
cv2.namedWindow("img", 0)
cv2.imshow("img",img)
cv2.namedWindow("gray", 0)
cv2.imshow("gray",gray)
cv2.namedWindow("hsv", 0)
cv2.imshow("hsv", hsv)
cv2.waitKey(1)
print("===end")
print("contrast = ", contrast * 1.0 / cnt)
print("brightness = ", brightness * 1.0 / cnt)
print("saturation = ", saturation * 1.0 / cnt)
标签:gray,img,means,cv2,亮度,print,hsv,图像,饱和度
From: https://www.cnblogs.com/yanghailin/p/16824099.html