Commit c886afb5 authored by Andrey Kamaev's avatar Andrey Kamaev

Finalize cv::Mat transition

parent 71e43852
This source diff could not be displayed because it is too large. You can view the blob instead.
/*! \file core.hpp
\brief The Core Functionality
*/
/*M/////////////////////////////////////////////////////////////////////////////////////// /*M///////////////////////////////////////////////////////////////////////////////////////
// //
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
...@@ -83,11 +80,6 @@ struct CvSeqBlock; ...@@ -83,11 +80,6 @@ struct CvSeqBlock;
*/ */
namespace cv { namespace cv {
class CV_EXPORTS MatOp_Base;
class CV_EXPORTS MatArg;
template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
/*! /*!
The standard OpenCV exception class. The standard OpenCV exception class.
Instances of the class are thrown by various functions and methods in the case of critical errors. Instances of the class are thrown by various functions and methods in the case of critical errors.
...@@ -146,7 +138,7 @@ CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll ...@@ -146,7 +138,7 @@ CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll
class CV_EXPORTS RNG class CV_EXPORTS RNG
{ {
public: public:
enum { UNIFORM=0, NORMAL=1 }; enum { UNIFORM = 0, NORMAL = 1 };
RNG(); RNG();
RNG(uint64 state); RNG(uint64 state);
...@@ -170,7 +162,7 @@ public: ...@@ -170,7 +162,7 @@ public:
float uniform(float a, float b); float uniform(float a, float b);
//! returns uniformly distributed double-precision floating-point random number from [a,b) range //! returns uniformly distributed double-precision floating-point random number from [a,b) range
double uniform(double a, double b); double uniform(double a, double b);
void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange=false ); void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false );
//! returns Gaussian random variate with mean zero. //! returns Gaussian random variate with mean zero.
double gaussian(double sigma); double gaussian(double sigma);
...@@ -221,93 +213,115 @@ CV_EXPORTS void swap(Mat& a, Mat& b); ...@@ -221,93 +213,115 @@ CV_EXPORTS void swap(Mat& a, Mat& b);
//! adds one matrix to another (dst = src1 + src2) //! adds one matrix to another (dst = src1 + src2)
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
InputArray mask=noArray(), int dtype=-1); InputArray mask = noArray(), int dtype = -1);
//! subtracts one matrix from another (dst = src1 - src2) //! subtracts one matrix from another (dst = src1 - src2)
CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
InputArray mask=noArray(), int dtype=-1); InputArray mask = noArray(), int dtype = -1);
//! computes element-wise weighted product of the two arrays (dst = scale*src1*src2) //! computes element-wise weighted product of the two arrays (dst = scale*src1*src2)
CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, CV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
OutputArray dst, double scale=1, int dtype=-1); OutputArray dst, double scale = 1, int dtype = -1);
//! computes element-wise weighted quotient of the two arrays (dst = scale*src1/src2) //! computes element-wise weighted quotient of the two arrays (dst = scale * src1 / src2)
CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
double scale=1, int dtype=-1); double scale = 1, int dtype = -1);
//! computes element-wise weighted reciprocal of an array (dst = scale/src2) //! computes element-wise weighted reciprocal of an array (dst = scale/src2)
CV_EXPORTS_W void divide(double scale, InputArray src2, CV_EXPORTS_W void divide(double scale, InputArray src2,
OutputArray dst, int dtype=-1); OutputArray dst, int dtype = -1);
//! adds scaled array to another one (dst = alpha*src1 + src2) //! adds scaled array to another one (dst = alpha*src1 + src2)
CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst); CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
//! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma) //! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2, CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
double beta, double gamma, OutputArray dst, int dtype=-1); double beta, double gamma, OutputArray dst, int dtype = -1);
//! 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) //! 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)
CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst, CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
double alpha=1, double beta=0); double alpha = 1, double beta = 0);
//! transforms array of numbers using a lookup table: dst(i)=lut(src(i)) //! transforms array of numbers using a lookup table: dst(i)=lut(src(i))
CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst, CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst,
int interpolation=0); int interpolation = 0);
//! computes sum of array elements //! computes sum of array elements
CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src); CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
//! computes the number of nonzero array elements //! computes the number of nonzero array elements
CV_EXPORTS_W int countNonZero( InputArray src ); CV_EXPORTS_W int countNonZero( InputArray src );
//! returns the list of locations of non-zero pixels //! returns the list of locations of non-zero pixels
CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx ); CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
//! computes mean value of selected array elements //! computes mean value of selected array elements
CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask=noArray()); CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray());
//! computes mean value and standard deviation of all or selected array elements //! computes mean value and standard deviation of all or selected array elements
CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev, CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
InputArray mask=noArray()); InputArray mask=noArray());
//! computes norm of the selected array part //! computes norm of the selected array part
CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray()); CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray());
//! computes norm of selected part of the difference between two arrays //! computes norm of selected part of the difference between two arrays
CV_EXPORTS_W double norm(InputArray src1, InputArray src2, CV_EXPORTS_W double norm(InputArray src1, InputArray src2,
int normType=NORM_L2, InputArray mask=noArray()); int normType = NORM_L2, InputArray mask = noArray());
//! computes norm of a sparse matrix
CV_EXPORTS double norm( const SparseMat& src, int normType );
//! naive nearest neighbor finder //! naive nearest neighbor finder
CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2, CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2,
OutputArray dist, int dtype, OutputArray nidx, OutputArray dist, int dtype, OutputArray nidx,
int normType=NORM_L2, int K=0, int normType = NORM_L2, int K = 0,
InputArray mask=noArray(), int update=0, InputArray mask = noArray(), int update = 0,
bool crosscheck=false); bool crosscheck = false);
//! 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 //! 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_W void normalize( InputArray src, OutputArray dst, double alpha=1, double beta=0, 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()); 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 );
//! finds global minimum and maximum array elements and returns their values and their locations //! finds global minimum and maximum array elements and returns their values and their locations
CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal, CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0, CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0,
CV_OUT Point* maxLoc=0, InputArray mask=noArray()); CV_OUT Point* maxLoc = 0, InputArray mask = noArray());
CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal,
int* minIdx=0, int* maxIdx=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);
//! transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows //! transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows
CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype=-1); CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype = -1);
//! makes multi-channel array out of several single-channel arrays //! makes multi-channel array out of several single-channel arrays
CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst); CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
//! makes multi-channel array out of several single-channel arrays //! makes multi-channel array out of several single-channel arrays
CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst); CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst);
//! copies each plane of a multi-channel array to a dedicated array //! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS void split(const Mat& src, Mat* mvbegin); CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
//! copies each plane of a multi-channel array to a dedicated array //! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv); CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv);
//! copies selected channels from the input arrays to the selected channels of the output arrays //! copies selected channels from the input arrays to the selected channels of the output arrays
CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
const int* fromTo, size_t npairs); const int* fromTo, size_t npairs);
CV_EXPORTS void mixChannels(const std::vector<Mat>& src, std::vector<Mat>& dst, CV_EXPORTS void mixChannels(const std::vector<Mat>& src, std::vector<Mat>& dst,
const int* fromTo, size_t npairs); const int* fromTo, size_t npairs); //TODO: use arrays
CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputArrayOfArrays dst, CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputArrayOfArrays dst,
const std::vector<int>& fromTo); const std::vector<int>& fromTo); //TODO: InputOutputArrayOfArrays
//! extracts a single channel from src (coi is 0-based index) //! extracts a single channel from src (coi is 0-based index)
CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi); CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
...@@ -320,40 +334,54 @@ CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode); ...@@ -320,40 +334,54 @@ CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
//! replicates the input matrix the specified number of times in the horizontal and/or vertical direction //! replicates the input matrix the specified number of times in the horizontal and/or vertical direction
CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst); CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx); CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst); CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst); CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst); CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst);
CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst); CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst); CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst); CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst);
//! computes bitwise conjunction of the two arrays (dst = src1 & src2) //! computes bitwise conjunction of the two arrays (dst = src1 & src2)
CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
OutputArray dst, InputArray mask=noArray()); OutputArray dst, InputArray mask = noArray());
//! computes bitwise disjunction of the two arrays (dst = src1 | src2) //! computes bitwise disjunction of the two arrays (dst = src1 | src2)
CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
OutputArray dst, InputArray mask=noArray()); OutputArray dst, InputArray mask = noArray());
//! computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2) //! computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2)
CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
OutputArray dst, InputArray mask=noArray()); OutputArray dst, InputArray mask = noArray());
//! inverts each bit of array (dst = ~src) //! inverts each bit of array (dst = ~src)
CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
InputArray mask=noArray()); InputArray mask = noArray());
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2)) //! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst); CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
//! set mask elements for those array elements which are within the element-specific bounding box (dst = lowerb <= src && src < upperb) //! set mask elements for those array elements which are within the element-specific bounding box (dst = lowerb <= src && src < upperb)
CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb, CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
InputArray upperb, OutputArray dst); InputArray upperb, OutputArray dst);
//! compares elements of two arrays (dst = src1 <cmpop> src2) //! compares elements of two arrays (dst = src1 <cmpop> src2)
CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop); CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
//! computes per-element minimum of two arrays (dst = min(src1, src2)) //! computes per-element minimum of two arrays (dst = min(src1, src2))
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst); CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
//! computes per-element maximum of two arrays (dst = max(src1, src2)) //! computes per-element maximum of two arrays (dst = max(src1, src2))
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst); CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
//TODO: can we drop these versions?
//! computes per-element minimum of two arrays (dst = min(src1, src2)) //! computes per-element minimum of two arrays (dst = min(src1, src2))
CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst); CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
//! computes per-element minimum of array and scalar (dst = min(src1, src2)) //! computes per-element minimum of array and scalar (dst = min(src1, src2))
...@@ -365,192 +393,128 @@ CV_EXPORTS void max(const Mat& src1, double src2, Mat& dst); ...@@ -365,192 +393,128 @@ CV_EXPORTS void max(const Mat& src1, double src2, Mat& dst);
//! computes square root of each matrix element (dst = src**0.5) //! computes square root of each matrix element (dst = src**0.5)
CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst); CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
//! raises the input matrix elements to the specified power (b = a**power) //! raises the input matrix elements to the specified power (b = a**power)
CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst); CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
//! computes exponent of each matrix element (dst = e**src) //! computes exponent of each matrix element (dst = e**src)
CV_EXPORTS_W void exp(InputArray src, OutputArray dst); CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
//! computes natural logarithm of absolute value of each matrix element: dst = log(abs(src)) //! computes natural logarithm of absolute value of each matrix element: dst = log(abs(src))
CV_EXPORTS_W void log(InputArray src, OutputArray dst); CV_EXPORTS_W void log(InputArray src, OutputArray dst);
//! computes cube root of the argument
CV_EXPORTS_W float cubeRoot(float val);
//! computes the angle in degrees (0..360) of the vector (x,y)
CV_EXPORTS_W float fastAtan2(float y, float x);
CV_EXPORTS void exp(const float* src, float* dst, int n);
CV_EXPORTS void log(const float* src, float* dst, int n);
CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees);
CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n);
//! converts polar coordinates to Cartesian //! converts polar coordinates to Cartesian
CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle, CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
OutputArray x, OutputArray y, bool angleInDegrees=false); OutputArray x, OutputArray y, bool angleInDegrees = false);
//! converts Cartesian coordinates to polar //! converts Cartesian coordinates to polar
CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y, CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
OutputArray magnitude, OutputArray angle, OutputArray magnitude, OutputArray angle,
bool angleInDegrees=false); bool angleInDegrees = false);
//! computes angle (angle(i)) of each (x(i), y(i)) vector //! computes angle (angle(i)) of each (x(i), y(i)) vector
CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle, CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
bool angleInDegrees=false); bool angleInDegrees = false);
//! computes magnitude (magnitude(i)) of each (x(i), y(i)) vector //! computes magnitude (magnitude(i)) of each (x(i), y(i)) vector
CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude); CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
//! checks that each matrix element is within the specified range. //! checks that each matrix element is within the specified range.
CV_EXPORTS_W bool checkRange(InputArray a, bool quiet=true, CV_OUT Point* pos=0, CV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0,
double minVal=-DBL_MAX, double maxVal=DBL_MAX); double minVal = -DBL_MAX, double maxVal = DBL_MAX);
//! converts NaN's to the given number //! converts NaN's to the given number
CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val=0); CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0);
//! implements generalized matrix product algorithm GEMM from BLAS //! implements generalized matrix product algorithm GEMM from BLAS
CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
InputArray src3, double gamma, OutputArray dst, int flags=0); InputArray src3, double gamma, OutputArray dst, int flags = 0);
//! multiplies matrix by its transposition from the left or from the right //! multiplies matrix by its transposition from the left or from the right
CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa, CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
InputArray delta=noArray(), InputArray delta = noArray(),
double scale=1, int dtype=-1 ); double scale = 1, int dtype = -1 );
//! transposes the matrix //! transposes the matrix
CV_EXPORTS_W void transpose(InputArray src, OutputArray dst); CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
//! performs affine transformation of each element of multi-channel input matrix //! performs affine transformation of each element of multi-channel input matrix
CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m ); CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
//! performs perspective transformation of each element of multi-channel input matrix //! performs perspective transformation of each element of multi-channel input matrix
CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m ); CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
//! extends the symmetrical matrix from the lower half or from the upper half //! extends the symmetrical matrix from the lower half or from the upper half
CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper=false); CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper = false);
//! initializes scaled identity matrix //! initializes scaled identity matrix
CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s=Scalar(1)); CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1));
//! computes determinant of a square matrix //! computes determinant of a square matrix
CV_EXPORTS_W double determinant(InputArray mtx); CV_EXPORTS_W double determinant(InputArray mtx);
//! computes trace of a matrix //! computes trace of a matrix
CV_EXPORTS_W Scalar trace(InputArray mtx); CV_EXPORTS_W Scalar trace(InputArray mtx);
//! computes inverse or pseudo-inverse matrix //! computes inverse or pseudo-inverse matrix
CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU); CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_LU);
//! solves linear system or a least-square problem //! solves linear system or a least-square problem
CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, CV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
OutputArray dst, int flags=DECOMP_LU); OutputArray dst, int flags = DECOMP_LU);
enum enum
{ {
SORT_EVERY_ROW=0, SORT_EVERY_ROW = 0,
SORT_EVERY_COLUMN=1, SORT_EVERY_COLUMN = 1,
SORT_ASCENDING=0, SORT_ASCENDING = 0,
SORT_DESCENDING=16 SORT_DESCENDING = 16
}; };
//! sorts independently each matrix row or each matrix column //! sorts independently each matrix row or each matrix column
CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags); CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
//! sorts independently each matrix row or each matrix column //! sorts independently each matrix row or each matrix column
CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags); CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
//! finds real roots of a cubic polynomial //! finds real roots of a cubic polynomial
CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots); CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
//! finds real and complex roots of a polynomial //! finds real and complex roots of a polynomial
CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters=300); CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters = 300);
//! finds eigenvalues of a symmetric matrix //! finds eigenvalues of a symmetric matrix
CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-1, CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, int lowindex = -1,
int highindex=-1); int highindex = -1);
//! finds eigenvalues and eigenvectors of a symmetric matrix //! finds eigenvalues and eigenvectors of a symmetric matrix
CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues,
OutputArray eigenvectors, OutputArray eigenvectors,
int lowindex=-1, int highindex=-1); int lowindex = -1, int highindex = -1);
CV_EXPORTS_W bool eigen(InputArray src, bool computeEigenvectors, CV_EXPORTS_W bool eigen(InputArray src, bool computeEigenvectors,
OutputArray eigenvalues, OutputArray eigenvectors); OutputArray eigenvalues, OutputArray eigenvectors);
enum enum
{ {
COVAR_SCRAMBLED=0, COVAR_SCRAMBLED = 0,
COVAR_NORMAL=1, COVAR_NORMAL = 1,
COVAR_USE_AVG=2, COVAR_USE_AVG = 2,
COVAR_SCALE=4, COVAR_SCALE = 4,
COVAR_ROWS=8, COVAR_ROWS = 8,
COVAR_COLS=16 COVAR_COLS = 16
}; };
//! computes covariation matrix of a set of samples //! computes covariation matrix of a set of samples
CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean, CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
int flags, int ctype=CV_64F); int flags, int ctype = CV_64F); //TODO: output arrays or drop
//! computes covariation matrix of a set of samples
CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
OutputArray mean, int flags, int ctype=CV_64F);
/*!
Principal Component Analysis
The class PCA is used to compute the special basis for a set of vectors. //! computes covariation matrix of a set of samples
The basis will consist of eigenvectors of the covariance matrix computed CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar, //TODO: InputArrayOfArrays
from the input set of vectors. After PCA is performed, vectors can be transformed from OutputArray mean, int flags, int ctype = CV_64F);
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.
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.
\code
using namespace cv;
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());
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
*/
class CV_EXPORTS PCA
{
public:
//! default constructor
PCA();
//! the constructor that performs PCA
PCA(InputArray data, InputArray mean, int flags, int maxComponents=0);
PCA(InputArray data, InputArray mean, int flags, double retainedVariance);
//! 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);
//! projects vector from the original space to the principal components subspace
Mat project(InputArray vec) const;
//! projects vector from the original space to the principal components subspace
void project(InputArray vec, OutputArray result) const;
//! reconstructs the original vector from the projection
Mat backProject(InputArray vec) const;
//! reconstructs the original vector from the projection
void backProject(InputArray vec, OutputArray result) const;
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
};
CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
OutputArray eigenvectors, int maxComponents=0); OutputArray eigenvectors, int maxComponents = 0);
CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
OutputArray eigenvectors, double retainedVariance); OutputArray eigenvectors, double retainedVariance);
...@@ -561,58 +525,8 @@ CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean, ...@@ -561,58 +525,8 @@ CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean, CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
InputArray eigenvectors, OutputArray result); InputArray eigenvectors, OutputArray result);
/*!
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.
*/
class CV_EXPORTS SVD
{
public:
enum { MODIFY_A=1, NO_UV=2, FULL_UV=4 };
//! the default constructor
SVD();
//! the constructor that performs SVD
SVD( InputArray src, int flags=0 );
//! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
SVD& operator ()( InputArray src, int flags=0 );
//! decomposes matrix and stores the results to user-provided matrices
static void compute( InputArray src, OutputArray w,
OutputArray u, OutputArray vt, int flags=0 );
//! computes singular values of a matrix
static void compute( InputArray src, OutputArray w, int flags=0 );
//! performs back substitution
static void backSubst( InputArray w, InputArray u,
InputArray vt, InputArray rhs,
OutputArray dst );
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 );
template<typename _Tp, int m, int n, int nm> static void compute( const Matx<_Tp, m, n>& a,
Matx<_Tp, nm, 1>& w );
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 );
//! finds dst = arg min_{|dst|=1} |m*dst|
static void solveZ( InputArray src, OutputArray dst );
//! 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;
Mat u, w, vt;
};
//! computes SVD of src //! computes SVD of src
CV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags=0 ); CV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags = 0 );
//! performs back substitution for the previously computed SVD //! performs back substitution for the previously computed SVD
CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt, CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
...@@ -620,43 +534,47 @@ CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt, ...@@ -620,43 +534,47 @@ CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
//! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix //! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix
CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar); CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
//! a synonym for Mahalanobis //! a synonym for Mahalanobis
CV_EXPORTS double Mahalonobis(InputArray v1, InputArray v2, InputArray icovar); CV_EXPORTS double Mahalonobis(InputArray v1, InputArray v2, InputArray icovar); //TODO: check if we can drop it or move to legacy
//! performs forward or inverse 1D or 2D Discrete Fourier Transformation //! performs forward or inverse 1D or 2D Discrete Fourier Transformation
CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0); CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
//! performs inverse 1D or 2D Discrete Fourier Transformation //! performs inverse 1D or 2D Discrete Fourier Transformation
CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0); CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
//! performs forward or inverse 1D or 2D Discrete Cosine Transformation //! performs forward or inverse 1D or 2D Discrete Cosine Transformation
CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags=0); CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags = 0);
//! performs inverse 1D or 2D Discrete Cosine Transformation //! performs inverse 1D or 2D Discrete Cosine Transformation
CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags=0); CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0);
//! computes element-wise product of the two Fourier spectrums. The second spectrum can optionally be conjugated before the multiplication //! computes element-wise product of the two Fourier spectrums. The second spectrum can optionally be conjugated before the multiplication
CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c, CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
int flags, bool conjB=false); int flags, bool conjB = false);
//! computes the minimal vector size vecsize1 >= vecsize so that the dft() of the vector of length vecsize1 can be computed efficiently //! computes the minimal vector size vecsize1 >= vecsize so that the dft() of the vector of length vecsize1 can be computed efficiently
CV_EXPORTS_W int getOptimalDFTSize(int vecsize); CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
/*! /*!
Various k-Means flags k-Means flags
*/ */
enum enum
{ {
KMEANS_RANDOM_CENTERS=0, // Chooses random centers for k-Means initialization KMEANS_RANDOM_CENTERS = 0, // Chooses random centers for k-Means initialization
KMEANS_PP_CENTERS=2, // Uses k-Means++ algorithm for 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 KMEANS_USE_INITIAL_LABELS = 1 // Uses the user-provided labels for K-Means initialization
}; };
//! clusters the input data using k-Means algorithm //! clusters the input data using k-Means algorithm
CV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels, CV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels,
TermCriteria criteria, int attempts, TermCriteria criteria, int attempts,
int flags, OutputArray centers=noArray() ); int flags, OutputArray centers = noArray() );
//! returns the thread-local Random number generator //! returns the thread-local Random number generator
CV_EXPORTS RNG& theRNG(); CV_EXPORTS RNG& theRNG();
//! returns the next unifomly-distributed random number of the specified type
template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
//! fills array with uniformly-distributed random numbers from the range [low, high) //! fills array with uniformly-distributed random numbers from the range [low, high)
CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high); CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
...@@ -664,71 +582,73 @@ CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high); ...@@ -664,71 +582,73 @@ CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev); CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
//! shuffles the input array elements //! shuffles the input array elements
CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor=1., RNG* rng=0); CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG* rng = 0);
CV_EXPORTS_AS(randShuffle) void randShuffle_(InputOutputArray dst, double iterFactor=1.);
CV_EXPORTS_AS(randShuffle) void randShuffle_(InputOutputArray dst, double iterFactor = 1.);
//! draws the line segment (pt1, pt2) in the image //! draws the line segment (pt1, pt2) in the image
CV_EXPORTS_W void line(CV_IN_OUT Mat& img, Point pt1, Point pt2, const Scalar& color, CV_EXPORTS_W void line(CV_IN_OUT Mat& img, Point pt1, Point pt2, const Scalar& color,
int thickness=1, int lineType=8, int shift=0); int thickness = 1, int lineType = 8, int shift = 0);
//! draws the rectangle outline or a solid rectangle with the opposite corners pt1 and pt2 in the image //! draws the rectangle outline or a solid rectangle with the opposite corners pt1 and pt2 in the image
CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2, CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2,
const Scalar& color, int thickness=1, const Scalar& color, int thickness = 1,
int lineType=8, int shift=0); int lineType = 8, int shift = 0);
//! draws the rectangle outline or a solid rectangle covering rec in the image //! draws the rectangle outline or a solid rectangle covering rec in the image
CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec, CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
const Scalar& color, int thickness=1, const Scalar& color, int thickness = 1,
int lineType=8, int shift=0); int lineType = 8, int shift = 0);
//! draws the circle outline or a solid circle in the image //! draws the circle outline or a solid circle in the image
CV_EXPORTS_W void circle(CV_IN_OUT Mat& img, Point center, int radius, CV_EXPORTS_W void circle(CV_IN_OUT Mat& img, Point center, int radius,
const Scalar& color, int thickness=1, const Scalar& color, int thickness = 1,
int lineType=8, int shift=0); int lineType = 8, int shift = 0);
//! draws an elliptic arc, ellipse sector or a rotated ellipse in the image //! draws an elliptic arc, ellipse sector or a rotated ellipse in the image
CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, Point center, Size axes, CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, Point center, Size axes,
double angle, double startAngle, double endAngle, double angle, double startAngle, double endAngle,
const Scalar& color, int thickness=1, const Scalar& color, int thickness = 1,
int lineType=8, int shift=0); int lineType = 8, int shift = 0);
//! draws a rotated ellipse in the image //! draws a rotated ellipse in the image
CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, const RotatedRect& box, const Scalar& color, CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, const RotatedRect& box, const Scalar& color,
int thickness=1, int lineType=8); int thickness = 1, int lineType = 8);
//! draws a filled convex polygon in the image //! draws a filled convex polygon in the image
CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts, CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
const Scalar& color, int lineType=8, const Scalar& color, int lineType = 8,
int shift=0); int shift = 0);
CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points, CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
const Scalar& color, int lineType=8, const Scalar& color, int lineType = 8,
int shift=0); int shift = 0);
//! fills an area bounded by one or more polygons //! fills an area bounded by one or more polygons
CV_EXPORTS void fillPoly(Mat& img, const Point** pts, CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
const int* npts, int ncontours, const int* npts, int ncontours,
const Scalar& color, int lineType=8, int shift=0, const Scalar& color, int lineType = 8, int shift = 0,
Point offset=Point() ); Point offset = Point() );
CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts, CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
const Scalar& color, int lineType=8, int shift=0, const Scalar& color, int lineType = 8, int shift = 0,
Point offset=Point() ); Point offset = Point() );
//! draws one or more polygonal curves //! draws one or more polygonal curves
CV_EXPORTS void polylines(Mat& img, const Point* const* pts, const int* npts, CV_EXPORTS void polylines(Mat& img, const Point* const* pts, const int* npts,
int ncontours, bool isClosed, const Scalar& color, int ncontours, bool isClosed, const Scalar& color,
int thickness=1, int lineType=8, int shift=0 ); int thickness = 1, int lineType = 8, int shift = 0 );
CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts, CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
bool isClosed, const Scalar& color, bool isClosed, const Scalar& color,
int thickness=1, int lineType=8, int shift=0 ); int thickness = 1, int lineType = 8, int shift = 0 );
//! draws contours in the image //! draws contours in the image
CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours, CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours,
int contourIdx, const Scalar& color, int contourIdx, const Scalar& color,
int thickness=1, int lineType=8, int thickness = 1, int lineType = 8,
InputArray hierarchy=noArray(), InputArray hierarchy = noArray(),
int maxLevel=INT_MAX, Point offset=Point() ); int maxLevel = INT_MAX, Point offset = Point() );
//! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height) //! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height)
CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2); CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
...@@ -736,35 +656,6 @@ CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt ...@@ -736,35 +656,6 @@ CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt
//! clips the line segment by the rectangle imgRect //! clips the line segment by the rectangle imgRect
CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2); CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);
/*!
Line iterator class
The class is used to iterate over all the pixels on the raster line
segment connecting two specified points.
*/
class CV_EXPORTS LineIterator
{
public:
//! 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;
uchar* ptr;
const uchar* ptr0;
int step, elemSize;
int err, count;
int minusDelta, plusDelta;
int minusStep, plusStep;
};
//! converts elliptic arc to a polygonal curve //! converts elliptic arc to a polygonal curve
CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
int arcStart, int arcEnd, int delta, int arcStart, int arcEnd, int delta,
...@@ -772,428 +663,215 @@ CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, ...@@ -772,428 +663,215 @@ CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
enum enum
{ {
FONT_HERSHEY_SIMPLEX = 0, FONT_HERSHEY_SIMPLEX = 0,
FONT_HERSHEY_PLAIN = 1, FONT_HERSHEY_PLAIN = 1,
FONT_HERSHEY_DUPLEX = 2, FONT_HERSHEY_DUPLEX = 2,
FONT_HERSHEY_COMPLEX = 3, FONT_HERSHEY_COMPLEX = 3,
FONT_HERSHEY_TRIPLEX = 4, FONT_HERSHEY_TRIPLEX = 4,
FONT_HERSHEY_COMPLEX_SMALL = 5, FONT_HERSHEY_COMPLEX_SMALL = 5,
FONT_HERSHEY_SCRIPT_SIMPLEX = 6, FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
FONT_HERSHEY_SCRIPT_COMPLEX = 7, FONT_HERSHEY_SCRIPT_COMPLEX = 7,
FONT_ITALIC = 16 FONT_ITALIC = 16
}; };
//! renders text string in the image //! renders text string in the image
CV_EXPORTS_W void putText( Mat& img, const String& text, Point org, CV_EXPORTS_W void putText( Mat& img, const String& text, Point org,
int fontFace, double fontScale, Scalar color, int fontFace, double fontScale, Scalar color,
int thickness=1, int lineType=8, int thickness = 1, int lineType = 8,
bool bottomLeftOrigin=false ); bool bottomLeftOrigin = false );
//! returns bounding box of the text string //! returns bounding box of the text string
CV_EXPORTS_W Size getTextSize(const String& text, int fontFace, CV_EXPORTS_W Size getTextSize(const String& text, int fontFace,
double fontScale, int thickness, double fontScale, int thickness,
CV_OUT int* baseLine); CV_OUT int* baseLine);
//////////// Iterators & Comma initializers ////////////////// 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);
class CV_EXPORTS MatConstIterator
{
public:
typedef uchar* value_type;
typedef ptrdiff_t difference_type;
typedef const uchar** pointer;
typedef uchar* reference;
typedef std::random_access_iterator_tag iterator_category;
//! default constructor
MatConstIterator();
//! constructor that sets the iterator to the beginning of the matrix
MatConstIterator(const Mat* _m);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator(const Mat* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator(const Mat* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator(const Mat* _m, const int* _idx);
//! copy constructor
MatConstIterator(const MatConstIterator& it);
//! copy operator
MatConstIterator& operator = (const MatConstIterator& it);
//! returns the current matrix element
uchar* operator *() const;
//! returns the i-th matrix element, relative to the current
uchar* operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatConstIterator& operator += (ptrdiff_t ofs);
//! shifts the iterator backward by the specified number of elements
MatConstIterator& operator -= (ptrdiff_t ofs);
//! decrements the iterator
MatConstIterator& operator --();
//! decrements the iterator
MatConstIterator operator --(int);
//! increments the iterator
MatConstIterator& operator ++();
//! increments the iterator
MatConstIterator operator ++(int);
//! returns the current iterator position
Point pos() const;
//! returns the current iterator position
void pos(int* _idx) const;
ptrdiff_t lpos() const;
void seek(ptrdiff_t ofs, bool relative=false);
void seek(const int* _idx, bool relative=false);
const Mat* m;
size_t elemSize;
uchar* ptr;
uchar* sliceStart;
uchar* sliceEnd;
};
/*! /*!
Matrix read-only iterator Principal Component Analysis
*/ The class PCA is used to compute the special basis for a set of vectors.
template<typename _Tp> The basis will consist of eigenvectors of the covariance matrix computed
class CV_EXPORTS MatConstIterator_ : public MatConstIterator 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
public: prominent eigenvectors (called the principal components),
typedef _Tp value_type; corresponding to the largest eigenvalues of the covariation matrix.
typedef ptrdiff_t difference_type; Thus the dimensionality of the vector and the correlation between the coordinates is reduced.
typedef const _Tp* pointer;
typedef const _Tp& reference;
typedef std::random_access_iterator_tag iterator_category;
//! default constructor The following sample is the function that takes two matrices. The first one stores the set
MatConstIterator_(); of vectors (a row per vector) that is used to compute PCA, the second one stores another
//! constructor that sets the iterator to the beginning of the matrix "test" set of vectors (a row per vector) that are first compressed with PCA,
MatConstIterator_(const Mat_<_Tp>* _m); then reconstructed back and then the reconstruction error norm is computed and printed for each vector.
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
//! copy constructor
MatConstIterator_(const MatConstIterator_& it);
//! copy operator
MatConstIterator_& operator = (const MatConstIterator_& it);
//! returns the current matrix element
_Tp operator *() const;
//! returns the i-th matrix element, relative to the current
_Tp operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatConstIterator_& operator += (ptrdiff_t ofs);
//! shifts the iterator backward by the specified number of elements
MatConstIterator_& operator -= (ptrdiff_t ofs);
//! decrements the iterator
MatConstIterator_& operator --();
//! decrements the iterator
MatConstIterator_ operator --(int);
//! increments the iterator
MatConstIterator_& operator ++();
//! increments the iterator
MatConstIterator_ operator ++(int);
//! returns the current iterator position
Point pos() const;
};
\code
using namespace cv;
/*! PCA compressPCA(const Mat& pcaset, int maxComponents,
Matrix read-write iterator 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());
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
*/ */
template<typename _Tp> class CV_EXPORTS PCA
class CV_EXPORTS MatIterator_ : public MatConstIterator_<_Tp>
{ {
public: public:
typedef _Tp* pointer; //! default constructor
typedef _Tp& reference; PCA();
typedef std::random_access_iterator_tag iterator_category;
//! the default constructor //! the constructor that performs PCA
MatIterator_(); PCA(InputArray data, InputArray mean, int flags, int maxComponents = 0);
//! constructor that sets the iterator to the beginning of the matrix PCA(InputArray data, InputArray mean, int flags, double retainedVariance);
MatIterator_(Mat_<_Tp>* _m);
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(const Mat_<_Tp>* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
//! copy constructor
MatIterator_(const MatIterator_& it);
//! copy operator
MatIterator_& operator = (const MatIterator_<_Tp>& it );
//! returns the current matrix element
_Tp& operator *() const;
//! returns the i-th matrix element, relative to the current
_Tp& operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatIterator_& operator += (ptrdiff_t ofs);
//! shifts the iterator backward by the specified number of elements
MatIterator_& operator -= (ptrdiff_t ofs);
//! decrements the iterator
MatIterator_& operator --();
//! decrements the iterator
MatIterator_ operator --(int);
//! increments the iterator
MatIterator_& operator ++();
//! increments the iterator
MatIterator_ operator ++(int);
};
template<typename _Tp> class CV_EXPORTS MatOp_Iter_; //! 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);
//! projects vector from the original space to the principal components subspace
Mat project(InputArray vec) const;
/////////////////////////// multi-dimensional dense matrix ////////////////////////// //! projects vector from the original space to the principal components subspace
void project(InputArray vec, OutputArray result) const;
/*! //! reconstructs the original vector from the projection
n-Dimensional Dense Matrix Iterator Class. Mat backProject(InputArray vec) const;
The class cv::NAryMatIterator is used for iterating over one or more n-dimensional dense arrays (cv::Mat's). //! reconstructs the original vector from the projection
void backProject(InputArray vec, OutputArray result) const;
The iterator is completely different from cv::Mat_ and cv::SparseMat_ iterators. Mat eigenvectors; //!< eigenvectors of the covariation matrix
It iterates through the slices (or planes), not the elements, where "slice" is a continuous part of the arrays. Mat eigenvalues; //!< eigenvalues of the covariation matrix
Mat mean; //!< mean value subtracted before the projection and added after the back projection
};
Here is the example on how the iterator can be used to normalize 3D histogram:
\code
void normalizeColorHist(Mat& hist)
{
#if 1
// intialize iterator (the style is different from STL).
// after initialization the iterator will contain
// the number of slices or planes
// the iterator will go through
Mat* arrays[] = { &hist, 0 };
Mat planes[1];
NAryMatIterator it(arrays, planes);
double s = 0;
// iterate through the matrix. on each iteration
// it.planes[i] (of type Mat) will be set to the current plane of
// i-th n-dim matrix passed to the iterator constructor.
for(int p = 0; p < it.nplanes; p++, ++it)
s += sum(it.planes[0])[0];
it = NAryMatIterator(hist);
s = 1./s;
for(int p = 0; p < it.nplanes; p++, ++it)
it.planes[0] *= s;
#elif 1
// this is a shorter implementation of the above
// using built-in operations on Mat
double s = sum(hist)[0];
hist.convertTo(hist, hist.type(), 1./s, 0);
#else
// and this is even shorter one
// (assuming that the histogram elements are non-negative)
normalize(hist, hist, 1, 0, NORM_L1);
#endif
}
\endcode
You can iterate through several matrices simultaneously as long as they have the same geometry /*!
(dimensionality and all the dimension sizes are the same), which is useful for binary Singular Value Decomposition class
and n-ary operations on such matrices. Just pass those matrices to cv::MatNDIterator.
Then, during the iteration it.planes[0], it.planes[1], ... will The class is used to compute Singular Value Decomposition of a floating-point matrix and then
be the slices of the corresponding matrices 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.
*/ */
class CV_EXPORTS NAryMatIterator class CV_EXPORTS SVD
{ {
public: public:
//! the default constructor enum { MODIFY_A = 1, NO_UV = 2, FULL_UV = 4 };
NAryMatIterator();
//! the full constructor taking arbitrary number of n-dim matrices
NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1);
//! the full constructor taking arbitrary number of n-dim matrices
NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
//! the separate iterator initialization method
void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
//! proceeds to the next plane of every iterated matrix
NAryMatIterator& operator ++();
//! proceeds to the next plane of every iterated matrix (postfix increment operator)
NAryMatIterator operator ++(int);
//! the iterated arrays
const Mat** arrays;
//! the current planes
Mat* planes;
//! data pointers
uchar** ptrs;
//! the number of arrays
int narrays;
//! the number of hyper-planes that the iterator steps through
size_t nplanes;
//! the size of each segment (in elements)
size_t size;
protected:
int iterdepth;
size_t idx;
};
//typedef NAryMatIterator NAryMatNDIterator; //! the default constructor
SVD();
typedef void (*ConvertData)(const void* from, void* to, int cn); //! the constructor that performs SVD
typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alpha, double beta); SVD( InputArray src, int flags = 0 );
//! returns the function for converting pixels from one data type to another //! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
CV_EXPORTS ConvertData getConvertElem(int fromType, int toType); SVD& operator ()( InputArray src, int flags = 0 );
//! returns the function for converting pixels from one data type to another with the optional scaling
CV_EXPORTS ConvertScaleData getConvertScaleElem(int fromType, int toType);
//! finds global minimum and maximum sparse array elements and returns their values and their locations //! decomposes matrix and stores the results to user-provided matrices
CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal, static void compute( InputArray src, OutputArray w,
double* maxVal, int* minIdx=0, int* maxIdx=0); OutputArray u, OutputArray vt, int flags = 0 );
//! computes norm of a sparse matrix
CV_EXPORTS double norm( const SparseMat& src, int normType );
//! 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 );
/*! //! computes singular values of a matrix
Read-Only Sparse Matrix Iterator. static void compute( InputArray src, OutputArray w, int flags = 0 );
Here is how to use the iterator to compute the sum of floating-point sparse matrix elements:
\code //! performs back substitution
SparseMatConstIterator it = m.begin(), it_end = m.end(); static void backSubst( InputArray w, InputArray u,
double s = 0; InputArray vt, InputArray rhs,
CV_Assert( m.type() == CV_32F ); OutputArray dst );
for( ; it != it_end; ++it )
s += it.value<float>();
\endcode
*/
class CV_EXPORTS SparseMatConstIterator
{
public:
//! the default constructor
SparseMatConstIterator();
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatConstIterator(const SparseMat* _m);
//! the copy constructor
SparseMatConstIterator(const SparseMatConstIterator& it);
//! the assignment operator
SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
//! template method returning the current matrix element
template<typename _Tp> const _Tp& value() const;
//! returns the current node of the sparse matrix. it.node->idx is the current element index
const SparseMat::Node* node() const;
//! moves iterator to the previous element
SparseMatConstIterator& operator --();
//! moves iterator to the previous element
SparseMatConstIterator operator --(int);
//! moves iterator to the next element
SparseMatConstIterator& operator ++();
//! moves iterator to the next element
SparseMatConstIterator operator ++(int);
//! moves iterator to the element after the last element
void seekEnd();
const SparseMat* m;
size_t hashidx;
uchar* ptr;
};
/*! //! finds dst = arg min_{|dst|=1} |m*dst|
Read-write Sparse Matrix Iterator static void solveZ( InputArray src, OutputArray dst );
The class is similar to cv::SparseMatConstIterator, //! performs back substitution, so that dst is the solution or pseudo-solution of m*dst = rhs, where m is the decomposed matrix
but can be used for in-place modification of the matrix elements. void backSubst( InputArray rhs, OutputArray dst ) const;
*/
class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
{
public:
//! the default constructor
SparseMatIterator();
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatIterator(SparseMat* _m);
//! the full constructor setting the iterator to the specified sparse matrix element
SparseMatIterator(SparseMat* _m, const int* idx);
//! the copy constructor
SparseMatIterator(const SparseMatIterator& it);
//! the assignment operator
SparseMatIterator& operator = (const SparseMatIterator& it);
//! returns read-write reference to the current sparse matrix element
template<typename _Tp> _Tp& value() const;
//! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!)
SparseMat::Node* node() const;
//! moves iterator to the next element
SparseMatIterator& operator ++();
//! moves iterator to the next element
SparseMatIterator operator ++(int);
};
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 );
/*! template<typename _Tp, int m, int n, int nm> static
Template Read-Only Sparse Matrix Iterator Class. void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w );
This is the derived from SparseMatConstIterator class that template<typename _Tp, int m, int n, int nm, int nb> static
introduces more convenient operator *() for accessing the current element. 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 );
*/
template<typename _Tp> class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
{
public:
typedef std::forward_iterator_tag iterator_category;
//! the default constructor Mat u, w, vt;
SparseMatConstIterator_(); };
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
//! the copy constructor
SparseMatConstIterator_(const SparseMatConstIterator_& it);
//! the assignment operator
SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
//! the element access operator
const _Tp& operator *() const;
//! moves iterator to the next element
SparseMatConstIterator_& operator ++();
//! moves iterator to the next element
SparseMatConstIterator_ operator ++(int);
};
/*! /*!
Template Read-Write Sparse Matrix Iterator Class. Line iterator class
This is the derived from cv::SparseMatConstIterator_ class that The class is used to iterate over all the pixels on the raster line
introduces more convenient operator *() for accessing the current element. segment connecting two specified points.
*/ */
template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp> class CV_EXPORTS LineIterator
{ {
public: public:
typedef std::forward_iterator_tag iterator_category; //! intializes the iterator
LineIterator( const Mat& img, Point pt1, Point pt2,
//! the default constructor int connectivity = 8, bool leftToRight = false );
SparseMatIterator_(); //! returns pointer to the current pixel
//! the full constructor setting the iterator to the first sparse matrix element uchar* operator *();
SparseMatIterator_(SparseMat_<_Tp>* _m); //! prefix increment operator (++it). shifts iterator to the next pixel
//! the copy constructor LineIterator& operator ++();
SparseMatIterator_(const SparseMatIterator_& it); //! postfix increment operator (it++). shifts iterator to the next pixel
LineIterator operator ++(int);
//! the assignment operator //! returns coordinates of the current pixel
SparseMatIterator_& operator = (const SparseMatIterator_& it); Point pos() const;
//! returns the reference to the current element
_Tp& operator *() const;
//! moves the iterator to the next element uchar* ptr;
SparseMatIterator_& operator ++(); const uchar* ptr0;
//! moves the iterator to the next element int step, elemSize;
SparseMatIterator_ operator ++(int); int err, count;
int minusDelta, plusDelta;
int minusStep, plusStep;
}; };
//////////////////// Fast Nearest-Neighbor Search Structure ////////////////////
/*! /*!
Fast Nearest Neighbor Search Class. Fast Nearest Neighbor Search Class.
...@@ -1230,6 +908,7 @@ public: ...@@ -1230,6 +908,7 @@ public:
Node() : idx(-1), left(-1), right(-1), boundary(0.f) {} Node() : idx(-1), left(-1), right(-1), boundary(0.f) {}
Node(int _idx, int _left, int _right, float _boundary) Node(int _idx, int _left, int _right, float _boundary)
: idx(_idx), left(_left), right(_right), boundary(_boundary) {} : idx(_idx), left(_left), right(_right), boundary(_boundary) {}
//! split dimension; >=0 for nodes (dim), < 0 for leaves (index of the point) //! split dimension; >=0 for nodes (dim), < 0 for leaves (index of the point)
int idx; int idx;
//! node indices of the left and the right branches //! node indices of the left and the right branches
...@@ -1241,32 +920,32 @@ public: ...@@ -1241,32 +920,32 @@ public:
//! the default constructor //! the default constructor
CV_WRAP KDTree(); CV_WRAP KDTree();
//! the full constructor that builds the search tree //! the full constructor that builds the search tree
CV_WRAP KDTree(InputArray points, bool copyAndReorderPoints=false); CV_WRAP KDTree(InputArray points, bool copyAndReorderPoints = false);
//! the full constructor that builds the search tree //! the full constructor that builds the search tree
CV_WRAP KDTree(InputArray points, InputArray _labels, CV_WRAP KDTree(InputArray points, InputArray _labels,
bool copyAndReorderPoints=false); bool copyAndReorderPoints = false);
//! builds the search tree //! builds the search tree
CV_WRAP void build(InputArray points, bool copyAndReorderPoints=false); CV_WRAP void build(InputArray points, bool copyAndReorderPoints = false);
//! builds the search tree //! builds the search tree
CV_WRAP void build(InputArray points, InputArray labels, CV_WRAP void build(InputArray points, InputArray labels,
bool copyAndReorderPoints=false); bool copyAndReorderPoints = false);
//! finds the K nearest neighbors of "vec" while looking at Emax (at most) leaves //! finds the K nearest neighbors of "vec" while looking at Emax (at most) leaves
CV_WRAP int findNearest(InputArray vec, int K, int Emax, CV_WRAP int findNearest(InputArray vec, int K, int Emax,
OutputArray neighborsIdx, OutputArray neighborsIdx,
OutputArray neighbors=noArray(), OutputArray neighbors = noArray(),
OutputArray dist=noArray(), OutputArray dist = noArray(),
OutputArray labels=noArray()) const; OutputArray labels = noArray()) const;
//! finds all the points from the initial set that belong to the specified box //! finds all the points from the initial set that belong to the specified box
CV_WRAP void findOrthoRange(InputArray minBounds, CV_WRAP void findOrthoRange(InputArray minBounds,
InputArray maxBounds, InputArray maxBounds,
OutputArray neighborsIdx, OutputArray neighborsIdx,
OutputArray neighbors=noArray(), OutputArray neighbors = noArray(),
OutputArray labels=noArray()) const; OutputArray labels = noArray()) const;
//! returns vectors with the specified indices //! returns vectors with the specified indices
CV_WRAP void getPoints(InputArray idx, OutputArray pts, CV_WRAP void getPoints(InputArray idx, OutputArray pts,
OutputArray labels=noArray()) const; OutputArray labels = noArray()) const;
//! return a vector with the specified index //! return a vector with the specified index
const float* getPoint(int ptidx, int* label=0) const; const float* getPoint(int ptidx, int* label = 0) const;
//! returns the search space dimensionality //! returns the search space dimensionality
CV_WRAP int dims() const; CV_WRAP int dims() const;
...@@ -1277,6 +956,11 @@ public: ...@@ -1277,6 +956,11 @@ public:
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 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
}; };
//////////////////////////////////////// XML & YAML I/O //////////////////////////////////// //////////////////////////////////////// XML & YAML I/O ////////////////////////////////////
class CV_EXPORTS FileNode; class CV_EXPORTS FileNode;
...@@ -1883,7 +1567,7 @@ template<> struct ParamType<uchar> ...@@ -1883,7 +1567,7 @@ template<> struct ParamType<uchar>
} //namespace cv } //namespace cv
#include "opencv2/core/operations.hpp" #include "opencv2/core/operations.hpp"
#include "opencv2/core/mat.inl.hpp"
#include "opencv2/core/cvstd.inl.hpp" #include "opencv2/core/cvstd.inl.hpp"
#endif /*__OPENCV_CORE_HPP__*/ #endif /*__OPENCV_CORE_HPP__*/
...@@ -279,11 +279,22 @@ CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); ...@@ -279,11 +279,22 @@ CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n);
CV_EXPORTS float normL1_(const float* a, const float* b, int n);
CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n); CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n);
CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n); CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n);
CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize); CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize);
CV_EXPORTS float normL1_(const float* a, const float* b, int n);
CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n);
CV_EXPORTS void exp(const float* src, float* dst, int n);
CV_EXPORTS void log(const float* src, float* dst, int n);
CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees);
CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n);
//! computes cube root of the argument
CV_EXPORTS_W float cubeRoot(float val);
//! computes the angle in degrees (0..360) of the vector (x,y)
CV_EXPORTS_W float fastAtan2(float y, float x);
...@@ -442,11 +453,11 @@ class CV_EXPORTS KeyPoint; ...@@ -442,11 +453,11 @@ class CV_EXPORTS KeyPoint;
class CV_EXPORTS DMatch; class CV_EXPORTS DMatch;
class CV_EXPORTS Mat; class CV_EXPORTS Mat;
class CV_EXPORTS MatExpr;
class CV_EXPORTS SparseMat; class CV_EXPORTS SparseMat;
typedef Mat MatND; typedef Mat MatND;
class CV_EXPORTS MatExpr;
template<typename _Tp> class CV_EXPORTS Mat_; template<typename _Tp> class CV_EXPORTS Mat_;
template<typename _Tp> class CV_EXPORTS SparseMat_; template<typename _Tp> class CV_EXPORTS SparseMat_;
...@@ -470,8 +481,6 @@ namespace gpu ...@@ -470,8 +481,6 @@ namespace gpu
class CV_EXPORTS GpuMat; class CV_EXPORTS GpuMat;
} }
} // cv } // cv
#endif //__OPENCV_CORE_BASE_HPP__ #endif //__OPENCV_CORE_BASE_HPP__
...@@ -91,7 +91,6 @@ public: ...@@ -91,7 +91,6 @@ public:
template<typename _Tp> _InputArray(const std::vector<Mat_<_Tp> >& vec); template<typename _Tp> _InputArray(const std::vector<Mat_<_Tp> >& vec);
template<typename _Tp> _InputArray(const _Tp* vec, int n); template<typename _Tp> _InputArray(const _Tp* vec, int n);
template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx); template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
_InputArray(const Scalar& s);
_InputArray(const double& val); _InputArray(const double& val);
_InputArray(const gpu::GpuMat& d_mat); _InputArray(const gpu::GpuMat& d_mat);
_InputArray(const ogl::Buffer& buf); _InputArray(const ogl::Buffer& buf);
...@@ -780,7 +779,6 @@ public: ...@@ -780,7 +779,6 @@ public:
MStep step; MStep step;
protected: protected:
void initEmpty();
}; };
...@@ -1345,7 +1343,7 @@ public: ...@@ -1345,7 +1343,7 @@ public:
///////////////////////////////// Mat_<_Tp> //////////////////////////////////// ///////////////////////////////// SparseMat_<_Tp> ////////////////////////////////////
/*! /*!
The Template Sparse Matrix class derived from cv::SparseMat The Template Sparse Matrix class derived from cv::SparseMat
...@@ -1427,6 +1425,598 @@ public: ...@@ -1427,6 +1425,598 @@ public:
SparseMatConstIterator_<_Tp> end() const; SparseMatConstIterator_<_Tp> end() const;
}; };
////////////////////////////////// MatConstIterator //////////////////////////////////
class CV_EXPORTS MatConstIterator
{
public:
typedef uchar* value_type;
typedef ptrdiff_t difference_type;
typedef const uchar** pointer;
typedef uchar* reference;
#ifndef OPENCV_NOSTL
typedef std::random_access_iterator_tag iterator_category;
#endif
//! default constructor
MatConstIterator();
//! constructor that sets the iterator to the beginning of the matrix
MatConstIterator(const Mat* _m);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator(const Mat* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator(const Mat* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator(const Mat* _m, const int* _idx);
//! copy constructor
MatConstIterator(const MatConstIterator& it);
//! copy operator
MatConstIterator& operator = (const MatConstIterator& it);
//! returns the current matrix element
uchar* operator *() const;
//! returns the i-th matrix element, relative to the current
uchar* operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatConstIterator& operator += (ptrdiff_t ofs);
//! shifts the iterator backward by the specified number of elements
MatConstIterator& operator -= (ptrdiff_t ofs);
//! decrements the iterator
MatConstIterator& operator --();
//! decrements the iterator
MatConstIterator operator --(int);
//! increments the iterator
MatConstIterator& operator ++();
//! increments the iterator
MatConstIterator operator ++(int);
//! returns the current iterator position
Point pos() const;
//! returns the current iterator position
void pos(int* _idx) const;
ptrdiff_t lpos() const;
void seek(ptrdiff_t ofs, bool relative = false);
void seek(const int* _idx, bool relative = false);
const Mat* m;
size_t elemSize;
uchar* ptr;
uchar* sliceStart;
uchar* sliceEnd;
};
////////////////////////////////// MatConstIterator_ /////////////////////////////////
/*!
Matrix read-only iterator
*/
template<typename _Tp>
class MatConstIterator_ : public MatConstIterator
{
public:
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
#ifndef OPENCV_NOSTL
typedef std::random_access_iterator_tag iterator_category;
#endif
//! default constructor
MatConstIterator_();
//! constructor that sets the iterator to the beginning of the matrix
MatConstIterator_(const Mat_<_Tp>* _m);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
//! copy constructor
MatConstIterator_(const MatConstIterator_& it);
//! copy operator
MatConstIterator_& operator = (const MatConstIterator_& it);
//! returns the current matrix element
_Tp operator *() const;
//! returns the i-th matrix element, relative to the current
_Tp operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatConstIterator_& operator += (ptrdiff_t ofs);
//! shifts the iterator backward by the specified number of elements
MatConstIterator_& operator -= (ptrdiff_t ofs);
//! decrements the iterator
MatConstIterator_& operator --();
//! decrements the iterator
MatConstIterator_ operator --(int);
//! increments the iterator
MatConstIterator_& operator ++();
//! increments the iterator
MatConstIterator_ operator ++(int);
//! returns the current iterator position
Point pos() const;
};
//////////////////////////////////// MatIterator_ ////////////////////////////////////
/*!
Matrix read-write iterator
*/
template<typename _Tp>
class MatIterator_ : public MatConstIterator_<_Tp>
{
public:
typedef _Tp* pointer;
typedef _Tp& reference;
#ifndef OPENCV_NOSTL
typedef std::random_access_iterator_tag iterator_category;
#endif
//! the default constructor
MatIterator_();
//! constructor that sets the iterator to the beginning of the matrix
MatIterator_(Mat_<_Tp>* _m);
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(const Mat_<_Tp>* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
//! copy constructor
MatIterator_(const MatIterator_& it);
//! copy operator
MatIterator_& operator = (const MatIterator_<_Tp>& it );
//! returns the current matrix element
_Tp& operator *() const;
//! returns the i-th matrix element, relative to the current
_Tp& operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatIterator_& operator += (ptrdiff_t ofs);
//! shifts the iterator backward by the specified number of elements
MatIterator_& operator -= (ptrdiff_t ofs);
//! decrements the iterator
MatIterator_& operator --();
//! decrements the iterator
MatIterator_ operator --(int);
//! increments the iterator
MatIterator_& operator ++();
//! increments the iterator
MatIterator_ operator ++(int);
};
/////////////////////////////// SparseMatConstIterator ///////////////////////////////
/*!
Read-Only Sparse Matrix Iterator.
Here is how to use the iterator to compute the sum of floating-point sparse matrix elements:
\code
SparseMatConstIterator it = m.begin(), it_end = m.end();
double s = 0;
CV_Assert( m.type() == CV_32F );
for( ; it != it_end; ++it )
s += it.value<float>();
\endcode
*/
class CV_EXPORTS SparseMatConstIterator
{
public:
//! the default constructor
SparseMatConstIterator();
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatConstIterator(const SparseMat* _m);
//! the copy constructor
SparseMatConstIterator(const SparseMatConstIterator& it);
//! the assignment operator
SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
//! template method returning the current matrix element
template<typename _Tp> const _Tp& value() const;
//! returns the current node of the sparse matrix. it.node->idx is the current element index
const SparseMat::Node* node() const;
//! moves iterator to the previous element
SparseMatConstIterator& operator --();
//! moves iterator to the previous element
SparseMatConstIterator operator --(int);
//! moves iterator to the next element
SparseMatConstIterator& operator ++();
//! moves iterator to the next element
SparseMatConstIterator operator ++(int);
//! moves iterator to the element after the last element
void seekEnd();
const SparseMat* m;
size_t hashidx;
uchar* ptr;
};
////////////////////////////////// SparseMatIterator /////////////////////////////////
/*!
Read-write Sparse Matrix Iterator
The class is similar to cv::SparseMatConstIterator,
but can be used for in-place modification of the matrix elements.
*/
class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
{
public:
//! the default constructor
SparseMatIterator();
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatIterator(SparseMat* _m);
//! the full constructor setting the iterator to the specified sparse matrix element
SparseMatIterator(SparseMat* _m, const int* idx);
//! the copy constructor
SparseMatIterator(const SparseMatIterator& it);
//! the assignment operator
SparseMatIterator& operator = (const SparseMatIterator& it);
//! returns read-write reference to the current sparse matrix element
template<typename _Tp> _Tp& value() const;
//! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!)
SparseMat::Node* node() const;
//! moves iterator to the next element
SparseMatIterator& operator ++();
//! moves iterator to the next element
SparseMatIterator operator ++(int);
};
/////////////////////////////// SparseMatConstIterator_ //////////////////////////////
/*!
Template Read-Only Sparse Matrix Iterator Class.
This is the derived from SparseMatConstIterator class that
introduces more convenient operator *() for accessing the current element.
*/
template<typename _Tp> class SparseMatConstIterator_ : public SparseMatConstIterator
{
public:
#ifndef OPENCV_NOSTL
typedef std::forward_iterator_tag iterator_category;
#endif
//! the default constructor
SparseMatConstIterator_();
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
//! the copy constructor
SparseMatConstIterator_(const SparseMatConstIterator_& it);
//! the assignment operator
SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
//! the element access operator
const _Tp& operator *() const;
//! moves iterator to the next element
SparseMatConstIterator_& operator ++();
//! moves iterator to the next element
SparseMatConstIterator_ operator ++(int);
};
///////////////////////////////// SparseMatIterator_ /////////////////////////////////
/*!
Template Read-Write Sparse Matrix Iterator Class.
This is the derived from cv::SparseMatConstIterator_ class that
introduces more convenient operator *() for accessing the current element.
*/
template<typename _Tp> class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
{
public:
#ifndef OPENCV_NOSTL
typedef std::forward_iterator_tag iterator_category;
#endif
//! the default constructor
SparseMatIterator_();
//! the full constructor setting the iterator to the first sparse matrix element
SparseMatIterator_(SparseMat_<_Tp>* _m);
//! the copy constructor
SparseMatIterator_(const SparseMatIterator_& it);
//! the assignment operator
SparseMatIterator_& operator = (const SparseMatIterator_& it);
//! returns the reference to the current element
_Tp& operator *() const;
//! moves the iterator to the next element
SparseMatIterator_& operator ++();
//! moves the iterator to the next element
SparseMatIterator_ operator ++(int);
};
/////////////////////////////////// NAryMatIterator //////////////////////////////////
/*!
n-Dimensional Dense Matrix Iterator Class.
The class cv::NAryMatIterator is used for iterating over one or more n-dimensional dense arrays (cv::Mat's).
The iterator is completely different from cv::Mat_ and cv::SparseMat_ iterators.
It iterates through the slices (or planes), not the elements, where "slice" is a continuous part of the arrays.
Here is the example on how the iterator can be used to normalize 3D histogram:
\code
void normalizeColorHist(Mat& hist)
{
#if 1
// intialize iterator (the style is different from STL).
// after initialization the iterator will contain
// the number of slices or planes
// the iterator will go through
Mat* arrays[] = { &hist, 0 };
Mat planes[1];
NAryMatIterator it(arrays, planes);
double s = 0;
// iterate through the matrix. on each iteration
// it.planes[i] (of type Mat) will be set to the current plane of
// i-th n-dim matrix passed to the iterator constructor.
for(int p = 0; p < it.nplanes; p++, ++it)
s += sum(it.planes[0])[0];
it = NAryMatIterator(hist);
s = 1./s;
for(int p = 0; p < it.nplanes; p++, ++it)
it.planes[0] *= s;
#elif 1
// this is a shorter implementation of the above
// using built-in operations on Mat
double s = sum(hist)[0];
hist.convertTo(hist, hist.type(), 1./s, 0);
#else
// and this is even shorter one
// (assuming that the histogram elements are non-negative)
normalize(hist, hist, 1, 0, NORM_L1);
#endif
}
\endcode
You can iterate through several matrices simultaneously as long as they have the same geometry
(dimensionality and all the dimension sizes are the same), which is useful for binary
and n-ary operations on such matrices. Just pass those matrices to cv::MatNDIterator.
Then, during the iteration it.planes[0], it.planes[1], ... will
be the slices of the corresponding matrices
*/
class CV_EXPORTS NAryMatIterator
{
public:
//! the default constructor
NAryMatIterator();
//! the full constructor taking arbitrary number of n-dim matrices
NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1);
//! the full constructor taking arbitrary number of n-dim matrices
NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
//! the separate iterator initialization method
void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
//! proceeds to the next plane of every iterated matrix
NAryMatIterator& operator ++();
//! proceeds to the next plane of every iterated matrix (postfix increment operator)
NAryMatIterator operator ++(int);
//! the iterated arrays
const Mat** arrays;
//! the current planes
Mat* planes;
//! data pointers
uchar** ptrs;
//! the number of arrays
int narrays;
//! the number of hyper-planes that the iterator steps through
size_t nplanes;
//! the size of each segment (in elements)
size_t size;
protected:
int iterdepth;
size_t idx;
};
///////////////////////////////// Matrix Expressions /////////////////////////////////
class CV_EXPORTS MatOp
{
public:
MatOp();
virtual ~MatOp();
virtual bool elementWise(const MatExpr& expr) const;
virtual void assign(const MatExpr& expr, Mat& m, int type=-1) const = 0;
virtual void roi(const MatExpr& expr, const Range& rowRange,
const Range& colRange, MatExpr& res) const;
virtual void diag(const MatExpr& expr, int d, MatExpr& res) const;
virtual void augAssignAdd(const MatExpr& expr, Mat& m) const;
virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const;
virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const;
virtual void augAssignDivide(const MatExpr& expr, Mat& m) const;
virtual void augAssignAnd(const MatExpr& expr, Mat& m) const;
virtual void augAssignOr(const MatExpr& expr, Mat& m) const;
virtual void augAssignXor(const MatExpr& expr, Mat& m) const;
virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const;
virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const;
virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const;
virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const;
virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const;
virtual void divide(double s, const MatExpr& expr, MatExpr& res) const;
virtual void abs(const MatExpr& expr, MatExpr& res) const;
virtual void transpose(const MatExpr& expr, MatExpr& res) const;
virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
virtual void invert(const MatExpr& expr, int method, MatExpr& res) const;
virtual Size size(const MatExpr& expr) const;
virtual int type(const MatExpr& expr) const;
};
class CV_EXPORTS MatExpr
{
public:
MatExpr();
explicit MatExpr(const Mat& m);
MatExpr(const MatOp* _op, int _flags, const Mat& _a = Mat(), const Mat& _b = Mat(),
const Mat& _c = Mat(), double _alpha = 1, double _beta = 1, const Scalar& _s = Scalar());
operator Mat() const;
template<typename _Tp> operator Mat_<_Tp>() const;
Size size() const;
int type() const;
MatExpr row(int y) const;
MatExpr col(int x) const;
MatExpr diag(int d = 0) const;
MatExpr operator()( const Range& rowRange, const Range& colRange ) const;
MatExpr operator()( const Rect& roi ) const;
MatExpr t() const;
MatExpr inv(int method = DECOMP_LU) const;
MatExpr mul(const MatExpr& e, double scale=1) const;
MatExpr mul(const Mat& m, double scale=1) const;
Mat cross(const Mat& m) const;
double dot(const Mat& m) const;
const MatOp* op;
int flags;
Mat a, b, c;
double alpha, beta;
Scalar s;
};
CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s);
CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a);
CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m);
CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e);
CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s);
CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e);
CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2);
CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s);
CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a);
CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m);
CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e);
CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s);
CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e);
CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2);
CV_EXPORTS MatExpr operator - (const Mat& m);
CV_EXPORTS MatExpr operator - (const MatExpr& e);
CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator * (const Mat& a, double s);
CV_EXPORTS MatExpr operator * (double s, const Mat& a);
CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m);
CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e);
CV_EXPORTS MatExpr operator * (const MatExpr& e, double s);
CV_EXPORTS MatExpr operator * (double s, const MatExpr& e);
CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2);
CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator / (const Mat& a, double s);
CV_EXPORTS MatExpr operator / (double s, const Mat& a);
CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m);
CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e);
CV_EXPORTS MatExpr operator / (const MatExpr& e, double s);
CV_EXPORTS MatExpr operator / (double s, const MatExpr& e);
CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2);
CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator < (const Mat& a, double s);
CV_EXPORTS MatExpr operator < (double s, const Mat& a);
CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator <= (const Mat& a, double s);
CV_EXPORTS MatExpr operator <= (double s, const Mat& a);
CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator == (const Mat& a, double s);
CV_EXPORTS MatExpr operator == (double s, const Mat& a);
CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator != (const Mat& a, double s);
CV_EXPORTS MatExpr operator != (double s, const Mat& a);
CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator >= (const Mat& a, double s);
CV_EXPORTS MatExpr operator >= (double s, const Mat& a);
CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator > (const Mat& a, double s);
CV_EXPORTS MatExpr operator > (double s, const Mat& a);
CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s);
CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a);
CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s);
CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a);
CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b);
CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s);
CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a);
CV_EXPORTS MatExpr operator ~(const Mat& m);
CV_EXPORTS MatExpr min(const Mat& a, const Mat& b);
CV_EXPORTS MatExpr min(const Mat& a, double s);
CV_EXPORTS MatExpr min(double s, const Mat& a);
CV_EXPORTS MatExpr max(const Mat& a, const Mat& b);
CV_EXPORTS MatExpr max(const Mat& a, double s);
CV_EXPORTS MatExpr max(double s, const Mat& a);
CV_EXPORTS MatExpr abs(const Mat& m);
CV_EXPORTS MatExpr abs(const MatExpr& e);
} // cv } // cv
#include "opencv2/core/mat.inl.hpp"
#endif // __OPENCV_CORE_MAT_HPP__ #endif // __OPENCV_CORE_MAT_HPP__
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -234,6 +234,110 @@ Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) c ...@@ -234,6 +234,110 @@ Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) c
} }
////////////////////////////// Augmenting algebraic & logical operations //////////////////////////////////
#define CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
static inline A& operator op (A& a, const B& b) { cvop; return a; }
#define CV_MAT_AUG_OPERATOR(op, cvop, A, B) \
CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
#define CV_MAT_AUG_OPERATOR_T(op, cvop, A, B) \
template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
CV_MAT_AUG_OPERATOR (+=, cv::add(a,b,a), Mat, Mat)
CV_MAT_AUG_OPERATOR (+=, cv::add(a,b,a), Mat, Scalar)
CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar)
CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
CV_MAT_AUG_OPERATOR (-=, cv::subtract(a,b,a), Mat, Mat)
CV_MAT_AUG_OPERATOR (-=, cv::subtract(a,b,a), Mat, Scalar)
CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Scalar)
CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
CV_MAT_AUG_OPERATOR (*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat, Mat)
CV_MAT_AUG_OPERATOR_T(*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat_<_Tp>, Mat_<_Tp>)
CV_MAT_AUG_OPERATOR (*=, a.convertTo(a, -1, b), Mat, double)
CV_MAT_AUG_OPERATOR_T(*=, a.convertTo(a, -1, b), Mat_<_Tp>, double)
CV_MAT_AUG_OPERATOR (/=, cv::divide(a,b,a), Mat, Mat)
CV_MAT_AUG_OPERATOR_T(/=, cv::divide(a,b,a), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(/=, cv::divide(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
CV_MAT_AUG_OPERATOR (/=, a.convertTo((Mat&)a, -1, 1./b), Mat, double)
CV_MAT_AUG_OPERATOR_T(/=, a.convertTo((Mat&)a, -1, 1./b), Mat_<_Tp>, double)
CV_MAT_AUG_OPERATOR (&=, cv::bitwise_and(a,b,a), Mat, Mat)
CV_MAT_AUG_OPERATOR (&=, cv::bitwise_and(a,b,a), Mat, Scalar)
CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Scalar)
CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
CV_MAT_AUG_OPERATOR (|=, cv::bitwise_or(a,b,a), Mat, Mat)
CV_MAT_AUG_OPERATOR (|=, cv::bitwise_or(a,b,a), Mat, Scalar)
CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Scalar)
CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
CV_MAT_AUG_OPERATOR (^=, cv::bitwise_xor(a,b,a), Mat, Mat)
CV_MAT_AUG_OPERATOR (^=, cv::bitwise_xor(a,b,a), Mat, Scalar)
CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Mat)
CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Scalar)
CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
#undef CV_MAT_AUG_OPERATOR_T
#undef CV_MAT_AUG_OPERATOR
#undef CV_MAT_AUG_OPERATOR1
///////////////////////////////////////////// SVD //////////////////////////////////////////////////////
inline SVD::SVD() {}
inline SVD::SVD( InputArray m, int flags ) { operator ()(m, flags); }
inline void SVD::solveZ( InputArray m, OutputArray _dst )
{
Mat mtx = m.getMat();
SVD svd(mtx, (mtx.rows >= mtx.cols ? 0 : SVD::FULL_UV));
_dst.create(svd.vt.cols, 1, svd.vt.type());
Mat dst = _dst.getMat();
svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst);
}
template<typename _Tp, int m, int n, int nm> inline void
SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt )
{
CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector.");
Mat _a(a, false), _u(u, false), _w(w, false), _vt(vt, false);
SVD::compute(_a, _w, _u, _vt);
CV_Assert(_w.data == (uchar*)&w.val[0] && _u.data == (uchar*)&u.val[0] && _vt.data == (uchar*)&vt.val[0]);
}
template<typename _Tp, int m, int n, int nm> inline void
SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w )
{
CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector.");
Mat _a(a, false), _w(w, false);
SVD::compute(_a, _w);
CV_Assert(_w.data == (uchar*)&w.val[0]);
}
template<typename _Tp, int m, int n, int nm, int nb> inline void
SVD::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 )
{
CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector.");
Mat _u(u, false), _w(w, false), _vt(vt, false), _rhs(rhs, false), _dst(dst, false);
SVD::backSubst(_w, _u, _vt, _rhs, _dst);
CV_Assert(_dst.data == (uchar*)&dst.val[0]);
}
//////////////////////////////// Vector //////////////////////////////// //////////////////////////////// Vector ////////////////////////////////
// template vector class. It is similar to STL's vector, // template vector class. It is similar to STL's vector,
...@@ -500,6 +604,13 @@ inline Point LineIterator::pos() const ...@@ -500,6 +604,13 @@ inline Point LineIterator::pos() const
return p; return p;
} }
//! returns the next unifomly-distributed random number of the specified type
template<typename _Tp> static inline _Tp randu()
{
return (_Tp)theRNG();
}
//////////////////////////////////////// XML & YAML I/O //////////////////////////////////// //////////////////////////////////////// XML & YAML I/O ////////////////////////////////////
CV_EXPORTS_W void write( FileStorage& fs, const String& name, int value ); CV_EXPORTS_W void write( FileStorage& fs, const String& name, int value );
......
...@@ -220,6 +220,10 @@ static inline bool isInitializer(const MatExpr& e) { return e.op == &g_MatOp_Ini ...@@ -220,6 +220,10 @@ static inline bool isInitializer(const MatExpr& e) { return e.op == &g_MatOp_Ini
///////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////
MatOp::MatOp() {}
MatOp::~MatOp() {}
bool MatOp::elementWise(const MatExpr& /*expr*/) const bool MatOp::elementWise(const MatExpr& /*expr*/) const
{ {
return false; return false;
......
...@@ -262,9 +262,10 @@ void Mat::deallocate() ...@@ -262,9 +262,10 @@ void Mat::deallocate()
} }
Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) : size(&rows) Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange)
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), refcount(0), datastart(0), dataend(0),
datalimit(0), allocator(0), size(&rows)
{ {
initEmpty();
CV_Assert( m.dims >= 2 ); CV_Assert( m.dims >= 2 );
if( m.dims > 2 ) if( m.dims > 2 )
{ {
...@@ -335,9 +336,10 @@ Mat::Mat(const Mat& m, const Rect& roi) ...@@ -335,9 +336,10 @@ Mat::Mat(const Mat& m, const Rect& roi)
} }
Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps) : size(&rows) Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps)
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), refcount(0), datastart(0), dataend(0),
datalimit(0), allocator(0), size(&rows)
{ {
initEmpty();
flags |= CV_MAT_TYPE(_type); flags |= CV_MAT_TYPE(_type);
data = datastart = (uchar*)_data; data = datastart = (uchar*)_data;
setSize(*this, _dims, _sizes, _steps, true); setSize(*this, _dims, _sizes, _steps, true);
...@@ -345,9 +347,10 @@ Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _st ...@@ -345,9 +347,10 @@ Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _st
} }
Mat::Mat(const Mat& m, const Range* ranges) : size(&rows) Mat::Mat(const Mat& m, const Range* ranges)
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), refcount(0), datastart(0), dataend(0),
datalimit(0), allocator(0), size(&rows)
{ {
initEmpty();
int i, d = m.dims; int i, d = m.dims;
CV_Assert(ranges); CV_Assert(ranges);
...@@ -833,6 +836,18 @@ Mat Mat::reshape(int new_cn, int new_rows) const ...@@ -833,6 +836,18 @@ Mat Mat::reshape(int new_cn, int new_rows) const
return hdr; return hdr;
} }
Mat Mat::diag(const Mat& d)
{
CV_Assert( d.cols == 1 || d.rows == 1 );
int len = d.rows + d.cols - 1;
Mat m(len, len, d.type(), Scalar(0));
Mat md = m.diag();
if( d.cols == 1 )
d.copyTo(md);
else
transpose(d, md);
return m;
}
int Mat::checkVector(int _elemChannels, int _depth, bool _requireContinuous) const int Mat::checkVector(int _elemChannels, int _depth, bool _requireContinuous) const
{ {
...@@ -3407,16 +3422,6 @@ void MatConstIterator::seek(const int* _idx, bool relative) ...@@ -3407,16 +3422,6 @@ void MatConstIterator::seek(const int* _idx, bool relative)
seek(ofs, relative); seek(ofs, relative);
} }
ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a)
{
if( a.m != b.m )
return INT_MAX;
if( a.sliceEnd == b.sliceEnd )
return (b.ptr - a.ptr)/b.elemSize;
return b.lpos() - a.lpos();
}
//////////////////////////////// SparseMat //////////////////////////////// //////////////////////////////// SparseMat ////////////////////////////////
template<typename T1, typename T2> void template<typename T1, typename T2> void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment