图片存在灰白、深黑区域的检测

import cv2 as cv

file_path = 'E:/Python/pythonProject_4/1.jpg'
def blackAndwhite_screen(file_path):
    img = cv.imread(file_path)
    rows=img.shape[0]
    cols=img.shape[1]

    n=0
    for r in range(0,rows):
        for c in range(0,cols):
            if img[r,c,0] == img[r,c,1] == img[r,c,2] <= 100:
                n+=1
            elif img[r,c,0] == img[r,c,1] == img[r,c,2] >= 200:
                n+=1

    if n>=rows*cols*0.3:
        #print(0)
        return False
    else:
        #print(1)
        return True

result = blackAndwhite_screen(file_path)
print(result)


版权声明:本文为weixin_40338379原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。