python 灰度图取值范围_python判断灰度图

import time

import cv2

import numpy as np

import os

def checkGray(chip):

# chip_gray = cv2.cvtColor(chip,cv2.COLOR_BGR2GRAY)

r,g,b = cv2.split(chip)

r = r.astype(np.float32)

g = g.astype(np.float32)

b = b.astype(np.float32)

s_w, s_h = r.shape[:2] x = (r+b+g)/3

area_s=s_w * s_h

# x = chip_gray

r_gray = abs(r-x)

g_gray = abs(g-x)

b_gray= abs(b-x)

r_sum = np.sum(r_gray)/area_s

g_sum = np.sum(g_gray)/area_s

b_sum = np.sum(b_gray)/area_s

gray_degree = (r_sum+g_sum+b_sum)/3

if gray_degree 10:

pass

return False,s_sum

# print('color',s_sum)

else:

print('gray',s_sum)

return True,s_sum

if __name__ == '__main__':

path=r'faces_emore_images\001344/'

start=time.time()

files =os.listdir(path)

for file in files:

if file.endswith(".jpg"):

img=cv2.imread(path+file)

ret,value= checkGray(img)

if ret:

print(f'{value:.3f},'+path + file)

print('time',time.time()-start)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值