首页 > 代码库 > 碉堡了,python识别黄色图片

碉堡了,python识别黄色图片

创建testimg.py

import sys
from PIL import Image

img = Image.open(sys.argv[1]).convert(‘YCbCr‘)

w, h = img.size

data = http://www.mamicode.com/img.getdata()

cnt = 0

for i, ycbcr in enumerate(data):

y, cb, cr = ycbcr

if 86 <= cb <= 117 and 140 <= cr <= 168:

cnt += 1

print ‘%s %s a porn image.‘%(sys.argv[1], ‘is‘ if cnt > w * h * 0.3 else ‘is not‘)

需先安装PIL Library

 使用 :python testimg.py XXX.jpg