創作內容

0 GP

Python opencv計算批量圖片的BGR各自的平均值

作者:Jarvis│2021-05-13 10:33:09│巴幣:0│人氣:114
import os
import cv2
import numpy as np
path = r'C:\Users\csim\Desktop\Selected_front'
def compute(path):
    file_names = os.listdir(path)
    per_image_Rmean = []
    per_image_Gmean = []
    per_image_Bmean = []
    for file_name in file_names:
        img = cv2.imread(os.path.join(path, file_name), 1)
        per_image_Bmean.append(np.mean(img[:,:,0]))
        per_image_Gmean.append(np.mean(img[:,:,1]))
        per_image_Rmean.append(np.mean(img[:,:,2]))
    R_mean = np.mean(per_image_Rmean)
    G_mean = np.mean(per_image_Gmean)
    B_mean = np.mean(per_image_Bmean)
    return R_mean, G_mean, B_mean
 
if __name__ == '__main__':
    R, G, B= compute(path)
    print(R, G ,B)
引用網址:https://home.gamer.com.tw/TrackBack.php?sn=5147400
All rights reserved. 版權所有,保留一切權利

相關創作

留言共 0 篇留言

我要留言提醒:您尚未登入,請先登入再留言

喜歡★mysecret20w 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:listdir 讀取資料... 後一篇:listdir Hu m...

追蹤私訊切換新版閱覽

作品資料夾

colanncolann
想找發明、小說、繪圖、漫畫、動畫、配音、音樂、模型的創作者們,一起交流、交友、交往! >.0看更多我要大聲說昨天22:29


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】