一段用来判断图片是否是色情图片的python代码,安装了pil包既可以使用
转自:http://blog.csdn.net/lanphaday
import sys, Image pic = '2.jpg' img = Image.open(pic).convert('YCbCr') w, h = img.size data = 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.'%(pic, 'is' if cnt > w * h * 0.3 else 'is not')