2010-05-11 19:44:00 +02:00
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
2011-04-17 15:14:45 +02:00
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
2010-05-11 19:44:00 +02:00
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
# ifndef __OPENCV_CORE_HPP__
# define __OPENCV_CORE_HPP__
2013-03-29 09:59:55 +01:00
# ifndef __cplusplus
# error core.hpp header must be compiled as C++
# endif
2013-03-14 11:49:15 +01:00
# include "opencv2/core/cvdef.h"
2013-03-20 10:00:04 +01:00
# include "opencv2/core/version.hpp"
2013-03-27 12:54:04 +01:00
# include "opencv2/core/base.hpp"
2013-03-27 15:43:06 +01:00
# include "opencv2/core/cvstd.hpp"
2013-03-27 12:54:04 +01:00
# include "opencv2/core/traits.hpp"
# include "opencv2/core/matx.hpp"
2013-03-26 16:48:50 +01:00
# include "opencv2/core/types.hpp"
2013-03-28 18:01:12 +01:00
# include "opencv2/core/mat.hpp"
2013-04-01 17:18:05 +02:00
# include "opencv2/core/persistence.hpp"
2010-05-11 19:44:00 +02:00
# ifndef SKIP_INCLUDES
# include <limits.h>
# include <algorithm>
# include <cmath>
2011-04-07 00:00:09 +02:00
# include <cstddef>
2010-05-11 19:44:00 +02:00
# include <complex>
# include <map>
# include <new>
# include <vector>
2012-02-06 09:38:03 +01:00
# include <sstream>
2010-05-11 19:44:00 +02:00
# endif // SKIP_INCLUDES
2010-05-18 17:41:28 +02:00
/*! \namespace cv
Namespace where all the C + + OpenCV functionality resides
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
namespace cv {
2010-05-18 17:41:28 +02:00
/*!
The standard OpenCV exception class .
Instances of the class are thrown by various functions and methods in the case of critical errors .
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS Exception : public std : : exception
{
public :
2011-04-17 15:14:45 +02:00
/*!
2010-05-18 17:41:28 +02:00
Default constructor
*/
2011-06-08 23:35:19 +02:00
Exception ( ) ;
2010-05-18 17:41:28 +02:00
/*!
Full constructor . Normally the constuctor is not called explicitly .
Instead , the macros CV_Error ( ) , CV_Error_ ( ) and CV_Assert ( ) are used .
*/
2013-03-22 17:37:49 +01:00
Exception ( int _code , const String & _err , const String & _func , const String & _file , int _line ) ;
2011-06-08 23:35:19 +02:00
virtual ~ Exception ( ) throw ( ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
/*!
\ return the error description and the context as a text string .
2012-05-28 13:22:43 +02:00
*/
2011-06-08 23:35:19 +02:00
virtual const char * what ( ) const throw ( ) ;
void formatMessage ( ) ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
String msg ; ///< the formatted error message
2010-05-11 19:44:00 +02:00
2011-04-17 15:14:45 +02:00
int code ; ///< error code @see CVStatus
2013-03-22 17:37:49 +01:00
String err ; ///< error description
String func ; ///< function name. Available only when the compiler supports __func__ macro
String file ; ///< source file name where the error has occured
2012-05-28 13:22:43 +02:00
int line ; ///< line number in the source file where the error has occured
2010-05-11 19:44:00 +02:00
} ;
2010-05-18 17:41:28 +02:00
2010-05-21 22:37:05 +02:00
//! Signals an error and raises the exception.
2012-05-28 13:22:43 +02:00
2010-05-21 22:37:05 +02:00
/*!
2010-05-18 17:41:28 +02:00
By default the function prints information about the error to stderr ,
then it either stops if setBreakOnError ( ) had been called before or raises the exception .
It is possible to alternate error processing by using redirectError ( ) .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ param exc the exception raisen .
*/
2013-03-28 13:47:45 +01:00
//TODO: drop this version
2010-05-11 19:44:00 +02:00
CV_EXPORTS void error ( const Exception & exc ) ;
2010-05-18 17:41:28 +02:00
2010-05-11 19:44:00 +02:00
2012-04-30 16:33:52 +02:00
typedef void ( * BinaryFunc ) ( const uchar * src1 , size_t step1 ,
const uchar * src2 , size_t step2 ,
uchar * dst , size_t step , Size sz ,
void * ) ;
CV_EXPORTS BinaryFunc getConvertFunc ( int sdepth , int ddepth ) ;
CV_EXPORTS BinaryFunc getConvertScaleFunc ( int sdepth , int ddepth ) ;
2012-05-28 13:22:43 +02:00
CV_EXPORTS BinaryFunc getCopyMaskFunc ( size_t esz ) ;
2010-10-12 14:31:40 +02:00
//! swaps two matrices
CV_EXPORTS void swap ( Mat & a , Mat & b ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! adds one matrix to another (dst = src1 + src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void add ( InputArray src1 , InputArray src2 , OutputArray dst ,
2013-03-30 16:03:55 +01:00
InputArray mask = noArray ( ) , int dtype = - 1 ) ;
2012-05-28 13:22:43 +02:00
//! subtracts one matrix from another (dst = src1 - src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void subtract ( InputArray src1 , InputArray src2 , OutputArray dst ,
2013-03-30 16:03:55 +01:00
InputArray mask = noArray ( ) , int dtype = - 1 ) ;
2010-10-12 14:31:40 +02:00
//! computes element-wise weighted product of the two arrays (dst = scale*src1*src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void multiply ( InputArray src1 , InputArray src2 ,
2013-03-30 16:03:55 +01:00
OutputArray dst , double scale = 1 , int dtype = - 1 ) ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
//! computes element-wise weighted quotient of the two arrays (dst = scale * src1 / src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void divide ( InputArray src1 , InputArray src2 , OutputArray dst ,
2013-03-30 16:03:55 +01:00
double scale = 1 , int dtype = - 1 ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes element-wise weighted reciprocal of an array (dst = scale/src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void divide ( double scale , InputArray src2 ,
2013-03-30 16:03:55 +01:00
OutputArray dst , int dtype = - 1 ) ;
2010-10-12 14:31:40 +02:00
//! adds scaled array to another one (dst = alpha*src1 + src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void scaleAdd ( InputArray src1 , double alpha , InputArray src2 , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void addWeighted ( InputArray src1 , double alpha , InputArray src2 ,
2013-03-30 16:03:55 +01:00
double beta , double gamma , OutputArray dst , int dtype = - 1 ) ;
2011-04-17 15:14:45 +02:00
2010-10-12 14:31:40 +02:00
//! scales array elements, computes absolute values and converts the results to 8-bit unsigned integers: dst(i)=saturate_cast<uchar>abs(src(i)*alpha+beta)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void convertScaleAbs ( InputArray src , OutputArray dst ,
2013-03-30 16:03:55 +01:00
double alpha = 1 , double beta = 0 ) ;
2011-04-17 15:14:45 +02:00
//! transforms array of numbers using a lookup table: dst(i)=lut(src(i))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void LUT ( InputArray src , InputArray lut , OutputArray dst ,
2013-03-30 16:03:55 +01:00
int interpolation = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! computes sum of array elements
2012-05-28 13:22:43 +02:00
CV_EXPORTS_AS ( sumElems ) Scalar sum ( InputArray src ) ;
2013-03-30 16:03:55 +01:00
2010-05-18 17:41:28 +02:00
//! computes the number of nonzero array elements
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W int countNonZero ( InputArray src ) ;
2013-03-30 16:03:55 +01:00
2012-10-11 20:52:15 +02:00
//! returns the list of locations of non-zero pixels
CV_EXPORTS_W void findNonZero ( InputArray src , OutputArray idx ) ;
2012-10-17 09:12:04 +02:00
2010-05-18 17:41:28 +02:00
//! computes mean value of selected array elements
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W Scalar mean ( InputArray src , InputArray mask = noArray ( ) ) ;
2010-05-18 17:41:28 +02:00
//! computes mean value and standard deviation of all or selected array elements
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void meanStdDev ( InputArray src , OutputArray mean , OutputArray stddev ,
2011-06-08 08:55:04 +02:00
InputArray mask = noArray ( ) ) ;
2013-03-30 16:03:55 +01:00
2010-05-25 16:57:10 +02:00
//! computes norm of the selected array part
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W double norm ( InputArray src1 , int normType = NORM_L2 , InputArray mask = noArray ( ) ) ;
2010-05-18 17:41:28 +02:00
//! computes norm of selected part of the difference between two arrays
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double norm ( InputArray src1 , InputArray src2 ,
2013-03-30 16:03:55 +01:00
int normType = NORM_L2 , InputArray mask = noArray ( ) ) ;
//! computes norm of a sparse matrix
CV_EXPORTS double norm ( const SparseMat & src , int normType ) ;
2012-03-15 15:36:01 +01:00
//! naive nearest neighbor finder
CV_EXPORTS_W void batchDistance ( InputArray src1 , InputArray src2 ,
OutputArray dist , int dtype , OutputArray nidx ,
2013-03-30 16:03:55 +01:00
int normType = NORM_L2 , int K = 0 ,
InputArray mask = noArray ( ) , int update = 0 ,
bool crosscheck = false ) ;
2012-03-15 15:36:01 +01:00
2012-05-28 13:22:43 +02:00
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void normalize ( InputArray src , OutputArray dst , double alpha = 1 , double beta = 0 ,
int norm_type = NORM_L2 , int dtype = - 1 , InputArray mask = noArray ( ) ) ;
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
CV_EXPORTS void normalize ( const SparseMat & src , SparseMat & dst , double alpha , int normType ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! finds global minimum and maximum array elements and returns their values and their locations
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void minMaxLoc ( InputArray src , CV_OUT double * minVal ,
2013-03-30 16:03:55 +01:00
CV_OUT double * maxVal = 0 , CV_OUT Point * minLoc = 0 ,
CV_OUT Point * maxLoc = 0 , InputArray mask = noArray ( ) ) ;
CV_EXPORTS void minMaxIdx ( InputArray src , double * minVal , double * maxVal = 0 ,
int * minIdx = 0 , int * maxIdx = 0 , InputArray mask = noArray ( ) ) ;
//! finds global minimum and maximum sparse array elements and returns their values and their locations
CV_EXPORTS void minMaxLoc ( const SparseMat & a , double * minVal ,
double * maxVal , int * minIdx = 0 , int * maxIdx = 0 ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void reduce ( InputArray src , OutputArray dst , int dim , int rtype , int dtype = - 1 ) ;
2011-04-17 15:14:45 +02:00
2010-05-25 16:57:10 +02:00
//! makes multi-channel array out of several single-channel arrays
2011-04-17 15:14:45 +02:00
CV_EXPORTS void merge ( const Mat * mv , size_t count , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2010-11-23 17:39:20 +01:00
//! makes multi-channel array out of several single-channel arrays
2012-05-11 15:36:48 +02:00
CV_EXPORTS_W void merge ( InputArrayOfArrays mv , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! copies each plane of a multi-channel array to a dedicated array
2010-10-27 20:26:39 +02:00
CV_EXPORTS void split ( const Mat & src , Mat * mvbegin ) ;
2013-03-30 16:03:55 +01:00
2010-11-23 17:39:20 +01:00
//! copies each plane of a multi-channel array to a dedicated array
2012-05-11 15:36:48 +02:00
CV_EXPORTS_W void split ( InputArray m , OutputArrayOfArrays mv ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! copies selected channels from the input arrays to the selected channels of the output arrays
2010-10-27 20:26:39 +02:00
CV_EXPORTS void mixChannels ( const Mat * src , size_t nsrcs , Mat * dst , size_t ndsts ,
const int * fromTo , size_t npairs ) ;
2013-03-30 16:03:55 +01:00
2013-02-24 17:14:01 +01:00
CV_EXPORTS void mixChannels ( const std : : vector < Mat > & src , std : : vector < Mat > & dst ,
2013-03-30 16:03:55 +01:00
const int * fromTo , size_t npairs ) ; //TODO: use arrays
2011-08-08 09:08:58 +02:00
CV_EXPORTS_W void mixChannels ( InputArrayOfArrays src , InputArrayOfArrays dst ,
2013-03-30 16:03:55 +01:00
const std : : vector < int > & fromTo ) ; //TODO: InputOutputArrayOfArrays
2010-10-27 20:26:39 +02:00
2011-06-18 12:56:49 +02:00
//! extracts a single channel from src (coi is 0-based index)
CV_EXPORTS_W void extractChannel ( InputArray src , OutputArray dst , int coi ) ;
//! inserts a single channel to dst (coi is 0-based index)
CV_EXPORTS_W void insertChannel ( InputArray src , InputOutputArray dst , int coi ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! reverses the order of the rows, columns or both in a matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void flip ( InputArray src , OutputArray dst , int flipCode ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! replicates the input matrix the specified number of times in the horizontal and/or vertical direction
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void repeat ( InputArray src , int ny , int nx , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2010-11-23 17:39:20 +01:00
CV_EXPORTS Mat repeat ( const Mat & src , int ny , int nx ) ;
2012-05-28 13:22:43 +02:00
2011-04-17 15:14:45 +02:00
CV_EXPORTS void hconcat ( const Mat * src , size_t nsrc , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2011-06-06 16:51:27 +02:00
CV_EXPORTS void hconcat ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2012-04-30 16:33:52 +02:00
CV_EXPORTS_W void hconcat ( InputArrayOfArrays src , OutputArray dst ) ;
2010-05-11 19:44:00 +02:00
2011-04-17 15:14:45 +02:00
CV_EXPORTS void vconcat ( const Mat * src , size_t nsrc , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2011-06-06 16:51:27 +02:00
CV_EXPORTS void vconcat ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2012-04-30 16:33:52 +02:00
CV_EXPORTS_W void vconcat ( InputArrayOfArrays src , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes bitwise conjunction of the two arrays (dst = src1 & src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_and ( InputArray src1 , InputArray src2 ,
2013-03-30 16:03:55 +01:00
OutputArray dst , InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! computes bitwise disjunction of the two arrays (dst = src1 | src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_or ( InputArray src1 , InputArray src2 ,
2013-03-30 16:03:55 +01:00
OutputArray dst , InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_xor ( InputArray src1 , InputArray src2 ,
2013-03-30 16:03:55 +01:00
OutputArray dst , InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! inverts each bit of array (dst = ~src)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_not ( InputArray src , OutputArray dst ,
2013-03-30 16:03:55 +01:00
InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void absdiff ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2012-05-28 13:22:43 +02:00
//! set mask elements for those array elements which are within the element-specific bounding box (dst = lowerb <= src && src < upperb)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void inRange ( InputArray src , InputArray lowerb ,
2012-05-28 13:22:43 +02:00
InputArray upperb , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2010-10-12 14:31:40 +02:00
//! compares elements of two arrays (dst = src1 <cmpop> src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void compare ( InputArray src1 , InputArray src2 , OutputArray dst , int cmpop ) ;
2013-03-30 16:03:55 +01:00
2010-10-12 14:31:40 +02:00
//! computes per-element minimum of two arrays (dst = min(src1, src2))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void min ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2011-04-17 15:14:45 +02:00
//! computes per-element maximum of two arrays (dst = max(src1, src2))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void max ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2011-04-17 15:14:45 +02:00
2013-03-30 16:03:55 +01:00
//TODO: can we drop these versions?
2011-04-17 15:14:45 +02:00
//! computes per-element minimum of two arrays (dst = min(src1, src2))
CV_EXPORTS void min ( const Mat & src1 , const Mat & src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element minimum of array and scalar (dst = min(src1, src2))
2011-04-17 15:14:45 +02:00
CV_EXPORTS void min ( const Mat & src1 , double src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element maximum of two arrays (dst = max(src1, src2))
2011-04-17 15:14:45 +02:00
CV_EXPORTS void max ( const Mat & src1 , const Mat & src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element maximum of array and scalar (dst = max(src1, src2))
2012-05-28 13:22:43 +02:00
CV_EXPORTS void max ( const Mat & src1 , double src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes square root of each matrix element (dst = src**0.5)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void sqrt ( InputArray src , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2012-05-28 13:22:43 +02:00
//! raises the input matrix elements to the specified power (b = a**power)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void pow ( InputArray src , double power , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2010-10-12 14:31:40 +02:00
//! computes exponent of each matrix element (dst = e**src)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void exp ( InputArray src , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2010-10-12 14:31:40 +02:00
//! computes natural logarithm of absolute value of each matrix element: dst = log(abs(src))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void log ( InputArray src , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-05-21 22:37:05 +02:00
//! converts polar coordinates to Cartesian
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void polarToCart ( InputArray magnitude , InputArray angle ,
2013-03-30 16:03:55 +01:00
OutputArray x , OutputArray y , bool angleInDegrees = false ) ;
2010-05-21 22:37:05 +02:00
//! converts Cartesian coordinates to polar
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void cartToPolar ( InputArray x , InputArray y ,
2011-04-17 15:14:45 +02:00
OutputArray magnitude , OutputArray angle ,
2013-03-30 16:03:55 +01:00
bool angleInDegrees = false ) ;
2010-05-21 22:37:05 +02:00
//! computes angle (angle(i)) of each (x(i), y(i)) vector
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void phase ( InputArray x , InputArray y , OutputArray angle ,
2013-03-30 16:03:55 +01:00
bool angleInDegrees = false ) ;
2010-05-21 22:37:05 +02:00
//! computes magnitude (magnitude(i)) of each (x(i), y(i)) vector
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void magnitude ( InputArray x , InputArray y , OutputArray magnitude ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! checks that each matrix element is within the specified range.
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W bool checkRange ( InputArray a , bool quiet = true , CV_OUT Point * pos = 0 ,
double minVal = - DBL_MAX , double maxVal = DBL_MAX ) ;
2012-04-30 16:33:52 +02:00
//! converts NaN's to the given number
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void patchNaNs ( InputOutputArray a , double val = 0 ) ;
2012-05-28 13:22:43 +02:00
2010-05-21 22:37:05 +02:00
//! implements generalized matrix product algorithm GEMM from BLAS
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void gemm ( InputArray src1 , InputArray src2 , double alpha ,
2013-03-30 16:03:55 +01:00
InputArray src3 , double gamma , OutputArray dst , int flags = 0 ) ;
2010-05-21 22:37:05 +02:00
//! multiplies matrix by its transposition from the left or from the right
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void mulTransposed ( InputArray src , OutputArray dst , bool aTa ,
2013-03-30 16:03:55 +01:00
InputArray delta = noArray ( ) ,
double scale = 1 , int dtype = - 1 ) ;
2010-05-21 22:37:05 +02:00
//! transposes the matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void transpose ( InputArray src , OutputArray dst ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! performs affine transformation of each element of multi-channel input matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void transform ( InputArray src , OutputArray dst , InputArray m ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! performs perspective transformation of each element of multi-channel input matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void perspectiveTransform ( InputArray src , OutputArray dst , InputArray m ) ;
2010-05-11 19:44:00 +02:00
2012-05-28 13:22:43 +02:00
//! extends the symmetrical matrix from the lower half or from the upper half
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void completeSymm ( InputOutputArray mtx , bool lowerToUpper = false ) ;
2010-05-21 22:37:05 +02:00
//! initializes scaled identity matrix
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void setIdentity ( InputOutputArray mtx , const Scalar & s = Scalar ( 1 ) ) ;
2010-05-21 22:37:05 +02:00
//! computes determinant of a square matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double determinant ( InputArray mtx ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! computes trace of a matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W Scalar trace ( InputArray mtx ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! computes inverse or pseudo-inverse matrix
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W double invert ( InputArray src , OutputArray dst , int flags = DECOMP_LU ) ;
2010-05-21 22:37:05 +02:00
//! solves linear system or a least-square problem
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W bool solve ( InputArray src1 , InputArray src2 ,
2013-03-30 16:03:55 +01:00
OutputArray dst , int flags = DECOMP_LU ) ;
2011-07-19 14:27:07 +02:00
enum
{
2013-03-30 16:03:55 +01:00
SORT_EVERY_ROW = 0 ,
SORT_EVERY_COLUMN = 1 ,
SORT_ASCENDING = 0 ,
SORT_DESCENDING = 16
2011-07-19 14:27:07 +02:00
} ;
2010-05-21 22:37:05 +02:00
//! sorts independently each matrix row or each matrix column
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void sort ( InputArray src , OutputArray dst , int flags ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! sorts independently each matrix row or each matrix column
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void sortIdx ( InputArray src , OutputArray dst , int flags ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! finds real roots of a cubic polynomial
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W int solveCubic ( InputArray coeffs , OutputArray roots ) ;
2013-03-30 16:03:55 +01:00
2010-05-21 22:37:05 +02:00
//! finds real and complex roots of a polynomial
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W double solvePoly ( InputArray coeffs , OutputArray roots , int maxIters = 300 ) ;
2010-05-25 16:57:10 +02:00
//! finds eigenvalues of a symmetric matrix
2013-03-30 16:03:55 +01:00
CV_EXPORTS bool eigen ( InputArray src , OutputArray eigenvalues , int lowindex = - 1 ,
int highindex = - 1 ) ;
2010-05-25 16:57:10 +02:00
//! finds eigenvalues and eigenvectors of a symmetric matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS bool eigen ( InputArray src , OutputArray eigenvalues ,
2011-04-17 15:14:45 +02:00
OutputArray eigenvectors ,
2013-03-30 16:03:55 +01:00
int lowindex = - 1 , int highindex = - 1 ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W bool eigen ( InputArray src , bool computeEigenvectors ,
OutputArray eigenvalues , OutputArray eigenvectors ) ;
2011-07-19 14:27:07 +02:00
enum
{
2013-03-30 16:03:55 +01:00
COVAR_SCRAMBLED = 0 ,
COVAR_NORMAL = 1 ,
COVAR_USE_AVG = 2 ,
COVAR_SCALE = 4 ,
COVAR_ROWS = 8 ,
COVAR_COLS = 16
2011-07-19 14:27:07 +02:00
} ;
2010-05-25 16:57:10 +02:00
//! computes covariation matrix of a set of samples
2010-10-27 20:26:39 +02:00
CV_EXPORTS void calcCovarMatrix ( const Mat * samples , int nsamples , Mat & covar , Mat & mean ,
2013-03-30 16:03:55 +01:00
int flags , int ctype = CV_64F ) ; //TODO: output arrays or drop
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
//! computes covariation matrix of a set of samples
CV_EXPORTS_W void calcCovarMatrix ( InputArray samples , OutputArray covar , //TODO: InputArrayOfArrays
OutputArray mean , int flags , int ctype = CV_64F ) ;
2010-05-11 19:44:00 +02:00
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W void PCACompute ( InputArray data , InputOutputArray mean ,
2013-03-30 16:03:55 +01:00
OutputArray eigenvectors , int maxComponents = 0 ) ;
2012-05-28 13:22:43 +02:00
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W void PCACompute ( InputArray data , InputOutputArray mean ,
2012-08-23 05:21:49 +02:00
OutputArray eigenvectors , double retainedVariance ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W void PCAProject ( InputArray data , InputArray mean ,
InputArray eigenvectors , OutputArray result ) ;
CV_EXPORTS_W void PCABackProject ( InputArray data , InputArray mean ,
InputArray eigenvectors , OutputArray result ) ;
//! computes SVD of src
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void SVDecomp ( InputArray src , OutputArray w , OutputArray u , OutputArray vt , int flags = 0 ) ;
2011-07-18 18:31:30 +02:00
//! performs back substitution for the previously computed SVD
CV_EXPORTS_W void SVBackSubst ( InputArray w , InputArray u , InputArray vt ,
2013-03-14 11:49:15 +01:00
InputArray rhs , OutputArray dst ) ;
2011-07-18 18:31:30 +02:00
2010-05-25 16:57:10 +02:00
//! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double Mahalanobis ( InputArray v1 , InputArray v2 , InputArray icovar ) ;
2013-03-30 16:03:55 +01:00
2010-05-25 16:57:10 +02:00
//! a synonym for Mahalanobis
2013-03-30 16:03:55 +01:00
CV_EXPORTS double Mahalonobis ( InputArray v1 , InputArray v2 , InputArray icovar ) ; //TODO: check if we can drop it or move to legacy
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! performs forward or inverse 1D or 2D Discrete Fourier Transformation
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void dft ( InputArray src , OutputArray dst , int flags = 0 , int nonzeroRows = 0 ) ;
2010-05-25 16:57:10 +02:00
//! performs inverse 1D or 2D Discrete Fourier Transformation
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void idft ( InputArray src , OutputArray dst , int flags = 0 , int nonzeroRows = 0 ) ;
2010-05-25 16:57:10 +02:00
//! performs forward or inverse 1D or 2D Discrete Cosine Transformation
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void dct ( InputArray src , OutputArray dst , int flags = 0 ) ;
2010-05-25 16:57:10 +02:00
//! performs inverse 1D or 2D Discrete Cosine Transformation
2013-03-30 16:03:55 +01:00
CV_EXPORTS_W void idct ( InputArray src , OutputArray dst , int flags = 0 ) ;
2010-05-25 16:57:10 +02:00
//! computes element-wise product of the two Fourier spectrums. The second spectrum can optionally be conjugated before the multiplication
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void mulSpectrums ( InputArray a , InputArray b , OutputArray c ,
2013-03-30 16:03:55 +01:00
int flags , bool conjB = false ) ;
2010-05-25 16:57:10 +02:00
//! computes the minimal vector size vecsize1 >= vecsize so that the dft() of the vector of length vecsize1 can be computed efficiently
2010-10-27 20:26:39 +02:00
CV_EXPORTS_W int getOptimalDFTSize ( int vecsize ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
/*!
2013-03-30 16:03:55 +01:00
k - Means flags
2010-05-25 16:57:10 +02:00
*/
enum
{
2013-03-30 16:03:55 +01:00
KMEANS_RANDOM_CENTERS = 0 , // Chooses random centers for k-Means initialization
KMEANS_PP_CENTERS = 2 , // Uses k-Means++ algorithm for initialization
KMEANS_USE_INITIAL_LABELS = 1 // Uses the user-provided labels for K-Means initialization
2010-05-25 16:57:10 +02:00
} ;
2013-03-30 16:03:55 +01:00
2010-05-25 16:57:10 +02:00
//! clusters the input data using k-Means algorithm
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W double kmeans ( InputArray data , int K , InputOutputArray bestLabels ,
2011-04-17 15:14:45 +02:00
TermCriteria criteria , int attempts ,
2013-03-30 16:03:55 +01:00
int flags , OutputArray centers = noArray ( ) ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! returns the thread-local Random number generator
2010-05-11 19:44:00 +02:00
CV_EXPORTS RNG & theRNG ( ) ;
2010-05-25 16:57:10 +02:00
//! fills array with uniformly-distributed random numbers from the range [low, high)
2011-06-08 00:51:31 +02:00
CV_EXPORTS_W void randu ( InputOutputArray dst , InputArray low , InputArray high ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! fills array with normally-distributed random numbers with the specified mean and the standard deviation
2011-06-08 00:51:31 +02:00
CV_EXPORTS_W void randn ( InputOutputArray dst , InputArray mean , InputArray stddev ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! shuffles the input array elements
2013-03-30 16:03:55 +01:00
CV_EXPORTS void randShuffle ( InputOutputArray dst , double iterFactor = 1. , RNG * rng = 0 ) ;
CV_EXPORTS_AS ( randShuffle ) void randShuffle_ ( InputOutputArray dst , double iterFactor = 1. ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws the line segment (pt1, pt2) in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void line ( CV_IN_OUT Mat & img , Point pt1 , Point pt2 , const Scalar & color ,
2013-03-30 16:03:55 +01:00
int thickness = 1 , int lineType = 8 , int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws the rectangle outline or a solid rectangle with the opposite corners pt1 and pt2 in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void rectangle ( CV_IN_OUT Mat & img , Point pt1 , Point pt2 ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2012-05-28 13:22:43 +02:00
//! draws the rectangle outline or a solid rectangle covering rec in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS void rectangle ( CV_IN_OUT Mat & img , Rect rec ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws the circle outline or a solid circle in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void circle ( CV_IN_OUT Mat & img , Point center , int radius ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws an elliptic arc, ellipse sector or a rotated ellipse in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void ellipse ( CV_IN_OUT Mat & img , Point center , Size axes ,
2010-05-11 19:44:00 +02:00
double angle , double startAngle , double endAngle ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws a rotated ellipse in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void ellipse ( CV_IN_OUT Mat & img , const RotatedRect & box , const Scalar & color ,
2013-03-30 16:03:55 +01:00
int thickness = 1 , int lineType = 8 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws a filled convex polygon in the image
2010-10-27 20:26:39 +02:00
CV_EXPORTS void fillConvexPoly ( Mat & img , const Point * pts , int npts ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int lineType = 8 ,
int shift = 0 ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W void fillConvexPoly ( InputOutputArray img , InputArray points ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int lineType = 8 ,
int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! fills an area bounded by one or more polygons
2010-10-27 20:26:39 +02:00
CV_EXPORTS void fillPoly ( Mat & img , const Point * * pts ,
const int * npts , int ncontours ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int lineType = 8 , int shift = 0 ,
Point offset = Point ( ) ) ;
2010-05-11 19:44:00 +02:00
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W void fillPoly ( InputOutputArray img , InputArrayOfArrays pts ,
2013-03-30 16:03:55 +01:00
const Scalar & color , int lineType = 8 , int shift = 0 ,
Point offset = Point ( ) ) ;
2011-07-18 18:31:30 +02:00
2010-05-25 16:57:10 +02:00
//! draws one or more polygonal curves
2012-10-16 17:37:12 +02:00
CV_EXPORTS void polylines ( Mat & img , const Point * const * pts , const int * npts ,
2010-10-12 14:31:40 +02:00
int ncontours , bool isClosed , const Scalar & color ,
2013-03-30 16:03:55 +01:00
int thickness = 1 , int lineType = 8 , int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2011-07-29 16:31:28 +02:00
CV_EXPORTS_W void polylines ( InputOutputArray img , InputArrayOfArrays pts ,
2011-07-18 18:31:30 +02:00
bool isClosed , const Scalar & color ,
2013-03-30 16:03:55 +01:00
int thickness = 1 , int lineType = 8 , int shift = 0 ) ;
2011-07-18 18:31:30 +02:00
2012-05-28 22:11:38 +02:00
//! draws contours in the image
CV_EXPORTS_W void drawContours ( InputOutputArray image , InputArrayOfArrays contours ,
int contourIdx , const Scalar & color ,
2013-03-30 16:03:55 +01:00
int thickness = 1 , int lineType = 8 ,
InputArray hierarchy = noArray ( ) ,
int maxLevel = INT_MAX , Point offset = Point ( ) ) ;
2012-05-28 22:11:38 +02:00
2010-05-25 16:57:10 +02:00
//! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height)
2010-10-27 20:26:39 +02:00
CV_EXPORTS bool clipLine ( Size imgSize , CV_IN_OUT Point & pt1 , CV_IN_OUT Point & pt2 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! clips the line segment by the rectangle imgRect
2011-07-14 16:13:10 +02:00
CV_EXPORTS_W bool clipLine ( Rect imgRect , CV_OUT CV_IN_OUT Point & pt1 , CV_OUT CV_IN_OUT Point & pt2 ) ;
2010-05-25 16:57:10 +02:00
//! converts elliptic arc to a polygonal curve
2010-10-27 20:26:39 +02:00
CV_EXPORTS_W void ellipse2Poly ( Point center , Size axes , int angle ,
2011-04-17 15:14:45 +02:00
int arcStart , int arcEnd , int delta ,
2013-02-24 17:14:01 +01:00
CV_OUT std : : vector < Point > & pts ) ;
2010-05-11 19:44:00 +02:00
enum
{
2013-03-30 16:03:55 +01:00
FONT_HERSHEY_SIMPLEX = 0 ,
FONT_HERSHEY_PLAIN = 1 ,
FONT_HERSHEY_DUPLEX = 2 ,
FONT_HERSHEY_COMPLEX = 3 ,
FONT_HERSHEY_TRIPLEX = 4 ,
FONT_HERSHEY_COMPLEX_SMALL = 5 ,
2010-05-11 19:44:00 +02:00
FONT_HERSHEY_SCRIPT_SIMPLEX = 6 ,
FONT_HERSHEY_SCRIPT_COMPLEX = 7 ,
2013-03-30 16:03:55 +01:00
FONT_ITALIC = 16
2010-05-11 19:44:00 +02:00
} ;
2010-05-25 16:57:10 +02:00
//! renders text string in the image
2013-03-22 17:37:49 +01:00
CV_EXPORTS_W void putText ( Mat & img , const String & text , Point org ,
2010-05-11 19:44:00 +02:00
int fontFace , double fontScale , Scalar color ,
2013-03-30 16:03:55 +01:00
int thickness = 1 , int lineType = 8 ,
bool bottomLeftOrigin = false ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! returns bounding box of the text string
2013-03-22 17:37:49 +01:00
CV_EXPORTS_W Size getTextSize ( const String & text , int fontFace ,
2010-05-11 19:44:00 +02:00
double fontScale , int thickness ,
2010-10-12 14:31:40 +02:00
CV_OUT int * baseLine ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
typedef void ( * ConvertData ) ( const void * from , void * to , int cn ) ;
typedef void ( * ConvertScaleData ) ( const void * from , void * to , int cn , double alpha , double beta ) ;
//! returns the function for converting pixels from one data type to another
CV_EXPORTS ConvertData getConvertElem ( int fromType , int toType ) ;
//! returns the function for converting pixels from one data type to another with the optional scaling
CV_EXPORTS ConvertScaleData getConvertScaleElem ( int fromType , int toType ) ;
2010-05-11 19:44:00 +02:00
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
/*!
2013-03-30 16:03:55 +01:00
Principal Component Analysis
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
The class PCA is used to compute the special basis for a set of vectors .
The basis will consist of eigenvectors of the covariance matrix computed
from the input set of vectors . After PCA is performed , vectors can be transformed from
the original high - dimensional space to the subspace formed by a few most
prominent eigenvectors ( called the principal components ) ,
corresponding to the largest eigenvalues of the covariation matrix .
Thus the dimensionality of the vector and the correlation between the coordinates is reduced .
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
The following sample is the function that takes two matrices . The first one stores the set
of vectors ( a row per vector ) that is used to compute PCA , the second one stores another
" test " set of vectors ( a row per vector ) that are first compressed with PCA ,
then reconstructed back and then the reconstruction error norm is computed and printed for each vector .
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
\ code
using namespace cv ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
PCA compressPCA ( const Mat & pcaset , int maxComponents ,
const Mat & testset , Mat & compressed )
{
PCA pca ( pcaset , // pass the data
Mat ( ) , // we do not have a pre-computed mean vector,
// so let the PCA engine to compute it
CV_PCA_DATA_AS_ROW , // indicate that the vectors
// are stored as matrix rows
// (use CV_PCA_DATA_AS_COL if the vectors are
// the matrix columns)
maxComponents // specify, how many principal components to retain
) ;
// if there is no test data, just return the computed basis, ready-to-use
if ( ! testset . data )
return pca ;
CV_Assert ( testset . cols = = pcaset . cols ) ;
compressed . create ( testset . rows , maxComponents , testset . type ( ) ) ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
Mat reconstructed ;
for ( int i = 0 ; i < testset . rows ; i + + )
{
Mat vec = testset . row ( i ) , coeffs = compressed . row ( i ) , reconstructed ;
// compress the vector, the result will be stored
// in the i-th row of the output matrix
pca . project ( vec , coeffs ) ;
// and then reconstruct it
pca . backProject ( coeffs , reconstructed ) ;
// and measure the error
printf ( " %d. diff = %g \n " , i , norm ( vec , reconstructed , NORM_L2 ) ) ;
}
return pca ;
}
\ endcode
2010-05-25 16:57:10 +02:00
*/
2013-03-30 16:03:55 +01:00
class CV_EXPORTS PCA
2010-05-11 19:44:00 +02:00
{
public :
2013-03-30 16:03:55 +01:00
//! default constructor
PCA ( ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! the constructor that performs PCA
PCA ( InputArray data , InputArray mean , int flags , int maxComponents = 0 ) ;
PCA ( InputArray data , InputArray mean , int flags , double retainedVariance ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! operator that performs PCA. The previously stored data, if any, is released
PCA & operator ( ) ( InputArray data , InputArray mean , int flags , int maxComponents = 0 ) ;
PCA & operator ( ) ( InputArray data , InputArray mean , int flags , double retainedVariance ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! projects vector from the original space to the principal components subspace
Mat project ( InputArray vec ) const ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! projects vector from the original space to the principal components subspace
void project ( InputArray vec , OutputArray result ) const ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! reconstructs the original vector from the projection
Mat backProject ( InputArray vec ) const ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
//! reconstructs the original vector from the projection
void backProject ( InputArray vec , OutputArray result ) const ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
Mat eigenvectors ; //!< eigenvectors of the covariation matrix
Mat eigenvalues ; //!< eigenvalues of the covariation matrix
Mat mean ; //!< mean value subtracted before the projection and added after the back projection
} ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
/*!
Singular Value Decomposition class
The class is used to compute Singular Value Decomposition of a floating - point matrix and then
use it to solve least - square problems , under - determined linear systems , invert matrices ,
compute condition numbers etc .
For a bit faster operation you can pass flags = SVD : : MODIFY_A | . . . to modify the decomposed matrix
when it is not necessarily to preserve it . If you want to compute condition number of a matrix
or absolute value of its determinant - you do not need SVD : : u or SVD : : vt ,
so you can pass flags = SVD : : NO_UV | . . . . Another flag SVD : : FULL_UV indicates that the full - size SVD : : u and SVD : : vt
must be computed , which is not necessary most of the time .
2010-05-25 16:57:10 +02:00
*/
2013-03-30 16:03:55 +01:00
class CV_EXPORTS SVD
2010-05-11 19:44:00 +02:00
{
public :
2013-03-30 16:03:55 +01:00
enum { MODIFY_A = 1 , NO_UV = 2 , FULL_UV = 4 } ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
//! the default constructor
SVD ( ) ;
2010-10-12 14:31:40 +02:00
2013-03-30 16:03:55 +01:00
//! the constructor that performs SVD
SVD ( InputArray src , int flags = 0 ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
SVD & operator ( ) ( InputArray src , int flags = 0 ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! decomposes matrix and stores the results to user-provided matrices
static void compute ( InputArray src , OutputArray w ,
OutputArray u , OutputArray vt , int flags = 0 ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! computes singular values of a matrix
static void compute ( InputArray src , OutputArray w , int flags = 0 ) ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
//! performs back substitution
static void backSubst ( InputArray w , InputArray u ,
InputArray vt , InputArray rhs ,
OutputArray dst ) ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
//! finds dst = arg min_{|dst|=1} |m*dst|
static void solveZ ( InputArray src , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
//! performs back substitution, so that dst is the solution or pseudo-solution of m*dst = rhs, where m is the decomposed matrix
void backSubst ( InputArray rhs , OutputArray dst ) const ;
2010-05-11 19:44:00 +02:00
2013-03-30 16:03:55 +01:00
template < typename _Tp , int m , int n , int nm > static
void compute ( const Matx < _Tp , m , n > & a , Matx < _Tp , nm , 1 > & w , Matx < _Tp , m , nm > & u , Matx < _Tp , n , nm > & vt ) ;
2010-05-25 16:57:10 +02:00
2013-03-30 16:03:55 +01:00
template < typename _Tp , int m , int n , int nm > static
void compute ( const Matx < _Tp , m , n > & a , Matx < _Tp , nm , 1 > & w ) ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
template < typename _Tp , int m , int n , int nm , int nb > static
void backSubst ( const Matx < _Tp , nm , 1 > & w , const Matx < _Tp , m , nm > & u , const Matx < _Tp , n , nm > & vt , const Matx < _Tp , m , nb > & rhs , Matx < _Tp , n , nb > & dst ) ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
Mat u , w , vt ;
} ;
2010-05-11 19:44:00 +02:00
2012-05-28 13:22:43 +02:00
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
/*!
2013-03-30 16:03:55 +01:00
Line iterator class
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
The class is used to iterate over all the pixels on the raster line
segment connecting two specified points .
2010-05-25 16:57:10 +02:00
*/
2013-03-30 16:03:55 +01:00
class CV_EXPORTS LineIterator
2010-05-11 19:44:00 +02:00
{
public :
2013-03-30 16:03:55 +01:00
//! intializes the iterator
LineIterator ( const Mat & img , Point pt1 , Point pt2 ,
int connectivity = 8 , bool leftToRight = false ) ;
//! returns pointer to the current pixel
uchar * operator * ( ) ;
//! prefix increment operator (++it). shifts iterator to the next pixel
LineIterator & operator + + ( ) ;
//! postfix increment operator (it++). shifts iterator to the next pixel
LineIterator operator + + ( int ) ;
//! returns coordinates of the current pixel
Point pos ( ) const ;
2012-05-28 13:22:43 +02:00
2013-03-30 16:03:55 +01:00
uchar * ptr ;
const uchar * ptr0 ;
int step , elemSize ;
int err , count ;
int minusDelta , plusDelta ;
int minusStep , plusStep ;
2010-05-11 19:44:00 +02:00
} ;
2013-03-30 16:03:55 +01:00
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
/*!
Fast Nearest Neighbor Search Class .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class implements D . Lowe BBF ( Best - Bin - First ) algorithm for the last
approximate ( or accurate ) nearest neighbor search in multi - dimensional spaces .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
First , a set of vectors is passed to KDTree : : KDTree ( ) constructor
or KDTree : : build ( ) method , where it is reordered .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
Then arbitrary vectors can be passed to KDTree : : findNearest ( ) methods , which
find the K nearest neighbors among the vectors from the initial set .
The user can balance between the speed and accuracy of the search by varying Emax
parameter , which is the number of leaves that the algorithm checks .
The larger parameter values yield more accurate results at the expense of lower processing speed .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
KDTree T ( points , false ) ;
const int K = 3 , Emax = INT_MAX ;
int idx [ K ] ;
float dist [ K ] ;
T . findNearest ( query_vec , K , Emax , idx , 0 , dist ) ;
CV_Assert ( dist [ 0 ] < = dist [ 1 ] & & dist [ 1 ] < = dist [ 2 ] ) ;
\ endcode
2012-05-28 13:22:43 +02:00
*/
2010-10-27 20:26:39 +02:00
class CV_EXPORTS_W KDTree
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
/*!
The node of the search tree .
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
struct Node
{
Node ( ) : idx ( - 1 ) , left ( - 1 ) , right ( - 1 ) , boundary ( 0.f ) { }
Node ( int _idx , int _left , int _right , float _boundary )
: idx ( _idx ) , left ( _left ) , right ( _right ) , boundary ( _boundary ) { }
2013-03-30 16:03:55 +01:00
2010-05-25 16:57:10 +02:00
//! split dimension; >=0 for nodes (dim), < 0 for leaves (index of the point)
int idx ;
//! node indices of the left and the right branches
int left , right ;
//! go to the left if query_vec[node.idx]<=node.boundary, otherwise go to the right
float boundary ;
2010-05-11 19:44:00 +02:00
} ;
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-10-27 20:26:39 +02:00
CV_WRAP KDTree ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor that builds the search tree
2013-03-30 16:03:55 +01:00
CV_WRAP KDTree ( InputArray points , bool copyAndReorderPoints = false ) ;
2010-11-02 18:58:22 +01:00
//! the full constructor that builds the search tree
2011-06-06 16:51:27 +02:00
CV_WRAP KDTree ( InputArray points , InputArray _labels ,
2013-03-30 16:03:55 +01:00
bool copyAndReorderPoints = false ) ;
2010-05-25 16:57:10 +02:00
//! builds the search tree
2013-03-30 16:03:55 +01:00
CV_WRAP void build ( InputArray points , bool copyAndReorderPoints = false ) ;
2010-11-02 18:58:22 +01:00
//! builds the search tree
2011-06-06 16:51:27 +02:00
CV_WRAP void build ( InputArray points , InputArray labels ,
2013-03-30 16:03:55 +01:00
bool copyAndReorderPoints = false ) ;
2010-05-25 16:57:10 +02:00
//! finds the K nearest neighbors of "vec" while looking at Emax (at most) leaves
2011-06-06 16:51:27 +02:00
CV_WRAP int findNearest ( InputArray vec , int K , int Emax ,
2011-04-17 15:14:45 +02:00
OutputArray neighborsIdx ,
2013-03-30 16:03:55 +01:00
OutputArray neighbors = noArray ( ) ,
OutputArray dist = noArray ( ) ,
OutputArray labels = noArray ( ) ) const ;
2012-05-28 13:22:43 +02:00
//! finds all the points from the initial set that belong to the specified box
2011-06-06 16:51:27 +02:00
CV_WRAP void findOrthoRange ( InputArray minBounds ,
InputArray maxBounds ,
2011-04-17 15:14:45 +02:00
OutputArray neighborsIdx ,
2013-03-30 16:03:55 +01:00
OutputArray neighbors = noArray ( ) ,
OutputArray labels = noArray ( ) ) const ;
2010-05-25 16:57:10 +02:00
//! returns vectors with the specified indices
2011-06-06 16:51:27 +02:00
CV_WRAP void getPoints ( InputArray idx , OutputArray pts ,
2013-03-30 16:03:55 +01:00
OutputArray labels = noArray ( ) ) const ;
2010-05-25 16:57:10 +02:00
//! return a vector with the specified index
2013-03-30 16:03:55 +01:00
const float * getPoint ( int ptidx , int * label = 0 ) const ;
2010-05-25 16:57:10 +02:00
//! returns the search space dimensionality
2010-10-27 20:26:39 +02:00
CV_WRAP int dims ( ) const ;
2010-05-11 19:44:00 +02:00
2013-02-24 17:14:01 +01:00
std : : vector < Node > nodes ; //!< all the tree nodes
2010-10-27 20:26:39 +02:00
CV_PROP Mat points ; //!< all the points. It can be a reordered copy of the input vector set or the original vector set.
2013-02-24 17:14:01 +01:00
CV_PROP std : : vector < int > labels ; //!< the parallel array of labels.
2010-10-27 20:26:39 +02:00
CV_PROP int maxDepth ; //!< maximum depth of the search tree. Do not modify it
CV_PROP_RW int normType ; //!< type of the distance (cv::NORM_L1 or cv::NORM_L2) used for search. Initially set to cv::NORM_L2, but you can modify it
2010-05-11 19:44:00 +02:00
} ;
2013-03-30 16:03:55 +01:00
2010-05-25 16:57:10 +02:00
/*!
2013-04-01 17:18:05 +02:00
Random Number Generator
2012-05-28 13:22:43 +02:00
2013-04-01 17:18:05 +02:00
The class implements RNG using Multiply - with - Carry algorithm
2010-05-25 16:57:10 +02:00
*/
2013-04-01 17:18:05 +02:00
class CV_EXPORTS RNG
2010-05-11 19:44:00 +02:00
{
public :
2013-04-01 17:18:05 +02:00
enum { UNIFORM = 0 , NORMAL = 1 } ;
2010-05-11 19:44:00 +02:00
2013-04-01 17:18:05 +02:00
RNG ( ) ;
RNG ( uint64 state ) ;
//! updates the state and returns the next 32-bit unsigned integer random number
unsigned next ( ) ;
2010-05-11 19:44:00 +02:00
2013-04-01 17:18:05 +02:00
operator uchar ( ) ;
operator schar ( ) ;
operator ushort ( ) ;
operator short ( ) ;
operator unsigned ( ) ;
//! returns a random integer sampled uniformly from [0, N).
unsigned operator ( ) ( unsigned N ) ;
unsigned operator ( ) ( ) ;
operator int ( ) ;
operator float ( ) ;
operator double ( ) ;
//! returns uniformly distributed integer random number from [a,b) range
int uniform ( int a , int b ) ;
//! returns uniformly distributed floating-point random number from [a,b) range
float uniform ( float a , float b ) ;
//! returns uniformly distributed double-precision floating-point random number from [a,b) range
double uniform ( double a , double b ) ;
void fill ( InputOutputArray mat , int distType , InputArray a , InputArray b , bool saturateRange = false ) ;
//! returns Gaussian random variate with mean zero.
double gaussian ( double sigma ) ;
2012-05-28 13:22:43 +02:00
2013-04-01 17:18:05 +02:00
uint64 state ;
} ;
2012-05-28 13:22:43 +02:00
2013-04-01 17:18:05 +02:00
class CV_EXPORTS RNG_MT19937
2010-05-11 19:44:00 +02:00
{
public :
2013-04-01 17:18:05 +02:00
RNG_MT19937 ( ) ;
RNG_MT19937 ( unsigned s ) ;
void seed ( unsigned s ) ;
unsigned next ( ) ;
2012-05-28 13:22:43 +02:00
2013-04-01 17:18:05 +02:00
operator int ( ) ;
operator unsigned ( ) ;
operator float ( ) ;
operator double ( ) ;
2010-05-11 19:44:00 +02:00
2013-04-01 17:18:05 +02:00
unsigned operator ( ) ( unsigned N ) ;
unsigned operator ( ) ( ) ;
2010-05-11 19:44:00 +02:00
2013-04-01 17:18:05 +02:00
// returns uniformly distributed integer random number from [a,b) range
int uniform ( int a , int b ) ;
// returns uniformly distributed floating-point random number from [a,b) range
float uniform ( float a , float b ) ;
// returns uniformly distributed double-precision floating-point random number from [a,b) range
double uniform ( double a , double b ) ;
2010-05-11 19:44:00 +02:00
2013-04-01 17:18:05 +02:00
private :
enum PeriodParameters { N = 624 , M = 397 } ;
unsigned state [ N ] ;
int mti ;
2010-05-11 19:44:00 +02:00
} ;
2010-05-25 16:57:10 +02:00
2013-03-29 09:59:55 +01:00
2013-04-01 17:18:05 +02:00
//////////////////////////////////////// Algorithm ////////////////////////////////////
2010-05-11 19:44:00 +02:00
2012-01-24 21:14:07 +01:00
class CV_EXPORTS Algorithm ;
class CV_EXPORTS AlgorithmInfo ;
struct CV_EXPORTS AlgorithmInfoData ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
template < typename _Tp > struct ParamType { } ;
2012-05-28 13:22:43 +02:00
2011-02-18 11:29:57 +01:00
/*!
Base class for high - level OpenCV algorithms
2012-05-28 13:22:43 +02:00
*/
2012-04-30 16:33:52 +02:00
class CV_EXPORTS_W Algorithm
2011-02-18 11:29:57 +01:00
{
public :
2012-01-24 21:14:07 +01:00
Algorithm ( ) ;
2011-02-18 11:29:57 +01:00
virtual ~ Algorithm ( ) ;
2013-03-22 17:37:49 +01:00
String name ( ) const ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
template < typename _Tp > typename ParamType < _Tp > : : member_type get ( const String & name ) const ;
2012-01-24 21:14:07 +01:00
template < typename _Tp > typename ParamType < _Tp > : : member_type get ( const char * name ) const ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
CV_WRAP int getInt ( const String & name ) const ;
CV_WRAP double getDouble ( const String & name ) const ;
CV_WRAP bool getBool ( const String & name ) const ;
CV_WRAP String getString ( const String & name ) const ;
CV_WRAP Mat getMat ( const String & name ) const ;
CV_WRAP std : : vector < Mat > getMatVector ( const String & name ) const ;
CV_WRAP Ptr < Algorithm > getAlgorithm ( const String & name ) const ;
void set ( const String & name , int value ) ;
void set ( const String & name , double value ) ;
void set ( const String & name , bool value ) ;
void set ( const String & name , const String & value ) ;
void set ( const String & name , const Mat & value ) ;
void set ( const String & name , const std : : vector < Mat > & value ) ;
void set ( const String & name , const Ptr < Algorithm > & value ) ;
template < typename _Tp > void set ( const String & name , const Ptr < _Tp > & value ) ;
CV_WRAP void setInt ( const String & name , int value ) ;
CV_WRAP void setDouble ( const String & name , double value ) ;
CV_WRAP void setBool ( const String & name , bool value ) ;
CV_WRAP void setString ( const String & name , const String & value ) ;
CV_WRAP void setMat ( const String & name , const Mat & value ) ;
CV_WRAP void setMatVector ( const String & name , const std : : vector < Mat > & value ) ;
CV_WRAP void setAlgorithm ( const String & name , const Ptr < Algorithm > & value ) ;
template < typename _Tp > void setAlgorithm ( const String & name , const Ptr < _Tp > & value ) ;
2012-10-23 19:37:27 +02:00
2012-03-15 15:36:01 +01:00
void set ( const char * name , int value ) ;
void set ( const char * name , double value ) ;
void set ( const char * name , bool value ) ;
2013-03-22 17:37:49 +01:00
void set ( const char * name , const String & value ) ;
2012-03-15 15:36:01 +01:00
void set ( const char * name , const Mat & value ) ;
2013-02-24 17:14:01 +01:00
void set ( const char * name , const std : : vector < Mat > & value ) ;
2012-03-15 15:36:01 +01:00
void set ( const char * name , const Ptr < Algorithm > & value ) ;
2012-06-28 14:17:11 +02:00
template < typename _Tp > void set ( const char * name , const Ptr < _Tp > & value ) ;
2012-05-28 13:22:43 +02:00
2012-10-23 19:37:27 +02:00
void setInt ( const char * name , int value ) ;
void setDouble ( const char * name , double value ) ;
void setBool ( const char * name , bool value ) ;
2013-03-22 17:37:49 +01:00
void setString ( const char * name , const String & value ) ;
2012-10-23 19:37:27 +02:00
void setMat ( const char * name , const Mat & value ) ;
2013-02-24 17:14:01 +01:00
void setMatVector ( const char * name , const std : : vector < Mat > & value ) ;
2012-10-23 19:37:27 +02:00
void setAlgorithm ( const char * name , const Ptr < Algorithm > & value ) ;
template < typename _Tp > void setAlgorithm ( const char * name , const Ptr < _Tp > & value ) ;
2013-03-22 17:37:49 +01:00
CV_WRAP String paramHelp ( const String & name ) const ;
2012-01-24 21:14:07 +01:00
int paramType ( const char * name ) const ;
2013-03-22 17:37:49 +01:00
CV_WRAP int paramType ( const String & name ) const ;
CV_WRAP void getParams ( CV_OUT std : : vector < String > & names ) const ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
virtual void write ( FileStorage & fs ) const ;
virtual void read ( const FileNode & fn ) ;
2012-05-28 13:22:43 +02:00
2011-02-18 11:29:57 +01:00
typedef Algorithm * ( * Constructor ) ( void ) ;
2012-01-24 21:14:07 +01:00
typedef int ( Algorithm : : * Getter ) ( ) const ;
typedef void ( Algorithm : : * Setter ) ( int ) ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
CV_WRAP static void getList ( CV_OUT std : : vector < String > & algorithms ) ;
CV_WRAP static Ptr < Algorithm > _create ( const String & name ) ;
template < typename _Tp > static Ptr < _Tp > create ( const String & name ) ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
virtual AlgorithmInfo * info ( ) const /* TODO: make it = 0 ; */ { return 0 ; }
} ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
class CV_EXPORTS AlgorithmInfo
{
public :
2012-04-30 16:33:52 +02:00
friend class Algorithm ;
2013-03-22 17:37:49 +01:00
AlgorithmInfo ( const String & name , Algorithm : : Constructor create ) ;
2012-01-24 21:14:07 +01:00
~ AlgorithmInfo ( ) ;
void get ( const Algorithm * algo , const char * name , int argType , void * value ) const ;
2012-03-17 10:50:47 +01:00
void addParam_ ( Algorithm & algo , const char * name , int argType ,
2012-05-28 13:22:43 +02:00
void * value , bool readOnly ,
2012-01-24 21:14:07 +01:00
Algorithm : : Getter getter , Algorithm : : Setter setter ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
String paramHelp ( const char * name ) const ;
2012-01-24 21:14:07 +01:00
int paramType ( const char * name ) const ;
2013-03-22 17:37:49 +01:00
void getParams ( std : : vector < String > & names ) const ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
void write ( const Algorithm * algo , FileStorage & fs ) const ;
void read ( Algorithm * algo , const FileNode & fn ) const ;
2013-03-22 17:37:49 +01:00
String name ( ) const ;
2012-05-28 13:22:43 +02:00
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
int & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
int ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( int ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
bool & value , bool readOnly = false ,
2012-03-15 15:36:01 +01:00
int ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( int ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
double & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
double ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( double ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2013-03-22 17:37:49 +01:00
String & value , bool readOnly = false ,
String ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const String & ) = 0 ,
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
Mat & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
Mat ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Mat & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-04-13 23:50:59 +02:00
void addParam ( Algorithm & algo , const char * name ,
2013-02-24 17:14:01 +01:00
std : : vector < Mat > & value , bool readOnly = false ,
std : : vector < Mat > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const std : : vector < Mat > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
Ptr < Algorithm > & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
Ptr < Algorithm > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Ptr < Algorithm > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
float & value , bool readOnly = false ,
float ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( float ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
unsigned int & value , bool readOnly = false ,
unsigned int ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( unsigned int ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
uint64 & value , bool readOnly = false ,
uint64 ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( uint64 ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
uchar & value , bool readOnly = false ,
uchar ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( uchar ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-06-29 09:46:53 +02:00
template < typename _Tp , typename _Base > void addParam ( Algorithm & algo , const char * name ,
Ptr < _Tp > & value , bool readOnly = false ,
Ptr < _Tp > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Ptr < _Tp > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-06-29 09:46:53 +02:00
template < typename _Tp > void addParam ( Algorithm & algo , const char * name ,
Ptr < _Tp > & value , bool readOnly = false ,
Ptr < _Tp > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Ptr < _Tp > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2011-02-18 11:29:57 +01:00
protected :
2012-01-24 21:14:07 +01:00
AlgorithmInfoData * data ;
2012-04-30 16:33:52 +02:00
void set ( Algorithm * algo , const char * name , int argType ,
const void * value , bool force = false ) const ;
2012-01-24 21:14:07 +01:00
} ;
struct CV_EXPORTS Param
{
2013-02-28 08:10:40 +01:00
enum { INT = 0 , BOOLEAN = 1 , REAL = 2 , STRING = 3 , MAT = 4 , MAT_VECTOR = 5 , ALGORITHM = 6 , FLOAT = 7 , UNSIGNED_INT = 8 , UINT64 = 9 , UCHAR = 11 } ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
Param ( ) ;
Param ( int _type , bool _readonly , int _offset ,
Algorithm : : Getter _getter = 0 ,
Algorithm : : Setter _setter = 0 ,
2013-03-22 17:37:49 +01:00
const String & _help = String ( ) ) ;
2012-01-24 21:14:07 +01:00
int type ;
int offset ;
bool readonly ;
Algorithm : : Getter getter ;
Algorithm : : Setter setter ;
2013-03-22 17:37:49 +01:00
String help ;
2012-01-24 21:14:07 +01:00
} ;
template < > struct ParamType < bool >
{
typedef bool const_param_type ;
typedef bool member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : BOOLEAN } ;
2012-05-28 13:22:43 +02:00
} ;
2012-01-24 21:14:07 +01:00
template < > struct ParamType < int >
{
typedef int const_param_type ;
typedef int member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : INT } ;
} ;
template < > struct ParamType < double >
{
typedef double const_param_type ;
typedef double member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : REAL } ;
} ;
2013-03-22 17:37:49 +01:00
template < > struct ParamType < String >
2012-01-24 21:14:07 +01:00
{
2013-03-22 17:37:49 +01:00
typedef const String & const_param_type ;
typedef String member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : STRING } ;
} ;
template < > struct ParamType < Mat >
{
typedef const Mat & const_param_type ;
typedef Mat member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : MAT } ;
2011-02-18 11:29:57 +01:00
} ;
2011-04-18 17:14:32 +02:00
2013-02-24 17:14:01 +01:00
template < > struct ParamType < std : : vector < Mat > >
2012-04-13 23:50:59 +02:00
{
2013-02-24 17:14:01 +01:00
typedef const std : : vector < Mat > & const_param_type ;
typedef std : : vector < Mat > member_type ;
2012-05-28 13:22:43 +02:00
2012-04-13 23:50:59 +02:00
enum { type = Param : : MAT_VECTOR } ;
} ;
2012-01-24 21:14:07 +01:00
template < > struct ParamType < Algorithm >
{
typedef const Ptr < Algorithm > & const_param_type ;
typedef Ptr < Algorithm > member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : ALGORITHM } ;
} ;
2012-05-28 13:22:43 +02:00
2012-09-07 15:44:01 +02:00
template < > struct ParamType < float >
2011-05-15 21:25:00 +02:00
{
2012-09-07 15:44:01 +02:00
typedef float const_param_type ;
typedef float member_type ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
enum { type = Param : : FLOAT } ;
2012-09-07 11:24:48 +02:00
} ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
template < > struct ParamType < unsigned >
2012-09-07 11:24:48 +02:00
{
2012-09-07 15:44:01 +02:00
typedef unsigned const_param_type ;
typedef unsigned member_type ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
enum { type = Param : : UNSIGNED_INT } ;
} ;
2011-08-04 18:09:04 +02:00
2012-09-07 15:44:01 +02:00
template < > struct ParamType < uint64 >
{
typedef uint64 const_param_type ;
typedef uint64 member_type ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
enum { type = Param : : UINT64 } ;
} ;
2011-05-15 21:25:00 +02:00
2013-02-04 17:25:18 +01:00
template < > struct ParamType < uchar >
{
typedef uchar const_param_type ;
typedef uchar member_type ;
enum { type = Param : : UCHAR } ;
} ;
2012-09-07 11:24:48 +02:00
2013-03-14 17:10:54 +01:00
} //namespace cv
2010-05-11 19:44:00 +02:00
# include "opencv2/core/operations.hpp"
2013-03-20 10:00:04 +01:00
# include "opencv2/core/cvstd.inl.hpp"
2013-03-28 15:22:40 +01:00
2013-03-30 16:03:55 +01:00
2010-05-11 19:44:00 +02:00
# endif /*__OPENCV_CORE_HPP__*/