Skip to content

Instantly share code, notes, and snippets.

@qingfeng
Created October 28, 2008 09:38
Show Gist options
  • Save qingfeng/20336 to your computer and use it in GitHub Desktop.
Save qingfeng/20336 to your computer and use it in GitHub Desktop.
Image is a porn image?
#!/usr/local/bin/python
import sys, Image
if __name__ == '__main__':
fn = sys.argv[1]
img = Image.open(fn).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.'%(fn, 'is' if cnt > w * h * 0.3 else 'is not')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment