cxmat.hpp
资源名称:gabor.rar [点击查看]
上传用户:soukeisyuu
上传日期:2022-07-03
资源大小:5943k
文件大小:148k
源码类别:
波变换
开发平台:
Visual C++
- }
- static inline Mat& operator *= (const Mat& a, double alpha)
- {
- a.convertTo((Mat&)a, -1, alpha);
- return (Mat&)a;
- }
- static inline Mat& operator += (const Mat& a, const Scalar& s)
- {
- add(a, s, (Mat&)a);
- return (Mat&)a;
- }
- static inline Mat& operator -= (const Mat& a, const Scalar& s)
- { return (a += -s); }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- (Mat&)a += (const Mat&)b;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- (Mat&)a -= (const Mat&)b;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- (Mat&)a *= (const Mat&)b;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const Scalar& s)
- {
- (Mat&)a += s;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const Scalar& s)
- {
- (Mat&)a -= s;
- return (Mat_<_Tp>&)a;
- }
- template<typename A, typename M> static inline
- M& operator += (const M& a, const MatExpr_<A, M>& b)
- { return (a += (M)b); }
- template<typename A, typename M> static inline
- M& operator -= (const M& a, const MatExpr_<A, M>& b)
- { return (a -= (M)b); }
- template<typename A, typename M> static inline
- M& operator *= (const M& a, const MatExpr_<A, M>& b)
- { return (a *= (M)b); }
- template<typename A, typename M> static inline
- M& operator += (const M& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- scaleAdd( b.e.a1, Scalar(b.e.a2), _a, _a );
- return _a;
- }
- template<typename A, typename M> static inline
- M& operator -= (const M& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- scaleAdd( b.e.a1, -Scalar(b.e.a2), _a, _a );
- return _a;
- }
- template<typename A, typename M> static inline
- M& operator += (const M& a,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_AddEx_<Mat>::apply( a, 1, (M)b.e.a1, b.e.a2, b.e.a3, _a );
- return _a;
- }
- template<typename A, typename M> static inline
- M& operator -= (const M& a,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_AddEx_<Mat>::apply( a, 1, (M)b.e.a1, -b.e.a2, -b.e.a3, _a );
- return _a;
- }
- template<typename A, typename B, typename M> static inline
- M& operator += (const M& a,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_MatMulAdd_<Mat>::apply( (M)b.e.a1, (M)b.e.a2, b.e.a3, a, 1, b.e.a4, _a );
- return _a;
- }
- template<typename A, typename B, typename M> static inline
- M& operator -= (const M& a,
- const MatExpr_<MatExpr_Op4_<A, B, double, int, M, MatOp_MatMul_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_MatMulAdd_<Mat>::apply( (M)b.e.a1, (M)b.e.a2, -b.e.a3, a, 1, b.e.a4, _a );
- return _a;
- }
- template<typename A, typename M> static inline
- M& operator *= (const M& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_MatMul_<Mat>::apply( a, (M)b.e.a1, b.e.a2, 0, _a );
- return _a;
- }
- template<typename A, typename M> static inline
- M& operator *= (const M& a,
- const MatExpr_<MatExpr_Op3_<A, double, double, M, MatOp_ScaleAddS_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_MatMulAdd_<Mat>::apply( a, (M)b.e.a1, b.e.a2, a, b.e.a3, 0, _a );
- return _a;
- }
- template<typename A, typename M> static inline
- M& operator *= (const M& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_T_<Mat> >, M>& b)
- {
- M& _a = (M&)a;
- MatOp_MatMul_<Mat>::apply( a, (M)b.e.a1, b.e.a2, GEMM_2_T, _a );
- return _a;
- }
- ////////////////////////////// Logical operations ///////////////////////////////
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> >, Mat>
- operator & (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, '&'));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> >, Mat>
- operator | (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, '|'));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> >, Mat>
- operator ^ (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, '^'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> >, Mat_<_Tp> >
- operator & (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(
- a, b, '&'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> >, Mat_<_Tp> >
- operator | (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(
- a, b, '|'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> >, Mat_<_Tp> >
- operator ^ (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(
- a, b, '^'));
- }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator & (const MatExpr_<A, M>& a, const MatExpr_<B, M>& b)
- { return (M)a & (M)b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator & (const MatExpr_<A, M>& a, const M& b)
- { return (M)a & b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator & (const M& a, const MatExpr_<A, M>& b)
- { return a & (M)b; }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator | (const MatExpr_<A, M>& a, const MatExpr_<B, M>& b)
- { return (M)a | (M)b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator | (const MatExpr_<A, M>& a, const M& b)
- { return (M)a | b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator | (const M& a, const MatExpr_<A, M>& b)
- { return a | (M)b; }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator ^ (const MatExpr_<A, M>& a, const MatExpr_<B, M>& b)
- { return (M)a ^ (M)b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator ^ (const MatExpr_<A, M>& a, const M& b)
- { return (M)a ^ b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- operator ^ (const M& a, const MatExpr_<A, M>& b)
- { return a ^ (M)b; }
- static inline Mat& operator &= (const Mat& a, const Mat& b)
- {
- MatOp_Bin_<Mat>::apply( a, b, '&', (Mat&)a );
- return (Mat&)a;
- }
- static inline Mat& operator |= (const Mat& a, const Mat& b)
- {
- MatOp_Bin_<Mat>::apply( a, b, '|', (Mat&)a );
- return (Mat&)a;
- }
- static inline Mat& operator ^= (const Mat& a, const Mat& b)
- {
- MatOp_Bin_<Mat>::apply( a, b, '^', (Mat&)a );
- return (Mat&)a;
- }
- template<typename _Tp> static inline Mat_<_Tp>&
- operator &= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- (Mat&)a &= (const Mat&)b;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline Mat_<_Tp>&
- operator |= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- (Mat&)a |= (const Mat&)b;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline Mat_<_Tp>&
- operator ^= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- (Mat&)a ^= (const Mat&)b;
- return (Mat_<_Tp>&)a;
- }
- template<typename A, typename M> static inline M&
- operator &= (const M& a, const MatExpr_<A, M>& b)
- { return (a &= (M)b); }
- template<typename A, typename M> static inline M&
- operator |= (const M& a, const MatExpr_<A, M>& b)
- { return (a |= (M)b); }
- template<typename A, typename M> static inline M&
- operator ^= (const M& a, const MatExpr_<A, M>& b)
- { return (a ^= (M)b); }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator & (const Mat& a, const Scalar& s)
- {
- typedef MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, s, '&'));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator & (const Scalar& s, const Mat& a)
- { return a & s; }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator | (const Mat& a, const Scalar& s)
- {
- typedef MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, s, '|'));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator | (const Scalar& s, const Mat& a)
- { return a | s; }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator ^ (const Mat& a, const Scalar& s)
- {
- typedef MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, s, '^'));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator ^ (const Scalar& s, const Mat& a)
- { return a ^ s; }
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- operator ~ (const Mat& a)
- {
- typedef MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, Scalar(), '~'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator & (const Mat_<_Tp>& a, const Scalar& s)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, s, '&'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator & (const Scalar& s, const Mat_<_Tp>& a)
- { return a & s; }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator | (const Mat_<_Tp>& a, const Scalar& s)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, s, '|'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator | (const Scalar& s, const Mat_<_Tp>& a)
- { return a | s; }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator ^ (const Mat_<_Tp>& a, const Scalar& s)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, s, '^'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator ^ (const Scalar& s, const Mat_<_Tp>& a)
- { return a ^ s; }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> >, Mat_<_Tp> >
- operator ~ (const Mat_<_Tp>& a)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, Scalar(), '~'));
- }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator & (const MatExpr_<A, M>& a, const Scalar& s)
- { return (M)a & s; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator & (const Scalar& s, const MatExpr_<A, M>& a)
- { return (M)a & s; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator | (const MatExpr_<A, M>& a, const Scalar& s)
- { return (M)a | s; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator | (const Scalar& s, const MatExpr_<A, M>& a)
- { return (M)a | s; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator ^ (const MatExpr_<A, M>& a, const Scalar& s)
- { return (M)a ^ s; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator ^ (const Scalar& s, const MatExpr_<A, M>& a)
- { return (M)a ^ s; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, Scalar, int, M, MatOp_BinS_<Mat> >, M >
- operator ~ (const MatExpr_<A, M>& a)
- { return ~(M)a; }
- static inline Mat& operator &= (const Mat& a, const Scalar& s)
- {
- MatOp_BinS_<Mat>::apply( a, s, '&', (Mat&)a );
- return (Mat&)a;
- }
- static inline Mat& operator |= (const Mat& a, const Scalar& s)
- {
- MatOp_BinS_<Mat>::apply( a, s, '|', (Mat&)a );
- return (Mat&)a;
- }
- static inline Mat& operator ^= (const Mat& a, const Scalar& s)
- {
- MatOp_BinS_<Mat>::apply( a, s, '^', (Mat&)a );
- return (Mat&)a;
- }
- template<typename _Tp> static inline Mat_<_Tp>&
- operator &= (const Mat_<_Tp>& a, const Scalar& s)
- {
- (Mat&)a &= s;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline Mat_<_Tp>&
- operator |= (const Mat_<_Tp>& a, const Scalar& s)
- {
- (Mat&)a |= s;
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline Mat_<_Tp>&
- operator ^= (const Mat_<_Tp>& a, const Scalar& s)
- {
- (Mat&)a ^= s;
- return (Mat_<_Tp>&)a;
- }
- ////////////////////////////// Comparison operations ///////////////////////////////
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> >, Mat>
- operator == (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, CMP_EQ));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> >, Mat>
- operator >= (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, CMP_GE));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> >, Mat>
- operator > (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, CMP_GT));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> >, Mat>
- operator <= (const Mat& a, const Mat& b)
- { return b >= a; }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> >, Mat>
- operator < (const Mat& a, const Mat& b)
- { return b > a; }
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> >, Mat>
- operator != (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Cmp_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, CMP_NE));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator == (const Mat& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha, CMP_EQ));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator >= (const Mat& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha, CMP_GE));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator > (const Mat& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha, CMP_GT));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator <= (const Mat& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha, CMP_LE));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator < (const Mat& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha, CMP_LT));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator != (const Mat& a, double alpha)
- {
- typedef MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha, CMP_NE));
- }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator == (double alpha, const Mat& a)
- { return a == alpha; }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator >= (double alpha, const Mat& a)
- { return a <= alpha; }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator > (double alpha, const Mat& a)
- { return a < alpha; }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator <= (double alpha, const Mat& a)
- { return a >= alpha; }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator < (double alpha, const Mat& a)
- { return a > alpha; }
- static inline MatExpr_<MatExpr_Op3_<Mat, double, int, Mat, MatOp_CmpS_<Mat> >, Mat>
- operator != (double alpha, const Mat& a)
- { return a != alpha; }
- /////////////////////////////// Miscellaneous operations //////////////////////////////
- // max(A, B)
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> >, Mat>
- max(const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, 'M'));
- }
- // min(A, B)
- static inline MatExpr_<MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> >, Mat>
- min(const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op3_<Mat, Mat, int, Mat, MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, 'm'));
- }
- // abs(A)
- static inline MatExpr_<MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> >, Mat>
- abs(const Mat& a)
- {
- typedef MatExpr_Op3_<Mat, Scalar, int, Mat, MatOp_BinS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, Scalar(0), 'a'));
- }
- // max(A, B)
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> >, Mat_<_Tp> >
- max(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(
- a, b, 'M'));
- }
- // min(A, B)
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> >, Mat_<_Tp> >
- min(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Mat_<_Tp>, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(
- a, b, 'm'));
- }
- // abs(A)
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>,
- MatOp_BinS_<Mat> >, Mat_<_Tp> >
- abs(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op3_<Mat_<_Tp>, Scalar, int, Mat_<_Tp>,
- MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(
- a, Scalar(0), 'a'));
- }
- // max(A, B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- max(const MatExpr_<A, M>& a, const MatExpr_<B, M>& b)
- { return max((M)a, (M)b); }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- max(const MatExpr_<A, M>& a, const M& b)
- { return max((M)a, b); }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- max(const M& a, const MatExpr_<A, M>& b)
- { return max(a, (M)b); }
- // min(A, B)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- min(const MatExpr_<A, M>& a, const MatExpr_<B, M>& b)
- { return min((M)a, (M)b); }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- min(const MatExpr_<A, M>& a, const M& b)
- { return min((M)a, b); }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- min(const M& a, const MatExpr_<A, M>& b)
- { return min(a, (M)b); }
- // abs(A)
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> >, M>
- abs(const MatExpr_<MatExpr_Op2_<A, B, M, MatOp_Sub_<Mat> >, M>& a)
- {
- typedef MatExpr_Op3_<M, M, int, M, MatOp_Bin_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)a.e.a2, 'a'));
- }
- template<typename _Tp> void merge(const Mat_<_Tp>* mvbegin, size_t count, Mat& dst)
- { merge( (const Mat*)mvbegin, count, dst ); }
- static inline void split(const Mat& m, vector<Mat>& mv)
- {
- mv.resize(m.channels());
- if(m.channels() > 0)
- split(m, &mv[0]);
- }
- template<typename _Tp> void split(const Mat& src, vector<Mat_<_Tp> >& mv)
- { split(src, (vector<Mat>&)mv ); }
- static inline void merge(const vector<Mat>& mv, Mat& dst)
- { merge(&mv[0], mv.size(), dst); }
- static inline void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
- const int* fromTo, int npairs)
- {
- mixChannels(&src[0], (int)src.size(), &dst[0], (int)dst.size(), fromTo, npairs);
- }
- ///// Element-wise multiplication
- inline MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
- Mat::mul(const Mat& m, double scale) const
- {
- typedef MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(*this, m, scale, '*'));
- }
- inline MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
- Mat::mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_Scale_<Mat> >, Mat>& m, double scale) const
- {
- typedef MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(*this, m.e.a1, m.e.a2*scale, '*'));
- }
- inline MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
- Mat::mul(const MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_DivRS_<Mat> >, Mat>& m, double scale) const
- {
- typedef MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(*this, m.e.a1, scale/m.e.a2, '/'));
- }
- template<typename _Tp> inline
- MatExpr_<MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, char, Mat_<_Tp>, MatOp_MulDiv_<Mat> >, Mat_<_Tp> >
- Mat_<_Tp>::mul(const Mat_<_Tp>& m, double scale) const
- {
- typedef MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, char, Mat_<_Tp>, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(*this, m, scale, '*'));
- }
- template<typename _Tp> inline
- MatExpr_<MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, char, Mat_<_Tp>, MatOp_MulDiv_<Mat> >, Mat_<_Tp> >
- Mat_<_Tp>::mul(const MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_Scale_<Mat> >, Mat_<_Tp> >& m, double scale) const
- {
- typedef MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, char, Mat_<_Tp>, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(*this, m.e.a1, m.e.a2*scale, '*'));
- }
- template<typename _Tp> inline
- MatExpr_<MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, char, Mat_<_Tp>, MatOp_MulDiv_<Mat> >, Mat_<_Tp> >
- Mat_<_Tp>::mul(const MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_DivRS_<Mat> >, Mat_<_Tp> >& m, double scale) const
- {
- typedef MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double, char, Mat_<_Tp>, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(*this, m.e.a1, scale/m.e.a2, '/'));
- }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op4_<A, B, double, char, M, MatOp_MulDiv_<Mat> >, M>& a,
- double alpha)
- {
- typedef MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, (M)a.e.a2, a.e.a3*alpha, a.e.a4));
- }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator * (double alpha,
- const MatExpr_<MatExpr_Op4_<A, B, double, char, M, MatOp_MulDiv_<Mat> >, M>& a)
- { return a*alpha; }
- ////// Element-wise division
- static inline MatExpr_<MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> >, Mat>
- operator / (const Mat& a, const Mat& b)
- {
- typedef MatExpr_Op4_<Mat, Mat, double, char, Mat, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, b, 1, '/'));
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double,
- char, Mat_<_Tp>, MatOp_MulDiv_<Mat> >, Mat_<_Tp> >
- operator / (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- typedef MatExpr_Op4_<Mat_<_Tp>, Mat_<_Tp>, double,
- char, Mat_<_Tp>, MatOp_MulDiv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, b, 1, '/'));
- }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const MatExpr_<A, M>& a, const MatExpr_<B, M>& b)
- { return (M)a/(M)b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const MatExpr_<A, M>& a, const M& b)
- { return (M)a/b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const M& a, const MatExpr_<A, M>& b)
- { return a/(M)b; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const M& b)
- { return ((M)a.e.a1/b)*a.e.a2; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const M& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& b)
- { return (a/(M)b.e.a1)*(1./b.e.a2); }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_Scale_<Mat> >, M>& b)
- { return ((M)a.e.a1/(M)b.e.a1)*(a.e.a2/b.e.a2); }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const M& a,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_DivRS_<Mat> >, M>& b)
- { return a.mul((M)b.e.a1, 1./b.e.a2); }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op4_<M, M, double, char, M, MatOp_MulDiv_<Mat> >, M>
- operator / (const MatExpr_<A, M>& a,
- const MatExpr_<MatExpr_Op2_<B, double, M, MatOp_DivRS_<Mat> >, M>& b)
- { return ((M)a).mul((M)b.e.a1, 1./b.e.a2); }
- static inline
- MatExpr_<MatExpr_Op2_<Mat, double, Mat, MatOp_DivRS_<Mat> >, Mat >
- operator / (double alpha, const Mat& a)
- {
- typedef MatExpr_Op2_<Mat, double, Mat, MatOp_DivRS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(a, alpha));
- }
- static inline Mat& operator /= (const Mat& a, double alpha)
- {
- MatOp_Scale_<Mat>::apply( a, 1./alpha, (Mat&)a );
- return (Mat&)a;
- }
- template<typename _Tp>
- static inline Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, double alpha)
- {
- MatOp_Scale_<Mat>::apply( a, 1./alpha, (Mat&)a );
- return (Mat_<_Tp>&)a;
- }
- template<typename _Tp> static inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>, MatOp_DivRS_<Mat> >, Mat_<_Tp> >
- operator / (double alpha, const Mat_<_Tp>& a)
- {
- typedef MatExpr_Op2_<Mat_<_Tp>, double, Mat_<_Tp>,
- MatOp_DivRS_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(a, alpha));
- }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_DivRS_<Mat> >, M>
- operator / (double alpha, const MatExpr_<A, M>& a)
- { return alpha/(M)a; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_DivRS_<Mat> >, M>
- operator / (double alpha,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_Scale_<Mat> >, M>& a)
- { return (alpha/a.e.a2)/(M)a.e.a1; }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op2_<M, double, M, MatOp_Scale_<Mat> >, M>
- operator / (double alpha,
- const MatExpr_<MatExpr_Op2_<A, double, M, MatOp_DivRS_<Mat> >, M>& a)
- { return (M)a.e.a1*(alpha/a.e.a2); }
- static inline Mat& operator /= (const Mat& a, const Mat& b)
- {
- MatOp_MulDiv_<Mat>::apply( a, b, 1, '/', (Mat&)a );
- return (Mat&)a;
- }
- template<typename A, typename M>
- static inline M& operator /= (const M& a, const MatExpr_<MatExpr_Op2_<A, double,
- M, MatOp_Scale_<Mat> >, M>& b)
- {
- MatOp_MulDiv_<Mat>::apply( a, (M)b.e.a1, 1./b.e.a2, '/', (M&)a );
- return (M&)a;
- }
- template<typename A, typename M>
- static inline M& operator /= (const M& a, const MatExpr_<MatExpr_Op2_<A, double,
- M, MatOp_DivRS_<Mat> >, M>& b)
- {
- MatOp_MulDiv_<Mat>::apply( a, (M)b.e.a1, 1./b.e.a2, '*', (M&)a );
- return (M&)a;
- }
- // Mat Inversion and solving linear systems
- inline MatExpr_<MatExpr_Op2_<Mat, int, Mat, MatOp_Inv_<Mat> >, Mat>
- Mat::inv(int method) const
- {
- typedef MatExpr_Op2_<Mat, int, Mat, MatOp_Inv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(*this, method));
- }
- template<typename _Tp> inline
- MatExpr_<MatExpr_Op2_<Mat_<_Tp>, int, Mat_<_Tp>, MatOp_Inv_<Mat> >, Mat_<_Tp> >
- Mat_<_Tp>::inv(int method) const
- {
- typedef MatExpr_Op2_<Mat_<_Tp>, int, Mat_<_Tp>, MatOp_Inv_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat_<_Tp> >(MatExpr_Temp(*this, method));
- }
- template<typename A, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Solve_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op2_<A, int, M, MatOp_Inv_<Mat> >, M>& a,
- const M& b)
- {
- typedef MatExpr_Op3_<M, M, int, M, MatOp_Solve_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, M>(MatExpr_Temp((M)a.e.a1, b, a.e.a2));
- }
- template<typename A, typename B, typename M> static inline
- MatExpr_<MatExpr_Op3_<M, M, int, M, MatOp_Solve_<Mat> >, M>
- operator * (const MatExpr_<MatExpr_Op2_<A, int, M, MatOp_Inv_<Mat> >, M>& a,
- const MatExpr_<B, M>& b)
- { return a*(M)b; }
- /////////////////////////////// Initialization ////////////////////////////////////////
- inline MatExpr_Initializer Mat::zeros(int rows, int cols, int type)
- {
- typedef MatExpr_Op4_<Size, int, Scalar, int, Mat, MatOp_Set_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(Size(cols, rows), type, 0, 0));
- }
- inline MatExpr_Initializer Mat::zeros(Size size, int type)
- {
- return zeros(size.height, size.width, type);
- }
- inline MatExpr_Initializer Mat::ones(int rows, int cols, int type)
- {
- typedef MatExpr_Op4_<Size, int, Scalar, int, Mat, MatOp_Set_<Mat> > MatExpr_Temp;
- return MatExpr_<MatExpr_Temp, Mat>(MatExpr_Temp(Size(cols, rows), type, 1, 1));
- }
- inline MatExpr_Initializer Mat::ones(Size size, int type)
- {
- return ones(size.height, size.width, type);
- }
- inline MatExpr_Initializer Mat::eye(int rows, int cols, int type)
- {
- typedef MatExpr_Op4_<Size, int, Scalar, int, Mat, MatOp_Set_<Mat> > MatExpr_Temp;
- return MatExpr_Initializer(MatExpr_Temp(Size(cols, rows), type, 1, 2));
- }
- inline MatExpr_Initializer Mat::eye(Size size, int type)
- {
- return eye(size.height, size.width, type);
- }
- static inline MatExpr_Initializer operator * (const MatExpr_Initializer& a, double alpha)
- {
- typedef MatExpr_Op4_<Size, int, Scalar, int, Mat, MatOp_Set_<Mat> > MatExpr_Temp;
- return MatExpr_Initializer(MatExpr_Temp(a.e.a1, a.e.a2, a.e.a3*alpha, a.e.a4));
- }
- static inline MatExpr_Initializer operator * (double alpha, MatExpr_Initializer& a)
- {
- typedef MatExpr_Op4_<Size, int, Scalar, int, Mat, MatOp_Set_<Mat> > MatExpr_Temp;
- return MatExpr_Initializer(MatExpr_Temp(a.e.a1, a.e.a2, a.e.a3*alpha, a.e.a4));
- }
- template<typename _Tp> inline MatExpr_Initializer Mat_<_Tp>::zeros(int rows, int cols)
- { return Mat::zeros(rows, cols, DataType<_Tp>::type); }
- template<typename _Tp> inline MatExpr_Initializer Mat_<_Tp>::zeros(Size size)
- { return Mat::zeros(size, DataType<_Tp>::type); }
- template<typename _Tp> inline MatExpr_Initializer Mat_<_Tp>::ones(int rows, int cols)
- { return Mat::ones(rows, cols, DataType<_Tp>::type); }
- template<typename _Tp> inline MatExpr_Initializer Mat_<_Tp>::ones(Size size)
- { return Mat::ones(size, DataType<_Tp>::type); }
- template<typename _Tp> inline MatExpr_Initializer Mat_<_Tp>::eye(int rows, int cols)
- { return Mat::eye(rows, cols, DataType<_Tp>::type); }
- template<typename _Tp> inline MatExpr_Initializer Mat_<_Tp>::eye(Size size)
- { return Mat::eye(size, DataType<_Tp>::type); }
- //////////// Iterators & Comma initializers //////////////////
- template<typename _Tp> inline MatConstIterator_<_Tp>::MatConstIterator_()
- : m(0), ptr(0), sliceEnd(0) {}
- template<typename _Tp> inline MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m) : m(_m)
- {
- if( !_m )
- ptr = sliceEnd = 0;
- else
- {
- ptr = (_Tp*)_m->data;
- sliceEnd = ptr + (_m->isContinuous() ? _m->rows*_m->cols : _m->cols);
- }
- }
- template<typename _Tp> inline MatConstIterator_<_Tp>::
- MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col) : m(_m)
- {
- if( !_m )
- ptr = sliceEnd = 0;
- else
- {
- CV_DbgAssert( (unsigned)_row < _m->rows && (unsigned)_col < _m->cols );
- ptr = (_Tp*)(_m->data + _m->step*_row);
- sliceEnd = _m->isContinuous() ? (_Tp*)_m->data + _m->rows*_m->cols : ptr + _m->cols;
- ptr += _col;
- }
- }
- template<typename _Tp> inline MatConstIterator_<_Tp>::
- MatConstIterator_(const Mat_<_Tp>* _m, Point _pt) : m(_m)
- {
- if( !_m )
- ptr = sliceEnd = 0;
- else
- {
- CV_DbgAssert( (unsigned)_pt.y < (unsigned)_m->rows && (unsigned)_pt.x < (unsigned)_m->cols );
- ptr = (_Tp*)(_m->data + _m->step*_pt.y);
- sliceEnd = _m->isContinuous() ? (_Tp*)_m->data + _m->rows*_m->cols : ptr + _m->cols;
- ptr += _pt.x;
- }
- }
- template<typename _Tp> inline MatConstIterator_<_Tp>::
- MatConstIterator_(const MatConstIterator_& it)
- : m(it.m), ptr(it.ptr), sliceEnd(it.sliceEnd) {}
- template<typename _Tp> inline MatConstIterator_<_Tp>&
- MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it )
- {
- m = it.m; ptr = it.ptr; sliceEnd = it.sliceEnd;
- return *this;
- }
- template<typename _Tp> inline _Tp MatConstIterator_<_Tp>::operator *() const { return *ptr; }
- template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (int ofs)
- {
- if( !m || ofs == 0 )
- return *this;
- ptr += ofs;
- if( m->isContinuous() )
- {
- if( ptr > sliceEnd )
- ptr = sliceEnd;
- else if( ptr < (_Tp*)m->data )
- ptr = (_Tp*)m->data;
- }
- else if( ptr >= sliceEnd || ptr < sliceEnd - m->cols )
- {
- ptr -= ofs;
- Point pt = pos();
- int cols = m->cols;
- ofs += pt.y*cols + pt.x;
- if( ofs > cols*m->rows )
- ofs = cols*m->rows;
- else if( ofs < 0 )
- ofs = 0;
- pt.y = ofs/cols;
- pt.x = ofs - pt.y*cols;
- ptr = (_Tp*)(m->data + m->step*pt.y);
- sliceEnd = ptr + cols;
- ptr += pt.x;
- }
- return *this;
- }
- template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (int ofs)
- { return (*this += -ofs); }
- template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --()
- { return (*this += -1); }
- template<typename _Tp> inline MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int)
- {
- MatConstIterator_ b = *this;
- *this += -1;
- return b;
- }
- template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++()
- {
- if( m && ++ptr >= sliceEnd )
- {
- --ptr;
- *this += 1;
- }
- return *this;
- }
- template<typename _Tp> inline MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int)
- {
- MatConstIterator_ b = *this;
- if( m && ++ptr >= sliceEnd )
- {
- --ptr;
- *this += 1;
- }
- return b;
- }
- template<typename _Tp> inline Point MatConstIterator_<_Tp>::pos() const
- {
- if( !m )
- return Point();
- if( m->isContinuous() )
- {
- int ofs = ptr - (_Tp*)m->data, y = ofs / m->cols, x = ofs - y*m->cols;
- return Point(x,y);
- }
- else
- {
- int stepT = m->stepT(), y = (ptr - (_Tp*)m->data)/stepT, x = (ptr - (_Tp*)m->data) - y*stepT;
- return Point(x,y);
- }
- }
- template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_() : MatConstIterator_<_Tp>() {}
- template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m)
- : MatConstIterator_<_Tp>(_m) {}
- template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col)
- : MatConstIterator_<_Tp>(_m, _row, _col) {}
- template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(const Mat_<_Tp>* _m, Point _pt)
- : MatConstIterator_<_Tp>(_m, _pt) {}
- template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(const MatIterator_& it)
- : MatConstIterator_<_Tp>(it) {}
- template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it )
- {
- this->m = it.m; this->ptr = it.ptr; this->sliceEnd = it.sliceEnd;
- return *this;
- }
- template<typename _Tp> inline _Tp& MatIterator_<_Tp>::operator *() const { return *(this->ptr); }
- template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (int ofs)
- {
- MatConstIterator_<_Tp>::operator += (ofs);
- return *this;
- }
- template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (int ofs)
- {
- MatConstIterator_<_Tp>::operator += (-ofs);
- return *this;
- }
- template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator --()
- {
- MatConstIterator_<_Tp>::operator += (-1);
- return *this;
- }
- template<typename _Tp> inline MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int)
- {
- MatIterator_ b = *this;
- MatConstIterator_<_Tp>::operator += (-1);
- return b;
- }
- template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++()
- {
- if( this->m && ++this->ptr >= this->sliceEnd )
- {
- --this->ptr;
- MatConstIterator_<_Tp>::operator += (1);
- }
- return *this;
- }
- template<typename _Tp> inline MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int)
- {
- MatIterator_ b = *this;
- if( this->m && ++this->ptr >= this->sliceEnd )
- {
- --this->ptr;
- MatConstIterator_<_Tp>::operator += (1);
- }
- return b;
- }
- template<typename _Tp> static inline bool
- operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- { return a.m == b.m && a.ptr == b.ptr; }
- template<typename _Tp> static inline bool
- operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- { return !(a == b); }
- template<typename _Tp> static inline bool
- operator < (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- { return a.ptr < b.ptr; }
- template<typename _Tp> static inline bool
- operator > (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- { return a.ptr > b.ptr; }
- template<typename _Tp> static inline bool
- operator <= (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- { return a.ptr <= b.ptr; }
- template<typename _Tp> static inline bool
- operator >= (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- { return a.ptr >= b.ptr; }
- template<typename _Tp> static inline int
- operator - (const MatConstIterator_<_Tp>& b, const MatConstIterator_<_Tp>& a)
- {
- if( a.m != b.m )
- return INT_MAX;
- if( a.sliceEnd == b.sliceEnd )
- return b.ptr - a.ptr;
- {
- Point ap = a.pos(), bp = b.pos();
- if( bp.y > ap.y )
- return (bp.y - ap.y - 1)*a.m->cols + (a.m->cols - ap.x) + bp.x;
- if( bp.y < ap.y )
- return -((ap.y - bp.y - 1)*a.m->cols + (a.m->cols - bp.x) + ap.x);
- return bp.x - ap.x;
- }
- }
- template<typename _Tp> static inline MatConstIterator_<_Tp>
- operator + (const MatConstIterator_<_Tp>& a, int ofs)
- { MatConstIterator_<_Tp> b = a; return b += ofs; }
- template<typename _Tp> static inline MatConstIterator_<_Tp>
- operator + (int ofs, const MatConstIterator_<_Tp>& a)
- { MatConstIterator_<_Tp> b = a; return b += ofs; }
- template<typename _Tp> static inline MatConstIterator_<_Tp>
- operator - (const MatConstIterator_<_Tp>& a, int ofs)
- { MatConstIterator_<_Tp> b = a; return b += -ofs; }
- template<typename _Tp> inline _Tp MatConstIterator_<_Tp>::operator [](int i) const
- { return *(*this + i); }
- template<typename _Tp> static inline MatIterator_<_Tp>
- operator + (const MatIterator_<_Tp>& a, int ofs)
- { MatIterator_<_Tp> b = a; return b += ofs; }
- template<typename _Tp> static inline MatIterator_<_Tp>
- operator + (int ofs, const MatIterator_<_Tp>& a)
- { MatIterator_<_Tp> b = a; return b += ofs; }
- template<typename _Tp> static inline MatIterator_<_Tp>
- operator - (const MatIterator_<_Tp>& a, int ofs)
- { MatIterator_<_Tp> b = a; return b += -ofs; }
- template<typename _Tp> inline _Tp& MatIterator_<_Tp>::operator [](int i) const
- { return *(*this + i); }
- template<typename _Tp> inline MatConstIterator_<_Tp> Mat_<_Tp>::begin() const
- { return Mat::begin<_Tp>(); }
- template<typename _Tp> inline MatConstIterator_<_Tp> Mat_<_Tp>::end() const
- { return Mat::end<_Tp>(); }
- template<typename _Tp> inline MatIterator_<_Tp> Mat_<_Tp>::begin()
- { return Mat::begin<_Tp>(); }
- template<typename _Tp> inline MatIterator_<_Tp> Mat_<_Tp>::end()
- { return Mat::end<_Tp>(); }
- template<typename _Tp> class CV_EXPORTS MatOp_Iter_
- {
- public:
- MatOp_Iter_() {}
- static void apply(const MatIterator_<_Tp>& a, Mat& c, int type=-1)
- {
- if( type < 0 )
- c = *a.m;
- else
- a.m->convertTo(c, type);
- }
- };
- template<typename _Tp> inline MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m) :
- MatExpr_<MatExpr_Op1_<MatIterator_<_Tp>, Mat_<_Tp>,
- MatOp_Iter_<_Tp> >, Mat_<_Tp> >(MatIterator_<_Tp>(_m)) {}
- template<typename _Tp> template<typename T2> inline MatCommaInitializer_<_Tp>&
- MatCommaInitializer_<_Tp>::operator , (T2 v)
- {
- CV_DbgAssert( this->e.a1 < this->e.a1.m->end() );
- *this->e.a1 = _Tp(v); ++this->e.a1;
- return *this;
- }
- template<typename _Tp> inline MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const
- {
- CV_DbgAssert( this->e.a1 == this->e.a1.m->end() );
- return *this->e.a1.m;
- }
- template<typename _Tp> inline Mat_<_Tp> MatCommaInitializer_<_Tp>::operator *() const
- {
- CV_DbgAssert( this->e.a1 == this->e.a1.m->end() );
- return *this->e.a1.m;
- }
- template<typename _Tp> inline void
- MatCommaInitializer_<_Tp>::assignTo(Mat& m, int type) const
- {
- Mat_<_Tp>(*this).assignTo(m, type);
- }
- template<typename _Tp, typename T2> static inline MatCommaInitializer_<_Tp>
- operator << (const Mat_<_Tp>& m, T2 val)
- {
- MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m);
- return (commaInitializer, val);
- }
- //////////////////////////////// MatND ////////////////////////////////
- inline MatND::MatND()
- : flags(MAGIC_VAL), dims(0), refcount(0), data(0), datastart(0), dataend(0)
- {
- }
- inline MatND::MatND(int _dims, const int* _sizes, int _type)
- : flags(MAGIC_VAL), dims(0), refcount(0), data(0), datastart(0), dataend(0)
- {
- create(_dims, _sizes, _type);
- }
- inline MatND::MatND(int _dims, const int* _sizes, int _type, const Scalar& _s)
- : flags(MAGIC_VAL), dims(0), refcount(0), data(0), datastart(0), dataend(0)
- {
- create(_dims, _sizes, _type);
- *this = _s;
- }
- inline MatND::MatND(const MatND& m)
- : flags(m.flags), dims(m.dims), refcount(m.refcount),
- data(m.data), datastart(m.datastart), dataend(m.dataend)
- {
- int i, d = dims;
- for( i = 0; i < d; i++ )
- {
- size[i] = m.size[i];
- step[i] = m.step[i];
- }
- if( refcount )
- CV_XADD(refcount, 1);
- }
- inline MatND::MatND(const CvMatND* m, bool copyData)
- : flags(MAGIC_VAL|(m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG))),
- dims(m->dims), refcount(0), data(m->data.ptr)
- {
- int i, d = dims;
- for( i = 0; i < d; i++ )
- {
- size[i] = m->dim[i].size;
- step[i] = m->dim[i].step;
- }
- datastart = data;
- dataend = datastart + size[0]*step[0];
- if( copyData )
- {
- MatND temp(*this);
- temp.copyTo(*this);
- }
- }
- inline MatND::~MatND() { release(); }
- inline MatND& MatND::operator = (const MatND& m)
- {
- if( this != &m )
- {
- if( m.refcount )
- CV_XADD(m.refcount, 1);
- release();
- flags = m.flags;
- dims = m.dims;
- data = m.data;
- datastart = m.datastart;
- dataend = m.dataend;
- refcount = m.refcount;
- int i, d = dims;
- for( i = 0; i < d; i++ )
- {
- size[i] = m.size[i];
- step[i] = m.step[i];
- }
- }
- return *this;
- }
- inline MatND MatND::clone() const
- {
- MatND temp;
- this->copyTo(temp);
- return temp;
- }
- inline MatND MatND::operator()(const Range* ranges) const
- {
- return MatND(*this, ranges);
- }
- inline void MatND::assignTo( MatND& m, int type ) const
- {
- if( type < 0 )
- m = *this;
- else
- convertTo(m, type);
- }
- inline void MatND::addref()
- {
- if( refcount ) CV_XADD(refcount, 1);
- }
- inline void MatND::release()
- {
- if( refcount && CV_XADD(refcount, -1) == 1 )
- fastFree(datastart);
- dims = 0;
- data = datastart = dataend = 0;
- refcount = 0;
- }
- inline bool MatND::isContinuous() const { return (flags & CONTINUOUS_FLAG) != 0; }
- inline size_t MatND::elemSize() const { return getElemSize(flags); }
- inline size_t MatND::elemSize1() const { return CV_ELEM_SIZE1(flags); }
- inline int MatND::type() const { return CV_MAT_TYPE(flags); }
- inline int MatND::depth() const { return CV_MAT_DEPTH(flags); }
- inline int MatND::channels() const { return CV_MAT_CN(flags); }
- inline size_t MatND::step1(int i) const
- { CV_DbgAssert((unsigned)i < (unsigned)dims); return step[i]/elemSize1(); }
- inline uchar* MatND::ptr(int i0)
- {
- CV_DbgAssert( dims == 1 && data &&
- (unsigned)i0 < (unsigned)size[0] );
- return data + i0*step[0];
- }
- inline const uchar* MatND::ptr(int i0) const
- {
- CV_DbgAssert( dims == 1 && data &&
- (unsigned)i0 < (unsigned)size[0] );
- return data + i0*step[0];
- }
- inline uchar* MatND::ptr(int i0, int i1)
- {
- CV_DbgAssert( dims == 2 && data &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] );
- return data + i0*step[0] + i1*step[1];
- }
- inline const uchar* MatND::ptr(int i0, int i1) const
- {
- CV_DbgAssert( dims == 2 && data &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] );
- return data + i0*step[0] + i1*step[1];
- }
- inline uchar* MatND::ptr(int i0, int i1, int i2)
- {
- CV_DbgAssert( dims == 3 && data &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] &&
- (unsigned)i2 < (unsigned)size[2] );
- return data + i0*step[0] + i1*step[1] + i2*step[2];
- }
- inline const uchar* MatND::ptr(int i0, int i1, int i2) const
- {
- CV_DbgAssert( dims == 3 && data &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] &&
- (unsigned)i2 < (unsigned)size[2] );
- return data + i0*step[0] + i1*step[1] + i2*step[2];
- }
- inline uchar* MatND::ptr(const int* idx)
- {
- int i, d = dims;
- uchar* p = data;
- CV_DbgAssert( data );
- for( i = 0; i < d; i++ )
- {
- CV_DbgAssert( (unsigned)idx[i] < (unsigned)size[i] );
- p += idx[i]*step[i];
- }
- return p;
- }
- inline const uchar* MatND::ptr(const int* idx) const
- {
- int i, d = dims;
- uchar* p = data;
- CV_DbgAssert( data );
- for( i = 0; i < d; i++ )
- {
- CV_DbgAssert( (unsigned)idx[i] < (unsigned)size[i] );
- p += idx[i]*step[i];
- }
- return p;
- }
- template<typename _Tp> inline _Tp& MatND::at(int i0)
- { return *(_Tp*)ptr(i0); }
- template<typename _Tp> inline const _Tp& MatND::at(int i0) const
- { return *(const _Tp*)ptr(i0); }
- template<typename _Tp> inline _Tp& MatND::at(int i0, int i1)
- { return *(_Tp*)ptr(i0, i1); }
- template<typename _Tp> inline const _Tp& MatND::at(int i0, int i1) const
- { return *(const _Tp*)ptr(i0, i1); }
- template<typename _Tp> inline _Tp& MatND::at(int i0, int i1, int i2)
- { return *(_Tp*)ptr(i0, i1, i2); }
- template<typename _Tp> inline const _Tp& MatND::at(int i0, int i1, int i2) const
- { return *(const _Tp*)ptr(i0, i1, i2); }
- template<typename _Tp> inline _Tp& MatND::at(const int* idx)
- { return *(_Tp*)ptr(idx); }
- template<typename _Tp> inline const _Tp& MatND::at(const int* idx) const
- { return *(const _Tp*)ptr(idx); }
- inline NAryMatNDIterator::NAryMatNDIterator()
- {
- }
- inline void subtract(const MatND& a, const Scalar& s, MatND& c, const MatND& mask=MatND())
- {
- add(a, -s, c, mask);
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_()
- {
- flags = MAGIC_VAL | DataType<_Tp>::type;
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_(int _dims, const int* _sizes)
- : MatND(_dims, _sizes, DataType<_Tp>::type)
- {
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_(int _dims, const int* _sizes, const _Tp& _s)
- : MatND(_dims, _sizes, DataType<_Tp>::type, Scalar(_s))
- {
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_(const MatND& m)
- {
- if( m.type() == DataType<_Tp>::type )
- *this = (const MatND_<_Tp>&)m;
- else
- m.convertTo(this, DataType<_Tp>::type);
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_(const MatND_<_Tp>& m) : MatND(m)
- {
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_(const MatND_<_Tp>& m, const Range* ranges)
- : MatND(m, ranges)
- {
- }
- template<typename _Tp> inline MatND_<_Tp>::MatND_(const CvMatND* m, bool copyData)
- {
- *this = MatND(m, copyData || CV_MAT_TYPE(m->type) != DataType<_Tp>::type);
- }
- template<typename _Tp> inline MatND_<_Tp>& MatND_<_Tp>::operator = (const MatND& m)
- {
- if( DataType<_Tp>::type == m.type() )
- {
- Mat::operator = (m);
- return *this;
- }
- if( DataType<_Tp>::depth == m.depth() )
- {
- return (*this = m.reshape(DataType<_Tp>::channels));
- }
- CV_DbgAssert(DataType<_Tp>::channels == m.channels());
- m.convertTo(*this, DataType<_Tp>::type);
- return *this;
- }
- template<typename _Tp> inline MatND_<_Tp>& MatND_<_Tp>::operator = (const MatND_<_Tp>& m)
- {
- return ((MatND&)*this = m);
- }
- template<typename _Tp> inline MatND_<_Tp>& MatND_<_Tp>::operator = (const _Tp& s)
- {
- return (MatND&)*this = Scalar(s);
- }
- template<typename _Tp> inline void MatND_<_Tp>::create(int _dims, const int* _sizes)
- {
- MatND::create(_dims, _sizes, DataType<_Tp>::type);
- }
- template<typename _Tp> template<typename _Tp2> inline MatND_<_Tp>::operator MatND_<_Tp2>() const
- {
- return MatND_<_Tp2>((const MatND&)*this);
- }
- template<typename _Tp> inline MatND_<_Tp> MatND_<_Tp>::clone() const
- {
- MatND_<_Tp> temp;
- this->copyTo(temp);
- return temp;
- }
- template<typename _Tp> inline MatND_<_Tp>
- MatND_<_Tp>::operator()(const Range* ranges) const
- { return MatND_<_Tp>(*this, ranges); }
- template<typename _Tp> inline size_t MatND_<_Tp>::elemSize() const
- { return CV_ELEM_SIZE(DataType<_Tp>::type); }
- template<typename _Tp> inline size_t MatND_<_Tp>::elemSize1() const
- { return CV_ELEM_SIZE1(DataType<_Tp>::type); }
- template<typename _Tp> inline int MatND_<_Tp>::type() const
- { return DataType<_Tp>::type; }
- template<typename _Tp> inline int MatND_<_Tp>::depth() const
- { return DataType<_Tp>::depth; }
- template<typename _Tp> inline int MatND_<_Tp>::channels() const
- { return DataType<_Tp>::channels; }
- template<typename _Tp> inline size_t MatND_<_Tp>::stepT(int i) const
- {
- CV_DbgAssert( (unsigned)i < (unsigned)dims );
- return step[i]/elemSize();
- }
- template<typename _Tp> inline size_t MatND_<_Tp>::step1(int i) const
- {
- CV_DbgAssert( (unsigned)i < (unsigned)dims );
- return step[i]/elemSize1();
- }
- template<typename _Tp> inline _Tp& MatND_<_Tp>::operator ()(const int* idx)
- {
- uchar* ptr = data;
- int i, d = dims;
- for( i = 0; i < d; i++ )
- {
- int ii = idx[i];
- CV_DbgAssert( (unsigned)ii < (unsigned)size[i] );
- ptr += ii*step[i];
- }
- return *(_Tp*)ptr;
- }
- template<typename _Tp> inline const _Tp& MatND_<_Tp>::operator ()(const int* idx) const
- {
- const uchar* ptr = data;
- int i, d = dims;
- for( i = 0; i < d; i++ )
- {
- int ii = idx[i];
- CV_DbgAssert( (unsigned)ii < (unsigned)size[i] );
- ptr += ii*step[i];
- }
- return *(const _Tp*)ptr;
- }
- template<typename _Tp> inline _Tp& MatND_<_Tp>::operator ()(int i0)
- {
- CV_DbgAssert( dims == 1 &&
- (unsigned)i0 < (unsigned)size[0] );
- return *(_Tp*)(data + i0*step[0]);
- }
- template<typename _Tp> inline const _Tp& MatND_<_Tp>::operator ()(int i0) const
- {
- CV_DbgAssert( dims == 1 &&
- (unsigned)i0 < (unsigned)size[0] );
- return *(const _Tp*)(data + i0*step[0]);
- }
- template<typename _Tp> inline _Tp& MatND_<_Tp>::operator ()(int i0, int i1)
- {
- CV_DbgAssert( dims == 2 &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] );
- return *(_Tp*)(data + i0*step[0] + i1*step[1]);
- }
- template<typename _Tp> inline const _Tp& MatND_<_Tp>::operator ()(int i0, int i1) const
- {
- CV_DbgAssert( dims == 2 &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] );
- return *(const _Tp*)(data + i0*step[0] + i1*step[1]);
- }
- template<typename _Tp> inline _Tp& MatND_<_Tp>::operator ()(int i0, int i1, int i2)
- {
- CV_DbgAssert( dims == 3 &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] &&
- (unsigned)i2 < (unsigned)size[2] );
- return *(_Tp*)(data + i0*step[0] + i1*step[1] + i2*step[2]);
- }
- template<typename _Tp> inline const _Tp& MatND_<_Tp>::operator ()(int i0, int i1, int i2) const
- {
- CV_DbgAssert( dims == 3 &&
- (unsigned)i0 < (unsigned)size[0] &&
- (unsigned)i1 < (unsigned)size[1] &&
- (unsigned)i2 < (unsigned)size[2] );
- return *(const _Tp*)(data + i0*step[0] + i1*step[1] + i2*step[2]);
- }
- static inline void merge(const vector<MatND>& mv, MatND& dst)
- {
- merge(&mv[0], mv.size(), dst);
- }
- static inline void split(const MatND& m, vector<MatND>& mv)
- {
- mv.resize(m.channels());
- if(m.channels() > 0)
- split(m, &mv[0]);
- }
- static inline void mixChannels(const vector<MatND>& src, vector<MatND>& dst,
- const int* fromTo, int npairs)
- {
- mixChannels(&src[0], (int)src.size(), &dst[0], (int)dst.size(), fromTo, npairs);
- }
- //////////////////////////////// SparseMat ////////////////////////////////
- inline SparseMat::SparseMat()
- : flags(MAGIC_VAL), hdr(0)
- {
- }
- inline SparseMat::SparseMat(int _dims, const int* _sizes, int _type)
- : flags(MAGIC_VAL), hdr(0)
- {
- create(_dims, _sizes, _type);
- }
- inline SparseMat::SparseMat(const SparseMat& m)
- : flags(m.flags), hdr(m.hdr)
- {
- addref();
- }
- inline SparseMat::~SparseMat()
- {
- release();
- }
- inline SparseMat& SparseMat::operator = (const SparseMat& m)
- {
- if( this != &m )
- {
- if( m.hdr )
- CV_XADD(&m.hdr->refcount, 1);
- release();
- flags = m.flags;
- hdr = m.hdr;
- }
- return *this;
- }
- inline SparseMat& SparseMat::operator = (const Mat& m)
- { return (*this = SparseMat(m)); }
- inline SparseMat& SparseMat::operator = (const MatND& m)
- { return (*this = SparseMat(m)); }
- inline SparseMat SparseMat::clone() const
- {
- SparseMat temp;
- this->copyTo(temp);
- return temp;
- }
- inline void SparseMat::assignTo( SparseMat& m, int type ) const
- {
- if( type < 0 )
- m = *this;
- else
- convertTo(m, type);
- }
- inline void SparseMat::addref()
- { if( hdr ) CV_XADD(&hdr->refcount, 1); }
- inline void SparseMat::release()
- {
- if( hdr && CV_XADD(&hdr->refcount, -1) == 1 )
- delete hdr;
- hdr = 0;
- }
- inline size_t SparseMat::elemSize() const
- { return CV_ELEM_SIZE(flags); }
- inline size_t SparseMat::elemSize1() const
- { return CV_ELEM_SIZE1(flags); }
- inline int SparseMat::type() const
- { return CV_MAT_TYPE(flags); }
- inline int SparseMat::depth() const
- { return CV_MAT_DEPTH(flags); }
- inline int SparseMat::channels() const
- { return CV_MAT_CN(flags); }
- inline const int* SparseMat::size() const
- {
- return hdr ? hdr->size : 0;
- }
- inline int SparseMat::size(int i) const
- {
- if( hdr )
- {
- CV_DbgAssert((unsigned)i < (unsigned)hdr->dims);
- return hdr->size[i];
- }
- return 0;
- }
- inline int SparseMat::dims() const
- {
- return hdr ? hdr->dims : 0;
- }
- inline size_t SparseMat::nzcount() const
- {
- return hdr ? hdr->nodeCount : 0;
- }
- inline size_t SparseMat::hash(int i0) const
- {
- return (size_t)i0;
- }
- inline size_t SparseMat::hash(int i0, int i1) const
- {
- return (size_t)(unsigned)i0*HASH_SCALE + (unsigned)i1;
- }
- inline size_t SparseMat::hash(int i0, int i1, int i2) const
- {
- return ((size_t)(unsigned)i0*HASH_SCALE + (unsigned)i1)*HASH_SCALE + (unsigned)i2;
- }
- inline size_t SparseMat::hash(const int* idx) const
- {
- size_t h = (unsigned)idx[0];
- if( !hdr )
- return 0;
- int i, d = hdr->dims;
- for( i = 1; i < d; i++ )
- h = h*HASH_SCALE + (unsigned)idx[i];
- return h;
- }
- template<typename _Tp> inline _Tp& SparseMat::ref(int i0, size_t* hashval)
- { return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval); }
- template<typename _Tp> inline _Tp& SparseMat::ref(int i0, int i1, size_t* hashval)
- { return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval); }
- template<typename _Tp> inline _Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval)
- { return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval); }
- template<typename _Tp> inline _Tp& SparseMat::ref(const int* idx, size_t* hashval)
- { return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval); }
- template<typename _Tp> inline _Tp SparseMat::value(int i0, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline _Tp SparseMat::value(int i0, int i1, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline _Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline _Tp SparseMat::value(const int* idx, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline const _Tp* SparseMat::find(int i0, size_t* hashval) const
- { return (const _Tp*)((SparseMat*)this)->ptr(i0, true, hashval); }
- template<typename _Tp> inline const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const
- { return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval); }
- template<typename _Tp> inline const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const
- { return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval); }
- template<typename _Tp> inline const _Tp* SparseMat::find(const int* idx, size_t* hashval) const
- { return (const _Tp*)((SparseMat*)this)->ptr(idx, true, hashval); }
- template<typename _Tp> inline _Tp& SparseMat::value(Node* n)
- { return *(_Tp*)((uchar*)n + hdr->valueOffset); }
- template<typename _Tp> inline const _Tp& SparseMat::value(const Node* n) const
- { return *(const _Tp*)((const uchar*)n + hdr->valueOffset); }
- inline SparseMat::Node* SparseMat::node(size_t nidx)
- { return (Node*)&hdr->pool[nidx]; }
- inline const SparseMat::Node* SparseMat::node(size_t nidx) const
- { return (const Node*)&hdr->pool[nidx]; }
- inline SparseMatIterator SparseMat::begin()
- { return SparseMatIterator(this); }
- inline SparseMatConstIterator SparseMat::begin() const
- { return SparseMatConstIterator(this); }
- inline SparseMatIterator SparseMat::end()
- { SparseMatIterator it(this); it.seekEnd(); return it; }
- inline SparseMatConstIterator SparseMat::end() const
- { SparseMatConstIterator it(this); it.seekEnd(); return it; }
- template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat::begin()
- { return SparseMatIterator_<_Tp>(this); }
- template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat::begin() const
- { return SparseMatConstIterator_<_Tp>(this); }
- template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat::end()
- { SparseMatIterator_<_Tp> it(this); it.seekEnd(); return it; }
- template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat::end() const
- { SparseMatConstIterator_<_Tp> it(this); it.seekEnd(); return it; }
- inline SparseMatConstIterator::SparseMatConstIterator()
- : m(0), hashidx(0), ptr(0)
- {
- }
- inline SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it)
- : m(it.m), hashidx(it.hashidx), ptr(it.ptr)
- {
- }
- static inline bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
- { return it1.m == it2.m && it1.hashidx == it2.hashidx && it1.ptr == it2.ptr; }
- static inline bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
- { return !(it1 == it2); }
- inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it)
- {
- if( this != &it )
- {
- m = it.m;
- hashidx = it.hashidx;
- ptr = it.ptr;
- }
- return *this;
- }
- template<typename _Tp> inline const _Tp& SparseMatConstIterator::value() const
- { return *(_Tp*)ptr; }
- inline const SparseMat::Node* SparseMatConstIterator::node() const
- {
- return ptr && m && m->hdr ?
- (const SparseMat::Node*)(ptr - m->hdr->valueOffset) : 0;
- }
- inline SparseMatConstIterator SparseMatConstIterator::operator ++(int)
- {
- SparseMatConstIterator it = *this;
- ++*this;
- return it;
- }
- inline void SparseMatConstIterator::seekEnd()
- {
- if( m && m->hdr )
- {
- hashidx = m->hdr->hashtab.size();
- ptr = 0;
- }
- }
- inline SparseMatIterator::SparseMatIterator()
- {}
- inline SparseMatIterator::SparseMatIterator(SparseMat* _m)
- : SparseMatConstIterator(_m)
- {}
- inline SparseMatIterator::SparseMatIterator(const SparseMatIterator& it)
- : SparseMatConstIterator(it)
- {
- }
- inline SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it)
- {
- (SparseMatConstIterator&)*this = it;
- return *this;
- }
- template<typename _Tp> inline _Tp& SparseMatIterator::value() const
- { return *(_Tp*)ptr; }
- inline SparseMat::Node* SparseMatIterator::node() const
- {
- return (SparseMat::Node*)SparseMatConstIterator::node();
- }
- inline SparseMatIterator& SparseMatIterator::operator ++()
- {
- SparseMatConstIterator::operator ++();
- return *this;
- }
- inline SparseMatIterator SparseMatIterator::operator ++(int)
- {
- SparseMatIterator it = *this;
- ++*this;
- return it;
- }
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_()
- { flags = MAGIC_VAL | DataType<_Tp>::type; }
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes)
- : SparseMat(_dims, _sizes, DataType<_Tp>::type)
- {}
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const SparseMat& m)
- {
- if( m.type() == DataType<_Tp>::type )
- *this = (const SparseMat_<_Tp>&)m;
- else
- m.convertTo(this, DataType<_Tp>::type);
- }
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m)
- {
- this->flags = m.flags;
- this->hdr = m.hdr;
- if( this->hdr )
- CV_XADD(&this->hdr->refcount, 1);
- }
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const Mat& m)
- {
- SparseMat sm(m);
- *this = sm;
- }
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const MatND& m)
- {
- SparseMat sm(m);
- *this = sm;
- }
- template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const CvSparseMat* m)
- {
- SparseMat sm(m);
- *this = sm;
- }
- template<typename _Tp> inline SparseMat_<_Tp>&
- SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m)
- {
- if( this != &m )
- {
- if( m.hdr ) CV_XADD(&m.hdr->refcount, 1);
- release();
- flags = m.flags;
- hdr = m.hdr;
- }
- return *this;
- }
- template<typename _Tp> inline SparseMat_<_Tp>&
- SparseMat_<_Tp>::operator = (const SparseMat& m)
- {
- if( m.type() == DataType<_Tp>::type )
- return (*this = (const SparseMat_<_Tp>&)m);
- m.convertTo(*this, DataType<_Tp>::type);
- return *this;
- }
- template<typename _Tp> inline SparseMat_<_Tp>&
- SparseMat_<_Tp>::operator = (const Mat& m)
- { return (*this = SparseMat(m)); }
- template<typename _Tp> inline SparseMat_<_Tp>&
- SparseMat_<_Tp>::operator = (const MatND& m)
- { return (*this = SparseMat(m)); }
- template<typename _Tp> inline SparseMat_<_Tp>
- SparseMat_<_Tp>::clone() const
- {
- SparseMat_<_Tp> m;
- this->copyTo(m);
- return m;
- }
- template<typename _Tp> inline void
- SparseMat_<_Tp>::create(int _dims, const int* _sizes)
- {
- SparseMat::create(_dims, _sizes, DataType<_Tp>::type);
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>::operator CvSparseMat*() const
- {
- return SparseMat::operator CvSparseMat*();
- }
- template<typename _Tp> inline int SparseMat_<_Tp>::type() const
- { return DataType<_Tp>::type; }
- template<typename _Tp> inline int SparseMat_<_Tp>::depth() const
- { return DataType<_Tp>::depth; }
- template<typename _Tp> inline int SparseMat_<_Tp>::channels() const
- { return DataType<_Tp>::channels; }
- template<typename _Tp> inline _Tp&
- SparseMat_<_Tp>::ref(int i0, size_t* hashval)
- { return SparseMat::ref<_Tp>(i0, hashval); }
- template<typename _Tp> inline _Tp
- SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const
- { return SparseMat::value<_Tp>(i0, hashval); }
- template<typename _Tp> inline _Tp&
- SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval)
- { return SparseMat::ref<_Tp>(i0, i1, hashval); }
- template<typename _Tp> inline _Tp
- SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const
- { return SparseMat::value<_Tp>(i0, i1, hashval); }
- template<typename _Tp> inline _Tp&
- SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval)
- { return SparseMat::ref<_Tp>(i0, i1, i2, hashval); }
- template<typename _Tp> inline _Tp
- SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const
- { return SparseMat::value<_Tp>(i0, i1, i2, hashval); }
- template<typename _Tp> inline _Tp&
- SparseMat_<_Tp>::ref(const int* idx, size_t* hashval)
- { return SparseMat::ref<_Tp>(idx, hashval); }
- template<typename _Tp> inline _Tp
- SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const
- { return SparseMat::value<_Tp>(idx, hashval); }
- template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin()
- { return SparseMatIterator_<_Tp>(this); }
- template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const
- { return SparseMatConstIterator_<_Tp>(this); }
- template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat_<_Tp>::end()
- { SparseMatIterator_<_Tp> it(this); it.seekEnd(); return it; }
- template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const
- { SparseMatConstIterator_<_Tp> it(this); it.seekEnd(); return it; }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_()
- {}
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m)
- : SparseMatConstIterator(_m)
- {}
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it)
- : SparseMatConstIterator(it)
- {}
- template<typename _Tp> inline SparseMatConstIterator_<_Tp>&
- SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it)
- { return ((SparseMatConstIterator&)*this = it); }
- template<typename _Tp> inline const _Tp&
- SparseMatConstIterator_<_Tp>::operator *() const
- { return *(const _Tp*)this->ptr; }
- template<typename _Tp> inline SparseMatConstIterator_<_Tp>&
- SparseMatConstIterator_<_Tp>::operator ++()
- {
- SparseMatConstIterator::operator ++();
- return *this;
- }
- template<typename _Tp> inline SparseMatConstIterator_<_Tp>
- SparseMatConstIterator_<_Tp>::operator ++(int)
- {
- SparseMatConstIterator it = *this;
- SparseMatConstIterator::operator ++();
- return it;
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_()
- {}
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m)
- : SparseMatConstIterator_<_Tp>(_m)
- {}
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it)
- : SparseMatConstIterator_<_Tp>(it)
- {}
- template<typename _Tp> inline SparseMatIterator_<_Tp>&
- SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it)
- { return ((SparseMatIterator&)*this = it); }
- template<typename _Tp> inline _Tp&
- SparseMatIterator_<_Tp>::operator *() const
- { return *(_Tp*)this->ptr; }
- template<typename _Tp> inline SparseMatIterator_<_Tp>&
- SparseMatIterator_<_Tp>::operator ++()
- {
- SparseMatConstIterator::operator ++();
- return *this;
- }
- template<typename _Tp> inline SparseMatIterator_<_Tp>
- SparseMatIterator_<_Tp>::operator ++(int)
- {
- SparseMatIterator it = *this;
- SparseMatConstIterator::operator ++();
- return it;
- }
- }
- #endif
- #endif