Nudity detection with Python

Overview

nude.py

Build status

About

Nudity detection with Python. Port of nude.js to Python.

Installation

from pip:

$ pip install --upgrade nudepy

from easy_install:

$ easy_install -ZU nudepy

Requirements

  • Python2.7+ and Python3.3+
  • Cython
  • Pillow

Usage

via command-line

$ nudepy IMAGE_FILE

via Python Module

import nude
from nude import Nude

print(nude.is_nude('./nude.rb/spec/images/damita.jpg'))

n = Nude('./nude.rb/spec/images/damita.jpg')
n.parse()
print("damita :", n.result, n.inspect())

see examples .

Links

Comments
  • Performance and command line update

    Performance and command line update

    I added automatic image resize so that it can run on really large images in a timely manner. I also fixed up the command line version so it uses argparse and has some prettier output.

    opened by Drewsif 8
  • Fixes handling BytesIO correctly

    Fixes handling BytesIO correctly

    Passing a BytesIO object would be considered an instance of IOBase and therefore would not open it as an image.

    Now, it will use Image.open on both strings and IOBase objects, but will accept PIL.Image objects as well in the else clause.

    opened by bobloy 2
  • speedup

    speedup

    make image a thumbnail first for speed, speedup increases with image resolution (since we're converting to approximately constant time); 10x speedup on the small test images, 30x+ on larger images

    opened by randm-prgrmr 2
  • Installation error

    Installation error

    Hi, I am trying to install the package via python3 -m pip install --upgrade nudepy howevrer I am running into the following error:

    Defaulting to user installation because normal site-packages is not writeable
    Requirement already satisfied: pip in /home/lskywalker416/.local/lib/python3.7/site-packages (21.2.4)
    Collecting install
      Using cached install-1.3.4-py3-none-any.whl (3.1 kB)
    Collecting nudepy
      Using cached nudepy-0.5.1.tar.gz (35 kB)
    Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (from nudepy) (5.4.1)
    Building wheels for collected packages: nudepy
      Building wheel for nudepy (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-7_jmbwcy
           cwd: /tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/
      Complete output (9 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.7
      copying nude.py -> build/lib.linux-x86_64-3.7
      running build_ext
      cythoning skin_classifier.pyx to skin_classifier.c
      error: /tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/skin_classifier.pyx
      ----------------------------------------
      ERROR: Failed building wheel for nudepy
      Running setup.py clean for nudepy
    Failed to build nudepy
    Installing collected packages: nudepy, install
        Running setup.py install for nudepy ... error
        ERROR: Command errored out with exit status 1:
         command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hb578l86/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/lskywalker416/.local/include/python3.7m/nudepy
             cwd: /tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/
        Complete output (9 lines):
        running install
        running build
        running build_py
        creating build
        creating build/lib.linux-x86_64-3.7
        copying nude.py -> build/lib.linux-x86_64-3.7
        running build_ext
        cythoning skin_classifier.pyx to skin_classifier.c
        error: /tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/skin_classifier.pyx
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-efz9gp75/nudepy_370d0f97a460431abc3646fde64bad7d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hb578l86/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/lskywalker416/.local/include/python3.7m/nudepy Check the logs for full command output.
    
    

    Host: Google Cloud VM Release: Debian GNU/Linux 10 (buster) Python version: Python 3.7.3 Pip version: pip 21.2.4

    opened by TheBozzz34 1
  • add nice output instead inspect

    add nice output instead inspect

    Hi! I added structured output for results instead just call inspect(). However, It takes additional requirement colorama for colored output. It looks like

    n = Nude('./nude.rb/spec/images/damita.jpg')
    n.parse()
    n.show()
    
    opened by saromanov 1
  • can be run as a script

    can be run as a script

    With this extension nude.py can be run as a script too:

    $ ./nude.py 
    Usage: ./nude.py <image>
    
    $ ./nude.py examples/images/damita.jpg
    False
    examples/images/damita.jpg: False #<__main__.Nude:0x2583550...
    
    opened by jabbalaci 1
  • Slow performance overall

    Slow performance overall

    Performance is kind of random. A 1.9 MiB image of my cat takes about 2 minutes to process (which is really unusable in the context of a web server handling POST data). I profiled this run:

       783201   44.737    0.000   44.739    0.000 .../site-packages/nude.py:147(_add_merge)
         4906   19.164    0.004   19.164    0.004 /usr/lib64/python2.7/copy.py:113(_copy_with_constructor)
            1   18.591   18.591  105.226  105.226 .../site-packages/nude.py:80(parse)
            1   17.738   17.738   36.937   36.937 .../site-packages/nude.py:181(_merge)
     12192768    2.073    0.000    2.073    0.000 {skin_classifier.skin_classifier}
     12192768    1.819    0.000    3.892    0.000 .../site-packages/nude.py:279(_classify_skin)
    

    This is sorted by total time.

    • _add_merge is called a lot, and also takes a lot of time overall, not in itself
    • Calls to copy are expensive, somewhat expected; would have to figure out a way to avoid copy calls
    • _classify_skin should be converted to C if possible?
    opened by Tatsh 0
  • I'm a getting a installation error.

    I'm a getting a installation error.

    $ pip install --upgrade nudepy

    ERROR: Command errored out with exit status 1:
      command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lbjhc6pt/nudepy_3b195ab8384e42f987f0811934cf8ca8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lbjhc6pt/nudepy_3b195ab8384e42f987f0811934cf8ca8/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-psp1didq                                        
          cwd: /tmp/pip-install-lbjhc6pt/nudepy_3b195ab8384e42f987f0811934cf8ca8/         
     Complete output (9 lines):                                                           
     running bdist_wheel                                                                  
     running build                                                                        
     running build_py                                                                     
     creating build                                                                       
     creating build/lib.linux-x86_64-3.9                                                  
     copying nude.py -> build/lib.linux-x86_64-3.9                                        
     running build_ext                                                                    
     cythoning skin_classifier.pyx to skin_classifier.c                                   
     error: /tmp/pip-install-lbjhc6pt/nudepy_3b195ab8384e42f987f0811934cf8ca8/skin_classifier.pyx                                                                                
     ----------------------------------------                                             
     ERROR: Failed building wheel for nudepy
    
    
    opened by JibinKoshy07 5
  • False Negative

    False Negative

    I was testing this script for some of my system use. When testing this code it gave me FALSE NEGATIVE on a full nude image. I can email you that image if you want to test, though I ca't upload it here because that is complete nude. Need help please have a look. Thanks for your time.

    opened by Ankur-Jat 3
  • Optimize skin classifier

    Optimize skin classifier

    I'm looking at the _classify_skin method. (https://github.com/hhatto/nude.py/blob/master/nude.py#L283) I think there is a big waste of processing here since it returns rgb_classifier or norm_rgb_classifier or hsv_classifier or ycbcr_classifier. It seams useless to calculate the next classifier if the previous is True.

    opened by felipelerena 0
  • help me

    help me

    Traceback (most recent call last): File "/usr/local/bin/nudepy", line 9, in load_entry_point('nudepy==0.2', 'console_scripts', 'nudepy')() File "/usr/local/lib/python2.7/dist-packages/nudepy-0.2-py2.7.egg/nude.py", line 438, in main callback(_testfile(fname, resize=args.resize)) File "/usr/local/lib/python2.7/dist-packages/nudepy-0.2-py2.7.egg/nude.py", line 373, in _testfile n.parse() File "/usr/local/lib/python2.7/dist-packages/nudepy-0.2-py2.7.egg/nude.py", line 89, in parse pixels = self.image.load() File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 203, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 420, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder zip not available

    opened by levinhne 1
  • False positive for a test example

    False positive for a test example

    I cloned the project and ran the tests immediately and got "True" for damita2.jpg from the examples. I will investigate to see what causes this.

    opened by zeynepsu 2
  • Support for BytesIO (or StringIO) image ?

    Support for BytesIO (or StringIO) image ?

    I currently want to integrate nudepy with one of my IRC Bot. (Some friends of me sends NSFW pics and people should be warned that it's NSFW) The fact is that I don't want to write the image on disk before analyzing it. Using requests, I can store the whole image in a BytesIO (or StringIO for python 2) in RAM instead of on disk. Is there a workaround to work with in RAM files ?

    opened by Depado 1
Owner
Hideo Hattori
Hideo Hattori
SALaD (Semi-Automatic Landslide Detection) is a landslide mapping system

SALaD (Semi-Automatic Landslide Detection) is a landslide mapping system. SALaD utilizes Object-based Image Analysis and Random Forest to map landslides.

NASA 14 Jan 4, 2023
An ascii art generator that's actually good. Does edge detection and selects the most appropriate characters.

Ascii Artist An ascii art generator that's actually good. Does edge detection and selects the most appropriate characters. Installing Installing with

null 18 Jan 3, 2023
㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.

python-barcode python-barcode provides a simple way to create barcodes in Python. There are no external dependencies when generating SVG files. Pillow

Hugo Barrera 419 Dec 26, 2022
Generative Art Synthesizer - a python program that generates python programs that generates generative art

GAS - Generative Art Synthesizer Generative Art Synthesizer - a python program that generates python programs that generates generative art. Examples

Alexey Borsky 43 Dec 3, 2022
Python avatar generator for absolute nerds

pagan Welcome to the Python Avatar Generator for Absolute Nerds. Current version: 0.4.3 View the change history here. Remember those good old days whe

David Bothe 280 Dec 16, 2022
The friendly PIL fork (Python Imaging Library)

Pillow Python Imaging Library (Fork) Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lund

Pillow 10.4k Dec 31, 2022
Python QR Code image generator

Pure python QR Code generator Generate QR codes. For a standard install (which will include pillow for generating images), run: pip install qrcode[pil

Lincoln Loop 3.5k Dec 31, 2022
python binding for libvips using cffi

README PyPI package: https://pypi.python.org/pypi/pyvips conda package: https://anaconda.org/conda-forge/pyvips We have formatted docs online here: ht

libvips 467 Dec 30, 2022
The ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

Eric McConville 1.2k Dec 30, 2022
Bringing vtk.js into Dash and Python

Dash VTK Dash VTK lets you integrate the vtk.js visualization pipeline directly into your Dash app. It is powered by react-vtk-js. Docs Demo Explorer

Plotly 88 Nov 29, 2022
python app to turn a photograph into a cartoon

Draw This. Draw This is a polaroid camera that draws cartoons. You point, and shoot - and out pops a cartoon; the camera's best interpretation of what

Dan Macnish 2k Dec 19, 2022
DrawBot is a powerful, free application for macOS that invites you to write Python scripts to generate two-dimensional graphics

DrawBot is a powerful, free application for macOS that invites you to write Python scripts to generate two-dimensional graphics.

Frederik Berlaen 344 Jan 6, 2023
Python-based tools for document analysis and OCR

ocropy OCRopus is a collection of document analysis programs, not a turn-key OCR system. In order to apply it to your documents, you may need to do so

OCRopus 3.2k Jan 4, 2023
ModernGL is a python wrapper over OpenGL 3.3+ core

ModernGL is a python wrapper over OpenGL 3.3+ core that simplifies the creation of simple graphics applications like scientific simulations, games or user interface

ModernGL 1.4k Jan 1, 2023
Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures.

WADs Out For [The] Ladies Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures. Development mostly focused on L

null 5 Apr 9, 2022
vsketch is a Python generative art toolkit for plotters

Generative plotter art environment for Python

Antoine Beyeler 380 Dec 29, 2022
📷 Python package and CLI utility to create photo mosaics.

?? Python package and CLI utility to create photo mosaics.

Loic Coyle 7 Oct 29, 2022
Pure Python bindings for the pure C++11/OpenCL Qrack quantum computer simulator library

pyqrack Pure Python bindings for the pure C++11/OpenCL Qrack quantum computer simulator library (PyQrack is just pure Qrack.) IMPORTANT: You must buil

vm6502q 6 Jul 21, 2022
Gallery written in Python to manage your photos

GalleryMan Gallery written in Python to manage your photos Installation

Asian Cat 24 Dec 18, 2022