python opencv计算图片rgb平均值

python opencv计算图片rgb平均值

import cv2
import numpy as np

# 读取图像 3_20240328144817           2_20240328165448
image = cv2.imread('3_20240328144817.jpg')

# 确保图像读取成功
if image is not None:
    # OpenCV读取图像为BGR格式,我们需要转换为RGB
    #rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    
    # 计算RGB各通道的平均值
    avg_color = np.average(image, axis=(0, 1))
    avg_mean_rgb=np.mean(avg_color)
    if abs(avg_mean_rgb-97.31319444444445)>2.0:
        # 输出RGB各通道的平均值
        print(f'Average RGB color: {avg_color}  ,mean:{avg_mean_rgb}')
else:
    print("Failed to load image.")

 

 

#############

posted @ 2024-04-01 11:05  西北逍遥  阅读(197)  评论(0编辑  收藏  举报