Commit 0e07cc36 authored by guillaume-heusch's avatar guillaume-heusch
Browse files

[doc] worked on the doc: doctests, API, ...

parent ddd301b5
......@@ -30,7 +30,7 @@ def show_image(image, title=''):
def main(user_input=None):
image = bob.io.base.load('./bob/ip/skincolorfilter/data/001.png')
image = bob.io.base.load('./bob/ip/skincolorfilter/data/001.bmp')
show_image(image, 'original image')
detection = bob.ip.facedetect.detect_single_face(image)
......
......@@ -5,31 +5,14 @@
parts = scripts
eggs = bob.ip.skincolorfilter
extensions = bob.buildout
mr.developer
auto-checkout = *
develop = .
src/bob.extension
src/bob.blitz
src/bob.core
src/bob.io.base
src/bob.io.image
src/bob.ip.base
src/bob.ip.facedetect
; options for bob.buildout
debug = true
verbose = true
newest = false
[sources]
bob.extension = git https://github.com/bioidiap/bob.extension
bob.blitz = git https://github.com/bioidiap/bob.blitz
bob.core = git https://github.com/bioidiap/bob.core
bob.io.base = git https://github.com/bioidiap/bob.io.base
bob.io.image = git https://github.com/bioidiap/bob.io.image
bob.ip.base = git https://github.com/bioidiap/bob.ip.base
bob.ip.facedetect = git https://github.com/bioidiap/bob.ip.facedetect
[scripts]
recipe = bob.buildout:scripts
dependent-scripts = true
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Mon 13 Aug 2012 12:38:15 CEST
# Guillaume Heusch <guillaume.heusch@idiap.ch>
# Mon Apr 4 14:24:42 CET 2016
#
# Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
# Copyright (C) 2011-2016 Idiap Research Institute, Martigny, Switzerland
import os
import sys
import glob
import pkg_resources
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
......@@ -25,12 +26,13 @@ import pkg_resources
extensions = [
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.pngmath',
'sphinx.ext.imgmath',
'sphinx.ext.ifconfig',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'matplotlib.sphinxext.plot_directive',
]
# The viewcode extension appeared only on Sphinx >= 1.0.0
......@@ -58,12 +60,12 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'Bob Example Project'
project = u'Skin color filter using Bob'
import time
copyright = u'%s, Idiap Research Institute' % time.strftime('%Y')
# Grab the setup entry
distribution = pkg_resources.require('bob.example.project')[0]
distribution = pkg_resources.require('bob.ip.skincolorfilter')[0]
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
......@@ -86,7 +88,7 @@ release = distribution.version
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
#exclude_patterns = ['**/links.rst']
exclude_patterns = ['links.rst']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
......@@ -108,13 +110,15 @@ pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# Included after all input documents
rst_epilog = ''
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
if sphinx.__version__ >= "1.0":
html_theme = 'nature'
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
......@@ -129,21 +133,21 @@ if sphinx.__version__ >= "1.0":
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = 'bob'
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = ''
html_logo = 'img/logo.png'
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = ''
html_favicon = 'img/favicon.ico'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['_static']
# html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
......@@ -187,7 +191,7 @@ html_favicon = ''
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'bob_example_project_doc'
htmlhelp_basename = 'bob_ip_skincolorfilter_doc'
# -- Options for LaTeX output --------------------------------------------------
......@@ -201,13 +205,13 @@ latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'bob_example_project.tex', u'Bob',
('index', 'bob_ip_skincolorfilter.tex', u'Documentation for the skin color filter',
u'Biometrics Group, Idiap Research Institute', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
latex_logo = ''
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
......@@ -219,24 +223,19 @@ latex_logo = ''
# If true, show URL addresses after external links.
#latex_show_urls = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# Included after all input documents
rst_epilog = ''
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'bob.example.project', u'Bob Example Project Documentation', [u'Idiap Research Institute'], 1)
('index', 'bob.ip.skincolorfilter', u'Documentation for the skin color filter', [u'Idiap Research Institute'], 1)
]
# Default processing flags for sphinx
......@@ -246,7 +245,7 @@ autodoc_default_flags = ['members', 'undoc-members', 'inherited-members', 'show-
# For inter-documentation mapping:
from bob.extension.utils import link_documentation
intersphinx_mapping = link_documentation()
intersphinx_mapping = link_documentation(['python', 'numpy', 'scipy', 'matplotlib', 'bob.db.verification.utils'])
def setup(app):
......
.. py:currentmodule:: bob.ip.skincolorfilter
.. testsetup:: *
from __future__ import print_function
import bob.io.base
import bob.io.base.test_utils
import bob.io.image
import bob.ip.facedetect
from bob.ip.skincolorfilter.skin_color_filter import SkinColorFilter
import pkg_resources
face_image = bob.io.base.load(bob.io.base.test_utils.datafile('001.png', 'bob.ip.skincolorfilter'))
=============
Users Guide
=============
This skin color filter relies on the result of face detection. The skin color values
are estimated from the center of the detected face area. The probability of a pixel
to be of skin color is modeled as a bivariate gaussian in the normalized rg colorspace
Skin pixels detection in a single image
---------------------------------------
The function to detect skin pixels will return a mask (logical numpy array of the
same size of the image) where location corresponding to skin color pixels is True.
Hence, to detect skin pixels inside a face image, you should do the following:
.. doctest::
>>> face_image = bob.io.base.load('001.png') # doctest: +SKIP
>>> detection = bob.ip.facedetect.detect_single_face(face_image)
>>> bounding_box, quality = bob.ip.facedetect.detect_single_face(face_image)
>>> face = face_image[:, bounding_box.top:bounding_box.bottom, bounding_box.left:bounding_box.right]
>>> skin_filter = SkinColorFilter()
>>> skin_filter.get_gaussian_parameters(face)
>>> skin_mask = skin_filter.get_skin_pixels(face_image, 0.5)
.. plot:: plot/detect_skin_pixels.py
:include-source: False
Skin pixels detection in videos
-------------------------------
To detect skin pixels in video, you don't need to re-init the gaussian parameters at each frame.
However, you can do it if you really want to by calling the appropriate function (i.e. get_gaussian_parameters).
.. vim: set fileencoding=utf-8 :
.. Guillaume HEUSCH <guillaume.heusch@idiap.ch>
.. Wed 30 Mar 15:46:29 CEST 2016
..
.. Copyright (C) 2015 Idiap Research Institute, Martigny, Switzerland
.. Bob skin color filter documentation master file, created by
sphinx-quickstart on Mon Apr 4 14:15:40 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. _bob.ip.skincolorfilter:
......@@ -36,6 +36,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. include:: links.rst
import sys
import numpy
import bob.io.base
import bob.io.base.test_utils
import bob.io.image
import bob.ip.facedetect
from bob.ip.skincolorfilter.skin_color_filter import SkinColorFilter
face_image = bob.io.base.load(bob.io.base.test_utils.datafile('001.png', 'bob.ip.skincolorfilter'))
detection = bob.ip.facedetect.detect_single_face(face_image)
bounding_box, quality = bob.ip.facedetect.detect_single_face(face_image)
face = face_image[:, bounding_box.top:bounding_box.bottom, bounding_box.left:bounding_box.right]
skin_filter = SkinColorFilter()
skin_filter.get_gaussian_parameters(face)
skin_mask = skin_filter.get_skin_pixels(face_image, 0.5)
skin_image = numpy.copy(face_image)
skin_image[:, numpy.logical_not(skin_mask)] = 0
from matplotlib import pyplot
ax = pyplot.subplot(2, 1, 1)
ax[0].imshow(numpy.rollaxis(numpy.rollaxis(face_image, 2),2))
ax[0].title('Original Image')
ax[1].imshow(numpy.rollaxis(numpy.rollaxis(skin_image, 2),2))
ax[1].title('Detected skin pixels')
============
Python API
============
.. automodule:: bob.ip.skincolorfilter.skin_color_filter
:members:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment