a big patch; use special proxy types (Input/OutputArray, Input/OutputArrayOfArrays) for passing in vectors, matrices etc.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -121,7 +121,7 @@ enum { DFT_INVERSE=1, DFT_SCALE=2, DFT_ROWS=4, DFT_COMPLEX_OUTPUT=16, DFT_REAL_O
|
||||
class CV_EXPORTS Exception : public std::exception
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
/*!
|
||||
Default constructor
|
||||
*/
|
||||
Exception() { code = 0; line = 0; }
|
||||
@@ -129,16 +129,16 @@ public:
|
||||
Full constructor. Normally the constuctor is not called explicitly.
|
||||
Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
|
||||
*/
|
||||
Exception(int _code, const string& _err, const string& _func, const string& _file, int _line)
|
||||
: code(_code), err(_err), func(_func), file(_file), line(_line)
|
||||
Exception(int _code, const string& _err, const string& _func, const string& _file, int _line)
|
||||
: code(_code), err(_err), func(_func), file(_file), line(_line)
|
||||
{ formatMessage(); }
|
||||
|
||||
virtual ~Exception() throw() {}
|
||||
virtual ~Exception() throw() {}
|
||||
|
||||
/*!
|
||||
\return the error description and the context as a text string.
|
||||
*/
|
||||
virtual const char *what() const throw() { return msg.c_str(); }
|
||||
virtual const char *what() const throw() { return msg.c_str(); }
|
||||
|
||||
void formatMessage()
|
||||
{
|
||||
@@ -148,13 +148,13 @@ public:
|
||||
msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str());
|
||||
}
|
||||
|
||||
string msg; ///< the formatted error message
|
||||
string msg; ///< the formatted error message
|
||||
|
||||
int code; ///< error code @see CVStatus
|
||||
string err; ///< error description
|
||||
string func; ///< function name. Available only when the compiler supports __func__ macro
|
||||
string file; ///< source file name where the error has occured
|
||||
int line; ///< line number in the source file where the error has occured
|
||||
int code; ///< error code @see CVStatus
|
||||
string err; ///< error description
|
||||
string func; ///< function name. Available only when the compiler supports __func__ macro
|
||||
string file; ///< source file name where the error has occured
|
||||
int line; ///< line number in the source file where the error has occured
|
||||
};
|
||||
|
||||
|
||||
@@ -641,6 +641,8 @@ typedef Vec<ushort, 4> Vec4w;
|
||||
typedef Vec<int, 2> Vec2i;
|
||||
typedef Vec<int, 3> Vec3i;
|
||||
typedef Vec<int, 4> Vec4i;
|
||||
typedef Vec<int, 6> Vec6i;
|
||||
typedef Vec<int, 8> Vec8i;
|
||||
|
||||
typedef Vec<float, 2> Vec2f;
|
||||
typedef Vec<float, 3> Vec3f;
|
||||
@@ -748,7 +750,7 @@ public:
|
||||
Point3_();
|
||||
Point3_(_Tp _x, _Tp _y, _Tp _z);
|
||||
Point3_(const Point3_& pt);
|
||||
explicit Point3_(const Point_<_Tp>& pt);
|
||||
explicit Point3_(const Point_<_Tp>& pt);
|
||||
Point3_(const CvPoint3D32f& pt);
|
||||
Point3_(const Vec<_Tp, 3>& v);
|
||||
|
||||
@@ -1252,10 +1254,90 @@ public:
|
||||
|
||||
protected:
|
||||
_Tp* obj; //< the object pointer.
|
||||
int* refcount; //< the associated bbbbbbbbbbbbbbbbbb reference counter
|
||||
int* refcount; //< the associated reference counter
|
||||
};
|
||||
|
||||
//////////////////////////////// Mat ////////////////////////////////
|
||||
|
||||
//////////////////////// Input/Output Array Arguments /////////////////////////////////
|
||||
|
||||
/*!
|
||||
Proxy datatype for passing Mat's and vector<>'s as input parameters
|
||||
*/
|
||||
class CV_EXPORTS InputArray
|
||||
{
|
||||
public:
|
||||
enum { KIND_SHIFT=16, NONE=0<<KIND_SHIFT, MAT=1<<KIND_SHIFT,
|
||||
MATX=2<<KIND_SHIFT, STD_VECTOR=3<<KIND_SHIFT,
|
||||
STD_VECTOR_VECTOR=4<<KIND_SHIFT,
|
||||
STD_VECTOR_MAT=5<<KIND_SHIFT, EXPR=6<<KIND_SHIFT };
|
||||
InputArray();
|
||||
InputArray(const Mat& m);
|
||||
InputArray(const MatExpr& expr);
|
||||
template<typename _Tp> InputArray(const vector<_Tp>& vec);
|
||||
template<typename _Tp> InputArray(const vector<vector<_Tp> >& vec);
|
||||
InputArray(const vector<Mat>& vec);
|
||||
template<typename _Tp, int m, int n> InputArray(const Matx<_Tp, m, n>& matx);
|
||||
InputArray(const double& val);
|
||||
Mat getMat(int i=-1) const;
|
||||
void getMatVector(vector<Mat>& mv) const;
|
||||
int kind() const;
|
||||
Size size(int i=-1) const;
|
||||
size_t total(int i=-1) const;
|
||||
int type(int i=-1) const;
|
||||
int depth(int i=-1) const;
|
||||
int channels(int i=-1) const;
|
||||
bool empty() const;
|
||||
|
||||
int flags;
|
||||
void* obj;
|
||||
Size sz;
|
||||
};
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
DEPTH_MASK_8U = 1 << CV_8U,
|
||||
DEPTH_MASK_8S = 1 << CV_8S,
|
||||
DEPTH_MASK_16U = 1 << CV_16U,
|
||||
DEPTH_MASK_16S = 1 << CV_16S,
|
||||
DEPTH_MASK_32S = 1 << CV_32S,
|
||||
DEPTH_MASK_32F = 1 << CV_32F,
|
||||
DEPTH_MASK_64F = 1 << CV_64F,
|
||||
DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1,
|
||||
DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
|
||||
DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
Proxy datatype for passing Mat's and vector<>'s as input parameters
|
||||
*/
|
||||
class CV_EXPORTS OutputArray : public InputArray
|
||||
{
|
||||
public:
|
||||
OutputArray();
|
||||
OutputArray(Mat& m);
|
||||
template<typename _Tp> OutputArray(vector<_Tp>& vec);
|
||||
template<typename _Tp> OutputArray(vector<vector<_Tp> >& vec);
|
||||
OutputArray(vector<Mat>& vec);
|
||||
template<typename _Tp, int m, int n> OutputArray(Matx<_Tp, m, n>& matx);
|
||||
bool fixedSize() const;
|
||||
bool fixedType() const;
|
||||
bool needed() const;
|
||||
Mat& getMatRef(int i=-1);
|
||||
void create(Size sz, int type, int i=-1, bool allocateVector=false, int fixedDepthMask=0);
|
||||
void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0);
|
||||
void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0);
|
||||
void release();
|
||||
void clear();
|
||||
};
|
||||
|
||||
typedef InputArray InputArrayOfArrays;
|
||||
typedef OutputArray OutputArrayOfArrays;
|
||||
|
||||
typedef OutputArray InputOutputArray;
|
||||
|
||||
/////////////////////////////////////// Mat ///////////////////////////////////////////
|
||||
|
||||
enum { MAGIC_MASK=0xFFFF0000, TYPE_MASK=0x00000FFF, DEPTH_MASK=7 };
|
||||
|
||||
@@ -1563,19 +1645,18 @@ public:
|
||||
Mat clone() const;
|
||||
//! copies the matrix content to "m".
|
||||
// It calls m.create(this->size(), this->type()).
|
||||
void copyTo( Mat& m ) const;
|
||||
template<typename _Tp> void copyTo( vector<_Tp>& v ) const;
|
||||
void copyTo( OutputArray m ) const;
|
||||
//! copies those matrix elements to "m" that are marked with non-zero mask elements.
|
||||
void copyTo( Mat& m, const Mat& mask ) const;
|
||||
void copyTo( OutputArray m, const InputArray& mask ) const;
|
||||
//! converts matrix to another datatype with optional scalng. See cvConvertScale.
|
||||
void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
|
||||
void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;
|
||||
|
||||
void assignTo( Mat& m, int type=-1 ) const;
|
||||
|
||||
//! sets every matrix element to s
|
||||
Mat& operator = (const Scalar& s);
|
||||
//! sets some of the matrix elements to s, according to the mask
|
||||
Mat& setTo(const Scalar& s, const Mat& mask=Mat());
|
||||
Mat& setTo(const Scalar& s, const InputArray& mask=InputArray());
|
||||
//! creates alternative matrix header for the same data, with different
|
||||
// number of channels and/or different number of rows. see cvReshape.
|
||||
Mat reshape(int _cn, int _rows=0) const;
|
||||
@@ -1586,13 +1667,13 @@ public:
|
||||
//! matrix inversion by means of matrix expressions
|
||||
MatExpr inv(int method=DECOMP_LU) const;
|
||||
//! per-element matrix multiplication by means of matrix expressions
|
||||
MatExpr mul(const Mat& m, double scale=1) const;
|
||||
MatExpr mul(const InputArray& m, double scale=1) const;
|
||||
MatExpr mul(const MatExpr& m, double scale=1) const;
|
||||
|
||||
//! computes cross-product of 2 3D vectors
|
||||
Mat cross(const Mat& m) const;
|
||||
Mat cross(const InputArray& m) const;
|
||||
//! computes dot-product
|
||||
double dot(const Mat& m) const;
|
||||
double dot(const InputArray& m) const;
|
||||
|
||||
//! Matlab-style matrix initialization
|
||||
static MatExpr zeros(int rows, int cols, int type);
|
||||
@@ -1809,7 +1890,7 @@ public:
|
||||
MStep step;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
Random Number Generator
|
||||
|
||||
@@ -1830,9 +1911,9 @@ public:
|
||||
operator ushort();
|
||||
operator short();
|
||||
operator unsigned();
|
||||
//! returns a random integer sampled uniformly from [0, N).
|
||||
unsigned operator()(unsigned N);
|
||||
unsigned operator ()();
|
||||
//! returns a random integer sampled uniformly from [0, N).
|
||||
unsigned operator()(unsigned N);
|
||||
unsigned operator ()();
|
||||
operator int();
|
||||
operator float();
|
||||
operator double();
|
||||
@@ -1842,14 +1923,12 @@ public:
|
||||
float uniform(float a, float b);
|
||||
//! returns uniformly distributed double-precision floating-point random number from [a,b) range
|
||||
double uniform(double a, double b);
|
||||
void fill( Mat& mat, int distType, const Scalar& a, const Scalar& b );
|
||||
//! returns Gaussian random variate with mean zero.
|
||||
double gaussian(double sigma);
|
||||
void fill( InputOutputArray mat, int distType, const InputArray& a, const InputArray& b );
|
||||
//! returns Gaussian random variate with mean zero.
|
||||
double gaussian(double sigma);
|
||||
|
||||
uint64 state;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
@@ -1879,6 +1958,7 @@ public:
|
||||
double epsilon; // the desired accuracy
|
||||
};
|
||||
|
||||
|
||||
//! swaps two matrices
|
||||
CV_EXPORTS void swap(Mat& a, Mat& b);
|
||||
|
||||
@@ -1886,79 +1966,75 @@ CV_EXPORTS void swap(Mat& a, Mat& b);
|
||||
CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
|
||||
bool allowND=true, int coiMode=0);
|
||||
//! extracts Channel of Interest from CvMat or IplImage and makes cv::Mat out of it.
|
||||
CV_EXPORTS void extractImageCOI(const CvArr* arr, CV_OUT Mat& coiimg, int coi=-1);
|
||||
CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1);
|
||||
//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage
|
||||
CV_EXPORTS void insertImageCOI(const Mat& coiimg, CvArr* arr, int coi=-1);
|
||||
|
||||
CV_EXPORTS void insertImageCOI(const InputArray& coiimg, CvArr* arr, int coi=-1);
|
||||
|
||||
//! adds one matrix to another (dst = src1 + src2)
|
||||
CV_EXPORTS_W void add(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask CV_WRAP_DEFAULT(Mat()));
|
||||
CV_EXPORTS_W void add(const InputArray& src1, const InputArray& src2, OutputArray dst,
|
||||
const InputArray& mask=InputArray(), int dtype=-1);
|
||||
//! subtracts one matrix from another (dst = src1 - src2)
|
||||
CV_EXPORTS_W void subtract(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask CV_WRAP_DEFAULT(Mat()));
|
||||
//! adds one matrix to another (dst = src1 + src2)
|
||||
CV_EXPORTS void add(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
|
||||
//! subtracts one matrix from another (dst = src1 - src2)
|
||||
CV_EXPORTS void subtract(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
|
||||
//! adds scalar to a matrix (dst = src1 + src2)
|
||||
CV_EXPORTS_W void add(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
//! subtracts scalar from a matrix (dst = src1 - src2)
|
||||
CV_EXPORTS_W void subtract(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
//! subtracts matrix from scalar (dst = src1 - src2)
|
||||
CV_EXPORTS_W void subtract(const Scalar& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
CV_EXPORTS_W void subtract(const InputArray& src1, const InputArray& src2, OutputArray dst,
|
||||
const InputArray& mask=InputArray(), int dtype=-1);
|
||||
|
||||
//! computes element-wise weighted product of the two arrays (dst = scale*src1*src2)
|
||||
CV_EXPORTS_W void multiply(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, double scale=1);
|
||||
CV_EXPORTS_W void multiply(const InputArray& src1, const InputArray& src2,
|
||||
OutputArray dst, double scale=1, int dtype=-1);
|
||||
|
||||
//! computes element-wise weighted quotient of the two arrays (dst = scale*src1/src2)
|
||||
CV_EXPORTS_W void divide(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, double scale=1);
|
||||
CV_EXPORTS_W void divide(const InputArray& src1, const InputArray& src2, OutputArray dst,
|
||||
double scale=1, int dtype=-1);
|
||||
|
||||
//! computes element-wise weighted reciprocal of an array (dst = scale/src2)
|
||||
CV_EXPORTS_W void divide(double scale, const Mat& src2, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void divide(double scale, const InputArray& src2,
|
||||
OutputArray dst, int dtype=-1);
|
||||
|
||||
//! adds scaled array to another one (dst = alpha*src1 + src2)
|
||||
CV_EXPORTS_W void scaleAdd(const Mat& src1, double alpha, const Mat& src2, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void scaleAdd(const InputArray& src1, double alpha, const InputArray& src2, OutputArray dst);
|
||||
|
||||
//! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
|
||||
CV_EXPORTS_W void addWeighted(const Mat& src1, double alpha, const Mat& src2,
|
||||
double beta, double gamma, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void addWeighted(const InputArray& src1, double alpha, const InputArray& src2,
|
||||
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)
|
||||
CV_EXPORTS_W void convertScaleAbs(const Mat& src, CV_OUT Mat& dst, double alpha=1, double beta=0);
|
||||
//! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i))
|
||||
CV_EXPORTS_W void LUT(const Mat& src, const Mat& lut, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void convertScaleAbs(const InputArray& src, OutputArray dst,
|
||||
double alpha=1, double beta=0);
|
||||
//! transforms array of numbers using a lookup table: dst(i)=lut(src(i))
|
||||
CV_EXPORTS_W void LUT(const InputArray& src, const InputArray& lut, OutputArray dst,
|
||||
int interpolation=0);
|
||||
|
||||
//! computes sum of array elements
|
||||
CV_EXPORTS_W Scalar sum(const Mat& src);
|
||||
CV_EXPORTS_W Scalar sum(const InputArray& src);
|
||||
//! computes the number of nonzero array elements
|
||||
CV_EXPORTS_W int countNonZero( const Mat& src );
|
||||
|
||||
//! computes mean value of array elements
|
||||
CV_EXPORTS Scalar mean(const Mat& src);
|
||||
CV_EXPORTS_W int countNonZero( const InputArray& src );
|
||||
//! computes mean value of selected array elements
|
||||
CV_EXPORTS_W Scalar mean(const Mat& src, const Mat& mask CV_WRAP_DEFAULT(Mat()));
|
||||
CV_EXPORTS_W Scalar mean(const InputArray& src, const InputArray& mask=InputArray());
|
||||
//! computes mean value and standard deviation of all or selected array elements
|
||||
CV_EXPORTS_W void meanStdDev(const Mat& src, CV_OUT Scalar& mean, CV_OUT Scalar& stddev, const Mat& mask=Mat());
|
||||
//! computes norm of array
|
||||
CV_EXPORTS double norm(const Mat& src1, int normType=NORM_L2);
|
||||
//! computes norm of the difference between two arrays
|
||||
CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType=NORM_L2);
|
||||
CV_EXPORTS_W void meanStdDev(const InputArray& src, OutputArray mean, OutputArray stddev,
|
||||
const InputArray& mask=InputArray());
|
||||
//! computes norm of the selected array part
|
||||
CV_EXPORTS_W double norm(const Mat& src1, int normType, const Mat& mask CV_WRAP_DEFAULT(Mat()));
|
||||
CV_EXPORTS_W double norm(const InputArray& src1, int normType=NORM_L2, const InputArray& mask=InputArray());
|
||||
//! computes norm of selected part of the difference between two arrays
|
||||
CV_EXPORTS_W double norm(const Mat& src1, const Mat& src2,
|
||||
int normType, const Mat& mask CV_WRAP_DEFAULT(Mat()));
|
||||
CV_EXPORTS_W double norm(const InputArray& src1, const InputArray& src2,
|
||||
int normType=NORM_L2, const InputArray& mask=InputArray());
|
||||
//! 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( const Mat& src, CV_OUT Mat& dst, double alpha=1, double beta=0,
|
||||
int norm_type=NORM_L2, int rtype=-1, const Mat& mask=Mat());
|
||||
CV_EXPORTS_W void normalize( const InputArray& src, OutputArray dst, double alpha=1, double beta=0,
|
||||
int norm_type=NORM_L2, int dtype=-1, const InputArray& mask=InputArray());
|
||||
|
||||
//! finds global minimum and maximum array elements and returns their values and their locations
|
||||
CV_EXPORTS_W void minMaxLoc(const Mat& src, CV_OUT double* minVal,
|
||||
CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
|
||||
CV_OUT Point* maxLoc=0, const Mat& mask=Mat());
|
||||
CV_EXPORTS void minMaxIdx(const Mat& src, double* minVal, double* maxVal,
|
||||
int* minIdx=0, int* maxIdx=0, const Mat& mask=Mat());
|
||||
CV_EXPORTS_W void minMaxLoc(const InputArray& src, CV_OUT double* minVal,
|
||||
CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0,
|
||||
CV_OUT Point* maxLoc=0, const InputArray& mask=InputArray());
|
||||
CV_EXPORTS void minMaxIdx(const InputArray& src, double* minVal, double* maxVal,
|
||||
int* minIdx=0, int* maxIdx=0, const InputArray& mask=InputArray());
|
||||
|
||||
//! 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(const Mat& src, CV_OUT Mat& dst, int dim, int rtype, int dtype=-1);
|
||||
CV_EXPORTS_W void reduce(const InputArray& src, OutputArray dst, int dim, int rtype, int dtype=-1);
|
||||
|
||||
//! makes multi-channel array out of several single-channel arrays
|
||||
CV_EXPORTS void merge(const Mat* mv, size_t count, CV_OUT Mat& dst);
|
||||
CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
|
||||
//! makes multi-channel array out of several single-channel arrays
|
||||
CV_EXPORTS_W void merge(const vector<Mat>& mv, Mat& dst);
|
||||
CV_EXPORTS_W void merge(const vector<Mat>& mv, OutputArray dst);
|
||||
|
||||
//! copies each plane of a multi-channel array to a dedicated array
|
||||
CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
|
||||
@@ -1969,133 +2045,131 @@ CV_EXPORTS_W void split(const Mat& m, vector<Mat>& mv);
|
||||
CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
|
||||
const int* fromTo, size_t npairs);
|
||||
CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
|
||||
const int* fromTo, int npairs);
|
||||
const int* fromTo, size_t npairs);
|
||||
|
||||
//! reverses the order of the rows, columns or both in a matrix
|
||||
CV_EXPORTS_W void flip(const Mat& src, CV_OUT Mat& dst, int flipCode);
|
||||
CV_EXPORTS_W void flip(const InputArray& src, OutputArray dst, int flipCode);
|
||||
|
||||
//! replicates the input matrix the specified number of times in the horizontal and/or vertical direction
|
||||
CV_EXPORTS_W void repeat(const Mat& src, int ny, int nx, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void repeat(const InputArray& src, int ny, int nx, OutputArray dst);
|
||||
CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
|
||||
|
||||
CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, Mat& dst);
|
||||
CV_EXPORTS void hconcat(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
CV_EXPORTS_W void hconcat(const vector<Mat>& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
|
||||
CV_EXPORTS void hconcat(const InputArray& src1, const InputArray& src2, OutputArray dst);
|
||||
CV_EXPORTS_W void hconcat(const InputArray& src, OutputArray dst);
|
||||
|
||||
CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, Mat& dst);
|
||||
CV_EXPORTS void vconcat(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
CV_EXPORTS_W void vconcat(const vector<Mat>& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
|
||||
CV_EXPORTS void vconcat(const InputArray& src1, const InputArray& src2, OutputArray dst);
|
||||
CV_EXPORTS_W void vconcat(const InputArray& src, OutputArray dst);
|
||||
|
||||
//! computes bitwise conjunction of the two arrays (dst = src1 & src2)
|
||||
CV_EXPORTS_W void bitwise_and(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
CV_EXPORTS_W void bitwise_and(const InputArray& src1, const InputArray& src2,
|
||||
OutputArray dst, const InputArray& mask=InputArray());
|
||||
//! computes bitwise disjunction of the two arrays (dst = src1 | src2)
|
||||
CV_EXPORTS_W void bitwise_or(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
CV_EXPORTS_W void bitwise_or(const InputArray& src1, const InputArray& src2,
|
||||
OutputArray dst, const InputArray& mask=InputArray());
|
||||
//! computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2)
|
||||
CV_EXPORTS_W void bitwise_xor(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
//! computes bitwise conjunction of an array and scalar (dst = src1 & src2)
|
||||
CV_EXPORTS_W void bitwise_and(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
//! computes bitwise disjunction of an array and scalar (dst = src1 | src2)
|
||||
CV_EXPORTS_W void bitwise_or(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
//! computes bitwise exclusive-or of an array and scalar (dst = src1 ^ src2)
|
||||
CV_EXPORTS_W void bitwise_xor(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());
|
||||
CV_EXPORTS_W void bitwise_xor(const InputArray& src1, const InputArray& src2,
|
||||
OutputArray dst, const InputArray& mask=InputArray());
|
||||
//! inverts each bit of array (dst = ~src)
|
||||
CV_EXPORTS_W void bitwise_not(const Mat& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void bitwise_not(const InputArray& src, OutputArray dst,
|
||||
const InputArray& mask=InputArray());
|
||||
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
|
||||
CV_EXPORTS_W void absdiff(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
|
||||
//! computes element-wise absolute difference of array and scalar (dst = abs(src1 - src2))
|
||||
CV_EXPORTS_W void absdiff(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void absdiff(const InputArray& src1, const InputArray& src2, OutputArray dst);
|
||||
//! 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(const Mat& src, const Mat& lowerb,
|
||||
const Mat& upperb, CV_OUT Mat& dst);
|
||||
//! set mask elements for those array elements which are within the fixed bounding box (dst = lowerb <= src && src < upperb)
|
||||
CV_EXPORTS_W void inRange(const Mat& src, const Scalar& lowerb,
|
||||
const Scalar& upperb, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void inRange(const InputArray& src, const InputArray& lowerb,
|
||||
const InputArray& upperb, OutputArray dst);
|
||||
//! compares elements of two arrays (dst = src1 <cmpop> src2)
|
||||
CV_EXPORTS_W void compare(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, int cmpop);
|
||||
//! compares elements of array with scalar (dst = src1 <cmpop> src2)
|
||||
CV_EXPORTS_W void compare(const Mat& src1, double s, CV_OUT Mat& dst, int cmpop);
|
||||
CV_EXPORTS_W void compare(const InputArray& src1, const InputArray& src2, OutputArray dst, int cmpop);
|
||||
//! computes per-element minimum of two arrays (dst = min(src1, src2))
|
||||
CV_EXPORTS_W void min(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
|
||||
//! computes per-element minimum of array and scalar (dst = min(src1, src2))
|
||||
CV_EXPORTS_W void min(const Mat& src1, double src2, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void min(const InputArray& src1, const InputArray& src2, OutputArray dst);
|
||||
//! computes per-element maximum of two arrays (dst = max(src1, src2))
|
||||
CV_EXPORTS_W void max(const Mat& src1, const Mat& src2, CV_OUT Mat& dst);
|
||||
//! computes per-element maximum of array and scalar (dst = max(src1, src2))
|
||||
CV_EXPORTS_W void max(const Mat& src1, double src2, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void max(const InputArray& src1, const InputArray& src2, OutputArray dst);
|
||||
|
||||
//! computes per-element minimum of two arrays (dst = min(src1, src2))
|
||||
CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
//! computes per-element minimum of array and scalar (dst = min(src1, src2))
|
||||
CV_EXPORTS void min(const Mat& src1, double src2, Mat& dst);
|
||||
//! computes per-element maximum of two arrays (dst = max(src1, src2))
|
||||
CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
//! computes per-element maximum of array and scalar (dst = max(src1, src2))
|
||||
CV_EXPORTS void max(const Mat& src1, double src2, Mat& dst);
|
||||
|
||||
//! computes square root of each matrix element (dst = src**0.5)
|
||||
CV_EXPORTS_W void sqrt(const Mat& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void sqrt(const InputArray& src, OutputArray dst);
|
||||
//! raises the input matrix elements to the specified power (b = a**power)
|
||||
CV_EXPORTS_W void pow(const Mat& src, double power, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void pow(const InputArray& src, double power, OutputArray dst);
|
||||
//! computes exponent of each matrix element (dst = e**src)
|
||||
CV_EXPORTS_W void exp(const Mat& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void exp(const InputArray& src, OutputArray dst);
|
||||
//! computes natural logarithm of absolute value of each matrix element: dst = log(abs(src))
|
||||
CV_EXPORTS_W void log(const Mat& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void log(const 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);
|
||||
//! converts polar coordinates to Cartesian
|
||||
CV_EXPORTS_W void polarToCart(const Mat& magnitude, const Mat& angle,
|
||||
CV_OUT Mat& x, CV_OUT Mat& y, bool angleInDegrees=false);
|
||||
CV_EXPORTS_W void polarToCart(const InputArray& magnitude, const InputArray& angle,
|
||||
OutputArray x, OutputArray y, bool angleInDegrees=false);
|
||||
//! converts Cartesian coordinates to polar
|
||||
CV_EXPORTS_W void cartToPolar(const Mat& x, const Mat& y,
|
||||
CV_OUT Mat& magnitude, CV_OUT Mat& angle,
|
||||
bool angleInDegrees=false);
|
||||
CV_EXPORTS_W void cartToPolar(const InputArray& x, const InputArray& y,
|
||||
OutputArray magnitude, OutputArray angle,
|
||||
bool angleInDegrees=false);
|
||||
//! computes angle (angle(i)) of each (x(i), y(i)) vector
|
||||
CV_EXPORTS_W void phase(const Mat& x, const Mat& y, CV_OUT Mat& angle,
|
||||
CV_EXPORTS_W void phase(const InputArray& x, const InputArray& y, OutputArray angle,
|
||||
bool angleInDegrees=false);
|
||||
//! computes magnitude (magnitude(i)) of each (x(i), y(i)) vector
|
||||
CV_EXPORTS_W void magnitude(const Mat& x, const Mat& y, CV_OUT Mat& magnitude);
|
||||
CV_EXPORTS_W void magnitude(const InputArray& x, const InputArray& y, OutputArray magnitude);
|
||||
//! checks that each matrix element is within the specified range.
|
||||
CV_EXPORTS_W bool checkRange(const Mat& a, bool quiet=true, CV_OUT Point* pt=0,
|
||||
CV_EXPORTS_W bool checkRange(const InputArray& a, bool quiet=true, CV_OUT Point* pt=0,
|
||||
double minVal=-DBL_MAX, double maxVal=DBL_MAX);
|
||||
//! implements generalized matrix product algorithm GEMM from BLAS
|
||||
CV_EXPORTS_W void gemm(const Mat& src1, const Mat& src2, double alpha,
|
||||
const Mat& src3, double gamma, CV_OUT Mat& dst, int flags=0);
|
||||
CV_EXPORTS_W void gemm(const InputArray& src1, const InputArray& src2, double alpha,
|
||||
const InputArray& src3, double gamma, OutputArray dst, int flags=0);
|
||||
//! multiplies matrix by its transposition from the left or from the right
|
||||
CV_EXPORTS_W void mulTransposed( const Mat& src, CV_OUT Mat& dst, bool aTa,
|
||||
const Mat& delta=Mat(),
|
||||
double scale=1, int rtype=-1 );
|
||||
CV_EXPORTS_W void mulTransposed( const InputArray& src, OutputArray dst, bool aTa,
|
||||
const InputArray& delta=InputArray(),
|
||||
double scale=1, int dtype=-1 );
|
||||
//! transposes the matrix
|
||||
CV_EXPORTS_W void transpose(const Mat& src, CV_OUT Mat& dst);
|
||||
CV_EXPORTS_W void transpose(const InputArray& src, OutputArray dst);
|
||||
//! performs affine transformation of each element of multi-channel input matrix
|
||||
CV_EXPORTS_W void transform(const Mat& src, CV_OUT Mat& dst, const Mat& m );
|
||||
CV_EXPORTS_W void transform(const InputArray& src, OutputArray dst, const InputArray& m );
|
||||
//! performs perspective transformation of each element of multi-channel input matrix
|
||||
CV_EXPORTS_W void perspectiveTransform(const Mat& src, CV_OUT Mat& dst, const Mat& m );
|
||||
CV_EXPORTS_W void perspectiveTransform(const InputArray& src, OutputArray dst, const InputArray& m );
|
||||
|
||||
//! extends the symmetrical matrix from the lower half or from the upper half
|
||||
CV_EXPORTS_W void completeSymm(Mat& mtx, bool lowerToUpper=false);
|
||||
CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper=false);
|
||||
//! initializes scaled identity matrix
|
||||
CV_EXPORTS_W void setIdentity(Mat& mtx, const Scalar& s=Scalar(1));
|
||||
CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s=Scalar(1));
|
||||
//! computes determinant of a square matrix
|
||||
CV_EXPORTS_W double determinant(const Mat& mtx);
|
||||
CV_EXPORTS_W double determinant(const InputArray& mtx);
|
||||
//! computes trace of a matrix
|
||||
CV_EXPORTS_W Scalar trace(const Mat& mtx);
|
||||
CV_EXPORTS_W Scalar trace(const InputArray& mtx);
|
||||
//! computes inverse or pseudo-inverse matrix
|
||||
CV_EXPORTS_W double invert(const Mat& src, CV_OUT Mat& dst, int flags=DECOMP_LU);
|
||||
CV_EXPORTS_W double invert(const InputArray& src, OutputArray dst, int flags=DECOMP_LU);
|
||||
//! solves linear system or a least-square problem
|
||||
CV_EXPORTS_W bool solve(const Mat& src1, const Mat& src2, CV_OUT Mat& dst, int flags=DECOMP_LU);
|
||||
CV_EXPORTS_W bool solve(const InputArray& src1, const InputArray& src2,
|
||||
OutputArray dst, int flags=DECOMP_LU);
|
||||
//! sorts independently each matrix row or each matrix column
|
||||
CV_EXPORTS_W void sort(const Mat& src, CV_OUT Mat& dst, int flags);
|
||||
CV_EXPORTS_W void sort(const InputArray& src, OutputArray dst, int flags);
|
||||
//! sorts independently each matrix row or each matrix column
|
||||
CV_EXPORTS_W void sortIdx(const Mat& src, CV_OUT Mat& dst, int flags);
|
||||
CV_EXPORTS_W void sortIdx(const InputArray& src, OutputArray dst, int flags);
|
||||
//! finds real roots of a cubic polynomial
|
||||
CV_EXPORTS_W int solveCubic(const Mat& coeffs, CV_OUT Mat& roots);
|
||||
CV_EXPORTS_W int solveCubic(const InputArray& coeffs, OutputArray roots);
|
||||
//! finds real and complex roots of a polynomial
|
||||
CV_EXPORTS_W double solvePoly(const Mat& coeffs, CV_OUT Mat& roots, int maxIters=300);
|
||||
CV_EXPORTS_W double solvePoly(const InputArray& coeffs, OutputArray roots, int maxIters=300);
|
||||
//! finds eigenvalues of a symmetric matrix
|
||||
CV_EXPORTS bool eigen(const Mat& src, CV_OUT Mat& eigenvalues, int lowindex=-1,
|
||||
CV_EXPORTS bool eigen(const InputArray& src, OutputArray eigenvalues, int lowindex=-1,
|
||||
int highindex=-1);
|
||||
//! finds eigenvalues and eigenvectors of a symmetric matrix
|
||||
CV_EXPORTS bool eigen(const Mat& src, CV_OUT Mat& eigenvalues, CV_OUT Mat& eigenvectors,
|
||||
CV_EXPORTS bool eigen(const InputArray& src, OutputArray eigenvalues,
|
||||
OutputArray eigenvectors,
|
||||
int lowindex=-1, int highindex=-1);
|
||||
//! computes covariation matrix of a set of samples
|
||||
CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
|
||||
int flags, int ctype=CV_64F);
|
||||
//! computes covariation matrix of a set of samples
|
||||
CV_EXPORTS_W void calcCovarMatrix( const Mat& samples, CV_OUT Mat& covar, CV_OUT Mat& mean,
|
||||
int flags, int ctype=CV_64F);
|
||||
CV_EXPORTS_W void calcCovarMatrix( const InputArray& samples, OutputArray covar,
|
||||
OutputArray mean, int flags, int ctype=CV_64F);
|
||||
|
||||
/*!
|
||||
Principal Component Analysis
|
||||
@@ -2157,17 +2231,17 @@ public:
|
||||
//! default constructor
|
||||
PCA();
|
||||
//! the constructor that performs PCA
|
||||
PCA(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
|
||||
PCA(const InputArray& data, const InputArray& mean, int flags, int maxComponents=0);
|
||||
//! operator that performs PCA. The previously stored data, if any, is released
|
||||
PCA& operator()(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
|
||||
PCA& operator()(const InputArray& data, const InputArray& mean, int flags, int maxComponents=0);
|
||||
//! projects vector from the original space to the principal components subspace
|
||||
Mat project(const Mat& vec) const;
|
||||
Mat project(const InputArray& vec) const;
|
||||
//! projects vector from the original space to the principal components subspace
|
||||
void project(const Mat& vec, CV_OUT Mat& result) const;
|
||||
void project(const InputArray& vec, OutputArray result) const;
|
||||
//! reconstructs the original vector from the projection
|
||||
Mat backProject(const Mat& vec) const;
|
||||
Mat backProject(const InputArray& vec) const;
|
||||
//! reconstructs the original vector from the projection
|
||||
void backProject(const Mat& vec, CV_OUT Mat& result) const;
|
||||
void backProject(const InputArray& vec, OutputArray result) const;
|
||||
|
||||
Mat eigenvectors; //!< eigenvectors of the covariation matrix
|
||||
Mat eigenvalues; //!< eigenvalues of the covariation matrix
|
||||
@@ -2194,17 +2268,19 @@ public:
|
||||
//! the default constructor
|
||||
SVD();
|
||||
//! the constructor that performs SVD
|
||||
SVD( const Mat& src, int flags=0 );
|
||||
SVD( const InputArray& src, int flags=0 );
|
||||
//! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
|
||||
SVD& operator ()( const Mat& src, int flags=0 );
|
||||
SVD& operator ()( const InputArray& src, int flags=0 );
|
||||
|
||||
//! decomposes matrix and stores the results to user-provided matrices
|
||||
static void compute( const Mat& src, CV_OUT Mat& w, CV_OUT Mat& u, CV_OUT Mat& vt, int flags=0 );
|
||||
static void compute( const InputArray& src, OutputArray w,
|
||||
OutputArray u, OutputArray vt, int flags=0 );
|
||||
//! computes singular values of a matrix
|
||||
static void compute( const Mat& src, CV_OUT Mat& w, int flags=0 );
|
||||
static void compute( const InputArray& src, OutputArray w, int flags=0 );
|
||||
//! performs back substitution
|
||||
static void backSubst( const Mat& w, const Mat& u, const Mat& vt,
|
||||
const Mat& rhs, CV_OUT Mat& dst );
|
||||
static void backSubst( const InputArray& w, const InputArray& u,
|
||||
const InputArray& vt, const 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 );
|
||||
@@ -2214,29 +2290,29 @@ public:
|
||||
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( const Mat& src, CV_OUT Mat& dst );
|
||||
static void solveZ( const 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( const Mat& rhs, CV_OUT Mat& dst ) const;
|
||||
void backSubst( const InputArray& rhs, OutputArray dst ) const;
|
||||
|
||||
Mat u, w, vt;
|
||||
};
|
||||
|
||||
//! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix
|
||||
CV_EXPORTS_W double Mahalanobis(const Mat& v1, const Mat& v2, const Mat& icovar);
|
||||
CV_EXPORTS_W double Mahalanobis(const InputArray& v1, const InputArray& v2, const InputArray& icovar);
|
||||
//! a synonym for Mahalanobis
|
||||
CV_EXPORTS double Mahalonobis(const Mat& v1, const Mat& v2, const Mat& icovar);
|
||||
CV_EXPORTS double Mahalonobis(const InputArray& v1, const InputArray& v2, const InputArray& icovar);
|
||||
|
||||
//! performs forward or inverse 1D or 2D Discrete Fourier Transformation
|
||||
CV_EXPORTS_W void dft(const Mat& src, CV_OUT Mat& dst, int flags=0, int nonzeroRows=0);
|
||||
CV_EXPORTS_W void dft(const InputArray& src, OutputArray dst, int flags=0, int nonzeroRows=0);
|
||||
//! performs inverse 1D or 2D Discrete Fourier Transformation
|
||||
CV_EXPORTS_W void idft(const Mat& src, CV_OUT Mat& dst, int flags=0, int nonzeroRows=0);
|
||||
CV_EXPORTS_W void idft(const InputArray& src, OutputArray dst, int flags=0, int nonzeroRows=0);
|
||||
//! performs forward or inverse 1D or 2D Discrete Cosine Transformation
|
||||
CV_EXPORTS_W void dct(const Mat& src, CV_OUT Mat& dst, int flags=0);
|
||||
CV_EXPORTS_W void dct(const InputArray& src, OutputArray dst, int flags=0);
|
||||
//! performs inverse 1D or 2D Discrete Cosine Transformation
|
||||
CV_EXPORTS_W void idct(const Mat& src, CV_OUT Mat& dst, int flags=0);
|
||||
CV_EXPORTS_W void idct(const 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
|
||||
CV_EXPORTS_W void mulSpectrums(const Mat& a, const Mat& b, CV_OUT Mat& c,
|
||||
int flags, bool conjB=false);
|
||||
CV_EXPORTS_W void mulSpectrums(const InputArray& a, const InputArray& b, OutputArray c,
|
||||
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
|
||||
CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
|
||||
|
||||
@@ -2250,9 +2326,9 @@ enum
|
||||
KMEANS_USE_INITIAL_LABELS=1 // Uses the user-provided labels for K-Means initialization
|
||||
};
|
||||
//! clusters the input data using k-Means algorithm
|
||||
CV_EXPORTS_W double kmeans( const Mat& data, int K, CV_OUT Mat& bestLabels,
|
||||
TermCriteria criteria, int attempts,
|
||||
int flags, CV_OUT Mat* centers=0 );
|
||||
CV_EXPORTS_W double kmeans( const InputArray& data, int K, CV_OUT InputOutputArray bestLabels,
|
||||
TermCriteria criteria, int attempts,
|
||||
int flags, OutputArray centers=OutputArray() );
|
||||
|
||||
//! returns the thread-local Random number generator
|
||||
CV_EXPORTS RNG& theRNG();
|
||||
@@ -2261,13 +2337,13 @@ CV_EXPORTS RNG& theRNG();
|
||||
template<typename _Tp> static inline _Tp randu() { return (_Tp)theRNG(); }
|
||||
|
||||
//! fills array with uniformly-distributed random numbers from the range [low, high)
|
||||
CV_EXPORTS_W void randu(CV_OUT Mat& dst, const Scalar& low, const Scalar& high);
|
||||
CV_EXPORTS_W void randu(CV_IN_OUT OutputArray dst, const InputArray& low, const InputArray& high);
|
||||
|
||||
//! fills array with normally-distributed random numbers with the specified mean and the standard deviation
|
||||
CV_EXPORTS_W void randn(CV_OUT Mat& dst, const Scalar& mean, const Scalar& stddev);
|
||||
CV_EXPORTS_W void randn(CV_IN_OUT OutputArray dst, const InputArray& mean, const InputArray& stddev);
|
||||
|
||||
//! shuffles the input array elements
|
||||
CV_EXPORTS void randShuffle(Mat& dst, double iterFactor=1., RNG* rng=0);
|
||||
CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor=1., RNG* rng=0);
|
||||
|
||||
//! draws the line segment (pt1, pt2) in the image
|
||||
CV_EXPORTS_W void line(Mat& img, Point pt1, Point pt2, const Scalar& color,
|
||||
@@ -2351,8 +2427,8 @@ public:
|
||||
|
||||
//! converts elliptic arc to a polygonal curve
|
||||
CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
|
||||
int arcStart, int arcEnd, int delta,
|
||||
CV_OUT vector<Point>& pts );
|
||||
int arcStart, int arcEnd, int delta,
|
||||
CV_OUT vector<Point>& pts );
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -2828,6 +2904,7 @@ template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS Au
|
||||
{
|
||||
public:
|
||||
typedef _Tp value_type;
|
||||
enum { buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) };
|
||||
|
||||
//! the default contructor
|
||||
AutoBuffer();
|
||||
@@ -2851,7 +2928,7 @@ protected:
|
||||
//! size of the real buffer
|
||||
size_t size;
|
||||
//! pre-allocated buffer
|
||||
_Tp buf[fixed_size];
|
||||
_Tp buf[fixed_size+buffer_padding];
|
||||
};
|
||||
|
||||
/////////////////////////// multi-dimensional dense matrix //////////////////////////
|
||||
@@ -2912,9 +2989,11 @@ 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, int narrays=-1);
|
||||
void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
|
||||
|
||||
//! proceeds to the next plane of every iterated matrix
|
||||
NAryMatIterator& operator ++();
|
||||
@@ -2925,12 +3004,17 @@ public:
|
||||
const Mat** arrays;
|
||||
//! the current planes
|
||||
Mat* planes;
|
||||
//! data pointers
|
||||
uchar** ptrs;
|
||||
//! the number of arrays
|
||||
int narrays;
|
||||
//! the number of planes in each array
|
||||
int nplanes;
|
||||
//! 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, idx;
|
||||
int iterdepth;
|
||||
size_t idx;
|
||||
};
|
||||
|
||||
//typedef NAryMatIterator NAryMatNDIterator;
|
||||
@@ -3081,7 +3165,7 @@ public:
|
||||
\param try1d if true and m is a single-column matrix (Nx1),
|
||||
then the sparse matrix will be 1-dimensional.
|
||||
*/
|
||||
SparseMat(const Mat& m);
|
||||
explicit SparseMat(const Mat& m);
|
||||
//! converts old-style sparse matrix to the new-style. All the data is copied
|
||||
SparseMat(const CvSparseMat* m);
|
||||
//! the destructor
|
||||
@@ -3563,39 +3647,30 @@ public:
|
||||
//! the default constructor
|
||||
CV_WRAP KDTree();
|
||||
//! the full constructor that builds the search tree
|
||||
CV_WRAP KDTree(const Mat& _points, bool copyAndReorderPoints=false);
|
||||
CV_WRAP KDTree(const InputArray& points, bool copyAndReorderPoints=false);
|
||||
//! the full constructor that builds the search tree
|
||||
CV_WRAP KDTree(const Mat& _points, const Mat& _labels, bool copyAndReorderPoints=false);
|
||||
CV_WRAP KDTree(const InputArray& points, const InputArray& _labels,
|
||||
bool copyAndReorderPoints=false);
|
||||
//! builds the search tree
|
||||
CV_WRAP void build(const Mat& _points, bool copyAndReorderPoints=false);
|
||||
CV_WRAP void build(const InputArray& points, bool copyAndReorderPoints=false);
|
||||
//! builds the search tree
|
||||
CV_WRAP void build(const Mat& _points, const Mat& _labels, bool copyAndReorderPoints=false);
|
||||
CV_WRAP void build(const InputArray& points, const InputArray& labels,
|
||||
bool copyAndReorderPoints=false);
|
||||
//! finds the K nearest neighbors of "vec" while looking at Emax (at most) leaves
|
||||
int findNearest(const float* vec,
|
||||
int K, int Emax, int* neighborsIdx,
|
||||
Mat* neighbors=0, float* dist=0, int* labels=0) const;
|
||||
//! finds the K nearest neighbors while looking at Emax (at most) leaves
|
||||
int findNearest(const float* vec, int K, int Emax,
|
||||
vector<int>* neighborsIdx,
|
||||
Mat* neighbors=0,
|
||||
vector<float>* dist=0,
|
||||
vector<int>* labels=0) const;
|
||||
CV_WRAP int findNearest(const vector<float>& vec, int K, int Emax,
|
||||
CV_OUT vector<int>* neighborsIdx,
|
||||
CV_OUT Mat* neighbors=0,
|
||||
CV_OUT vector<float>* dist=0,
|
||||
CV_OUT vector<int>* labels=0) const;
|
||||
CV_WRAP int findNearest(const InputArray& vec, int K, int Emax,
|
||||
OutputArray neighborsIdx,
|
||||
OutputArray neighbors=OutputArray(),
|
||||
OutputArray dist=OutputArray(),
|
||||
OutputArray labels=OutputArray()) const;
|
||||
//! finds all the points from the initial set that belong to the specified box
|
||||
void findOrthoRange(const float* minBounds, const float* maxBounds,
|
||||
vector<int>* neighborsIdx, Mat* neighbors=0,
|
||||
vector<int>* labels=0) const;
|
||||
CV_WRAP void findOrthoRange(const vector<float>& minBounds, const vector<float>& maxBounds,
|
||||
CV_OUT vector<int>* neighborsIdx, CV_OUT Mat* neighbors=0,
|
||||
CV_OUT vector<int>* labels=0) const;
|
||||
CV_WRAP void findOrthoRange(const InputArray& minBounds,
|
||||
const InputArray& maxBounds,
|
||||
OutputArray neighborsIdx,
|
||||
OutputArray neighbors=OutputArray(),
|
||||
OutputArray labels=OutputArray()) const;
|
||||
//! returns vectors with the specified indices
|
||||
void getPoints(const int* idx, size_t nidx, Mat& pts, vector<int>* labels=0) const;
|
||||
//! returns vectors with the specified indices
|
||||
CV_WRAP void getPoints(const vector<int>& idxs, Mat& pts, CV_OUT vector<int>* labels=0) const;
|
||||
CV_WRAP void getPoints(const InputArray& idx, OutputArray pts,
|
||||
OutputArray labels=OutputArray()) const;
|
||||
//! return a vector with the specified index
|
||||
const float* getPoint(int ptidx, int* label=0) const;
|
||||
//! returns the search space dimensionality
|
||||
@@ -4042,7 +4117,7 @@ public:
|
||||
int index;
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
class CV_EXPORTS AlgorithmImpl;
|
||||
|
||||
/*!
|
||||
@@ -4088,7 +4163,6 @@ protected:
|
||||
|
||||
Ptr<AlgorithmImpl> impl;
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
@@ -608,21 +608,6 @@ template<typename _Tp> inline MatIterator_<_Tp> Mat::end()
|
||||
return it;
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp> inline void Mat::copyTo(vector<_Tp>& v) const
|
||||
{
|
||||
int n = checkVector(DataType<_Tp>::channels);
|
||||
if( empty() || n == 0 )
|
||||
{
|
||||
v.clear();
|
||||
return;
|
||||
}
|
||||
CV_Assert( n > 0 );
|
||||
v.resize(n);
|
||||
Mat temp(dims, size.p, DataType<_Tp>::type, &v[0]);
|
||||
convertTo(temp, DataType<_Tp>::type);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline Mat::operator vector<_Tp>() const
|
||||
{
|
||||
vector<_Tp> v;
|
||||
@@ -726,10 +711,12 @@ static inline Mat cvarrToMatND(const CvArr* arr, bool copyData=false, int coiMod
|
||||
///////////////////////////////////////////// SVD //////////////////////////////////////////////////////
|
||||
|
||||
inline SVD::SVD() {}
|
||||
inline SVD::SVD( const Mat& m, int flags ) { operator ()(m, flags); }
|
||||
inline void SVD::solveZ( const Mat& m, Mat& dst )
|
||||
inline SVD::SVD( const InputArray& m, int flags ) { operator ()(m, flags); }
|
||||
inline void SVD::solveZ( const InputArray& m, OutputArray _dst )
|
||||
{
|
||||
SVD svd(m);
|
||||
_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);
|
||||
}
|
||||
|
||||
@@ -1075,6 +1062,22 @@ process( const Mat_<T1>& m1, const Mat_<T2>& m2, Mat_<T3>& m3, Op op )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////// Input/Output Arrays /////////////////////////////////
|
||||
|
||||
template<typename _Tp> InputArray::InputArray(const vector<_Tp>& vec)
|
||||
: flags(STD_VECTOR + DataType<_Tp>::type), obj((void*)&vec) {}
|
||||
|
||||
template<typename _Tp> InputArray::InputArray(const vector<vector<_Tp> >& vec)
|
||||
: flags(STD_VECTOR_VECTOR + DataType<_Tp>::type), obj((void*)&vec) {}
|
||||
|
||||
template<typename _Tp, int m, int n> InputArray::InputArray(const Matx<_Tp, m, n>& mtx)
|
||||
: flags(MATX + DataType<_Tp>::type), obj((void*)&mtx), sz(n, m) {}
|
||||
|
||||
template<typename _Tp> OutputArray::OutputArray(vector<_Tp>& vec) : InputArray(vec) {}
|
||||
template<typename _Tp> OutputArray::OutputArray(vector<vector<_Tp> >& vec) : InputArray(vec) {}
|
||||
template<typename _Tp, int m, int n> OutputArray::OutputArray(Matx<_Tp, m, n>& mtx) : InputArray(mtx) {}
|
||||
|
||||
//////////////////////////////////// Matrix Expressions /////////////////////////////////////////
|
||||
|
||||
class CV_EXPORTS MatOp
|
||||
@@ -1113,6 +1116,9 @@ public:
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1152,6 +1158,9 @@ public:
|
||||
MatExpr mul(const MatExpr& e, double scale=1) const;
|
||||
MatExpr mul(const Mat& m, double scale=1) const;
|
||||
|
||||
Size size() const;
|
||||
int type() const;
|
||||
|
||||
const MatOp* op;
|
||||
int flags;
|
||||
|
||||
|
@@ -2298,10 +2298,17 @@ inline Point LineIterator::pos() const
|
||||
/////////////////////////////// AutoBuffer ////////////////////////////////////////
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::AutoBuffer()
|
||||
: ptr(buf), size(fixed_size) {}
|
||||
{
|
||||
ptr = alignPtr(buf, 16);
|
||||
size = fixed_size;
|
||||
}
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size)
|
||||
: ptr(buf), size(fixed_size) { allocate(_size); }
|
||||
{
|
||||
ptr = alignPtr(buf, 16);
|
||||
size = fixed_size;
|
||||
allocate(_size);
|
||||
}
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::~AutoBuffer()
|
||||
{ deallocate(); }
|
||||
@@ -2320,10 +2327,11 @@ template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size>::deallocate()
|
||||
{
|
||||
if( ptr != buf )
|
||||
_Tp* buf0 = alignPtr(buf, 16);
|
||||
if( ptr != buf0 )
|
||||
{
|
||||
cv::deallocate<_Tp>(ptr, size);
|
||||
ptr = buf;
|
||||
ptr = buf0;
|
||||
size = fixed_size;
|
||||
}
|
||||
}
|
||||
@@ -3550,7 +3558,6 @@ template<typename _Tp> static inline std::ostream& operator << (std::ostream& ou
|
||||
return out;
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<typename _Tp> struct AlgorithmParamType {};
|
||||
template<> struct AlgorithmParamType<int> { enum { type = CV_PARAM_TYPE_INT }; };
|
||||
template<> struct AlgorithmParamType<double> { enum { type = CV_PARAM_TYPE_REAL }; };
|
||||
@@ -3594,7 +3601,6 @@ template<typename _Tp> void Algorithm::setParamRange(int propId, const _Tp& minV
|
||||
{
|
||||
setParamRange_(propId, AlgorithmParamType<_Tp>::type, &minVal, &maxVal);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -722,10 +722,10 @@ icvGetNodePtr( CvSparseMat* mat, const int* idx, int* _type,
|
||||
node->hashval = hashval;
|
||||
node->next = (CvSparseNode*)mat->hashtable[tabidx];
|
||||
mat->hashtable[tabidx] = node;
|
||||
CV_MEMCPY_INT( CV_NODE_IDX(mat,node), idx, mat->dims );
|
||||
memcpy(CV_NODE_IDX(mat,node), idx, mat->dims*sizeof(idx[0]));
|
||||
ptr = (uchar*)CV_NODE_VAL(mat,node);
|
||||
if( create_node > 0 )
|
||||
CV_ZERO_CHAR( ptr, CV_ELEM_SIZE(mat->type));
|
||||
memset( ptr, 0, CV_ELEM_SIZE(mat->type));
|
||||
}
|
||||
|
||||
if( _type )
|
||||
@@ -1512,7 +1512,7 @@ cvScalarToRawData( const CvScalar* scalar, void* data, int type, int extend_to_1
|
||||
do
|
||||
{
|
||||
offset -= pix_size;
|
||||
CV_MEMCPY_AUTO( (char*)data + offset, data, pix_size );
|
||||
memcpy((char*)data + offset, data, pix_size);
|
||||
}
|
||||
while( offset > pix_size );
|
||||
}
|
||||
@@ -2358,7 +2358,7 @@ cvClearND( CvArr* arr, const int* idx )
|
||||
uchar* ptr;
|
||||
ptr = cvPtrND( arr, idx, &type );
|
||||
if( ptr )
|
||||
CV_ZERO_CHAR( ptr, CV_ELEM_SIZE(type) );
|
||||
memset( ptr, 0, CV_ELEM_SIZE(type) );
|
||||
}
|
||||
else
|
||||
icvDeleteNode( (CvSparseMat*)arr, idx, 0 );
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -52,18 +52,12 @@ namespace cv
|
||||
{
|
||||
|
||||
template<typename T> static void
|
||||
copyMask_(const Mat& srcmat, Mat& dstmat, const Mat& maskmat)
|
||||
copyMask_(const uchar* _src, size_t sstep, const uchar* mask, size_t mstep, uchar* _dst, size_t dstep, Size size)
|
||||
{
|
||||
const uchar* mask = maskmat.data;
|
||||
size_t sstep = srcmat.step;
|
||||
size_t dstep = dstmat.step;
|
||||
size_t mstep = maskmat.step;
|
||||
Size size = getContinuousSize(srcmat, dstmat, maskmat);
|
||||
|
||||
for( int y = 0; y < size.height; y++, mask += mstep )
|
||||
for( ; size.height--; mask += mstep, _src += sstep, _dst += dstep )
|
||||
{
|
||||
const T* src = (const T*)(srcmat.data + sstep*y);
|
||||
T* dst = (T*)(dstmat.data + dstep*y);
|
||||
const T* src = (const T*)_src;
|
||||
T* dst = (T*)_dst;
|
||||
int x = 0;
|
||||
for( ; x <= size.width - 4; x += 4 )
|
||||
{
|
||||
@@ -82,389 +76,397 @@ copyMask_(const Mat& srcmat, Mat& dstmat, const Mat& maskmat)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> static void
|
||||
setMask_(const void* _scalar, Mat& dstmat, const Mat& maskmat)
|
||||
static void
|
||||
copyMaskGeneric(const uchar* _src, size_t sstep, const uchar* mask, size_t mstep, uchar* _dst, size_t dstep, Size size, void* _esz)
|
||||
{
|
||||
T scalar = *(T*)_scalar;
|
||||
const uchar* mask = maskmat.data;
|
||||
size_t dstep = dstmat.step;
|
||||
size_t mstep = maskmat.step;
|
||||
Size size = dstmat.size();
|
||||
|
||||
if( dstmat.isContinuous() && maskmat.isContinuous() )
|
||||
size_t k, esz = *(size_t*)_esz;
|
||||
for( ; size.height--; mask += mstep, _src += sstep, _dst += dstep )
|
||||
{
|
||||
size.width *= size.height;
|
||||
size.height = 1;
|
||||
const uchar* src = _src;
|
||||
uchar* dst = _dst;
|
||||
int x = 0;
|
||||
for( ; x < size.width; x++, src += esz, dst += esz )
|
||||
{
|
||||
if( !mask[x] )
|
||||
continue;
|
||||
for( k = 0; k < esz; k++ )
|
||||
dst[k] = src[k];
|
||||
}
|
||||
}
|
||||
|
||||
for( int y = 0; y < size.height; y++, mask += mstep )
|
||||
}
|
||||
|
||||
template<typename T> static void
|
||||
setMask_(T value, const uchar* mask, size_t mstep, uchar* _dst, size_t dstep, Size size)
|
||||
{
|
||||
for( ; size.height--; mask += mstep, _dst += dstep )
|
||||
{
|
||||
T* dst = (T*)(dstmat.data + dstep*y);
|
||||
T* dst = (T*)_dst;
|
||||
int x = 0;
|
||||
for( ; x <= size.width - 4; x += 4 )
|
||||
{
|
||||
if( mask[x] )
|
||||
dst[x] = scalar;
|
||||
dst[x] = value;
|
||||
if( mask[x+1] )
|
||||
dst[x+1] = scalar;
|
||||
dst[x+1] = value;
|
||||
if( mask[x+2] )
|
||||
dst[x+2] = scalar;
|
||||
dst[x+2] = value;
|
||||
if( mask[x+3] )
|
||||
dst[x+3] = scalar;
|
||||
dst[x+3] = value;
|
||||
}
|
||||
for( ; x < size.width; x++ )
|
||||
if( mask[x] )
|
||||
dst[x] = scalar;
|
||||
dst[x] = value;
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*SetMaskFunc)(const void* scalar, Mat& dst, const Mat& mask);
|
||||
|
||||
CopyMaskFunc g_copyMaskFuncTab[] =
|
||||
static void
|
||||
setMaskGeneric(const uchar* value, size_t, const uchar* mask, size_t mstep, uchar* _dst, size_t dstep, Size size, void* _esz)
|
||||
{
|
||||
size_t k, esz = *(size_t*)_esz;
|
||||
for( ; size.height--; mask += mstep, _dst += dstep )
|
||||
{
|
||||
uchar* dst = _dst;
|
||||
int x = 0;
|
||||
for( ; x < size.width; x++, dst += esz )
|
||||
{
|
||||
if( !mask[x] )
|
||||
continue;
|
||||
for( k = 0; k < esz; k++ )
|
||||
dst[k] = value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define DEF_COPY_SET_MASK(suffix, type) \
|
||||
static void copyMask##suffix(const uchar* src, size_t sstep, const uchar* mask, size_t mstep, \
|
||||
uchar* dst, size_t dstep, Size size, void*) \
|
||||
{ \
|
||||
copyMask_<type>(src, sstep, mask, mstep, dst, dstep, size); \
|
||||
} \
|
||||
static void setMask##suffix( const uchar* src, size_t, const uchar* mask, size_t mstep, \
|
||||
uchar* dst, size_t dstep, Size size, void*) \
|
||||
{ \
|
||||
setMask_<type>(*(const type*)src, mask, mstep, dst, dstep, size); \
|
||||
}
|
||||
|
||||
|
||||
DEF_COPY_SET_MASK(8u, uchar);
|
||||
DEF_COPY_SET_MASK(16u, ushort);
|
||||
DEF_COPY_SET_MASK(8uC3, Vec3b);
|
||||
DEF_COPY_SET_MASK(32s, int);
|
||||
DEF_COPY_SET_MASK(16uC3, Vec3s);
|
||||
DEF_COPY_SET_MASK(32sC2, Vec2i);
|
||||
DEF_COPY_SET_MASK(32sC3, Vec3i);
|
||||
DEF_COPY_SET_MASK(32sC4, Vec4i);
|
||||
DEF_COPY_SET_MASK(32sC6, Vec6i);
|
||||
DEF_COPY_SET_MASK(32sC8, Vec8i);
|
||||
|
||||
BinaryFunc copyMaskTab[] =
|
||||
{
|
||||
0,
|
||||
copyMask_<uchar>, // 1
|
||||
copyMask_<ushort>, // 2
|
||||
copyMask_<Vec<uchar,3> >, // 3
|
||||
copyMask_<int>, // 4
|
||||
copyMask8u,
|
||||
copyMask16u,
|
||||
copyMask8uC3,
|
||||
copyMask32s,
|
||||
0,
|
||||
copyMask_<Vec<ushort,3> >, // 6
|
||||
copyMask16uC3,
|
||||
0,
|
||||
copyMask_<Vec<int,2> >, // 8
|
||||
copyMask32sC2,
|
||||
0, 0, 0,
|
||||
copyMask_<Vec<int,3> >, // 12
|
||||
copyMask32sC3,
|
||||
0, 0, 0,
|
||||
copyMask_<Vec<int,4> >, // 16
|
||||
copyMask32sC4,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
copyMask_<Vec<int,6> >, // 24
|
||||
copyMask32sC6,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
copyMask_<Vec<int,8> > // 32
|
||||
copyMask32sC8
|
||||
};
|
||||
|
||||
static SetMaskFunc setMaskFuncTab[] =
|
||||
BinaryFunc setMaskTab[] =
|
||||
{
|
||||
0,
|
||||
setMask_<uchar>, // 1
|
||||
setMask_<ushort>, // 2
|
||||
setMask_<Vec<uchar,3> >, // 3
|
||||
setMask_<int>, // 4
|
||||
setMask8u,
|
||||
setMask16u,
|
||||
setMask8uC3,
|
||||
setMask32s,
|
||||
0,
|
||||
setMask_<Vec<ushort,3> >, // 6
|
||||
setMask16uC3,
|
||||
0,
|
||||
setMask_<Vec<int,2> >, // 8
|
||||
setMask32sC2,
|
||||
0, 0, 0,
|
||||
setMask_<Vec<int,3> >, // 12
|
||||
setMask32sC3,
|
||||
0, 0, 0,
|
||||
setMask_<Vec<int,4> >, // 16
|
||||
setMask32sC4,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
setMask_<Vec<int,6> >, // 24
|
||||
setMask32sC6,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
setMask_<Vec<int,8> > // 32
|
||||
};
|
||||
|
||||
setMask32sC8
|
||||
};
|
||||
|
||||
BinaryFunc getCopyMaskFunc(size_t esz)
|
||||
{
|
||||
return esz <= 32 && copyMaskTab[esz] ? copyMaskTab[esz] : copyMaskGeneric;
|
||||
}
|
||||
|
||||
/* dst = src */
|
||||
void Mat::copyTo( Mat& dst ) const
|
||||
void Mat::copyTo( OutputArray _dst ) const
|
||||
{
|
||||
if( data == dst.data && data != 0 )
|
||||
return;
|
||||
|
||||
if( dims > 2 )
|
||||
int dtype = _dst.type();
|
||||
if( _dst.fixedType() && dtype != type() )
|
||||
{
|
||||
dst.create( dims, size, type() );
|
||||
if( total() != 0 )
|
||||
{
|
||||
const Mat* arrays[] = { this, &dst, 0 };
|
||||
Mat planes[2];
|
||||
NAryMatIterator it(arrays, planes);
|
||||
CV_DbgAssert(it.planes[0].isContinuous() &&
|
||||
it.planes[1].isContinuous());
|
||||
size_t planeSize = it.planes[0].elemSize()*it.planes[0].rows*it.planes[0].cols;
|
||||
convertTo( _dst, dtype );
|
||||
return;
|
||||
}
|
||||
|
||||
if( empty() )
|
||||
{
|
||||
_dst.release();
|
||||
return;
|
||||
}
|
||||
|
||||
if( dims <= 2 )
|
||||
{
|
||||
_dst.create( rows, cols, type() );
|
||||
Mat dst = _dst.getMat();
|
||||
if( data == dst.data )
|
||||
return;
|
||||
|
||||
for( int i = 0; i < it.nplanes; i++, ++it )
|
||||
memcpy(it.planes[1].data, it.planes[0].data, planeSize);
|
||||
if( rows > 0 && cols > 0 )
|
||||
{
|
||||
const uchar* sptr = data;
|
||||
uchar* dptr = dst.data;
|
||||
|
||||
Size sz = getContinuousSize(*this, dst, (int)elemSize());
|
||||
for( ; sz.height--; sptr += step, dptr += dst.step )
|
||||
memcpy( dptr, sptr, sz.width );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
dst.create( rows, cols, type() );
|
||||
Size sz = size();
|
||||
_dst.create( dims, size, type() );
|
||||
Mat dst = _dst.getMat();
|
||||
if( data == dst.data )
|
||||
return;
|
||||
|
||||
if( rows > 0 && cols > 0 )
|
||||
if( total() != 0 )
|
||||
{
|
||||
const uchar* sptr = data;
|
||||
uchar* dptr = dst.data;
|
||||
|
||||
size_t width = sz.width*elemSize();
|
||||
if( isContinuous() && dst.isContinuous() )
|
||||
{
|
||||
width *= sz.height;
|
||||
sz.height = 1;
|
||||
}
|
||||
|
||||
for( ; sz.height--; sptr += step, dptr += dst.step )
|
||||
memcpy( dptr, sptr, width );
|
||||
const Mat* arrays[] = { this, &dst };
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs, 2);
|
||||
size_t size = it.size*elemSize();
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
memcpy(ptrs[1], ptrs[0], size);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat::copyTo( Mat& dst, const Mat& mask ) const
|
||||
void Mat::copyTo( OutputArray _dst, const InputArray& _mask ) const
|
||||
{
|
||||
Mat mask = _mask.getMat();
|
||||
if( !mask.data )
|
||||
{
|
||||
copyTo(dst);
|
||||
copyTo(_dst);
|
||||
return;
|
||||
}
|
||||
|
||||
if( dims > 2 )
|
||||
{
|
||||
dst.create( dims, size, type() );
|
||||
const Mat* arrays[] = { this, &dst, &mask, 0 };
|
||||
Mat planes[3];
|
||||
NAryMatIterator it(arrays, planes);
|
||||
|
||||
for( int i = 0; i < it.nplanes; i++, ++it )
|
||||
it.planes[0].copyTo(it.planes[1], it.planes[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
uchar* data0 = dst.data;
|
||||
dst.create( size(), type() );
|
||||
CV_Assert( mask.type() == CV_8U );
|
||||
|
||||
size_t esz = elemSize();
|
||||
BinaryFunc copymask = getCopyMaskFunc(esz);
|
||||
|
||||
uchar* data0 = _dst.getMat().data;
|
||||
_dst.create( dims, size, type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
if( dst.data != data0 ) // do not leave dst uninitialized
|
||||
dst = Scalar(0);
|
||||
getCopyMaskFunc((int)elemSize())(*this, dst, mask);
|
||||
|
||||
if( dims <= 2 )
|
||||
{
|
||||
Size sz = getContinuousSize(*this, dst, mask);
|
||||
copymask(data, step, mask.data, mask.step, dst.data, dst.step, sz, &esz);
|
||||
return;
|
||||
}
|
||||
|
||||
const Mat* arrays[] = { this, &dst, &mask, 0 };
|
||||
uchar* ptrs[3];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
Size sz((int)it.size, 1);
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
copymask(ptrs[0], 0, ptrs[2], 0, ptrs[1], 0, sz, &esz);
|
||||
}
|
||||
|
||||
Mat& Mat::operator = (const Scalar& s)
|
||||
{
|
||||
if( dims > 2 )
|
||||
{
|
||||
const Mat* arrays[] = { this, 0 };
|
||||
Mat planes[1];
|
||||
NAryMatIterator it(arrays, planes);
|
||||
|
||||
for( int i = 0; i < it.nplanes; i++, ++it )
|
||||
it.planes[0] = s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Size sz = size();
|
||||
uchar* dst = data;
|
||||
|
||||
sz.width *= (int)elemSize();
|
||||
if( isContinuous() )
|
||||
{
|
||||
sz.width *= sz.height;
|
||||
sz.height = 1;
|
||||
}
|
||||
const Mat* arrays[] = { this };
|
||||
uchar* ptr;
|
||||
NAryMatIterator it(arrays, &ptr, 1);
|
||||
size_t size = it.size*elemSize();
|
||||
|
||||
if( s[0] == 0 && s[1] == 0 && s[2] == 0 && s[3] == 0 )
|
||||
{
|
||||
for( ; sz.height--; dst += step )
|
||||
memset( dst, 0, sz.width );
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
memset( ptr, 0, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
int t = type(), esz1 = (int)elemSize1();
|
||||
double scalar[12];
|
||||
scalarToRawData(s, scalar, t, 12);
|
||||
int copy_len = 12*esz1;
|
||||
uchar* dst_limit = dst + sz.width;
|
||||
|
||||
if( sz.height-- )
|
||||
if( it.nplanes > 0 )
|
||||
{
|
||||
while( dst + copy_len <= dst_limit )
|
||||
double scalar[12];
|
||||
scalarToRawData(s, scalar, type(), 12);
|
||||
size_t blockSize = 12*elemSize1();
|
||||
|
||||
for( size_t j = 0; j < size; j += blockSize )
|
||||
{
|
||||
memcpy( dst, scalar, copy_len );
|
||||
dst += copy_len;
|
||||
size_t sz = std::min(blockSize, size - j);
|
||||
memcpy( ptr + j, scalar, sz );
|
||||
}
|
||||
memcpy( dst, scalar, dst_limit - dst );
|
||||
}
|
||||
|
||||
if( sz.height > 0 )
|
||||
|
||||
for( size_t i = 1; i < it.nplanes; i++ )
|
||||
{
|
||||
dst = dst_limit - sz.width + step;
|
||||
for( ; sz.height--; dst += step )
|
||||
memcpy( dst, data, sz.width );
|
||||
++it;
|
||||
memcpy( ptr, data, size );
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat& Mat::setTo(const Scalar& s, const Mat& mask)
|
||||
Mat& Mat::setTo(const Scalar& s, const InputArray& _mask)
|
||||
{
|
||||
Mat mask = _mask.getMat();
|
||||
if( !mask.data )
|
||||
*this = s;
|
||||
else
|
||||
{
|
||||
CV_Assert( channels() <= 4 );
|
||||
SetMaskFunc func = setMaskFuncTab[elemSize()];
|
||||
CV_Assert( func != 0 );
|
||||
CV_Assert( channels() <= 4 && mask.type() == CV_8U );
|
||||
size_t esz = elemSize();
|
||||
BinaryFunc func = esz <= 32 ? setMaskTab[esz] : setMaskGeneric;
|
||||
double buf[4];
|
||||
scalarToRawData(s, buf, type(), 0);
|
||||
|
||||
if( dims > 2 )
|
||||
{
|
||||
const Mat* arrays[] = { this, &mask, 0 };
|
||||
Mat planes[2];
|
||||
NAryMatIterator it(arrays, planes);
|
||||
|
||||
for( int i = 0; i < it.nplanes; i++, ++it )
|
||||
func(buf, it.planes[0], it.planes[1]);
|
||||
}
|
||||
else
|
||||
func(buf, *this, mask);
|
||||
const Mat* arrays[] = { this, &mask, 0 };
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
Size sz((int)it.size, 1);
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
func((const uchar*)buf, 0, ptrs[1], 0, ptrs[0], 0, sz, &esz);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> static void
|
||||
flipHoriz_( const Mat& srcmat, Mat& dstmat, bool flipv )
|
||||
static void
|
||||
flipHoriz( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size size, size_t esz )
|
||||
{
|
||||
uchar* dst0 = dstmat.data;
|
||||
size_t srcstep = srcmat.step;
|
||||
int dststep = (int)dstmat.step;
|
||||
Size size = srcmat.size();
|
||||
int i, j, limit = ((size.width + 1)/2)*esz;
|
||||
AutoBuffer<int> _tab(size.width*esz);
|
||||
int* tab = _tab;
|
||||
|
||||
for( i = 0; i < size.width; i++ )
|
||||
for( size_t k = 0; k < esz; k++ )
|
||||
tab[i*esz + k] = (size.width - i - 1)*esz + k;
|
||||
|
||||
if( flipv )
|
||||
for( ; size.height--; src += sstep, dst += dstep )
|
||||
{
|
||||
dst0 += (size.height - 1)*dststep;
|
||||
dststep = -dststep;
|
||||
}
|
||||
|
||||
for( int y = 0; y < size.height; y++ )
|
||||
{
|
||||
const T* src = (const T*)(srcmat.data + srcstep*y);
|
||||
T* dst = (T*)(dst0 + dststep*y);
|
||||
|
||||
for( int i = 0; i < (size.width + 1)/2; i++ )
|
||||
for( i = 0; i < limit; i++ )
|
||||
{
|
||||
T t0 = src[i], t1 = src[size.width - i - 1];
|
||||
dst[i] = t1; dst[size.width - i - 1] = t0;
|
||||
j = tab[i];
|
||||
uchar t0 = src[i], t1 = src[j];
|
||||
dst[i] = t1; dst[j] = t0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*FlipHorizFunc)( const Mat& src, Mat& dst, bool flipv );
|
||||
|
||||
static void
|
||||
flipVert( const Mat& srcmat, Mat& dstmat )
|
||||
flipVert( const uchar* src0, size_t sstep, uchar* dst0, size_t dstep, Size size, size_t esz )
|
||||
{
|
||||
const uchar* src = srcmat.data;
|
||||
uchar* dst = dstmat.data;
|
||||
size_t srcstep = srcmat.step, dststep = dstmat.step;
|
||||
Size size = srcmat.size();
|
||||
const uchar* src1 = src + (size.height - 1)*srcstep;
|
||||
uchar* dst1 = dst + (size.height - 1)*dststep;
|
||||
size.width *= (int)srcmat.elemSize();
|
||||
const uchar* src1 = src0 + (size.height - 1)*sstep;
|
||||
uchar* dst1 = dst0 + (size.height - 1)*dstep;
|
||||
size.width *= (int)esz;
|
||||
|
||||
for( int y = 0; y < (size.height + 1)/2; y++, src += srcstep, src1 -= srcstep,
|
||||
dst += dststep, dst1 -= dststep )
|
||||
for( int y = 0; y < (size.height + 1)/2; y++, src0 += sstep, src1 -= sstep,
|
||||
dst0 += dstep, dst1 -= dstep )
|
||||
{
|
||||
int i = 0;
|
||||
if( ((size_t)(src)|(size_t)(dst)|(size_t)src1|(size_t)dst1) % sizeof(int) == 0 )
|
||||
if( ((size_t)src0|(size_t)dst0|(size_t)src1|(size_t)dst1) % sizeof(int) == 0 )
|
||||
{
|
||||
for( ; i <= size.width - 16; i += 16 )
|
||||
{
|
||||
int t0 = ((int*)(src + i))[0];
|
||||
int t0 = ((int*)(src0 + i))[0];
|
||||
int t1 = ((int*)(src1 + i))[0];
|
||||
|
||||
((int*)(dst + i))[0] = t1;
|
||||
((int*)(dst0 + i))[0] = t1;
|
||||
((int*)(dst1 + i))[0] = t0;
|
||||
|
||||
t0 = ((int*)(src + i))[1];
|
||||
t0 = ((int*)(src0 + i))[1];
|
||||
t1 = ((int*)(src1 + i))[1];
|
||||
|
||||
((int*)(dst + i))[1] = t1;
|
||||
((int*)(dst0 + i))[1] = t1;
|
||||
((int*)(dst1 + i))[1] = t0;
|
||||
|
||||
t0 = ((int*)(src + i))[2];
|
||||
t0 = ((int*)(src0 + i))[2];
|
||||
t1 = ((int*)(src1 + i))[2];
|
||||
|
||||
((int*)(dst + i))[2] = t1;
|
||||
((int*)(dst0 + i))[2] = t1;
|
||||
((int*)(dst1 + i))[2] = t0;
|
||||
|
||||
t0 = ((int*)(src + i))[3];
|
||||
t0 = ((int*)(src0 + i))[3];
|
||||
t1 = ((int*)(src1 + i))[3];
|
||||
|
||||
((int*)(dst + i))[3] = t1;
|
||||
((int*)(dst0 + i))[3] = t1;
|
||||
((int*)(dst1 + i))[3] = t0;
|
||||
}
|
||||
|
||||
for( ; i <= size.width - 4; i += 4 )
|
||||
{
|
||||
int t0 = ((int*)(src + i))[0];
|
||||
int t0 = ((int*)(src0 + i))[0];
|
||||
int t1 = ((int*)(src1 + i))[0];
|
||||
|
||||
((int*)(dst + i))[0] = t1;
|
||||
((int*)(dst0 + i))[0] = t1;
|
||||
((int*)(dst1 + i))[0] = t0;
|
||||
}
|
||||
}
|
||||
|
||||
for( ; i < size.width; i++ )
|
||||
{
|
||||
uchar t0 = src[i];
|
||||
uchar t0 = src0[i];
|
||||
uchar t1 = src1[i];
|
||||
|
||||
dst[i] = t1;
|
||||
dst0[i] = t1;
|
||||
dst1[i] = t0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void flip( const Mat& src, Mat& dst, int flip_mode )
|
||||
void flip( const InputArray& _src, OutputArray _dst, int flip_mode )
|
||||
{
|
||||
static FlipHorizFunc tab[] =
|
||||
{
|
||||
0,
|
||||
flipHoriz_<uchar>, // 1
|
||||
flipHoriz_<ushort>, // 2
|
||||
flipHoriz_<Vec<uchar,3> >, // 3
|
||||
flipHoriz_<int>, // 4
|
||||
0,
|
||||
flipHoriz_<Vec<ushort,3> >, // 6
|
||||
0,
|
||||
flipHoriz_<Vec<int,2> >, // 8
|
||||
0, 0, 0,
|
||||
flipHoriz_<Vec<int,3> >, // 12
|
||||
0, 0, 0,
|
||||
flipHoriz_<Vec<int,4> >, // 16
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
flipHoriz_<Vec<int,6> >, // 24
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
flipHoriz_<Vec<int,8> > // 32
|
||||
};
|
||||
Mat src = _src.getMat();
|
||||
|
||||
CV_Assert( src.dims <= 2 );
|
||||
dst.create( src.size(), src.type() );
|
||||
_dst.create( src.size(), src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
size_t esz = src.elemSize();
|
||||
|
||||
if( flip_mode == 0 )
|
||||
flipVert( src, dst );
|
||||
if( flip_mode <= 0 )
|
||||
flipVert( src.data, src.step, dst.data, dst.step, src.size(), esz );
|
||||
else
|
||||
{
|
||||
int esz = (int)src.elemSize();
|
||||
CV_Assert( esz <= 32 );
|
||||
FlipHorizFunc func = tab[esz];
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
if( flip_mode > 0 )
|
||||
func( src, dst, false );
|
||||
else if( src.data != dst.data )
|
||||
func( src, dst, true );
|
||||
else
|
||||
{
|
||||
func( dst, dst, false );
|
||||
flipVert( dst, dst );
|
||||
}
|
||||
}
|
||||
flipHoriz( src.data, src.step, dst.data, dst.step, src.size(), esz );
|
||||
|
||||
if( flip_mode < 0 )
|
||||
flipHoriz( dst.data, dst.step, dst.data, dst.step, dst.size(), esz );
|
||||
}
|
||||
|
||||
|
||||
void repeat(const Mat& src, int ny, int nx, Mat& dst)
|
||||
void repeat(const InputArray& _src, int ny, int nx, OutputArray _dst)
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
CV_Assert( src.dims <= 2 );
|
||||
|
||||
dst.create(src.rows*ny, src.cols*nx, src.type());
|
||||
_dst.create(src.rows*ny, src.cols*nx, src.type());
|
||||
Mat dst = _dst.getMat();
|
||||
Size ssize = src.size(), dsize = dst.size();
|
||||
int esz = (int)src.elemSize();
|
||||
int x, y;
|
||||
@@ -524,7 +526,7 @@ cvCopy( const void* srcarr, void* dstarr, const void* maskarr )
|
||||
{
|
||||
CvSparseNode* node_copy = (CvSparseNode*)cvSetNew( dst1->heap );
|
||||
int tabidx = node->hashval & (dst1->hashsize - 1);
|
||||
CV_MEMCPY_AUTO( node_copy, node, dst1->heap->elem_size );
|
||||
memcpy( node_copy, node, dst1->heap->elem_size );
|
||||
node_copy->next = (CvSparseNode*)dst1->hashtable[tabidx];
|
||||
dst1->hashtable[tabidx] = node_copy;
|
||||
}
|
||||
|
@@ -1146,7 +1146,7 @@ cvSeqPush( CvSeq *seq, const void *element )
|
||||
}
|
||||
|
||||
if( element )
|
||||
CV_MEMCPY_AUTO( ptr, element, elem_size );
|
||||
memcpy( ptr, element, elem_size );
|
||||
seq->first->prev->count++;
|
||||
seq->total++;
|
||||
seq->ptr = ptr + elem_size;
|
||||
@@ -1171,7 +1171,7 @@ cvSeqPop( CvSeq *seq, void *element )
|
||||
seq->ptr = ptr = seq->ptr - elem_size;
|
||||
|
||||
if( element )
|
||||
CV_MEMCPY_AUTO( element, ptr, elem_size );
|
||||
memcpy( element, ptr, elem_size );
|
||||
seq->ptr = ptr;
|
||||
seq->total--;
|
||||
|
||||
@@ -1208,7 +1208,7 @@ cvSeqPushFront( CvSeq *seq, const void *element )
|
||||
ptr = block->data -= elem_size;
|
||||
|
||||
if( element )
|
||||
CV_MEMCPY_AUTO( ptr, element, elem_size );
|
||||
memcpy( ptr, element, elem_size );
|
||||
block->count++;
|
||||
block->start_index--;
|
||||
seq->total++;
|
||||
@@ -1233,7 +1233,7 @@ cvSeqPopFront( CvSeq *seq, void *element )
|
||||
block = seq->first;
|
||||
|
||||
if( element )
|
||||
CV_MEMCPY_AUTO( element, block->data, elem_size );
|
||||
memcpy( element, block->data, elem_size );
|
||||
block->data += elem_size;
|
||||
block->start_index++;
|
||||
seq->total--;
|
||||
@@ -1708,7 +1708,7 @@ cvSeqRemoveSlice( CvSeq* seq, CvSlice slice )
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
CV_MEMCPY_AUTO( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
memcpy( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
CV_NEXT_SEQ_ELEM( elem_size, reader_to );
|
||||
CV_NEXT_SEQ_ELEM( elem_size, reader_from );
|
||||
}
|
||||
@@ -1726,7 +1726,7 @@ cvSeqRemoveSlice( CvSeq* seq, CvSlice slice )
|
||||
CV_PREV_SEQ_ELEM( elem_size, reader_to );
|
||||
CV_PREV_SEQ_ELEM( elem_size, reader_from );
|
||||
|
||||
CV_MEMCPY_AUTO( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
memcpy( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
}
|
||||
|
||||
cvSeqPopMulti( seq, 0, slice.end_index - slice.start_index, 1 );
|
||||
@@ -1796,7 +1796,7 @@ cvSeqInsertSlice( CvSeq* seq, int index, const CvArr* from_arr )
|
||||
|
||||
for( i = 0; i < index; i++ )
|
||||
{
|
||||
CV_MEMCPY_AUTO( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
memcpy( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
CV_NEXT_SEQ_ELEM( elem_size, reader_to );
|
||||
CV_NEXT_SEQ_ELEM( elem_size, reader_from );
|
||||
}
|
||||
@@ -1814,7 +1814,7 @@ cvSeqInsertSlice( CvSeq* seq, int index, const CvArr* from_arr )
|
||||
{
|
||||
CV_PREV_SEQ_ELEM( elem_size, reader_to );
|
||||
CV_PREV_SEQ_ELEM( elem_size, reader_from );
|
||||
CV_MEMCPY_AUTO( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
memcpy( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1823,7 +1823,7 @@ cvSeqInsertSlice( CvSeq* seq, int index, const CvArr* from_arr )
|
||||
|
||||
for( i = 0; i < from_total; i++ )
|
||||
{
|
||||
CV_MEMCPY_AUTO( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
memcpy( reader_to.ptr, reader_from.ptr, elem_size );
|
||||
CV_NEXT_SEQ_ELEM( elem_size, reader_to );
|
||||
CV_NEXT_SEQ_ELEM( elem_size, reader_from );
|
||||
}
|
||||
@@ -2525,7 +2525,7 @@ cvSetAdd( CvSet* set, CvSetElem* element, CvSetElem** inserted_element )
|
||||
|
||||
id = free_elem->flags & CV_SET_ELEM_IDX_MASK;
|
||||
if( element )
|
||||
CV_MEMCPY_INT( free_elem, element, (size_t)set->elem_size/sizeof(int) );
|
||||
memcpy( free_elem, element, set->elem_size );
|
||||
|
||||
free_elem->flags = id;
|
||||
set->active_count++;
|
||||
@@ -2616,8 +2616,7 @@ cvGraphAddVtx( CvGraph* graph, const CvGraphVtx* _vertex, CvGraphVtx** _inserted
|
||||
if( vertex )
|
||||
{
|
||||
if( _vertex )
|
||||
CV_MEMCPY_INT( vertex + 1, _vertex + 1,
|
||||
(size_t)(graph->elem_size - sizeof(CvGraphVtx))/sizeof(int) );
|
||||
memcpy( vertex + 1, _vertex + 1, graph->elem_size - sizeof(CvGraphVtx) );
|
||||
vertex->first = 0;
|
||||
index = vertex->flags;
|
||||
}
|
||||
@@ -2784,17 +2783,17 @@ cvGraphAddEdgeByPtr( CvGraph* graph,
|
||||
edge->next[1] = end_vtx->first;
|
||||
start_vtx->first = end_vtx->first = edge;
|
||||
|
||||
delta = (graph->edges->elem_size - sizeof(*edge))/sizeof(int);
|
||||
delta = graph->edges->elem_size - sizeof(*edge);
|
||||
if( _edge )
|
||||
{
|
||||
if( delta > 0 )
|
||||
CV_MEMCPY_INT( edge + 1, _edge + 1, delta );
|
||||
memcpy( edge + 1, _edge + 1, delta );
|
||||
edge->weight = _edge->weight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( delta > 0 )
|
||||
CV_ZERO_INT( edge + 1, delta );
|
||||
memset( edge + 1, 0, delta );
|
||||
edge->weight = 1.f;
|
||||
}
|
||||
|
||||
@@ -3548,14 +3547,14 @@ KDTree::KDTree()
|
||||
normType = NORM_L2;
|
||||
}
|
||||
|
||||
KDTree::KDTree(const Mat& _points, bool _copyData)
|
||||
KDTree::KDTree(const InputArray& _points, bool _copyData)
|
||||
{
|
||||
maxDepth = -1;
|
||||
normType = NORM_L2;
|
||||
build(_points, _copyData);
|
||||
}
|
||||
|
||||
KDTree::KDTree(const Mat& _points, const Mat& _labels, bool _copyData)
|
||||
KDTree::KDTree(const InputArray& _points, const InputArray& _labels, bool _copyData)
|
||||
{
|
||||
maxDepth = -1;
|
||||
normType = NORM_L2;
|
||||
@@ -3638,14 +3637,15 @@ computeSums( const Mat& points, const size_t* ofs, int a, int b, double* sums )
|
||||
}
|
||||
|
||||
|
||||
void KDTree::build(const Mat& _points, bool _copyData)
|
||||
void KDTree::build(const InputArray& _points, bool _copyData)
|
||||
{
|
||||
build(_points, Mat(), _copyData);
|
||||
build(_points, InputArray(), _copyData);
|
||||
}
|
||||
|
||||
|
||||
void KDTree::build(const Mat& _points, const Mat& _labels, bool _copyData)
|
||||
void KDTree::build(const InputArray& __points, const InputArray& __labels, bool _copyData)
|
||||
{
|
||||
Mat _points = __points.getMat(), _labels = __labels.getMat();
|
||||
CV_Assert(_points.type() == CV_32F && !_points.empty());
|
||||
vector<KDTree::Node>().swap(nodes);
|
||||
|
||||
@@ -3744,57 +3744,6 @@ void KDTree::build(const Mat& _points, const Mat& _labels, bool _copyData)
|
||||
}
|
||||
|
||||
|
||||
int KDTree::findNearest(const float* vec, int K, int emax,
|
||||
vector<int>* neighborsIdx,
|
||||
Mat* neighbors,
|
||||
vector<float>* dist,
|
||||
vector<int>* labels) const
|
||||
{
|
||||
K = std::min(K, points.rows);
|
||||
CV_Assert(K > 0);
|
||||
if(neighborsIdx)
|
||||
neighborsIdx->resize(K);
|
||||
if(dist)
|
||||
dist->resize(K);
|
||||
if(labels)
|
||||
labels->resize(K);
|
||||
K = findNearest(vec, K, emax, neighborsIdx ? &(*neighborsIdx)[0] : 0,
|
||||
neighbors, dist ? &(*dist)[0] : 0, labels ? &(*labels)[0] : 0);
|
||||
if(neighborsIdx)
|
||||
neighborsIdx->resize(K);
|
||||
if(dist)
|
||||
dist->resize(K);
|
||||
if(labels)
|
||||
labels->resize(K);
|
||||
return K;
|
||||
}
|
||||
|
||||
int KDTree::findNearest(const vector<float>& vec, int K, int emax,
|
||||
vector<int>* neighborsIdx,
|
||||
Mat* neighbors,
|
||||
vector<float>* dist,
|
||||
vector<int>* labels) const
|
||||
{
|
||||
CV_Assert((int)vec.size() == points.cols);
|
||||
K = std::min(K, points.rows);
|
||||
CV_Assert(K > 0);
|
||||
if(neighborsIdx)
|
||||
neighborsIdx->resize(K);
|
||||
if(dist)
|
||||
dist->resize(K);
|
||||
if(labels)
|
||||
labels->resize(K);
|
||||
K = findNearest(&vec[0], K, emax, neighborsIdx ? &(*neighborsIdx)[0] : 0,
|
||||
neighbors, dist ? &(*dist)[0] : 0, labels ? &(*labels)[0] : 0);
|
||||
if(neighborsIdx)
|
||||
neighborsIdx->resize(K);
|
||||
if(dist)
|
||||
dist->resize(K);
|
||||
if(labels)
|
||||
labels->resize(K);
|
||||
return K;
|
||||
}
|
||||
|
||||
struct PQueueElem
|
||||
{
|
||||
PQueueElem() : dist(0), idx(0) {}
|
||||
@@ -3804,11 +3753,14 @@ struct PQueueElem
|
||||
};
|
||||
|
||||
|
||||
int KDTree::findNearest(const float* vec, int K, int emax,
|
||||
int* _neighborsIdx, Mat* _neighbors,
|
||||
float* _dist, int* _labels) const
|
||||
int KDTree::findNearest(const InputArray& _vec, int K, int emax,
|
||||
OutputArray _neighborsIdx, OutputArray _neighbors,
|
||||
OutputArray _dist, OutputArray _labels) const
|
||||
|
||||
{
|
||||
Mat vecmat = _vec.getMat();
|
||||
CV_Assert( vecmat.isContinuous() && vecmat.type() == CV_32F && vecmat.total() == (size_t)points.cols );
|
||||
const float* vec = vecmat.ptr<float>();
|
||||
K = std::min(K, points.rows);
|
||||
int dims = points.cols;
|
||||
|
||||
@@ -3929,42 +3881,43 @@ int KDTree::findNearest(const float* vec, int K, int emax,
|
||||
}
|
||||
|
||||
K = std::min(K, ncount);
|
||||
if( _neighborsIdx )
|
||||
if( _neighborsIdx.needed() )
|
||||
{
|
||||
for( i = 0; i < K; i++ )
|
||||
_neighborsIdx[i] = idx[i];
|
||||
}
|
||||
if( _dist )
|
||||
{
|
||||
for( i = 0; i < K; i++ )
|
||||
_dist[i] = std::sqrt(dist[i]);
|
||||
}
|
||||
if( _labels )
|
||||
{
|
||||
for( i = 0; i < K; i++ )
|
||||
_labels[i] = labels[idx[i]];
|
||||
_neighborsIdx.create(K, 1, CV_32S, -1, true);
|
||||
Mat nidx = _neighborsIdx.getMat();
|
||||
Mat(nidx.size(), CV_32S, &idx[0]).copyTo(nidx);
|
||||
}
|
||||
if( _dist.needed() )
|
||||
sqrt(Mat(K, 1, CV_32F, dist), _dist);
|
||||
|
||||
if( _neighbors )
|
||||
getPoints(idx, K, *_neighbors);
|
||||
if( _neighbors.needed() || _labels.needed() )
|
||||
getPoints(Mat(K, 1, CV_32S, idx), _neighbors, _labels);
|
||||
return K;
|
||||
}
|
||||
|
||||
|
||||
void KDTree::findOrthoRange(const float* L, const float* R,
|
||||
vector<int>* neighborsIdx,
|
||||
Mat* neighbors, vector<int>* _labels) const
|
||||
void KDTree::findOrthoRange(const InputArray& _lowerBound,
|
||||
const InputArray& _upperBound,
|
||||
OutputArray _neighborsIdx,
|
||||
OutputArray _neighbors,
|
||||
OutputArray _labels ) const
|
||||
{
|
||||
int dims = points.cols;
|
||||
Mat lowerBound = _lowerBound.getMat(), upperBound = _upperBound.getMat();
|
||||
CV_Assert( lowerBound.size == upperBound.size &&
|
||||
lowerBound.isContinuous() &&
|
||||
upperBound.isContinuous() &&
|
||||
lowerBound.type() == upperBound.type() &&
|
||||
lowerBound.type() == CV_32F &&
|
||||
lowerBound.total() == (size_t)dims );
|
||||
const float* L = lowerBound.ptr<float>();
|
||||
const float* R = upperBound.ptr<float>();
|
||||
|
||||
CV_Assert( L && R );
|
||||
|
||||
vector<int> _idx, *idx = neighborsIdx ? neighborsIdx : &_idx;
|
||||
vector<int> idx;
|
||||
AutoBuffer<int> _stack(MAX_TREE_DEPTH*2 + 1);
|
||||
int* stack = _stack;
|
||||
int top = 0;
|
||||
|
||||
idx->clear();
|
||||
stack[top++] = 0;
|
||||
|
||||
while( --top >= 0 )
|
||||
@@ -3981,7 +3934,7 @@ void KDTree::findOrthoRange(const float* L, const float* R,
|
||||
if( row[j] < L[j] || row[j] >= R[j] )
|
||||
break;
|
||||
if( j == dims )
|
||||
idx->push_back(i);
|
||||
idx.push_back(i);
|
||||
continue;
|
||||
}
|
||||
if( L[n.idx] <= n.boundary )
|
||||
@@ -3990,55 +3943,57 @@ void KDTree::findOrthoRange(const float* L, const float* R,
|
||||
stack[top++] = n.right;
|
||||
}
|
||||
|
||||
if( neighbors )
|
||||
getPoints( &(*idx)[0], idx->size(), *neighbors, _labels );
|
||||
}
|
||||
|
||||
|
||||
void KDTree::findOrthoRange(const vector<float>& L, const vector<float>& R,
|
||||
vector<int>* neighborsIdx, Mat* neighbors, vector<int>* _labels) const
|
||||
{
|
||||
size_t dims = points.cols;
|
||||
CV_Assert(L.size() == dims && R.size() == dims);
|
||||
findOrthoRange(&L[0], &R[0], neighborsIdx, neighbors, _labels);
|
||||
}
|
||||
|
||||
|
||||
void KDTree::getPoints(const int* idx, size_t nidx, Mat& pts, vector<int>* _labels) const
|
||||
{
|
||||
int dims = points.cols, n = (int)nidx;
|
||||
pts.create( n, dims, points.type());
|
||||
if(_labels)
|
||||
_labels->resize(nidx);
|
||||
|
||||
for( int i = 0; i < n; i++ )
|
||||
if( _neighborsIdx.needed() )
|
||||
{
|
||||
int k = idx[i];
|
||||
CV_Assert( (unsigned)k < (unsigned)points.rows );
|
||||
const float* src = points.ptr<float>(k);
|
||||
std::copy(src, src + dims, pts.ptr<float>(i));
|
||||
if(_labels)
|
||||
(*_labels)[i] = labels[k];
|
||||
_neighborsIdx.create(idx.size(), 1, CV_32S, -1, true);
|
||||
Mat nidx = _neighborsIdx.getMat();
|
||||
Mat(nidx.size(), CV_32S, &idx[0]).copyTo(nidx);
|
||||
}
|
||||
getPoints( idx, _neighbors, _labels );
|
||||
}
|
||||
|
||||
|
||||
void KDTree::getPoints(const vector<int>& idx, Mat& pts, vector<int>* _labels) const
|
||||
{
|
||||
int dims = points.cols;
|
||||
int i, nidx = (int)idx.size();
|
||||
pts.create( nidx, dims, points.type());
|
||||
|
||||
if(_labels)
|
||||
_labels->resize(nidx);
|
||||
void KDTree::getPoints(const InputArray& _idx, OutputArray _pts, OutputArray _labels) const
|
||||
{
|
||||
Mat idxmat = _idx.getMat(), pts, labelsmat;
|
||||
CV_Assert( idxmat.isContinuous() && idxmat.type() == CV_32S &&
|
||||
(idxmat.cols == 1 || idxmat.rows == 1) );
|
||||
const int* idx = idxmat.ptr<int>();
|
||||
int* dstlabels = 0;
|
||||
|
||||
int dims = points.cols;
|
||||
int i, nidx = (int)idxmat.total();
|
||||
if( nidx == 0 )
|
||||
{
|
||||
_pts.release();
|
||||
_labels.release();
|
||||
return;
|
||||
}
|
||||
|
||||
if( _pts.needed() )
|
||||
{
|
||||
_pts.create( nidx, dims, points.type());
|
||||
pts = _pts.getMat();
|
||||
}
|
||||
|
||||
if(_labels.needed())
|
||||
{
|
||||
_labels.create(nidx, 1, CV_32S, -1, true);
|
||||
labelsmat = _labels.getMat();
|
||||
CV_Assert( labelsmat.isContinuous() );
|
||||
dstlabels = labelsmat.ptr<int>();
|
||||
}
|
||||
const int* srclabels = !labels.empty() ? &labels[0] : 0;
|
||||
|
||||
for( i = 0; i < nidx; i++ )
|
||||
{
|
||||
int k = idx[i];
|
||||
CV_Assert( (unsigned)k < (unsigned)points.rows );
|
||||
const float* src = points.ptr<float>(k);
|
||||
std::copy(src, src + dims, pts.ptr<float>(i));
|
||||
if(_labels) (*_labels)[i] = labels[k];
|
||||
if( pts.data )
|
||||
std::copy(src, src + dims, pts.ptr<float>(i));
|
||||
if( dstlabels )
|
||||
dstlabels[i] = srclabels ? srclabels[k] : k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4047,7 +4002,7 @@ const float* KDTree::getPoint(int ptidx, int* label) const
|
||||
{
|
||||
CV_Assert( (unsigned)ptidx < (unsigned)points.rows);
|
||||
if(label)
|
||||
*label = label[ptidx];
|
||||
*label = labels[ptidx];
|
||||
return points.ptr<float>(ptidx);
|
||||
}
|
||||
|
||||
|
@@ -235,7 +235,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2,
|
||||
|
||||
static void
|
||||
Line( Mat& img, Point pt1, Point pt2,
|
||||
const void* color, int connectivity = 8 )
|
||||
const void* _color, int connectivity = 8 )
|
||||
{
|
||||
if( connectivity == 0 )
|
||||
connectivity = 8;
|
||||
@@ -245,10 +245,21 @@ Line( Mat& img, Point pt1, Point pt2,
|
||||
LineIterator iterator(img, pt1, pt2, connectivity, true);
|
||||
int i, count = iterator.count;
|
||||
int pix_size = (int)img.elemSize();
|
||||
const uchar* color = (const uchar*)_color;
|
||||
|
||||
for( i = 0; i < count; i++, ++iterator )
|
||||
{
|
||||
CV_MEMCPY_AUTO( *iterator, color, pix_size );
|
||||
uchar* ptr = *iterator;
|
||||
if( pix_size == 1 )
|
||||
ptr[0] = color[0];
|
||||
else if( pix_size == 3 )
|
||||
{
|
||||
ptr[0] = color[0];
|
||||
ptr[1] = color[1];
|
||||
ptr[2] = color[2];
|
||||
}
|
||||
else
|
||||
memcpy( *iterator, color, pix_size );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1317,7 +1328,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
|
||||
center.y >= radius && center.y < size.height - radius;
|
||||
|
||||
#define ICV_PUT_POINT( ptr, x ) \
|
||||
CV_MEMCPY_CHAR( ptr + (x)*pix_size, color, pix_size );
|
||||
memcpy( ptr + (x)*pix_size, color, pix_size );
|
||||
|
||||
while( dx >= dy )
|
||||
{
|
||||
|
@@ -1449,27 +1449,25 @@ static void CCSIDFT_64f( const double* src, double* dst, int n, int nf, int* fac
|
||||
CCSIDFT( src, dst, n, nf, factors, itab, wave, tab_size, spec, buf, flags, scale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void dft( const Mat& src0, Mat& dst, int flags, int nonzero_rows )
|
||||
void cv::dft( const InputArray& _src0, OutputArray _dst, int flags, int nonzero_rows )
|
||||
{
|
||||
static DFTFunc dft_tbl[6];
|
||||
static int inittab = 0;
|
||||
|
||||
if( !inittab )
|
||||
static DFTFunc dft_tbl[6] =
|
||||
{
|
||||
dft_tbl[0] = (DFTFunc)DFT_32f;
|
||||
dft_tbl[1] = (DFTFunc)RealDFT_32f;
|
||||
dft_tbl[2] = (DFTFunc)CCSIDFT_32f;
|
||||
dft_tbl[3] = (DFTFunc)DFT_64f;
|
||||
dft_tbl[4] = (DFTFunc)RealDFT_64f;
|
||||
dft_tbl[5] = (DFTFunc)CCSIDFT_64f;
|
||||
inittab = 1;
|
||||
}
|
||||
(DFTFunc)DFT_32f,
|
||||
(DFTFunc)RealDFT_32f,
|
||||
(DFTFunc)CCSIDFT_32f,
|
||||
(DFTFunc)DFT_64f,
|
||||
(DFTFunc)RealDFT_64f,
|
||||
(DFTFunc)CCSIDFT_64f
|
||||
};
|
||||
|
||||
AutoBuffer<uchar> buf;
|
||||
void *spec = 0;
|
||||
|
||||
Mat src = src0;
|
||||
Mat src0 = _src0.getMat(), src = src0;
|
||||
int prev_len = 0, stage = 0;
|
||||
bool inv = (flags & DFT_INVERSE) != 0;
|
||||
int nf = 0, real_transform = src.channels() == 1 || (inv && (flags & DFT_REAL_OUTPUT)!=0);
|
||||
@@ -1485,11 +1483,13 @@ void dft( const Mat& src0, Mat& dst, int flags, int nonzero_rows )
|
||||
CV_Assert( type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 );
|
||||
|
||||
if( !inv && src.channels() == 1 && (flags & DFT_COMPLEX_OUTPUT) )
|
||||
dst.create( src.size(), CV_MAKETYPE(depth, 2) );
|
||||
_dst.create( src.size(), CV_MAKETYPE(depth, 2) );
|
||||
else if( inv && src.channels() == 2 && (flags & DFT_REAL_OUTPUT) )
|
||||
dst.create( src.size(), depth );
|
||||
_dst.create( src.size(), depth );
|
||||
else
|
||||
dst.create( src.size(), type );
|
||||
_dst.create( src.size(), type );
|
||||
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
if( !real_transform )
|
||||
elem_size = complex_elem_size;
|
||||
@@ -1840,14 +1840,15 @@ void dft( const Mat& src0, Mat& dst, int flags, int nonzero_rows )
|
||||
}
|
||||
|
||||
|
||||
void idft( const Mat& src, Mat& dst, int flags, int nonzero_rows )
|
||||
void cv::idft( const InputArray& src, OutputArray dst, int flags, int nonzero_rows )
|
||||
{
|
||||
dft( src, dst, flags | DFT_INVERSE, nonzero_rows );
|
||||
}
|
||||
|
||||
void mulSpectrums( const Mat& srcA, const Mat& srcB,
|
||||
Mat& dst, int flags, bool conjB )
|
||||
void cv::mulSpectrums( const InputArray& _srcA, const InputArray& _srcB,
|
||||
OutputArray _dst, int flags, bool conjB )
|
||||
{
|
||||
Mat srcA = _srcA.getMat(), srcB = _srcB.getMat();
|
||||
int depth = srcA.depth(), cn = srcA.channels(), type = srcA.type();
|
||||
int rows = srcA.rows, cols = srcA.cols;
|
||||
int j, k;
|
||||
@@ -1855,7 +1856,8 @@ void mulSpectrums( const Mat& srcA, const Mat& srcB,
|
||||
CV_Assert( type == srcB.type() && srcA.size() == srcB.size() );
|
||||
CV_Assert( type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 );
|
||||
|
||||
dst.create( srcA.rows, srcA.cols, type );
|
||||
_dst.create( srcA.rows, srcA.cols, type );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
bool is_1d = (flags & DFT_ROWS) || (rows == 1 || (cols == 1 &&
|
||||
srcA.isContinuous() && srcB.isContinuous() && dst.isContinuous()));
|
||||
@@ -2008,6 +2010,9 @@ void mulSpectrums( const Mat& srcA, const Mat& srcB,
|
||||
Discrete Cosine Transform
|
||||
\****************************************************************************************/
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
/* DCT is calculated using DFT, as described here:
|
||||
http://www.ece.utexas.edu/~bevans/courses/ee381k/lectures/09_DCT/lecture9/:
|
||||
*/
|
||||
@@ -2210,23 +2215,21 @@ static void IDCT_64f(const double* src, int src_step, double* dft_src, double* d
|
||||
IDCT(src, src_step, dft_src, dft_dst, dst, dst_step,
|
||||
n, nf, factors, itab, dft_wave, dct_wave, spec, buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void dct( const Mat& src0, Mat& dst, int flags )
|
||||
void cv::dct( const InputArray& _src0, OutputArray _dst, int flags )
|
||||
{
|
||||
static DCTFunc dct_tbl[4];
|
||||
static int inittab = 0;
|
||||
|
||||
if( !inittab )
|
||||
static DCTFunc dct_tbl[4] =
|
||||
{
|
||||
dct_tbl[0] = (DCTFunc)DCT_32f;
|
||||
dct_tbl[1] = (DCTFunc)IDCT_32f;
|
||||
dct_tbl[2] = (DCTFunc)DCT_64f;
|
||||
dct_tbl[3] = (DCTFunc)IDCT_64f;
|
||||
inittab = 1;
|
||||
}
|
||||
(DCTFunc)DCT_32f,
|
||||
(DCTFunc)IDCT_32f,
|
||||
(DCTFunc)DCT_64f,
|
||||
(DCTFunc)IDCT_64f
|
||||
};
|
||||
|
||||
bool inv = (flags & DCT_INVERSE) != 0;
|
||||
Mat src = src0;
|
||||
Mat src0 = _src0.getMat(), src = src0;
|
||||
int type = src.type(), depth = src.depth();
|
||||
void /* *spec_dft = 0, */ *spec = 0;
|
||||
|
||||
@@ -2242,7 +2245,8 @@ void dct( const Mat& src0, Mat& dst, int flags )
|
||||
AutoBuffer<uchar> buf;
|
||||
|
||||
CV_Assert( type == CV_32FC1 || type == CV_64FC1 );
|
||||
dst.create( src.rows, src.cols, type );
|
||||
_dst.create( src.rows, src.cols, type );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
DCTFunc dct_func = dct_tbl[inv + (depth == CV_64F)*2];
|
||||
|
||||
@@ -2369,11 +2373,14 @@ void dct( const Mat& src0, Mat& dst, int flags )
|
||||
}
|
||||
|
||||
|
||||
void idct( const Mat& src, Mat& dst, int flags )
|
||||
void cv::idct( const InputArray& src, OutputArray dst, int flags )
|
||||
{
|
||||
dct( src, dst, flags | DCT_INVERSE );
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
static const int optimalDFTSizeTab[] = {
|
||||
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40, 45, 48,
|
||||
50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125, 128, 135, 144, 150, 160,
|
||||
@@ -2555,8 +2562,9 @@ static const int optimalDFTSizeTab[] = {
|
||||
2097152000, 2099520000, 2109375000, 2123366400, 2125764000
|
||||
};
|
||||
|
||||
int
|
||||
getOptimalDFTSize( int size0 )
|
||||
}
|
||||
|
||||
int cv::getOptimalDFTSize( int size0 )
|
||||
{
|
||||
int a = 0, b = sizeof(optimalDFTSizeTab)/sizeof(optimalDFTSizeTab[0]) - 1;
|
||||
if( (unsigned)size0 >= (unsigned)optimalDFTSizeTab[b] )
|
||||
@@ -2574,8 +2582,6 @@ getOptimalDFTSize( int size0 )
|
||||
return optimalDFTSizeTab[b];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CV_IMPL void
|
||||
cvDFT( const CvArr* srcarr, CvArr* dstarr, int flags, int nonzero_rows )
|
||||
{
|
||||
|
@@ -212,6 +212,8 @@ bool Cholesky(double* A, int m, double* b, int n)
|
||||
{
|
||||
return CholImpl(A, m, b, n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* Determinant of the matrix *
|
||||
@@ -222,8 +224,9 @@ bool Cholesky(double* A, int m, double* b, int n)
|
||||
m(0,1)*((double)m(1,0)*m(2,2) - (double)m(1,2)*m(2,0)) + \
|
||||
m(0,2)*((double)m(1,0)*m(2,1) - (double)m(1,1)*m(2,0)))
|
||||
|
||||
double determinant( const Mat& mat )
|
||||
double cv::determinant( const InputArray& _mat )
|
||||
{
|
||||
Mat mat = _mat.getMat();
|
||||
double result = 0;
|
||||
int type = mat.type(), rows = mat.rows;
|
||||
size_t step = mat.step;
|
||||
@@ -325,13 +328,16 @@ double determinant( const Mat& mat )
|
||||
#define Df( y, x ) ((float*)(dstdata + y*dststep))[x]
|
||||
#define Dd( y, x ) ((double*)(dstdata + y*dststep))[x]
|
||||
|
||||
double invert( const Mat& src, Mat& dst, int method )
|
||||
double cv::invert( const InputArray& _src, OutputArray _dst, int method )
|
||||
{
|
||||
double result = 0;
|
||||
Mat src = _src.getMat();
|
||||
int type = src.type();
|
||||
|
||||
CV_Assert( method == DECOMP_LU || method == DECOMP_CHOLESKY || method == DECOMP_SVD );
|
||||
|
||||
_dst.create( src.cols, src.rows, type );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
if( method == DECOMP_SVD )
|
||||
{
|
||||
int n = std::min(src.rows, src.cols);
|
||||
@@ -346,8 +352,7 @@ double invert( const Mat& src, Mat& dst, int method )
|
||||
}
|
||||
|
||||
CV_Assert( src.rows == src.cols && (type == CV_32F || type == CV_64F));
|
||||
dst.create( src.rows, src.cols, type );
|
||||
|
||||
|
||||
if( src.rows <= 3 )
|
||||
{
|
||||
uchar* srcdata = src.data;
|
||||
@@ -572,9 +577,10 @@ double invert( const Mat& src, Mat& dst, int method )
|
||||
* Solving a linear system *
|
||||
\****************************************************************************************/
|
||||
|
||||
bool solve( const Mat& src, const Mat& _src2, Mat& dst, int method )
|
||||
bool cv::solve( const InputArray& _src, const InputArray& _src2arg, OutputArray _dst, int method )
|
||||
{
|
||||
bool result = true;
|
||||
Mat src = _src.getMat(), _src2 = _src2arg.getMat();
|
||||
int type = src.type();
|
||||
bool is_normal = (method & DECOMP_NORMAL) != 0;
|
||||
|
||||
@@ -588,7 +594,8 @@ bool solve( const Mat& src, const Mat& _src2, Mat& dst, int method )
|
||||
if( (method == DECOMP_LU || method == DECOMP_CHOLESKY) &&
|
||||
src.rows <= 3 && src.rows == src.cols && _src2.cols == 1 )
|
||||
{
|
||||
dst.create( src.cols, _src2.cols, src.type() );
|
||||
_dst.create( src.cols, _src2.cols, src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
#define bf(y) ((float*)(bdata + y*src2step))[0]
|
||||
#define bd(y) ((double*)(bdata + y*src2step))[0]
|
||||
@@ -729,7 +736,8 @@ bool solve( const Mat& src, const Mat& _src2, Mat& dst, int method )
|
||||
char N[] = {'N', '\0'}, L[] = {'L', '\0'};
|
||||
|
||||
Mat src2 = _src2;
|
||||
dst.create( src.cols, src2.cols, src.type() );
|
||||
_dst.create( src.cols, src2.cols, src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
if( m <= n )
|
||||
is_normal = false;
|
||||
@@ -905,6 +913,9 @@ bool solve( const Mat& src, const Mat& _src2, Mat& dst, int method )
|
||||
|
||||
/////////////////// finding eigenvalues and eigenvectors of a symmetric matrix ///////////////
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<typename Real> static inline Real hypot(Real a, Real b)
|
||||
{
|
||||
a = std::abs(a);
|
||||
@@ -1077,9 +1088,10 @@ template<typename Real> bool jacobi(const Mat& _S0, Mat& _e, Mat& matE, bool com
|
||||
}
|
||||
|
||||
|
||||
static bool eigen( const Mat& src, Mat& evals, Mat& evects, bool computeEvects,
|
||||
static bool eigen( const InputArray& _src, OutputArray _evals, OutputArray _evects, bool computeEvects,
|
||||
int lowindex, int highindex )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
int type = src.type();
|
||||
integer n = src.rows;
|
||||
|
||||
@@ -1094,9 +1106,14 @@ static bool eigen( const Mat& src, Mat& evals, Mat& evects, bool computeEvects,
|
||||
CV_Assert( src.rows == src.cols );
|
||||
CV_Assert (type == CV_32F || type == CV_64F);
|
||||
|
||||
// allow for 1xn eigenvalue matrix too
|
||||
if( !(evals.rows == 1 && evals.cols == n && evals.type() == type) )
|
||||
evals.create(n, 1, type);
|
||||
_evals.create(n, 1, type, -1, true);
|
||||
Mat evals = _evals.getMat(), evects;
|
||||
|
||||
if( computeEvects )
|
||||
{
|
||||
_evects.create(n, n, type);
|
||||
evects = _evects.getMat();
|
||||
}
|
||||
|
||||
if( n <= 20 )
|
||||
{
|
||||
@@ -1122,10 +1139,7 @@ static bool eigen( const Mat& src, Mat& evals, Mat& evects, bool computeEvects,
|
||||
lda = (int)(src.step/elem_size);
|
||||
|
||||
if( computeEvects )
|
||||
{
|
||||
evects.create(n, n, type);
|
||||
ldv = (int)(evects.step/elem_size);
|
||||
}
|
||||
|
||||
bool copy_evals = !evals.isContinuous();
|
||||
|
||||
@@ -1211,19 +1225,21 @@ static bool eigen( const Mat& src, Mat& evals, Mat& evects, bool computeEvects,
|
||||
return result;
|
||||
}
|
||||
|
||||
bool eigen( const Mat& src, Mat& evals, int lowindex, int highindex )
|
||||
}
|
||||
|
||||
bool cv::eigen( const InputArray& src, OutputArray evals, int lowindex, int highindex )
|
||||
{
|
||||
Mat evects;
|
||||
return eigen(src, evals, evects, false, lowindex, highindex);
|
||||
return eigen(src, evals, OutputArray(), false, lowindex, highindex);
|
||||
}
|
||||
|
||||
bool eigen( const Mat& src, Mat& evals, Mat& evects, int lowindex,
|
||||
int highindex )
|
||||
bool cv::eigen( const InputArray& src, OutputArray evals, OutputArray evects,
|
||||
int lowindex, int highindex )
|
||||
{
|
||||
return eigen(src, evals, evects, true, lowindex, highindex);
|
||||
}
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
/* y[0:m,0:n] += diag(a[0:1,0:m]) * x[0:m,0:n] */
|
||||
template<typename T1, typename T2, typename T3> static void
|
||||
@@ -1316,29 +1332,33 @@ SVBkSb( int m, int n, const T* w, int incw,
|
||||
}
|
||||
|
||||
|
||||
static void _SVDcompute( const Mat& a, Mat& w, Mat* u, Mat* vt, int flags )
|
||||
static void _SVDcompute( const InputArray& _aarr, OutputArray _w,
|
||||
OutputArray _u, OutputArray _vt, int flags )
|
||||
{
|
||||
Mat a = _aarr.getMat(), u, vt;
|
||||
integer m = a.rows, n = a.cols, mn = std::max(m, n), nm = std::min(m, n);
|
||||
int type = a.type(), elem_size = (int)a.elemSize();
|
||||
bool compute_uv = u && vt;
|
||||
bool compute_uv = _u.needed() || _vt.needed();
|
||||
|
||||
if( flags & SVD::NO_UV )
|
||||
{
|
||||
if(u) u->release();
|
||||
if(vt) vt->release();
|
||||
u = vt = 0;
|
||||
_u.release();
|
||||
_vt.release();
|
||||
compute_uv = false;
|
||||
}
|
||||
|
||||
if( compute_uv )
|
||||
{
|
||||
u->create( (int)m, (int)((flags & SVD::FULL_UV) ? m : nm), type );
|
||||
vt->create( (int)((flags & SVD::FULL_UV) ? n : nm), n, type );
|
||||
_u.create( (int)m, (int)((flags & SVD::FULL_UV) ? m : nm), type );
|
||||
_vt.create( (int)((flags & SVD::FULL_UV) ? n : nm), n, type );
|
||||
u = _u.getMat();
|
||||
vt = _vt.getMat();
|
||||
}
|
||||
|
||||
w.create(nm, 1, type);
|
||||
_w.create(nm, 1, type, -1, true);
|
||||
|
||||
Mat _a = a;
|
||||
Mat _a = a, w = _w.getMat();
|
||||
CV_Assert( w.isContinuous() );
|
||||
int a_ofs = 0, work_ofs=0, iwork_ofs=0, buf_size = 0;
|
||||
bool temp_a = false;
|
||||
double u1=0, v1=0, work1=0;
|
||||
@@ -1353,7 +1373,7 @@ static void _SVDcompute( const Mat& a, Mat& w, Mat* u, Mat* vt, int flags )
|
||||
{
|
||||
if( mode[0] == 'N' || mode[0] == 'A' )
|
||||
temp_a = true;
|
||||
else if( compute_uv && (a.size() == vt->size() || a.size() == u->size()) && mode[0] == 'S' )
|
||||
else if( compute_uv && (a.size() == vt.size() || a.size() == u.size()) && mode[0] == 'S' )
|
||||
mode[0] = 'O';
|
||||
}
|
||||
|
||||
@@ -1396,59 +1416,67 @@ static void _SVDcompute( const Mat& a, Mat& w, Mat* u, Mat* vt, int flags )
|
||||
|
||||
if( !(flags & SVD::MODIFY_A) && !temp_a )
|
||||
{
|
||||
if( compute_uv && a.size() == vt->size() )
|
||||
if( compute_uv && a.size() == vt.size() )
|
||||
{
|
||||
a.copyTo(*vt);
|
||||
_a = *vt;
|
||||
a.copyTo(vt);
|
||||
_a = vt;
|
||||
}
|
||||
else if( compute_uv && a.size() == u->size() )
|
||||
else if( compute_uv && a.size() == u.size() )
|
||||
{
|
||||
a.copyTo(*u);
|
||||
_a = *u;
|
||||
a.copyTo(u);
|
||||
_a = u;
|
||||
}
|
||||
}
|
||||
|
||||
if( compute_uv )
|
||||
{
|
||||
ldv = (int)(vt->step ? vt->step/elem_size : vt->cols);
|
||||
ldu = (int)(u->step ? u->step/elem_size : u->cols);
|
||||
ldv = (int)(vt.step ? vt.step/elem_size : vt.cols);
|
||||
ldu = (int)(u.step ? u.step/elem_size : u.cols);
|
||||
}
|
||||
|
||||
lda = (int)(_a.step ? _a.step/elem_size : _a.cols);
|
||||
if( type == CV_32F )
|
||||
{
|
||||
sgesdd_(mode, &n, &m, (float*)_a.data, &lda, (float*)w.data,
|
||||
vt ? (float*)vt->data : (float*)&v1, &ldv, u ? (float*)u->data : (float*)&u1, &ldu,
|
||||
(float*)(buffer + work_ofs), &lwork, (integer*)(buffer + iwork_ofs), &info );
|
||||
sgesdd_(mode, &n, &m, _a.ptr<float>(), &lda, w.ptr<float>(),
|
||||
vt.data ? vt.ptr<float>() : (float*)&v1, &ldv,
|
||||
u.data ? u.ptr<float>() : (float*)&u1, &ldu,
|
||||
(float*)(buffer + work_ofs), &lwork,
|
||||
(integer*)(buffer + iwork_ofs), &info );
|
||||
}
|
||||
else
|
||||
{
|
||||
dgesdd_(mode, &n, &m, (double*)_a.data, &lda, (double*)w.data,
|
||||
vt ? (double*)vt->data : &v1, &ldv, u ? (double*)u->data : &u1, &ldu,
|
||||
(double*)(buffer + work_ofs), &lwork, (integer*)(buffer + iwork_ofs), &info );
|
||||
dgesdd_(mode, &n, &m, _a.ptr<double>(), &lda, w.ptr<double>(),
|
||||
vt.data ? vt.ptr<double>() : &v1, &ldv,
|
||||
u.data ? u.ptr<double>() : &u1, &ldu,
|
||||
(double*)(buffer + work_ofs), &lwork,
|
||||
(integer*)(buffer + iwork_ofs), &info );
|
||||
}
|
||||
CV_Assert(info >= 0);
|
||||
if(info != 0)
|
||||
{
|
||||
*u = Scalar(0.);
|
||||
*vt = Scalar(0.);
|
||||
if( u.data )
|
||||
u = Scalar(0.);
|
||||
if( vt.data )
|
||||
vt = Scalar(0.);
|
||||
w = Scalar(0.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SVD::compute( const Mat& a, Mat& w, Mat& u, Mat& vt, int flags )
|
||||
void SVD::compute( const InputArray& a, OutputArray w, OutputArray u, OutputArray vt, int flags )
|
||||
{
|
||||
_SVDcompute(a, w, &u, &vt, flags);
|
||||
_SVDcompute(a, w, u, vt, flags);
|
||||
}
|
||||
|
||||
void SVD::compute( const Mat& a, Mat& w, int flags )
|
||||
void SVD::compute( const InputArray& a, OutputArray w, int flags )
|
||||
{
|
||||
_SVDcompute(a, w, 0, 0, flags);
|
||||
_SVDcompute(a, w, OutputArray(), OutputArray(), flags);
|
||||
}
|
||||
|
||||
void SVD::backSubst( const Mat& w, const Mat& u, const Mat& vt, const Mat& rhs, Mat& dst )
|
||||
void SVD::backSubst( const InputArray& _w, const InputArray& _u, const InputArray& _vt,
|
||||
const InputArray& _rhs, OutputArray _dst )
|
||||
{
|
||||
Mat w = _w.getMat(), u = _u.getMat(), vt = _vt.getMat(), rhs = _rhs.getMat();
|
||||
int type = w.type(), esz = (int)w.elemSize();
|
||||
int m = u.rows, n = vt.cols, nb = rhs.data ? rhs.cols : m;
|
||||
AutoBuffer<double> buffer(nb);
|
||||
@@ -1456,7 +1484,8 @@ void SVD::backSubst( const Mat& w, const Mat& u, const Mat& vt, const Mat& rhs,
|
||||
|
||||
CV_Assert( rhs.data == 0 || (rhs.type() == type && rhs.rows == m) );
|
||||
|
||||
dst.create( n, nb, type );
|
||||
_dst.create( n, nb, type );
|
||||
Mat dst = _dst.getMat();
|
||||
if( type == CV_32F )
|
||||
SVBkSb(m, n, (float*)w.data, 1, (float*)u.data, (int)(u.step/esz), false,
|
||||
(float*)vt.data, (int)(vt.step/esz), true, (float*)rhs.data, (int)(rhs.step/esz),
|
||||
@@ -1470,14 +1499,14 @@ void SVD::backSubst( const Mat& w, const Mat& u, const Mat& vt, const Mat& rhs,
|
||||
}
|
||||
|
||||
|
||||
SVD& SVD::operator ()(const Mat& a, int flags)
|
||||
SVD& SVD::operator ()(const InputArray& a, int flags)
|
||||
{
|
||||
_SVDcompute(a, w, &u, &vt, flags);
|
||||
_SVDcompute(a, w, u, vt, flags);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void SVD::backSubst( const Mat& rhs, Mat& dst ) const
|
||||
void SVD::backSubst( const InputArray& rhs, OutputArray dst ) const
|
||||
{
|
||||
backSubst( w, u, vt, rhs, dst );
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -208,9 +208,11 @@ static inline bool isIdentity(const MatExpr& e) { return e.op == &g_MatOp_Identi
|
||||
static inline bool isAddEx(const MatExpr& e) { return e.op == &g_MatOp_AddEx; }
|
||||
static inline bool isScaled(const MatExpr& e) { return isAddEx(e) && (!e.b.data || e.beta == 0) && e.s == Scalar(); }
|
||||
static inline bool isBin(const MatExpr& e, char c) { return e.op == &g_MatOp_Bin && e.flags == c; }
|
||||
static inline bool isCmp(const MatExpr& e) { return e.op == &g_MatOp_Cmp; }
|
||||
static inline bool isReciprocal(const MatExpr& e) { return isBin(e,'/') && (!e.b.data || e.beta == 0); }
|
||||
static inline bool isT(const MatExpr& e) { return e.op == &g_MatOp_T; }
|
||||
static inline bool isInv(const MatExpr& e) { return e.op == &g_MatOp_Invert; }
|
||||
static inline bool isSolve(const MatExpr& e) { return e.op == &g_MatOp_Solve; }
|
||||
static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; }
|
||||
static inline bool isMatProd(const MatExpr& e) { return e.op == &g_MatOp_GEMM && (!e.c.data || e.beta == 0); }
|
||||
static inline bool isInitializer(const MatExpr& e) { return e.op == &g_MatOp_Initializer; }
|
||||
@@ -571,7 +573,18 @@ void MatOp::invert(const MatExpr& expr, int method, MatExpr& res) const
|
||||
expr.op->assign(expr, m);
|
||||
MatOp_Invert::makeExpr(res, method, m);
|
||||
}
|
||||
|
||||
|
||||
Size MatOp::size(const MatExpr& expr) const
|
||||
{
|
||||
return !expr.a.empty() ? expr.a.size() : expr.b.empty() ? expr.b.size() : expr.c.size();
|
||||
}
|
||||
|
||||
int MatOp::type(const MatExpr& expr) const
|
||||
{
|
||||
return !expr.a.empty() ? expr.a.type() : expr.b.empty() ? expr.b.type() : expr.c.type();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MatExpr::MatExpr(const Mat& m) : op(&g_MatOp_Identity), flags(0), a(m), b(Mat()), c(Mat()), alpha(1), beta(0), s(Scalar())
|
||||
@@ -1142,6 +1155,30 @@ MatExpr abs(const MatExpr& e)
|
||||
}
|
||||
|
||||
|
||||
Size MatExpr::size() const
|
||||
{
|
||||
if( isT(*this) || isInv(*this) )
|
||||
return Size(a.rows, a.cols);
|
||||
if( isGEMM(*this) )
|
||||
return Size(b.cols, a.rows);
|
||||
if( isSolve(*this) )
|
||||
return Size(b.cols, a.cols);
|
||||
if( isInitializer(*this) )
|
||||
return a.size();
|
||||
return op ? op->size(*this) : Size();
|
||||
}
|
||||
|
||||
|
||||
int MatExpr::type() const
|
||||
{
|
||||
if( isInitializer(*this) )
|
||||
return a.type();
|
||||
if( isCmp(*this) )
|
||||
return CV_8U;
|
||||
return op ? op->type(*this) : -1;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Identity::assign(const MatExpr& e, Mat& m, int type) const
|
||||
@@ -1552,10 +1589,10 @@ MatExpr Mat::inv(int method) const
|
||||
}
|
||||
|
||||
|
||||
MatExpr Mat::mul(const Mat& m, double scale) const
|
||||
MatExpr Mat::mul(const InputArray& m, double scale) const
|
||||
{
|
||||
MatExpr e;
|
||||
MatOp_Bin::makeExpr(e, '*', *this, m, scale);
|
||||
MatOp_Bin::makeExpr(e, '*', *this, m.getMat(), scale);
|
||||
return e;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -65,74 +65,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CV_MEMCPY_CHAR( dst, src, len ) \
|
||||
{ \
|
||||
size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
|
||||
char* _icv_memcpy_dst_ = (char*)(dst); \
|
||||
const char* _icv_memcpy_src_ = (const char*)(src); \
|
||||
\
|
||||
for( _icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; _icv_memcpy_i_++ ) \
|
||||
_icv_memcpy_dst_[_icv_memcpy_i_] = _icv_memcpy_src_[_icv_memcpy_i_]; \
|
||||
}
|
||||
|
||||
|
||||
#define CV_MEMCPY_INT( dst, src, len ) \
|
||||
{ \
|
||||
size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
|
||||
int* _icv_memcpy_dst_ = (int*)(dst); \
|
||||
const int* _icv_memcpy_src_ = (const int*)(src); \
|
||||
assert( ((size_t)_icv_memcpy_src_&(sizeof(int)-1)) == 0 && \
|
||||
((size_t)_icv_memcpy_dst_&(sizeof(int)-1)) == 0 ); \
|
||||
\
|
||||
for(_icv_memcpy_i_=0;_icv_memcpy_i_<_icv_memcpy_len_;_icv_memcpy_i_++) \
|
||||
_icv_memcpy_dst_[_icv_memcpy_i_] = _icv_memcpy_src_[_icv_memcpy_i_];\
|
||||
}
|
||||
|
||||
|
||||
#define CV_MEMCPY_AUTO( dst, src, len ) \
|
||||
{ \
|
||||
size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
|
||||
char* _icv_memcpy_dst_ = (char*)(dst); \
|
||||
const char* _icv_memcpy_src_ = (const char*)(src); \
|
||||
if( (_icv_memcpy_len_ & (sizeof(int)-1)) == 0 ) \
|
||||
{ \
|
||||
assert( ((size_t)_icv_memcpy_src_&(sizeof(int)-1)) == 0 && \
|
||||
((size_t)_icv_memcpy_dst_&(sizeof(int)-1)) == 0 ); \
|
||||
for( _icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; \
|
||||
_icv_memcpy_i_+=sizeof(int) ) \
|
||||
{ \
|
||||
*(int*)(_icv_memcpy_dst_+_icv_memcpy_i_) = \
|
||||
*(const int*)(_icv_memcpy_src_+_icv_memcpy_i_); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
for(_icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; _icv_memcpy_i_++)\
|
||||
_icv_memcpy_dst_[_icv_memcpy_i_] = _icv_memcpy_src_[_icv_memcpy_i_]; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define CV_ZERO_CHAR( dst, len ) \
|
||||
{ \
|
||||
size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
|
||||
char* _icv_memcpy_dst_ = (char*)(dst); \
|
||||
\
|
||||
for( _icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; _icv_memcpy_i_++ ) \
|
||||
_icv_memcpy_dst_[_icv_memcpy_i_] = '\0'; \
|
||||
}
|
||||
|
||||
|
||||
#define CV_ZERO_INT( dst, len ) \
|
||||
{ \
|
||||
size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
|
||||
int* _icv_memcpy_dst_ = (int*)(dst); \
|
||||
assert( ((size_t)_icv_memcpy_dst_&(sizeof(int)-1)) == 0 ); \
|
||||
\
|
||||
for(_icv_memcpy_i_=0;_icv_memcpy_i_<_icv_memcpy_len_;_icv_memcpy_i_++) \
|
||||
_icv_memcpy_dst_[_icv_memcpy_i_] = 0; \
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@@ -150,23 +82,11 @@ extern const uchar g_Saturate8u[];
|
||||
#define CV_MIN_8U(a,b) ((a) - CV_FAST_CAST_8U((a) - (b)))
|
||||
#define CV_MAX_8U(a,b) ((a) + CV_FAST_CAST_8U((b) - (a)))
|
||||
|
||||
typedef void (*CopyMaskFunc)(const Mat& src, Mat& dst, const Mat& mask);
|
||||
|
||||
extern CopyMaskFunc g_copyMaskFuncTab[];
|
||||
|
||||
static inline CopyMaskFunc getCopyMaskFunc(int esz)
|
||||
{
|
||||
CV_Assert( (unsigned)esz <= 32U );
|
||||
CopyMaskFunc func = g_copyMaskFuncTab[esz];
|
||||
CV_Assert( func != 0 );
|
||||
return func;
|
||||
}
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
void deleteThreadAllocData();
|
||||
void deleteThreadRNGData();
|
||||
#endif
|
||||
|
||||
|
||||
template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
|
||||
{
|
||||
@@ -192,22 +112,6 @@ template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
|
||||
T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(b - a); }
|
||||
};
|
||||
|
||||
template<typename T1, typename T2=T1, typename T3=T1> struct OpMul
|
||||
{
|
||||
typedef T1 type1;
|
||||
typedef T2 type2;
|
||||
typedef T3 rtype;
|
||||
T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a * b); }
|
||||
};
|
||||
|
||||
template<typename T1, typename T2=T1, typename T3=T1> struct OpDiv
|
||||
{
|
||||
typedef T1 type1;
|
||||
typedef T2 type2;
|
||||
typedef T3 rtype;
|
||||
T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a / b); }
|
||||
};
|
||||
|
||||
template<typename T> struct OpMin
|
||||
{
|
||||
typedef T type1;
|
||||
@@ -261,155 +165,35 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2,
|
||||
|
||||
struct NoVec
|
||||
{
|
||||
int operator()(const void*, const void*, void*, int) const { return 0; }
|
||||
size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
|
||||
};
|
||||
|
||||
extern volatile bool USE_SSE2;
|
||||
|
||||
typedef void (*BinaryFunc)(const uchar* src1, size_t step1,
|
||||
const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, Size sz,
|
||||
void*);
|
||||
|
||||
BinaryFunc getConvertFunc(int sdepth, int ddepth);
|
||||
BinaryFunc getConvertScaleFunc(int sdepth, int ddepth);
|
||||
BinaryFunc getCopyMaskFunc(size_t esz);
|
||||
|
||||
enum { BLOCK_SIZE = 1024 };
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
static inline IppiSize ippiSize(int width, int height) { IppiSize sz={width, height}; return sz; }
|
||||
static inline IppiSize ippiSize(Size _sz) { reIppiSize sz={_sz.width, _sz.height}; return sz; }
|
||||
#endif
|
||||
|
||||
#if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7)
|
||||
#define ARITHM_USE_IPP 1
|
||||
#define IF_IPP(then_call, else_call) then_call
|
||||
#else
|
||||
#define ARITHM_USE_IPP 0
|
||||
#define IF_IPP(then_call, else_call) else_call
|
||||
#endif
|
||||
|
||||
template<class Op, class VecOp> static void
|
||||
binaryOpC1_( const Mat& srcmat1, const Mat& srcmat2, Mat& dstmat )
|
||||
{
|
||||
Op op; VecOp vecOp;
|
||||
typedef typename Op::type1 T1;
|
||||
typedef typename Op::type2 T2;
|
||||
typedef typename Op::rtype DT;
|
||||
|
||||
const T1* src1 = (const T1*)srcmat1.data;
|
||||
const T2* src2 = (const T2*)srcmat2.data;
|
||||
DT* dst = (DT*)dstmat.data;
|
||||
size_t step1 = srcmat1.step/sizeof(src1[0]);
|
||||
size_t step2 = srcmat2.step/sizeof(src2[0]);
|
||||
size_t step = dstmat.step/sizeof(dst[0]);
|
||||
Size size = getContinuousSize( srcmat1, srcmat2, dstmat, dstmat.channels() );
|
||||
|
||||
if( size.width == 1 )
|
||||
{
|
||||
for( ; size.height--; src1 += step1, src2 += step2, dst += step )
|
||||
dst[0] = op( src1[0], src2[0] );
|
||||
return;
|
||||
}
|
||||
|
||||
for( ; size.height--; src1 += step1, src2 += step2, dst += step )
|
||||
{
|
||||
int x;
|
||||
x = vecOp(src1, src2, dst, size.width);
|
||||
for( ; x <= size.width - 4; x += 4 )
|
||||
{
|
||||
DT f0, f1;
|
||||
f0 = op( src1[x], src2[x] );
|
||||
f1 = op( src1[x+1], src2[x+1] );
|
||||
dst[x] = f0;
|
||||
dst[x+1] = f1;
|
||||
f0 = op(src1[x+2], src2[x+2]);
|
||||
f1 = op(src1[x+3], src2[x+3]);
|
||||
dst[x+2] = f0;
|
||||
dst[x+3] = f1;
|
||||
}
|
||||
|
||||
for( ; x < size.width; x++ )
|
||||
dst[x] = op( src1[x], src2[x] );
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*BinaryFunc)(const Mat& src1, const Mat& src2, Mat& dst);
|
||||
|
||||
template<class Op> static void
|
||||
binarySOpCn_( const Mat& srcmat, Mat& dstmat, const Scalar& _scalar )
|
||||
{
|
||||
Op op;
|
||||
typedef typename Op::type1 T;
|
||||
typedef typename Op::type2 WT;
|
||||
typedef typename Op::rtype DT;
|
||||
const T* src0 = (const T*)srcmat.data;
|
||||
DT* dst0 = (DT*)dstmat.data;
|
||||
size_t step1 = srcmat.step/sizeof(src0[0]);
|
||||
size_t step = dstmat.step/sizeof(dst0[0]);
|
||||
int cn = dstmat.channels();
|
||||
Size size = getContinuousSize( srcmat, dstmat, cn );
|
||||
WT scalar[12];
|
||||
scalarToRawData(_scalar, scalar, CV_MAKETYPE(DataType<WT>::depth,cn), 12);
|
||||
|
||||
for( ; size.height--; src0 += step1, dst0 += step )
|
||||
{
|
||||
int i, len = size.width;
|
||||
const T* src = src0;
|
||||
T* dst = dst0;
|
||||
|
||||
for( ; (len -= 12) >= 0; dst += 12, src += 12 )
|
||||
{
|
||||
DT t0 = op(src[0], scalar[0]);
|
||||
DT t1 = op(src[1], scalar[1]);
|
||||
dst[0] = t0; dst[1] = t1;
|
||||
|
||||
t0 = op(src[2], scalar[2]);
|
||||
t1 = op(src[3], scalar[3]);
|
||||
dst[2] = t0; dst[3] = t1;
|
||||
|
||||
t0 = op(src[4], scalar[4]);
|
||||
t1 = op(src[5], scalar[5]);
|
||||
dst[4] = t0; dst[5] = t1;
|
||||
|
||||
t0 = op(src[6], scalar[6]);
|
||||
t1 = op(src[7], scalar[7]);
|
||||
dst[6] = t0; dst[7] = t1;
|
||||
|
||||
t0 = op(src[8], scalar[8]);
|
||||
t1 = op(src[9], scalar[9]);
|
||||
dst[8] = t0; dst[9] = t1;
|
||||
|
||||
t0 = op(src[10], scalar[10]);
|
||||
t1 = op(src[11], scalar[11]);
|
||||
dst[10] = t0; dst[11] = t1;
|
||||
}
|
||||
|
||||
for( (len) += 12, i = 0; i < (len); i++ )
|
||||
dst[i] = op((WT)src[i], scalar[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Op> static void
|
||||
binarySOpC1_( const Mat& srcmat, Mat& dstmat, double _scalar )
|
||||
{
|
||||
Op op;
|
||||
typedef typename Op::type1 T;
|
||||
typedef typename Op::type2 WT;
|
||||
typedef typename Op::rtype DT;
|
||||
WT scalar = saturate_cast<WT>(_scalar);
|
||||
const T* src = (const T*)srcmat.data;
|
||||
DT* dst = (DT*)dstmat.data;
|
||||
size_t step1 = srcmat.step/sizeof(src[0]);
|
||||
size_t step = dstmat.step/sizeof(dst[0]);
|
||||
Size size = srcmat.size();
|
||||
|
||||
size.width *= srcmat.channels();
|
||||
if( srcmat.isContinuous() && dstmat.isContinuous() )
|
||||
{
|
||||
size.width *= size.height;
|
||||
size.height = 1;
|
||||
}
|
||||
|
||||
for( ; size.height--; src += step1, dst += step )
|
||||
{
|
||||
int x;
|
||||
for( x = 0; x <= size.width - 4; x += 4 )
|
||||
{
|
||||
DT f0 = op( src[x], scalar );
|
||||
DT f1 = op( src[x+1], scalar );
|
||||
dst[x] = f0;
|
||||
dst[x+1] = f1;
|
||||
f0 = op( src[x+2], scalar );
|
||||
f1 = op( src[x+3], scalar );
|
||||
dst[x+2] = f0;
|
||||
dst[x+3] = f1;
|
||||
}
|
||||
|
||||
for( ; x < size.width; x++ )
|
||||
dst[x] = op( src[x], scalar );
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*BinarySFuncCn)(const Mat& src1, Mat& dst, const Scalar& scalar);
|
||||
typedef void (*BinarySFuncC1)(const Mat& src1, Mat& dst, double scalar);
|
||||
|
||||
}
|
||||
|
||||
#endif /*_CXCORE_INTERNAL_H_*/
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -170,12 +170,14 @@ struct IPPInitializer
|
||||
IPPInitializer ippInitializer;
|
||||
#else
|
||||
volatile bool useOptimizedFlag = false;
|
||||
volatile bool USE_SSE2 = false;
|
||||
#endif
|
||||
|
||||
void setUseOptimized( bool flag )
|
||||
{
|
||||
useOptimizedFlag = flag;
|
||||
currentFeatures = flag ? &featuresEnabled : &featuresDisabled;
|
||||
USE_SSE2 = currentFeatures->have[CV_CPU_SSE2];
|
||||
}
|
||||
|
||||
bool useOptimized(void)
|
||||
|
@@ -35,7 +35,7 @@ struct BaseElemWiseOp
|
||||
|
||||
virtual int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL_BUT_8S, 1,
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1,
|
||||
ninputs > 1 ? ARITHM_MAX_CHANNELS : 4);
|
||||
}
|
||||
|
||||
@@ -172,6 +172,10 @@ struct ScaleAddOp : public BaseAddOp
|
||||
{
|
||||
scaleAdd(src[0], alpha, src[1], dst);
|
||||
}
|
||||
double getMaxErr(int depth)
|
||||
{
|
||||
return depth <= CV_32S ? 2 : depth < CV_64F ? 1e-4 : 1e-12;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -414,7 +418,7 @@ struct CmpOp : public BaseElemWiseOp
|
||||
}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL_BUT_8S, 1, 1);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1, 1);
|
||||
}
|
||||
|
||||
double getMaxErr(int)
|
||||
@@ -431,6 +435,8 @@ struct CmpSOp : public BaseElemWiseOp
|
||||
{
|
||||
BaseElemWiseOp::generateScalars(depth, rng);
|
||||
cmpop = rng.uniform(0, 6);
|
||||
if( depth < CV_32F )
|
||||
gamma[0] = cvRound(gamma[0]);
|
||||
}
|
||||
void op(const vector<Mat>& src, Mat& dst, const Mat&)
|
||||
{
|
||||
@@ -442,7 +448,7 @@ struct CmpSOp : public BaseElemWiseOp
|
||||
}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL_BUT_8S, 1, 1);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1, 1);
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
@@ -465,7 +471,7 @@ struct CopyOp : public BaseElemWiseOp
|
||||
}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
@@ -488,7 +494,7 @@ struct SetOp : public BaseElemWiseOp
|
||||
}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
@@ -504,14 +510,14 @@ inRangeS_(const _Tp* src, const _WTp* a, const _WTp* b, uchar* dst, size_t total
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
_Tp val = src[i*cn];
|
||||
dst[i] = a[0] <= val && val < b[0] ? 255 : 0;
|
||||
dst[i] = a[0] <= val && val <= b[0] ? 255 : 0;
|
||||
}
|
||||
for( c = 1; c < cn; c++ )
|
||||
{
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
_Tp val = src[i*cn + c];
|
||||
dst[i] = a[c] <= val && val < b[c] ? dst[i] : 0;
|
||||
dst[i] = a[c] <= val && val <= b[c] ? dst[i] : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -523,14 +529,14 @@ template<typename _Tp> static void inRange_(const _Tp* src, const _Tp* a, const
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
_Tp val = src[i*cn];
|
||||
dst[i] = a[i*cn] <= val && val < b[i*cn] ? 255 : 0;
|
||||
dst[i] = a[i*cn] <= val && val <= b[i*cn] ? 255 : 0;
|
||||
}
|
||||
for( c = 1; c < cn; c++ )
|
||||
{
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
_Tp val = src[i*cn + c];
|
||||
dst[i] = a[i*cn + c] <= val && val < b[i*cn + c] ? dst[i] : 0;
|
||||
dst[i] = a[i*cn + c] <= val && val <= b[i*cn + c] ? dst[i] : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -703,13 +709,13 @@ struct ConvertScaleOp : public BaseElemWiseOp
|
||||
}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
int srctype = cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
|
||||
ddepth = cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, 1);
|
||||
int srctype = cvtest::randomType(rng, DEPTH_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
|
||||
ddepth = cvtest::randomType(rng, DEPTH_MASK_ALL, 1, 1);
|
||||
return srctype;
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
return ddepth <= CV_32S ? 2 : ddepth < CV_64F ? 1e-4 : 1e-12;
|
||||
return ddepth <= CV_32S ? 2 : ddepth < CV_64F ? 1e-3 : 1e-12;
|
||||
}
|
||||
void generateScalars(int depth, RNG& rng)
|
||||
{
|
||||
@@ -940,7 +946,7 @@ struct ExpOp : public BaseElemWiseOp
|
||||
ExpOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {};
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_FLT, 1, ARITHM_MAX_CHANNELS);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_FLT, 1, ARITHM_MAX_CHANNELS);
|
||||
}
|
||||
void getValueRange(int depth, double& minval, double& maxval)
|
||||
{
|
||||
@@ -967,7 +973,7 @@ struct LogOp : public BaseElemWiseOp
|
||||
LogOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {};
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_FLT, 1, ARITHM_MAX_CHANNELS);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_FLT, 1, ARITHM_MAX_CHANNELS);
|
||||
}
|
||||
void getValueRange(int depth, double& minval, double& maxval)
|
||||
{
|
||||
@@ -1052,7 +1058,7 @@ struct CartToPolarToCartOp : public BaseElemWiseOp
|
||||
}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_FLT, 1, 1);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_FLT, 1, 1);
|
||||
}
|
||||
void op(const vector<Mat>& src, Mat& dst, const Mat&)
|
||||
{
|
||||
@@ -1128,7 +1134,7 @@ struct SumOp : public BaseElemWiseOp
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
return 1e-6;
|
||||
return 1e-5;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1139,7 +1145,7 @@ struct CountNonZeroOp : public BaseElemWiseOp
|
||||
{}
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, 1);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL, 1, 1);
|
||||
}
|
||||
void op(const vector<Mat>& src, Mat& dst, const Mat& mask)
|
||||
{
|
||||
@@ -1208,7 +1214,7 @@ struct NormOp : public BaseElemWiseOp
|
||||
};
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL_BUT_8S, 1, 4);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1, 4);
|
||||
}
|
||||
void op(const vector<Mat>& src, Mat& dst, const Mat& mask)
|
||||
{
|
||||
@@ -1242,7 +1248,7 @@ struct MinMaxLocOp : public BaseElemWiseOp
|
||||
};
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, cvtest::TYPE_MASK_ALL_BUT_8S, 1, 1);
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1, 1);
|
||||
}
|
||||
void saveOutput(const vector<int>& minidx, const vector<int>& maxidx,
|
||||
double minval, double maxval, Mat& dst)
|
||||
@@ -1341,6 +1347,8 @@ INSTANTIATE_TEST_CASE_P(Core_SubRS, ElemWiseTest, ::testing::Values(ElemWiseOpPt
|
||||
INSTANTIATE_TEST_CASE_P(Core_ScaleAdd, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::ScaleAddOp)));
|
||||
INSTANTIATE_TEST_CASE_P(Core_AddWeighted, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::AddWeightedOp)));
|
||||
INSTANTIATE_TEST_CASE_P(Core_AbsDiff, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::AbsDiffOp)));
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Core_AbsDiffS, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::AbsDiffSOp)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Core_And, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::LogicOp('&'))));
|
||||
@@ -1380,3 +1388,6 @@ INSTANTIATE_TEST_CASE_P(Core_Sum, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(
|
||||
INSTANTIATE_TEST_CASE_P(Core_Norm, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::NormOp)));
|
||||
INSTANTIATE_TEST_CASE_P(Core_MinMaxLoc, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::MinMaxLocOp)));
|
||||
INSTANTIATE_TEST_CASE_P(Core_CartToPolarToCart, ElemWiseTest, ::testing::Values(ElemWiseOpPtr(new cvtest::CartToPolarToCartOp)));
|
||||
|
||||
|
||||
|
||||
|
@@ -827,3 +827,4 @@ TEST(Core_DCT, accuracy) { CxCore_DCTTest test; test.safe_run(); }
|
||||
TEST(Core_DFT, accuracy) { CxCore_DFTTest test; test.safe_run(); }
|
||||
TEST(Core_MulSpectrums, accuracy) { CxCore_MulSpectrumsTest test; test.safe_run(); }
|
||||
|
||||
|
||||
|
@@ -277,8 +277,6 @@ public:
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
int code = cvtest::TS::OK;
|
||||
|
||||
double diffPrjEps, diffBackPrjEps,
|
||||
prjEps, backPrjEps,
|
||||
evalEps, evecEps;
|
||||
@@ -327,26 +325,44 @@ protected:
|
||||
if( err > eigenEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of eigen(); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
}
|
||||
// check pca eigenvalues
|
||||
evalEps = 1e-6, evecEps = 1;
|
||||
evalEps = 1e-6, evecEps = 1e-3;
|
||||
err = norm( rPCA.eigenvalues, subEval );
|
||||
if( err > evalEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "pca.eigenvalues is incorrect (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
// check pca eigenvectors
|
||||
err = norm( rPCA.eigenvectors, subEvec, CV_RELATIVE_L2 );
|
||||
if( err > evecEps )
|
||||
for(int i = 0; i < subEvec.rows; i++)
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "pca.eigenvectors is incorrect (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
Mat r0 = rPCA.eigenvectors.row(i);
|
||||
Mat r1 = subEvec.row(i);
|
||||
err = norm( r0, r1, CV_L2 );
|
||||
if( err > evecEps )
|
||||
{
|
||||
r1 *= -1;
|
||||
double err2 = norm(r0, r1, CV_L2);
|
||||
if( err2 > evecEps )
|
||||
{
|
||||
Mat tmp;
|
||||
absdiff(rPCA.eigenvectors, subEvec, tmp);
|
||||
double mval = 0; Point mloc;
|
||||
minMaxLoc(tmp, 0, &mval, 0, &mloc);
|
||||
|
||||
ts->printf( cvtest::TS::LOG, "pca.eigenvectors is incorrect (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
ts->printf( cvtest::TS::LOG, "max diff is %g at (i=%d, j=%d) (%g vs %g)\n",
|
||||
mval, mloc.y, mloc.x, rPCA.eigenvectors.at<float>(mloc.y, mloc.x),
|
||||
subEvec.at<float>(mloc.y, mloc.x));
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prjEps = 1.265, backPrjEps = 1.265;
|
||||
@@ -359,8 +375,8 @@ protected:
|
||||
if( err > prjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
// check pca backProject
|
||||
Mat backPrj = rPrjTestPoints.row(i) * subEvec + avg;
|
||||
@@ -368,27 +384,28 @@ protected:
|
||||
if( err > backPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. check C++ PCA & COL
|
||||
cPCA( rPoints.t(), Mat(), CV_PCA_DATA_AS_COL, maxComponents );
|
||||
diffPrjEps = 1, diffBackPrjEps = 1;
|
||||
err = norm(cPCA.project(rTestPoints.t()), rPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
Mat ocvPrjTestPoints = cPCA.project(rTestPoints.t());
|
||||
err = norm(cv::abs(ocvPrjTestPoints), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 );
|
||||
if( err > diffPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
err = norm(cPCA.backProject(rPrjTestPoints.t()), rBackPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
err = norm(cPCA.backProject(ocvPrjTestPoints), rBackPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
if( err > diffBackPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CHECK_C
|
||||
@@ -411,15 +428,15 @@ protected:
|
||||
if( err > diffPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of cvProjectPCA() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
err = norm(backPrjTestPoints, rBackPrjTestPoints, CV_RELATIVE_L2);
|
||||
if( err > diffBackPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. check C PCA & COL
|
||||
@@ -435,27 +452,21 @@ protected:
|
||||
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
|
||||
cvBackProjectPCA( &_prjTestPoints, &_avg, &_evec, &_backPrjTestPoints );
|
||||
|
||||
err = norm(prjTestPoints, rPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
err = norm(cv::abs(prjTestPoints), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 );
|
||||
if( err > diffPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of cvProjectPCA() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
err = norm(backPrjTestPoints, rBackPrjTestPoints.t(), CV_RELATIVE_L2);
|
||||
if( err > diffBackPrjEps )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
exit_func:
|
||||
|
||||
RNG& _rng = ts->get_rng();
|
||||
_rng = rng;
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -790,7 +801,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
|
||||
break;
|
||||
}
|
||||
|
||||
minMaxLoc(Md, &val1, &val2, idx1, idx2);
|
||||
minMaxIdx(Md, &val1, &val2, idx1, idx2);
|
||||
s1 = idx2string(idx1, dims), s2 = idx2string(idx2, dims);
|
||||
if( (min_val < 0 && (val1 != min_val || s1 != min_sidx)) ||
|
||||
(max_val > 0 && (val2 != max_val || s2 != max_sidx)) )
|
||||
@@ -809,3 +820,5 @@ void Core_ArrayOpTest::run( int /* start_from */)
|
||||
TEST(Core_PCA, accuracy) { Core_PCATest test; test.safe_run(); }
|
||||
TEST(Core_Reduce, accuracy) { Core_ReduceTest test; test.safe_run(); }
|
||||
TEST(Core_Array, basic_operations) { Core_ArrayOpTest test; test.safe_run(); }
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user