Commit 4fa1c641 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

added stub docs for the new Python bindings; updated PDF's

parent e5f7a0c6
...@@ -223,8 +223,10 @@ pngmath_latex_preamble = r""" ...@@ -223,8 +223,10 @@ pngmath_latex_preamble = r"""
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]). # (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [ latex_documents = [
('modules/refman', 'opencv2refman.tex', u'The OpenCV Reference Manual', ('modules/refman', 'opencv2refman_cpp.tex', u'The OpenCV 2.x C++ Reference Manual',
u'', 'manual'), u'', 'manual'),
('doc/opencv2/py/py_index', 'opencv2refman_py.tex', u'The OpenCV 2.x Python Reference Manual',
u'', 'manual'),
('doc/opencv1/c/c_index', 'opencv1refman_c.tex', u'The OpenCV 1.x C Reference Manual', ('doc/opencv1/c/c_index', 'opencv1refman_c.tex', u'The OpenCV 1.x C Reference Manual',
u'', 'manual'), u'', 'manual'),
('doc/opencv1/py/py_index', 'opencv1refman_py.tex', u'The OpenCV 1.x Python Reference Manual', ('doc/opencv1/py/py_index', 'opencv1refman_py.tex', u'The OpenCV 1.x Python Reference Manual',
......
This diff is collapsed.
project(opencv_refman)
file(GLOB_RECURSE OPENCV2_FILES_PICT ../../modules/*.png ../../modules/*.jpg)
file(GLOB_RECURSE OPENCV2_FILES_RST ../../modules/*.rst)
add_custom_target(refman
${SPHINX_BUILD}
-b latex -c ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../modules .
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/../mymath.sty ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${PDFLATEX_COMPILER} opencv
COMMAND ${PDFLATEX_COMPILER} opencv
DEPENDS conf.py ${OPENCV2_FILES_RST} ${OPENCV2_FILES_PICT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating the OpenCV Reference Manual")
#install(FILES ${CURRENT_BINARY_DIR}/opencv.pdf DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT main)
*******************************************************
calib3d. Camera Calibration, Pose Estimation and Stereo
*******************************************************
.. toctree::
:maxdepth: 2
calib3d_camera_calibration_and_3d_reconstruction
Cookbook
========
.. highlight:: python
Here is a collection of code fragments demonstrating some features
of the OpenCV Python bindings.
Convert an image
----------------
.. doctest::
>>> import cv
>>> im = cv.LoadImageM("building.jpg")
>>> print type(im)
<type 'cv.cvmat'>
>>> cv.SaveImage("foo.png", im)
..
Resize an image
---------------
To resize an image in OpenCV, create a destination image of the appropriate size, then call
:ref:`Resize`
.
.. doctest::
>>> import cv
>>> original = cv.LoadImageM("building.jpg")
>>> thumbnail = cv.CreateMat(original.rows / 10, original.cols / 10, cv.CV_8UC3)
>>> cv.Resize(original, thumbnail)
..
Compute the Laplacian
---------------------
.. doctest::
>>> import cv
>>> im = cv.LoadImageM("building.jpg", 1)
>>> dst = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_16S, 3)
>>> laplace = cv.Laplace(im, dst)
>>> cv.SaveImage("foo-laplace.png", dst)
..
Using GoodFeaturesToTrack
-------------------------
To find the 10 strongest corner features in an image, use
:ref:`GoodFeaturesToTrack`
like this:
.. doctest::
>>> import cv
>>> img = cv.LoadImageM("building.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
>>> eig_image = cv.CreateMat(img.rows, img.cols, cv.CV_32FC1)
>>> temp_image = cv.CreateMat(img.rows, img.cols, cv.CV_32FC1)
>>> for (x,y) in cv.GoodFeaturesToTrack(img, eig_image, temp_image, 10, 0.04, 1.0, useHarris = True):
... print "good feature at", x,y
good feature at 198.0 514.0
good feature at 791.0 260.0
good feature at 370.0 467.0
good feature at 374.0 469.0
good feature at 490.0 520.0
good feature at 262.0 278.0
good feature at 781.0 134.0
good feature at 3.0 247.0
good feature at 667.0 321.0
good feature at 764.0 304.0
..
Using GetSubRect
----------------
GetSubRect returns a rectangular part of another image. It does this without copying any data.
.. doctest::
>>> import cv
>>> img = cv.LoadImageM("building.jpg")
>>> sub = cv.GetSubRect(img, (60, 70, 32, 32)) # sub is 32x32 patch within img
>>> cv.SetZero(sub) # clear sub to zero, which also clears 32x32 pixels in img
..
Using CreateMat, and accessing an element
-----------------------------------------
.. doctest::
>>> import cv
>>> mat = cv.CreateMat(5, 5, cv.CV_32FC1)
>>> cv.Set(mat, 1.0)
>>> mat[3,1] += 0.375
>>> print mat[3,1]
1.375
>>> print [mat[3,i] for i in range(5)]
[1.0, 1.375, 1.0, 1.0, 1.0]
..
ROS image message to OpenCV
---------------------------
See this tutorial:
`Using CvBridge to convert between ROS images And OpenCV images <http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages>`_
.
PIL Image to OpenCV
-------------------
(For details on PIL see the
`PIL handbook <http://www.pythonware.com/library/pil/handbook/image.htm>`_
.)
.. doctest::
>>> import Image, cv
>>> pi = Image.open('building.jpg') # PIL image
>>> cv_im = cv.CreateImageHeader(pi.size, cv.IPL_DEPTH_8U, 3)
>>> cv.SetData(cv_im, pi.tostring())
>>> print pi.size, cv.GetSize(cv_im)
(868, 600) (868, 600)
>>> print pi.tostring() == cv_im.tostring()
True
..
OpenCV to PIL Image
-------------------
.. doctest::
>>> import Image, cv
>>> cv_im = cv.CreateImage((320,200), cv.IPL_DEPTH_8U, 1)
>>> pi = Image.fromstring("L", cv.GetSize(cv_im), cv_im.tostring())
>>> print pi.size
(320, 200)
..
NumPy and OpenCV
----------------
Using the
`array interface <http://docs.scipy.org/doc/numpy/reference/arrays.interface.html>`_
, to use an OpenCV CvMat in NumPy:
.. doctest::
>>> import cv, numpy
>>> mat = cv.CreateMat(3, 5, cv.CV_32FC1)
>>> cv.Set(mat, 7)
>>> a = numpy.asarray(mat)
>>> print a
[[ 7. 7. 7. 7. 7.]
[ 7. 7. 7. 7. 7.]
[ 7. 7. 7. 7. 7.]]
..
and to use a NumPy array in OpenCV:
.. doctest::
>>> import cv, numpy
>>> a = numpy.ones((480, 640))
>>> mat = cv.fromarray(a)
>>> print mat.rows
480
>>> print mat.cols
640
..
also, most OpenCV functions can work on NumPy arrays directly, for example:
.. doctest::
>>> picture = numpy.ones((640, 480))
>>> cv.Smooth(picture, picture, cv.CV_GAUSSIAN, 15, 15)
..
Given a 2D array,
the
:ref:`fromarray`
function (or the implicit version shown above)
returns a single-channel
:ref:`CvMat`
of the same size.
For a 3D array of size
:math:`j \times k \times l`
, it returns a
:ref:`CvMat`
sized
:math:`j \times k`
with
:math:`l`
channels.
Alternatively, use
:ref:`fromarray`
with the
``allowND``
option to always return a
:ref:`cvMatND`
.
OpenCV to pygame
----------------
To convert an OpenCV image to a
`pygame <http://www.pygame.org/>`_
surface:
.. doctest::
>>> import pygame.image, cv
>>> src = cv.LoadImage("lena.jpg")
>>> src_rgb = cv.CreateMat(src.height, src.width, cv.CV_8UC3)
>>> cv.CvtColor(src, src_rgb, cv.CV_BGR2RGB)
>>> pg_img = pygame.image.frombuffer(src_rgb.tostring(), cv.GetSize(src_rgb), "RGB")
>>> print pg_img
<Surface(512x512x24 SW)>
..
OpenCV and OpenEXR
------------------
Using
`OpenEXR's Python bindings <http://www.excamera.com/sphinx/articles-openexr.html>`_
you can make a simple
image viewer:
::
import OpenEXR, Imath, cv
filename = "GoldenGate.exr"
exrimage = OpenEXR.InputFile(filename)
dw = exrimage.header()['dataWindow']
(width, height) = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
def fromstr(s):
mat = cv.CreateMat(height, width, cv.CV_32FC1)
cv.SetData(mat, s)
return mat
pt = Imath.PixelType(Imath.PixelType.FLOAT)
(r, g, b) = [fromstr(s) for s in exrimage.channels("RGB", pt)]
bgr = cv.CreateMat(height, width, cv.CV_32FC3)
cv.Merge(b, g, r, None, bgr)
cv.ShowImage(filename, bgr)
cv.WaitKey()
..
****************************
core. The Core Functionality
****************************
.. toctree::
:maxdepth: 2
core_basic_structures
core_operations_on_arrays
core_dynamic_structures
core_drawing_functions
core_xml_yaml_persistence
core_clustering
core_utility_and_system_functions_and_macros
Basic Structures
================
.. highlight:: python
.. index:: CvPoint
.. _CvPoint:
CvPoint
-------
.. class:: CvPoint
2D point with integer coordinates (usually zero-based).
2D point, represented as a tuple
``(x, y)``
, where x and y are integers.
.. index:: CvPoint2D32f
.. _CvPoint2D32f:
CvPoint2D32f
------------
.. class:: CvPoint2D32f
2D point with floating-point coordinates
2D point, represented as a tuple
``(x, y)``
, where x and y are floats.
.. index:: CvPoint3D32f
.. _CvPoint3D32f:
CvPoint3D32f
------------
.. class:: CvPoint3D32f
3D point with floating-point coordinates
3D point, represented as a tuple
``(x, y, z)``
, where x, y and z are floats.
.. index:: CvPoint2D64f
.. _CvPoint2D64f:
CvPoint2D64f
------------
.. class:: CvPoint2D64f
2D point with double precision floating-point coordinates
2D point, represented as a tuple
``(x, y)``
, where x and y are floats.
.. index:: CvPoint3D64f
.. _CvPoint3D64f:
CvPoint3D64f
------------
.. class:: CvPoint3D64f
3D point with double precision floating-point coordinates
3D point, represented as a tuple
``(x, y, z)``
, where x, y and z are floats.
.. index:: CvSize
.. _CvSize:
CvSize
------
.. class:: CvSize
Pixel-accurate size of a rectangle.
Size of a rectangle, represented as a tuple
``(width, height)``
, where width and height are integers.
.. index:: CvSize2D32f
.. _CvSize2D32f:
CvSize2D32f
-----------
.. class:: CvSize2D32f
Sub-pixel accurate size of a rectangle.
Size of a rectangle, represented as a tuple
``(width, height)``
, where width and height are floats.
.. index:: CvRect
.. _CvRect:
CvRect
------
.. class:: CvRect
Offset (usually the top-left corner) and size of a rectangle.
Rectangle, represented as a tuple
``(x, y, width, height)``
, where all are integers.
.. index:: CvScalar
.. _CvScalar:
CvScalar
--------
.. class:: CvScalar
A container for 1-,2-,3- or 4-tuples of doubles.
CvScalar is always represented as a 4-tuple.
.. doctest::
>>> import cv
>>> cv.Scalar(1, 2, 3, 4)
(1.0, 2.0, 3.0, 4.0)
>>> cv.ScalarAll(7)
(7.0, 7.0, 7.0, 7.0)
>>> cv.RealScalar(7)
(7.0, 0.0, 0.0, 0.0)
>>> cv.RGB(17, 110, 255)
(255.0, 110.0, 17.0, 0.0)
..
.. index:: CvTermCriteria
.. _CvTermCriteria:
CvTermCriteria
--------------
.. class:: CvTermCriteria
Termination criteria for iterative algorithms.
Represented by a tuple
``(type, max_iter, epsilon)``
.
.. attribute:: type
``CV_TERMCRIT_ITER`` , ``CV_TERMCRIT_EPS`` or ``CV_TERMCRIT_ITER | CV_TERMCRIT_EPS``
.. attribute:: max_iter
Maximum number of iterations
.. attribute:: epsilon
Required accuracy
::
(cv.CV_TERMCRIT_ITER, 10, 0) # terminate after 10 iterations
(cv.CV_TERMCRIT_EPS, 0, 0.01) # terminate when epsilon reaches 0.01
(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 10, 0.01) # terminate as soon as either condition is met
..
.. index:: CvMat
.. _CvMat:
CvMat
-----
.. class:: CvMat
A multi-channel 2D matrix. Created by
:ref:`CreateMat`
,
:ref:`LoadImageM`
,
:ref:`CreateMatHeader`
,
:ref:`fromarray`
.
.. attribute:: type
A CvMat signature containing the type of elements and flags, int
.. attribute:: step
Full row length in bytes, int
.. attribute:: rows
Number of rows, int
.. attribute:: cols
Number of columns, int
.. method:: tostring() -> str
Returns the contents of the CvMat as a single string.
.. index:: CvMatND
.. _CvMatND:
CvMatND
-------
.. class:: CvMatND
Multi-dimensional dense multi-channel array.
.. attribute:: type
A CvMatND signature combining the type of elements and flags, int
.. method:: tostring() -> str
Returns the contents of the CvMatND as a single string.
.. index:: IplImage
.. _IplImage:
IplImage
--------
.. class:: IplImage
The
:ref:`IplImage`
object was inherited from the Intel Image Processing
Library, in which the format is native. OpenCV only supports a subset
of possible
:ref:`IplImage`
formats.
.. attribute:: nChannels
Number of channels, int.
.. attribute:: width
Image width in pixels
.. attribute:: height
Image height in pixels
.. attribute:: depth
Pixel depth in bits. The supported depths are:
.. attribute:: IPL_DEPTH_8U
Unsigned 8-bit integer
.. attribute:: IPL_DEPTH_8S
Signed 8-bit integer
.. attribute:: IPL_DEPTH_16U
Unsigned 16-bit integer
.. attribute:: IPL_DEPTH_16S
Signed 16-bit integer
.. attribute:: IPL_DEPTH_32S
Signed 32-bit integer
.. attribute:: IPL_DEPTH_32F
Single-precision floating point
.. attribute:: IPL_DEPTH_64F
Double-precision floating point
.. attribute:: origin
0 - top-left origin, 1 - bottom-left origin (Windows bitmap style)
.. method:: tostring() -> str
Returns the contents of the CvMatND as a single string.
.. index:: CvArr
.. _CvArr:
CvArr
-----
.. class:: CvArr
Arbitrary array
``CvArr``
is used
*only*
as a function parameter to specify that the parameter can be:
* an :ref:`IplImage`
* a :ref:`CvMat`
* any other type that exports the `array interface <http://docs.scipy.org/doc/numpy/reference/arrays.interface.html>`_
Clustering
==========
.. highlight:: python
.. index:: KMeans2
.. _KMeans2:
KMeans2
-------
.. function:: KMeans2(samples,nclusters,labels,termcrit)-> None
Splits set of vectors by a given number of clusters.
:param samples: Floating-point matrix of input samples, one row per sample
:type samples: :class:`CvArr`
:param nclusters: Number of clusters to split the set by
:type nclusters: int
:param labels: Output integer vector storing cluster indices for every sample
:type labels: :class:`CvArr`
:param termcrit: Specifies maximum number of iterations and/or accuracy (distance the centers can move by between subsequent iterations)
:type termcrit: :class:`CvTermCriteria`
The function
``cvKMeans2``
implements a k-means algorithm that finds the
centers of
``nclusters``
clusters and groups the input samples
around the clusters. On output,
:math:`\texttt{labels}_i`
contains a cluster index for
samples stored in the i-th row of the
``samples``
matrix.
This diff is collapsed.
Dynamic Structures
==================
.. highlight:: python
.. index:: CvMemStorage
.. _CvMemStorage:
CvMemStorage
------------
.. class:: CvMemStorage
Growing memory storage.
Many OpenCV functions use a given storage area for their results
and working storage. These storage areas can be created using
:ref:`CreateMemStorage`
. OpenCV Python tracks the objects occupying a
CvMemStorage, and automatically releases the CvMemStorage when there are
no objects referring to it. For this reason, there is explicit function
to release a CvMemStorage.
.. doctest::
>>> import cv
>>> image = cv.LoadImageM("building.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
>>> seq = cv.FindContours(image, cv.CreateMemStorage(), cv.CV_RETR_TREE, cv.CV_CHAIN_APPROX_SIMPLE)
>>> del seq # associated storage is also released
..
.. index:: CvSeq
.. _CvSeq:
CvSeq
-----
.. class:: CvSeq
Growable sequence of elements.
Many OpenCV functions return a CvSeq object. The CvSeq obect is a sequence, so these are all legal:
::
seq = cv.FindContours(scribble, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE)
# seq is a sequence of point pairs
print len(seq)
# FindContours returns a sequence of (x,y) points, so to print them out:
for (x,y) in seq:
print (x,y)
print seq[10] # tenth entry in the seqeuence
print seq[::-1] # reversed sequence
print sorted(list(seq)) # sorted sequence
..
Also, a CvSeq object has methods
``h_next()``
,
``h_prev()``
,
``v_next()``
and
``v_prev()``
.
Some OpenCV functions (for example
:ref:`FindContours`
) can return multiple CvSeq objects, connected by these relations.
In this case the methods return the other sequences. If no relation between sequences exists, then the methods return
``None``
.
.. index:: CvSet
.. _CvSet:
CvSet
-----
.. class:: CvSet
Collection of nodes.
Some OpenCV functions return a CvSet object. The CvSet obect is iterable, for example:
::
for i in s:
print i
print set(s)
print list(s)
..
.. index:: CloneSeq
.. _CloneSeq:
CloneSeq
--------
.. function:: CloneSeq(seq,storage)-> None
Creates a copy of a sequence.
:param seq: Sequence
:type seq: :class:`CvSeq`
:param storage: The destination storage block to hold the new sequence header and the copied data, if any. If it is NULL, the function uses the storage block containing the input sequence.
:type storage: :class:`CvMemStorage`
The function makes a complete copy of the input sequence and returns it.
.. index:: CreateMemStorage
.. _CreateMemStorage:
CreateMemStorage
----------------
.. function:: CreateMemStorage(blockSize = 0) -> memstorage
Creates memory storage.
:param blockSize: Size of the storage blocks in bytes. If it is 0, the block size is set to a default value - currently it is about 64K.
:type blockSize: int
The function creates an empty memory storage. See
:ref:`CvMemStorage`
description.
.. index:: SeqInvert
.. _SeqInvert:
SeqInvert
---------
.. function:: SeqInvert(seq)-> None
Reverses the order of sequence elements.
:param seq: Sequence
:type seq: :class:`CvSeq`
The function reverses the sequence in-place - makes the first element go last, the last element go first and so forth.
.. index:: SeqRemove
.. _SeqRemove:
SeqRemove
---------
.. function:: SeqRemove(seq,index)-> None
Removes an element from the middle of a sequence.
:param seq: Sequence
:type seq: :class:`CvSeq`
:param index: Index of removed element
:type index: int
The function removes elements with the given
index. If the index is out of range the function reports an error. An
attempt to remove an element from an empty sequence is a special
case of this situation. The function removes an element by shifting
the sequence elements between the nearest end of the sequence and the
``index``
-th position, not counting the latter.
.. index:: SeqRemoveSlice
.. _SeqRemoveSlice:
SeqRemoveSlice
--------------
.. function:: SeqRemoveSlice(seq,slice)-> None
Removes a sequence slice.
:param seq: Sequence
:type seq: :class:`CvSeq`
:param slice: The part of the sequence to remove
:type slice: :class:`CvSlice`
The function removes a slice from the sequence.
This diff is collapsed.
This diff is collapsed.
*******************************************************
features2d. Feature Detection and Descriptor Extraction
*******************************************************
.. toctree::
:maxdepth: 2
features2d_feature_detection_and_description
*************************************
highgui. High-level GUI and Media I/O
*************************************
While OpenCV was designed for use in full-scale
applications and can be used within functionally rich UI frameworks (such as Qt, WinForms or Cocoa) or without any UI at all, sometimes there is a need to try some functionality quickly and visualize the results. This is what the HighGUI module has been designed for.
It provides easy interface to:
*
create and manipulate windows that can display images and "remember" their content (no need to handle repaint events from OS)
*
add trackbars to the windows, handle simple mouse events as well as keyboard commmands
*
read and write images to/from disk or memory.
*
read video from camera or file and write video to a file.
.. toctree::
:maxdepth: 2
highgui_user_interface
highgui_reading_and_writing_images_and_video
This diff is collapsed.
*************************
imgproc. Image Processing
*************************
.. toctree::
:maxdepth: 2
imgproc_histograms
imgproc_image_filtering
imgproc_geometric_image_transformations
imgproc_miscellaneous_image_transformations
imgproc_structural_analysis_and_shape_descriptors
imgproc_planar_subdivisions
imgproc_motion_analysis_and_object_tracking
imgproc_feature_detection
imgproc_object_detection
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
***************************
objdetect. Object Detection
***************************
.. toctree::
:maxdepth: 2
objdetect_cascade_classification
This diff is collapsed.
This diff is collapsed.
*********************
video. Video Analysis
*********************
.. toctree::
:maxdepth: 2
video_motion_analysis_and_object_tracking
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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