代码如下
import os
from PIL import Image
import numpy as np
# 获取当前目录
current_dir = os.getcwd()
# 构建"results"子目录的路径
results_dir = 'path'
# 遍历"results"子目录中的所有文件
for root, dirs, files in os.walk(results_dir):
for file in files:
# 判断文件是否为图片文件
if file.endswith(".jpg") or file.endswith(".png"):
# 构建图片的完整路径
image_path = os.path.join(root, file)
# 打开图片
image = Image.open(image_path)
img = np.array(image)
max_index = np.unravel_index(np.argmax(img, axis=None), img.shape)
max_value = img[max_index]
#判断是否为纯黑图
if max_value == 0:
print("这是纯黑图")
else:
print("这不是纯黑图")