propagated some more changes from 2.3 to trunk

This commit is contained in:
Vadim Pisarevsky 2011-06-23 12:15:35 +00:00
parent 6e613bca9b
commit f0624c08dc
116 changed files with 22049 additions and 6609 deletions

View File

@ -1,235 +0,0 @@
# By including this file, all files in the CMAKE_INSTALL_DEBUG_LIBRARIES,
# will be installed with INSTALL_PROGRAMS into /bin for WIN32 and /lib
# for non-win32. If CMAKE_SKIP_INSTALL_RULES is set to TRUE before including
# this file, then the INSTALL command is not called. The use can use
# the variable CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS to use a custom install
# command and install them into any directory they want.
# If it is the MSVC compiler, then the microsoft run
# time libraries will be found add automatically added to the
# CMAKE_INSTALL_DEBUG_LIBRARIES, and installed.
# If CMAKE_INSTALL_DEBUG_LIBRARIES is set and it is the MSVC
# compiler, then the debug libraries are installed when available.
# If CMAKE_INSTALL_MFC_LIBRARIES is set then the MFC run time
# libraries are installed as well as the CRT run time libraries.
IF(MSVC)
FILE(TO_CMAKE_PATH "$ENV{SYSTEMROOT}" SYSTEMROOT)
IF(MSVC70)
SET(__install__libs
"${SYSTEMROOT}/system32/msvcp70.dll"
"${SYSTEMROOT}/system32/msvcr70.dll"
)
ENDIF(MSVC70)
IF(MSVC71)
SET(__install__libs
"${SYSTEMROOT}/system32/msvcp71.dll"
"${SYSTEMROOT}/system32/msvcr71.dll"
)
ENDIF(MSVC71)
IF(CMAKE_CL_64)
SET(CMAKE_MSVC_ARCH amd64)
ELSE(CMAKE_CL_64)
SET(CMAKE_MSVC_ARCH x86)
ENDIF(CMAKE_CL_64)
GET_FILENAME_COMPONENT(devenv_dir "${CMAKE_MAKE_PROGRAM}" PATH)
GET_FILENAME_COMPONENT(base_dir "${devenv_dir}/../.." ABSOLUTE)
IF(MSVC80)
# Find the runtime library redistribution directory.
FIND_PATH(MSVC80_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC80.CRT/Microsoft.VC80.CRT.manifest
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0;InstallDir]/../../VC/redist"
"${base_dir}/VC/redist"
)
MARK_AS_ADVANCED(MSVC80_REDIST_DIR)
SET(MSVC80_CRT_DIR "${MSVC80_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.CRT")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
SET(__install__libs
"${MSVC80_CRT_DIR}/Microsoft.VC80.CRT.manifest"
"${MSVC80_CRT_DIR}/msvcm80.dll"
"${MSVC80_CRT_DIR}/msvcp80.dll"
"${MSVC80_CRT_DIR}/msvcr80.dll"
)
IF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC80_CRT_DIR
"${MSVC80_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC80.DebugCRT")
SET(__install__libs ${__install__libs}
"${MSVC80_CRT_DIR}/Microsoft.VC80.DebugCRT.manifest"
"${MSVC80_CRT_DIR}/msvcm80d.dll"
"${MSVC80_CRT_DIR}/msvcp80d.dll"
"${MSVC80_CRT_DIR}/msvcr80d.dll"
)
ENDIF(CMAKE_INSTALL_DEBUG_LIBRARIES)
ENDIF(MSVC80)
IF(MSVC90)
# Find the runtime library redistribution directory.
FIND_PATH(MSVC90_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0;InstallDir]/../../VC/redist"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\9.0;InstallDir]/../../VC/redist"
"${base_dir}/VC/redist"
)
MARK_AS_ADVANCED(MSVC90_REDIST_DIR)
SET(MSVC90_CRT_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.CRT")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
SET(__install__libs
"${MSVC90_CRT_DIR}/Microsoft.VC90.CRT.manifest"
"${MSVC90_CRT_DIR}/msvcm90.dll"
"${MSVC90_CRT_DIR}/msvcp90.dll"
"${MSVC90_CRT_DIR}/msvcr90.dll"
)
IF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC90_CRT_DIR
"${MSVC90_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC90.DebugCRT")
SET(__install__libs ${__install__libs}
"${MSVC90_CRT_DIR}/Microsoft.VC90.DebugCRT.manifest"
"${MSVC90_CRT_DIR}/msvcm90d.dll"
"${MSVC90_CRT_DIR}/msvcp90d.dll"
"${MSVC90_CRT_DIR}/msvcr90d.dll"
)
ENDIF(CMAKE_INSTALL_DEBUG_LIBRARIES)
IF(CMAKE_INSTALL_OPENMP_LIBRARIES)
SET(MSVC90_OPENMP_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.OPENMP")
SET(__install__libs ${__install__libs}
"${MSVC90_OPENMP_DIR}/Microsoft.VC90.OpenMP.manifest"
"${MSVC90_OPENMP_DIR}/vcomp90.dll"
)
IF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC90_OPENMP_DIR
"${MSVC90_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC90.DebugOPENMP")
SET(__install__libs ${__install__libs}
"${MSVC90_OPENMP_DIR}/Microsoft.VC90.DebugOpenMP.manifest"
"${MSVC90_OPENMP_DIR}/vcomp90d.dll"
)
ENDIF(CMAKE_INSTALL_DEBUG_LIBRARIES)
ENDIF(CMAKE_INSTALL_OPENMP_LIBRARIES)
ENDIF(MSVC90)
IF(CMAKE_INSTALL_MFC_LIBRARIES)
IF(MSVC70)
SET(__install__libs ${__install__libs}
"${SYSTEMROOT}/system32/mfc70.dll"
)
ENDIF(MSVC70)
IF(MSVC71)
SET(__install__libs ${__install__libs}
"${SYSTEMROOT}/system32/mfc71.dll"
)
ENDIF(MSVC71)
IF(MSVC80)
IF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC80_MFC_DIR
"${MSVC80_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC80.DebugMFC")
SET(__install__libs ${__install__libs}
"${MSVC80_MFC_DIR}/Microsoft.VC80.DebugMFC.manifest"
"${MSVC80_MFC_DIR}/mfc80d.dll"
"${MSVC80_MFC_DIR}/mfc80ud.dll"
"${MSVC80_MFC_DIR}/mfcm80d.dll"
"${MSVC80_MFC_DIR}/mfcm80ud.dll"
)
ENDIF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC80_MFC_DIR "${MSVC80_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.MFC")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
SET(__install__libs ${__install__libs}
"${MSVC80_MFC_DIR}/Microsoft.VC80.MFC.manifest"
"${MSVC80_MFC_DIR}/mfc80.dll"
"${MSVC80_MFC_DIR}/mfc80u.dll"
"${MSVC80_MFC_DIR}/mfcm80.dll"
"${MSVC80_MFC_DIR}/mfcm80u.dll"
)
# include the language dll's for vs8 as well as the actuall dll's
SET(MSVC80_MFCLOC_DIR "${MSVC80_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.MFCLOC")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
SET(__install__libs ${__install__libs}
"${MSVC80_MFCLOC_DIR}/Microsoft.VC80.MFCLOC.manifest"
"${MSVC80_MFCLOC_DIR}/mfc80chs.dll"
"${MSVC80_MFCLOC_DIR}/mfc80cht.dll"
"${MSVC80_MFCLOC_DIR}/mfc80enu.dll"
"${MSVC80_MFCLOC_DIR}/mfc80esp.dll"
"${MSVC80_MFCLOC_DIR}/mfc80deu.dll"
"${MSVC80_MFCLOC_DIR}/mfc80fra.dll"
"${MSVC80_MFCLOC_DIR}/mfc80ita.dll"
"${MSVC80_MFCLOC_DIR}/mfc80jpn.dll"
"${MSVC80_MFCLOC_DIR}/mfc80kor.dll"
)
ENDIF(MSVC80)
IF(MSVC90)
IF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC90_MFC_DIR
"${MSVC90_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC90.DebugMFC")
SET(__install__libs ${__install__libs}
"${MSVC90_MFC_DIR}/Microsoft.VC90.DebugMFC.manifest"
"${MSVC90_MFC_DIR}/mfc90d.dll"
"${MSVC90_MFC_DIR}/mfc90ud.dll"
"${MSVC90_MFC_DIR}/mfcm90d.dll"
"${MSVC90_MFC_DIR}/mfcm90ud.dll"
)
ENDIF(CMAKE_INSTALL_DEBUG_LIBRARIES)
SET(MSVC90_MFC_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.MFC")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
SET(__install__libs ${__install__libs}
"${MSVC90_MFC_DIR}/Microsoft.VC90.MFC.manifest"
"${MSVC90_MFC_DIR}/mfc90.dll"
"${MSVC90_MFC_DIR}/mfc90u.dll"
"${MSVC90_MFC_DIR}/mfcm90.dll"
"${MSVC90_MFC_DIR}/mfcm90u.dll"
)
# include the language dll's for vs9 as well as the actuall dll's
SET(MSVC90_MFCLOC_DIR "${MSVC90_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.MFCLOC")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
SET(__install__libs ${__install__libs}
"${MSVC90_MFCLOC_DIR}/Microsoft.VC90.MFCLOC.manifest"
"${MSVC90_MFCLOC_DIR}/mfc90chs.dll"
"${MSVC90_MFCLOC_DIR}/mfc90cht.dll"
"${MSVC90_MFCLOC_DIR}/mfc90enu.dll"
"${MSVC90_MFCLOC_DIR}/mfc90esp.dll"
"${MSVC90_MFCLOC_DIR}/mfc90deu.dll"
"${MSVC90_MFCLOC_DIR}/mfc90fra.dll"
"${MSVC90_MFCLOC_DIR}/mfc90ita.dll"
"${MSVC90_MFCLOC_DIR}/mfc90jpn.dll"
"${MSVC90_MFCLOC_DIR}/mfc90kor.dll"
)
ENDIF(MSVC90)
ENDIF(CMAKE_INSTALL_MFC_LIBRARIES)
FOREACH(lib
${__install__libs}
)
IF(EXISTS ${lib})
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} ${lib})
ENDIF(EXISTS ${lib})
ENDFOREACH(lib)
ENDIF(MSVC)
# Include system runtime libraries in the installation if any are
# specified by CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS.
IF(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
IF(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP)
IF(WIN32)
INSTALL_PROGRAMS(/bin ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS})
ELSE(WIN32)
INSTALL_PROGRAMS(/lib ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS})
ENDIF(WIN32)
ENDIF(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP)
ENDIF(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)

View File

@ -10,7 +10,6 @@ endif()
#if(ENABLE_OPENMP)
# set(CMAKE_INSTALL_OPENMP_LIBRARIES 1)
#endif()
#include(OpenCVInstallRequiredSystemLibraries.cmake)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_NAME "OpenCV")
@ -77,7 +76,7 @@ set(CPACK_SOURCE_PACKAGE_FILE_NAME
if(WIN32)
set(CPACK_GENERATOR "NSIS")
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_NSIS_PACKAGE_NAME "OpenCV ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_NSIS_PACKAGE_NAME "OpenCV ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}rc")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}\\\\doc\\\\opencv.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}\\\\doc\\\\opencv.ico")
#set(CPACK_PACKAGE_ICON "utils/opencv.ico")
@ -90,7 +89,9 @@ if(WIN32)
set(CPACK_NSIS_MENU_LINKS
"http://opencv.willowgarage.com" "Start Page"
"doc\\\\opencv.pdf" "The Reference Manual"
"doc\\\\opencv2refman_cpp.pdf" "The OpenCV C++ Reference Manual"
"doc\\\\opencv2refman_py.pdf" "The OpenCV Python Reference Manual"
"doc\\\\opencv_tutorials.pdf" "The OpenCV Tutorials for Beginners"
"CMakeLists.txt" "The Build Script (open with CMake)"
"samples\\\\c" "C Samples"
"samples\\\\cpp" "C++ Samples"

View File

@ -13,12 +13,13 @@ project(opencv_docs)
file(GLOB_RECURSE OPENCV2_FILES_PICT ../modules/*.png ../modules/*.jpg)
file(GLOB_RECURSE OPENCV2_FILES_RST ../modules/*.rst)
file(GLOB_RECURSE OPENCV2_PY_FILES_RST opencv2/*.rst)
file(GLOB_RECURSE OPENCV1_FILES_PICT pics/*.png pics/*.jpg)
file(GLOB_RECURSE OPENCV1_FILES_RST opencv1/*.rst)
file(GLOB_RECURSE OPENCV_FILES_UG user_guide/*.rst)
file(GLOB_RECURSE OPENCV_FILES_TUT tutorials/*.rst)
set(OPENCV_DOC_DEPS conf.py ${OPENCV2_FILES_RST} ${OPENCV2_FILES_PICT}
set(OPENCV_DOC_DEPS conf.py ${OPENCV2_FILES_RST} ${OPENCV2_FILES_PICT} ${OPENCV2_PY_FILES_RST}
${OPENCV1_FILES_RST} ${OPENCV1_FILES_PICT}
${OPENCV_FILES_UG} ${OPENCV_FILES_TUT})
@ -30,8 +31,10 @@ add_custom_target(docs
${CMAKE_CURRENT_SOURCE_DIR}/pics ${CMAKE_CURRENT_BINARY_DIR}/doc/opencv1/pics
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/mymath.sty ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${PDFLATEX_COMPILER} opencv2refman
COMMAND ${PDFLATEX_COMPILER} opencv2refman
COMMAND ${PDFLATEX_COMPILER} opencv2refman_cpp
COMMAND ${PDFLATEX_COMPILER} opencv2refman_cpp
COMMAND ${PDFLATEX_COMPILER} opencv2refman_py
COMMAND ${PDFLATEX_COMPILER} opencv2refman_py
COMMAND ${PDFLATEX_COMPILER} opencv1refman_c
COMMAND ${PDFLATEX_COMPILER} opencv1refman_c
COMMAND ${PDFLATEX_COMPILER} opencv1refman_py

View File

@ -1,54 +0,0 @@
This file describes how to create the opencv.pdf manual in the
.../opencv/doc directory. It further describes how to produce
the html files on disk that populate the online OpenCV documenation
wiki.
-------------------------------------------------------------------------
In Ubuntu or Debian, required to build the opencv.pdf manual:
sudo apt-get install texlive texlive-latex-extra latex-xcolor texlive-fonts-extra
To build the HTML documentation, these are also required:
sudo apt-get install python-setuptools ## See [1] below for another install method
sudo easy_install -U Sphinx ## This is NOT the speech recognition program.
sudo apt-get install dvipng
sudo easy_install plasTeX
-------------------------------------------------------------------------
In other Linux distros you will also need to install LiveTeX and,
optionally, if you want to produce the hmtl files, the Sphinx tool (http://sphinx.pocoo.org/)
In MacOSX you can use MacTex (https://www.tug.org/mactex/).
In Windows you can use MiKTeX
--------------------------------------------------------------------------
(1) To build the latex files to create the opencv.pdf manual, in the
.../opencv/doc directory, issue the command:
sh go
(2) If you want to build the html files that OpenCV uses to populate the
online documentation, assuming you downloaded easy_install,
Sphinx and plasTex as above, then from the .../opencv/doc/latex2sphinx directory,
issue the "buildall" commend there:
sh buildall
The resulting html files will be be created in:
.../opencv/doc/latex2sphinx/_build/html
Under this html directory, you will find index.html files for:
cpp The C++ manual
c The C manual
py The Python manual
--------------------------------------------------------------------------
[1] To install easy install on Ubuntu, try either (as stated above):
sudo apt-get install python-setuptools
or try using:
First:
wget -q http://peak.telecommunity.com/dist/ez_setup.py
Then
sudo python ez_setup.py

View File

@ -274,17 +274,30 @@ tt.descname {
font-size: 1.6em;
}
dl.cfunction {
padding-bottom: 9px;
}
dl.cfunction > dt:first-child {
margin-bottom: 7px;
border-bottom: 1px dotted black;
}
div.math p {
margin-top: 10px;
margin-bottom: 10px;
}
dl.function > dt:first-child {
margin-bottom: 7px;
background-color: #ecf0f3;
}
dl.cfunction > dt:first-child {
margin-bottom: 7px;
background-color: #ecf0f3;
}
dl.pyfunction > dt:first-child {
margin-bottom: 7px;
background-color: #ecf0f3;
}
table.field-list {
margin-top: 20px;
}
ul.simple {
list-style: none;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 303 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -126,7 +126,7 @@ html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
@ -223,8 +223,10 @@ pngmath_latex_preamble = r"""
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
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'),
('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',
u'', 'manual'),
('doc/opencv1/py/py_index', 'opencv1refman_py.tex', u'The OpenCV 1.x Python Reference Manual',

View File

@ -9,7 +9,7 @@ IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
For Open Source Computer Vision Library
Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
Copyright (C) 2008-2010, Willow Garage Inc., all rights reserved.
Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
Third party copyrights are property of their respective owners.
Redistribution and use in source and binary forms, with or without modification,

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
"""
ocv domain, a modified copy of sphinx.domains.cpp. The original copyright is below
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ocv domain, a modified copy of sphinx.domains.cpp + shpinx.domains.python.
The original copyright is below
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The C++ language domain.
The OpenCV C/C++/Python/Java/... language domain.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
@ -13,6 +14,7 @@ import re
from copy import deepcopy
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx import addnodes
from sphinx.roles import XRefRole
@ -21,7 +23,271 @@ from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription
from sphinx.util.nodes import make_refnode
from sphinx.util.compat import Directive
from sphinx.util.docfields import Field, TypedField
from sphinx.util.docfields import Field, GroupedField, TypedField
########################### Python Part ###########################
# REs for Python signatures
py_sig_re = re.compile(
r'''^ ([\w.]*\.)? # class name(s)
(\w+) \s* # thing name
(?: \((.*)\) # optional: arguments
(?:\s* -> \s* (.*))? # return annotation
)? $ # and nothing more
''', re.VERBOSE)
def _pseudo_parse_arglist(signode, arglist):
""""Parse" a list of arguments separated by commas.
Arguments can have "optional" annotations given by enclosing them in
brackets. Currently, this will split at any comma, even if it's inside a
string literal (e.g. default argument value).
"""
paramlist = addnodes.desc_parameterlist()
stack = [paramlist]
try:
for argument in arglist.split(','):
argument = argument.strip()
ends_open = ends_close = 0
while argument.startswith('['):
stack.append(addnodes.desc_optional())
stack[-2] += stack[-1]
argument = argument[1:].strip()
while argument.startswith(']'):
stack.pop()
argument = argument[1:].strip()
while argument.endswith(']'):
ends_close += 1
argument = argument[:-1].strip()
while argument.endswith('['):
ends_open += 1
argument = argument[:-1].strip()
if argument:
stack[-1] += addnodes.desc_parameter(argument, argument, noemph=True)
while ends_open:
stack.append(addnodes.desc_optional())
stack[-2] += stack[-1]
ends_open -= 1
while ends_close:
stack.pop()
ends_close -= 1
if len(stack) != 1:
raise IndexError
except IndexError:
# if there are too few or too many elements on the stack, just give up
# and treat the whole argument list as one argument, discarding the
# already partially populated paramlist node
signode += addnodes.desc_parameterlist()
signode[-1] += addnodes.desc_parameter(arglist, arglist)
else:
signode += paramlist
class OCVPyObject(ObjectDescription):
"""
Description of a general Python object.
"""
option_spec = {
'noindex': directives.flag,
'module': directives.unchanged,
}
doc_field_types = [
TypedField('parameter', label=l_('Parameters'),
names=('param', 'parameter', 'arg', 'argument',
'keyword', 'kwarg', 'kwparam'),
typerolename='obj', typenames=('paramtype', 'type'),
can_collapse=True),
TypedField('variable', label=l_('Variables'), rolename='obj',
names=('var', 'ivar', 'cvar'),
typerolename='obj', typenames=('vartype',),
can_collapse=True),
GroupedField('exceptions', label=l_('Raises'), rolename='exc',
names=('raises', 'raise', 'exception', 'except'),
can_collapse=True),
Field('returnvalue', label=l_('Returns'), has_arg=False,
names=('returns', 'return')),
Field('returntype', label=l_('Return type'), has_arg=False,
names=('rtype',)),
]
def get_signature_prefix(self, sig):
"""
May return a prefix to put before the object name in the signature.
"""
return ''
def needs_arglist(self):
"""
May return true if an empty argument list is to be generated even if
the document contains none.
"""
return False
def handle_signature(self, sig, signode):
"""
Transform a Python signature into RST nodes.
Returns (fully qualified name of the thing, classname if any).
If inside a class, the current class name is handled intelligently:
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present
"""
signode += nodes.strong("Python:", "Python:")
signode += addnodes.desc_name(" ", " ")
m = py_sig_re.match(sig)
if m is None:
raise ValueError
name_prefix, name, arglist, retann = m.groups()
# determine module and class name (if applicable), as well as full name
modname = self.options.get(
'module', self.env.temp_data.get('py:module'))
classname = self.env.temp_data.get('py:class')
if classname:
add_module = False
if name_prefix and name_prefix.startswith(classname):
fullname = name_prefix + name
# class name is given again in the signature
name_prefix = name_prefix[len(classname):].lstrip('.')
elif name_prefix:
# class name is given in the signature, but different
# (shouldn't happen)
fullname = classname + '.' + name_prefix + name
else:
# class name is not given in the signature
fullname = classname + '.' + name
else:
add_module = True
if name_prefix:
classname = name_prefix.rstrip('.')
fullname = name_prefix + name
else:
classname = ''
fullname = name
signode['module'] = modname
signode['class'] = classname
signode['fullname'] = fullname
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
signode += addnodes.desc_annotation(sig_prefix, sig_prefix)
if name_prefix:
signode += addnodes.desc_addname(name_prefix, name_prefix)
# exceptions are a special case, since they are documented in the
# 'exceptions' module.
elif add_module and self.env.config.add_module_names:
modname = self.options.get(
'module', self.env.temp_data.get('py:module'))
if modname and modname != 'exceptions':
nodetext = modname + '.'
signode += addnodes.desc_addname(nodetext, nodetext)
signode += addnodes.desc_name(name, name)
if not arglist:
if self.needs_arglist():
# for callables, add an empty parameter list
signode += addnodes.desc_parameterlist()
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname, name_prefix
_pseudo_parse_arglist(signode, arglist)
if retann:
signode += addnodes.desc_returns(retann, retann)
return fullname, name_prefix
def get_index_text(self, modname, name):
"""
Return the text for the index entry of the object.
"""
raise NotImplementedError('must be implemented in subclasses')
def add_target_and_index(self, name_cls, sig, signode):
modname = self.options.get(
'module', self.env.temp_data.get('py:module'))
fullname = (modname and modname + '.' or '') + name_cls[0]
# note target
if fullname not in self.state.document.ids:
signode['names'].append(fullname)
signode['ids'].append(fullname)
signode['first'] = (not self.names)
self.state.document.note_explicit_target(signode)
objects = self.env.domaindata['py']['objects']
if fullname in objects:
self.env.warn(
self.env.docname,
'duplicate object description of %s, ' % fullname +
'other instance in ' +
self.env.doc2path(objects[fullname][0]) +
', use :noindex: for one of them',
self.lineno)
objects[fullname] = (self.env.docname, self.objtype)
indextext = self.get_index_text(modname, name_cls)
if indextext:
self.indexnode['entries'].append(('single', indextext,
fullname, fullname))
def before_content(self):
# needed for automatic qualification of members (reset in subclasses)
self.clsname_set = False
def after_content(self):
if self.clsname_set:
self.env.temp_data['py:class'] = None
class OCVPyModulelevel(OCVPyObject):
"""
Description of an object on module level (functions, data).
"""
def needs_arglist(self):
return self.objtype == 'pyfunction'
def get_index_text(self, modname, name_cls):
if self.objtype == 'pyfunction':
if not modname:
fname = name_cls[0]
if not fname.startswith("cv") and not fname.startswith("cv2"):
return _('%s() (Python function)') % fname
pos = fname.find(".")
modname = fname[:pos]
fname = fname[pos+1:]
return _('%s() (Python function in %s)') % (fname, modname)
return _('%s() (Python function in %s)') % (name_cls[0], modname)
elif self.objtype == 'pydata':
if not modname:
return _('%s (Python variable)') % name_cls[0]
return _('%s (in module %s)') % (name_cls[0], modname)
else:
return ''
class OCVPyXRefRole(XRefRole):
def process_link(self, env, refnode, has_explicit_title, title, target):
refnode['ocv:module'] = env.temp_data.get('ocv:module')
refnode['ocv:class'] = env.temp_data.get('ocv:class')
if not has_explicit_title:
title = title.lstrip('.') # only has a meaning for the target
target = target.lstrip('~') # only has a meaning for the title
# if the first character is a tilde, don't display the module/class
# parts of the contents
if title[0:1] == '~':
title = title[1:]
dot = title.rfind('.')
if dot != -1:
title = title[dot+1:]
# if the first character is a dot, search more specific namespaces first
# else search builtins first
if target[0:1] == '.':
target = target[1:]
refnode['refspecific'] = True
return title, target
########################### C/C++/Java Part ###########################
_identifier_re = re.compile(r'(~?\b[a-zA-Z_][a-zA-Z0-9_]*)\b')
_whitespace_re = re.compile(r'\s+(?u)')
@ -838,6 +1104,8 @@ class OCVObject(ObjectDescription):
node += pnode
def attach_modifiers(self, node, obj):
node += nodes.strong("C++:", "C++:")
node += addnodes.desc_name(" ", " ")
if obj.visibility != 'public':
node += addnodes.desc_annotation(obj.visibility,
obj.visibility)
@ -976,10 +1244,12 @@ class OCVFunctionObject(OCVObject):
if arg.type is not None:
self.attach_type(param, arg.type)
param += nodes.Text(u' ')
param += nodes.emphasis(unicode(arg.name), unicode(arg.name))
#param += nodes.emphasis(unicode(arg.name), unicode(arg.name))
param += nodes.strong(unicode(arg.name), unicode(arg.name))
if arg.default is not None:
def_ = u'=' + unicode(arg.default)
param += nodes.emphasis(def_, def_)
#param += nodes.emphasis(def_, def_)
param += nodes.Text(def_)
paramlist += param
node += paramlist
@ -1059,6 +1329,7 @@ class OCVDomain(Domain):
object_types = {
'class': ObjType(l_('class'), 'class'),
'function': ObjType(l_('function'), 'func', 'funcx'),
'pyfunction': ObjType(l_('pyfunction'), 'pyfunc'),
'member': ObjType(l_('member'), 'member'),
'type': ObjType(l_('type'), 'type')
}
@ -1066,6 +1337,7 @@ class OCVDomain(Domain):
directives = {
'class': OCVClassObject,
'function': OCVFunctionObject,
'pyfunction': OCVPyModulelevel,
'member': OCVMemberObject,
'type': OCVTypeObject,
'namespace': OCVCurrentNamespace
@ -1074,6 +1346,7 @@ class OCVDomain(Domain):
'class': OCVXRefRole(),
'func' : OCVXRefRole(fix_parens=True),
'funcx' : OCVXRefRole(),
'pyfunc' : OCVPyXRefRole(),
'member': OCVXRefRole(),
'type': OCVXRefRole()
}

Binary file not shown.

View File

@ -1781,6 +1781,8 @@ Difference norm between two projections is the maximal distance between correspo
``criteria.epsilon``
serves to stop the algorithm if the difference is small.
An example of using ``cvPOSIT`` and ``cvCreatePOSITObject`` is available at http://opencv.willowgarage.com/wiki/Posit
.. index:: ProjectPoints2

View File

@ -1,206 +0,0 @@
# -*- coding: utf-8 -*-
#
# opencv documentation build configuration file, created by
# sphinx-quickstart on Thu Jun 4 21:06:43 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# 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.
#sys.path.append(os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.pngmath', 'sphinx.ext.doctest'] # , 'sphinx.ext.intersphinx']
doctest_test_doctest_blocks = 'block'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'opencv'
copyright = u'2010, authors'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.2'
# The full version, including alpha/beta/rc tags.
release = '2.2.9'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'blue'
# 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
# documentation.
html_theme_options = {
"lang" : "%LANG%" # buildall substitutes this for c, cpp, py
}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = ['../_themes']
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = '../opencv-logo2.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 = None
# 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']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'opencvdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#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', 'opencv.tex', u'opencv Documentation',
u'author', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = 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_use_modindex = True
pngmath_latex_preamble = '\usepackage{mymath}\usepackage{amsmath}\usepackage{bbm}\usepackage[usenames]{color}'
# intersphinx_mapping = {
# 'http://docs.python.org/': None,
# }
intersphinx_mapping = {}
latex_elements = {'preamble': '\usepackage{mymath}\usepackage{amssymb}\usepackage{amsmath}\usepackage{bbm}'}

View File

@ -7234,7 +7234,7 @@ mSet
.. cfunction:: void cvmSet(CvMat* mat, int row, int col, double value)
Returns a specific element of a single-channel floating-point matrix.
Sets a specific element of a single-channel floating-point matrix.

View File

@ -648,13 +648,7 @@ The function can do the following transformations:
) The Bayer pattern is widely used in CCD and CMOS cameras. It allows one to get color pictures from a single plane where R,G and B pixels (sensors of a particular component) are interleaved like this:
.. math::
\newcommand{\Rcell}{\color{red}R} \newcommand{\Gcell}{\color{green}G} \newcommand{\Bcell}{\color{blue}B} \definecolor{BackGray}{rgb}{0.8,0.8,0.8} \begin{array}{ c c c c c } \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \\ \Gcell & \colorbox{BackGray}{\Bcell} & \colorbox{BackGray}{\Gcell} & \Bcell & \Gcell \\ \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \\ \Gcell & \Bcell & \Gcell & \Bcell & \Gcell \\ \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \end{array}
.. image:: ../pics/bayer.png
The output RGB components of a pixel are interpolated from 1, 2 or
4 neighbors of the pixel having the same color. There are several

View File

@ -1,206 +0,0 @@
# -*- coding: utf-8 -*-
#
# opencv documentation build configuration file, created by
# sphinx-quickstart on Thu Jun 4 21:06:43 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# 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.
#sys.path.append(os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.pngmath', 'sphinx.ext.doctest'] # , 'sphinx.ext.intersphinx']
doctest_test_doctest_blocks = 'block'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'opencv'
copyright = u'2010, authors'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.2'
# The full version, including alpha/beta/rc tags.
release = '2.2.9'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'blue'
# 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
# documentation.
html_theme_options = {
"lang" : "%LANG%" # buildall substitutes this for c, cpp, py
}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = ['../_themes']
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = '../opencv-logo2.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 = None
# 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']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'opencvdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#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', 'opencv.tex', u'opencv Documentation',
u'author', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = 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_use_modindex = True
pngmath_latex_preamble = '\usepackage{mymath}\usepackage{amsmath}\usepackage{bbm}\usepackage[usenames]{color}'
# intersphinx_mapping = {
# 'http://docs.python.org/': None,
# }
intersphinx_mapping = {}
latex_elements = {'preamble': '\usepackage{mymath}\usepackage{amssymb}\usepackage{amsmath}\usepackage{bbm}'}

View File

@ -663,14 +663,7 @@ The function can do the following transformations:
``CV_BayerBG2BGR, CV_BayerGB2BGR, CV_BayerRG2BGR, CV_BayerGR2BGR, CV_BayerBG2RGB, CV_BayerGB2RGB, CV_BayerRG2RGB, CV_BayerGR2RGB``
) The Bayer pattern is widely used in CCD and CMOS cameras. It allows one to get color pictures from a single plane where R,G and B pixels (sensors of a particular component) are interleaved like this:
.. math::
\newcommand{\Rcell}{\color{red}R} \newcommand{\Gcell}{\color{green}G} \newcommand{\Bcell}{\color{blue}B} \definecolor{BackGray}{rgb}{0.8,0.8,0.8} \begin{array}{ c c c c c } \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \\ \Gcell & \colorbox{BackGray}{\Bcell} & \colorbox{BackGray}{\Gcell} & \Bcell & \Gcell \\ \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \\ \Gcell & \Bcell & \Gcell & \Bcell & \Gcell \\ \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \end{array}
.. image:: ../pics/bayer.png
The output RGB components of a pixel are interpolated from 1, 2 or
4 neighbors of the pixel having the same color. There are several

BIN
doc/opencv1refman_c.pdf Normal file

Binary file not shown.

BIN
doc/opencv1refman_py.pdf Normal file

Binary file not shown.

View File

@ -1,18 +0,0 @@
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)

View File

@ -0,0 +1,10 @@
*******************************************************
calib3d. Camera Calibration, Pose Estimation and Stereo
*******************************************************
.. toctree::
:maxdepth: 2
calib3d_camera_calibration_and_3d_reconstruction

File diff suppressed because it is too large Load Diff

371
doc/opencv2/py/cookbook.rst Normal file
View File

@ -0,0 +1,371 @@
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()
..

16
doc/opencv2/py/core.rst Normal file
View File

@ -0,0 +1,16 @@
****************************
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

View File

@ -0,0 +1,520 @@
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>`_

View File

@ -0,0 +1,60 @@
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.

View File

@ -0,0 +1,967 @@
Drawing Functions
=================
.. highlight:: python
Drawing functions work with matrices/images of arbitrary depth.
The boundaries of the shapes can be rendered with antialiasing (implemented only for 8-bit images for now).
All the functions include the parameter color that uses a rgb value (that may be constructed
with
``CV_RGB``
) for color
images and brightness for grayscale images. For color images the order channel
is normally
*Blue, Green, Red*
, this is what
:cpp:func:`imshow`
,
:cpp:func:`imread`
and
:cpp:func:`imwrite`
expect
If you are using your own image rendering and I/O functions, you can use any channel ordering, the drawing functions process each channel independently and do not depend on the channel order or even on the color space used. The whole image can be converted from BGR to RGB or to a different color space using
:cpp:func:`cvtColor`
.
If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, many drawing functions can handle pixel coordinates specified with sub-pixel accuracy, that is, the coordinates can be passed as fixed-point numbers, encoded as integers. The number of fractional bits is specified by the
``shift``
parameter and the real point coordinates are calculated as
:math:`\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})`
. This feature is especially effective wehn rendering antialiased shapes.
Also, note that the functions do not support alpha-transparency - when the target image is 4-channnel, then the
``color[3]``
is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image.
.. index:: Circle
.. _Circle:
Circle
------
.. function:: Circle(img,center,radius,color,thickness=1,lineType=8,shift=0)-> None
Draws a circle.
:param img: Image where the circle is drawn
:type img: :class:`CvArr`
:param center: Center of the circle
:type center: :class:`CvPoint`
:param radius: Radius of the circle
:type radius: int
:param color: Circle color
:type color: :class:`CvScalar`
:param thickness: Thickness of the circle outline if positive, otherwise this indicates that a filled circle is to be drawn
:type thickness: int
:param lineType: Type of the circle boundary, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the center coordinates and radius value
:type shift: int
The function draws a simple or filled circle with a
given center and radius.
.. index:: ClipLine
.. _ClipLine:
ClipLine
--------
.. function:: ClipLine(imgSize, pt1, pt2) -> (clipped_pt1, clipped_pt2)
Clips the line against the image rectangle.
:param imgSize: Size of the image
:type imgSize: :class:`CvSize`
:param pt1: First ending point of the line segment.
:type pt1: :class:`CvPoint`
:param pt2: Second ending point of the line segment.
:type pt2: :class:`CvPoint`
The function calculates a part of the line segment which is entirely within the image.
If the line segment is outside the image, it returns None. If the line segment is inside the image it returns a new pair of points.
.. index:: DrawContours
.. _DrawContours:
DrawContours
------------
.. function:: DrawContours(img,contour,external_color,hole_color,max_level,thickness=1,lineType=8,offset=(0,0))-> None
Draws contour outlines or interiors in an image.
:param img: Image where the contours are to be drawn. As with any other drawing function, the contours are clipped with the ROI.
:type img: :class:`CvArr`
:param contour: Pointer to the first contour
:type contour: :class:`CvSeq`
:param external_color: Color of the external contours
:type external_color: :class:`CvScalar`
:param hole_color: Color of internal contours (holes)
:type hole_color: :class:`CvScalar`
:param max_level: Maximal level for drawn contours. If 0, only ``contour`` is drawn. If 1, the contour and all contours following
it on the same level are drawn. If 2, all contours following and all
contours one level below the contours are drawn, and so forth. If the value
is negative, the function does not draw the contours following after ``contour`` but draws the child contours of ``contour`` up
to the :math:`|\texttt{max\_level}|-1` level.
:type max_level: int
:param thickness: Thickness of lines the contours are drawn with.
If it is negative (For example, =CV _ FILLED), the contour interiors are
drawn.
:type thickness: int
:param lineType: Type of the contour segments, see :ref:`Line` description
:type lineType: int
The function draws contour outlines in the image if
:math:`\texttt{thickness} \ge 0`
or fills the area bounded by the contours if
:math:`\texttt{thickness}<0`
.
.. index:: Ellipse
.. _Ellipse:
Ellipse
-------
.. function:: Ellipse(img,center,axes,angle,start_angle,end_angle,color,thickness=1,lineType=8,shift=0)-> None
Draws a simple or thick elliptic arc or an fills ellipse sector.
:param img: The image
:type img: :class:`CvArr`
:param center: Center of the ellipse
:type center: :class:`CvPoint`
:param axes: Length of the ellipse axes
:type axes: :class:`CvSize`
:param angle: Rotation angle
:type angle: float
:param start_angle: Starting angle of the elliptic arc
:type start_angle: float
:param end_angle: Ending angle of the elliptic arc.
:type end_angle: float
:param color: Ellipse color
:type color: :class:`CvScalar`
:param thickness: Thickness of the ellipse arc outline if positive, otherwise this indicates that a filled ellipse sector is to be drawn
:type thickness: int
:param lineType: Type of the ellipse boundary, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the center coordinates and axes' values
:type shift: int
The function draws a simple or thick elliptic
arc or fills an ellipse sector. The arc is clipped by the ROI rectangle.
A piecewise-linear approximation is used for antialiased arcs and
thick arcs. All the angles are given in degrees. The picture below
explains the meaning of the parameters.
Parameters of Elliptic Arc
.. index:: EllipseBox
.. _EllipseBox:
EllipseBox
----------
.. function:: EllipseBox(img,box,color,thickness=1,lineType=8,shift=0)-> None
Draws a simple or thick elliptic arc or fills an ellipse sector.
:param img: Image
:type img: :class:`CvArr`
:param box: The enclosing box of the ellipse drawn
:type box: :class:`CvBox2D`
:param thickness: Thickness of the ellipse boundary
:type thickness: int
:param lineType: Type of the ellipse boundary, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the box vertex coordinates
:type shift: int
The function draws a simple or thick ellipse outline, or fills an ellipse. The functions provides a convenient way to draw an ellipse approximating some shape; that is what
:ref:`CamShift`
and
:ref:`FitEllipse`
do. The ellipse drawn is clipped by ROI rectangle. A piecewise-linear approximation is used for antialiased arcs and thick arcs.
.. index:: FillConvexPoly
.. _FillConvexPoly:
FillConvexPoly
--------------
.. function:: FillConvexPoly(img,pn,color,lineType=8,shift=0)-> None
Fills a convex polygon.
:param img: Image
:type img: :class:`CvArr`
:param pn: List of coordinate pairs
:type pn: :class:`CvPoints`
:param color: Polygon color
:type color: :class:`CvScalar`
:param lineType: Type of the polygon boundaries, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the vertex coordinates
:type shift: int
The function fills a convex polygon's interior.
This function is much faster than the function
``cvFillPoly``
and can fill not only convex polygons but any monotonic polygon,
i.e., a polygon whose contour intersects every horizontal line (scan
line) twice at the most.
.. index:: FillPoly
.. _FillPoly:
FillPoly
--------
.. function:: FillPoly(img,polys,color,lineType=8,shift=0)-> None
Fills a polygon's interior.
:param img: Image
:type img: :class:`CvArr`
:param polys: List of lists of (x,y) pairs. Each list of points is a polygon.
:type polys: list of lists of (x,y) pairs
:param color: Polygon color
:type color: :class:`CvScalar`
:param lineType: Type of the polygon boundaries, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the vertex coordinates
:type shift: int
The function fills an area bounded by several
polygonal contours. The function fills complex areas, for example,
areas with holes, contour self-intersection, and so forth.
.. index:: GetTextSize
.. _GetTextSize:
GetTextSize
-----------
.. function:: GetTextSize(textString,font)-> (textSize,baseline)
Retrieves the width and height of a text string.
:param font: Pointer to the font structure
:type font: :class:`CvFont`
:param textString: Input string
:type textString: str
:param textSize: Resultant size of the text string. Height of the text does not include the height of character parts that are below the baseline.
:type textSize: :class:`CvSize`
:param baseline: y-coordinate of the baseline relative to the bottom-most text point
:type baseline: int
The function calculates the dimensions of a rectangle to enclose a text string when a specified font is used.
.. index:: InitFont
.. _InitFont:
InitFont
--------
.. function:: InitFont(fontFace,hscale,vscale,shear=0,thickness=1,lineType=8)-> font
Initializes font structure.
:param font: Pointer to the font structure initialized by the function
:type font: :class:`CvFont`
:param fontFace: Font name identifier. Only a subset of Hershey fonts http://sources.isc.org/utils/misc/hershey-font.txt are supported now:
* **CV_FONT_HERSHEY_SIMPLEX** normal size sans-serif font
* **CV_FONT_HERSHEY_PLAIN** small size sans-serif font
* **CV_FONT_HERSHEY_DUPLEX** normal size sans-serif font (more complex than ``CV_FONT_HERSHEY_SIMPLEX`` )
* **CV_FONT_HERSHEY_COMPLEX** normal size serif font
* **CV_FONT_HERSHEY_TRIPLEX** normal size serif font (more complex than ``CV_FONT_HERSHEY_COMPLEX`` )
* **CV_FONT_HERSHEY_COMPLEX_SMALL** smaller version of ``CV_FONT_HERSHEY_COMPLEX``
* **CV_FONT_HERSHEY_SCRIPT_SIMPLEX** hand-writing style font
* **CV_FONT_HERSHEY_SCRIPT_COMPLEX** more complex variant of ``CV_FONT_HERSHEY_SCRIPT_SIMPLEX``
The parameter can be composited from one of the values above and an optional ``CV_FONT_ITALIC`` flag, which indicates italic or oblique font.
:type fontFace: int
:param hscale: Horizontal scale. If equal to ``1.0f`` , the characters have the original width depending on the font type. If equal to ``0.5f`` , the characters are of half the original width.
:type hscale: float
:param vscale: Vertical scale. If equal to ``1.0f`` , the characters have the original height depending on the font type. If equal to ``0.5f`` , the characters are of half the original height.
:type vscale: float
:param shear: Approximate tangent of the character slope relative to the vertical line. A zero value means a non-italic font, ``1.0f`` means about a 45 degree slope, etc.
:type shear: float
:param thickness: Thickness of the text strokes
:type thickness: int
:param lineType: Type of the strokes, see :ref:`Line` description
:type lineType: int
The function initializes the font structure that can be passed to text rendering functions.
.. index:: InitLineIterator
.. _InitLineIterator:
InitLineIterator
----------------
.. function:: InitLineIterator(image, pt1, pt2, connectivity=8, left_to_right=0) -> line_iterator
Initializes the line iterator.
:param image: Image to sample the line from
:type image: :class:`CvArr`
:param pt1: First ending point of the line segment
:type pt1: :class:`CvPoint`
:param pt2: Second ending point of the line segment
:type pt2: :class:`CvPoint`
:param connectivity: The scanned line connectivity, 4 or 8.
:type connectivity: int
:param left_to_right:
If ( :math:`\texttt{left\_to\_right} = 0` ) then the line is scanned in the specified order, from ``pt1`` to ``pt2`` .
If ( :math:`\texttt{left\_to\_right} \ne 0` ) the line is scanned from left-most point to right-most.
:type left_to_right: int
:param line_iterator: Iterator over the pixels of the line
:type line_iterator: :class:`iter`
The function returns an iterator over the pixels connecting the two points.
The points on the line are
calculated one by one using a 4-connected or 8-connected Bresenham
algorithm.
Example: Using line iterator to calculate the sum of pixel values along a color line
.. doctest::
>>> import cv
>>> img = cv.LoadImageM("building.jpg", cv.CV_LOAD_IMAGE_COLOR)
>>> li = cv.InitLineIterator(img, (100, 100), (125, 150))
>>> red_sum = 0
>>> green_sum = 0
>>> blue_sum = 0
>>> for (r, g, b) in li:
... red_sum += r
... green_sum += g
... blue_sum += b
>>> print red_sum, green_sum, blue_sum
10935.0 9496.0 7946.0
..
or more concisely using
`zip <http://docs.python.org/library/functions.html#zip>`_
:
.. doctest::
>>> import cv
>>> img = cv.LoadImageM("building.jpg", cv.CV_LOAD_IMAGE_COLOR)
>>> li = cv.InitLineIterator(img, (100, 100), (125, 150))
>>> print [sum(c) for c in zip(*li)]
[10935.0, 9496.0, 7946.0]
..
.. index:: Line
.. _Line:
Line
----
.. function:: Line(img,pt1,pt2,color,thickness=1,lineType=8,shift=0)-> None
Draws a line segment connecting two points.
:param img: The image
:type img: :class:`CvArr`
:param pt1: First point of the line segment
:type pt1: :class:`CvPoint`
:param pt2: Second point of the line segment
:type pt2: :class:`CvPoint`
:param color: Line color
:type color: :class:`CvScalar`
:param thickness: Line thickness
:type thickness: int
:param lineType: Type of the line:
* **8** (or omitted) 8-connected line.
* **4** 4-connected line.
* **CV_AA** antialiased line.
:type lineType: int
:param shift: Number of fractional bits in the point coordinates
:type shift: int
The function draws the line segment between
``pt1``
and
``pt2``
points in the image. The line is
clipped by the image or ROI rectangle. For non-antialiased lines
with integer coordinates the 8-connected or 4-connected Bresenham
algorithm is used. Thick lines are drawn with rounding endings.
Antialiased lines are drawn using Gaussian filtering. To specify
the line color, the user may use the macro
``CV_RGB( r, g, b )``
.
.. index:: PolyLine
.. _PolyLine:
PolyLine
--------
.. function:: PolyLine(img,polys,is_closed,color,thickness=1,lineType=8,shift=0)-> None
Draws simple or thick polygons.
:param polys: List of lists of (x,y) pairs. Each list of points is a polygon.
:type polys: list of lists of (x,y) pairs
:param img: Image
:type img: :class:`CvArr`
:param is_closed: Indicates whether the polylines must be drawn
closed. If closed, the function draws the line from the last vertex
of every contour to the first vertex.
:type is_closed: int
:param color: Polyline color
:type color: :class:`CvScalar`
:param thickness: Thickness of the polyline edges
:type thickness: int
:param lineType: Type of the line segments, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the vertex coordinates
:type shift: int
The function draws single or multiple polygonal curves.
.. index:: PutText
.. _PutText:
PutText
-------
.. function:: PutText(img,text,org,font,color)-> None
Draws a text string.
:param img: Input image
:type img: :class:`CvArr`
:param text: String to print
:type text: str
:param org: Coordinates of the bottom-left corner of the first letter
:type org: :class:`CvPoint`
:param font: Pointer to the font structure
:type font: :class:`CvFont`
:param color: Text color
:type color: :class:`CvScalar`
The function renders the text in the image with
the specified font and color. The printed text is clipped by the ROI
rectangle. Symbols that do not belong to the specified font are
replaced with the symbol for a rectangle.
.. index:: Rectangle
.. _Rectangle:
Rectangle
---------
.. function:: Rectangle(img,pt1,pt2,color,thickness=1,lineType=8,shift=0)-> None
Draws a simple, thick, or filled rectangle.
:param img: Image
:type img: :class:`CvArr`
:param pt1: One of the rectangle's vertices
:type pt1: :class:`CvPoint`
:param pt2: Opposite rectangle vertex
:type pt2: :class:`CvPoint`
:param color: Line color (RGB) or brightness (grayscale image)
:type color: :class:`CvScalar`
:param thickness: Thickness of lines that make up the rectangle. Negative values, e.g., CV _ FILLED, cause the function to draw a filled rectangle.
:type thickness: int
:param lineType: Type of the line, see :ref:`Line` description
:type lineType: int
:param shift: Number of fractional bits in the point coordinates
:type shift: int
The function draws a rectangle with two opposite corners
``pt1``
and
``pt2``
.
.. index:: CV_RGB
.. _CV_RGB:
CV_RGB
------
.. function:: CV_RGB(red,grn,blu)->CvScalar
Constructs a color value.
:param red: Red component
:type red: float
:param grn: Green component
:type grn: float
:param blu: Blue component
:type blu: float

View File

@ -0,0 +1,295 @@
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.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
Utility and System Functions and Macros
=======================================
.. highlight:: python
Error Handling
--------------
Errors in argument type cause a
``TypeError``
exception.
OpenCV errors cause an
``cv.error``
exception.
For example a function argument that is the wrong type produces a
``TypeError``
:
.. doctest::
>>> import cv
>>> cv.LoadImage(4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument 1 must be string, not int
..
A function with the
.. doctest::
>>> cv.CreateMat(-1, -1, cv.CV_8UC1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
error: Non-positive width or height
..
.. index:: GetTickCount
.. _GetTickCount:
GetTickCount
------------
.. function:: GetTickCount() -> long
Returns the number of ticks.
The function returns number of the ticks starting from some platform-dependent event (number of CPU ticks from the startup, number of milliseconds from 1970th year, etc.). The function is useful for accurate measurement of a function/user-code execution time. To convert the number of ticks to time units, use
:ref:`GetTickFrequency`
.
.. index:: GetTickFrequency
.. _GetTickFrequency:
GetTickFrequency
----------------
.. function:: GetTickFrequency() -> long
Returns the number of ticks per microsecond.
The function returns the number of ticks per microsecond. Thus, the quotient of
:ref:`GetTickCount`
and
:ref:`GetTickFrequency`
will give the number of microseconds starting from the platform-dependent event.

View File

@ -0,0 +1,95 @@
XML/YAML Persistence
====================
.. highlight:: python
.. index:: Load
.. _Load:
Load
----
.. function:: Load(filename,storage=NULL,name=NULL)-> generic
Loads an object from a file.
:param filename: File name
:type filename: str
:param storage: Memory storage for dynamic structures, such as :ref:`CvSeq` or :ref:`CvGraph` . It is not used for matrices or images.
:type storage: :class:`CvMemStorage`
:param name: Optional object name. If it is NULL, the first top-level object in the storage will be loaded.
:type name: str
The function loads an object from a file. It provides a
simple interface to
:ref:`Read`
. After the object is loaded, the file
storage is closed and all the temporary buffers are deleted. Thus,
to load a dynamic structure, such as a sequence, contour, or graph, one
should pass a valid memory storage destination to the function.
.. index:: Save
.. _Save:
Save
----
.. function:: Save(filename,structPtr,name=NULL,comment=NULL)-> None
Saves an object to a file.
:param filename: File name
:type filename: str
:param structPtr: Object to save
:type structPtr: :class:`generic`
:param name: Optional object name. If it is NULL, the name will be formed from ``filename`` .
:type name: str
:param comment: Optional comment to put in the beginning of the file
:type comment: str
The function saves an object to a file. It provides a simple interface to
:ref:`Write`
.

View File

@ -0,0 +1,10 @@
*******************************************************
features2d. Feature Detection and Descriptor Extraction
*******************************************************
.. toctree::
:maxdepth: 2
features2d_feature_detection_and_description

View File

@ -0,0 +1,264 @@
Feature detection and description
=================================
.. highlight:: python
* **image** The image. Keypoints (corners) will be detected on this.
* **keypoints** Keypoints detected on the image.
* **threshold** Threshold on difference between intensity of center pixel and
pixels on circle around this pixel. See description of the algorithm.
* **nonmaxSupression** If it is true then non-maximum supression will be applied to detected corners (keypoints).
.. index:: CvSURFPoint
.. _CvSURFPoint:
CvSURFPoint
-----------
.. class:: CvSURFPoint
A SURF keypoint, represented as a tuple
``((x, y), laplacian, size, dir, hessian)``
.
.. attribute:: x
x-coordinate of the feature within the image
.. attribute:: y
y-coordinate of the feature within the image
.. attribute:: laplacian
-1, 0 or +1. sign of the laplacian at the point. Can be used to speedup feature comparison since features with laplacians of different signs can not match
.. attribute:: size
size of the feature
.. attribute:: dir
orientation of the feature: 0..360 degrees
.. attribute:: hessian
value of the hessian (can be used to approximately estimate the feature strengths; see also params.hessianThreshold)
.. index:: ExtractSURF
.. _ExtractSURF:
ExtractSURF
-----------
.. function:: ExtractSURF(image,mask,storage,params)-> (keypoints,descriptors)
Extracts Speeded Up Robust Features from an image.
:param image: The input 8-bit grayscale image
:type image: :class:`CvArr`
:param mask: The optional input 8-bit mask. The features are only found in the areas that contain more than 50 % of non-zero mask pixels
:type mask: :class:`CvArr`
:param keypoints: sequence of keypoints.
:type keypoints: :class:`CvSeq` of :class:`CvSURFPoint`
:param descriptors: sequence of descriptors. Each SURF descriptor is a list of floats, of length 64 or 128.
:type descriptors: :class:`CvSeq` of list of float
:param storage: Memory storage where keypoints and descriptors will be stored
:type storage: :class:`CvMemStorage`
:param params: Various algorithm parameters in a tuple ``(extended, hessianThreshold, nOctaves, nOctaveLayers)`` :
* **extended** 0 means basic descriptors (64 elements each), 1 means extended descriptors (128 elements each)
* **hessianThreshold** only features with hessian larger than that are extracted. good default value is ~300-500 (can depend on the average local contrast and sharpness of the image). user can further filter out some features based on their hessian values and other characteristics.
* **nOctaves** the number of octaves to be used for extraction. With each next octave the feature size is doubled (3 by default)
* **nOctaveLayers** The number of layers within each octave (4 by default)
:type params: :class:`CvSURFParams`
The function cvExtractSURF finds robust features in the image, as
described in
Bay06
. For each feature it returns its location, size,
orientation and optionally the descriptor, basic or extended. The function
can be used for object tracking and localization, image stitching etc.
To extract strong SURF features from an image
.. doctest::
>>> import cv
>>> im = cv.LoadImageM("building.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
>>> (keypoints, descriptors) = cv.ExtractSURF(im, None, cv.CreateMemStorage(), (0, 30000, 3, 1))
>>> print len(keypoints), len(descriptors)
6 6
>>> for ((x, y), laplacian, size, dir, hessian) in keypoints:
... print "x=%d y=%d laplacian=%d size=%d dir=%f hessian=%f" % (x, y, laplacian, size, dir, hessian)
x=30 y=27 laplacian=-1 size=31 dir=69.778503 hessian=36979.789062
x=296 y=197 laplacian=1 size=33 dir=111.081039 hessian=31514.349609
x=296 y=266 laplacian=1 size=32 dir=107.092300 hessian=31477.908203
x=254 y=284 laplacian=1 size=31 dir=279.137360 hessian=34169.800781
x=498 y=525 laplacian=-1 size=33 dir=278.006592 hessian=31002.759766
x=777 y=281 laplacian=1 size=70 dir=167.940964 hessian=35538.363281
..
.. index:: GetStarKeypoints
.. _GetStarKeypoints:
GetStarKeypoints
----------------
.. function:: GetStarKeypoints(image,storage,params)-> keypoints
Retrieves keypoints using the StarDetector algorithm.
:param image: The input 8-bit grayscale image
:type image: :class:`CvArr`
:param storage: Memory storage where the keypoints will be stored
:type storage: :class:`CvMemStorage`
:param params: Various algorithm parameters in a tuple ``(maxSize, responseThreshold, lineThresholdProjected, lineThresholdBinarized, suppressNonmaxSize)`` :
* **maxSize** maximal size of the features detected. The following values of the parameter are supported: 4, 6, 8, 11, 12, 16, 22, 23, 32, 45, 46, 64, 90, 128
* **responseThreshold** threshold for the approximatd laplacian, used to eliminate weak features
* **lineThresholdProjected** another threshold for laplacian to eliminate edges
* **lineThresholdBinarized** another threshold for the feature scale to eliminate edges
* **suppressNonmaxSize** linear size of a pixel neighborhood for non-maxima suppression
:type params: :class:`CvStarDetectorParams`
The function GetStarKeypoints extracts keypoints that are local
scale-space extremas. The scale-space is constructed by computing
approximate values of laplacians with different sigma's at each
pixel. Instead of using pyramids, a popular approach to save computing
time, all of the laplacians are computed at each pixel of the original
high-resolution image. But each approximate laplacian value is computed
in O(1) time regardless of the sigma, thanks to the use of integral
images. The algorithm is based on the paper
Agrawal08
, but instead
of a square, hexagon or octagon it uses an 8-end star shape, hence the name,
consisting of overlapping upright and tilted squares.
Each keypoint is represented by a tuple
``((x, y), size, response)``
:
* **x, y** Screen coordinates of the keypoint
* **size** feature size, up to ``maxSize``
* **response** approximated laplacian value for the keypoint

View File

@ -0,0 +1,38 @@
*************************************
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

View File

@ -0,0 +1,679 @@
Reading and Writing Images and Video
====================================
.. highlight:: python
.. index:: LoadImage
.. _LoadImage:
LoadImage
---------
.. function:: LoadImage(filename, iscolor=CV_LOAD_IMAGE_COLOR)->None
Loads an image from a file as an IplImage.
:param filename: Name of file to be loaded.
:type filename: str
:param iscolor: Specific color type of the loaded image:
* **CV_LOAD_IMAGE_COLOR** the loaded image is forced to be a 3-channel color image
* **CV_LOAD_IMAGE_GRAYSCALE** the loaded image is forced to be grayscale
* **CV_LOAD_IMAGE_UNCHANGED** the loaded image will be loaded as is.
:type iscolor: int
The function
``cvLoadImage``
loads an image from the specified file and returns the pointer to the loaded image. Currently the following file formats are supported:
*
Windows bitmaps - BMP, DIB
*
JPEG files - JPEG, JPG, JPE
*
Portable Network Graphics - PNG
*
Portable image format - PBM, PGM, PPM
*
Sun rasters - SR, RAS
*
TIFF files - TIFF, TIF
Note that in the current implementation the alpha channel, if any, is stripped from the output image, e.g. 4-channel RGBA image will be loaded as RGB.
.. index:: LoadImageM
.. _LoadImageM:
LoadImageM
----------
.. function:: LoadImageM(filename, iscolor=CV_LOAD_IMAGE_COLOR)->None
Loads an image from a file as a CvMat.
:param filename: Name of file to be loaded.
:type filename: str
:param iscolor: Specific color type of the loaded image:
* **CV_LOAD_IMAGE_COLOR** the loaded image is forced to be a 3-channel color image
* **CV_LOAD_IMAGE_GRAYSCALE** the loaded image is forced to be grayscale
* **CV_LOAD_IMAGE_UNCHANGED** the loaded image will be loaded as is.
:type iscolor: int
The function
``cvLoadImageM``
loads an image from the specified file and returns the pointer to the loaded image.
urrently the following file formats are supported:
*
Windows bitmaps - BMP, DIB
*
JPEG files - JPEG, JPG, JPE
*
Portable Network Graphics - PNG
*
Portable image format - PBM, PGM, PPM
*
Sun rasters - SR, RAS
*
TIFF files - TIFF, TIF
Note that in the current implementation the alpha channel, if any, is stripped from the output image, e.g. 4-channel RGBA image will be loaded as RGB.
.. index:: SaveImage
.. _SaveImage:
SaveImage
---------
.. function:: SaveImage(filename,image)-> None
Saves an image to a specified file.
:param filename: Name of the file.
:type filename: str
:param image: Image to be saved.
:type image: :class:`CvArr`
The function
``cvSaveImage``
saves the image to the specified file. The image format is chosen based on the
``filename``
extension, see
:ref:`LoadImage`
. Only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use
``cvCvtScale``
and
``cvCvtColor``
to convert it before saving, or use universal
``cvSave``
to save the image to XML or YAML format.
.. index:: CvCapture
.. _CvCapture:
CvCapture
---------
.. class:: CvCapture
Video capturing structure.
The structure
``CvCapture``
does not have a public interface and is used only as a parameter for video capturing functions.
.. index:: CaptureFromCAM
.. _CaptureFromCAM:
CaptureFromCAM
--------------
.. function:: CaptureFromCAM(index) -> CvCapture
Initializes capturing a video from a camera.
:param index: Index of the camera to be used. If there is only one camera or it does not matter what camera is used -1 may be passed.
:type index: int
The function
``cvCaptureFromCAM``
allocates and initializes the CvCapture structure for reading a video stream from the camera. Currently two camera interfaces can be used on Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL); and two on Linux: V4L and FireWire (IEEE1394).
To release the structure, use
:ref:`ReleaseCapture`
.
.. index:: CaptureFromFile
.. _CaptureFromFile:
CaptureFromFile
---------------
.. function:: CaptureFromFile(filename) -> CvCapture
Initializes capturing a video from a file.
:param filename: Name of the video file.
:type filename: str
The function
``cvCaptureFromFile``
allocates and initializes the CvCapture structure for reading the video stream from the specified file. Which codecs and file formats are supported depends on the back end library. On Windows HighGui uses Video for Windows (VfW), on Linux ffmpeg is used and on Mac OS X the back end is QuickTime. See VideoCodecs for some discussion on what to expect and how to prepare your video files.
After the allocated structure is not used any more it should be released by the
:ref:`ReleaseCapture`
function.
.. index:: GetCaptureProperty
.. _GetCaptureProperty:
GetCaptureProperty
------------------
.. function:: GetCaptureProperty(capture, property_id)->double
Gets video capturing properties.
:param capture: video capturing structure.
:type capture: :class:`CvCapture`
:param property_id: Property identifier. Can be one of the following:
:type property_id: int
* **CV_CAP_PROP_POS_MSEC** Film current position in milliseconds or video capture timestamp
* **CV_CAP_PROP_POS_FRAMES** 0-based index of the frame to be decoded/captured next
* **CV_CAP_PROP_POS_AVI_RATIO** Relative position of the video file (0 - start of the film, 1 - end of the film)
* **CV_CAP_PROP_FRAME_WIDTH** Width of the frames in the video stream
* **CV_CAP_PROP_FRAME_HEIGHT** Height of the frames in the video stream
* **CV_CAP_PROP_FPS** Frame rate
* **CV_CAP_PROP_FOURCC** 4-character code of codec
* **CV_CAP_PROP_FRAME_COUNT** Number of frames in the video file
* **CV_CAP_PROP_FORMAT** The format of the Mat objects returned by retrieve()
* **CV_CAP_PROP_MODE** A backend-specific value indicating the current capture mode
* **CV_CAP_PROP_BRIGHTNESS** Brightness of the image (only for cameras)
* **CV_CAP_PROP_CONTRAST** Contrast of the image (only for cameras)
* **CV_CAP_PROP_SATURATION** Saturation of the image (only for cameras)
* **CV_CAP_PROP_HUE** Hue of the image (only for cameras)
* **CV_CAP_PROP_GAIN** Gain of the image (only for cameras)
* **CV_CAP_PROP_EXPOSURE** Exposure (only for cameras)
* **CV_CAP_PROP_CONVERT_RGB** Boolean flags indicating whether images should be converted to RGB
* **CV_CAP_PROP_WHITE_BALANCE** Currently unsupported
* **CV_CAP_PROP_RECTIFICATION** TOWRITE (note: only supported by DC1394 v 2.x backend currently)
The function
``cvGetCaptureProperty``
retrieves the specified property of the camera or video file.
.. index:: GrabFrame
.. _GrabFrame:
GrabFrame
---------
.. function:: GrabFrame(capture) -> int
Grabs the frame from a camera or file.
:param capture: video capturing structure.
:type capture: :class:`CvCapture`
The function
``cvGrabFrame``
grabs the frame from a camera or file. The grabbed frame is stored internally. The purpose of this function is to grab the frame
*quickly*
so that syncronization can occur if it has to read from several cameras simultaneously. The grabbed frames are not exposed because they may be stored in a compressed format (as defined by the camera/driver). To retrieve the grabbed frame,
:ref:`RetrieveFrame`
should be used.
.. index:: QueryFrame
.. _QueryFrame:
QueryFrame
----------
.. function:: QueryFrame(capture) -> iplimage
Grabs and returns a frame from a camera or file.
:param capture: video capturing structure.
:type capture: :class:`CvCapture`
The function
``cvQueryFrame``
grabs a frame from a camera or video file, decompresses it and returns it. This function is just a combination of
:ref:`GrabFrame`
and
:ref:`RetrieveFrame`
, but in one call. The returned image should not be released or modified by the user. In the event of an error, the return value may be NULL.
.. index:: RetrieveFrame
.. _RetrieveFrame:
RetrieveFrame
-------------
.. function:: RetrieveFrame(capture) -> iplimage
Gets the image grabbed with cvGrabFrame.
:param capture: video capturing structure.
:type capture: :class:`CvCapture`
The function
``cvRetrieveFrame``
returns the pointer to the image grabbed with the
:ref:`GrabFrame`
function. The returned image should not be released or modified by the user. In the event of an error, the return value may be NULL.
.. index:: SetCaptureProperty
.. _SetCaptureProperty:
SetCaptureProperty
------------------
.. function:: SetCaptureProperty(capture, property_id,value)->None
Sets video capturing properties.
:param capture: video capturing structure.
:type capture: :class:`CvCapture`
:param property_id: property identifier. Can be one of the following:
:type property_id: int
* **CV_CAP_PROP_POS_MSEC** Film current position in milliseconds or video capture timestamp
* **CV_CAP_PROP_POS_FRAMES** 0-based index of the frame to be decoded/captured next
* **CV_CAP_PROP_POS_AVI_RATIO** Relative position of the video file (0 - start of the film, 1 - end of the film)
* **CV_CAP_PROP_FRAME_WIDTH** Width of the frames in the video stream
* **CV_CAP_PROP_FRAME_HEIGHT** Height of the frames in the video stream
* **CV_CAP_PROP_FPS** Frame rate
* **CV_CAP_PROP_FOURCC** 4-character code of codec
* **CV_CAP_PROP_FRAME_COUNT** Number of frames in the video file
* **CV_CAP_PROP_FORMAT** The format of the Mat objects returned by retrieve()
* **CV_CAP_PROP_MODE** A backend-specific value indicating the current capture mode
* **CV_CAP_PROP_BRIGHTNESS** Brightness of the image (only for cameras)
* **CV_CAP_PROP_CONTRAST** Contrast of the image (only for cameras)
* **CV_CAP_PROP_SATURATION** Saturation of the image (only for cameras)
* **CV_CAP_PROP_HUE** Hue of the image (only for cameras)
* **CV_CAP_PROP_GAIN** Gain of the image (only for cameras)
* **CV_CAP_PROP_EXPOSURE** Exposure (only for cameras)
* **CV_CAP_PROP_CONVERT_RGB** Boolean flags indicating whether images should be converted to RGB
* **CV_CAP_PROP_WHITE_BALANCE** Currently unsupported
* **CV_CAP_PROP_RECTIFICATION** TOWRITE (note: only supported by DC1394 v 2.x backend currently)
:param value: value of the property.
:type value: float
The function
``cvSetCaptureProperty``
sets the specified property of video capturing. Currently the function supports only video files:
``CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO``
.
NB This function currently does nothing when using the latest CVS download on linux with FFMPEG (the function contents are hidden if 0 is used and returned).
.. index:: CreateVideoWriter
.. _CreateVideoWriter:
CreateVideoWriter
-----------------
.. function:: CreateVideoWriter(filename, fourcc, fps, frame_size, is_color) -> CvVideoWriter
Creates the video file writer.
:param filename: Name of the output video file.
:type filename: str
:param fourcc: 4-character code of codec used to compress the frames. For example, ``CV_FOURCC('P','I','M,'1')`` is a MPEG-1 codec, ``CV_FOURCC('M','J','P','G')`` is a motion-jpeg codec etc.
Under Win32 it is possible to pass -1 in order to choose compression method and additional compression parameters from dialog. Under Win32 if 0 is passed while using an avi filename it will create a video writer that creates an uncompressed avi file.
:type fourcc: int
:param fps: Framerate of the created video stream.
:type fps: float
:param frame_size: Size of the video frames.
:type frame_size: :class:`CvSize`
:param is_color: If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).
:type is_color: int
The function
``cvCreateVideoWriter``
creates the video writer structure.
Which codecs and file formats are supported depends on the back end library. On Windows HighGui uses Video for Windows (VfW), on Linux ffmpeg is used and on Mac OS X the back end is QuickTime. See VideoCodecs for some discussion on what to expect.
.. index:: WriteFrame
.. _WriteFrame:
WriteFrame
----------
.. function:: WriteFrame(writer, image)->int
Writes a frame to a video file.
:param writer: Video writer structure
:type writer: :class:`CvVideoWriter`
:param image: The written frame
:type image: :class:`IplImage`
The function
``cvWriteFrame``
writes/appends one frame to a video file.

View File

@ -0,0 +1,576 @@
User Interface
==============
.. highlight:: python
.. index:: CreateTrackbar
.. _CreateTrackbar:
CreateTrackbar
--------------
.. function:: CreateTrackbar(trackbarName, windowName, value, count, onChange) -> None
Creates a trackbar and attaches it to the specified window
:param trackbarName: Name of the created trackbar.
:type trackbarName: str
:param windowName: Name of the window which will be used as a parent for created trackbar.
:type windowName: str
:param value: Initial value for the slider position, between 0 and ``count`` .
:type value: int
:param count: Maximal position of the slider. Minimal position is always 0.
:type count: int
:param onChange:
OpenCV calls ``onChange`` every time the slider changes position.
OpenCV will call it as ``func(x)`` where ``x`` is the new position of the slider.
:type onChange: :class:`PyCallableObject`
The function
``cvCreateTrackbar``
creates a trackbar (a.k.a. slider or range control) with the specified name and range, assigns a variable to be syncronized with trackbar position and specifies a callback function to be called on trackbar position change. The created trackbar is displayed on the top of the given window.
\
\
**[Qt Backend Only]**
qt-specific details:
* **windowName** Name of the window which will be used as a parent for created trackbar. Can be NULL if the trackbar should be attached to the control panel.
The created trackbar is displayed at the bottom of the given window if
*windowName*
is correctly provided, or displayed on the control panel if
*windowName*
is NULL.
By clicking on the label of each trackbar, it is possible to edit the trackbar's value manually for a more accurate control of it.
.. index:: DestroyAllWindows
.. _DestroyAllWindows:
DestroyAllWindows
-----------------
.. function:: DestroyAllWindows()-> None
Destroys all of the HighGUI windows.
The function
``cvDestroyAllWindows``
destroys all of the opened HighGUI windows.
.. index:: DestroyWindow
.. _DestroyWindow:
DestroyWindow
-------------
.. function:: DestroyWindow(name)-> None
Destroys a window.
:param name: Name of the window to be destroyed.
:type name: str
The function
``cvDestroyWindow``
destroys the window with the given name.
.. index:: GetTrackbarPos
.. _GetTrackbarPos:
GetTrackbarPos
--------------
.. function:: GetTrackbarPos(trackbarName,windowName)-> None
Returns the trackbar position.
:param trackbarName: Name of the trackbar.
:type trackbarName: str
:param windowName: Name of the window which is the parent of the trackbar.
:type windowName: str
The function
``cvGetTrackbarPos``
returns the current position of the specified trackbar.
\
\
**[Qt Backend Only]**
qt-specific details:
* **windowName** Name of the window which is the parent of the trackbar. Can be NULL if the trackbar is attached to the control panel.
.. index:: MoveWindow
.. _MoveWindow:
MoveWindow
----------
.. function:: MoveWindow(name,x,y)-> None
Sets the position of the window.
:param name: Name of the window to be moved.
:type name: str
:param x: New x coordinate of the top-left corner
:type x: int
:param y: New y coordinate of the top-left corner
:type y: int
The function
``cvMoveWindow``
changes the position of the window.
.. index:: NamedWindow
.. _NamedWindow:
NamedWindow
-----------
.. function:: NamedWindow(name,flags=CV_WINDOW_AUTOSIZE)-> None
Creates a window.
:param name: Name of the window in the window caption that may be used as a window identifier.
:type name: str
:param flags: Flags of the window. Currently the only supported flag is ``CV_WINDOW_AUTOSIZE`` . If this is set, window size is automatically adjusted to fit the displayed image (see :ref:`ShowImage` ), and the user can not change the window size manually.
:type flags: int
The function
``cvNamedWindow``
creates a window which can be used as a placeholder for images and trackbars. Created windows are referred to by their names.
If a window with the same name already exists, the function does nothing.
\
\
**[Qt Backend Only]**
qt-specific details:
* **flags** Flags of the window. Currently the supported flags are:
* **CV_WINDOW_NORMAL or CV_WINDOW_AUTOSIZE:** ``CV_WINDOW_NORMAL`` let the user resize the window, whereas ``CV_WINDOW_AUTOSIZE`` adjusts automatically the window's size to fit the displayed image (see :ref:`ShowImage` ), and the user can not change the window size manually.
* **CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO:** ``CV_WINDOW_FREERATIO`` adjust the image without respect the its ration, whereas ``CV_WINDOW_KEEPRATIO`` keep the image's ratio.
* **CV_GUI_NORMAL or CV_GUI_EXPANDED:** ``CV_GUI_NORMAL`` is the old way to draw the window without statusbar and toolbar, whereas ``CV_GUI_EXPANDED`` is the new enhance GUI.
This parameter is optional. The default flags set for a new window are ``CV_WINDOW_AUTOSIZE`` , ``CV_WINDOW_KEEPRATIO`` , and ``CV_GUI_EXPANDED`` .
However, if you want to modify the flags, you can combine them using OR operator, ie:
::
cvNamedWindow( ``myWindow'', ``CV_WINDOW_NORMAL`` textbar ``CV_GUI_NORMAL`` );
..
.. index:: ResizeWindow
.. _ResizeWindow:
ResizeWindow
------------
.. function:: ResizeWindow(name,width,height)-> None
Sets the window size.
:param name: Name of the window to be resized.
:type name: str
:param width: New width
:type width: int
:param height: New height
:type height: int
The function
``cvResizeWindow``
changes the size of the window.
.. index:: SetMouseCallback
.. _SetMouseCallback:
SetMouseCallback
----------------
.. function:: SetMouseCallback(windowName, onMouse, param) -> None
Assigns callback for mouse events.
:param windowName: Name of the window.
:type windowName: str
:param onMouse: Callable to be called every time a mouse event occurs in the specified window. This callable should have signature `` Foo(event, x, y, flags, param)-> None ``
where ``event`` is one of ``CV_EVENT_*`` , ``x`` and ``y`` are the coordinates of the mouse pointer in image coordinates (not window coordinates), ``flags`` is a combination of ``CV_EVENT_FLAG_*`` , and ``param`` is a user-defined parameter passed to the ``cvSetMouseCallback`` function call.
:type onMouse: :class:`PyCallableObject`
:param param: User-defined parameter to be passed to the callback function.
:type param: object
The function
``cvSetMouseCallback``
sets the callback function for mouse events occuring within the specified window.
The
``event``
parameter is one of:
* **CV_EVENT_MOUSEMOVE** Mouse movement
* **CV_EVENT_LBUTTONDOWN** Left button down
* **CV_EVENT_RBUTTONDOWN** Right button down
* **CV_EVENT_MBUTTONDOWN** Middle button down
* **CV_EVENT_LBUTTONUP** Left button up
* **CV_EVENT_RBUTTONUP** Right button up
* **CV_EVENT_MBUTTONUP** Middle button up
* **CV_EVENT_LBUTTONDBLCLK** Left button double click
* **CV_EVENT_RBUTTONDBLCLK** Right button double click
* **CV_EVENT_MBUTTONDBLCLK** Middle button double click
The
``flags``
parameter is a combination of :
* **CV_EVENT_FLAG_LBUTTON** Left button pressed
* **CV_EVENT_FLAG_RBUTTON** Right button pressed
* **CV_EVENT_FLAG_MBUTTON** Middle button pressed
* **CV_EVENT_FLAG_CTRLKEY** Control key pressed
* **CV_EVENT_FLAG_SHIFTKEY** Shift key pressed
* **CV_EVENT_FLAG_ALTKEY** Alt key pressed
.. index:: SetTrackbarPos
.. _SetTrackbarPos:
SetTrackbarPos
--------------
.. function:: SetTrackbarPos(trackbarName,windowName,pos)-> None
Sets the trackbar position.
:param trackbarName: Name of the trackbar.
:type trackbarName: str
:param windowName: Name of the window which is the parent of trackbar.
:type windowName: str
:param pos: New position.
:type pos: int
The function
``cvSetTrackbarPos``
sets the position of the specified trackbar.
\
\
**[Qt Backend Only]**
qt-specific details:
* **windowName** Name of the window which is the parent of trackbar. Can be NULL if the trackbar is attached to the control panel.
.. index:: ShowImage
.. _ShowImage:
ShowImage
---------
.. function:: ShowImage(name,image)-> None
Displays the image in the specified window
:param name: Name of the window.
:type name: str
:param image: Image to be shown.
:type image: :class:`CvArr`
The function
``cvShowImage``
displays the image in the specified window. If the window was created with the
``CV_WINDOW_AUTOSIZE``
flag then the image is shown with its original size, otherwise the image is scaled to fit in the window. The function may scale the image, depending on its depth:
*
If the image is 8-bit unsigned, it is displayed as is.
*
If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].
*
If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].
.. index:: WaitKey
.. _WaitKey:
WaitKey
-------
.. function:: WaitKey(delay=0)-> int
Waits for a pressed key.
:param delay: Delay in milliseconds.
:type delay: int
The function
``cvWaitKey``
waits for key event infinitely (
:math:`\texttt{delay} <= 0`
) or for
``delay``
milliseconds. Returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed.
**Note:**
This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing, unless HighGUI is used within some environment that takes care of event processing.
\
\
**[Qt Backend Only]**
qt-specific details:
With this current Qt implementation, this is the only way to process event such as repaint for the windows, and so on
ldots

View File

@ -0,0 +1,18 @@
*************************
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

View File

@ -0,0 +1,628 @@
Feature Detection
=================
.. highlight:: python
.. index:: Canny
.. _Canny:
Canny
-----
.. function:: Canny(image,edges,threshold1,threshold2,aperture_size=3)-> None
Implements the Canny algorithm for edge detection.
:param image: Single-channel input image
:type image: :class:`CvArr`
:param edges: Single-channel image to store the edges found by the function
:type edges: :class:`CvArr`
:param threshold1: The first threshold
:type threshold1: float
:param threshold2: The second threshold
:type threshold2: float
:param aperture_size: Aperture parameter for the Sobel operator (see :ref:`Sobel` )
:type aperture_size: int
The function finds the edges on the input image
``image``
and marks them in the output image
``edges``
using the Canny algorithm. The smallest value between
``threshold1``
and
``threshold2``
is used for edge linking, the largest value is used to find the initial segments of strong edges.
.. index:: CornerEigenValsAndVecs
.. _CornerEigenValsAndVecs:
CornerEigenValsAndVecs
----------------------
.. function:: CornerEigenValsAndVecs(image,eigenvv,blockSize,aperture_size=3)-> None
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
:param image: Input image
:type image: :class:`CvArr`
:param eigenvv: Image to store the results. It must be 6 times wider than the input image
:type eigenvv: :class:`CvArr`
:param blockSize: Neighborhood size (see discussion)
:type blockSize: int
:param aperture_size: Aperture parameter for the Sobel operator (see :ref:`Sobel` )
:type aperture_size: int
For every pixel, the function
``cvCornerEigenValsAndVecs``
considers a
:math:`\texttt{blockSize} \times \texttt{blockSize}`
neigborhood S(p). It calcualtes the covariation matrix of derivatives over the neigborhood as:
.. math::
M = \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 & \sum _{S(p)}(dI/dx \cdot dI/dy)^2 \\ \sum _{S(p)}(dI/dx \cdot dI/dy)^2 & \sum _{S(p)}(dI/dy)^2 \end{bmatrix}
After that it finds eigenvectors and eigenvalues of the matrix and stores them into destination image in form
:math:`(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)`
where
* :math:`\lambda_1, \lambda_2`
are the eigenvalues of
:math:`M`
; not sorted
* :math:`x_1, y_1`
are the eigenvectors corresponding to
:math:`\lambda_1`
* :math:`x_2, y_2`
are the eigenvectors corresponding to
:math:`\lambda_2`
.. index:: CornerHarris
.. _CornerHarris:
CornerHarris
------------
.. function:: CornerHarris(image,harris_dst,blockSize,aperture_size=3,k=0.04)-> None
Harris edge detector.
:param image: Input image
:type image: :class:`CvArr`
:param harris_dst: Image to store the Harris detector responses. Should have the same size as ``image``
:type harris_dst: :class:`CvArr`
:param blockSize: Neighborhood size (see the discussion of :ref:`CornerEigenValsAndVecs` )
:type blockSize: int
:param aperture_size: Aperture parameter for the Sobel operator (see :ref:`Sobel` ).
:type aperture_size: int
:param k: Harris detector free parameter. See the formula below
:type k: float
The function runs the Harris edge detector on the image. Similarly to
:ref:`CornerMinEigenVal`
and
:ref:`CornerEigenValsAndVecs`
, for each pixel it calculates a
:math:`2\times2`
gradient covariation matrix
:math:`M`
over a
:math:`\texttt{blockSize} \times \texttt{blockSize}`
neighborhood. Then, it stores
.. math::
det(M) - k \, trace(M)^2
to the destination image. Corners in the image can be found as the local maxima of the destination image.
.. index:: CornerMinEigenVal
.. _CornerMinEigenVal:
CornerMinEigenVal
-----------------
.. function:: CornerMinEigenVal(image,eigenval,blockSize,aperture_size=3)-> None
Calculates the minimal eigenvalue of gradient matrices for corner detection.
:param image: Input image
:type image: :class:`CvArr`
:param eigenval: Image to store the minimal eigenvalues. Should have the same size as ``image``
:type eigenval: :class:`CvArr`
:param blockSize: Neighborhood size (see the discussion of :ref:`CornerEigenValsAndVecs` )
:type blockSize: int
:param aperture_size: Aperture parameter for the Sobel operator (see :ref:`Sobel` ).
:type aperture_size: int
The function is similar to
:ref:`CornerEigenValsAndVecs`
but it calculates and stores only the minimal eigen value of derivative covariation matrix for every pixel, i.e.
:math:`min(\lambda_1, \lambda_2)`
in terms of the previous function.
.. index:: FindCornerSubPix
.. _FindCornerSubPix:
FindCornerSubPix
----------------
.. function:: FindCornerSubPix(image,corners,win,zero_zone,criteria)-> corners
Refines the corner locations.
:param image: Input image
:type image: :class:`CvArr`
:param corners: Initial coordinates of the input corners as a list of (x, y) pairs
:type corners: sequence of (float, float)
:param win: Half of the side length of the search window. For example, if ``win`` =(5,5), then a :math:`5*2+1 \times 5*2+1 = 11 \times 11` search window would be used
:type win: :class:`CvSize`
:param zero_zone: Half of the size of the dead region in the middle of the search zone over which the summation in the formula below is not done. It is used sometimes to avoid possible singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such size
:type zero_zone: :class:`CvSize`
:param criteria: Criteria for termination of the iterative process of corner refinement. That is, the process of corner position refinement stops either after a certain number of iterations or when a required accuracy is achieved. The ``criteria`` may specify either of or both the maximum number of iteration and the required accuracy
:type criteria: :class:`CvTermCriteria`
The function iterates to find the sub-pixel accurate location of corners, or radial saddle points, as shown in on the picture below.
It returns the refined coordinates as a list of (x, y) pairs.
Sub-pixel accurate corner locator is based on the observation that every vector from the center
:math:`q`
to a point
:math:`p`
located within a neighborhood of
:math:`q`
is orthogonal to the image gradient at
:math:`p`
subject to image and measurement noise. Consider the expression:
.. math::
\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)
where
:math:`{DI_{p_i}}`
is the image gradient at the one of the points
:math:`p_i`
in a neighborhood of
:math:`q`
. The value of
:math:`q`
is to be found such that
:math:`\epsilon_i`
is minimized. A system of equations may be set up with
:math:`\epsilon_i`
set to zero:
.. math::
\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) q = \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)
where the gradients are summed within a neighborhood ("search window") of
:math:`q`
. Calling the first gradient term
:math:`G`
and the second gradient term
:math:`b`
gives:
.. math::
q = G^{-1} \cdot b
The algorithm sets the center of the neighborhood window at this new center
:math:`q`
and then iterates until the center keeps within a set threshold.
.. index:: GoodFeaturesToTrack
.. _GoodFeaturesToTrack:
GoodFeaturesToTrack
-------------------
.. function:: GoodFeaturesToTrack(image,eigImage,tempImage,cornerCount,qualityLevel,minDistance,mask=NULL,blockSize=3,useHarris=0,k=0.04)-> corners
Determines strong corners on an image.
:param image: The source 8-bit or floating-point 32-bit, single-channel image
:type image: :class:`CvArr`
:param eigImage: Temporary floating-point 32-bit image, the same size as ``image``
:type eigImage: :class:`CvArr`
:param tempImage: Another temporary image, the same size and format as ``eigImage``
:type tempImage: :class:`CvArr`
:param cornerCount: number of corners to detect
:type cornerCount: int
:param qualityLevel: Multiplier for the max/min eigenvalue; specifies the minimal accepted quality of image corners
:type qualityLevel: float
:param minDistance: Limit, specifying the minimum possible distance between the returned corners; Euclidian distance is used
:type minDistance: float
:param mask: Region of interest. The function selects points either in the specified region or in the whole image if the mask is NULL
:type mask: :class:`CvArr`
:param blockSize: Size of the averaging block, passed to the underlying :ref:`CornerMinEigenVal` or :ref:`CornerHarris` used by the function
:type blockSize: int
:param useHarris: If nonzero, Harris operator ( :ref:`CornerHarris` ) is used instead of default :ref:`CornerMinEigenVal`
:type useHarris: int
:param k: Free parameter of Harris detector; used only if ( :math:`\texttt{useHarris} != 0` )
:type k: float
The function finds the corners with big eigenvalues in the image. The function first calculates the minimal
eigenvalue for every source image pixel using the
:ref:`CornerMinEigenVal`
function and stores them in
``eigImage``
. Then it performs
non-maxima suppression (only the local maxima in
:math:`3\times 3`
neighborhood
are retained). The next step rejects the corners with the minimal
eigenvalue less than
:math:`\texttt{qualityLevel} \cdot max(\texttt{eigImage}(x,y))`
.
Finally, the function ensures that the distance between any two corners is not smaller than
``minDistance``
. The weaker corners (with a smaller min eigenvalue) that are too close to the stronger corners are rejected.
Note that the if the function is called with different values
``A``
and
``B``
of the parameter
``qualityLevel``
, and
``A``
> {B}, the array of returned corners with
``qualityLevel=A``
will be the prefix of the output corners array with
``qualityLevel=B``
.
.. index:: HoughLines2
.. _HoughLines2:
HoughLines2
-----------
.. function:: HoughLines2(image,storage,method,rho,theta,threshold,param1=0,param2=0)-> lines
Finds lines in a binary image using a Hough transform.
:param image: The 8-bit, single-channel, binary source image. In the case of a probabilistic method, the image is modified by the function
:type image: :class:`CvArr`
:param storage: The storage for the lines that are detected. It can
be a memory storage (in this case a sequence of lines is created in
the storage and returned by the function) or single row/single column
matrix (CvMat*) of a particular type (see below) to which the lines'
parameters are written. The matrix header is modified by the function
so its ``cols`` or ``rows`` will contain the number of lines
detected. If ``storage`` is a matrix and the actual number
of lines exceeds the matrix size, the maximum possible number of lines
is returned (in the case of standard hough transform the lines are sorted
by the accumulator value)
:type storage: :class:`CvMemStorage`
:param method: The Hough transform variant, one of the following:
* **CV_HOUGH_STANDARD** classical or standard Hough transform. Every line is represented by two floating-point numbers :math:`(\rho, \theta)` , where :math:`\rho` is a distance between (0,0) point and the line, and :math:`\theta` is the angle between x-axis and the normal to the line. Thus, the matrix must be (the created sequence will be) of ``CV_32FC2`` type
* **CV_HOUGH_PROBABILISTIC** probabilistic Hough transform (more efficient in case if picture contains a few long linear segments). It returns line segments rather than the whole line. Each segment is represented by starting and ending points, and the matrix must be (the created sequence will be) of ``CV_32SC4`` type
* **CV_HOUGH_MULTI_SCALE** multi-scale variant of the classical Hough transform. The lines are encoded the same way as ``CV_HOUGH_STANDARD``
:type method: int
:param rho: Distance resolution in pixel-related units
:type rho: float
:param theta: Angle resolution measured in radians
:type theta: float
:param threshold: Threshold parameter. A line is returned by the function if the corresponding accumulator value is greater than ``threshold``
:type threshold: int
:param param1: The first method-dependent parameter:
* For the classical Hough transform it is not used (0).
* For the probabilistic Hough transform it is the minimum line length.
* For the multi-scale Hough transform it is the divisor for the distance resolution :math:`\rho` . (The coarse distance resolution will be :math:`\rho` and the accurate resolution will be :math:`(\rho / \texttt{param1})` ).
:type param1: float
:param param2: The second method-dependent parameter:
* For the classical Hough transform it is not used (0).
* For the probabilistic Hough transform it is the maximum gap between line segments lying on the same line to treat them as a single line segment (i.e. to join them).
* For the multi-scale Hough transform it is the divisor for the angle resolution :math:`\theta` . (The coarse angle resolution will be :math:`\theta` and the accurate resolution will be :math:`(\theta / \texttt{param2})` ).
:type param2: float
The function implements a few variants of the Hough transform for line detection.
.. index:: PreCornerDetect
.. _PreCornerDetect:
PreCornerDetect
---------------
.. function:: PreCornerDetect(image,corners,apertureSize=3)-> None
Calculates the feature map for corner detection.
:param image: Input image
:type image: :class:`CvArr`
:param corners: Image to store the corner candidates
:type corners: :class:`CvArr`
:param apertureSize: Aperture parameter for the Sobel operator (see :ref:`Sobel` )
:type apertureSize: int
The function calculates the function
.. math::
D_x^2 D_{yy} + D_y^2 D_{xx} - 2 D_x D_y D_{xy}
where
:math:`D_?`
denotes one of the first image derivatives and
:math:`D_{??}`
denotes a second image derivative.
The corners can be found as local maximums of the function below:
.. include:: ../../python_fragments/precornerdetect.py
:literal:

View File

@ -0,0 +1,748 @@
Geometric Image Transformations
===============================
.. highlight:: python
The functions in this section perform various geometrical transformations of 2D images. That is, they do not change the image content, but deform the pixel grid, and map this deformed grid to the destination image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel
:math:`(x, y)`
of the destination image, the functions compute coordinates of the corresponding "donor" pixel in the source image and copy the pixel value, that is:
.. math::
\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))
In the case when the user specifies the forward mapping:
:math:`\left<g_x, g_y\right>: \texttt{src} \rightarrow \texttt{dst}`
, the OpenCV functions first compute the corresponding inverse mapping:
:math:`\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}`
and then use the above formula.
The actual implementations of the geometrical transformations, from the most generic
:ref:`Remap`
and to the simplest and the fastest
:ref:`Resize`
, need to solve the 2 main problems with the above formula:
#.
extrapolation of non-existing pixels. Similarly to the filtering functions, described in the previous section, for some
:math:`(x,y)`
one of
:math:`f_x(x,y)`
or
:math:`f_y(x,y)`
, or they both, may fall outside of the image, in which case some extrapolation method needs to be used. OpenCV provides the same selection of the extrapolation methods as in the filtering functions, but also an additional method
``BORDER_TRANSPARENT``
, which means that the corresponding pixels in the destination image will not be modified at all.
#.
interpolation of pixel values. Usually
:math:`f_x(x,y)`
and
:math:`f_y(x,y)`
are floating-point numbers (i.e.
:math:`\left<f_x, f_y\right>`
can be an affine or perspective transformation, or radial lens distortion correction etc.), so a pixel values at fractional coordinates needs to be retrieved. In the simplest case the coordinates can be just rounded to the nearest integer coordinates and the corresponding pixel used, which is called nearest-neighbor interpolation. However, a better result can be achieved by using more sophisticated
`interpolation methods <http://en.wikipedia.org/wiki/Multivariate_interpolation>`_
, where a polynomial function is fit into some neighborhood of the computed pixel
:math:`(f_x(x,y), f_y(x,y))`
and then the value of the polynomial at
:math:`(f_x(x,y), f_y(x,y))`
is taken as the interpolated pixel value. In OpenCV you can choose between several interpolation methods, see
:ref:`Resize`
.
.. index:: GetRotationMatrix2D
.. _GetRotationMatrix2D:
GetRotationMatrix2D
-------------------
.. function:: GetRotationMatrix2D(center,angle,scale,mapMatrix)-> None
Calculates the affine matrix of 2d rotation.
:param center: Center of the rotation in the source image
:type center: :class:`CvPoint2D32f`
:param angle: The rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner)
:type angle: float
:param scale: Isotropic scale factor
:type scale: float
:param mapMatrix: Pointer to the destination :math:`2\times 3` matrix
:type mapMatrix: :class:`CvMat`
The function
``cv2DRotationMatrix``
calculates the following matrix:
.. math::
\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} - (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}
where
.. math::
\alpha = \texttt{scale} \cdot cos( \texttt{angle} ), \beta = \texttt{scale} \cdot sin( \texttt{angle} )
The transformation maps the rotation center to itself. If this is not the purpose, the shift should be adjusted.
.. index:: GetAffineTransform
.. _GetAffineTransform:
GetAffineTransform
------------------
.. function:: GetAffineTransform(src,dst,mapMatrix)-> None
Calculates the affine transform from 3 corresponding points.
:param src: Coordinates of 3 triangle vertices in the source image
:type src: :class:`CvPoint2D32f`
:param dst: Coordinates of the 3 corresponding triangle vertices in the destination image
:type dst: :class:`CvPoint2D32f`
:param mapMatrix: Pointer to the destination :math:`2 \times 3` matrix
:type mapMatrix: :class:`CvMat`
The function cvGetAffineTransform calculates the matrix of an affine transform such that:
.. math::
\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}
where
.. math::
dst(i)=(x'_i,y'_i),
src(i)=(x_i, y_i),
i=0,1,2
.. index:: GetPerspectiveTransform
.. _GetPerspectiveTransform:
GetPerspectiveTransform
-----------------------
.. function:: GetPerspectiveTransform(src,dst,mapMatrix)-> None
Calculates the perspective transform from 4 corresponding points.
:param src: Coordinates of 4 quadrangle vertices in the source image
:type src: :class:`CvPoint2D32f`
:param dst: Coordinates of the 4 corresponding quadrangle vertices in the destination image
:type dst: :class:`CvPoint2D32f`
:param mapMatrix: Pointer to the destination :math:`3\times 3` matrix
:type mapMatrix: :class:`CvMat`
The function
``cvGetPerspectiveTransform``
calculates a matrix of perspective transforms such that:
.. math::
\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}
where
.. math::
dst(i)=(x'_i,y'_i),
src(i)=(x_i, y_i),
i=0,1,2,3
.. index:: GetQuadrangleSubPix
.. _GetQuadrangleSubPix:
GetQuadrangleSubPix
-------------------
.. function:: GetQuadrangleSubPix(src,dst,mapMatrix)-> None
Retrieves the pixel quadrangle from an image with sub-pixel accuracy.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Extracted quadrangle
:type dst: :class:`CvArr`
:param mapMatrix: The transformation :math:`2 \times 3` matrix :math:`[A|b]` (see the discussion)
:type mapMatrix: :class:`CvMat`
The function
``cvGetQuadrangleSubPix``
extracts pixels from
``src``
at sub-pixel accuracy and stores them to
``dst``
as follows:
.. math::
dst(x, y)= src( A_{11} x' + A_{12} y' + b_1, A_{21} x' + A_{22} y' + b_2)
where
.. math::
x'=x- \frac{(width(dst)-1)}{2} ,
y'=y- \frac{(height(dst)-1)}{2}
and
.. math::
\texttt{mapMatrix} = \begin{bmatrix} A_{11} & A_{12} & b_1 \\ A_{21} & A_{22} & b_2 \end{bmatrix}
The values of pixels at non-integer coordinates are retrieved using bilinear interpolation. When the function needs pixels outside of the image, it uses replication border mode to reconstruct the values. Every channel of multiple-channel images is processed independently.
.. index:: GetRectSubPix
.. _GetRectSubPix:
GetRectSubPix
-------------
.. function:: GetRectSubPix(src,dst,center)-> None
Retrieves the pixel rectangle from an image with sub-pixel accuracy.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Extracted rectangle
:type dst: :class:`CvArr`
:param center: Floating point coordinates of the extracted rectangle center within the source image. The center must be inside the image
:type center: :class:`CvPoint2D32f`
The function
``cvGetRectSubPix``
extracts pixels from
``src``
:
.. math::
dst(x, y) = src(x + \texttt{center.x} - (width( \texttt{dst} )-1)*0.5, y + \texttt{center.y} - (height( \texttt{dst} )-1)*0.5)
where the values of the pixels at non-integer coordinates are retrieved
using bilinear interpolation. Every channel of multiple-channel
images is processed independently. While the rectangle center
must be inside the image, parts of the rectangle may be
outside. In this case, the replication border mode is used to get
pixel values beyond the image boundaries.
.. index:: LogPolar
.. _LogPolar:
LogPolar
--------
.. function:: LogPolar(src,dst,center,M,flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS)-> None
Remaps an image to log-polar space.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param center: The transformation center; where the output precision is maximal
:type center: :class:`CvPoint2D32f`
:param M: Magnitude scale parameter. See below
:type M: float
:param flags: A combination of interpolation methods and the following optional flags:
* **CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero
* **CV_WARP_INVERSE_MAP** See below
:type flags: int
The function
``cvLogPolar``
transforms the source image using the following transformation:
Forward transformation (
``CV_WARP_INVERSE_MAP``
is not set):
.. math::
dst( \phi , \rho ) = src(x,y)
Inverse transformation (
``CV_WARP_INVERSE_MAP``
is set):
.. math::
dst(x,y) = src( \phi , \rho )
where
.. math::
\rho = M \cdot \log{\sqrt{x^2 + y^2}} , \phi =atan(y/x)
The function emulates the human "foveal" vision and can be used for fast scale and rotation-invariant template matching, for object tracking and so forth.
The function can not operate in-place.
.. index:: Remap
.. _Remap:
Remap
-----
.. function:: Remap(src,dst,mapx,mapy,flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS,fillval=(0,0,0,0))-> None
Applies a generic geometrical transformation to the image.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param mapx: The map of x-coordinates (CV _ 32FC1 image)
:type mapx: :class:`CvArr`
:param mapy: The map of y-coordinates (CV _ 32FC1 image)
:type mapy: :class:`CvArr`
:param flags: A combination of interpolation method and the following optional flag(s):
* **CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to ``fillval``
:type flags: int
:param fillval: A value used to fill outliers
:type fillval: :class:`CvScalar`
The function
``cvRemap``
transforms the source image using the specified map:
.. math::
\texttt{dst} (x,y) = \texttt{src} ( \texttt{mapx} (x,y), \texttt{mapy} (x,y))
Similar to other geometrical transformations, some interpolation method (specified by user) is used to extract pixels with non-integer coordinates.
Note that the function can not operate in-place.
.. index:: Resize
.. _Resize:
Resize
------
.. function:: Resize(src,dst,interpolation=CV_INTER_LINEAR)-> None
Resizes an image.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param interpolation: Interpolation method:
* **CV_INTER_NN** nearest-neigbor interpolation
* **CV_INTER_LINEAR** bilinear interpolation (used by default)
* **CV_INTER_AREA** resampling using pixel area relation. It is the preferred method for image decimation that gives moire-free results. In terms of zooming it is similar to the ``CV_INTER_NN`` method
* **CV_INTER_CUBIC** bicubic interpolation
:type interpolation: int
The function
``cvResize``
resizes an image
``src``
so that it fits exactly into
``dst``
. If ROI is set, the function considers the ROI as supported.
.. index:: WarpAffine
.. _WarpAffine:
WarpAffine
----------
.. function:: WarpAffine(src,dst,mapMatrix,flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,fillval=(0,0,0,0))-> None
Applies an affine transformation to an image.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param mapMatrix: :math:`2\times 3` transformation matrix
:type mapMatrix: :class:`CvMat`
:param flags: A combination of interpolation methods and the following optional flags:
* **CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels; if some of them correspond to outliers in the source image, they are set to ``fillval``
* **CV_WARP_INVERSE_MAP** indicates that ``matrix`` is inversely
transformed from the destination image to the source and, thus, can be used
directly for pixel interpolation. Otherwise, the function finds
the inverse transform from ``mapMatrix``
:type flags: int
:param fillval: A value used to fill outliers
:type fillval: :class:`CvScalar`
The function
``cvWarpAffine``
transforms the source image using the specified matrix:
.. math::
dst(x',y') = src(x,y)
where
.. math::
\begin{matrix} \begin{bmatrix} x' \\ y' \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} & \mbox{if CV\_WARP\_INVERSE\_MAP is not set} \\ \begin{bmatrix} x \\ y \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} & \mbox{otherwise} \end{matrix}
The function is similar to
:ref:`GetQuadrangleSubPix`
but they are not exactly the same.
:ref:`WarpAffine`
requires input and output image have the same data type, has larger overhead (so it is not quite suitable for small images) and can leave part of destination image unchanged. While
:ref:`GetQuadrangleSubPix`
may extract quadrangles from 8-bit images into floating-point buffer, has smaller overhead and always changes the whole destination image content.
Note that the function can not operate in-place.
To transform a sparse set of points, use the
:ref:`Transform`
function from cxcore.
.. index:: WarpPerspective
.. _WarpPerspective:
WarpPerspective
---------------
.. function:: WarpPerspective(src,dst,mapMatrix,flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS,fillval=(0,0,0,0))-> None
Applies a perspective transformation to an image.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param mapMatrix: :math:`3\times 3` transformation matrix
:type mapMatrix: :class:`CvMat`
:param flags: A combination of interpolation methods and the following optional flags:
* **CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels; if some of them correspond to outliers in the source image, they are set to ``fillval``
* **CV_WARP_INVERSE_MAP** indicates that ``matrix`` is inversely transformed from the destination image to the source and, thus, can be used directly for pixel interpolation. Otherwise, the function finds the inverse transform from ``mapMatrix``
:type flags: int
:param fillval: A value used to fill outliers
:type fillval: :class:`CvScalar`
The function
``cvWarpPerspective``
transforms the source image using the specified matrix:
.. math::
\begin{matrix} \begin{bmatrix} x' \\ y' \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} & \mbox{if CV\_WARP\_INVERSE\_MAP is not set} \\ \begin{bmatrix} x \\ y \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} & \mbox{otherwise} \end{matrix}
Note that the function can not operate in-place.
For a sparse set of points use the
:ref:`PerspectiveTransform`
function from CxCore.

View File

@ -0,0 +1,771 @@
Histograms
==========
.. highlight:: python
.. index:: CvHistogram
.. _CvHistogram:
CvHistogram
-----------
.. class:: CvHistogram
Multi-dimensional histogram.
A CvHistogram is a multi-dimensional histogram, created by function
:ref:`CreateHist`
. It has an attribute
``bins``
a
:ref:`CvMatND`
containing the histogram counts.
.. index:: CalcBackProject
.. _CalcBackProject:
CalcBackProject
---------------
.. function:: CalcBackProject(image,back_project,hist)-> None
Calculates the back projection.
:param image: Source images (though you may pass CvMat** as well)
:type image: sequence of :class:`IplImage`
:param back_project: Destination back projection image of the same type as the source images
:type back_project: :class:`CvArr`
:param hist: Histogram
:type hist: :class:`CvHistogram`
The function calculates the back project of the histogram. For each
tuple of pixels at the same position of all input single-channel images
the function puts the value of the histogram bin, corresponding to the
tuple in the destination image. In terms of statistics, the value of
each output image pixel is the probability of the observed tuple given
the distribution (histogram). For example, to find a red object in the
picture, one may do the following:
#.
Calculate a hue histogram for the red object assuming the image contains only this object. The histogram is likely to have a strong maximum, corresponding to red color.
#.
Calculate back projection of a hue plane of input image where the object is searched, using the histogram. Threshold the image.
#.
Find connected components in the resulting picture and choose the right component using some additional criteria, for example, the largest connected component.
That is the approximate algorithm of Camshift color object tracker, except for the 3rd step, instead of which CAMSHIFT algorithm is used to locate the object on the back projection given the previous object position.
.. index:: CalcBackProjectPatch
.. _CalcBackProjectPatch:
CalcBackProjectPatch
--------------------
.. function:: CalcBackProjectPatch(images,dst,patch_size,hist,method,factor)-> None
Locates a template within an image by using a histogram comparison.
:param images: Source images (though, you may pass CvMat** as well)
:type images: sequence of :class:`IplImage`
:param dst: Destination image
:type dst: :class:`CvArr`
:param patch_size: Size of the patch slid though the source image
:type patch_size: :class:`CvSize`
:param hist: Histogram
:type hist: :class:`CvHistogram`
:param method: Comparison method, passed to :ref:`CompareHist` (see description of that function)
:type method: int
:param factor: Normalization factor for histograms, will affect the normalization scale of the destination image, pass 1 if unsure
:type factor: float
The function calculates the back projection by comparing histograms of the source image patches with the given histogram. Taking measurement results from some image at each location over ROI creates an array
``image``
. These results might be one or more of hue,
``x``
derivative,
``y``
derivative, Laplacian filter, oriented Gabor filter, etc. Each measurement output is collected into its own separate image. The
``image``
image array is a collection of these measurement images. A multi-dimensional histogram
``hist``
is constructed by sampling from the
``image``
image array. The final histogram is normalized. The
``hist``
histogram has as many dimensions as the number of elements in
``image``
array.
Each new image is measured and then converted into an
``image``
image array over a chosen ROI. Histograms are taken from this
``image``
image in an area covered by a "patch" with an anchor at center as shown in the picture below. The histogram is normalized using the parameter
``norm_factor``
so that it may be compared with
``hist``
. The calculated histogram is compared to the model histogram;
``hist``
uses The function
``cvCompareHist``
with the comparison method=
``method``
). The resulting output is placed at the location corresponding to the patch anchor in the probability image
``dst``
. This process is repeated as the patch is slid over the ROI. Iterative histogram update by subtracting trailing pixels covered by the patch and adding newly covered pixels to the histogram can save a lot of operations, though it is not implemented yet.
Back Project Calculation by Patches
.. index:: CalcHist
.. _CalcHist:
CalcHist
--------
.. function:: CalcHist(image,hist,accumulate=0,mask=NULL)-> None
Calculates the histogram of image(s).
:param image: Source images (though you may pass CvMat** as well)
:type image: sequence of :class:`IplImage`
:param hist: Pointer to the histogram
:type hist: :class:`CvHistogram`
:param accumulate: Accumulation flag. If it is set, the histogram is not cleared in the beginning. This feature allows user to compute a single histogram from several images, or to update the histogram online
:type accumulate: int
:param mask: The operation mask, determines what pixels of the source images are counted
:type mask: :class:`CvArr`
The function calculates the histogram of one or more
single-channel images. The elements of a tuple that is used to increment
a histogram bin are taken at the same location from the corresponding
input images.
.. include:: ../../python_fragments/calchist.py
:literal:
.. index:: CalcProbDensity
.. _CalcProbDensity:
CalcProbDensity
---------------
.. function:: CalcProbDensity(hist1,hist2,dst_hist,scale=255)-> None
Divides one histogram by another.
:param hist1: first histogram (the divisor)
:type hist1: :class:`CvHistogram`
:param hist2: second histogram
:type hist2: :class:`CvHistogram`
:param dst_hist: destination histogram
:type dst_hist: :class:`CvHistogram`
:param scale: scale factor for the destination histogram
:type scale: float
The function calculates the object probability density from the two histograms as:
.. math::
\texttt{dist\_hist} (I)= \forkthree{0}{if $\texttt{hist1}(I)=0$}{\texttt{scale}}{if $\texttt{hist1}(I) \ne 0$ and $\texttt{hist2}(I) > \texttt{hist1}(I)$}{\frac{\texttt{hist2}(I) \cdot \texttt{scale}}{\texttt{hist1}(I)}}{if $\texttt{hist1}(I) \ne 0$ and $\texttt{hist2}(I) \le \texttt{hist1}(I)$}
So the destination histogram bins are within less than
``scale``
.
.. index:: ClearHist
.. _ClearHist:
ClearHist
---------
.. function:: ClearHist(hist)-> None
Clears the histogram.
:param hist: Histogram
:type hist: :class:`CvHistogram`
The function sets all of the histogram bins to 0 in the case of a dense histogram and removes all histogram bins in the case of a sparse array.
.. index:: CompareHist
.. _CompareHist:
CompareHist
-----------
.. function:: CompareHist(hist1,hist2,method)->float
Compares two dense histograms.
:param hist1: The first dense histogram
:type hist1: :class:`CvHistogram`
:param hist2: The second dense histogram
:type hist2: :class:`CvHistogram`
:param method: Comparison method, one of the following:
* **CV_COMP_CORREL** Correlation
* **CV_COMP_CHISQR** Chi-Square
* **CV_COMP_INTERSECT** Intersection
* **CV_COMP_BHATTACHARYYA** Bhattacharyya distance
:type method: int
The function compares two dense histograms using the specified method (
:math:`H_1`
denotes the first histogram,
:math:`H_2`
the second):
* Correlation (method=CV\_COMP\_CORREL)
.. math::
d(H_1,H_2) = \frac{\sum_I (H'_1(I) \cdot H'_2(I))}{\sqrt{\sum_I(H'_1(I)^2) \cdot \sum_I(H'_2(I)^2)}}
where
.. math::
H'_k(I) = \frac{H_k(I) - 1}{N \cdot \sum_J H_k(J)}
where N is the number of histogram bins.
* Chi-Square (method=CV\_COMP\_CHISQR)
.. math::
d(H_1,H_2) = \sum _I \frac{(H_1(I)-H_2(I))^2}{H_1(I)+H_2(I)}
* Intersection (method=CV\_COMP\_INTERSECT)
.. math::
d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))
* Bhattacharyya distance (method=CV\_COMP\_BHATTACHARYYA)
.. math::
d(H_1,H_2) = \sqrt{1 - \sum_I \frac{\sqrt{H_1(I) \cdot H_2(I)}}{ \sqrt{ \sum_I H_1(I) \cdot \sum_I H_2(I) }}}
The function returns
:math:`d(H_1, H_2)`
.
Note: the method
``CV_COMP_BHATTACHARYYA``
only works with normalized histograms.
To compare a sparse histogram or more general sparse configurations of weighted points, consider using the
:ref:`CalcEMD2`
function.
.. index:: CreateHist
.. _CreateHist:
CreateHist
----------
.. function:: CreateHist(dims, type, ranges, uniform = 1) -> hist
Creates a histogram.
:param dims: for an N-dimensional histogram, list of length N giving the size of each dimension
:type dims: sequence of int
:param type: Histogram representation format: ``CV_HIST_ARRAY`` means that the histogram data is represented as a multi-dimensional dense array CvMatND; ``CV_HIST_SPARSE`` means that histogram data is represented as a multi-dimensional sparse array CvSparseMat
:type type: int
:param ranges: Array of ranges for the histogram bins. Its meaning depends on the ``uniform`` parameter value. The ranges are used for when the histogram is calculated or backprojected to determine which histogram bin corresponds to which value/tuple of values from the input image(s)
:type ranges: list of tuples of ints
:param uniform: Uniformity flag; if not 0, the histogram has evenly
spaced bins and for every :math:`0<=i<cDims` ``ranges[i]``
is an array of two numbers: lower and upper boundaries for the i-th
histogram dimension.
The whole range [lower,upper] is then split
into ``dims[i]`` equal parts to determine the ``i-th`` input
tuple value ranges for every histogram bin. And if ``uniform=0`` ,
then ``i-th`` element of ``ranges`` array contains ``dims[i]+1`` elements: :math:`\texttt{lower}_0, \texttt{upper}_0,
\texttt{lower}_1, \texttt{upper}_1 = \texttt{lower}_2,
...
\texttt{upper}_{dims[i]-1}`
where :math:`\texttt{lower}_j` and :math:`\texttt{upper}_j`
are lower and upper
boundaries of ``i-th`` input tuple value for ``j-th``
bin, respectively. In either case, the input values that are beyond
the specified range for a histogram bin are not counted by :ref:`CalcHist` and filled with 0 by :ref:`CalcBackProject`
:type uniform: int
The function creates a histogram of the specified
size and returns a pointer to the created histogram. If the array
``ranges``
is 0, the histogram bin ranges must be specified later
via the function
:ref:`SetHistBinRanges`
. Though
:ref:`CalcHist`
and
:ref:`CalcBackProject`
may process 8-bit images without setting
bin ranges, they assume thy are equally spaced in 0 to 255 bins.
.. index:: GetMinMaxHistValue
.. _GetMinMaxHistValue:
GetMinMaxHistValue
------------------
.. function:: GetMinMaxHistValue(hist)-> (min_value,max_value,min_idx,max_idx)
Finds the minimum and maximum histogram bins.
:param hist: Histogram
:type hist: :class:`CvHistogram`
:param min_value: Minimum value of the histogram
:type min_value: :class:`CvScalar`
:param max_value: Maximum value of the histogram
:type max_value: :class:`CvScalar`
:param min_idx: Coordinates of the minimum
:type min_idx: sequence of int
:param max_idx: Coordinates of the maximum
:type max_idx: sequence of int
The function finds the minimum and
maximum histogram bins and their positions. All of output arguments are
optional. Among several extremas with the same value the ones with the
minimum index (in lexicographical order) are returned. In the case of several maximums
or minimums, the earliest in lexicographical order (extrema locations)
is returned.
.. index:: NormalizeHist
.. _NormalizeHist:
NormalizeHist
-------------
.. function:: NormalizeHist(hist,factor)-> None
Normalizes the histogram.
:param hist: Pointer to the histogram
:type hist: :class:`CvHistogram`
:param factor: Normalization factor
:type factor: float
The function normalizes the histogram bins by scaling them, such that the sum of the bins becomes equal to
``factor``
.
.. index:: QueryHistValue_1D
.. _QueryHistValue_1D:
QueryHistValue_1D
-----------------
.. function:: QueryHistValue_1D(hist, idx0) -> float
Returns the value from a 1D histogram bin.
:param hist: Histogram
:type hist: :class:`CvHistogram`
:param idx0: bin index 0
:type idx0: int
.. index:: QueryHistValue_2D
.. _QueryHistValue_2D:
QueryHistValue_2D
-----------------
.. function:: QueryHistValue_2D(hist, idx0, idx1) -> float
Returns the value from a 2D histogram bin.
:param hist: Histogram
:type hist: :class:`CvHistogram`
:param idx0: bin index 0
:type idx0: int
:param idx1: bin index 1
:type idx1: int
.. index:: QueryHistValue_3D
.. _QueryHistValue_3D:
QueryHistValue_3D
-----------------
.. function:: QueryHistValue_3D(hist, idx0, idx1, idx2) -> float
Returns the value from a 3D histogram bin.
:param hist: Histogram
:type hist: :class:`CvHistogram`
:param idx0: bin index 0
:type idx0: int
:param idx1: bin index 1
:type idx1: int
:param idx2: bin index 2
:type idx2: int
.. index:: QueryHistValue_nD
.. _QueryHistValue_nD:
QueryHistValue_nD
-----------------
.. function:: QueryHistValue_nD(hist, idx) -> float
Returns the value from a 1D histogram bin.
:param hist: Histogram
:type hist: :class:`CvHistogram`
:param idx: list of indices, of same length as the dimension of the histogram's bin.
:type idx: sequence of int
.. index:: ThreshHist
.. _ThreshHist:
ThreshHist
----------
.. function:: ThreshHist(hist,threshold)-> None
Thresholds the histogram.
:param hist: Pointer to the histogram
:type hist: :class:`CvHistogram`
:param threshold: Threshold level
:type threshold: float
The function clears histogram bins that are below the specified threshold.

View File

@ -0,0 +1,732 @@
Image Filtering
===============
.. highlight:: python
Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images (represented as
:cpp:func:`Mat`
's), that is, for each pixel location
:math:`(x,y)`
in the source image some its (normally rectangular) neighborhood is considered and used to compute the response. In case of a linear filter it is a weighted sum of pixel values, in case of morphological operations it is the minimum or maximum etc. The computed response is stored to the destination image at the same location
:math:`(x,y)`
. It means, that the output image will be of the same size as the input image. Normally, the functions supports multi-channel arrays, in which case every channel is processed independently, therefore the output image will also have the same number of channels as the input one.
Another common feature of the functions and classes described in this section is that, unlike simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For example, if we want to smooth an image using a Gaussian
:math:`3 \times 3`
filter, then during the processing of the left-most pixels in each row we need pixels to the left of them, i.e. outside of the image. We can let those pixels be the same as the left-most image pixels (i.e. use "replicated border" extrapolation method), or assume that all the non-existing pixels are zeros ("contant border" extrapolation method) etc.
.. index:: IplConvKernel
.. _IplConvKernel:
IplConvKernel
-------------
.. class:: IplConvKernel
An IplConvKernel is a rectangular convolution kernel, created by function
:ref:`CreateStructuringElementEx`
.
.. index:: CopyMakeBorder
.. _CopyMakeBorder:
CopyMakeBorder
--------------
.. function:: CopyMakeBorder(src,dst,offset,bordertype,value=(0,0,0,0))-> None
Copies an image and makes a border around it.
:param src: The source image
:type src: :class:`CvArr`
:param dst: The destination image
:type dst: :class:`CvArr`
:param offset: Coordinates of the top-left corner (or bottom-left in the case of images with bottom-left origin) of the destination image rectangle where the source image (or its ROI) is copied. Size of the rectanlge matches the source image size/ROI size
:type offset: :class:`CvPoint`
:param bordertype: Type of the border to create around the copied source image rectangle; types include:
* **IPL_BORDER_CONSTANT** border is filled with the fixed value, passed as last parameter of the function.
* **IPL_BORDER_REPLICATE** the pixels from the top and bottom rows, the left-most and right-most columns are replicated to fill the border.
(The other two border types from IPL, ``IPL_BORDER_REFLECT`` and ``IPL_BORDER_WRAP`` , are currently unsupported)
:type bordertype: int
:param value: Value of the border pixels if ``bordertype`` is ``IPL_BORDER_CONSTANT``
:type value: :class:`CvScalar`
The function copies the source 2D array into the interior of the destination array and makes a border of the specified type around the copied area. The function is useful when one needs to emulate border type that is different from the one embedded into a specific algorithm implementation. For example, morphological functions, as well as most of other filtering functions in OpenCV, internally use replication border type, while the user may need a zero border or a border, filled with 1's or 255's.
.. index:: CreateStructuringElementEx
.. _CreateStructuringElementEx:
CreateStructuringElementEx
--------------------------
.. function:: CreateStructuringElementEx(cols,rows,anchorX,anchorY,shape,values=None)-> kernel
Creates a structuring element.
:param cols: Number of columns in the structuring element
:type cols: int
:param rows: Number of rows in the structuring element
:type rows: int
:param anchorX: Relative horizontal offset of the anchor point
:type anchorX: int
:param anchorY: Relative vertical offset of the anchor point
:type anchorY: int
:param shape: Shape of the structuring element; may have the following values:
* **CV_SHAPE_RECT** a rectangular element
* **CV_SHAPE_CROSS** a cross-shaped element
* **CV_SHAPE_ELLIPSE** an elliptic element
* **CV_SHAPE_CUSTOM** a user-defined element. In this case the parameter ``values`` specifies the mask, that is, which neighbors of the pixel must be considered
:type shape: int
:param values: Pointer to the structuring element data, a plane array, representing row-by-row scanning of the element matrix. Non-zero values indicate points that belong to the element. If the pointer is ``NULL`` , then all values are considered non-zero, that is, the element is of a rectangular shape. This parameter is considered only if the shape is ``CV_SHAPE_CUSTOM``
:type values: sequence of int
The function CreateStructuringElementEx allocates and fills the structure
``IplConvKernel``
, which can be used as a structuring element in the morphological operations.
.. index:: Dilate
.. _Dilate:
Dilate
------
.. function:: Dilate(src,dst,element=None,iterations=1)-> None
Dilates an image by using a specific structuring element.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param element: Structuring element used for dilation. If it is ``None`` , a ``3 x 3`` rectangular structuring element is used
:type element: :class:`IplConvKernel`
:param iterations: Number of times dilation is applied
:type iterations: int
The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken:
.. math::
\max _{(x',y') \, in \, \texttt{element} }src(x+x',y+y')
The function supports the in-place mode. Dilation can be applied several (``iterations``) times. For color images, each channel is processed independently.
.. index:: Erode
.. _Erode:
Erode
-----
.. function:: Erode(src,dst,element=None,iterations=1)-> None
Erodes an image by using a specific structuring element.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param element: Structuring element used for erosion. If it is ``None`` , a ``3 x 3`` rectangular structuring element is used
:type element: :class:`IplConvKernel`
:param iterations: Number of times erosion is applied
:type iterations: int
The function erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken:
.. math::
\min _{(x',y') \, in \, \texttt{element} }src(x+x',y+y')
The function supports the in-place mode. Erosion can be applied several (
``iterations``
) times. For color images, each channel is processed independently.
.. index:: Filter2D
.. _Filter2D:
Filter2D
--------
.. function:: Filter2D(src,dst,kernel,anchor=(-1,-1))-> None
Convolves an image with the kernel.
:param src: The source image
:type src: :class:`CvArr`
:param dst: The destination image
:type dst: :class:`CvArr`
:param kernel: Convolution kernel, a single-channel floating point matrix. If you want to apply different kernels to different channels, split the image into separate color planes using :ref:`Split` and process them individually
:type kernel: :class:`CvMat`
:param anchor: The anchor of the kernel that indicates the relative position of a filtered point within the kernel. The anchor shoud lie within the kernel. The special default value (-1,-1) means that it is at the kernel center
:type anchor: :class:`CvPoint`
The function applies an arbitrary linear filter to the image. In-place operation is supported. When the aperture is partially outside the image, the function interpolates outlier pixel values from the nearest pixels that are inside the image.
.. index:: Laplace
.. _Laplace:
Laplace
-------
.. function:: Laplace(src,dst,apertureSize=3)-> None
Calculates the Laplacian of an image.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param apertureSize: Aperture size (it has the same meaning as :ref:`Sobel` )
:type apertureSize: int
The function calculates the Laplacian of the source image by adding up the second x and y derivatives calculated using the Sobel operator:
.. math::
\texttt{dst} (x,y) = \frac{d^2 \texttt{src}}{dx^2} + \frac{d^2 \texttt{src}}{dy^2}
Setting
``apertureSize``
= 1 gives the fastest variant that is equal to convolving the image with the following kernel:
.. math::
\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}
Similar to the
:ref:`Sobel`
function, no scaling is done and the same combinations of input and output formats are supported.
.. index:: MorphologyEx
.. _MorphologyEx:
MorphologyEx
------------
.. function:: MorphologyEx(src,dst,temp,element,operation,iterations=1)-> None
Performs advanced morphological transformations.
:param src: Source image
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param temp: Temporary image, required in some cases
:type temp: :class:`CvArr`
:param element: Structuring element
:type element: :class:`IplConvKernel`
:param operation: Type of morphological operation, one of the following:
* **CV_MOP_OPEN** opening
* **CV_MOP_CLOSE** closing
* **CV_MOP_GRADIENT** morphological gradient
* **CV_MOP_TOPHAT** "top hat"
* **CV_MOP_BLACKHAT** "black hat"
:type operation: int
:param iterations: Number of times erosion and dilation are applied
:type iterations: int
The function can perform advanced morphological transformations using erosion and dilation as basic operations.
Opening:
.. math::
dst=open(src,element)=dilate(erode(src,element),element)
Closing:
.. math::
dst=close(src,element)=erode(dilate(src,element),element)
Morphological gradient:
.. math::
dst=morph \_ grad(src,element)=dilate(src,element)-erode(src,element)
"Top hat":
.. math::
dst=tophat(src,element)=src-open(src,element)
"Black hat":
.. math::
dst=blackhat(src,element)=close(src,element)-src
The temporary image
``temp``
is required for a morphological gradient and, in the case of in-place operation, for "top hat" and "black hat".
.. index:: PyrDown
.. _PyrDown:
PyrDown
-------
.. function:: PyrDown(src,dst,filter=CV_GAUSSIAN_5X5)-> None
Downsamples an image.
:param src: The source image
:type src: :class:`CvArr`
:param dst: The destination image, should have a half as large width and height than the source
:type dst: :class:`CvArr`
:param filter: Type of the filter used for convolution; only ``CV_GAUSSIAN_5x5`` is currently supported
:type filter: int
The function performs the downsampling step of the Gaussian pyramid decomposition. First it convolves the source image with the specified filter and then downsamples the image by rejecting even rows and columns.
.. index:: Smooth
.. _Smooth:
Smooth
------
.. function:: Smooth(src,dst,smoothtype=CV_GAUSSIAN,param1=3,param2=0,param3=0,param4=0)-> None
Smooths the image in one of several ways.
:param src: The source image
:type src: :class:`CvArr`
:param dst: The destination image
:type dst: :class:`CvArr`
:param smoothtype: Type of the smoothing:
* **CV_BLUR_NO_SCALE** linear convolution with :math:`\texttt{param1}\times\texttt{param2}` box kernel (all 1's). If you want to smooth different pixels with different-size box kernels, you can use the integral image that is computed using :ref:`Integral`
* **CV_BLUR** linear convolution with :math:`\texttt{param1}\times\texttt{param2}` box kernel (all 1's) with subsequent scaling by :math:`1/(\texttt{param1}\cdot\texttt{param2})`
* **CV_GAUSSIAN** linear convolution with a :math:`\texttt{param1}\times\texttt{param2}` Gaussian kernel
* **CV_MEDIAN** median filter with a :math:`\texttt{param1}\times\texttt{param1}` square aperture
* **CV_BILATERAL** bilateral filter with a :math:`\texttt{param1}\times\texttt{param1}` square aperture, color sigma= ``param3`` and spatial sigma= ``param4`` . If ``param1=0`` , the aperture square side is set to ``cvRound(param4*1.5)*2+1`` . Information about bilateral filtering can be found at http://www.dai.ed.ac.uk/CVonline/LOCAL\_COPIES/MANDUCHI1/Bilateral\_Filtering.html
:type smoothtype: int
:param param1: The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)
:type param1: int
:param param2: The second parameter of the smoothing operation, the aperture height. Ignored by ``CV_MEDIAN`` and ``CV_BILATERAL`` methods. In the case of simple scaled/non-scaled and Gaussian blur if ``param2`` is zero, it is set to ``param1`` . Otherwise it must be a positive odd number.
:type param2: int
:param param3: In the case of a Gaussian parameter this parameter may specify Gaussian :math:`\sigma` (standard deviation). If it is zero, it is calculated from the kernel size:
.. math::
\sigma = 0.3 (n/2 - 1) + 0.8 \quad \text{where} \quad n= \begin{array}{l l} \mbox{\texttt{param1} for horizontal kernel} \\ \mbox{\texttt{param2} for vertical kernel} \end{array}
Using standard sigma for small kernels ( :math:`3\times 3` to :math:`7\times 7` ) gives better speed. If ``param3`` is not zero, while ``param1`` and ``param2`` are zeros, the kernel size is calculated from the sigma (to provide accurate enough operation).
:type param3: float
The function smooths an image using one of several methods. Every of the methods has some features and restrictions listed below
Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format (similar to
:ref:`Sobel`
and
:ref:`Laplace`
) and 32-bit floating point to 32-bit floating-point format.
Simple blur and Gaussian blur support 1- or 3-channel, 8-bit and 32-bit floating point images. These two methods can process images in-place.
Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.
.. index:: Sobel
.. _Sobel:
Sobel
-----
.. function:: Sobel(src,dst,xorder,yorder,apertureSize = 3)-> None
Calculates the first, second, third or mixed image derivatives using an extended Sobel operator.
:param src: Source image of type CvArr*
:type src: :class:`CvArr`
:param dst: Destination image
:type dst: :class:`CvArr`
:param xorder: Order of the derivative x
:type xorder: int
:param yorder: Order of the derivative y
:type yorder: int
:param apertureSize: Size of the extended Sobel kernel, must be 1, 3, 5 or 7
:type apertureSize: int
In all cases except 1, an
:math:`\texttt{apertureSize} \times
\texttt{apertureSize}`
separable kernel will be used to calculate the
derivative. For
:math:`\texttt{apertureSize} = 1`
a
:math:`3 \times 1`
or
:math:`1 \times 3`
a kernel is used (Gaussian smoothing is not done). There is also the special
value
``CV_SCHARR``
(-1) that corresponds to a
:math:`3\times3`
Scharr
filter that may give more accurate results than a
:math:`3\times3`
Sobel. Scharr
aperture is
.. math::
\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}
for the x-derivative or transposed for the y-derivative.
The function calculates the image derivative by convolving the image with the appropriate kernel:
.. math::
\texttt{dst} (x,y) = \frac{d^{xorder+yorder} \texttt{src}}{dx^{xorder} \cdot dy^{yorder}}
The Sobel operators combine Gaussian smoothing and differentiation
so the result is more or less resistant to the noise. Most often,
the function is called with (
``xorder``
= 1,
``yorder``
= 0,
``apertureSize``
= 3) or (
``xorder``
= 0,
``yorder``
= 1,
``apertureSize``
= 3) to calculate the first x- or y- image
derivative. The first case corresponds to a kernel of:
.. math::
\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}
and the second one corresponds to a kernel of:
.. math::
\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}
or a kernel of:
.. math::
\vecthreethree{1}{2}{1}{0}{0}{0}{-1}{2}{-1}
depending on the image origin (
``origin``
field of
``IplImage``
structure). No scaling is done, so the destination image
usually has larger numbers (in absolute values) than the source image does. To
avoid overflow, the function requires a 16-bit destination image if the
source image is 8-bit. The result can be converted back to 8-bit using the
:ref:`ConvertScale`
or the
:ref:`ConvertScaleAbs`
function. Besides 8-bit images
the function can process 32-bit floating-point images. Both the source and the
destination must be single-channel images of equal size or equal ROI size.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,216 @@
Motion Analysis and Object Tracking
===================================
.. highlight:: python
.. index:: Acc
.. _Acc:
Acc
---
.. function:: Acc(image,sum,mask=NULL)-> None
Adds a frame to an accumulator.
:param image: Input image, 1- or 3-channel, 8-bit or 32-bit floating point. (each channel of multi-channel image is processed independently)
:type image: :class:`CvArr`
:param sum: Accumulator with the same number of channels as input image, 32-bit or 64-bit floating-point
:type sum: :class:`CvArr`
:param mask: Optional operation mask
:type mask: :class:`CvArr`
The function adds the whole image
``image``
or its selected region to the accumulator
``sum``
:
.. math::
\texttt{sum} (x,y) \leftarrow \texttt{sum} (x,y) + \texttt{image} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
.. index:: MultiplyAcc
.. _MultiplyAcc:
MultiplyAcc
-----------
.. function:: MultiplyAcc(image1,image2,acc,mask=NULL)-> None
Adds the product of two input images to the accumulator.
:param image1: First input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently)
:type image1: :class:`CvArr`
:param image2: Second input image, the same format as the first one
:type image2: :class:`CvArr`
:param acc: Accumulator with the same number of channels as input images, 32-bit or 64-bit floating-point
:type acc: :class:`CvArr`
:param mask: Optional operation mask
:type mask: :class:`CvArr`
The function adds the product of 2 images or their selected regions to the accumulator
``acc``
:
.. math::
\texttt{acc} (x,y) \leftarrow \texttt{acc} (x,y) + \texttt{image1} (x,y) \cdot \texttt{image2} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
.. index:: RunningAvg
.. _RunningAvg:
RunningAvg
----------
.. function:: RunningAvg(image,acc,alpha,mask=NULL)-> None
Updates the running average.
:param image: Input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently)
:type image: :class:`CvArr`
:param acc: Accumulator with the same number of channels as input image, 32-bit or 64-bit floating-point
:type acc: :class:`CvArr`
:param alpha: Weight of input image
:type alpha: float
:param mask: Optional operation mask
:type mask: :class:`CvArr`
The function calculates the weighted sum of the input image
``image``
and the accumulator
``acc``
so that
``acc``
becomes a running average of frame sequence:
.. math::
\texttt{acc} (x,y) \leftarrow (1- \alpha ) \cdot \texttt{acc} (x,y) + \alpha \cdot \texttt{image} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
where
:math:`\alpha`
regulates the update speed (how fast the accumulator forgets about previous frames).
.. index:: SquareAcc
.. _SquareAcc:
SquareAcc
---------
.. function:: SquareAcc(image,sqsum,mask=NULL)-> None
Adds the square of the source image to the accumulator.
:param image: Input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently)
:type image: :class:`CvArr`
:param sqsum: Accumulator with the same number of channels as input image, 32-bit or 64-bit floating-point
:type sqsum: :class:`CvArr`
:param mask: Optional operation mask
:type mask: :class:`CvArr`
The function adds the input image
``image``
or its selected region, raised to power 2, to the accumulator
``sqsum``
:
.. math::
\texttt{sqsum} (x,y) \leftarrow \texttt{sqsum} (x,y) + \texttt{image} (x,y)^2 \quad \text{if} \quad \texttt{mask} (x,y) \ne 0

View File

@ -0,0 +1,155 @@
Object Detection
================
.. highlight:: python
.. index:: MatchTemplate
.. _MatchTemplate:
MatchTemplate
-------------
.. function:: MatchTemplate(image,templ,result,method)-> None
Compares a template against overlapped image regions.
:param image: Image where the search is running; should be 8-bit or 32-bit floating-point
:type image: :class:`CvArr`
:param templ: Searched template; must be not greater than the source image and the same data type as the image
:type templ: :class:`CvArr`
:param result: A map of comparison results; single-channel 32-bit floating-point.
If ``image`` is :math:`W \times H` and ``templ`` is :math:`w \times h` then ``result`` must be :math:`(W-w+1) \times (H-h+1)`
:type result: :class:`CvArr`
:param method: Specifies the way the template must be compared with the image regions (see below)
:type method: int
The function is similar to
:ref:`CalcBackProjectPatch`
. It slides through
``image``
, compares the
overlapped patches of size
:math:`w \times h`
against
``templ``
using the specified method and stores the comparison results to
``result``
. Here are the formulas for the different comparison
methods one may use (
:math:`I`
denotes
``image``
,
:math:`T`
``template``
,
:math:`R`
``result``
). The summation is done over template and/or the
image patch:
:math:`x' = 0...w-1, y' = 0...h-1`
* method=CV\_TM\_SQDIFF
.. math::
R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2
* method=CV\_TM\_SQDIFF\_NORMED
.. math::
R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}
* method=CV\_TM\_CCORR
.. math::
R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))
* method=CV\_TM\_CCORR\_NORMED
.. math::
R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}
* method=CV\_TM\_CCOEFF
.. math::
R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))
where
.. math::
\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}
* method=CV\_TM\_CCOEFF\_NORMED
.. math::
R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }
After the function finishes the comparison, the best matches can be found as global minimums (
``CV_TM_SQDIFF``
) or maximums (
``CV_TM_CCORR``
and
``CV_TM_CCOEFF``
) using the
:ref:`MinMaxLoc`
function. In the case of a color image, template summation in the numerator and each sum in the denominator is done over all of the channels (and separate mean values are used for each channel).

View File

@ -0,0 +1,561 @@
Planar Subdivisions
===================
.. highlight:: python
.. index:: CvSubdiv2D
.. _CvSubdiv2D:
CvSubdiv2D
----------
.. class:: CvSubdiv2D
Planar subdivision.
.. attribute:: edges
A :ref:`CvSet` of :ref:`CvSubdiv2DEdge`
Planar subdivision is the subdivision of a plane into a set of
non-overlapped regions (facets) that cover the whole plane. The above
structure describes a subdivision built on a 2d point set, where the points
are linked together and form a planar graph, which, together with a few
edges connecting the exterior subdivision points (namely, convex hull points)
with infinity, subdivides a plane into facets by its edges.
For every subdivision there exists a dual subdivision in which facets and
points (subdivision vertices) swap their roles, that is, a facet is
treated as a vertex (called a virtual point below) of the dual subdivision and
the original subdivision vertices become facets. On the picture below
original subdivision is marked with solid lines and dual subdivision
with dotted lines.
OpenCV subdivides a plane into triangles using Delaunay's
algorithm. Subdivision is built iteratively starting from a dummy
triangle that includes all the subdivision points for sure. In this
case the dual subdivision is a Voronoi diagram of the input 2d point set. The
subdivisions can be used for the 3d piece-wise transformation of a plane,
morphing, fast location of points on the plane, building special graphs
(such as NNG,RNG) and so forth.
.. index:: CvSubdiv2DPoint
.. _CvSubdiv2DPoint:
CvSubdiv2DPoint
---------------
.. class:: CvSubdiv2DPoint
Point of original or dual subdivision.
.. attribute:: first
A connected :ref:`CvSubdiv2DEdge`
.. attribute:: pt
Position, as a :ref:`CvPoint2D32f`
.. index:: CalcSubdivVoronoi2D
.. _CalcSubdivVoronoi2D:
CalcSubdivVoronoi2D
-------------------
.. function:: CalcSubdivVoronoi2D(subdiv)-> None
Calculates the coordinates of Voronoi diagram cells.
:param subdiv: Delaunay subdivision, in which all the points are already added
:type subdiv: :class:`CvSubdiv2D`
The function calculates the coordinates
of virtual points. All virtual points corresponding to some vertex of the
original subdivision form (when connected together) a boundary of the Voronoi
cell at that point.
.. index:: ClearSubdivVoronoi2D
.. _ClearSubdivVoronoi2D:
ClearSubdivVoronoi2D
--------------------
.. function:: ClearSubdivVoronoi2D(subdiv)-> None
Removes all virtual points.
:param subdiv: Delaunay subdivision
:type subdiv: :class:`CvSubdiv2D`
The function removes all of the virtual points. It
is called internally in
:ref:`CalcSubdivVoronoi2D`
if the subdivision
was modified after previous call to the function.
.. index:: CreateSubdivDelaunay2D
.. _CreateSubdivDelaunay2D:
CreateSubdivDelaunay2D
----------------------
.. function:: CreateSubdivDelaunay2D(rect,storage)-> delaunay_triangulation
Creates an empty Delaunay triangulation.
:param rect: Rectangle that includes all of the 2d points that are to be added to the subdivision
:type rect: :class:`CvRect`
:param storage: Container for subdivision
:type storage: :class:`CvMemStorage`
The function creates an empty Delaunay
subdivision, where 2d points can be added using the function
:ref:`SubdivDelaunay2DInsert`
. All of the points to be added must be within
the specified rectangle, otherwise a runtime error will be raised.
Note that the triangulation is a single large triangle that covers the given rectangle. Hence the three vertices of this triangle are outside the rectangle
``rect``
.
.. index:: FindNearestPoint2D
.. _FindNearestPoint2D:
FindNearestPoint2D
------------------
.. function:: FindNearestPoint2D(subdiv,pt)-> point
Finds the closest subdivision vertex to the given point.
:param subdiv: Delaunay or another subdivision
:type subdiv: :class:`CvSubdiv2D`
:param pt: Input point
:type pt: :class:`CvPoint2D32f`
The function is another function that
locates the input point within the subdivision. It finds the subdivision vertex that
is the closest to the input point. It is not necessarily one of vertices
of the facet containing the input point, though the facet (located using
:ref:`Subdiv2DLocate`
) is used as a starting
point. The function returns a pointer to the found subdivision vertex.
.. index:: Subdiv2DEdgeDst
.. _Subdiv2DEdgeDst:
Subdiv2DEdgeDst
---------------
.. function:: Subdiv2DEdgeDst(edge)-> point
Returns the edge destination.
:param edge: Subdivision edge (not a quad-edge)
:type edge: :class:`CvSubdiv2DEdge`
The function returns the edge destination. The
returned pointer may be NULL if the edge is from dual subdivision and
the virtual point coordinates are not calculated yet. The virtual points
can be calculated using the function
:ref:`CalcSubdivVoronoi2D`
.
.. index:: Subdiv2DGetEdge
.. _Subdiv2DGetEdge:
Subdiv2DGetEdge
---------------
.. function:: Subdiv2DGetEdge(edge,type)-> CvSubdiv2DEdge
Returns one of the edges related to the given edge.
:param edge: Subdivision edge (not a quad-edge)
:type edge: :class:`CvSubdiv2DEdge`
:param type: Specifies which of the related edges to return, one of the following:
:type type: :class:`CvNextEdgeType`
* **CV_NEXT_AROUND_ORG** next around the edge origin ( ``eOnext`` on the picture below if ``e`` is the input edge)
* **CV_NEXT_AROUND_DST** next around the edge vertex ( ``eDnext`` )
* **CV_PREV_AROUND_ORG** previous around the edge origin (reversed ``eRnext`` )
* **CV_PREV_AROUND_DST** previous around the edge destination (reversed ``eLnext`` )
* **CV_NEXT_AROUND_LEFT** next around the left facet ( ``eLnext`` )
* **CV_NEXT_AROUND_RIGHT** next around the right facet ( ``eRnext`` )
* **CV_PREV_AROUND_LEFT** previous around the left facet (reversed ``eOnext`` )
* **CV_PREV_AROUND_RIGHT** previous around the right facet (reversed ``eDnext`` )
The function returns one of the edges related to the input edge.
.. index:: Subdiv2DNextEdge
.. _Subdiv2DNextEdge:
Subdiv2DNextEdge
----------------
.. function:: Subdiv2DNextEdge(edge)-> CvSubdiv2DEdge
Returns next edge around the edge origin
:param edge: Subdivision edge (not a quad-edge)
:type edge: :class:`CvSubdiv2DEdge`
The function returns the next edge around the edge origin:
``eOnext``
on the picture above if
``e``
is the input edge)
.. index:: Subdiv2DLocate
.. _Subdiv2DLocate:
Subdiv2DLocate
--------------
.. function:: Subdiv2DLocate(subdiv, pt) -> (loc, where)
Returns the location of a point within a Delaunay triangulation.
:param subdiv: Delaunay or another subdivision
:type subdiv: :class:`CvSubdiv2D`
:param pt: The point to locate
:type pt: :class:`CvPoint2D32f`
:param loc: The location of the point within the triangulation
:type loc: int
:param where: The edge or vertex. See below.
:type where: :class:`CvSubdiv2DEdge`, :class:`CvSubdiv2DPoint`
The function locates the input point within the subdivision. There are 5 cases:
*
The point falls into some facet.
``loc``
is
``CV_PTLOC_INSIDE``
and
``where``
is one of edges of the facet.
*
The point falls onto the edge.
``loc``
is
``CV_PTLOC_ON_EDGE``
and
``where``
is the edge.
*
The point coincides with one of the subdivision vertices.
``loc``
is
``CV_PTLOC_VERTEX``
and
``where``
is the vertex.
*
The point is outside the subdivsion reference rectangle.
``loc``
is
``CV_PTLOC_OUTSIDE_RECT``
and
``where``
is None.
*
One of input arguments is invalid. The function raises an exception.
.. index:: Subdiv2DRotateEdge
.. _Subdiv2DRotateEdge:
Subdiv2DRotateEdge
------------------
.. function:: Subdiv2DRotateEdge(edge,rotate)-> CvSubdiv2DEdge
Returns another edge of the same quad-edge.
:param edge: Subdivision edge (not a quad-edge)
:type edge: :class:`CvSubdiv2DEdge`
:param rotate: Specifies which of the edges of the same quad-edge as the input one to return, one of the following:
* **0** the input edge ( ``e`` on the picture below if ``e`` is the input edge)
* **1** the rotated edge ( ``eRot`` )
* **2** the reversed edge (reversed ``e`` (in green))
* **3** the reversed rotated edge (reversed ``eRot`` (in green))
:type rotate: int
The function returns one of the edges of the same quad-edge as the input edge.
.. index:: SubdivDelaunay2DInsert
.. _SubdivDelaunay2DInsert:
SubdivDelaunay2DInsert
----------------------
.. function:: SubdivDelaunay2DInsert(subdiv,pt)-> point
Inserts a single point into a Delaunay triangulation.
:param subdiv: Delaunay subdivision created by the function :ref:`CreateSubdivDelaunay2D`
:type subdiv: :class:`CvSubdiv2D`
:param pt: Inserted point
:type pt: :class:`CvPoint2D32f`
The function inserts a single point into a subdivision and modifies the subdivision topology appropriately. If a point with the same coordinates exists already, no new point is added. The function returns a pointer to the allocated point. No virtual point coordinates are calculated at this stage.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
************
Introduction
************
Starting with release 2.0, OpenCV has a new Python interface. This replaces the previous
`SWIG-based Python interface <http://opencv.willowgarage.com/wiki/SwigPythonInterface>`_
.
Some highlights of the new bindings:
* single import of all of OpenCV using ``import cv``
* OpenCV functions no longer have the "cv" prefix
* simple types like CvRect and CvScalar use Python tuples
* sharing of Image storage, so image transport between OpenCV and other systems (e.g. numpy and ROS) is very efficient
* complete documentation for the Python functions
This cookbook section contains a few illustrative examples of OpenCV Python code.
.. toctree::
:maxdepth: 2
cookbook

View File

@ -0,0 +1,10 @@
***************************
objdetect. Object Detection
***************************
.. toctree::
:maxdepth: 2
objdetect_cascade_classification

View File

@ -0,0 +1,180 @@
Cascade Classification
======================
.. highlight:: python
Haar Feature-based Cascade Classifier for Object Detection
----------------------------------------------------------
The object detector described below has been initially proposed by Paul Viola
:ref:`Viola01`
and improved by Rainer Lienhart
:ref:`Lienhart02`
. First, a classifier (namely a
*cascade of boosted classifiers working with haar-like features*
) is trained with a few hundred sample views of a particular object (i.e., a face or a car), called positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary images of the same size.
After a classifier is trained, it can be applied to a region of interest
(of the same size as used during the training) in an input image. The
classifier outputs a "1" if the region is likely to show the object
(i.e., face/car), and "0" otherwise. To search for the object in the
whole image one can move the search window across the image and check
every location using the classifier. The classifier is designed so that
it can be easily "resized" in order to be able to find the objects of
interest at different sizes, which is more efficient than resizing the
image itself. So, to find an object of an unknown size in the image the
scan procedure should be done several times at different scales.
The word "cascade" in the classifier name means that the resultant
classifier consists of several simpler classifiers (
*stages*
) that
are applied subsequently to a region of interest until at some stage the
candidate is rejected or all the stages are passed. The word "boosted"
means that the classifiers at every stage of the cascade are complex
themselves and they are built out of basic classifiers using one of four
different
``boosting``
techniques (weighted voting). Currently
Discrete Adaboost, Real Adaboost, Gentle Adaboost and Logitboost are
supported. The basic classifiers are decision-tree classifiers with at
least 2 leaves. Haar-like features are the input to the basic classifers,
and are calculated as described below. The current algorithm uses the
following Haar-like features:
The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within the region of interest and the scale (this scale is not the same as the scale used at the detection stage, though these two scales are multiplied). For example, in the case of the third line feature (2c) the response is calculated as the difference between the sum of image pixels under the rectangle covering the whole feature (including the two white stripes and the black stripe in the middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to compensate for the differences in the size of areas. The sums of pixel values over a rectangular regions are calculated rapidly using integral images (see below and the
:ref:`Integral`
description).
A simple demonstration of face detection, which draws a rectangle around each detected face:
::
hc = cv.Load("haarcascade_frontalface_default.xml")
img = cv.LoadImage("faces.jpg", 0)
faces = cv.HaarDetectObjects(img, hc, cv.CreateMemStorage())
for (x,y,w,h),n in faces:
cv.Rectangle(img, (x,y), (x+w,y+h), 255)
cv.SaveImage("faces_detected.jpg", img)
..
.. index:: HaarDetectObjects
.. _HaarDetectObjects:
HaarDetectObjects
-----------------
.. function:: HaarDetectObjects(image,cascade,storage,scaleFactor=1.1,minNeighbors=3,flags=0,minSize=(0,0))-> detected_objects
Detects objects in the image.
:param image: Image to detect objects in
:type image: :class:`CvArr`
:param cascade: Haar classifier cascade in internal representation
:type cascade: :class:`CvHaarClassifierCascade`
:param storage: Memory storage to store the resultant sequence of the object candidate rectangles
:type storage: :class:`CvMemStorage`
:param scaleFactor: The factor by which the search window is scaled between the subsequent scans, 1.1 means increasing window by 10 %
:param minNeighbors: Minimum number (minus 1) of neighbor rectangles that makes up an object. All the groups of a smaller number of rectangles than ``min_neighbors`` -1 are rejected. If ``minNeighbors`` is 0, the function does not any grouping at all and returns all the detected candidate rectangles, which may be useful if the user wants to apply a customized grouping procedure
:param flags: Mode of operation. Currently the only flag that may be specified is ``CV_HAAR_DO_CANNY_PRUNING`` . If it is set, the function uses Canny edge detector to reject some image regions that contain too few or too much edges and thus can not contain the searched object. The particular threshold values are tuned for face detection and in this case the pruning speeds up the processing
:type flags: int
:param minSize: Minimum window size. By default, it is set to the size of samples the classifier has been trained on ( :math:`\sim 20\times 20` for face detection)
:param maxSize: Maximum window size to use. By default, it is set to the size of the image.
The function finds rectangular regions in the given image that are likely to contain objects the cascade has been trained for and returns those regions as a sequence of rectangles. The function scans the image several times at different scales (see
:ref:`SetImagesForHaarClassifierCascade`
). Each time it considers overlapping regions in the image and applies the classifiers to the regions using
:ref:`RunHaarClassifierCascade`
. It may also apply some heuristics to reduce number of analyzed regions, such as Canny prunning. After it has proceeded and collected the candidate rectangles (regions that passed the classifier cascade), it groups them and returns a sequence of average rectangles for each large enough group. The default parameters (
``scale_factor``
=1.1,
``min_neighbors``
=3,
``flags``
=0) are tuned for accurate yet slow object detection. For a faster operation on real video images the settings are:
``scale_factor``
=1.2,
``min_neighbors``
=2,
``flags``
=
``CV_HAAR_DO_CANNY_PRUNING``
,
``min_size``
=
*minimum possible face size*
(for example,
:math:`\sim`
1/4 to 1/16 of the image area in the case of video conferencing).
The function returns a list of tuples,
``(rect, neighbors)``
, where rect is a
:ref:`CvRect`
specifying the object's extents
and neighbors is a number of neighbors.
.. doctest::
>>> import cv
>>> image = cv.LoadImageM("lena.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
>>> cascade = cv.Load("../../data/haarcascades/haarcascade_frontalface_alt.xml")
>>> print cv.HaarDetectObjects(image, cascade, cv.CreateMemStorage(0), 1.2, 2, 0, (20, 20))
[((217, 203, 169, 169), 24)]
..

View File

@ -0,0 +1,17 @@
###############################
OpenCV 2.x Python API Reference
###############################
.. highlight:: python
.. toctree::
:maxdepth: 2
introduction
core
imgproc
features2d
objdetect
video
highgui
calib3d

10
doc/opencv2/py/video.rst Normal file
View File

@ -0,0 +1,10 @@
*********************
video. Video Analysis
*********************
.. toctree::
:maxdepth: 2
video_motion_analysis_and_object_tracking

File diff suppressed because it is too large Load Diff

BIN
doc/opencv2refman_cpp.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
doc/pics/bayer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -10,6 +10,7 @@ Welcome to opencv documentation!
:maxdepth: 2
modules/refman.rst
doc/opencv2/py/py_index.rst
doc/opencv1/c/c_index.rst
doc/opencv1/py/py_index.rst
doc/user_guide/user_guide.rst

View File

@ -17,8 +17,8 @@ void help()
{
printf("\nThis program demonstrates the one way interest point descriptor found in features2d.hpp\n"
"Correspondences are drawn\n");
printf("Format: \n./one_way_sample [path_to_samples] [image1] [image2]\n");
printf("For example: ./one_way_sample ../../../opencv/samples/c scene_l.bmp scene_r.bmp\n");
printf("Format: \n./one_way_sample <path_to_samples> <image1> <image2>\n");
printf("For example: ./one_way_sample . ../c/scene_l.bmp ../c/scene_r.bmp\n");
}
using namespace cv;
@ -32,7 +32,7 @@ int main(int argc, char** argv)
const CvSize patch_size = cvSize(24, 24);
const int pose_count = 50;
if (argc != 3 && argc != 4)
if (argc != 4)
{
help();
return 0;

View File

@ -9,9 +9,9 @@ using namespace cv;
void help()
{
printf("Use the SURF descriptor for matching keypoints between 2 images\n");
printf("Format: \n./generic_descriptor_match [image1] [image2] [algorithm] [XML params]\n");
printf("For example: ./generic_descriptor_match scene_l.bmp scene_r.bmp FERN fern_params.xml\n");
printf("Use the SURF descriptor for matching keypoints between 2 images\n");
printf("Format: \n./generic_descriptor_match <image1> <image2> <algorithm> <XML params>\n");
printf("For example: ./generic_descriptor_match ../c/scene_l.bmp ../c/scene_r.bmp FERN fern_params.xml\n");
}
IplImage* DrawCorrespondences(IplImage* img1, const vector<KeyPoint>& features1, IplImage* img2,

View File

@ -1,12 +0,0 @@
# -------------------------------------------------------------------------
# CMake file for Octave samples. See root CMakeLists.txt
# -------------------------------------------------------------------------
file(GLOB OCTAVE_SAMPLES *.m)
if(NOT WIN32)
install(FILES ${OCTAVE_SAMPLES}
DESTINATION share/opencv/samples/octave
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif()

View File

@ -1,184 +0,0 @@
#! /usr/bin/env octave
## import the necessary things for OpenCV
addpath("/home/x/opencv2/interfaces/swig/octave");
source("/home/x/opencv2/interfaces/swig/octave/PKG_ADD_template");
debug_on_error(true);
debug_on_warning(true);
crash_dumps_octave_core (0)
cv;
highgui;
#############################################################################
## definition of some constants
## how many bins we want for the histogram, and their ranges
hdims = 16;
hranges = {0, 180};
## ranges for the limitation of the histogram
vmin = 10;
vmax = 256;
smin = 30;
## the range we want to monitor
hsv_min = cv.cvScalar (0, smin, vmin, 0);
hsv_max = cv.cvScalar (180, 256, vmax, 0);
#############################################################################
## some useful functions
function rgb = hsv2rgb (hue)
global cv;
## convert the hue value to the corresponding rgb value
sector_data = [0, 2, 1; 1, 2, 0; 1, 0, 2; 2, 0, 1; 2, 1, 0; 0, 1, 2]+1;
hue *= 0.1 / 3;
sector = cv.cvFloor (hue);
p = cv.cvRound (255 * (hue - sector));
if (bitand(sector,1))
p = bitxor(p,255);
endif
rgb = zeros(1,3);
rgb (sector_data (sector+1, 1)) = 255;
rgb (sector_data (sector+1, 2)) = 0;
rgb (sector_data (sector+1, 3)) = p;
rgb = cv.cvScalar (rgb (3), rgb (2), rgb (1), 0);
endfunction
#############################################################################
## so, here is the main part of the program
## a small welcome
printf("OpenCV Octave wrapper test\n");
printf("OpenCV version: %s (%d, %d, %d)\n",
cv.CV_VERSION,cv.CV_MAJOR_VERSION,
cv.CV_MINOR_VERSION,cv.CV_SUBMINOR_VERSION);
## first, create the necessary windows
highgui.cvNamedWindow ('Camera', highgui.CV_WINDOW_AUTOSIZE);
highgui.cvNamedWindow ('Histogram', highgui.CV_WINDOW_AUTOSIZE);
## move the new window to a better place
#highgui.cvMoveWindow ('Camera', 10, 40);
#highgui.cvMoveWindow ('Histogram', 10, 270);
try
## try to get the device number from the command line
device = int32 (argv(){1});
have_device = true;
catch
## no device number on the command line, assume we want the 1st device
device = -1;
end_try_catch
## no argument on the command line, try to use the camera
capture = highgui.cvCreateCameraCapture (device);
## set the wanted image size from the camera
highgui.cvSetCaptureProperty (capture, \
highgui.CV_CAP_PROP_FRAME_WIDTH, 320);
highgui.cvSetCaptureProperty (capture, \
highgui.CV_CAP_PROP_FRAME_HEIGHT, 240);
## create an image to put in the histogram
histimg = cv.cvCreateImage (cv.cvSize (320,240), 8, 3);
## init the image of the histogram to black
cv.cvSetZero (histimg);
## capture the 1st frame to get some propertie on it
frame = highgui.cvQueryFrame (capture);
## get some properties of the frame
frame_size = cv.cvGetSize (frame);
## compute which selection of the frame we want to monitor
selection = cv.cvRect (0, 0, frame.width, frame.height);
## create some images usefull later
hue = cv.cvCreateImage (frame_size, 8, 1);
mask = cv.cvCreateImage (frame_size, 8, 1);
hsv = cv.cvCreateImage (frame_size, 8, 3 );
## create the histogram
hist = cv.cvCreateHist ({hdims}, cv.CV_HIST_ARRAY, {hranges}, 1);
while (1) ## do forever
## 1. capture the current image
frame = highgui.cvQueryFrame (capture);
if (swig_this(frame)==0);
## no image captured... end the processing
break
endif
## mirror the captured image
cv.cvFlip (frame, [], 1);
## compute the hsv version of the image
cv.cvCvtColor (frame, hsv, cv.CV_BGR2HSV);
## compute which pixels are in the wanted range
cv.cvInRangeS (hsv, hsv_min, hsv_max, mask);
## extract the hue from the hsv array
cv.cvSplit (hsv, hue, [], [], []);
## select the rectangle of interest in the hue/mask arrays
hue_roi = cv.cvGetSubRect (hue, selection);
mask_roi = cv.cvGetSubRect (mask, selection);
## it's time to compute the histogram
cv.cvCalcHist (hue_roi, hist, 0, mask_roi);
## extract the min and max value of the histogram
[min_val, max_val, min_idx, max_idx] = cv.cvGetMinMaxHistValue (hist);
## compute the scale factor
if (max_val > 0)
scale = 255. / max_val;
else
scale = 0.;
endif
## scale the histograms
cv.cvConvertScale (hist.bins, hist.bins, scale, 0);
## clear the histogram image
cv.cvSetZero (histimg);
## compute the width for each bin do display
bin_w = histimg.width / hdims;
for (i=0:hdims-1)
## for all the bins
## get the value, and scale to the size of the hist image
val = cv.cvRound (cv.cvGetReal1D (hist.bins, i)
* histimg.height / 255);
## compute the color
color = hsv2rgb (i * 180. / hdims);
## draw the rectangle in the wanted color
cv.cvRectangle (histimg,
cv.cvPoint (i * bin_w, histimg.height),
cv.cvPoint ((i + 1) * bin_w, histimg.height - val),
color, -1, 8, 0);
## we can now display the images
highgui.cvShowImage ('Camera', frame);
highgui.cvShowImage ('Histogram', histimg);
endfor
## handle events
k = highgui.cvWaitKey (5);
if (k == 27)
## user has press the ESC key, so exit
break;
endif
endwhile

View File

@ -1,107 +0,0 @@
#! /usr/bin/env octave
## import the necessary things for OpenCV
addpath("/home/x/opencv2/interfaces/swig/octave");
source("/home/x/opencv2/interfaces/swig/octave/PKG_ADD_template");
debug_on_error(true);
debug_on_warning(true);
crash_dumps_octave_core (0)
cv;
highgui;
## the codec existing in cvcapp.cpp,
## need to have a better way to specify them in the future
## WARNING: I have see only MPEG1VIDEO working on my computer
H263 = 0x33363255;
H263I = 0x33363249;
MSMPEG4V3 = 0x33564944;
MPEG4 = 0x58564944;
MSMPEG4V2 = 0x3234504D;
MJPEG = 0x47504A4D;
MPEG1VIDEO = 0x314D4950;
AC3 = 0x2000;
MP2 = 0x50;
FLV1 = 0x31564C46;
#############################################################################
## so, here is the main part of the program
## a small welcome
printf("OpenCV Octave capture video\n");
## first, create the necessary window
highgui.cvNamedWindow ('Camera', highgui.CV_WINDOW_AUTOSIZE);
## move the new window to a better place
#highgui.cvMoveWindow ('Camera', 10, 10);
try
## try to get the device number from the command line
device = int32 (argv(){1});
catch
## no device number on the command line, assume we want the 1st device
device = -1;
end_try_catch
## no argument on the command line, try to use the camera
capture = highgui.cvCreateCameraCapture (device);
## check that capture device is OK
if (!swig_this(capture))
printf("Error opening capture device\n");
exit (1);
endif
## capture the 1st frame to get some propertie on it
frame = highgui.cvQueryFrame (capture);
## get size of the frame
frame_size = cv.cvGetSize (frame);
## get the frame rate of the capture device
fps = highgui.cvGetCaptureProperty (capture, highgui.CV_CAP_PROP_FPS);
if (fps == 0)
## no fps getted, so set it to 30 by default
fps = 30;
endif
## create the writer
writer = highgui.cvCreateVideoWriter ("captured.mpg", MPEG1VIDEO,
fps, frame_size, true);
## check the writer is OK
if (!swig_this(writer))
printf("Error opening writer\n");
exit(1);
endif
while (1)
## do forever
## 1. capture the current image
frame = highgui.cvQueryFrame (capture);
if (swig_this(frame) == 0)
## no image captured... end the processing
break
endif
## write the frame to the output file
highgui.cvWriteFrame (writer, frame);
## display the frames to have a visual output
highgui.cvShowImage ('Camera', frame);
## handle events
k = highgui.cvWaitKey (5);
if (k & 0x100 == 27)
## user has press the ESC key, so exit
break
endif
endwhile
## end working with the writer
## not working at this time... Need to implement some typemaps...
## but exiting without calling it is OK in this simple application
##highgui.cvReleaseVideoWriter (writer)

View File

@ -1,23 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
arg_list=argv();
cvNamedWindow("win");
if (!size(arg_list,1))
error("must specify filename");
exit
endif
filename = arg_list{1};
im = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE);
im3 = cvLoadImage(filename, CV_LOAD_IMAGE_COLOR);
chessboard_dim = cvSize( 5, 6 );
[found_all, corners] = cvFindChessboardCorners( im, chessboard_dim );
cvDrawChessboardCorners( im3, chessboard_dim, corners, found_all );
cvShowImage("win", im3);
cvWaitKey();

View File

@ -1,140 +0,0 @@
#! /usr/bin/env octave
printf("OpenCV Octave version of contours\n");
## import the necessary things for OpenCV
cv;
global _SIZE;
global _red;
global _green;
global _blue;
global contours;
## some default constants
_SIZE = 500;
_DEFAULT_LEVEL = 3;
## definition of some colors
_red = cvScalar (0, 0, 255, 0);
_green = cvScalar (0, 255, 0, 0);
_white = cvRealScalar (255);
_black = cvRealScalar (0);
## the callback on the trackbar, to set the level of contours we want
## to display
function on_trackbar (position)
global cv;
global _SIZE;
global _red;
global _green;
global _blue;
global contours;
## create the image for putting in it the founded contours
contours_image = cvCreateImage (cvSize (_SIZE, _SIZE), 8, 3);
## compute the real level of display, given the current position
levels = position - 3;
## initialisation
_contours = contours;
if (levels <= 0)
## zero or negative value
## => get to the nearest face to make it look more funny
_contours = contours.h_next.h_next.h_next;
endif
## first, clear the image where we will draw contours
cvSetZero (contours_image);
## draw contours in red and green
cvDrawContours (contours_image, _contours, _red, _green, levels, 3, cv.CV_AA, cvPoint (0, 0));
## finally, show the image
cvShowImage ("contours", contours_image);
endfunction
## create the image where we want to display results
image = cvCreateImage (cvSize (_SIZE, _SIZE), 8, 1);
## start with an empty image
cvSetZero (image);
## draw the original picture
for i=0:6-1,
dx = mod(i,2) * 250 - 30;
dy = (i / 2) * 150;
cvEllipse (image,
cvPoint (dx + 150, dy + 100),
cvSize (100, 70),
0, 0, 360, _white, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 115, dy + 70),
cvSize (30, 20),
0, 0, 360, _black, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 185, dy + 70),
cvSize (30, 20),
0, 0, 360, _black, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 115, dy + 70),
cvSize (15, 15),
0, 0, 360, _white, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 185, dy + 70),
cvSize (15, 15),
0, 0, 360, _white, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 115, dy + 70),
cvSize (5, 5),
0, 0, 360, _black, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 185, dy + 70),
cvSize (5, 5),
0, 0, 360, _black, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 150, dy + 100),
cvSize (10, 5),
0, 0, 360, _black, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 150, dy + 150),
cvSize (40, 10),
0, 0, 360, _black, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 27, dy + 100),
cvSize (20, 35),
0, 0, 360, _white, -1, 8, 0);
cvEllipse (image,
cvPoint (dx + 273, dy + 100),
cvSize (20, 35),
0, 0, 360, _white, -1, 8, 0);
endfor
## create window and display the original picture in it
cvNamedWindow ("image", 1);
cvShowImage ("image", image);
## create the storage area
storage = cvCreateMemStorage (0);
## find the contours
[nb_contours, contours] = cvFindContours (image, storage, sizeof_CvContour, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint (0,0));
## comment this out if you do not want approximation
contours = cvApproxPoly (contours, sizeof_CvContour, storage, CV_POLY_APPROX_DP, 3, 1);
## create the window for the contours
cvNamedWindow ("contours", 1);
## create the trackbar, to enable the change of the displayed level
cvCreateTrackbar ("levels+3", "contours", 3, 7, @on_trackbar);
## call one time the callback, so we will have the 1st display done
on_trackbar (_DEFAULT_LEVEL);
## wait a key pressed to end
cvWaitKey (0);

View File

@ -1,74 +0,0 @@
#! /usr/bin/env octave
printf("OpenCV Octave version of convexhull\n");
## import the necessary things for OpenCV
cv;
highgui;
## how many points we want at max
_MAX_POINTS = 100;
## create the image where we want to display results
image = cv.cvCreateImage (cv.cvSize (500, 500), 8, 3);
## create the window to put the image in
highgui.cvNamedWindow ('hull', highgui.CV_WINDOW_AUTOSIZE);
while (true)
## do forever
## get a random number of points
count = int32(rand()*_MAX_POINTS)+1
## initialisations
points = {};
for i=1:count,
## generate a random point
points{i} = cv.cvPoint \
(int32(rand() * (image.width / 2) + image.width / 4), \
int32(rand() * (image.height / 2) + image.height / 4)); \
endfor
## compute the convex hull
hull = cv.cvConvexHull2 (points, cv.CV_CLOCKWISE, 0);
## start with an empty image
cv.cvSetZero (image);
for i=1:count,
## draw all the points
cv.cvCircle (image, points {i}, 2, \
cv.cvScalar (0, 0, 255, 0), \
cv.CV_FILLED, cv.CV_AA, 0);
endfor
## start the line from the last point
pt0 = points {hull [-1]};
for point_index = 1:hull.rows,
## connect the previous point to the current one
## get the current one
pt1 = points {point_index};
## draw
cv.cvLine (image, pt0, pt1, \
cv.cvScalar (0, 255, 0, 0), \
1, cv.CV_AA, 0);
## now, current one will be the previous one for the next iteration
pt0 = pt1;
endfor
## display the final image
highgui.cvShowImage ('hull', image);
## handle events, and wait a key pressed
k = highgui.cvWaitKey (0);
if (k == '\x1b')
## user has press the ESC key, so exit
break
endif
endwhile

View File

@ -1,170 +0,0 @@
#! /usr/bin/env octave
## the script demostrates iterative construction of
## delaunay triangulation and voronoi tesselation
## Original Author (C version): ?
## Converted to Python by: Roman Stanchak
## Converted to Octave by: Xavier Delacour
cv;
highgui;
function draw_subdiv_point( img, fp, color )
global CV_FILLED;
cvCircle( img, cvPoint(cvRound(fp.x), cvRound(fp.y)), 3, color, \
CV_FILLED, 8, 0 );
endfunction
function draw_subdiv_edge( img, edge, color )
global CV_AA;
org_pt = cvSubdiv2DEdgeOrg(edge);
dst_pt = cvSubdiv2DEdgeDst(edge);
if (org_pt && dst_pt )
org = org_pt.pt;
dst = dst_pt.pt;
iorg = cvPoint( cvRound( org.x ), cvRound( org.y ));
idst = cvPoint( cvRound( dst.x ), cvRound( dst.y ));
cvLine( img, iorg, idst, color, 1, CV_AA, 0 );
endif
endfunction
function draw_subdiv( img, subdiv, delaunay_color, voronoi_color )
total = subdiv.edges.total;
elem_size = subdiv.edges.elem_size;
for edge in subdiv.edges,
edge_rot = cvSubdiv2DRotateEdge( edge, 1 );
if( CV_IS_SET_ELEM( edge ))
draw_subdiv_edge( img, edge_rot, voronoi_color );
draw_subdiv_edge( img, edge, delaunay_color );
endif
endfor
endfunction
function locate_point( subdiv, fp, img, active_color )
[res, e0, p] = cvSubdiv2DLocate( subdiv, fp );
if (e0)
e = e0
while (true)
draw_subdiv_edge( img, e, active_color );
e = cvSubdiv2DGetEdge(e,CV_NEXT_AROUND_LEFT);
if (e == e0)
break
endif
endwhile
endif
draw_subdiv_point( img, fp, active_color );
endfunction
function draw_subdiv_facet( img, edge )
t = edge;
count = 0;
## count number of edges in facet
while (count == 0 || t != edge)
count+=1;
t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
endwhile
buf = []
## gather points
t = edge;
for i=0:count-1,
assert t>4
pt = cvSubdiv2DEdgeOrg( t );
if (! pt)
break;
endif
buf.append( cvPoint( cvRound(pt.pt.x), cvRound(pt.pt.y) ) );
t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
endfor
if( len(buf)==count )
pt = cvSubdiv2DEdgeDst( cvSubdiv2DRotateEdge( edge, 1 ));
cvFillConvexPoly( img, buf, CV_RGB(randint(0,255),randint(0,255),randint(0,255)), CV_AA, 0 );
cvPolyLine( img, [buf], 1, CV_RGB(0,0,0), 1, CV_AA, 0);
draw_subdiv_point( img, pt.pt, CV_RGB(0,0,0));
endif
endfunction
function paint_voronoi( subdiv, img )
total = subdiv.edges.total;
elem_size = subdiv.edges.elem_size;
cvCalcSubdivVoronoi2D( subdiv );
for edge in subdiv.edges,
if( CV_IS_SET_ELEM( edge ))
## left
draw_subdiv_facet( img, cvSubdiv2DRotateEdge( edge, 1 ));
## right
draw_subdiv_facet( img, cvSubdiv2DRotateEdge( edge, 3 ));
endif
endfor
endfunction
win = "source";
rect = cvRect( 0, 0, 600, 600 );
active_facet_color = CV_RGB( 255, 0, 0 );
delaunay_color = CV_RGB( 0,0,0);
voronoi_color = CV_RGB(0, 180, 0);
bkgnd_color = CV_RGB(255,255,255);
img = cvCreateImage( cvSize(rect.width,rect.height), 8, 3 );
cvSet( img, bkgnd_color );
cvNamedWindow( win, 1 );
storage = cvCreateMemStorage(0);
subdiv = cvCreateSubdivDelaunay2D( rect, storage );
printf("Delaunay triangulation will be build now interactively.\n");
printf("To stop the process, press any key\n");
for i=0:200-1,
fp = cvPoint2D32f( int32(rand()*(rect.width-10)+5), int32(rand()*(rect.height-10)+5) )
locate_point( subdiv, fp, img, active_facet_color );
cvShowImage( win, img );
if( cvWaitKey( 100 ) >= 0 )
break;
endif
cvSubdivDelaunay2DInsert( subdiv, fp );
cvCalcSubdivVoronoi2D( subdiv );
cvSet( img, bkgnd_color );
draw_subdiv( img, subdiv, delaunay_color, voronoi_color );
cvShowImage( win, img );
if( cvWaitKey( 100 ) >= 0 )
break;
endif
endfor
cvSet( img, bkgnd_color );
paint_voronoi( subdiv, img );
cvShowImage( win, img );
cvWaitKey(0);
cvDestroyWindow( win );

View File

@ -1,129 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
file_name = "../c/baboon.jpg";
global Gbrightness;
global Gcontrast;
global hist_size;
global ranges;
global src_image;
global dst_image;
global hist_image;
global hist;
global lut;
_brightness = 100;
_contrast = 100;
Gbrightness = 100;
Gcontrast = 100;
hist_size = 64;
range_0={0,256};
ranges = { range_0 };
src_image=[];
dst_image=[];
hist_image=[];
hist=[];
lut=cvCreateMat(256,1,CV_8U);
## brightness/contrast callback function
function update_brightness( val )
global Gbrightness # global tag is required, or we get UnboundLocalError
Gbrightness = val;
update_brightcont( );
endfunction
function update_contrast( val )
global Gcontrast; # global tag is required, or we get UnboundLocalError
Gcontrast = val;
update_brightcont( );
endfunction
function update_brightcont()
global Gbrightness;
global Gcontrast;
global hist_size;
global ranges;
global src_image;
global dst_image;
global hist_image;
global hist;
global lut;
global cvCalcHist; # use cv namespace for these instead
global cvZero;
global cvScale;
brightness = Gbrightness - 100;
contrast = Gcontrast - 100;
max_value = 0;
## The algorithm is by Werner D. Streidt
## (http://visca.com/ffactory/archives/5-99/msg00021.html)
if( contrast > 0 )
delta = 127.*contrast/100;
a = 255./(255. - delta*2);
b = a*(brightness - delta);
else
delta = -128.*contrast/100;
a = (256.-delta*2)/255.;
b = a*brightness + delta;
endif
for i=0:256-1,
v = cvRound(a*i + b);
if( v < 0 )
v = 0;
endif
if( v > 255 )
v = 255;
endif
lut(i) = v;
endfor
cvLUT( src_image, dst_image, lut );
cvShowImage( "image", dst_image );
cvCalcHist( dst_image, hist, 0, [] );
cvZero( dst_image );
[min_value, max_value] = cvGetMinMaxHistValue( hist );
cvScale( hist.bins, hist.bins, double(hist_image.height)/max_value, 0 );
##cvNormalizeHist( hist, 1000 );
cvSet( hist_image, cvScalarAll(255));
bin_w = cvRound(double(hist_image.width)/hist_size);
for i=0:hist_size-1,
cvRectangle( hist_image, cvPoint(i*bin_w, hist_image.height), cvPoint((i+1)*bin_w, hist_image.height - cvRound(cvGetReal1D(hist.bins,i))), cvScalarAll(0), -1, 8, 0 );
endfor
cvShowImage( "histogram", hist_image );
endfunction
## Load the source image. HighGUI use.
if size(argv, 1)>1
file_name = argv(){1}
endif
src_image = cvLoadImage( file_name, 0 );
if (!swig_this(src_image))
printf("Image was not loaded.\n");
exit(-1);
endif
dst_image = cvCloneImage(src_image);
hist_image = cvCreateImage(cvSize(320,200), 8, 1);
hist = cvCreateHist({hist_size}, CV_HIST_ARRAY, ranges, 1);
cvNamedWindow("image", 0);
cvNamedWindow("histogram", 0);
cvCreateTrackbar("brightness", "image", _brightness, 200, @update_brightness);
cvCreateTrackbar("contrast", "image", _contrast, 200, @update_contrast);
update_brightcont();
cvWaitKey(0);

View File

@ -1,115 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
## Rearrange the quadrants of Fourier image so that the origin is at
## the image center
## src & dst arrays of equal size & type
function cvShiftDFT(src_arr, dst_arr )
size = cvGetSize(src_arr);
dst_size = cvGetSize(dst_arr);
if(dst_size.width != size.width || \
dst_size.height != size.height)
cvError( CV_StsUnmatchedSizes, "cvShiftDFT", \
"Source and Destination arrays must have equal sizes", \
__FILE__, __LINE__ );
endif
if(swig_this(src_arr) == swig_this(dst_arr))
tmp = cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr));
endif
cx = size.width/2;
cy = size.height/2; # image center
q1 = cvGetSubRect( src_arr, cvRect(0,0,cx, cy) );
q2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) );
q3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) );
q4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) );
d1 = cvGetSubRect( src_arr, cvRect(0,0,cx,cy) );
d2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) );
d3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) );
d4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) );
if(swig_this(src_arr) != swig_this(dst_arr))
if( !CV_ARE_TYPES_EQ( q1, d1 ))
cvError( CV_StsUnmatchedFormats, \
"cvShiftDFT", "Source and Destination arrays must have the same format", \
__FILE__, __LINE__ );
endif
cvCopy(q3, d1);
cvCopy(q4, d2);
cvCopy(q1, d3);
cvCopy(q2, d4);
else
cvCopy(q3, tmp);
cvCopy(q1, q3);
cvCopy(tmp, q1);
cvCopy(q4, tmp);
cvCopy(q2, q4);
cvCopy(tmp, q2);
endif
endfunction
im = cvLoadImage( argv(){1}, CV_LOAD_IMAGE_GRAYSCALE);
realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2);
cvScale(im, realInput, 1.0, 0.0);
cvZero(imaginaryInput);
cvMerge(realInput, imaginaryInput, [], [], complexInput);
dft_M = cvGetOptimalDFTSize( im.height - 1 );
dft_N = cvGetOptimalDFTSize( im.width - 1 );
dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
image_Im = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
## copy A to dft_A and pad dft_A with zeros
tmp = cvGetSubRect( dft_A, cvRect(0,0, im.width, im.height));
cvCopy( complexInput, tmp, [] );
if(dft_A.width > im.width)
tmp = cvGetSubRect( dft_A, cvRect(im.width,0, dft_N - im.width, im.height));
cvZero( tmp );
endif
## no need to pad bottom part of dft_A with zeros because of
## use nonzero_rows parameter in cvDFT() call below
cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput.height );
cvNamedWindow("win", 0);
cvNamedWindow("magnitude", 0);
cvShowImage("win", im);
## Split Fourier in real and imaginary parts
cvSplit( dft_A, image_Re, image_Im, [], [] );
## Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
cvPow( image_Re, image_Re, 2.0);
cvPow( image_Im, image_Im, 2.0);
cvAdd( image_Re, image_Im, image_Re, []);
cvPow( image_Re, image_Re, 0.5 );
## Compute log(1 + Mag)
cvAddS( image_Re, cvScalarAll(1.0), image_Re, [] ); # 1 + Mag
cvLog( image_Re, image_Re ); # log(1 + Mag)
## Rearrange the quadrants of Fourier image so that the origin is at
## the image center
cvShiftDFT( image_Re, image_Re );
[min, max] = cvMinMaxLoc(image_Re);
cvScale(image_Re, image_Re, 1.0/(max-min), 1.0*(-min)/(max-min));
cvShowImage("magnitude", image_Re);
cvWaitKey(-1);

View File

@ -1,76 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global g;
g.wndname = "Distance transform";
g.tbarname = "Threshold";
## The output images
g.dist = 0;
g.dist8u1 = 0;
g.dist8u2 = 0;
g.dist8u = 0;
g.dist32s = 0;
g.gray = 0;
g.edge = 0;
## define a trackbar callback
function on_trackbar( edge_thresh )
global g;
global cv;
cvThreshold( g.gray, g.edge, double(edge_thresh), double(edge_thresh), cv.CV_THRESH_BINARY );
## Distance transform
cvDistTransform( g.edge, g.dist, cv.CV_DIST_L2, cv.CV_DIST_MASK_5, [], [] );
cvConvertScale( g.dist, g.dist, 5000.0, 0 );
cvPow( g.dist, g.dist, 0.5 );
cvConvertScale( g.dist, g.dist32s, 1.0, 0.5 );
cvAndS( g.dist32s, cvScalarAll(255), g.dist32s, [] );
cvConvertScale( g.dist32s, g.dist8u1, 1, 0 );
cvConvertScale( g.dist32s, g.dist32s, -1, 0 );
cvAddS( g.dist32s, cvScalarAll(255), g.dist32s, [] );
cvConvertScale( g.dist32s, g.dist8u2, 1, 0 );
cvMerge( g.dist8u1, g.dist8u2, g.dist8u2, [], g.dist8u );
cvShowImage( g.wndname, g.dist8u );
endfunction
edge_thresh = 100;
filename = "../c/stuff.jpg";
if (size(argv, 1) > 1)
filename = argv(){1};
endif
g.gray = cvLoadImage( filename, 0 );
if (!swig_this(g.gray))
printf("Failed to load %s\n",filename);
exit(-1);
endif
## Create the output image
g.dist = cvCreateImage( cvSize(g.gray.width,g.gray.height), IPL_DEPTH_32F, 1 );
g.dist8u1 = cvCloneImage( g.gray );
g.dist8u2 = cvCloneImage( g.gray );
g.dist8u = cvCreateImage( cvSize(g.gray.width,g.gray.height), IPL_DEPTH_8U, 3 );
g.dist32s = cvCreateImage( cvSize(g.gray.width,g.gray.height), IPL_DEPTH_32S, 1 );
## Convert to grayscale
g.edge = cvCloneImage( g.gray );
## Create a window
cvNamedWindow( g.wndname, 1 );
## create a toolbar
cvCreateTrackbar( g.tbarname, g.wndname, edge_thresh, 255, @on_trackbar );
## Show the image
on_trackbar(edge_thresh);
## Wait for a key stroke; the same function arranges events processing
cvWaitKey(0);

View File

@ -1,161 +0,0 @@
#! /usr/bin/env octave
printf("OpenCV Octave version of drawing\n");
## import the necessary things for OpenCV
cv;
highgui;
function ret=random_color ()
ret = CV_RGB(int32(rand()*255), int32(rand()*255), int32(rand()*255));
endfunction
## some "constants"
width = 1000;
height = 700;
window_name = "Drawing Demo";
number = 100;
delay = 5;
line_type = cv.CV_AA; # change it to 8 to see non-antialiased graphics
## create the source image
image = cv.cvCreateImage (cv.cvSize (width, height), 8, 3);
## create window and display the original picture in it
highgui.cvNamedWindow (window_name, 1);
cv.cvSetZero (image);
highgui.cvShowImage (window_name, image);
## draw some lines
for i=0:number-1,
pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
pt2 = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
cv.cvLine (image, pt1, pt2,
random_color (),
int32(rand() * 10),
line_type, 0);
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## draw some rectangles
for i=0:number-1,
pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
pt2 = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
cv.cvRectangle (image, pt1, pt2,
random_color (),
int32(rand() * 10 - 1),
line_type, 0);
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## draw some ellipes
for i=0:number-1,
pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
sz = cv.cvSize (int32(rand() * 200),
int32(rand() * 200));
angle = rand() * 1000 * 0.180;
cv.cvEllipse (image, pt1, sz, angle, angle - 100, angle + 200,
random_color (),
int32(rand() * 10 - 1),
line_type, 0);
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## init the list of polylines
nb_polylines = 2;
polylines_size = 3;
pt = cell(1, nb_polylines);
for a=1:nb_polylines,
pt{a} = cell(1,polylines_size);
endfor
## draw some polylines
for i=0:number-1,
for a=1:nb_polylines,
for b=1:polylines_size,
pt {a}{b} = cv.cvPoint (int32(rand() * 2 * width - width), \
int32(rand() * 2 * height - height));
endfor
endfor
cv.cvPolyLine (image, pt, 1, random_color(), int32(rand() * 8 + 1), line_type, 0);
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## draw some filled polylines
for i=0:number-1,
for a=1:nb_polylines,
for b=1:polylines_size,
pt {a}{b} = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
endfor
endfor
cv.cvFillPoly (image, pt, random_color (), line_type, 0);
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## draw some circles
for i=0:number-1,
pt1 = cv.cvPoint (int32(rand() * 2 * width - width),
int32(rand() * 2 * height - height));
cv.cvCircle (image, pt1, int32(rand() * 300), random_color (), \
int32(rand() * 10 - 1), line_type, 0);
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## draw some text
for i=0:number-1,
pt1 = cv.cvPoint (int32(rand() * 2 * width - width), \
int32(rand() * 2 * height - height));
font = cv.cvInitFont (int32(rand() * 8), \
rand() * 100 * 0.05 + 0.01, \
rand() * 100 * 0.05 + 0.01, \
rand() * 5 * 0.1, \
int32(rand() * 10), \
line_type);
cv.cvPutText (image, "Testing text rendering!", \
pt1, font, \
random_color ());
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## prepare a text, and get it's properties
font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX, \
3, 3, 0.0, 5, line_type);
[text_size, ymin] = cv.cvGetTextSize ("OpenCV forever!", font);
pt1.x = int32((width - text_size.width) / 2);
pt1.y = int32((height + text_size.height) / 2);
image2 = cv.cvCloneImage(image);
## now, draw some OpenCV pub ;-)
for i=0:255-1,
cv.cvSubS (image2, cv.cvScalarAll (i), image, []);
cv.cvPutText (image, "OpenCV forever!",
pt1, font, cv.cvScalar (255, i, i));
highgui.cvShowImage (window_name, image);
highgui.cvWaitKey (delay);
endfor
## wait some key to end
highgui.cvWaitKey (0);

View File

@ -1,69 +0,0 @@
#! /usr/bin/env octave
printf("OpenCV Octave version of edge\n");
global g;
## import the necessary things for OpenCV
cv;
highgui;
## some definitions
g.win_name = "Edge";
g.trackbar_name = "Threshold";
## the callback on the trackbar
function on_trackbar (position)
global g;
global cv;
global highgui;
cv.cvSmooth (g.gray, g.edge, cv.CV_BLUR, 3, 3, 0);
cv.cvNot (g.gray, g.edge);
## run the edge dector on gray scale
cv.cvCanny (g.gray, g.edge, position, position * 3, 3);
## reset
cv.cvSetZero (g.col_edge);
## copy edge points
cv.cvCopy (g.image, g.col_edge, g.edge);
## show the image
highgui.cvShowImage (g.win_name, g.col_edge);
endfunction
filename = "../c/fruits.jpg";
if (size(argv, 1)>1)
filename = argv(){1};
endif
## load the image gived on the command line
g.image = highgui.cvLoadImage (filename);
if (!swig_this(g.image))
printf("Error loading image '%s'",filename);
exit(-1);
endif
## create the output image
g.col_edge = cv.cvCreateImage (cv.cvSize (g.image.width, g.image.height), 8, 3);
## convert to grayscale
g.gray = cv.cvCreateImage (cv.cvSize (g.image.width, g.image.height), 8, 1);
g.edge = cv.cvCreateImage (cv.cvSize (g.image.width, g.image.height), 8, 1);
cv.cvCvtColor (g.image, g.gray, cv.CV_BGR2GRAY);
## create the window
highgui.cvNamedWindow (g.win_name, highgui.CV_WINDOW_AUTOSIZE);
## create the trackbar
highgui.cvCreateTrackbar (g.trackbar_name, g.win_name, 1, 100, @on_trackbar);
## show the image
on_trackbar (0);
## wait a key pressed to end
highgui.cvWaitKey (0);

View File

@ -1,143 +0,0 @@
#! /usr/bin/env octave
## This program is demonstration for face and object detection using haar-like features.
## The program finds faces in a camera image or video stream and displays a red box around them.
## Original C implementation by: ?
## Python implementation by: Roman Stanchak
## Octave implementation by: Xavier Delacour
addpath("/home/x/opencv2/interfaces/swig/octave");
source("/home/x/opencv2/interfaces/swig/octave/PKG_ADD_template");
debug_on_error(true);
debug_on_warning(true);
crash_dumps_octave_core (0)
cv;
highgui;
## Global Variables
global g;
g.cascade = [];
g.storage = cvCreateMemStorage(0);
g.cascade_name = "../../data/haarcascades/haarcascade_frontalface_alt.xml";
g.input_name = "../c/lena.jpg";
## Parameters for haar detection
## From the API:
## The default parameters (scale_factor=1.1, min_neighbors=3, flags=0) are tuned
## for accurate yet slow object detection. For a faster operation on real video
## images the settings are:
## scale_factor=1.2, min_neighbors=2, flags=CV_HAAR_DO_CANNY_PRUNING,
## min_size=<minimum possible face size
g.min_size = cvSize(20,20);
g.image_scale = 1.3;
g.haar_scale = 1.2;
g.min_neighbors = 2;
g.haar_flags = 0;
function detect_and_draw( img )
global g;
global cv;
gray = cvCreateImage( cvSize(img.width,img.height), 8, 1 );
small_img = cvCreateImage( cvSize( cvRound (img.width/g.image_scale),
cvRound (img.height/g.image_scale)), 8, 1 );
cvCvtColor( img, gray, cv.CV_BGR2GRAY );
cvResize( gray, small_img, cv.CV_INTER_LINEAR );
cvEqualizeHist( small_img, small_img );
cvClearMemStorage( g.storage );
if( swig_this(g.cascade) )
tic
faces = cvHaarDetectObjects( small_img, g.cascade, g.storage,
g.haar_scale, g.min_neighbors, g.haar_flags, g.min_size );
toc
if (swig_this(faces))
for r = CvSeq_map(faces),
r = r{1};
pt1 = cvPoint( int32(r.x*g.image_scale), int32(r.y*g.image_scale));
pt2 = cvPoint( int32((r.x+r.width)*g.image_scale), int32((r.y+r.height)*g.image_scale) );
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
endfor
endif
endif
cvShowImage( "result", img );
endfunction
if (size(argv, 2) > 0 && (strcmp(argv(){1}, "--help") || strcmp(argv(){1}, "-h")))
printf("Usage: facedetect --cascade \"<cascade_path>\" [filename|camera_index]\n");
exit(-1);
endif
if (size(argv, 2) >= 2)
if (strcmp(argv(){1},"--cascade"))
g.cascade_name = argv(){2};
if (size(argv, 2) >= 3)
g.input_name = argv(){3};
endif
endif
elseif (size(argv, 2) == 1)
g.input_name = argv(){1};
endif
## the OpenCV API says this function is obsolete, but we can't
## cast the output of cvLoad to a HaarClassifierCascade, so use this anyways
## the size parameter is ignored
g.cascade = cvLoadHaarClassifierCascade( g.cascade_name, cvSize(1,1) );
if (!swig_this(g.cascade))
printf("ERROR: Could not load classifier cascade\n");
exit(-1);
endif
g.input_name
if (all(isdigit(g.input_name)))
capture = cvCreateCameraCapture( sscanf(g.input_name, "%i") );
else
capture = cvCreateFileCapture( g.input_name );
endif
capture
cvNamedWindow( "result", 1 );
if( swig_this(capture) )
frame_copy = [];
while (true)
frame = cvQueryFrame( capture );
if( ! swig_this(frame) )
cvWaitKey(0);
endif
if( !swig_this(frame_copy) )
frame_copy = cvCreateImage( cvSize(frame.width,frame.height),
IPL_DEPTH_8U, frame.nChannels );
endif
if( frame.origin == IPL_ORIGIN_TL )
cvCopy( frame, frame_copy );
else
cvFlip( frame, frame_copy, 0 );
endif
detect_and_draw( frame_copy );
if( cvWaitKey( 10 ) == 27 )
break;
endif
endwhile
else
image = cvLoadImage( g.input_name, 1 );
if( swig_this(image) )
detect_and_draw( image );
cvWaitKey(0);
endif
endif
cvDestroyWindow("result");

View File

@ -1,179 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global g;
g.color_img0 = [];
g.mask = [];
g.color_img = [];
g.gray_img0 = [];
g.gray_img = [];
g.ffill_case = 1;
g.lo_diff = 20
g.up_diff = 20;
g.connectivity = 4;
g.is_color = 1;
g.is_mask = 0;
g.new_mask_val = 255;
function ret = randint(v1, v2)
ret = int32(rand() * (v2 - v1) + v1);
end
function update_lo( pos )
g.lo_diff = pos;
endfunction
function update_up( pos )
g.up_diff = pos;
endfunction
function on_mouse( event, x, y, flags, param )
global g;
global cv;
global highgui;
if( !swig_this(g.color_img) )
return;
endif
if (event == highgui.CV_EVENT_LBUTTONDOWN)
comp = cv.CvConnectedComp();
my_mask = [];
seed = cvPoint(x,y);
if (g.ffill_case==0)
lo = 0;
up = 0;
flags = g.connectivity + bitshift(g.new_mask_val,8);
else
lo = g.lo_diff;
up = g.up_diff;
flags = g.connectivity + bitshift(g.new_mask_val,8) + \
cv.CV_FLOODFILL_FIXED_RANGE;
endif
color = CV_RGB( randint(0,255), randint(0,255), randint(0,255) );
if( g.is_mask )
my_mask = g.mask;
cvThreshold( g.mask, g.mask, 1, 128, cv.CV_THRESH_BINARY );
endif
if( g.is_color )
cv.cvFloodFill( g.color_img, seed, color, cv.CV_RGB( lo, lo, lo ),
CV_RGB( up, up, up ), comp, flags, my_mask );
cvShowImage( "image", g.color_img );
else
brightness = cvRealScalar((r*2 + g*7 + b + 5)/10);
cvFloodFill( g.gray_img, seed, brightness, cvRealScalar(lo),
cvRealScalar(up), comp, flags, my_mask );
cvShowImage( "image", g.gray_img );
endif
printf("%i pixels were repainted\n", comp.area);
if( g.is_mask )
cvShowImage( "mask", g.mask );
endif
endif
endfunction
filename = "../c/fruits.jpg";
if (size(argv, 1)>0)
filename=argv(){1};
endif
g.color_img0 = cvLoadImage(filename,1);
if (!swig_this(g.color_img0))
printf("Could not open %s\n",filename);
exit(-1);
endif
printf("Hot keys:\n");
printf("\tESC - quit the program\n");
printf("\tc - switch color/grayscale mode\n");
printf("\tm - switch mask mode\n");
printf("\tr - restore the original image\n");
printf("\ts - use null-range floodfill\n");
printf("\tf - use gradient floodfill with fixed(absolute) range\n");
printf("\tg - use gradient floodfill with floating(relative) range\n");
printf("\t4 - use 4-g.connectivity mode\n");
printf("\t8 - use 8-g.connectivity mode\n");
g.color_img = cvCloneImage( g.color_img0 );
g.gray_img0 = cvCreateImage( cvSize(g.color_img.width, g.color_img.height), 8, 1 );
cvCvtColor( g.color_img, g.gray_img0, CV_BGR2GRAY );
g.gray_img = cvCloneImage( g.gray_img0 );
g.mask = cvCreateImage( cvSize(g.color_img.width + 2, g.color_img.height + 2), 8, 1 );
cvNamedWindow( "image", 1 );
cvCreateTrackbar( "g.lo_diff", "image", g.lo_diff, 255, @update_lo);
cvCreateTrackbar( "g.up_diff", "image", g.up_diff, 255, @update_up);
cvSetMouseCallback( "image", @on_mouse );
while (true)
if( g.is_color )
cvShowImage( "image", g.color_img );
else
cvShowImage( "image", g.gray_img );
endif
c = cvWaitKey(0);
if (c==27)
printf("Exiting ...\n");
exit(0)
elseif (c=='c')
if( g.is_color )
print("Grayscale mode is set");
cvCvtColor( g.color_img, g.gray_img, CV_BGR2GRAY );
g.is_color = 0;
else
print("Color mode is set");
cvCopy( g.color_img0, g.color_img, [] );
cvZero( g.mask );
g.is_color = 1;
endif
elseif (c=='m')
if( g.is_mask )
cvDestroyWindow( "mask" );
g.is_mask = 0;
else
cvNamedWindow( "mask", 0 );
cvZero( g.mask );
cvShowImage( "mask", g.mask );
g.is_mask = 1;
endif
elseif (c=='r')
printf("Original image is restored");
cvCopy( g.color_img0, g.color_img, [] );
cvCopy( g.gray_img0, g.gray_img, [] );
cvZero( g.mask );
elseif (c=='s')
printf("Simple floodfill mode is set");
g.ffill_case = 0;
elseif (c=='f')
printf("Fixed Range floodfill mode is set");
g.ffill_case = 1;
elseif (c=='g')
printf("Gradient (floating range) floodfill mode is set");
g.ffill_case = 2;
elseif (c=='4')
printf("4-g.connectivity mode is set");
g.connectivity = 4;
elseif (c=='8')
printf("8-g.connectivity mode is set");
g.connectivity = 8;
endif
endwhile

View File

@ -1,123 +0,0 @@
#! /usr/bin/env octave
## This program is demonstration for ellipse fitting. Program finds
## contours and approximate it by ellipses.
## Trackbar specify threshold parametr.
## White lines is contours. Red lines is fitting ellipses.
## Original C implementation by: Denis Burenkov.
## Python implementation by: Roman Stanchak
## Octave implementation by: Xavier Delacour
cv;
highgui;
global g;
g.image02 = [];
g.image03 = [];
g.image04 = [];
function process_image( slider_pos )
global g;
global cv;
global highgui;
## Define trackbar callback functon. This function find contours,
## draw it and approximate it by ellipses.
stor = cv.cvCreateMemStorage(0);
## Threshold the source image. This needful for cv.cvFindContours().
cv.cvThreshold( g.image03, g.image02, slider_pos, 255, cv.CV_THRESH_BINARY );
## Find all contours.
[nb_contours, cont] = cv.cvFindContours (g.image02,stor,cv.sizeof_CvContour,cv.CV_RETR_LIST,cv.CV_CHAIN_APPROX_NONE,cv.cvPoint (0,0));
## Clear images. IPL use.
cv.cvZero(g.image02);
cv.cvZero(g.image04);
## This cycle draw all contours and approximate it by ellipses.
for c = cv.CvSeq_hrange(cont),
c = c{1};
count = c.total; # This is number point in contour
## Number point must be more than or equal to 6 (for cv.cvFitEllipse_32f).
if( count < 6 )
continue;
endif
## Alloc memory for contour point set.
PointArray = cv.cvCreateMat(1, count, cv.CV_32SC2);
PointArray2D32f= cv.cvCreateMat( 1, count, cv.CV_32FC2);
## Get contour point set.
cv.cvCvtSeqToArray(c, PointArray, cv.cvSlice(0, cv.CV_WHOLE_SEQ_END_INDEX));
## Convert CvPoint set to CvBox2D32f set.
cv.cvConvert( PointArray, PointArray2D32f );
box = cv.CvBox2D();
## Fits ellipse to current contour.
box = cv.cvFitEllipse2(PointArray2D32f);
## Draw current contour.
cv.cvDrawContours(g.image04, c, cv.CV_RGB(255,255,255), cv.CV_RGB(255,255,255),0,1,8,cv.cvPoint(0,0));
## Convert ellipse data from float to integer representation.
center = cv.CvPoint();
size = cv.CvSize();
center.x = cv.cvRound(box.center.x);
center.y = cv.cvRound(box.center.y);
size.width = cv.cvRound(box.size.width*0.5);
size.height = cv.cvRound(box.size.height*0.5);
box.angle = -box.angle;
## Draw ellipse.
cv.cvEllipse(g.image04, center, size,box.angle, 0, 360,cv.CV_RGB(0,0,255), 1, cv.CV_AA, 0);
endfor
## Show image. HighGUI use.
highgui.cvShowImage( "Result", g.image04 );
endfunction
argc = size(argv, 1);
filename = "../c/stuff.jpg";
if(argc == 2)
filename = argv(){1};
endif
slider_pos = 70;
## load image and force it to be grayscale
g.image03 = highgui.cvLoadImage(filename, 0);
if (!swig_this( g.image03))
printf("Could not load image %s\n", filename);
exit(-1);
endif
## Create the destination images
g.image02 = cv.cvCloneImage( g.image03 );
g.image04 = cv.cvCloneImage( g.image03 );
## Create windows.
highgui.cvNamedWindow("Source", 1);
highgui.cvNamedWindow("Result", 1);
## Show the image.
highgui.cvShowImage("Source", g.image03);
## Create toolbars. HighGUI use.
highgui.cvCreateTrackbar( "Threshold", "Result", slider_pos, 255, @process_image );
process_image( 1 );
## Wait for a key stroke; the same function arranges events processing
printf("Press any key to exit\n");
highgui.cvWaitKey(0);
highgui.cvDestroyWindow("Source");
highgui.cvDestroyWindow("Result");

View File

@ -1,62 +0,0 @@
#! /usr/bin/env octave
## This is a standalone program. Pass an image name as a first parameter of the program.
cv;
highgui;
## toggle between CV_HOUGH_STANDARD and CV_HOUGH_PROBILISTIC
USE_STANDARD=0;
filename = "../../docs/ref/pics/building.jpg"
if (size(argv, 1)>=1)
filename = argv(){1};
endif
src=cvLoadImage(filename, 0);
if (!swig_this(src))
printf("Error opening image %s\n",filename);
exit(-1);
endif
dst = cvCreateImage( cvGetSize(src), 8, 1 );
color_dst = cvCreateImage( cvGetSize(src), 8, 3 );
storage = cvCreateMemStorage(0);
lines = 0;
cvCanny( src, dst, 50, 200, 3 );
cvCvtColor( dst, color_dst, CV_GRAY2BGR );
if (USE_STANDARD)
lines = cvHoughLines2( dst, storage, CV_HOUGH_STANDARD, 1, CV_PI/180, 100, 0, 0 );
for i=0:min(lines.total, 100)-1,
line = lines{i};
rho = line{0};
theta = line{1};
pt1 = CvPoint();
pt2 = CvPoint();
a = cos(theta);
b = sin(theta);
x0 = a*rho;
y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
cvLine( color_dst, pt1, pt2, CV_RGB(255,0,0), 3, 8 );
endfor
else
lines = cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 50, 50, 10 );
for line = CvSeq_map(lines),
line = line{1};
cvLine( color_dst, line{0}, line{1}, CV_RGB(255,0,0), 3, 8 );
endfor
endif
cvNamedWindow( "Source", 1 );
cvShowImage( "Source", src );
cvNamedWindow( "Hough", 1 );
cvShowImage( "Hough", color_dst );
cvWaitKey(0);

View File

@ -1,84 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global g;
inpaint_mask = [];
g.img0 = [];
g.img = [];
g.inpainted = [];
g.prev_pt = cvPoint(-1,-1);
function on_mouse( event, x, y, flags, param )
global g;
global cv;
global highgui;
if (!swig_this(g.img))
return;
endif
if (event == highgui.CV_EVENT_LBUTTONUP || ! (bitand(flags,highgui.CV_EVENT_FLAG_LBUTTON)))
g.prev_pt = cvPoint(-1,-1);
elseif (event == highgui.CV_EVENT_LBUTTONDOWN)
g.prev_pt = cvPoint(x,y);
elseif (event == highgui.CV_EVENT_MOUSEMOVE && bitand(flags,highgui.CV_EVENT_FLAG_LBUTTON))
pt = cvPoint(x,y);
if (g.prev_pt.x < 0)
g.prev_pt = pt;
endif
cvLine( g.inpaint_mask, g.prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
cvLine( g.img, g.prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
g.prev_pt = pt;
cvShowImage( "image", g.img );
endif
endfunction
filename = "../c/fruits.jpg";
if (size(argv, 1)>=1)
filename = argv(){1};
endif
g.img0 = cvLoadImage(filename,-1);
if (!swig_this(g.img0))
printf("Can't open image '%s'\n", filename);
exit(1);
endif
printf("Hot keys:\n");
printf("\tESC - quit the program\n");
printf("\tr - restore the original image\n");
printf("\ti or ENTER - run inpainting algorithm\n");
printf("\t\t(before running it, paint something on the image)\n");
cvNamedWindow( "image", 1 );
g.img = cvCloneImage( g.img0 );
g.inpainted = cvCloneImage( g.img0 );
g.inpaint_mask = cvCreateImage( cvGetSize(g.img), 8, 1 );
cvZero( g.inpaint_mask );
cvZero( g.inpainted );
cvShowImage( "image", g.img );
cvShowImage( "watershed transform", g.inpainted );
cvSetMouseCallback( "image", @on_mouse, [] );
while (true)
c = cvWaitKey(0);
if( c == 27 || c=='q')
break;
endif
if( c == 'r' )
cvZero( g.inpaint_mask );
cvCopy( g.img0, g.img );
cvShowImage( "image", g.img );
endif
if( c == 'i' || c == '\012' )
cvNamedWindow( "g.inpainted image", 1 );
cvInpaint( g.img, g.inpaint_mask, g.inpainted, 3, CV_INPAINT_TELEA );
cvShowImage( "g.inpainted image", g.inpainted );
endif
endwhile

View File

@ -1,102 +0,0 @@
#! /usr/bin/env octave
## Tracking of rotating point.
## Rotation speed is constant.
## Both state and measurements vectors are 1D (a point angle),
## Measurement is the real point angle + gaussian noise.
## The real and the estimated points are connected with yellow line segment,
## the real and the measured points are connected with red line segment.
## (if Kalman filter works correctly,
## the yellow segment should be shorter than the red one).
## Pressing any key (except ESC) will reset the tracking with a different speed.
## Pressing ESC will stop the program.
cv;
highgui;
global img;
function ret=calc_point(angle)
global img;
ret=cvPoint( cvRound(img.width/2 + img.width/3*cos(angle)), \
cvRound(img.height/2 - img.width/3*sin(angle)));
endfunction
function draw_cross( center, color, d )
global img;
global CV_AA;
cvLine( img, cvPoint( center.x - d, center.y - d ),
cvPoint( center.x + d, center.y + d ), color, 1, CV_AA, 0);
cvLine( img, cvPoint( center.x + d, center.y - d ),
cvPoint( center.x - d, center.y + d ), \
color, 1, CV_AA, 0 );
endfunction
A = [ 1, 1; 0, 1 ];
img = cvCreateImage( cvSize(500,500), 8, 3 );
kalman = cvCreateKalman( 2, 1, 0 );
state = cvCreateMat( 2, 1, CV_32FC1 ); # (phi, delta_phi)
process_noise = cvCreateMat( 2, 1, CV_32FC1 );
measurement = cvCreateMat( 1, 1, CV_32FC1 );
rng = cvRNG(-1);
code = -1;
cvZero( measurement );
cvNamedWindow( "Kalman", 1 );
while (true),
cvRandArr( rng, state, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) );
kalman.transition_matrix = mat2cv(A, CV_32FC1);
cvSetIdentity( kalman.measurement_matrix, cvRealScalar(1) );
cvSetIdentity( kalman.process_noise_cov, cvRealScalar(1e-5) );
cvSetIdentity( kalman.measurement_noise_cov, cvRealScalar(1e-1) );
cvSetIdentity( kalman.error_cov_post, cvRealScalar(1));
cvRandArr( rng, kalman.state_post, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) );
while (true),
state_angle = state(0);
state_pt = calc_point(state_angle);
prediction = cvKalmanPredict( kalman );
predict_angle = prediction(0);
predict_pt = calc_point(predict_angle);
cvRandArr( rng, measurement, CV_RAND_NORMAL, cvRealScalar(0), \
cvRealScalar(sqrt(kalman.measurement_noise_cov(0))) );
## generate measurement
cvMatMulAdd( kalman.measurement_matrix, state, measurement, measurement );
measurement_angle = measurement(0);
measurement_pt = calc_point(measurement_angle);
## plot points
cvZero( img );
draw_cross( state_pt, CV_RGB(255,255,255), 3 );
draw_cross( measurement_pt, CV_RGB(255,0,0), 3 );
draw_cross( predict_pt, CV_RGB(0,255,0), 3 );
cvLine( img, state_pt, measurement_pt, CV_RGB(255,0,0), 3, CV_AA, 0 );
cvLine( img, state_pt, predict_pt, CV_RGB(255,255,0), 3, CV_AA, 0 );
cvKalmanCorrect( kalman, measurement );
cvRandArr( rng, process_noise, CV_RAND_NORMAL, cvRealScalar(0), \
cvRealScalar(sqrt(kalman.process_noise_cov(0)(0))));
cvMatMulAdd( kalman.transition_matrix, state, process_noise, state );
cvShowImage( "Kalman", img );
code = cvWaitKey( 100 );
if( code > 0 )
break;
endif
endwhile
if( code == '\x1b' || code == 'q' || code == 'Q' )
break;
endif
endwhile
cvDestroyWindow("Kalman");

View File

@ -1,72 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
MAX_CLUSTERS=5;
function ret = randint(v1, v2)
ret = int32(rand() * (v2 - v1) + v1);
end
color_tab = { \
CV_RGB(255,0,0), \
CV_RGB(0,255,0), \
CV_RGB(100,100,255), \
CV_RGB(255,0,255), \
CV_RGB(255,255,0)};
img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
rng = cvRNG(-1);
cvNamedWindow( "clusters", 1 );
while (true),
cluster_count = randint(2, MAX_CLUSTERS);
sample_count = randint(1, 1000);
points = cvCreateMat( sample_count, 1, CV_32FC2 );
clusters = cvCreateMat( sample_count, 1, CV_32SC1 );
## generate random sample from multigaussian distribution
for k=0:cluster_count-1,
center = CvPoint();
center.x = mod(cvRandInt(rng), img.width);
center.y = mod(cvRandInt(rng), img.height);
first = k*sample_count/cluster_count;
last = sample_count;
if (k != cluster_count)
last = (k+1)*sample_count/cluster_count;
endif
point_chunk = cvGetRows(points, first, last);
cvRandArr( rng, point_chunk, CV_RAND_NORMAL, \
cvScalar(center.x,center.y,0,0), \
cvScalar(img.width*0.1,img.height*0.1,0,0));
endfor
## shuffle samples
cvRandShuffle( points, rng );
cvKMeans2( points, cluster_count, clusters, \
cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ));
cvZero( img );
for i=0:sample_count-1,
cluster_idx = clusters(i);
pt = points(i);
cvCircle( img, pt, 2, color_tab{cluster_idx + 1}, CV_FILLED, CV_AA, 0 );
cvCircle( img, pt, 2, color_tab{cluster_idx + 1}, CV_FILLED, CV_AA, 0 );
endfor
cvShowImage( "clusters", img );
key = cvWaitKey(0);
if( key == 27 || key == 'q' || key == 'Q' )
break;
endif
endwhile
cvDestroyWindow( "clusters" );

View File

@ -1,65 +0,0 @@
#! /usr/bin/env octave
addpath("/home/x/opencv2/interfaces/swig/octave");
source("/home/x/opencv2/interfaces/swig/octave/PKG_ADD_template");
debug_on_error(true);
debug_on_warning(true);
crash_dumps_octave_core (0)
cv;
highgui;
laplace = [];
colorlaplace = [];
planes = { [], [], [] };
capture = [];
if (size(argv, 2)==0)
capture = cvCreateCameraCapture( -1 );
elseif (size(argv, 2)==1 && all(isdigit(argv(){1})))
capture = cvCreateCameraCapture( int32(argv(){1}) );
elseif (size(argv, 2)==1)
capture = cvCreateFileCapture( argv(){1} );
endif
if (!swig_this(capture))
printf("Could not initialize capturing...\n");
exit(-1)
endif
cvNamedWindow( "Laplacian", 1 );
while (true),
frame = cvQueryFrame( capture );
if (!swig_this(frame))
break
endif
if (!swig_this(laplace))
for i=1:size(planes,2),
planes{i} = cvCreateImage( \
cvSize(frame.width,frame.height), \
8, 1 );
endfor
laplace = cvCreateImage( cvSize(frame.width,frame.height), IPL_DEPTH_16S, 1 );
colorlaplace = cvCreateImage( \
cvSize(frame.width,frame.height), \
8, 3 );
endif
cvSplit( frame, planes{1}, planes{2}, planes{3}, [] );
for plane = planes,
plane = plane{1};
cvLaplace( plane, laplace, 3 );
cvConvertScaleAbs( laplace, plane, 1, 0 );
endfor
cvMerge( planes{1}, planes{2}, planes{3}, [], colorlaplace );
# colorlaplace.origin = frame.origin;
cvShowImage("Laplacian", colorlaplace );
if (cvWaitKey(10) == 27)
break;
endif
endwhile
cvDestroyWindow("Laplacian");

View File

@ -1,219 +0,0 @@
#! /usr/bin/env octave
printf("OpenCV Octave version of lkdemo\n");
## import the necessary things for OpenCV
cv;
highgui;
#############################################################################
## some "constants"
win_size = 10;
MAX_COUNT = 500;
#############################################################################
## some "global" variables
global g;
g.image = [];
g.pt = [];
g.add_remove_pt = false;
g.flags = 0;
g.night_mode = false;
g.need_to_init = true;
g
#############################################################################
## the mouse callback
## the callback on the trackbar
function on_mouse (event, x, y, flags, param)
global g;
global cv;
global highgui;
if (swig_this(g.image) == 0)
## not initialized, so skip
return;
endif
if (g.image.origin != 0)
## different origin
y = g.image.height - y;
endif
if (event == highgui.CV_EVENT_LBUTTONDOWN)
## user has click, so memorize it
pt = cv.cvPoint (x, y);
g.add_remove_pt = true;
endif
endfunction
#############################################################################
## so, here is the main part of the program
filename = "/home/x/work/sneaker/dvgrab-001.avi";
if (size(argv, 1)>1)
filename=argv(){1};
endif
capture = highgui.cvCreateFileCapture (filename);
## check that capture device is OK
if (!swig_this(capture))
printf("Error opening capture device\n");
exit(1)
endif
## display a small howto use it
printf("Hot keys: \n");
printf("\tESC - quit the program\n");
printf("\tr - auto-initialize tracking\n");
printf("\tc - delete all the points\n");
printf("\tn - switch the \"night\" mode on/off\n");
printf("To add/remove a feature point click it\n");
## first, create the necessary windows
highgui.cvNamedWindow ('LkDemo', 1);
## register the mouse callback
highgui.cvSetMouseCallback ('LkDemo', @on_mouse, []);
while (1)
## do forever
## 1. capture the current image
frame = highgui.cvQueryFrame (capture);
if (swig_this(frame) == 0)
## no image captured... end the processing
break
endif
if (swig_this(g.image) == 0),
## create the images we need
g.image = cv.cvCreateImage (cv.cvGetSize (frame), 8, 3);
# g.image.origin = frame.origin;
g.grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1);
g.prev_grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1);
g.pyramid = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1);
g.prev_pyramid = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1);
g.points = {[], []};
endif
## copy the frame, so we can draw on it
cv.cvCopy (frame, g.image)
## create a grey version of the image
cv.cvCvtColor (g.image, g.grey, cv.CV_BGR2GRAY)
if (g.night_mode)
## night mode: only display the points
cv.cvSetZero (g.image);
endif
if (g.need_to_init)
## we want to search all the good points
## create the wanted images
eig = cv.cvCreateImage (cv.cvGetSize (g.grey), 32, 1);
temp = cv.cvCreateImage (cv.cvGetSize (g.grey), 32, 1);
## the default parameters
quality = 0.01;
min_distance = 10;
## search the good points
g.points {1} = cv.cvGoodFeaturesToTrack (g.grey, eig, temp,MAX_COUNT,quality, min_distance, [], 3, 0, 0.04);
## refine the corner locations
cv.cvFindCornerSubPix (g.grey,g.points {1},cv.cvSize (win_size, win_size), cv.cvSize (-1, -1),cv.cvTermCriteria (cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS,20, 0.03));
elseif (size (g.points {1}, 2) > 0)
## we have points, so display them
## calculate the optical flow
[tmp, status] = cv.cvCalcOpticalFlowPyrLK (g.prev_grey, g.grey, g.prev_pyramid, g.pyramid,g.points {1}, size (g.points {1},2),cv.cvSize (win_size, win_size), 3,size (g.points {1}, 2),[],cv.cvTermCriteria (bitor(cv.CV_TERMCRIT_ITER,cv.CV_TERMCRIT_EPS),20, 0.03),g.flags);
g.points {2} = tmp;
## initializations
point_counter = -1;
new_points = {};
for the_point = g.points {2},
the_point = the_point{1};
## go trough all the points
## increment the counter
point_counter += 1;
if (g.add_remove_pt)
## we have a point to add, so see if it is close to
## another one. If yes, don't use it
dx = pt.x - the_point.x;
dy = pt.y - the_point.y;
if (dx * dx + dy * dy <= 25)
## too close
g.add_remove_pt = 0;
continue;
endif
endif
if (!status {point_counter+1})
## we will disable this point
continue;
endif
## this point is a correct point
new_points{end+1} = the_point;
## draw the current point
cv.cvCircle (g.image, {the_point.x, the_point.y},3, cv.cvScalar (0, 255, 0, 0),-1, 8, 0);
endfor
## set back the points we keep;
points {1} = new_points;
endif
if (g.add_remove_pt)
## we want to add a point
points {1} = append (points {1}, cv.cvPointTo32f (pt));
## refine the corner locations
g.points {1} = cv.cvFindCornerSubPix \
(g.grey, {points {1}}, cv.cvSize (win_size, win_size), cv.cvSize \
(-1, -1), cv.cvTermCriteria (bitor(cv.CV_TERMCRIT_ITER, cv.CV_TERMCRIT_EPS),20, 0.03));
## we are no more in "add_remove_pt" mode
g.add_remove_pt = false
endif
## swapping
tmp = g.prev_grey; g.prev_grey = g.grey; g.grey = tmp;
tmp = g.prev_pyramid; g.prev_pyramid = g.pyramid; g.pyramid = tmp;
tmp = g.points{1}; g.points{1} = g.points{2}; g.points{2} = tmp;
g.need_to_init = false;
## we can now display the image
highgui.cvShowImage ('LkDemo', g.image)
## handle events
c = highgui.cvWaitKey (10);
if (c == 27)
## user has press the ESC key, so exit
break
endif
## processing depending on the character
if (c == int32('r'))
g.need_to_init = true;
elseif (c == int32('c'))
g.points = {[], []};
elseif (c == int32('n'))
g.night_mode = !g.night_mode;
endif
endwhile

View File

@ -1,50 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global g;
g.src=[];
g.dst=[];
g.src2=[];
function on_mouse( event, x, y, flags, param )
global g;
global cv;
global highgui;
if(!swig_this(g.src) )
return;
endif
if (event==highgui.CV_EVENT_LBUTTONDOWN)
cvLogPolar( g.src, g.dst, cvPoint2D32f(x,y), 40, cv.CV_INTER_LINEAR+cv.CV_WARP_FILL_OUTLIERS );
cvLogPolar( g.dst, g.src2, cvPoint2D32f(x,y), 40, cv.CV_INTER_LINEAR+cv.CV_WARP_FILL_OUTLIERS+cv.CV_WARP_INVERSE_MAP );
cvShowImage( "log-polar", g.dst );
cvShowImage( "inverse log-polar", g.src2 );
endif
endfunction
filename = "../c/fruits.jpg"
if (size(argv, 1)>1)
filename=argv(){1};
endif
g.src = cvLoadImage(filename,1);
if (!swig_this(g.src))
printf("Could not open %s",filename);
exit(-1)
endif
cvNamedWindow( "original",1 );
cvNamedWindow( "log-polar", 1 );
cvNamedWindow( "inverse log-polar", 1 );
g.dst = cvCreateImage( cvSize(256,256), 8, 3 );
g.src2 = cvCreateImage( cvGetSize(g.src), 8, 3 );
cvSetMouseCallback( "original", @on_mouse );
on_mouse( CV_EVENT_LBUTTONDOWN, g.src.width/2, g.src.height/2, [], []);
cvShowImage( "original", g.src );
cvWaitKey();

View File

@ -1,85 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
function ret = randint(a, b)
ret = int32(rand() * (b - a) + a);
endfunction
function minarea_array(img, count)
global cv;
global highgui;
pointMat = cvCreateMat( count, 1, cv.CV_32SC2 );
for i=0:count-1,
pointMat(i) = cvPoint( randint(img.width/4, img.width*3/4), randint(img.height/4, img.height*3/4) );
endfor
box = cvMinAreaRect2( pointMat );
box_vtx = cvBoxPoints( box );
[success, center, radius] = cvMinEnclosingCircle( pointMat );
cv.cvZero( img );
for i=0:count-1,
cvCircle( img, cvGet1D(pointMat,i), 2, CV_RGB( 255, 0, 0 ), \
cv.CV_FILLED, cv.CV_AA, 0 );
endfor
box_vtx = {cvPointFrom32f(box_vtx{1}), \
cvPointFrom32f(box_vtx{2}), \
cvPointFrom32f(box_vtx{3}), \
cvPointFrom32f(box_vtx{4})};
cvCircle( img, cvPointFrom32f(center), cvRound(radius), CV_RGB(255, 255, 0), 1, cv.CV_AA, 0 );
cvPolyLine( img, {box_vtx}, 1, CV_RGB(0,255,255), 1, cv.CV_AA ) ;
endfunction
function minarea_seq(img, count, storage)
global cv;
global highgui;
ptseq = cvCreateSeq( bitor(cv.CV_SEQ_KIND_GENERIC, cv.CV_32SC2), cv.sizeof_CvContour, cv.sizeof_CvPoint, storage );
ptseq = cv.CvSeq_CvPoint.cast( ptseq );
for i=0:count-1,
pt0 = cvPoint( randint(img.width/4, img.width*3/4), randint(img.height/4, img.height*3/4) );
cvSeqPush( ptseq, pt0 );
endfor
box = cvMinAreaRect2( ptseq );
box_vtx = cvBoxPoints( box );
[success, center, radius] = cvMinEnclosingCircle( ptseq );
cv.cvZero( img );
for pt = CvSeq_map(ptseq),
pt = pt{1};
cvCircle( img, pt, 2, CV_RGB( 255, 0, 0 ), cv.CV_FILLED, cv.CV_AA, 0 );
endfor
box_vtx = {cvPointFrom32f(box_vtx{1}), \
cvPointFrom32f(box_vtx{2}), \
cvPointFrom32f(box_vtx{3}), \
cvPointFrom32f(box_vtx{4})};
cvCircle( img, cvPointFrom32f(center), cvRound(radius), CV_RGB(255, 255, 0), 1, cv.CV_AA, 0 );
cvPolyLine( img, {box_vtx}, 1, CV_RGB(0,255,255), 1, cv.CV_AA );
cvClearMemStorage( storage );
endfunction
img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
storage = cvCreateMemStorage(0);
cvNamedWindow( "rect & circle", 1 );
use_seq=false;
while (true),
count = randint(1,100);
if (use_seq)
minarea_seq(img, count, storage);
else
minarea_array(img, count);
endif
cvShowImage("rect & circle", img);
key = cvWaitKey();
if( key == '\x1b' );
break;
endif
use_seq = !use_seq;
endwhile

View File

@ -1,15 +0,0 @@
#! /usr/bin/env octave
cvNamedWindow("win", CV_WINDOW_AUTOSIZE);
cap = cvCreateFileCapture("/home/x/work/sneaker/dvgrab-001.avi");
img = cvQueryFrame(cap);
printf("Got frame of dimensions (%i x %i)",img.width,img.height);
cvShowImage("win", img);
cvMoveWindow("win", 200, 200);
cvWaitKey(0);
octimg = cv2im(img);

View File

@ -1,86 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global src;
global image
global element
global element_shape
global global_pos;
global dest;
src = 0;
image = 0;
dest = 0;
element = 0;
element_shape = CV_SHAPE_RECT;
global_pos = 0;
function Opening(pos)
global src;
global image
global element
global element_shape
global global_pos;
global dest;
element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
cvErode(src,image,element,1);
cvDilate(image,dest,element,1);
cvShowImage("Opening&Closing window",dest);
endfunction
function Closing(pos)
global src;
global image
global element
global element_shape
global global_pos;
global dest;
element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
cvDilate(src,image,element,1);
cvErode(image,dest,element,1);
cvShowImage("Opening&Closing window",dest);
endfunction
function Erosion(pos)
global src;
global image
global element
global element_shape
global global_pos;
global dest;
element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
cvErode(src,dest,element,1);
cvShowImage("Erosion&Dilation window",dest);
endfunction
function Dilation(pos)
global src;
global image
global element
global element_shape
global global_pos;
global dest;
element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
cvDilate(src,dest,element,1);
cvShowImage("Erosion&Dilation window",dest);
endfunction
filename = "../c/baboon.jpg";
if (size(argv, 1)==1)
filename = argv(){1};
endif
src = cvLoadImage(filename,1);
if (! swig_this(src))
exit(-1);
endif
image = cvCloneImage(src);
dest = cvCloneImage(src);
cvNamedWindow("Opening&Closing window",1);
cvNamedWindow("Erosion&Dilation window",1);
cvShowImage("Opening&Closing window",src);
cvShowImage("Erosion&Dilation window",src);
cvCreateTrackbar("Open","Opening&Closing window",global_pos,10,@Opening);
cvCreateTrackbar("Close","Opening&Closing window",global_pos,10,@Closing);
cvCreateTrackbar("Dilate","Erosion&Dilation window",global_pos,10,@Dilation);
cvCreateTrackbar("Erode","Erosion&Dilation window",global_pos,10,@Erosion);
cvWaitKey(0);
cvDestroyWindow("Opening&Closing window");
cvDestroyWindow("Erosion&Dilation window");

View File

@ -1,126 +0,0 @@
#! /usr/bin/env octave
cv
highgui
CLOCKS_PER_SEC = 1.0
MHI_DURATION = 1;
MAX_TIME_DELTA = 0.5;
MIN_TIME_DELTA = 0.05;
N = 4;
buf = range(10)
last = 0;
mhi = []; # MHI
orient = []; # orientation
mask = []; # valid orientation mask
segmask = []; # motion segmentation map
storage = []; # temporary storage
function update_mhi( img, dst, diff_threshold )
global last
global mhi
global storage
global mask
global orient
global segmask
timestamp = time.clock()/CLOCKS_PER_SEC; # get current time in seconds
size = cvSize(img.width,img.height); # get current frame size
idx1 = last;
if (! mhi || mhi.width != size.width || mhi.height != size.height)
for i=0:N-1,
buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
cvZero( buf[i] );
mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
cvZero( mhi ); # clear MHI at the beginning
orient = cvCreateImage( size, IPL_DEPTH_32F, 1 );
segmask = cvCreateImage( size, IPL_DEPTH_32F, 1 );
mask = cvCreateImage( size, IPL_DEPTH_8U, 1 );
cvCvtColor( img, buf[last], CV_BGR2GRAY ); # convert frame to grayscale
idx2 = (last + 1) % N; # index of (last - (N-1))th frame
last = idx2;
silh = buf[idx2];
cvAbsDiff( buf[idx1], buf[idx2], silh ); # get difference between frames
cvThreshold( silh, silh, diff_threshold, 1, CV_THRESH_BINARY ); # and threshold it
cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ); # update MHI
cvCvtScale( mhi, mask, 255./MHI_DURATION,
(MHI_DURATION - timestamp)*255./MHI_DURATION );
cvZero( dst );
cvMerge( mask, [], [], [], dst );
cvCalcMotionGradient( mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3 );
if( not storage )
storage = cvCreateMemStorage(0);
else
cvClearMemStorage(storage);
seq = cvSegmentMotion( mhi, segmask, storage, timestamp, MAX_TIME_DELTA );
for i=-1:seq.total-1,
if( i < 0 ) # case of the whole image
comp_rect = cvRect( 0, 0, size.width, size.height );
color = CV_RGB(255,255,255);
magnitude = 100.;
else # i-th motion component
comp_rect = seq[i].rect
if( comp_rect.width + comp_rect.height < 100 ) # reject very small components
continue;
endif
endif
color = CV_RGB(255,0,0);
magnitude = 30.;
silh_roi = cvGetSubRect(silh, comp_rect);
mhi_roi = cvGetSubRect( mhi, comp_rect );
orient_roi = cvGetSubRect( orient, comp_rect );
mask_roi = cvGetSubRect( mask, comp_rect );
angle = cvCalcGlobalOrientation( orient_roi, mask_roi, mhi_roi, timestamp, MHI_DURATION);
angle = 360.0 - angle; # adjust for images with top-left origin
count = cvNorm( silh_roi, [], CV_L1, [] ); # calculate number of points within silhouette ROI
if( count < comp_rect.width * comp_rect.height * 0.05 )
continue;
endif
center = cvPoint( (comp_rect.x + comp_rect.width/2),
(comp_rect.y + comp_rect.height/2) );
cvCircle( dst, center, cvRound(magnitude*1.2), color, 3, CV_AA, 0 );
cvLine( dst, center, cvPoint( cvRound( center.x + magnitude*cos(angle*CV_PI/180)),
cvRound( center.y - magnitude*sin(angle*CV_PI/180))), \
color, 3, CV_AA, 0 );
endfor
endif
endfor
endif
endfunction
motion = 0;
capture = 0;
if (size(argv, 1)==1)
capture = cvCreateCameraCapture( 0 )
elseif (size(argv, 1)==2 && all(isdigit(argv(1, :))))
capture = cvCreateCameraCapture( int32(argv(1, :)) )
elseif (size(argv, 1)==2)
capture = cvCreateFileCapture( argv(1, :) );
endif
if (!capture)
print "Could not initialize capturing..."
exit(-1)
endif
cvNamedWindow( "Motion", 1 );
while (true)
image = cvQueryFrame( capture );
if( image )
if( ! motion )
motion = cvCreateImage( cvSize(image.width,image.height), 8, 3 );
cvZero( motion );
motion.origin = image.origin;
endif
update_mhi( image, motion, 30 );
cvShowImage( "Motion", motion );
if( cvWaitKey(10) != -1 )
break;
endif
else
break
endif
endwhile
cvDestroyWindow( "Motion" );

View File

@ -1,71 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global g;
g.image0 = [];
g.image1 = [];
g.threshold1 = 255;
g.threshold2 = 30;
g.l = g.level = 4;
g.block_size = 1000;
g.filter = CV_GAUSSIAN_5x5;
g.storage = [];
g.min_comp = CvConnectedComp();
function set_thresh1( val )
global g;
g.threshold1 = val;
ON_SEGMENT();
endfunction
function set_thresh2( val )
global g;
g.threshold2 = val;
ON_SEGMENT()
endfunction
function ON_SEGMENT()
global g;
global cv;
g
swig_this(g.image0)
swig_this(g.image1)
swig_this(g.storage)
g.level
g.threshold1
g.threshold2
comp = cv.cvPyrSegmentation(g.image0, g.image1, g.storage, g.level, g.threshold1+1, g.threshold2+1);
cvShowImage("Segmentation", g.image1);
endfunction
filename = "../c/fruits.jpg";
if (size(argv, 2) >= 1)
filename = argv(){1};
endif
g.image0 = cvLoadImage( filename, 1);
if (! swig_this(g.image0))
printf("Error opening %s\n",filename);
exit(-1);
endif
cvNamedWindow("Source", 0);
cvShowImage("Source", g.image0);
cvNamedWindow("Segmentation", 0);
g.storage = cvCreateMemStorage ( g.block_size );
new_width = bitshift(g.image0.width, -g.level);
new_height = bitshift(g.image0.height, -g.level);
g.image0 = cvCreateImage( cvSize(new_width,new_height), g.image0.depth, g.image0.nChannels );
g.image1 = cvCreateImage( cvSize(new_width,new_height), g.image0.depth, g.image0.nChannels );
## segmentation of the color image
g.l = 1;
g.threshold1 =255;
g.threshold2 =30;
ON_SEGMENT();
g.sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", g.threshold1, 255, @set_thresh1);
g.sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", g.threshold2, 255, @set_thresh2);
cvShowImage("Segmentation", image1);
cvWaitKey(0);
cvDestroyWindow("Segmentation");
cvDestroyWindow("Source");

View File

@ -1,173 +0,0 @@
#! /usr/bin/env octave
##
## The full "Square Detector" program.
## It loads several images subsequentally and tries to find squares in
## each image
##
cv;
highgui;
global g;
g.thresh = 50;
g.img = [];
g.img0 = [];
g.storage = [];
g.wndname = "Square Detection Demo";
function ret = compute_angle( pt1, pt2, pt0 )
dx1 = pt1.x - pt0.x;
dy1 = pt1.y - pt0.y;
dx2 = pt2.x - pt0.x;
dy2 = pt2.y - pt0.y;
ret = (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
endfunction
function squares = findSquares4( img, storage )
global g;
global cv;
N = 11;
sz = cvSize( img.width, img.height );
timg = cvCloneImage( img ); # make a copy of input image
gray = cvCreateImage( sz, 8, 1 );
pyr = cvCreateImage( cvSize(int32(sz.width/2), int32(sz.height/2)), 8, 3 );
## create empty sequence that will contain points -
## 4 points per square (the square's vertices)
squares = cvCreateSeq( 0, cv.sizeof_CvSeq, cv.sizeof_CvPoint, storage );
squares = cv.CvSeq_CvPoint.cast( squares );
## select the maximum ROI in the image
## with the width and height divisible by 2
subimage = cvGetSubRect( timg, cvRect( 0, 0, sz.width, sz.height ));
## down-scale and upscale the image to filter out the noise
cvPyrDown( subimage, pyr, 7 );
cvPyrUp( pyr, subimage, 7 );
tgray = cvCreateImage( sz, 8, 1 );
## find squares in every color plane of the image
for c=1:3,
## extract the c-th color plane
channels = {[], [], []};
channels{c} = tgray;
cvSplit( subimage, channels{1}, channels{2}, channels{3}, [] ) ;
for l=1:N,
## hack: use Canny instead of zero threshold level.
## Canny helps to catch squares with gradient shading
if( l == 1 )
## apply Canny. Take the upper threshold from slider
## and set the lower to 0 (which forces edges merging)
cvCanny( tgray, gray, 0, g.thresh, 5 );
## dilate canny output to remove potential
## holes between edge segments
cvDilate( gray, gray, [], 1 );
else
## apply threshold if l!=0
## tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0
cvThreshold( tgray, gray, l*255/N, 255, cv.CV_THRESH_BINARY );
endif
## find contours and store them all as a list
[count, contours] = cvFindContours( gray, storage, cv.sizeof_CvContour, cv.CV_RETR_LIST, cv.CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
if (!swig_this(contours))
continue;
endif
## test each contour
for contour = CvSeq_hrange(contours),
## approximate contour with accuracy proportional
## to the contour perimeter
result = cvApproxPoly( contour, cv.sizeof_CvContour, storage, cv.CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0 );
## square contours should have 4 vertices after approximation
## relatively large area (to filter out noisy contours)
## and be convex.
## Note: absolute value of an area is used because
## area may be positive or negative - in accordance with the
## contour orientation
if( result.total == 4 &&
abs(cvContourArea(result)) > 1000 &&
cvCheckContourConvexity(result) )
s = 0;
for i=1:5,
## find minimum angle between joint
## edges (maximum of cosine)
if( i > 2 )
t = abs(compute_angle( result{i}, result{i-2}, result{i-1}));
if (s<t)
s=t;
endif
endif
endfor
## if cosines of all angles are small
## (all angles are ~90 degree) then write quandrange
## vertices to resultant sequence
if( s < 0.3 )
for i=1:4,
squares.append( result{i} )
endfor
endif
endif
endfor
endfor
endfor
endfunction
## the function draws all the squares in the image
function drawSquares( img, squares )
global g;
global cv;
cpy = cvCloneImage( img );
## read 4 sequence elements at a time (all vertices of a square)
i=0;
while (i<squares.total)
pt = { squares{i}, squares{i+1}, squares{i+2}, squares{i+3} };
## draw the square as a closed polyline
cvPolyLine( cpy, {pt}, 1, CV_RGB(0,255,0), 3, cv.CV_AA, 0 );
i+=4;
endwhile
## show the resultant image
cvShowImage( g.wndname, cpy );
endfunction
function on_trackbar( a )
global g;
if( swig_this(g.img) )
drawSquares( g.img, findSquares4( g.img, g.storage ) );
endif
endfunction
g.names = {"../c/pic1.png", "../c/pic2.png", "../c/pic3.png", \
"../c/pic4.png", "../c/pic5.png", "../c/pic6.png" };
## create memory storage that will contain all the dynamic data
g.storage = cvCreateMemStorage(0);
for name = g.names,
g.img0 = cvLoadImage( name, 1 );
if (!swig_this(g.img0))
printf("Couldn't load %s\n",name);
continue;
endif
g.img = cvCloneImage( g.img0 );
## create window and a trackbar (slider) with parent "image" and set callback
## (the slider regulates upper threshold, passed to Canny edge detector)
cvNamedWindow( g.wndname, 1 );
cvCreateTrackbar( "canny thresh", g.wndname, g.thresh, 1000, @on_trackbar );
## force the image processing
on_trackbar(0);
## wait for key.
## Also the function cvWaitKey takes care of event processing
c = cvWaitKey(0);
## clear memory storage - reset free space position
cvClearMemStorage( g.storage );
if( c == '\x1b' )
break;
endif
endfor
cvDestroyWindow( g.wndname );

View File

@ -1,133 +0,0 @@
#! /usr/bin/env octave
cv;
highgui;
global g;
g.marker_mask = [];
g.markers = [];
g.img0 = []
g.img = []
g.img_gray = []
g.wshed = []
g.prev_pt = cvPoint(-1,-1);
function on_mouse( event, x, y, flags, param )
global g;
global cv;
global highgui;
if( !swig_this( g.img) )
return;
endif
if( event == highgui.CV_EVENT_LBUTTONUP || ! bitand(flags,highgui.CV_EVENT_FLAG_LBUTTON) )
g.prev_pt = cvPoint(-1,-1);
elseif( event == highgui.CV_EVENT_LBUTTONDOWN )
g.prev_pt = cvPoint(x,y);
elseif( event == highgui.CV_EVENT_MOUSEMOVE && bitand(flags,highgui.CV_EVENT_FLAG_LBUTTON) )
pt = cvPoint(x,y);
if( g.prev_pt.x < 0 )
g.prev_pt = pt;
endif
cvLine( g.marker_mask, g.prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
cvLine( g.img, g.prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
g.prev_pt = pt;
cvShowImage( "image", g.img );
endif
endfunction
filename = "../c/fruits.jpg";
if (size(argv, 1)>=1)
filename = argv(){1};
endif
rng = cvRNG(-1);
g.img0 = cvLoadImage(filename,1);
if (!swig_this(g.img0))
print "Error opening image '%s'" % filename
exit(-1)
endif
printf("Hot keys:\n");
printf("\tESC - quit the program\n");
printf("\tr - restore the original image\n");
printf("\tw - run watershed algorithm\n");
printf("\t (before that, roughly outline several g.markers on the image)\n");
cvNamedWindow( "image", 1 );
cvNamedWindow( "watershed transform", 1 );
g.img = cvCloneImage( g.img0 );
g.img_gray = cvCloneImage( g.img0 );
g.wshed = cvCloneImage( g.img0 );
g.marker_mask = cvCreateImage( cvGetSize(g.img), 8, 1 );
g.markers = cvCreateImage( cvGetSize(g.img), IPL_DEPTH_32S, 1 );
cvCvtColor( g.img, g.marker_mask, CV_BGR2GRAY );
cvCvtColor( g.marker_mask, g.img_gray, CV_GRAY2BGR );
cvZero( g.marker_mask );
cvZero( g.wshed );
cvShowImage( "image", g.img );
cvShowImage( "watershed transform", g.wshed );
cvSetMouseCallback( "image", @on_mouse, [] );
while (true)
c = cvWaitKey(0);
if (c=='\x1b')
break;
endif
if (c == 'r')
cvZero( g.marker_mask );
cvCopy( g.img0, g.img );
cvShowImage( "image", g.img );
endif
if (c == 'w')
storage = cvCreateMemStorage(0);
comp_count = 0;
##cvSaveImage( "g.wshed_mask.png", g.marker_mask );
##g.marker_mask = cvLoadImage( "g.wshed_mask.png", 0 );
[nb_cont, contours] = cvFindContours( g.marker_mask, storage, \
sizeof_CvContour, \
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
cvZero( g.markers );
swig_this(contours)
while (swig_this(contours))
cvDrawContours( g.markers, contours, cvScalarAll(comp_count+1), \
cvScalarAll(comp_count+1), -1, -1, 8, cvPoint(0,0) );
contours=contours.h_next;
comp_count+=1;
endwhile
comp_count
color_tab = cvCreateMat( comp_count, 1, CV_8UC3 );
for i=0:comp_count-1,
color_tab(i) = cvScalar( mod(cvRandInt(rng),180) + 50, \
mod(cvRandInt(rng),180) + 50, \
mod(cvRandInt(rng),180) + 50 );
endfor
t = int32(cvGetTickCount());
cvWatershed( g.img0, g.markers );
t = int32(cvGetTickCount()) - t;
##print "exec time = %f" % t/(cvGetTickFrequency()*1000.)
cvSet( g.wshed, cvScalarAll(255) );
## paint the watershed image
for j=0:g.markers.height-1,
for i=0:g.markers.width-1,
{j,i}
idx = g.markers({j,i});
if (idx==-1)
continue
endif
idx = idx-1;
g.wshed({j,i}) = color_tab({idx,0});
endfor
endfor
cvAddWeighted( g.wshed, 0.5, g.img_gray, 0.5, 0, g.wshed );
cvShowImage( "watershed transform", g.wshed );
cvWaitKey();
endif
endwhile

View File

@ -1,13 +0,0 @@
# -------------------------------------------------------------------------
# CMake file for Python samples. See root CMakeLists.txt
# -------------------------------------------------------------------------
file(GLOB PYTHON_SAMPLES *.py)
if(NOT WIN32)
install(FILES ${PYTHON_SAMPLES}
DESTINATION share/opencv/samples/python
PERMISSIONS OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
endif()

View File

@ -1,193 +0,0 @@
#! /usr/bin/env python
import sys
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
#############################################################################
# definition of some constants
# how many bins we want for the histogram, and their ranges
hdims = 16
hranges = [[0, 180]]
# ranges for the limitation of the histogram
vmin = 10
vmax = 256
smin = 30
# the range we want to monitor
hsv_min = cv.cvScalar (0, smin, vmin, 0)
hsv_max = cv.cvScalar (180, 256, vmax, 0)
#############################################################################
# some useful functions
def hsv2rgb (hue):
# convert the hue value to the corresponding rgb value
sector_data = [[0, 2, 1],
[1, 2, 0],
[1, 0, 2],
[2, 0, 1],
[2, 1, 0],
[0, 1, 2]]
hue *= 0.1 / 3
sector = cv.cvFloor (hue)
p = cv.cvRound (255 * (hue - sector))
if sector & 1:
p ^= 255
rgb = {}
rgb [sector_data [sector][0]] = 255
rgb [sector_data [sector][1]] = 0
rgb [sector_data [sector][2]] = p
return cv.cvScalar (rgb [2], rgb [1], rgb [0], 0)
#############################################################################
# so, here is the main part of the program
if __name__ == '__main__':
# a small welcome
print "OpenCV Python wrapper test"
print "OpenCV version: %s (%d, %d, %d)" % (cv.CV_VERSION,
cv.CV_MAJOR_VERSION,
cv.CV_MINOR_VERSION,
cv.CV_SUBMINOR_VERSION)
# first, create the necessary windows
highgui.cvNamedWindow ('Camera', highgui.CV_WINDOW_AUTOSIZE)
highgui.cvNamedWindow ('Histogram', highgui.CV_WINDOW_AUTOSIZE)
# move the new window to a better place
highgui.cvMoveWindow ('Camera', 10, 40)
highgui.cvMoveWindow ('Histogram', 10, 270)
try:
# try to get the device number from the command line
device = int (sys.argv [1])
# got it ! so remove it from the arguments
del sys.argv [1]
except (IndexError, ValueError):
# no device number on the command line, assume we want the 1st device
device = 0
if len (sys.argv) == 1:
# no argument on the command line, try to use the camera
capture = highgui.cvCreateCameraCapture (device)
# set the wanted image size from the camera
highgui.cvSetCaptureProperty (capture,
highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
highgui.cvSetCaptureProperty (capture,
highgui.CV_CAP_PROP_FRAME_HEIGHT, 240)
else:
# we have an argument on the command line,
# we can assume this is a file name, so open it
capture = highgui.cvCreateFileCapture (sys.argv [1])
# check that capture device is OK
if not capture:
print "Error opening capture device"
sys.exit (1)
# create an image to put in the histogram
histimg = cv.cvCreateImage (cv.cvSize (320,240), 8, 3)
# init the image of the histogram to black
cv.cvSetZero (histimg)
# capture the 1st frame to get some propertie on it
frame = highgui.cvQueryFrame (capture)
# get some properties of the frame
frame_size = cv.cvGetSize (frame)
# compute which selection of the frame we want to monitor
selection = cv.cvRect (0, 0, frame.width, frame.height)
# create some images usefull later
hue = cv.cvCreateImage (frame_size, 8, 1)
mask = cv.cvCreateImage (frame_size, 8, 1)
hsv = cv.cvCreateImage (frame_size, 8, 3 )
# create the histogram
hist = cv.cvCreateHist ([hdims], cv.CV_HIST_ARRAY, hranges, 1)
while 1:
# do forever
# 1. capture the current image
frame = highgui.cvQueryFrame (capture)
if frame is None:
# no image captured... end the processing
break
# mirror the captured image
cv.cvFlip (frame, None, 1)
# compute the hsv version of the image
cv.cvCvtColor (frame, hsv, cv.CV_BGR2HSV)
# compute which pixels are in the wanted range
cv.cvInRangeS (hsv, hsv_min, hsv_max, mask)
# extract the hue from the hsv array
cv.cvSplit (hsv, hue, None, None, None)
# select the rectangle of interest in the hue/mask arrays
hue_roi = cv.cvGetSubRect (hue, selection)
mask_roi = cv.cvGetSubRect (mask, selection)
# it's time to compute the histogram
cv.cvCalcHist (hue_roi, hist, 0, mask_roi)
# extract the min and max value of the histogram
min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue (hist)
# compute the scale factor
if max_val > 0:
scale = 255. / max_val
else:
scale = 0.
# scale the histograms
cv.cvConvertScale (hist.bins, hist.bins, scale, 0)
# clear the histogram image
cv.cvSetZero (histimg)
# compute the width for each bin do display
bin_w = histimg.width / hdims
for i in range (hdims):
# for all the bins
# get the value, and scale to the size of the hist image
val = cv.cvRound (cv.cvGetReal1D (hist.bins, i)
* histimg.height / 255)
# compute the color
color = hsv2rgb (i * 180. / hdims)
# draw the rectangle in the wanted color
cv.cvRectangle (histimg,
cv.cvPoint (i * bin_w, histimg.height),
cv.cvPoint ((i + 1) * bin_w, histimg.height - val),
color, -1, 8, 0)
# we can now display the images
highgui.cvShowImage ('Camera', frame)
highgui.cvShowImage ('Histogram', histimg)
# handle events
k = highgui.cvWaitKey (10)
if k == '\x1b':
# user has press the ESC key, so exit
break

View File

@ -1,106 +0,0 @@
#! /usr/bin/env python
import sys
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
# the codec existing in cvcapp.cpp,
# need to have a better way to specify them in the future
# WARNING: I have see only MPEG1VIDEO working on my computer
H263 = 0x33363255
H263I = 0x33363249
MSMPEG4V3 = 0x33564944
MPEG4 = 0x58564944
MSMPEG4V2 = 0x3234504D
MJPEG = 0x47504A4D
MPEG1VIDEO = 0x314D4950
AC3 = 0x2000
MP2 = 0x50
FLV1 = 0x31564C46
#############################################################################
# so, here is the main part of the program
if __name__ == '__main__':
# a small welcome
print "OpenCV Python capture video"
# first, create the necessary window
highgui.cvNamedWindow ('Camera', highgui.CV_WINDOW_AUTOSIZE)
# move the new window to a better place
highgui.cvMoveWindow ('Camera', 10, 10)
try:
# try to get the device number from the command line
device = int (sys.argv [1])
# got it ! so remove it from the arguments
del sys.argv [1]
except (IndexError, ValueError):
# no device number on the command line, assume we want the 1st device
device = 0
if len (sys.argv) == 1:
# no argument on the command line, try to use the camera
capture = highgui.cvCreateCameraCapture (device)
else:
# we have an argument on the command line,
# we can assume this is a file name, so open it
capture = highgui.cvCreateFileCapture (sys.argv [1])
# check that capture device is OK
if not capture:
print "Error opening capture device"
sys.exit (1)
# capture the 1st frame to get some propertie on it
frame = highgui.cvQueryFrame (capture)
# get size of the frame
frame_size = cv.cvGetSize (frame)
# get the frame rate of the capture device
fps = highgui.cvGetCaptureProperty (capture, highgui.CV_CAP_PROP_FPS)
if fps == 0:
# no fps getted, so set it to 30 by default
fps = 30
# create the writer
writer = highgui.cvCreateVideoWriter ("captured.mpg", MPEG1VIDEO,
fps, frame_size, True)
# check the writer is OK
if not writer:
print "Error opening writer"
sys.exit (1)
while 1:
# do forever
# 1. capture the current image
frame = highgui.cvQueryFrame (capture)
if frame is None:
# no image captured... end the processing
break
# write the frame to the output file
highgui.cvWriteFrame (writer, frame)
# display the frames to have a visual output
highgui.cvShowImage ('Camera', frame)
# handle events
k = highgui.cvWaitKey (5)
if k % 0x100 == 27:
# user has press the ESC key, so exit
break
# end working with the writer
# not working at this time... Need to implement some typemaps...
# but exiting without calling it is OK in this simple application
#highgui.cvReleaseVideoWriter (writer)

View File

@ -1,18 +0,0 @@
#!/usr/bin/python
from opencv.cv import *
from opencv.highgui import *
import sys
if __name__ == "__main__":
cvNamedWindow("win")
filename = sys.argv[1]
im = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE)
im3 = cvLoadImage(filename, CV_LOAD_IMAGE_COLOR)
chessboard_dim = cvSize( 5, 6 )
found_all, corners = cvFindChessboardCorners( im, chessboard_dim )
cvDrawChessboardCorners( im3, chessboard_dim, corners, found_all )
cvShowImage("win", im3);
cvWaitKey()

View File

@ -1,137 +0,0 @@
#! /usr/bin/env python
print "OpenCV Python version of contours"
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
# some default constants
_SIZE = 500
_DEFAULT_LEVEL = 3
# definition of some colors
_red = cv.cvScalar (0, 0, 255, 0);
_green = cv.cvScalar (0, 255, 0, 0);
_white = cv.cvRealScalar (255)
_black = cv.cvRealScalar (0)
# the callback on the trackbar, to set the level of contours we want
# to display
def on_trackbar (position):
# create the image for putting in it the founded contours
contours_image = cv.cvCreateImage (cv.cvSize (_SIZE, _SIZE), 8, 3)
# compute the real level of display, given the current position
levels = position - 3
# initialisation
_contours = contours
if levels <= 0:
# zero or negative value
# => get to the nearest face to make it look more funny
_contours = contours.h_next.h_next.h_next
# first, clear the image where we will draw contours
cv.cvSetZero (contours_image)
# draw contours in red and green
cv.cvDrawContours (contours_image, _contours,
_red, _green,
levels, 3, cv.CV_AA,
cv.cvPoint (0, 0))
# finally, show the image
highgui.cvShowImage ("contours", contours_image)
if __name__ == '__main__':
# create the image where we want to display results
image = cv.cvCreateImage (cv.cvSize (_SIZE, _SIZE), 8, 1)
# start with an empty image
cv.cvSetZero (image)
# draw the original picture
for i in range (6):
dx = (i % 2) * 250 - 30
dy = (i / 2) * 150
cv.cvEllipse (image,
cv.cvPoint (dx + 150, dy + 100),
cv.cvSize (100, 70),
0, 0, 360, _white, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 115, dy + 70),
cv.cvSize (30, 20),
0, 0, 360, _black, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 185, dy + 70),
cv.cvSize (30, 20),
0, 0, 360, _black, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 115, dy + 70),
cv.cvSize (15, 15),
0, 0, 360, _white, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 185, dy + 70),
cv.cvSize (15, 15),
0, 0, 360, _white, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 115, dy + 70),
cv.cvSize (5, 5),
0, 0, 360, _black, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 185, dy + 70),
cv.cvSize (5, 5),
0, 0, 360, _black, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 150, dy + 100),
cv.cvSize (10, 5),
0, 0, 360, _black, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 150, dy + 150),
cv.cvSize (40, 10),
0, 0, 360, _black, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 27, dy + 100),
cv.cvSize (20, 35),
0, 0, 360, _white, -1, 8, 0)
cv.cvEllipse (image,
cv.cvPoint (dx + 273, dy + 100),
cv.cvSize (20, 35),
0, 0, 360, _white, -1, 8, 0)
# create window and display the original picture in it
highgui.cvNamedWindow ("image", 1)
highgui.cvShowImage ("image", image)
# create the storage area
storage = cv.cvCreateMemStorage (0)
# find the contours
nb_contours, contours = cv.cvFindContours (image,
storage,
cv.sizeof_CvContour,
cv.CV_RETR_TREE,
cv.CV_CHAIN_APPROX_SIMPLE,
cv.cvPoint (0,0))
# comment this out if you do not want approximation
contours = cv.cvApproxPoly (contours, cv.sizeof_CvContour,
storage,
cv.CV_POLY_APPROX_DP, 3, 1)
# create the window for the contours
highgui.cvNamedWindow ("contours", 1)
# create the trackbar, to enable the change of the displayed level
highgui.cvCreateTrackbar ("levels+3", "contours", 3, 7, on_trackbar)
# call one time the callback, so we will have the 1st display done
on_trackbar (_DEFAULT_LEVEL)
# wait a key pressed to end
highgui.cvWaitKey (0)

View File

@ -1,78 +0,0 @@
#! /usr/bin/env python
print "OpenCV Python version of convexhull"
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
# to generate random values
import random
# how many points we want at max
_MAX_POINTS = 100
if __name__ == '__main__':
# main object to get random values from
my_random = random.Random ()
# create the image where we want to display results
image = cv.cvCreateImage (cv.cvSize (500, 500), 8, 3)
# create the window to put the image in
highgui.cvNamedWindow ('hull', highgui.CV_WINDOW_AUTOSIZE)
while True:
# do forever
# get a random number of points
count = my_random.randrange (0, _MAX_POINTS) + 1
# initialisations
points = []
for i in range (count):
# generate a random point
points.append (cv.cvPoint (
my_random.randrange (0, image.width / 2) + image.width / 4,
my_random.randrange (0, image.width / 2) + image.width / 4
))
# compute the convex hull
hull = cv.cvConvexHull2 (points, cv.CV_CLOCKWISE, 0)
# start with an empty image
cv.cvSetZero (image)
for i in range (count):
# draw all the points
cv.cvCircle (image, points [i], 2,
cv.cvScalar (0, 0, 255, 0),
cv.CV_FILLED, cv.CV_AA, 0)
# start the line from the last point
pt0 = points [hull [-1]]
for point_index in hull:
# connect the previous point to the current one
# get the current one
pt1 = points [point_index]
# draw
cv.cvLine (image, pt0, pt1,
cv.cvScalar (0, 255, 0, 0),
1, cv.CV_AA, 0)
# now, current one will be the previous one for the next iteration
pt0 = pt1
# display the final image
highgui.cvShowImage ('hull', image)
# handle events, and wait a key pressed
k = highgui.cvWaitKey (0)
if k == '\x1b':
# user has press the ESC key, so exit
break

View File

@ -1,149 +0,0 @@
#!/usr/bin/python
"""
the script demostrates iterative construction of
delaunay triangulation and voronoi tesselation
Original Author (C version): ?
Converted to Python by: Roman Stanchak
"""
from opencv.cv import *
from opencv.highgui import *
from random import random,randint
def draw_subdiv_point( img, fp, color ):
cvCircle( img, cvPoint(cvRound(fp.x), cvRound(fp.y)), 3, color, CV_FILLED, 8, 0 );
def draw_subdiv_edge( img, edge, color ):
org_pt = cvSubdiv2DEdgeOrg(edge);
dst_pt = cvSubdiv2DEdgeDst(edge);
if org_pt and dst_pt :
org = org_pt.pt;
dst = dst_pt.pt;
iorg = cvPoint( cvRound( org.x ), cvRound( org.y ));
idst = cvPoint( cvRound( dst.x ), cvRound( dst.y ));
cvLine( img, iorg, idst, color, 1, CV_AA, 0 );
def draw_subdiv( img, subdiv, delaunay_color, voronoi_color ):
total = subdiv.edges.total;
elem_size = subdiv.edges.elem_size;
for edge in subdiv.edges:
edge_rot = cvSubdiv2DRotateEdge( edge, 1 )
if( CV_IS_SET_ELEM( edge )):
draw_subdiv_edge( img, edge_rot, voronoi_color );
draw_subdiv_edge( img, edge, delaunay_color );
def locate_point( subdiv, fp, img, active_color ):
[res, e0, p] = cvSubdiv2DLocate( subdiv, fp );
if e0:
e = e0
while True:
draw_subdiv_edge( img, e, active_color );
e = cvSubdiv2DGetEdge(e,CV_NEXT_AROUND_LEFT);
if e == e0:
break
draw_subdiv_point( img, fp, active_color );
def draw_subdiv_facet( img, edge ):
t = edge;
count = 0;
# count number of edges in facet
while count == 0 or t != edge:
count+=1
t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
buf = []
# gather points
t = edge;
for i in range(count):
assert t>4
pt = cvSubdiv2DEdgeOrg( t );
if not pt:
break;
buf.append( cvPoint( cvRound(pt.pt.x), cvRound(pt.pt.y) ) );
t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
if( len(buf)==count ):
pt = cvSubdiv2DEdgeDst( cvSubdiv2DRotateEdge( edge, 1 ));
cvFillConvexPoly( img, buf, CV_RGB(randint(0,255),randint(0,255),randint(0,255)), CV_AA, 0 );
cvPolyLine( img, [buf], 1, CV_RGB(0,0,0), 1, CV_AA, 0);
draw_subdiv_point( img, pt.pt, CV_RGB(0,0,0));
def paint_voronoi( subdiv, img ):
total = subdiv.edges.total;
elem_size = subdiv.edges.elem_size;
cvCalcSubdivVoronoi2D( subdiv );
for edge in subdiv.edges:
if( CV_IS_SET_ELEM( edge )):
# left
draw_subdiv_facet( img, cvSubdiv2DRotateEdge( edge, 1 ));
# right
draw_subdiv_facet( img, cvSubdiv2DRotateEdge( edge, 3 ));
if __name__ == '__main__':
win = "source";
rect = cvRect( 0, 0, 600, 600 );
active_facet_color = CV_RGB( 255, 0, 0 );
delaunay_color = CV_RGB( 0,0,0);
voronoi_color = CV_RGB(0, 180, 0);
bkgnd_color = CV_RGB(255,255,255);
img = cvCreateImage( cvSize(rect.width,rect.height), 8, 3 );
cvSet( img, bkgnd_color );
cvNamedWindow( win, 1 );
storage = cvCreateMemStorage(0);
subdiv = cvCreateSubdivDelaunay2D( rect, storage );
print "Delaunay triangulation will be build now interactively."
print "To stop the process, press any key\n";
for i in range(200):
fp = cvPoint2D32f( random()*(rect.width-10)+5, random()*(rect.height-10)+5 )
locate_point( subdiv, fp, img, active_facet_color );
cvShowImage( win, img );
if( cvWaitKey( 100 ) >= 0 ):
break;
cvSubdivDelaunay2DInsert( subdiv, fp );
cvCalcSubdivVoronoi2D( subdiv );
cvSet( img, bkgnd_color );
draw_subdiv( img, subdiv, delaunay_color, voronoi_color );
cvShowImage( win, img );
if( cvWaitKey( 100 ) >= 0 ):
break;
cvSet( img, bkgnd_color );
paint_voronoi( subdiv, img );
cvShowImage( win, img );
cvWaitKey(0);
cvDestroyWindow( win );

View File

@ -1,102 +0,0 @@
#!/usr/bin/python
from opencv.cv import *
from opencv.highgui import *
import sys
file_name = "../c/baboon.jpg";
_brightness = 100
_contrast = 100
Gbrightness = 100
Gcontrast = 100
hist_size = 64
range_0=[0,256]
ranges = [ range_0 ]
src_image=None
dst_image=None
hist_image=None
hist=None
lut=cvCreateMat(256,1,CV_8U)
# brightness/contrast callback function
def update_brightness( val ):
global Gbrightness # global tag is required, or we get UnboundLocalError
Gbrightness = val
update_brightcont( )
def update_contrast( val ):
global Gcontrast # global tag is required, or we get UnboundLocalError
Gcontrast = val
update_brightcont( )
def update_brightcont():
# no global tag required for images ???
brightness = Gbrightness - 100;
contrast = Gcontrast - 100;
max_value = 0;
# The algorithm is by Werner D. Streidt
# (http://visca.com/ffactory/archives/5-99/msg00021.html)
if( contrast > 0 ):
delta = 127.*contrast/100;
a = 255./(255. - delta*2);
b = a*(brightness - delta);
else:
delta = -128.*contrast/100;
a = (256.-delta*2)/255.;
b = a*brightness + delta;
for i in range(256):
v = cvRound(a*i + b);
if( v < 0 ):
v = 0;
if( v > 255 ):
v = 255;
lut[i] = v;
cvLUT( src_image, dst_image, lut );
cvShowImage( "image", dst_image );
cvCalcHist( dst_image, hist, 0, None );
cvZero( dst_image );
min_value, max_value = cvGetMinMaxHistValue( hist );
cvScale( hist.bins, hist.bins, float(hist_image.height)/max_value, 0 );
#cvNormalizeHist( hist, 1000 );
cvSet( hist_image, cvScalarAll(255));
bin_w = cvRound(float(hist_image.width)/hist_size);
for i in range(hist_size):
cvRectangle( hist_image, cvPoint(i*bin_w, hist_image.height),
cvPoint((i+1)*bin_w, hist_image.height - cvRound(cvGetReal1D(hist.bins,i))),
cvScalarAll(0), -1, 8, 0 );
cvShowImage( "histogram", hist_image );
if __name__ == "__main__":
# Load the source image. HighGUI use.
if len(sys.argv)>1:
file_name = sys.argv[1]
src_image = cvLoadImage( file_name, 0 );
if not src_image:
print "Image was not loaded.";
sys.exit(-1)
dst_image = cvCloneImage(src_image);
hist_image = cvCreateImage(cvSize(320,200), 8, 1);
hist = cvCreateHist([hist_size], CV_HIST_ARRAY, ranges, 1);
cvNamedWindow("image", 0);
cvNamedWindow("histogram", 0);
cvCreateTrackbar("brightness", "image", _brightness, 200, update_brightness);
cvCreateTrackbar("contrast", "image", _contrast, 200, update_contrast);
update_brightcont();
cvWaitKey(0);

View File

@ -1,107 +0,0 @@
#!/usr/bin/python
from opencv.cv import *
from opencv.highgui import *
import sys
# Rearrange the quadrants of Fourier image so that the origin is at
# the image center
# src & dst arrays of equal size & type
def cvShiftDFT(src_arr, dst_arr ):
size = cvGetSize(src_arr)
dst_size = cvGetSize(dst_arr)
if(dst_size.width != size.width or
dst_size.height != size.height) :
cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ )
if(src_arr is dst_arr):
tmp = cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr))
cx = size.width/2
cy = size.height/2 # image center
q1 = cvGetSubRect( src_arr, cvRect(0,0,cx, cy) )
q2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) )
q3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) )
q4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) )
d1 = cvGetSubRect( src_arr, cvRect(0,0,cx,cy) )
d2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) )
d3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) )
d4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) )
if(src_arr is not dst_arr):
if( not CV_ARE_TYPES_EQ( q1, d1 )):
cvError( CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ )
cvCopy(q3, d1)
cvCopy(q4, d2)
cvCopy(q1, d3)
cvCopy(q2, d4)
else:
cvCopy(q3, tmp)
cvCopy(q1, q3)
cvCopy(tmp, q1)
cvCopy(q4, tmp)
cvCopy(q2, q4)
cvCopy(tmp, q2)
if __name__ == "__main__":
im = cvLoadImage( sys.argv[1], CV_LOAD_IMAGE_GRAYSCALE)
realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1)
imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1)
complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2)
cvScale(im, realInput, 1.0, 0.0)
cvZero(imaginaryInput)
cvMerge(realInput, imaginaryInput, None, None, complexInput)
dft_M = cvGetOptimalDFTSize( im.height - 1 )
dft_N = cvGetOptimalDFTSize( im.width - 1 )
dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 )
image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1)
image_Im = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1)
# copy A to dft_A and pad dft_A with zeros
tmp = cvGetSubRect( dft_A, cvRect(0,0, im.width, im.height))
cvCopy( complexInput, tmp, None )
if(dft_A.width > im.width):
tmp = cvGetSubRect( dft_A, cvRect(im.width,0, dft_N - im.width, im.height))
cvZero( tmp )
# no need to pad bottom part of dft_A with zeros because of
# use nonzero_rows parameter in cvDFT() call below
cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput.height )
cvNamedWindow("win", 0)
cvNamedWindow("magnitude", 0)
cvShowImage("win", im)
# Split Fourier in real and imaginary parts
cvSplit( dft_A, image_Re, image_Im, None, None )
# Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
cvPow( image_Re, image_Re, 2.0)
cvPow( image_Im, image_Im, 2.0)
cvAdd( image_Re, image_Im, image_Re, None)
cvPow( image_Re, image_Re, 0.5 )
# Compute log(1 + Mag)
cvAddS( image_Re, cvScalarAll(1.0), image_Re, None ) # 1 + Mag
cvLog( image_Re, image_Re ) # log(1 + Mag)
# Rearrange the quadrants of Fourier image so that the origin is at
# the image center
cvShiftDFT( image_Re, image_Re )
min, max, pt1, pt2 = cvMinMaxLoc(image_Re)
cvScale(image_Re, image_Re, 1.0/(max-min), 1.0*(-min)/(max-min))
cvShowImage("magnitude", image_Re)
cvWaitKey(0)

View File

@ -1,71 +0,0 @@
#!/usr/bin/python
import sys
from opencv.cv import *
from opencv.highgui import *
wndname = "Distance transform";
tbarname = "Threshold";
# The output images
dist = 0;
dist8u1 = 0;
dist8u2 = 0;
dist8u = 0;
dist32s = 0;
gray = 0;
edge = 0;
# define a trackbar callback
def on_trackbar( edge_thresh ):
cvThreshold( gray, edge, float(edge_thresh), float(edge_thresh), CV_THRESH_BINARY );
#Distance transform
cvDistTransform( edge, dist, CV_DIST_L2, CV_DIST_MASK_5, None, None );
cvConvertScale( dist, dist, 5000.0, 0 );
cvPow( dist, dist, 0.5 );
cvConvertScale( dist, dist32s, 1.0, 0.5 );
cvAndS( dist32s, cvScalarAll(255), dist32s, None );
cvConvertScale( dist32s, dist8u1, 1, 0 );
cvConvertScale( dist32s, dist32s, -1, 0 );
cvAddS( dist32s, cvScalarAll(255), dist32s, None );
cvConvertScale( dist32s, dist8u2, 1, 0 );
cvMerge( dist8u1, dist8u2, dist8u2, None, dist8u );
cvShowImage( wndname, dist8u );
if __name__ == "__main__":
edge_thresh = 100;
filename = "../c/stuff.jpg"
if len(sys.argv) > 1:
filename = sys.argv[1]
gray = cvLoadImage( filename, 0 )
if not gray:
print "Failed to load %s" % filename
sys.exit(-1)
# Create the output image
dist = cvCreateImage( cvSize(gray.width,gray.height), IPL_DEPTH_32F, 1 );
dist8u1 = cvCloneImage( gray );
dist8u2 = cvCloneImage( gray );
dist8u = cvCreateImage( cvSize(gray.width,gray.height), IPL_DEPTH_8U, 3 );
dist32s = cvCreateImage( cvSize(gray.width,gray.height), IPL_DEPTH_32S, 1 );
# Convert to grayscale
edge = cvCloneImage( gray );
# Create a window
cvNamedWindow( wndname, 1 );
# create a toolbar
cvCreateTrackbar( tbarname, wndname, edge_thresh, 255, on_trackbar );
# Show the image
on_trackbar(edge_thresh);
# Wait for a key stroke; the same function arranges events processing
cvWaitKey(0);

View File

@ -1,164 +0,0 @@
#! /usr/bin/env python
print "OpenCV Python version of drawing"
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
# for making random numbers
from random import Random
def random_color (random):
"""
Return a random color
"""
icolor = random.randint (0, 0xFFFFFF)
return cv.cvScalar (icolor & 0xff, (icolor >> 8) & 0xff, (icolor >> 16) & 0xff)
if __name__ == '__main__':
# some "constants"
width = 1000
height = 700
window_name = "Drawing Demo"
number = 100
delay = 5
line_type = cv.CV_AA # change it to 8 to see non-antialiased graphics
# create the source image
image = cv.cvCreateImage (cv.cvSize (width, height), 8, 3)
# create window and display the original picture in it
highgui.cvNamedWindow (window_name, 1)
cv.cvSetZero (image)
highgui.cvShowImage (window_name, image)
# create the random number
random = Random ()
# draw some lines
for i in range (number):
pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
pt2 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
cv.cvLine (image, pt1, pt2,
random_color (random),
random.randrange (0, 10),
line_type, 0)
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# draw some rectangles
for i in range (number):
pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
pt2 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
cv.cvRectangle (image, pt1, pt2,
random_color (random),
random.randrange (-1, 9),
line_type, 0)
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# draw some ellipes
for i in range (number):
pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
sz = cv.cvSize (random.randrange (0, 200),
random.randrange (0, 200))
angle = random.randrange (0, 1000) * 0.180
cv.cvEllipse (image, pt1, sz, angle, angle - 100, angle + 200,
random_color (random),
random.randrange (-1, 9),
line_type, 0)
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# init the list of polylines
nb_polylines = 2
polylines_size = 3
pt = [0,] * nb_polylines
for a in range (nb_polylines):
pt [a] = [0,] * polylines_size
# draw some polylines
for i in range (number):
for a in range (nb_polylines):
for b in range (polylines_size):
pt [a][b] = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
cv.cvPolyLine (image, pt, 1,
random_color (random),
random.randrange (1, 9),
line_type, 0)
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# draw some filled polylines
for i in range (number):
for a in range (nb_polylines):
for b in range (polylines_size):
pt [a][b] = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
cv.cvFillPoly (image, pt,
random_color (random),
line_type, 0)
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# draw some circles
for i in range (number):
pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
cv.cvCircle (image, pt1, random.randrange (0, 300),
random_color (random),
random.randrange (-1, 9),
line_type, 0)
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# draw some text
for i in range (number):
pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
random.randrange (-height, 2 * height))
font = cv.cvInitFont (random.randrange (0, 8),
random.randrange (0, 100) * 0.05 + 0.01,
random.randrange (0, 100) * 0.05 + 0.01,
random.randrange (0, 5) * 0.1,
random.randrange (0, 10),
line_type)
cv.cvPutText (image, "Testing text rendering!",
pt1, font,
random_color (random))
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# prepare a text, and get it's properties
font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX,
3, 3, 0.0, 5, line_type)
text_size, ymin = cv.cvGetTextSize ("OpenCV forever!", font)
pt1.x = (width - text_size.width) / 2
pt1.y = (height + text_size.height) / 2
image2 = cv.cvCloneImage(image)
# now, draw some OpenCV pub ;-)
for i in range (255):
cv.cvSubS (image2, cv.cvScalarAll (i), image, None)
cv.cvPutText (image, "OpenCV forever!",
pt1, font, cv.cvScalar (255, i, i))
highgui.cvShowImage (window_name, image)
highgui.cvWaitKey (delay)
# wait some key to end
highgui.cvWaitKey (0)

View File

@ -1,64 +0,0 @@
#! /usr/bin/env python
print "OpenCV Python version of edge"
import sys
# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui
# some definitions
win_name = "Edge"
trackbar_name = "Threshold"
# the callback on the trackbar
def on_trackbar (position):
cv.cvSmooth (gray, edge, cv.CV_BLUR, 3, 3, 0)
cv.cvNot (gray, edge)
# run the edge dector on gray scale
cv.cvCanny (gray, edge, position, position * 3, 3)
# reset
cv.cvSetZero (col_edge)
# copy edge points
cv.cvCopy (image, col_edge, edge)
# show the image
highgui.cvShowImage (win_name, col_edge)
if __name__ == '__main__':
filename = "../c/fruits.jpg"
if len(sys.argv)>1:
filename = sys.argv[1]
# load the image gived on the command line
image = highgui.cvLoadImage (filename)
if not image:
print "Error loading image '%s'" % filename
sys.exit(-1)
# create the output image
col_edge = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 3)
# convert to grayscale
gray = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 1)
edge = cv.cvCreateImage (cv.cvSize (image.width, image.height), 8, 1)
cv.cvCvtColor (image, gray, cv.CV_BGR2GRAY)
# create the window
highgui.cvNamedWindow (win_name, highgui.CV_WINDOW_AUTOSIZE)
# create the trackbar
highgui.cvCreateTrackbar (trackbar_name, win_name, 1, 100, on_trackbar)
# show the image
on_trackbar (0)
# wait a key pressed to end
highgui.cvWaitKey (0)

View File

@ -1,128 +0,0 @@
#!/usr/bin/python
"""
This program is demonstration for face and object detection using haar-like features.
The program finds faces in a camera image or video stream and displays a red box around them.
Original C implementation by: ?
Python implementation by: Roman Stanchak
"""
import sys
from opencv.cv import *
from opencv.highgui import *
# Global Variables
cascade = None
storage = cvCreateMemStorage(0)
cascade_name = "../../data/haarcascades/haarcascade_frontalface_alt.xml"
input_name = "../c/lena.jpg"
# Parameters for haar detection
# From the API:
# The default parameters (scale_factor=1.1, min_neighbors=3, flags=0) are tuned
# for accurate yet slow object detection. For a faster operation on real video
# images the settings are:
# scale_factor=1.2, min_neighbors=2, flags=CV_HAAR_DO_CANNY_PRUNING,
# min_size=<minimum possible face size
min_size = cvSize(20,20)
image_scale = 1.3
haar_scale = 1.2
min_neighbors = 2
haar_flags = 0
def detect_and_draw( img ):
# allocate temporary images
gray = cvCreateImage( cvSize(img.width,img.height), 8, 1 )
small_img = cvCreateImage((cvRound(img.width/image_scale),
cvRound (img.height/image_scale)), 8, 1 )
# convert color input image to grayscale
cvCvtColor( img, gray, CV_BGR2GRAY )
# scale input image for faster processing
cvResize( gray, small_img, CV_INTER_LINEAR )
cvEqualizeHist( small_img, small_img )
cvClearMemStorage( storage )
if( cascade ):
t = cvGetTickCount()
faces = cvHaarDetectObjects( small_img, cascade, storage,
haar_scale, min_neighbors, haar_flags, min_size )
t = cvGetTickCount() - t
print "detection time = %gms" % (t/(cvGetTickFrequency()*1000.))
if faces:
for face_rect in faces:
# the input to cvHaarDetectObjects was resized, so scale the
# bounding box of each face and convert it to two CvPoints
pt1 = cvPoint( int(face_rect.x*image_scale), int(face_rect.y*image_scale))
pt2 = cvPoint( int((face_rect.x+face_rect.width)*image_scale),
int((face_rect.y+face_rect.height)*image_scale) )
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 )
cvShowImage( "result", img )
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1].startswith("--cascade="):
cascade_name = sys.argv[1][ len("--cascade="): ]
if len(sys.argv) > 2:
input_name = sys.argv[2]
elif sys.argv[1] == "--help" or sys.argv[1] == "-h":
print "Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n"
sys.exit(-1)
else:
input_name = sys.argv[1]
# the OpenCV API says this function is obsolete, but we can't
# cast the output of cvLoad to a HaarClassifierCascade, so use this anyways
# the size parameter is ignored
cascade = cvLoadHaarClassifierCascade( cascade_name, cvSize(1,1) )
if not cascade:
print "ERROR: Could not load classifier cascade"
sys.exit(-1)
if input_name.isdigit():
capture = cvCreateCameraCapture( int(input_name) )
else:
capture = cvCreateFileCapture( input_name )
cvNamedWindow( "result", 1 )
if capture:
frame_copy = None
while True:
frame = cvQueryFrame( capture )
if not frame:
cvWaitKey(0)
break
if not frame_copy:
frame_copy = cvCreateImage( cvSize(frame.width,frame.height),
IPL_DEPTH_8U, frame.nChannels )
if frame.origin == IPL_ORIGIN_TL:
cvCopy( frame, frame_copy )
else:
cvFlip( frame, frame_copy, 0 )
detect_and_draw( frame_copy )
if( cvWaitKey( 10 ) >= 0 ):
break
else:
image = cvLoadImage( input_name, 1 )
if image:
detect_and_draw( image )
cvWaitKey(0)
cvDestroyWindow("result")

Some files were not shown because too many files have changed in this diff Show More