Detect Nudity in Images

It has been a while since I wrote any Python  script. Found this interesting Python library, which detects nudity in images. Some googling here and there just to refresh my memory on how to code in Python again.

First, install the library.
$ sudo apt-get install python-imaging
$ sudo pip install nudepy

Then, I wrote a tiny script to scan my Pictures folder for any nudity. The script is dog slow and can be optimized using multithreading. Next time, perhaps. On #1, you'll will to expand the expand the tilde manually.
import os, nude
from nude import Nude
from os import listdir
from os.path import expanduser

#1 expand tilde manually
path = expanduser("~/Pictures/")
files = listdir(path)
for file in files:
    n = Nude(path + file)
    # ordinal is optional since Python 2.7 [3]
    tpl = "image {} has {} nudity"
    print tpl.format(file, "no" if n.result == False else "")

Result time.  Detection is quite accurate even with baby photos. However, occasionally the library will throw exception for certain black and white photos.

Note to self : Code more in Python.

No comments:

Post a Comment