1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

a big patch; use special proxy types (Input/OutputArray, Input/OutputArrayOfArrays) for passing in vectors, matrices etc.

This commit is contained in:
Vadim Pisarevsky
2011-04-17 13:14:45 +00:00
parent 335370a7c0
commit abeeb40d46
94 changed files with 10831 additions and 9631 deletions
+379 -528
View File
@@ -45,555 +45,406 @@
namespace cv
{
inline float sqr(uchar a) { return CV_8TO32F_SQR(a); }
inline float sqr(float a) { return a*a; }
template<typename T, typename AT> void
acc_( const T* src, AT* dst, const uchar* mask, int len, int cn )
{
int i = 0;
inline double sqr(double a) { return a*a; }
if( !mask )
{
len *= cn;
for( ; i <= len - 4; i += 4 )
{
AT t0, t1;
t0 = src[i] + dst[i];
t1 = src[i+1] + dst[i+1];
dst[i] = t0; dst[i+1] = t1;
t0 = src[i+2] + dst[i+2];
t1 = src[i+3] + dst[i+3];
dst[i+2] = t0; dst[i+3] = t1;
}
for( ; i < len; i++ )
dst[i] += src[i];
}
else if( cn == 1 )
{
for( ; i < len; i++ )
{
if( mask[i] )
dst[i] += src[i];
}
}
else if( cn == 3 )
{
for( ; i < len; i++, src += 3, dst += 3 )
{
if( mask[i] )
{
AT t0 = src[0] + dst[0];
AT t1 = src[1] + dst[1];
AT t2 = src[2] + dst[2];
dst[0] = t0; dst[1] = t1; dst[2] = t2;
}
}
}
else
{
for( ; i < len; i++, src += cn, dst += cn )
if( mask[i] )
{
for( int k = 0; k < cn; k++ )
dst[k] += src[k];
}
}
}
inline Vec3f sqr(const Vec3b& a)
template<typename T, typename AT> void
accSqr_( const T* src, AT* dst, const uchar* mask, int len, int cn )
{
return Vec3f(CV_8TO32F_SQR(a[0]), CV_8TO32F_SQR(a[1]), CV_8TO32F_SQR(a[2]));
}
inline Vec3f sqr(const Vec3f& a)
{
return Vec3f(a[0]*a[0], a[1]*a[1], a[2]*a[2]);
}
inline Vec3d sqr(const Vec3d& a)
{
return Vec3d(a[0]*a[0], a[1]*a[1], a[2]*a[2]);
}
inline float multiply(uchar a, uchar b) { return CV_8TO32F(a)*CV_8TO32F(b); }
inline float multiply(float a, float b) { return a*b; }
inline double multiply(double a, double b) { return a*b; }
inline Vec3f multiply(const Vec3b& a, const Vec3b& b)
{
return Vec3f(
CV_8TO32F(a[0])*CV_8TO32F(b[0]),
CV_8TO32F(a[1])*CV_8TO32F(b[1]),
CV_8TO32F(a[2])*CV_8TO32F(b[2]));
}
inline Vec3f multiply(const Vec3f& a, const Vec3f& b)
{
return Vec3f(a[0]*b[0], a[1]*b[1], a[2]*b[2]);
}
inline Vec3d multiply(const Vec3d& a, const Vec3d& b)
{
return Vec3d(a[0]*b[0], a[1]*b[1], a[2]*b[2]);
}
int i = 0;
inline float addw(uchar a, float alpha, float b, float beta)
{
return b*beta + CV_8TO32F(a)*alpha;
}
inline float addw(float a, float alpha, float b, float beta)
{
return b*beta + a*alpha;
}
inline double addw(uchar a, double alpha, double b, double beta)
{
return b*beta + CV_8TO32F(a)*alpha;
}
inline double addw(float a, double alpha, double b, double beta)
{
return b*beta + a*alpha;
}
inline double addw(double a, double alpha, double b, double beta)
{
return b*beta + a*alpha;
if( !mask )
{
len *= cn;
for( ; i <= len - 4; i += 4 )
{
AT t0, t1;
t0 = (AT)src[i]*src[i] + dst[i];
t1 = (AT)src[i+1]*src[i+1] + dst[i+1];
dst[i] = t0; dst[i+1] = t1;
t0 = (AT)src[i+2]*src[i+2] + dst[i+2];
t1 = (AT)src[i+3]*src[i+3] + dst[i+3];
dst[i+2] = t0; dst[i+3] = t1;
}
for( ; i < len; i++ )
dst[i] += (AT)src[i]*src[i];
}
else if( cn == 1 )
{
for( ; i < len; i++ )
{
if( mask[i] )
dst[i] += (AT)src[i]*src[i];
}
}
else if( cn == 3 )
{
for( ; i < len; i++, src += 3, dst += 3 )
{
if( mask[i] )
{
AT t0 = (AT)src[0]*src[0] + dst[0];
AT t1 = (AT)src[1]*src[1] + dst[1];
AT t2 = (AT)src[2]*src[2] + dst[2];
dst[0] = t0; dst[1] = t1; dst[2] = t2;
}
}
}
else
{
for( ; i < len; i++, src += cn, dst += cn )
if( mask[i] )
{
for( int k = 0; k < cn; k++ )
dst[k] += (AT)src[k]*src[k];
}
}
}
inline Vec3f addw(const Vec3b& a, float alpha, const Vec3f& b, float beta)
template<typename T, typename AT> void
accProd_( const T* src1, const T* src2, AT* dst, const uchar* mask, int len, int cn )
{
return Vec3f(b[0]*beta + CV_8TO32F(a[0])*alpha,
b[1]*beta + CV_8TO32F(a[1])*alpha,
b[2]*beta + CV_8TO32F(a[2])*alpha);
int i = 0;
if( !mask )
{
len *= cn;
for( ; i <= len - 4; i += 4 )
{
AT t0, t1;
t0 = (AT)src1[i]*src2[i] + dst[i];
t1 = (AT)src1[i+1]*src2[i+1] + dst[i+1];
dst[i] = t0; dst[i+1] = t1;
t0 = (AT)src1[i+2]*src2[i+2] + dst[i+2];
t1 = (AT)src1[i+3]*src2[i+3] + dst[i+3];
dst[i+2] = t0; dst[i+3] = t1;
}
for( ; i < len; i++ )
dst[i] += (AT)src1[i]*src2[i];
}
else if( cn == 1 )
{
for( ; i < len; i++ )
{
if( mask[i] )
dst[i] += (AT)src1[i]*src2[i];
}
}
else if( cn == 3 )
{
for( ; i < len; i++, src1 += 3, src2 += 3, dst += 3 )
{
if( mask[i] )
{
AT t0 = (AT)src1[0]*src2[0] + dst[0];
AT t1 = (AT)src1[1]*src2[1] + dst[1];
AT t2 = (AT)src1[2]*src2[2] + dst[2];
dst[0] = t0; dst[1] = t1; dst[2] = t2;
}
}
}
else
{
for( ; i < len; i++, src1 += cn, src2 += cn, dst += cn )
if( mask[i] )
{
for( int k = 0; k < cn; k++ )
dst[k] += (AT)src1[k]*src2[k];
}
}
}
inline Vec3f addw(const Vec3f& a, float alpha, const Vec3f& b, float beta)
template<typename T, typename AT> void
accW_( const T* src, AT* dst, const uchar* mask, int len, int cn, double alpha )
{
return Vec3f(b[0]*beta + a[0]*alpha, b[1]*beta + a[1]*alpha, b[2]*beta + a[2]*alpha);
AT a = (AT)alpha, b = 1 - a;
int i = 0;
if( !mask )
{
len *= cn;
for( ; i <= len - 4; i += 4 )
{
AT t0, t1;
t0 = src[i]*a + dst[i]*b;
t1 = src[i+1]*a + dst[i+1]*b;
dst[i] = t0; dst[i+1] = t1;
t0 = src[i+2]*a + dst[i+2]*b;
t1 = src[i+3]*a + dst[i+3]*b;
dst[i+2] = t0; dst[i+3] = t1;
}
for( ; i < len; i++ )
dst[i] = src[i]*a + dst[i]*b;
}
else if( cn == 1 )
{
for( ; i < len; i++ )
{
if( mask[i] )
dst[i] = src[i]*a + dst[i]*b;
}
}
else if( cn == 3 )
{
for( ; i < len; i++, src += 3, dst += 3 )
{
if( mask[i] )
{
AT t0 = src[0]*a + dst[0]*b;
AT t1 = src[1]*a + dst[1]*b;
AT t2 = src[2]*a + dst[2]*b;
dst[0] = t0; dst[1] = t1; dst[2] = t2;
}
}
}
else
{
for( ; i < len; i++, src += cn, dst += cn )
if( mask[i] )
{
for( int k = 0; k < cn; k++ )
dst[k] += src[k]*a + dst[k]*b;
}
}
}
inline Vec3d addw(const Vec3b& a, double alpha, const Vec3d& b, double beta)
#define DEF_ACC_FUNCS(suffix, type, acctype) \
static void acc_##suffix(const type* src, acctype* dst, \
const uchar* mask, int len, int cn) \
{ acc_(src, dst, mask, len, cn); } \
\
static void accSqr_##suffix(const type* src, acctype* dst, \
const uchar* mask, int len, int cn) \
{ accSqr_(src, dst, mask, len, cn); } \
\
static void accProd_##suffix(const type* src1, const type* src2, \
acctype* dst, const uchar* mask, int len, int cn) \
{ accProd_(src1, src2, dst, mask, len, cn); } \
\
static void accW_##suffix(const type* src, acctype* dst, \
const uchar* mask, int len, int cn, double alpha) \
{ accW_(src, dst, mask, len, cn, alpha); }
DEF_ACC_FUNCS(8u32f, uchar, float)
DEF_ACC_FUNCS(8u64f, uchar, double)
DEF_ACC_FUNCS(16u32f, ushort, float)
DEF_ACC_FUNCS(16u64f, ushort, double)
DEF_ACC_FUNCS(32f, float, float)
DEF_ACC_FUNCS(32f64f, float, double)
DEF_ACC_FUNCS(64f, double, double)
typedef void (*AccFunc)(const uchar*, uchar*, const uchar*, int, int);
typedef void (*AccProdFunc)(const uchar*, const uchar*, uchar*, const uchar*, int, int);
typedef void (*AccWFunc)(const uchar*, uchar*, const uchar*, int, int, double);
static AccFunc accTab[] =
{
return Vec3d(b[0]*beta + CV_8TO32F(a[0])*alpha,
b[1]*beta + CV_8TO32F(a[1])*alpha,
b[2]*beta + CV_8TO32F(a[2])*alpha);
}
inline Vec3d addw(const Vec3f& a, double alpha, const Vec3d& b, double beta)
(AccFunc)acc_8u32f, (AccFunc)acc_8u64f,
(AccFunc)acc_16u32f, (AccFunc)acc_16u64f,
(AccFunc)acc_32f, (AccFunc)acc_32f64f,
(AccFunc)acc_64f
};
static AccFunc accSqrTab[] =
{
return Vec3d(b[0]*beta + a[0]*alpha, b[1]*beta + a[1]*alpha, b[2]*beta + a[2]*alpha);
}
inline Vec3d addw(const Vec3d& a, double alpha, const Vec3d& b, double beta)
(AccFunc)accSqr_8u32f, (AccFunc)accSqr_8u64f,
(AccFunc)accSqr_16u32f, (AccFunc)accSqr_16u64f,
(AccFunc)accSqr_32f, (AccFunc)accSqr_32f64f,
(AccFunc)accSqr_64f
};
static AccProdFunc accProdTab[] =
{
return Vec3d(b[0]*beta + a[0]*alpha, b[1]*beta + a[1]*alpha, b[2]*beta + a[2]*alpha);
(AccProdFunc)accProd_8u32f, (AccProdFunc)accProd_8u64f,
(AccProdFunc)accProd_16u32f, (AccProdFunc)accProd_16u64f,
(AccProdFunc)accProd_32f, (AccProdFunc)accProd_32f64f,
(AccProdFunc)accProd_64f
};
static AccWFunc accWTab[] =
{
(AccWFunc)accW_8u32f, (AccWFunc)accW_8u64f,
(AccWFunc)accW_16u32f, (AccWFunc)accW_16u64f,
(AccWFunc)accW_32f, (AccWFunc)accW_32f64f,
(AccWFunc)accW_64f
};
inline int getAccTabIdx(int sdepth, int ddepth)
{
return sdepth == CV_8U && ddepth == CV_32F ? 0 :
sdepth == CV_8U && ddepth == CV_64F ? 1 :
sdepth == CV_16U && ddepth == CV_32F ? 2 :
sdepth == CV_16U && ddepth == CV_64F ? 3 :
sdepth == CV_32F && ddepth == CV_32F ? 4 :
sdepth == CV_32F && ddepth == CV_64F ? 5 :
sdepth == CV_64F && ddepth == CV_64F ? 6 : -1;
}
template<typename T, typename AT> void
acc_( const Mat& _src, Mat& _dst )
{
Size size = _src.size();
size.width *= _src.channels();
if( _src.isContinuous() && _dst.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src = (const T*)(_src.data + _src.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
for( j = 0; j <= size.width - 4; j += 4 )
{
AT t0 = dst[j] + src[j], t1 = dst[j+1] + src[j+1];
dst[j] = t0; dst[j+1] = t1;
t0 = dst[j+2] + src[j+2]; t1 = dst[j+3] + src[j+3];
dst[j+2] = t0; dst[j+3] = t1;
}
for( ; j < size.width; j++ )
dst[j] += src[j];
}
}
template<typename T, typename AT> void
accSqr_( const Mat& _src, Mat& _dst )
{
Size size = _src.size();
size.width *= _src.channels();
if( _src.isContinuous() && _dst.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src = (const T*)(_src.data + _src.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
for( j = 0; j <= size.width - 4; j += 4 )
{
AT t0 = dst[j] + sqr(src[j]), t1 = dst[j+1] + sqr(src[j+1]);
dst[j] = t0; dst[j+1] = t1;
t0 = dst[j+2] + sqr(src[j+2]); t1 = dst[j+3] + sqr(src[j+3]);
dst[j+2] = t0; dst[j+3] = t1;
}
for( ; j < size.width; j++ )
dst[j] += sqr(src[j]);
}
}
template<typename T, typename AT> void
accProd_( const Mat& _src1, const Mat& _src2, Mat& _dst )
{
Size size = _src1.size();
size.width *= _src1.channels();
if( _src1.isContinuous() && _src2.isContinuous() && _dst.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src1 = (const T*)(_src1.data + _src1.step*i);
const T* src2 = (const T*)(_src2.data + _src2.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
for( j = 0; j <= size.width - 4; j += 4 )
{
AT t0, t1;
t0 = dst[j] + multiply(src1[j], src2[j]);
t1 = dst[j+1] + multiply(src1[j+1], src2[j+1]);
dst[j] = t0; dst[j+1] = t1;
t0 = dst[j+2] + multiply(src1[j+2], src2[j+2]);
t1 = dst[j+3] + multiply(src1[j+3], src2[j+3]);
dst[j+2] = t0; dst[j+3] = t1;
}
for( ; j < size.width; j++ )
dst[j] += multiply(src1[j], src2[j]);
}
}
template<typename T, typename AT> void
accW_( const Mat& _src, Mat& _dst, double _alpha )
{
AT alpha = (AT)_alpha, beta = (AT)(1 - _alpha);
Size size = _src.size();
size.width *= _src.channels();
if( _src.isContinuous() && _dst.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src = (const T*)(_src.data + _src.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
for( j = 0; j <= size.width - 4; j += 4 )
{
AT t0, t1;
t0 = addw(src[j], alpha, dst[j], beta);
t1 = addw(src[j+1], alpha, dst[j+1], beta);
dst[j] = t0; dst[j+1] = t1;
t0 = addw(src[j+2], alpha, dst[j+2], beta);
t1 = addw(src[j+3], alpha, dst[j+3], beta);
dst[j+2] = t0; dst[j+3] = t1;
}
for( ; j < size.width; j++ )
dst[j] = addw(src[j], alpha, dst[j], beta);
}
}
template<typename T, typename AT> void
accMask_( const Mat& _src, Mat& _dst, const Mat& _mask )
{
Size size = _src.size();
if( _src.isContinuous() && _dst.isContinuous() && _mask.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src = (const T*)(_src.data + _src.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
const uchar* mask = _mask.data + _mask.step*i;
for( j = 0; j < size.width; j++ )
if( mask[j] )
dst[j] += src[j];
}
}
template<typename T, typename AT> void
accSqrMask_( const Mat& _src, Mat& _dst, const Mat& _mask )
{
Size size = _src.size();
if( _src.isContinuous() && _dst.isContinuous() && _mask.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src = (const T*)(_src.data + _src.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
const uchar* mask = _mask.data + _mask.step*i;
for( j = 0; j < size.width; j++ )
if( mask[j] )
dst[j] += sqr(src[j]);
}
}
template<typename T, typename AT> void
accProdMask_( const Mat& _src1, const Mat& _src2, Mat& _dst, const Mat& _mask )
{
Size size = _src1.size();
if( _src1.isContinuous() && _src2.isContinuous() &&
_dst.isContinuous() && _mask.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src1 = (const T*)(_src1.data + _src1.step*i);
const T* src2 = (const T*)(_src2.data + _src2.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
const uchar* mask = _mask.data + _mask.step*i;
for( j = 0; j < size.width; j++ )
if( mask[j] )
dst[j] += multiply(src1[j], src2[j]);
}
}
template<typename T, typename AT> void
accWMask_( const Mat& _src, Mat& _dst, double _alpha, const Mat& _mask )
{
typedef typename DataType<AT>::channel_type AT1;
AT1 alpha = (AT1)_alpha, beta = (AT1)(1 - _alpha);
Size size = _src.size();
if( _src.isContinuous() && _dst.isContinuous() && _mask.isContinuous() )
{
size.width *= size.height;
size.height = 1;
}
int i, j;
for( i = 0; i < size.height; i++ )
{
const T* src = (const T*)(_src.data + _src.step*i);
AT* dst = (AT*)(_dst.data + _dst.step*i);
const uchar* mask = _mask.data + _mask.step*i;
for( j = 0; j < size.width; j++ )
if( mask[j] )
dst[j] = addw(src[j], alpha, dst[j], beta);
}
}
typedef void (*AccFunc)(const Mat&, Mat&);
typedef void (*AccMaskFunc)(const Mat&, Mat&, const Mat&);
typedef void (*AccProdFunc)(const Mat&, const Mat&, Mat&);
typedef void (*AccProdMaskFunc)(const Mat&, const Mat&, Mat&, const Mat&);
typedef void (*AccWFunc)(const Mat&, Mat&, double);
typedef void (*AccWMaskFunc)(const Mat&, Mat&, double, const Mat&);
void accumulate( const Mat& src, Mat& dst, const Mat& mask )
{
CV_Assert( dst.size() == src.size() && dst.channels() == src.channels() );
if( !mask.data )
{
AccFunc func = 0;
if( src.depth() == CV_8U && dst.depth() == CV_32F )
func = acc_<uchar, float>;
else if( src.depth() == CV_8U && dst.depth() == CV_64F )
func = acc_<uchar, double>;
else if( src.depth() == CV_32F && dst.depth() == CV_32F )
func = acc_<float, float>;
else if( src.depth() == CV_32F && dst.depth() == CV_64F )
func = acc_<float, double>;
else if( src.depth() == CV_64F && dst.depth() == CV_64F )
func = acc_<double, double>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, dst );
}
else
{
CV_Assert( mask.size() == src.size() && mask.type() == CV_8UC1 );
AccMaskFunc func = 0;
if( src.type() == CV_8UC1 && dst.type() == CV_32FC1 )
func = accMask_<uchar, float>;
else if( src.type() == CV_8UC3 && dst.type() == CV_32FC3 )
func = accMask_<Vec3b, Vec3f>;
else if( src.type() == CV_8UC1 && dst.type() == CV_64FC1 )
func = accMask_<uchar, double>;
else if( src.type() == CV_8UC3 && dst.type() == CV_64FC3 )
func = accMask_<Vec3b, Vec3d>;
else if( src.type() == CV_32FC1 && dst.type() == CV_32FC1 )
func = accMask_<float, float>;
else if( src.type() == CV_32FC3 && dst.type() == CV_32FC3 )
func = accMask_<Vec3f, Vec3f>;
else if( src.type() == CV_32FC1 && dst.type() == CV_64FC1 )
func = accMask_<float, double>;
else if( src.type() == CV_32FC3 && dst.type() == CV_64FC3 )
func = accMask_<Vec3f, Vec3d>;
else if( src.type() == CV_64FC1 && dst.type() == CV_64FC1 )
func = accMask_<double, double>;
else if( src.type() == CV_64FC3 && dst.type() == CV_64FC3 )
func = accMask_<Vec3d, Vec3d>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, dst, mask );
}
}
void accumulateSquare( const Mat& src, Mat& dst, const Mat& mask )
{
CV_Assert( dst.size() == src.size() && dst.channels() == src.channels() );
if( !mask.data )
{
AccFunc func = 0;
if( src.depth() == CV_8U && dst.depth() == CV_32F )
func = accSqr_<uchar, float>;
else if( src.depth() == CV_8U && dst.depth() == CV_64F )
func = accSqr_<uchar, double>;
else if( src.depth() == CV_32F && dst.depth() == CV_32F )
func = accSqr_<float, float>;
else if( src.depth() == CV_32F && dst.depth() == CV_64F )
func = accSqr_<float, double>;
else if( src.depth() == CV_64F && dst.depth() == CV_64F )
func = accSqr_<double, double>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, dst );
}
else
{
CV_Assert( mask.size() == src.size() && mask.type() == CV_8UC1 );
AccMaskFunc func = 0;
if( src.type() == CV_8UC1 && dst.type() == CV_32FC1 )
func = accSqrMask_<uchar, float>;
else if( src.type() == CV_8UC3 && dst.type() == CV_32FC3 )
func = accSqrMask_<Vec3b, Vec3f>;
else if( src.type() == CV_8UC1 && dst.type() == CV_64FC1 )
func = accSqrMask_<uchar, double>;
else if( src.type() == CV_8UC3 && dst.type() == CV_64FC3 )
func = accSqrMask_<Vec3b, Vec3d>;
else if( src.type() == CV_32FC1 && dst.type() == CV_32FC1 )
func = accSqrMask_<float, float>;
else if( src.type() == CV_32FC3 && dst.type() == CV_32FC3 )
func = accSqrMask_<Vec3f, Vec3f>;
else if( src.type() == CV_32FC1 && dst.type() == CV_64FC1 )
func = accSqrMask_<float, double>;
else if( src.type() == CV_32FC3 && dst.type() == CV_64FC3 )
func = accSqrMask_<Vec3f, Vec3d>;
else if( src.type() == CV_64FC1 && dst.type() == CV_64FC1 )
func = accSqrMask_<double, double>;
else if( src.type() == CV_64FC3 && dst.type() == CV_64FC3 )
func = accSqrMask_<Vec3d, Vec3d>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, dst, mask );
}
}
void accumulateProduct( const Mat& src1, const Mat& src2, Mat& dst, const Mat& mask )
{
CV_Assert( dst.size() == src1.size() && dst.channels() == src1.channels() &&
src1.size() == src2.size() && src1.type() == src2.type() );
if( !mask.data )
{
AccProdFunc func = 0;
if( src1.depth() == CV_8U && dst.depth() == CV_32F )
func = accProd_<uchar, float>;
else if( src1.depth() == CV_8U && dst.depth() == CV_64F )
func = accProd_<uchar, double>;
else if( src1.depth() == CV_32F && dst.depth() == CV_32F )
func = accProd_<float, float>;
else if( src1.depth() == CV_32F && dst.depth() == CV_64F )
func = accProd_<float, double>;
else if( src1.depth() == CV_64F && dst.depth() == CV_64F )
func = accProd_<double, double>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src1, src2, dst );
}
else
{
CV_Assert( mask.size() == src1.size() && mask.type() == CV_8UC1 );
AccProdMaskFunc func = 0;
if( src1.type() == CV_8UC1 && dst.type() == CV_32FC1 )
func = accProdMask_<uchar, float>;
else if( src1.type() == CV_8UC3 && dst.type() == CV_32FC3 )
func = accProdMask_<Vec3b, Vec3f>;
else if( src1.type() == CV_8UC1 && dst.type() == CV_64FC1 )
func = accProdMask_<uchar, double>;
else if( src1.type() == CV_8UC3 && dst.type() == CV_64FC3 )
func = accProdMask_<Vec3b, Vec3d>;
else if( src1.type() == CV_32FC1 && dst.type() == CV_32FC1 )
func = accProdMask_<float, float>;
else if( src1.type() == CV_32FC3 && dst.type() == CV_32FC3 )
func = accProdMask_<Vec3f, Vec3f>;
else if( src1.type() == CV_32FC1 && dst.type() == CV_64FC1 )
func = accProdMask_<float, double>;
else if( src1.type() == CV_32FC3 && dst.type() == CV_64FC3 )
func = accProdMask_<Vec3f, Vec3d>;
else if( src1.type() == CV_64FC1 && dst.type() == CV_64FC1 )
func = accProdMask_<double, double>;
else if( src1.type() == CV_64FC3 && dst.type() == CV_64FC3 )
func = accProdMask_<Vec3d, Vec3d>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src1, src2, dst, mask );
}
}
void accumulateWeighted( const Mat& src, Mat& dst, double alpha, const Mat& mask )
void cv::accumulate( const InputArray& _src, InputOutputArray _dst, const InputArray& _mask )
{
CV_Assert( dst.size() == src.size() && dst.channels() == src.channels() );
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels();
if( !mask.data )
{
AccWFunc func = 0;
if( src.depth() == CV_8U && dst.depth() == CV_32F )
func = accW_<uchar, float>;
else if( src.depth() == CV_8U && dst.depth() == CV_64F )
func = accW_<uchar, double>;
else if( src.depth() == CV_32F && dst.depth() == CV_32F )
func = accW_<float, float>;
else if( src.depth() == CV_32F && dst.depth() == CV_64F )
func = accW_<float, double>;
else if( src.depth() == CV_64F && dst.depth() == CV_64F )
func = accW_<double, double>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, dst, alpha );
}
else
{
CV_Assert( mask.size() == src.size() && mask.type() == CV_8UC1 );
AccWMaskFunc func = 0;
if( src.type() == CV_8UC1 && dst.type() == CV_32FC1 )
func = accWMask_<uchar, float>;
else if( src.type() == CV_8UC3 && dst.type() == CV_32FC3 )
func = accWMask_<Vec3b, Vec3f>;
else if( src.type() == CV_8UC1 && dst.type() == CV_64FC1 )
func = accWMask_<uchar, double>;
else if( src.type() == CV_8UC3 && dst.type() == CV_64FC3 )
func = accWMask_<Vec3b, Vec3d>;
else if( src.type() == CV_32FC1 && dst.type() == CV_32FC1 )
func = accWMask_<float, float>;
else if( src.type() == CV_32FC3 && dst.type() == CV_32FC3 )
func = accWMask_<Vec3f, Vec3f>;
else if( src.type() == CV_32FC1 && dst.type() == CV_64FC1 )
func = accWMask_<float, double>;
else if( src.type() == CV_32FC3 && dst.type() == CV_64FC3 )
func = accWMask_<Vec3f, Vec3d>;
else if( src.type() == CV_64FC1 && dst.type() == CV_64FC1 )
func = accWMask_<double, double>;
else if( src.type() == CV_64FC3 && dst.type() == CV_64FC3 )
func = accWMask_<Vec3d, Vec3d>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, dst, alpha, mask );
}
CV_Assert( dst.size == src.size && dst.channels() == cn );
if( !mask.empty() )
CV_Assert( mask.size == src.size && mask.type() == CV_8U );
int fidx = getAccTabIdx(sdepth, ddepth);
AccFunc func = fidx >= 0 ? accTab[fidx] : 0;
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, &dst, &mask, 0};
uchar* ptrs[3];
NAryMatIterator it(arrays, ptrs);
int len = (int)it.size;
for( size_t i = 0; i < it.nplanes; i++, ++it )
func(ptrs[0], ptrs[1], ptrs[2], len, cn);
}
void cv::accumulateSquare( const InputArray& _src, InputOutputArray _dst, const InputArray& _mask )
{
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels();
CV_Assert( dst.size == src.size && dst.channels() == cn );
if( !mask.empty() )
CV_Assert( mask.size == src.size && mask.type() == CV_8U );
int fidx = getAccTabIdx(sdepth, ddepth);
AccFunc func = fidx >= 0 ? accSqrTab[fidx] : 0;
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, &dst, &mask, 0};
uchar* ptrs[3];
NAryMatIterator it(arrays, ptrs);
int len = (int)it.size;
for( size_t i = 0; i < it.nplanes; i++, ++it )
func(ptrs[0], ptrs[1], ptrs[2], len, cn);
}
void cv::accumulateProduct( const InputArray& _src1, const InputArray& _src2,
InputOutputArray _dst, const InputArray& _mask )
{
Mat src1 = _src1.getMat(), src2 = _src2.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
int sdepth = src1.depth(), ddepth = dst.depth(), cn = src1.channels();
CV_Assert( src2.size && src1.size && src2.type() == src1.type() );
CV_Assert( dst.size == src1.size && dst.channels() == cn );
if( !mask.empty() )
CV_Assert( mask.size == src1.size && mask.type() == CV_8U );
int fidx = getAccTabIdx(sdepth, ddepth);
AccProdFunc func = fidx >= 0 ? accProdTab[fidx] : 0;
CV_Assert( func != 0 );
const Mat* arrays[] = {&src1, &src2, &dst, &mask, 0};
uchar* ptrs[4];
NAryMatIterator it(arrays, ptrs);
int len = (int)it.size;
for( size_t i = 0; i < it.nplanes; i++, ++it )
func(ptrs[0], ptrs[1], ptrs[2], ptrs[3], len, cn);
}
void cv::accumulateWeighted( const InputArray& _src, CV_IN_OUT InputOutputArray _dst,
double alpha, const InputArray& _mask )
{
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels();
CV_Assert( dst.size == src.size && dst.channels() == cn );
if( !mask.empty() )
CV_Assert( mask.size == src.size && mask.type() == CV_8U );
int fidx = getAccTabIdx(sdepth, ddepth);
AccWFunc func = fidx >= 0 ? accWTab[fidx] : 0;
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, &dst, &mask, 0};
uchar* ptrs[3];
NAryMatIterator it(arrays, ptrs);
int len = (int)it.size;
for( size_t i = 0; i < it.nplanes; i++, ++it )
func(ptrs[0], ptrs[1], ptrs[2], len, cn, alpha);
}
+5 -5
View File
@@ -335,14 +335,14 @@ CV_IMPL void cvCanny( const void* srcarr, void* dstarr,
}
}
void cv::Canny( const Mat& image, Mat& edges,
void cv::Canny( const InputArray& image, OutputArray _edges,
double threshold1, double threshold2,
int apertureSize, bool L2gradient )
{
Mat src = image;
edges.create(src.size(), CV_8U);
CvMat _src = src, _dst = edges;
cvCanny( &_src, &_dst, threshold1, threshold2,
Mat src = image.getMat();
_edges.create(src.size(), CV_8U);
CvMat c_src = src, c_dst = _edges.getMat();
cvCanny( &c_src, &c_dst, threshold1, threshold2,
apertureSize + (L2gradient ? CV_CANNY_L2_GRADIENT : 0));
}
+47 -24
View File
@@ -2618,13 +2618,15 @@ static void Bayer2RGB_VNG_8u( const Mat& srcmat, Mat& dstmat, int code )
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// The main function //
//////////////////////////////////////////////////////////////////////////////////////////
void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
void cv::cvtColor( const InputArray& _src, OutputArray _dst, int code, int dcn )
{
Mat src = _src.getMat(), dst;
Size sz = src.size();
int scn = src.channels(), depth = src.depth(), bidx;
@@ -2638,7 +2640,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
dcn = code == CV_BGR2BGRA || code == CV_RGB2BGRA || code == CV_BGRA2RGBA ? 4 : 3;
bidx = code == CV_BGR2BGRA || code == CV_BGRA2BGR ? 0 : 2;
dst.create( sz, CV_MAKETYPE(depth, dcn));
_dst.create( sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( depth == CV_8U )
CvtColorLoop(src, dst, RGB2RGB<uchar>(scn, dcn, bidx));
else if( depth == CV_16U )
@@ -2650,7 +2654,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_BGR2BGR565: case CV_BGR2BGR555: case CV_RGB2BGR565: case CV_RGB2BGR555:
case CV_BGRA2BGR565: case CV_BGRA2BGR555: case CV_RGBA2BGR565: case CV_RGBA2BGR555:
CV_Assert( (scn == 3 || scn == 4) && depth == CV_8U );
dst.create(sz, CV_8UC2);
_dst.create(sz, CV_8UC2);
dst = _dst.getMat();
CvtColorLoop(src, dst, RGB2RGB5x5(scn,
code == CV_BGR2BGR565 || code == CV_BGR2BGR555 ||
@@ -2664,7 +2669,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_BGR5652BGRA: case CV_BGR5552BGRA: case CV_BGR5652RGBA: case CV_BGR5552RGBA:
if(dcn <= 0) dcn = 3;
CV_Assert( (dcn == 3 || dcn == 4) && scn == 2 && depth == CV_8U );
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
CvtColorLoop(src, dst, RGB5x52RGB(dcn,
code == CV_BGR5652BGR || code == CV_BGR5552BGR ||
@@ -2676,7 +2682,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_BGR2GRAY: case CV_BGRA2GRAY: case CV_RGB2GRAY: case CV_RGBA2GRAY:
CV_Assert( scn == 3 || scn == 4 );
dst.create(sz, CV_MAKETYPE(depth, 1));
_dst.create(sz, CV_MAKETYPE(depth, 1));
dst = _dst.getMat();
bidx = code == CV_BGR2GRAY || code == CV_BGRA2GRAY ? 0 : 2;
if( depth == CV_8U )
@@ -2689,14 +2697,17 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_BGR5652GRAY: case CV_BGR5552GRAY:
CV_Assert( scn == 2 && depth == CV_8U );
dst.create(sz, CV_8UC1);
_dst.create(sz, CV_8UC1);
dst = _dst.getMat();
CvtColorLoop(src, dst, RGB5x52Gray(code == CV_BGR5652GRAY ? 6 : 5));
break;
case CV_GRAY2BGR: case CV_GRAY2BGRA:
if( dcn <= 0 ) dcn = 3;
CV_Assert( scn == 1 && (dcn == 3 || dcn == 4));
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( depth == CV_8U )
CvtColorLoop(src, dst, Gray2RGB<uchar>(dcn));
@@ -2708,7 +2719,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_GRAY2BGR565: case CV_GRAY2BGR555:
CV_Assert( scn == 1 && depth == CV_8U );
dst.create(sz, CV_8UC2);
_dst.create(sz, CV_8UC2);
dst = _dst.getMat();
CvtColorLoop(src, dst, Gray2RGB5x5(code == CV_GRAY2BGR565 ? 6 : 5));
break;
@@ -2723,7 +2735,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
const float* coeffs_f = code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? 0 : yuv_f;
const int* coeffs_i = code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? 0 : yuv_i;
dst.create(sz, CV_MAKETYPE(depth, 3));
_dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat();
if( depth == CV_8U )
CvtColorLoop(src, dst, RGB2YCrCb_i<uchar>(scn, bidx, coeffs_i));
@@ -2745,7 +2758,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
const float* coeffs_f = code == CV_YCrCb2BGR || code == CV_YCrCb2RGB ? 0 : yuv_f;
const int* coeffs_i = code == CV_YCrCb2BGR || code == CV_YCrCb2RGB ? 0 : yuv_i;
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( depth == CV_8U )
CvtColorLoop(src, dst, YCrCb2RGB_i<uchar>(dcn, bidx, coeffs_i));
@@ -2760,7 +2774,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
CV_Assert( scn == 3 || scn == 4 );
bidx = code == CV_BGR2XYZ ? 0 : 2;
dst.create(sz, CV_MAKETYPE(depth, 3));
_dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat();
if( depth == CV_8U )
CvtColorLoop(src, dst, RGB2XYZ_i<uchar>(scn, bidx, 0));
@@ -2775,7 +2790,8 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
CV_Assert( scn == 3 && (dcn == 3 || dcn == 4) );
bidx = code == CV_XYZ2BGR ? 0 : 2;
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( depth == CV_8U )
CvtColorLoop(src, dst, XYZ2RGB_i<uchar>(dcn, bidx, 0));
@@ -2794,8 +2810,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
int hrange = depth == CV_32F ? 360 : code == CV_BGR2HSV || code == CV_RGB2HSV ||
code == CV_BGR2HLS || code == CV_RGB2HLS ? 180 : 255;
dst.create(sz, CV_MAKETYPE(depth, 3));
_dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat();
if( code == CV_BGR2HSV || code == CV_RGB2HSV ||
code == CV_BGR2HSV_FULL || code == CV_RGB2HSV_FULL )
{
@@ -2824,8 +2841,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
int hrange = depth == CV_32F ? 360 : code == CV_HSV2BGR || code == CV_HSV2RGB ||
code == CV_HLS2BGR || code == CV_HLS2RGB ? 180 : 255;
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( code == CV_HSV2BGR || code == CV_HSV2RGB ||
code == CV_HSV2BGR_FULL || code == CV_HSV2RGB_FULL )
{
@@ -2853,8 +2871,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
bool srgb = code == CV_BGR2Lab || code == CV_RGB2Lab ||
code == CV_BGR2Luv || code == CV_RGB2Luv;
dst.create(sz, CV_MAKETYPE(depth, 3));
_dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat();
if( code == CV_BGR2Lab || code == CV_RGB2Lab ||
code == CV_LBGR2Lab || code == CV_LRGB2Lab )
{
@@ -2883,8 +2902,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
bool srgb = code == CV_Lab2BGR || code == CV_Lab2RGB ||
code == CV_Luv2BGR || code == CV_Luv2RGB;
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( code == CV_Lab2BGR || code == CV_Lab2RGB ||
code == CV_Lab2LBGR || code == CV_Lab2LRGB )
{
@@ -2906,7 +2926,10 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_BayerBG2GRAY: case CV_BayerGB2GRAY: case CV_BayerRG2GRAY: case CV_BayerGR2GRAY:
if(dcn <= 0) dcn = 1;
CV_Assert( scn == 1 && dcn == 1 && depth == CV_8U );
dst.create(sz, depth);
_dst.create(sz, depth);
dst = _dst.getMat();
Bayer2Gray_8u(src, dst, code);
break;
@@ -2914,7 +2937,9 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
case CV_BayerBG2BGR_VNG: case CV_BayerGB2BGR_VNG: case CV_BayerRG2BGR_VNG: case CV_BayerGR2BGR_VNG:
if(dcn <= 0) dcn = 3;
CV_Assert( scn == 1 && dcn == 3 && depth == CV_8U );
dst.create(sz, CV_MAKETYPE(depth, dcn));
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
if( code == CV_BayerBG2BGR || code == CV_BayerGB2BGR ||
code == CV_BayerRG2BGR || code == CV_BayerGR2BGR )
@@ -2926,8 +2951,6 @@ void cvtColor( const Mat& src, Mat& dst, int code, int dcn )
CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" );
}
}
}
CV_IMPL void
cvCvtColor( const CvArr* srcarr, CvArr* dstarr, int code )
+129 -133
View File
@@ -1469,37 +1469,40 @@ cvFindContours( void* img, CvMemStorage* storage,
return count;
}
namespace cv
{
static void
_findContours( Mat& image, vector<vector<Point> >& contours,
vector<Vec4i>* hierarchy, int mode, int method, Point offset )
void cv::findContours( const InputOutputArray _image, OutputArrayOfArrays _contours,
OutputArray _hierarchy, int mode, int method, Point offset )
{
Mat image = _image.getMat();
MemStorage storage(cvCreateMemStorage());
CvMat _image = image;
CvSeq* _contours = 0;
if( hierarchy )
hierarchy->clear();
cvFindContours(&_image, storage, &_contours, sizeof(CvContour), mode, method, offset);
if( !_contours )
CvMat _cimage = image;
CvSeq* _ccontours = 0;
if( _hierarchy.needed() )
_hierarchy.clear();
cvFindContours(&_cimage, storage, &_ccontours, sizeof(CvContour), mode, method, offset);
if( !_ccontours )
{
contours.clear();
_contours.clear();
return;
}
Seq<CvSeq*> all_contours(cvTreeToNodeSeq( _contours, sizeof(CvSeq), storage ));
Seq<CvSeq*> all_contours(cvTreeToNodeSeq( _ccontours, sizeof(CvSeq), storage ));
size_t i, total = all_contours.size();
contours.resize(total);
_contours.create(total, 1, 0, -1, true);
SeqIterator<CvSeq*> it = all_contours.begin();
for( i = 0; i < total; i++, ++it )
{
CvSeq* c = *it;
((CvContour*)c)->color = (int)i;
Seq<Point>(c).copyTo(contours[i]);
_contours.create(c->total, 1, CV_32SC2, i, true);
Mat ci = _contours.getMat(i);
CV_Assert( ci.isContinuous() );
cvCvtSeqToArray(c, ci.data);
}
if( hierarchy )
if( _hierarchy.needed() )
{
hierarchy->resize(total);
_hierarchy.create(1, total, CV_32SC4, -1, true);
Vec4i* hierarchy = _hierarchy.getMat().ptr<Vec4i>();
it = all_contours.begin();
for( i = 0; i < total; i++, ++it )
{
@@ -1508,62 +1511,57 @@ _findContours( Mat& image, vector<vector<Point> >& contours,
int h_prev = c->h_prev ? ((CvContour*)c->h_prev)->color : -1;
int v_next = c->v_next ? ((CvContour*)c->v_next)->color : -1;
int v_prev = c->v_prev ? ((CvContour*)c->v_prev)->color : -1;
(*hierarchy)[i] = Vec4i(h_next, h_prev, v_next, v_prev);
hierarchy[i] = Vec4i(h_next, h_prev, v_next, v_prev);
}
}
}
}
void cv::findContours( Mat& image, vector<vector<Point> >& contours,
vector<Vec4i>& hierarchy, int mode, int method, Point offset )
void cv::findContours( InputOutputArray _image, OutputArrayOfArrays _contours,
int mode, int method, Point offset)
{
_findContours(image, contours, &hierarchy, mode, method, offset);
}
void cv::findContours( Mat& image, vector<vector<Point> >& contours,
int mode, int method, Point offset)
{
_findContours(image, contours, 0, mode, method, offset);
findContours(_image, _contours, OutputArrayOfArrays(), mode, method, offset);
}
namespace cv
{
static void addChildContour(const vector<vector<Point> >& contours,
const vector<Vec4i>& hierarchy,
static void addChildContour(const InputArrayOfArrays& contours,
size_t ncontours,
const Vec4i* hierarchy,
int i, vector<CvSeq>& seq,
vector<CvSeqBlock>& block)
{
size_t count = contours.size();
for( ; i >= 0; i = hierarchy[i][0] )
{
const vector<Point>& ci = contours[i];
Mat ci = contours.getMat(i);
cvMakeSeqHeaderForArray(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point),
!ci.empty() ? (void*)&ci[0] : 0, (int)ci.size(),
!ci.empty() ? (void*)ci.data : 0, (int)ci.total(),
&seq[i], &block[i] );
int h_next = hierarchy[i][0], h_prev = hierarchy[i][1],
v_next = hierarchy[i][2], v_prev = hierarchy[i][3];
seq[i].h_next = (size_t)h_next < count ? &seq[h_next] : 0;
seq[i].h_prev = (size_t)h_prev < count ? &seq[h_prev] : 0;
seq[i].v_next = (size_t)v_next < count ? &seq[v_next] : 0;
seq[i].v_prev = (size_t)v_prev < count ? &seq[v_prev] : 0;
seq[i].h_next = (size_t)h_next < ncontours ? &seq[h_next] : 0;
seq[i].h_prev = (size_t)h_prev < ncontours ? &seq[h_prev] : 0;
seq[i].v_next = (size_t)v_next < ncontours ? &seq[v_next] : 0;
seq[i].v_prev = (size_t)v_prev < ncontours ? &seq[v_prev] : 0;
if( v_next >= 0 )
addChildContour(contours, hierarchy, v_next, seq, block);
addChildContour(contours, ncontours, hierarchy, v_next, seq, block);
}
}
}
void cv::drawContours( Mat& image, const vector<vector<Point> >& contours,
void cv::drawContours( InputOutputArray _image, const InputArrayOfArrays& _contours,
int contourIdx, const Scalar& color, int thickness,
int lineType, const vector<Vec4i>& hierarchy,
int lineType, const InputArray& _hierarchy,
int maxLevel, Point offset )
{
CvMat _image = image;
Mat image = _image.getMat(), hierarchy = _hierarchy.getMat();
CvMat _cimage = image;
size_t i = 0, first = 0, last = contours.size();
size_t ncontours = _contours.total();
size_t i = 0, first = 0, last = ncontours;
vector<CvSeq> seq;
vector<CvSeqBlock> block;
@@ -1585,9 +1583,13 @@ void cv::drawContours( Mat& image, const vector<vector<Point> >& contours,
for( i = first; i < last; i++ )
{
const vector<Point>& ci = contours[i];
cvMakeSeqHeaderForArray(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point),
!ci.empty() ? (void*)&ci[0] : 0, (int)ci.size(), &seq[i], &block[i] );
Mat ci = _contours.getMat(i);
if( ci.empty() )
continue;
int npoints = ci.checkVector(2, CV_32S);
CV_Assert( npoints > 0 );
cvMakeSeqHeaderForArray( CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point),
ci.data, npoints, &seq[i], &block[i] );
}
if( hierarchy.empty() || maxLevel == 0 )
@@ -1599,13 +1601,15 @@ void cv::drawContours( Mat& image, const vector<vector<Point> >& contours,
else
{
size_t count = last - first;
CV_Assert(hierarchy.size() == contours.size());
if( count == contours.size() )
CV_Assert(hierarchy.total() == ncontours && hierarchy.type() == CV_32SC4 );
const Vec4i* h = hierarchy.ptr<Vec4i>();
if( count == ncontours )
{
for( i = first; i < last; i++ )
{
int h_next = hierarchy[i][0], h_prev = hierarchy[i][1],
v_next = hierarchy[i][2], v_prev = hierarchy[i][3];
int h_next = h[i][0], h_prev = h[i][1],
v_next = h[i][2], v_prev = h[i][3];
seq[i].h_next = (size_t)h_next < count ? &seq[h_next] : 0;
seq[i].h_prev = (size_t)h_prev < count ? &seq[h_prev] : 0;
seq[i].v_next = (size_t)v_next < count ? &seq[v_next] : 0;
@@ -1614,85 +1618,88 @@ void cv::drawContours( Mat& image, const vector<vector<Point> >& contours,
}
else
{
int child = hierarchy[first][2];
int child = h[first][2];
if( child >= 0 )
{
addChildContour(contours, hierarchy, child, seq, block);
addChildContour(_contours, ncontours, h, child, seq, block);
seq[first].v_next = &seq[child];
}
}
}
cvDrawContours( &_image, &seq[first], color, color, contourIdx >= 0 ?
cvDrawContours( &_cimage, &seq[first], color, color, contourIdx >= 0 ?
-maxLevel : maxLevel, thickness, lineType, offset );
}
void cv::approxPolyDP( const Mat& curve, vector<Point>& approxCurve,
void cv::approxPolyDP( const InputArray& _curve, OutputArray _approxCurve,
double epsilon, bool closed )
{
CV_Assert(curve.checkVector(2, CV_32S) >= 0);
CvMat _curve = curve;
Mat curve = _curve.getMat();
int npoints = curve.checkVector(2), depth = curve.depth();
CV_Assert( npoints >= 0 && (depth == CV_32S || depth == CV_32F));
CvMat _ccurve = curve;
MemStorage storage(cvCreateMemStorage());
Seq<Point> seq(cvApproxPoly(&_curve, sizeof(CvContour), storage, CV_POLY_APPROX_DP, epsilon, closed));
seq.copyTo(approxCurve);
CvSeq* result = cvApproxPoly(&_ccurve, sizeof(CvContour), storage, CV_POLY_APPROX_DP, epsilon, closed);
if( result->total > 0 )
{
_approxCurve.create(result->total, 1, CV_MAKETYPE(curve.depth(), 2), -1, true);
cvCvtSeqToArray(result, _approxCurve.getMat().data );
}
}
void cv::approxPolyDP( const Mat& curve, vector<Point2f>& approxCurve,
double epsilon, bool closed )
{
CV_Assert(curve.checkVector(2, CV_32F) >= 0);
CvMat _curve = curve;
MemStorage storage(cvCreateMemStorage());
Seq<Point2f> seq(cvApproxPoly(&_curve, sizeof(CvContour), storage, CV_POLY_APPROX_DP, epsilon, closed));
seq.copyTo(approxCurve);
}
double cv::arcLength( const Mat& curve, bool closed )
double cv::arcLength( const InputArray& _curve, bool closed )
{
Mat curve = _curve.getMat();
CV_Assert(curve.checkVector(2) >= 0 && (curve.depth() == CV_32F || curve.depth() == CV_32S));
CvMat _curve = curve;
return cvArcLength(&_curve, CV_WHOLE_SEQ, closed);
CvMat _ccurve = curve;
return cvArcLength(&_ccurve, CV_WHOLE_SEQ, closed);
}
cv::Rect cv::boundingRect( const Mat& points )
cv::Rect cv::boundingRect( const InputArray& _points )
{
Mat points = _points.getMat();
CV_Assert(points.checkVector(2) >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _points = points;
return cvBoundingRect(&_points, 0);
CvMat _cpoints = points;
return cvBoundingRect(&_cpoints, 0);
}
double cv::contourArea( const Mat& contour, bool oriented )
double cv::contourArea( const InputArray& _contour, bool oriented )
{
Mat contour = _contour.getMat();
CV_Assert(contour.checkVector(2) >= 0 && (contour.depth() == CV_32F || contour.depth() == CV_32S));
CvMat _contour = contour;
return cvContourArea(&_contour, CV_WHOLE_SEQ, oriented);
CvMat _ccontour = contour;
return cvContourArea(&_ccontour, CV_WHOLE_SEQ, oriented);
}
cv::RotatedRect cv::minAreaRect( const Mat& points )
cv::RotatedRect cv::minAreaRect( const InputArray& _points )
{
Mat points = _points.getMat();
CV_Assert(points.checkVector(2) >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _points = points;
return cvMinAreaRect2(&_points, 0);
CvMat _cpoints = points;
return cvMinAreaRect2(&_cpoints, 0);
}
void cv::minEnclosingCircle( const Mat& points,
void cv::minEnclosingCircle( const InputArray& _points,
Point2f& center, float& radius )
{
Mat points = _points.getMat();
CV_Assert(points.checkVector(2) >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _points = points;
cvMinEnclosingCircle( &_points, (CvPoint2D32f*)&center, &radius );
CvMat _cpoints = points;
cvMinEnclosingCircle( &_cpoints, (CvPoint2D32f*)&center, &radius );
}
double cv::matchShapes( const Mat& contour1,
const Mat& contour2,
double cv::matchShapes( const InputArray& _contour1,
const InputArray& _contour2,
int method, double parameter )
{
Mat contour1 = _contour1.getMat(), contour2 = _contour2.getMat();
CV_Assert(contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 &&
(contour1.depth() == CV_32F || contour1.depth() == CV_32S) &&
contour1.depth() == contour2.depth());
@@ -1702,79 +1709,68 @@ double cv::matchShapes( const Mat& contour1,
}
void cv::convexHull( const Mat& points, vector<int>& hull, bool clockwise )
void cv::convexHull( const InputArray& _points, OutputArray _hull, bool clockwise, bool returnPoints )
{
int nelems = points.checkVector(2);
CV_Assert(nelems >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S));
hull.resize(nelems);
CvMat _points = Mat(points), _hull=Mat(hull);
cvConvexHull2(&_points, &_hull, clockwise ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE, 0);
hull.resize(_hull.cols + _hull.rows - 1);
Mat points = _points.getMat();
int nelems = points.checkVector(2), depth = points.depth();
CV_Assert(nelems >= 0 && (depth == CV_32F || depth == CV_32S));
if( nelems == 0 )
{
_hull.release();
return;
}
returnPoints = !_hull.fixedType() ? returnPoints : _hull.type() != CV_32S;
Mat hull(nelems, 1, returnPoints ? CV_MAKETYPE(depth, 2) : CV_32S);
CvMat _cpoints = points, _chull = hull;
cvConvexHull2(&_cpoints, &_chull, clockwise ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE, returnPoints);
_hull.create(_chull.rows, 1, hull.type(), -1, true);
Mat dhull = _hull.getMat(), shull(dhull.size(), dhull.type(), hull.data);
shull.copyTo(dhull);
}
void cv::convexHull( const Mat& points,
vector<Point>& hull, bool clockwise )
{
int nelems = points.checkVector(2, CV_32S);
CV_Assert(nelems >= 0);
hull.resize(nelems);
CvMat _points = Mat(points), _hull=Mat(hull);
cvConvexHull2(&_points, &_hull, clockwise ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE, 1);
hull.resize(_hull.cols + _hull.rows - 1);
}
void cv::convexHull( const Mat& points,
vector<Point2f>& hull, bool clockwise )
{
int nelems = points.checkVector(2, CV_32F);
CV_Assert(nelems >= 0);
hull.resize(nelems);
CvMat _points = Mat(points), _hull=Mat(hull);
cvConvexHull2(&_points, &_hull, clockwise ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE, 1);
hull.resize(_hull.cols + _hull.rows - 1);
}
bool cv::isContourConvex( const Mat& contour )
bool cv::isContourConvex( const InputArray& _contour )
{
Mat contour = _contour.getMat();
CV_Assert(contour.checkVector(2) >= 0 &&
(contour.depth() == CV_32F || contour.depth() == CV_32S));
CvMat c = Mat(contour);
return cvCheckContourConvexity(&c) > 0;
}
cv::RotatedRect cv::fitEllipse( const Mat& points )
cv::RotatedRect cv::fitEllipse( const InputArray& _points )
{
Mat points = _points.getMat();
CV_Assert(points.checkVector(2) >= 0 &&
(points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _points = points;
return cvFitEllipse2(&_points);
CvMat _cpoints = points;
return cvFitEllipse2(&_cpoints);
}
void cv::fitLine( const Mat& points, Vec4f& line, int distType,
void cv::fitLine( const InputArray& _points, OutputArray _line, int distType,
double param, double reps, double aeps )
{
CV_Assert(points.checkVector(2) >= 0 &&
(points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _points = points;
cvFitLine(&_points, distType, param, reps, aeps, &line[0]);
Mat points = _points.getMat();
bool is3d = points.checkVector(3) >= 0, is2d = is3d ? false : points.checkVector(2) >= 0;
CV_Assert((is2d || is3d) && (points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _cpoints = points;
float line[6];
cvFitLine(&_cpoints, distType, param, reps, aeps, &line[0]);
_line.create(is2d ? 4 : 6, 1, CV_32F, -1, true);
Mat l = _line.getMat();
CV_Assert( l.isContinuous() );
memcpy( l.data, line, (is2d ? 4 : 6)*sizeof(line[0]) );
}
void cv::fitLine( const Mat& points, Vec6f& line, int distType,
double param, double reps, double aeps )
{
CV_Assert(points.checkVector(3) >= 0 &&
(points.depth() == CV_32F || points.depth() == CV_32S));
CvMat _points = points;
cvFitLine(&_points, distType, param, reps, aeps, &line[0]);
}
double cv::pointPolygonTest( const Mat& contour,
double cv::pointPolygonTest( const InputArray& _contour,
Point2f pt, bool measureDist )
{
Mat contour = _contour.getMat();
CV_Assert(contour.checkVector(2) >= 0 &&
(contour.depth() == CV_32F || contour.depth() == CV_32S));
CvMat c = Mat(contour);
+22 -14
View File
@@ -297,36 +297,47 @@ cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size,
calcEigenValsVecs( cov, eigenv );
}
}
void cornerMinEigenVal( const Mat& src, Mat& dst, int blockSize, int ksize, int borderType )
void cv::cornerMinEigenVal( const InputArray& _src, OutputArray _dst, int blockSize, int ksize, int borderType )
{
dst.create( src.size(), CV_32F );
Mat src = _src.getMat();
_dst.create( src.size(), CV_32F );
Mat dst = _dst.getMat();
cornerEigenValsVecs( src, dst, blockSize, ksize, MINEIGENVAL, 0, borderType );
}
void cornerHarris( const Mat& src, Mat& dst, int blockSize, int ksize, double k, int borderType )
void cv::cornerHarris( const InputArray& _src, OutputArray _dst, int blockSize, int ksize, double k, int borderType )
{
dst.create( src.size(), CV_32F );
Mat src = _src.getMat();
_dst.create( src.size(), CV_32F );
Mat dst = _dst.getMat();
cornerEigenValsVecs( src, dst, blockSize, ksize, HARRIS, k, borderType );
}
void cornerEigenValsAndVecs( const Mat& src, Mat& dst, int blockSize, int ksize, int borderType )
void cv::cornerEigenValsAndVecs( const InputArray& _src, OutputArray _dst, int blockSize, int ksize, int borderType )
{
if( dst.rows != src.rows || dst.cols*dst.channels() != src.cols*6 || dst.depth() != CV_32F )
dst.create( src.size(), CV_32FC(6) );
Mat src = _src.getMat();
Size dsz = _dst.size();
int dtype = _dst.type();
if( dsz.height != src.rows || dsz.width*CV_MAT_CN(dtype) != src.cols*6 || CV_MAT_DEPTH(dtype) != CV_32F )
_dst.create( src.size(), CV_32FC(6) );
Mat dst = _dst.getMat();
cornerEigenValsVecs( src, dst, blockSize, ksize, EIGENVALSVECS, 0, borderType );
}
void preCornerDetect( const Mat& src, Mat& dst, int ksize, int borderType )
void cv::preCornerDetect( const InputArray& _src, OutputArray _dst, int ksize, int borderType )
{
Mat Dx, Dy, D2x, D2y, Dxy;
Mat Dx, Dy, D2x, D2y, Dxy, src = _src.getMat();
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_32FC1 );
dst.create( src.size(), CV_32F );
_dst.create( src.size(), CV_32F );
Mat dst = _dst.getMat();
Sobel( src, Dx, CV_32F, 1, 0, ksize, 1, 0, borderType );
Sobel( src, Dy, CV_32F, 0, 1, ksize, 1, 0, borderType );
Sobel( src, D2x, CV_32F, 2, 0, ksize, 1, 0, borderType );
@@ -358,9 +369,6 @@ void preCornerDetect( const Mat& src, Mat& dst, int ksize, int borderType )
}
}
}
CV_IMPL void
cvCornerMinEigenVal( const CvArr* srcarr, CvArr* dstarr,
int block_size, int aperture_size )
+8 -4
View File
@@ -254,13 +254,17 @@ cvFindCornerSubPix( const void* srcarr, CvPoint2D32f* corners,
}
}
void cv::cornerSubPix( const Mat& image, vector<Point2f>& corners,
void cv::cornerSubPix( const InputArray& _image, InputOutputArray _corners,
Size winSize, Size zeroZone,
TermCriteria criteria )
{
CvMat _image = image;
cvFindCornerSubPix(&_image, (CvPoint2D32f*)&corners[0], (int)corners.size(),
winSize, zeroZone, criteria );
Mat corners = _corners.getMat();
int ncorners = corners.checkVector(2);
CV_Assert( ncorners >= 0 && corners.depth() == CV_32F );
CvMat c_image = _image.getMat();
cvFindCornerSubPix( &c_image, (CvPoint2D32f*)corners.data, ncorners,
winSize, zeroZone, criteria );
}
/* End of file. */
+51 -40
View File
@@ -111,16 +111,16 @@ void icvSepConvSmall3_32f( float* src, int src_step, float* dst, int dst_step,
namespace cv
{
static void getScharrKernels( Mat& kx, Mat& ky, int dx, int dy, bool normalize, int ktype )
static void getScharrKernels( OutputArray _kx, OutputArray _ky,
int dx, int dy, bool normalize, int ktype )
{
const int ksize = 3;
CV_Assert( ktype == CV_32F || ktype == CV_64F );
if( kx.cols != ksize || kx.rows != 1 || kx.type() != ktype )
kx.create( ksize, 1, ktype );
if( ky.cols != ksize || ky.rows != 1 || ky.type() != ktype )
ky.create( ksize, 1, ktype );
_kx.create(ksize, 1, ktype, -1, true);
_ky.create(ksize, 1, ktype, -1, true);
Mat kx = _kx.getMat();
Mat ky = _ky.getMat();
CV_Assert( dx >= 0 && dy >= 0 && dx+dy == 1 );
@@ -142,7 +142,8 @@ static void getScharrKernels( Mat& kx, Mat& ky, int dx, int dy, bool normalize,
}
static void getSobelKernels( Mat& kx, Mat& ky, int dx, int dy, int _ksize, bool normalize, int ktype )
static void getSobelKernels( OutputArray _kx, OutputArray _ky,
int dx, int dy, int _ksize, bool normalize, int ktype )
{
int i, j, ksizeX = _ksize, ksizeY = _ksize;
if( ksizeX == 1 && dx > 0 )
@@ -152,10 +153,10 @@ static void getSobelKernels( Mat& kx, Mat& ky, int dx, int dy, int _ksize, bool
CV_Assert( ktype == CV_32F || ktype == CV_64F );
if( kx.cols != ksizeX || kx.rows != 1 || kx.type() != ktype )
kx.create( ksizeX, 1, ktype );
if( ky.cols != ksizeY || ky.rows != 1 || ky.type() != ktype )
ky.create( ksizeY, 1, ktype );
_kx.create(ksizeX, 1, ktype, -1, true);
_ky.create(ksizeY, 1, ktype, -1, true);
Mat kx = _kx.getMat();
Mat ky = _ky.getMat();
if( _ksize % 2 == 0 || _ksize > 31 )
CV_Error( CV_StsOutOfRange, "The kernel size must be odd and not larger than 31" );
@@ -218,9 +219,10 @@ static void getSobelKernels( Mat& kx, Mat& ky, int dx, int dy, int _ksize, bool
}
}
}
void getDerivKernels( Mat& kx, Mat& ky, int dx, int dy,
int ksize, bool normalize, int ktype )
void cv::getDerivKernels( OutputArray kx, OutputArray ky, int dx, int dy,
int ksize, bool normalize, int ktype )
{
if( ksize <= 0 )
getScharrKernels( kx, ky, dx, dy, normalize, ktype );
@@ -229,8 +231,8 @@ void getDerivKernels( Mat& kx, Mat& ky, int dx, int dy,
}
Ptr<FilterEngine> createDerivFilter(int srcType, int dstType,
int dx, int dy, int ksize, int borderType )
cv::Ptr<cv::FilterEngine> cv::createDerivFilter(int srcType, int dstType,
int dx, int dy, int ksize, int borderType )
{
Mat kx, ky;
getDerivKernels( kx, ky, dx, dy, ksize, false, CV_32F );
@@ -238,9 +240,11 @@ Ptr<FilterEngine> createDerivFilter(int srcType, int dstType,
kx, ky, Point(-1,-1), 0, borderType );
}
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
namespace cv
{
static bool IPPDerivScharr(const Mat& src, Mat& dst, int ddepth, int dx, int dy, double scale)
{
int bufSize = 0;
@@ -344,9 +348,7 @@ static bool IPPDeriv(const Mat& src, Mat& dst, int ddepth, int dx, int dy, int k
if(ksize == 3 || ksize == 5)
{
if( ddepth < 0 )
ddepth = src.depth();
dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
ddepth = src.depth();
if(src.type() == CV_8U && dst.type() == CV_16S && scale == 1)
{
@@ -462,21 +464,25 @@ static bool IPPDeriv(const Mat& src, Mat& dst, int ddepth, int dx, int dy, int k
return IPPDerivScharr(src, dst, ddepth, dx, dy, scale);
return false;
}
}
#endif
void Sobel( const Mat& src, Mat& dst, int ddepth, int dx, int dy,
int ksize, double scale, double delta, int borderType )
void cv::Sobel( const InputArray& _src, OutputArray _dst, int ddepth, int dx, int dy,
int ksize, double scale, double delta, int borderType )
{
Mat src = _src.getMat();
_dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
Mat dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if(dx < 3 && dy < 3 && src.channels() == 1 && borderType == 1)
{
if(IPPDeriv(src, dst, ddepth, dx, dy, ksize,scale) == true)
return;
}
if(dx < 3 && dy < 3 && src.channels() == 1 && borderType == 1)
{
if(IPPDeriv(src, dst, ddepth, dx, dy, ksize,scale))
return;
}
#endif
int ktype = std::max(CV_32F, std::max(ddepth, src.depth()));
@@ -495,15 +501,19 @@ void Sobel( const Mat& src, Mat& dst, int ddepth, int dx, int dy,
}
void Scharr( const Mat& src, Mat& dst, int ddepth, int dx, int dy,
double scale, double delta, int borderType )
void cv::Scharr( const InputArray& _src, OutputArray _dst, int ddepth, int dx, int dy,
double scale, double delta, int borderType )
{
Mat src = _src.getMat();
_dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
Mat dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if(dx < 2 && dy < 2 && src.channels() == 1 && borderType == 1)
{
if(IPPDerivScharr(src, dst, ddepth, dx, dy, scale) == true)
return;
}
if(dx < 2 && dy < 2 && src.channels() == 1 && borderType == 1)
{
if(IPPDerivScharr(src, dst, ddepth, dx, dy, scale))
return;
}
#endif
int ktype = std::max(CV_32F, std::max(ddepth, src.depth()));
@@ -522,9 +532,13 @@ void Scharr( const Mat& src, Mat& dst, int ddepth, int dx, int dy,
}
void Laplacian( const Mat& src, Mat& dst, int ddepth, int ksize,
double scale, double delta, int borderType )
void cv::Laplacian( const InputArray& _src, OutputArray _dst, int ddepth, int ksize,
double scale, double delta, int borderType )
{
Mat src = _src.getMat();
_dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
Mat dst = _dst.getMat();
if( ksize == 1 || ksize == 3 )
{
float K[2][9] =
@@ -548,7 +562,6 @@ void Laplacian( const Mat& src, Mat& dst, int ddepth, int ksize,
if( ddepth < 0 )
ddepth = src.depth();
int dtype = CV_MAKETYPE(ddepth, src.channels());
dst.create( src.size(), dtype );
int dy0 = std::min(std::max((int)(STRIPE_SIZE/(getElemSize(src.type())*src.cols)), 1), src.rows);
Ptr<FilterEngine> fx = createSeparableLinearFilter(src.type(),
@@ -578,8 +591,6 @@ void Laplacian( const Mat& src, Mat& dst, int ddepth, int ksize,
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
CV_IMPL void
+12 -9
View File
@@ -850,21 +850,24 @@ cvDistTransform( const void* srcarr, void* dstarr,
}
}
void cv::distanceTransform( const Mat& src, Mat& dst, Mat& labels,
void cv::distanceTransform( const InputArray& _src, OutputArray _dst, OutputArray _labels,
int distanceType, int maskSize )
{
dst.create(src.size(), CV_32F);
labels.create(src.size(), CV_32S);
CvMat _src = src, _dst = dst, _labels = labels;
cvDistTransform(&_src, &_dst, distanceType, maskSize, 0, &_labels);
Mat src = _src.getMat();
_dst.create(src.size(), CV_32F);
_labels.create(src.size(), CV_32S);
CvMat c_src = src, c_dst = _dst.getMat(), c_labels = _labels.getMat();
cvDistTransform(&c_src, &c_dst, distanceType, maskSize, 0, &c_labels);
}
void cv::distanceTransform( const Mat& src, Mat& dst,
void cv::distanceTransform( const InputArray& _src, OutputArray _dst,
int distanceType, int maskSize )
{
dst.create(src.size(), CV_32F);
CvMat _src = src, _dst = dst;
cvDistTransform(&_src, &_dst, distanceType, maskSize, 0, 0);
Mat src = _src.getMat();
_dst.create(src.size(), CV_32F);
Mat dst = _dst.getMat();
CvMat c_src = src, c_dst = _dst.getMat();
cvDistTransform(&c_src, &c_dst, distanceType, maskSize, 0, 0);
}
/* End of file. */
+16 -13
View File
@@ -1138,22 +1138,25 @@ icvDistC( const float *x, const float *y, void *user_param )
}
namespace cv
float cv::EMD( const InputArray& _signature1, const InputArray& _signature2,
int distType, const InputArray& _cost,
float* lowerBound, OutputArray _flow )
{
Mat signature1 = _signature1.getMat(), signature2 = _signature2.getMat();
Mat cost = _cost.getMat(), flow;
float EMD( const Mat& signature1, const Mat& signature2,
int distType, const Mat& cost, float* lowerBound, Mat* flow )
{
CvMat _signature1 = signature1;
CvMat _signature2 = signature2;
CvMat _cost = cost, _flow;
if( flow )
_flow = *flow;
CvMat _csignature1 = signature1;
CvMat _csignature2 = signature2;
CvMat _ccost = cost, _cflow;
if( _flow.needed() )
{
_flow.create((int)signature1.total(), (int)signature2.total(), CV_32F);
flow = _flow.getMat();
_cflow = flow;
}
return cvCalcEMD2( &_signature1, &_signature2, distType, 0, cost.empty() ? 0 : &_cost,
flow ? &_flow : 0, lowerBound, 0 );
}
return cvCalcEMD2( &_csignature1, &_csignature2, distType, 0, cost.empty() ? 0 : &_ccost,
_flow.needed() ? &_cflow : 0, lowerBound, 0 );
}
/* End of file. */
+13 -9
View File
@@ -50,13 +50,16 @@ template<typename T> struct greaterThanPtr
bool operator()(const T* a, const T* b) const { return *a > *b; }
};
void goodFeaturesToTrack( const Mat& image, vector<Point2f>& corners,
int maxCorners, double qualityLevel, double minDistance,
const Mat& mask, int blockSize,
bool useHarrisDetector, double harrisK )
}
void cv::goodFeaturesToTrack( const InputArray& _image, OutputArray _corners,
int maxCorners, double qualityLevel, double minDistance,
const InputArray& _mask, int blockSize,
bool useHarrisDetector, double harrisK )
{
Mat image = _image.getMat(), mask = _mask.getMat();
CV_Assert( qualityLevel > 0 && minDistance >= 0 && maxCorners >= 0 );
CV_Assert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == image.size()) );
Mat eig, tmp;
@@ -90,7 +93,7 @@ void goodFeaturesToTrack( const Mat& image, vector<Point2f>& corners,
}
sort( tmpCorners, greaterThanPtr<float>() );
corners.clear();
vector<Point2f> corners;
size_t i, j, total = tmpCorners.size(), ncorners = 0;
if(minDistance >= 1)
@@ -182,7 +185,10 @@ void goodFeaturesToTrack( const Mat& image, vector<Point2f>& corners,
break;
}
}
/*
Mat(corners).convertTo(_corners, _corners.fixedType() ? _corners.type() : CV_32F);
/*
for( i = 0; i < total; i++ )
{
int ofs = (int)((const uchar*)tmpCorners[i] - eig.data);
@@ -209,8 +215,6 @@ void goodFeaturesToTrack( const Mat& image, vector<Point2f>& corners,
}
*/
}
}
CV_IMPL void
cvGoodFeaturesToTrack( const void* _image, void*, void*,
+66 -45
View File
@@ -46,30 +46,16 @@
Base Image Filter
\****************************************************************************************/
namespace cv
{
BaseRowFilter::BaseRowFilter() { ksize = anchor = -1; }
BaseRowFilter::~BaseRowFilter() {}
BaseColumnFilter::BaseColumnFilter() { ksize = anchor = -1; }
BaseColumnFilter::~BaseColumnFilter() {}
void BaseColumnFilter::reset() {}
BaseFilter::BaseFilter() { ksize = Size(-1,-1); anchor = Point(-1,-1); }
BaseFilter::~BaseFilter() {}
void BaseFilter::reset() {}
/*
Various border types, image boundaries are denoted with '|'
* BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
* BORDER_REFLECT: fedcba|abcdefgh|hgfedcb
* BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba
* BORDER_WRAP: cdefgh|abcdefgh|abcdefg
* BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii with some specified 'i'
*/
int borderInterpolate( int p, int len, int borderType )
* BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
* BORDER_REFLECT: fedcba|abcdefgh|hgfedcb
* BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba
* BORDER_WRAP: cdefgh|abcdefgh|abcdefg
* BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii with some specified 'i'
*/
int cv::borderInterpolate( int p, int len, int borderType )
{
if( (unsigned)p < (unsigned)len )
;
@@ -104,6 +90,20 @@ int borderInterpolate( int p, int len, int borderType )
}
namespace cv
{
BaseRowFilter::BaseRowFilter() { ksize = anchor = -1; }
BaseRowFilter::~BaseRowFilter() {}
BaseColumnFilter::BaseColumnFilter() { ksize = anchor = -1; }
BaseColumnFilter::~BaseColumnFilter() {}
void BaseColumnFilter::reset() {}
BaseFilter::BaseFilter() { ksize = Size(-1,-1); anchor = Point(-1,-1); }
BaseFilter::~BaseFilter() {}
void BaseFilter::reset() {}
FilterEngine::FilterEngine()
{
srcType = dstType = bufType = -1;
@@ -454,13 +454,15 @@ void FilterEngine::apply(const Mat& src, Mat& dst,
dst.data + dstOfs.y*dst.step + dstOfs.x*dst.elemSize(), (int)dst.step );
}
}
/****************************************************************************************\
* Separable linear filter *
\****************************************************************************************/
int getKernelType(const Mat& _kernel, Point anchor)
int cv::getKernelType(const InputArray& __kernel, Point anchor)
{
Mat _kernel = __kernel.getMat();
CV_Assert( _kernel.channels() == 1 );
int i, sz = _kernel.rows*_kernel.cols;
@@ -495,6 +497,9 @@ int getKernelType(const Mat& _kernel, Point anchor)
}
namespace cv
{
struct RowNoVec
{
RowNoVec() {}
@@ -2527,10 +2532,13 @@ template<typename ST, typename DT> struct FixedPtCastEx
int SHIFT, DELTA;
};
Ptr<BaseRowFilter> getLinearRowFilter( int srcType, int bufType,
const Mat& kernel, int anchor,
int symmetryType )
}
cv::Ptr<cv::BaseRowFilter> cv::getLinearRowFilter( int srcType, int bufType,
const InputArray& _kernel, int anchor,
int symmetryType )
{
Mat kernel = _kernel.getMat();
int sdepth = CV_MAT_DEPTH(srcType), ddepth = CV_MAT_DEPTH(bufType);
int cn = CV_MAT_CN(srcType);
CV_Assert( cn == CV_MAT_CN(bufType) &&
@@ -2577,11 +2585,12 @@ Ptr<BaseRowFilter> getLinearRowFilter( int srcType, int bufType,
}
Ptr<BaseColumnFilter> getLinearColumnFilter( int bufType, int dstType,
const Mat& kernel, int anchor,
cv::Ptr<cv::BaseColumnFilter> cv::getLinearColumnFilter( int bufType, int dstType,
const InputArray& _kernel, int anchor,
int symmetryType, double delta,
int bits )
{
Mat kernel = _kernel.getMat();
int sdepth = CV_MAT_DEPTH(bufType), ddepth = CV_MAT_DEPTH(dstType);
int cn = CV_MAT_CN(dstType);
CV_Assert( cn == CV_MAT_CN(bufType) &&
@@ -2672,13 +2681,14 @@ Ptr<BaseColumnFilter> getLinearColumnFilter( int bufType, int dstType,
}
Ptr<FilterEngine> createSeparableLinearFilter(
cv::Ptr<cv::FilterEngine> cv::createSeparableLinearFilter(
int _srcType, int _dstType,
const Mat& _rowKernel, const Mat& _columnKernel,
const InputArray& __rowKernel, const InputArray& __columnKernel,
Point _anchor, double _delta,
int _rowBorderType, int _columnBorderType,
const Scalar& _borderValue )
{
Mat _rowKernel = __rowKernel.getMat(), _columnKernel = __columnKernel.getMat();
_srcType = CV_MAT_TYPE(_srcType);
_dstType = CV_MAT_TYPE(_dstType);
int sdepth = CV_MAT_DEPTH(_srcType), ddepth = CV_MAT_DEPTH(_dstType);
@@ -2742,6 +2752,9 @@ Ptr<FilterEngine> createSeparableLinearFilter(
* Non-separable linear filter *
\****************************************************************************************/
namespace cv
{
void preprocess2DKernel( const Mat& kernel, vector<Point>& coords, vector<uchar>& coeffs )
{
int i, j, k, nz = countNonZero(kernel), ktype = kernel.type();
@@ -2868,11 +2881,13 @@ template<typename ST, class CastOp, class VecOp> struct Filter2D : public BaseFi
VecOp vecOp;
};
}
Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
const Mat& _kernel, Point anchor,
cv::Ptr<cv::BaseFilter> cv::getLinearFilter(int srcType, int dstType,
const InputArray& __kernel, Point anchor,
double delta, int bits)
{
Mat _kernel = __kernel.getMat();
int sdepth = CV_MAT_DEPTH(srcType), ddepth = CV_MAT_DEPTH(dstType);
int cn = CV_MAT_CN(srcType), kdepth = _kernel.depth();
CV_Assert( cn == CV_MAT_CN(dstType) && ddepth >= sdepth );
@@ -2946,11 +2961,13 @@ Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
}
Ptr<FilterEngine> createLinearFilter( int _srcType, int _dstType, const Mat& _kernel,
Point _anchor, double _delta,
int _rowBorderType, int _columnBorderType,
const Scalar& _borderValue )
cv::Ptr<cv::FilterEngine> cv::createLinearFilter( int _srcType, int _dstType,
const InputArray& __kernel,
Point _anchor, double _delta,
int _rowBorderType, int _columnBorderType,
const Scalar& _borderValue )
{
Mat _kernel = __kernel.getMat();
_srcType = CV_MAT_TYPE(_srcType);
_dstType = CV_MAT_TYPE(_dstType);
int cn = CV_MAT_CN(_srcType);
@@ -2977,10 +2994,12 @@ Ptr<FilterEngine> createLinearFilter( int _srcType, int _dstType, const Mat& _ke
}
void filter2D( const Mat& src, Mat& dst, int ddepth,
const Mat& kernel, Point anchor,
double delta, int borderType )
void cv::filter2D( const InputArray& _src, OutputArray _dst, int ddepth,
const InputArray& _kernel, Point anchor,
double delta, int borderType )
{
Mat src = _src.getMat(), kernel = _kernel.getMat();
if( ddepth < 0 )
ddepth = src.depth();
@@ -2991,7 +3010,8 @@ void filter2D( const Mat& src, Mat& dst, int ddepth,
int dft_filter_size = 50;
#endif
dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
_dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
Mat dst = _dst.getMat();
anchor = normalizeAnchor(anchor, kernel.size());
if( kernel.cols*kernel.rows >= dft_filter_size )
@@ -3015,22 +3035,23 @@ void filter2D( const Mat& src, Mat& dst, int ddepth,
}
void sepFilter2D( const Mat& src, Mat& dst, int ddepth,
const Mat& kernelX, const Mat& kernelY, Point anchor,
double delta, int borderType )
void cv::sepFilter2D( const InputArray& _src, OutputArray _dst, int ddepth,
const InputArray& _kernelX, const InputArray& _kernelY, Point anchor,
double delta, int borderType )
{
Mat src = _src.getMat(), kernelX = _kernelX.getMat(), kernelY = _kernelY.getMat();
if( ddepth < 0 )
ddepth = src.depth();
dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
_dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
Mat dst = _dst.getMat();
Ptr<FilterEngine> f = createSeparableLinearFilter(src.type(),
dst.type(), kernelX, kernelY, anchor, delta, borderType & ~BORDER_ISOLATED );
f->apply(src, dst, Rect(0,0,-1,-1), Point(), (borderType & BORDER_ISOLATED) != 0 );
}
}
CV_IMPL void
cvFilter2D( const CvArr* srcarr, CvArr* dstarr, const CvMat* _kernel, CvPoint anchor )
+6 -6
View File
@@ -1114,25 +1114,25 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
}
int cv::floodFill( Mat& image, Point seedPoint,
int cv::floodFill( InputOutputArray _image, Point seedPoint,
Scalar newVal, Rect* rect,
Scalar loDiff, Scalar upDiff, int flags )
{
CvConnectedComp ccomp;
CvMat _image = image;
cvFloodFill(&_image, seedPoint, newVal, loDiff, upDiff, &ccomp, flags, 0);
CvMat c_image = _image.getMat();
cvFloodFill(&c_image, seedPoint, newVal, loDiff, upDiff, &ccomp, flags, 0);
if( rect )
*rect = ccomp.rect;
return cvRound(ccomp.area);
}
int cv::floodFill( Mat& image, Mat& mask,
int cv::floodFill( InputOutputArray _image, InputOutputArray _mask,
Point seedPoint, Scalar newVal, Rect* rect,
Scalar loDiff, Scalar upDiff, int flags )
{
CvConnectedComp ccomp;
CvMat _image = image, _mask = mask;
cvFloodFill(&_image, seedPoint, newVal, loDiff, upDiff, &ccomp, flags, &_mask);
CvMat c_image = _image.getMat(), c_mask = _mask.getMat();
cvFloodFill(&c_image, seedPoint, newVal, loDiff, upDiff, &ccomp, flags, &c_mask);
if( rect )
*rect = ccomp.rect;
return cvRound(ccomp.area);
+10 -5
View File
@@ -375,10 +375,10 @@ void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM )
CV_Assert( !bgdSamples.empty() && !fgdSamples.empty() );
Mat _bgdSamples( (int)bgdSamples.size(), 3, CV_32FC1, &bgdSamples[0][0] );
kmeans( _bgdSamples, GMM::componentsCount, bgdLabels,
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType, 0 );
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
Mat _fgdSamples( (int)fgdSamples.size(), 3, CV_32FC1, &fgdSamples[0][0] );
kmeans( _fgdSamples, GMM::componentsCount, fgdLabels,
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType, 0 );
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
bgdGMM.initLearning();
for( int i = 0; i < (int)bgdSamples.size(); i++ )
@@ -521,10 +521,15 @@ void estimateSegmentation( GCGraph<double>& graph, Mat& mask )
}
}
void cv::grabCut( const Mat& img, Mat& mask, Rect rect,
Mat& bgdModel, Mat& fgdModel,
int iterCount, int mode )
void cv::grabCut( const InputArray& _img, InputOutputArray _mask, Rect rect,
InputOutputArray _bgdModel, InputOutputArray _fgdModel,
int iterCount, int mode )
{
Mat img = _img.getMat();
Mat& mask = _mask.getMatRef();
Mat& bgdModel = _bgdModel.getMatRef();
Mat& fgdModel = _fgdModel.getMatRef();
if( img.empty() )
CV_Error( CV_StsBadArg, "image is empty" );
if( img.type() != CV_8UC3 )
+64 -48
View File
@@ -43,6 +43,10 @@
namespace cv
{
template<> void Ptr<CvHistogram>::delete_obj()
{ cvReleaseHist(&obj); }
////////////////// Helper functions //////////////////////
static const size_t OUT_OF_RANGE = (size_t)1 << (sizeof(size_t)*8 - 2);
@@ -586,18 +590,22 @@ calcHist_8u( vector<uchar*>& _ptrs, const vector<int>& _deltas,
}
}
}
void calcHist( const Mat* images, int nimages, const int* channels,
const Mat& mask, Mat& hist, int dims, const int* histSize,
const float** ranges, bool uniform, bool accumulate )
void cv::calcHist( const Mat* images, int nimages, const int* channels,
const InputArray& _mask, OutputArray _hist, int dims, const int* histSize,
const float** ranges, bool uniform, bool accumulate )
{
Mat mask = _mask.getMat();
CV_Assert(dims > 0 && histSize);
hist.create(dims, histSize, CV_32F);
Mat ihist = hist;
uchar* histdata = _hist.getMat().data;
_hist.create(dims, histSize, CV_32F);
Mat hist = _hist.getMat(), ihist = hist;
ihist.flags = (ihist.flags & ~CV_MAT_TYPE_MASK)|CV_32S;
if( !accumulate )
if( !accumulate || histdata != hist.data )
hist = Scalar(0.);
else
hist.convertTo(ihist, CV_32S);
@@ -626,7 +634,9 @@ void calcHist( const Mat* images, int nimages, const int* channels,
ihist.convertTo(hist, CV_32F);
}
namespace cv
{
template<typename T> static void
calcSparseHist_( vector<uchar*>& _ptrs, const vector<int>& _deltas,
Size imsize, SparseMat& hist, int dims, const float** _ranges,
@@ -803,11 +813,13 @@ static void calcHist( const Mat* images, int nimages, const int* channels,
}
}
}
void calcHist( const Mat* images, int nimages, const int* channels,
const Mat& mask, SparseMat& hist, int dims, const int* histSize,
void cv::calcHist( const Mat* images, int nimages, const int* channels,
const InputArray& _mask, SparseMat& hist, int dims, const int* histSize,
const float** ranges, bool uniform, bool accumulate )
{
Mat mask = _mask.getMat();
calcHist( images, nimages, channels, mask, hist, dims, histSize,
ranges, uniform, accumulate, false );
}
@@ -815,6 +827,8 @@ void calcHist( const Mat* images, int nimages, const int* channels,
/////////////////////////////////////// B A C K P R O J E C T ////////////////////////////////////
namespace cv
{
template<typename T, typename BT> static void
calcBackProj_( vector<uchar*>& _ptrs, const vector<int>& _deltas,
@@ -1102,12 +1116,14 @@ calcBackProj_8u( vector<uchar*>& _ptrs, const vector<int>& _deltas,
}
}
}
}
void calcBackProject( const Mat* images, int nimages, const int* channels,
const Mat& hist, Mat& backProject,
const float** ranges, double scale, bool uniform )
void cv::calcBackProject( const Mat* images, int nimages, const int* channels,
const InputArray& _hist, OutputArray _backProject,
const float** ranges, double scale, bool uniform )
{
Mat hist = _hist.getMat();
vector<uchar*> ptrs;
vector<int> deltas;
vector<double> uniranges;
@@ -1115,7 +1131,8 @@ void calcBackProject( const Mat* images, int nimages, const int* channels,
int dims = hist.dims == 2 && hist.size[1] == 1 ? 1 : hist.dims;
CV_Assert( dims > 0 && hist.data );
backProject.create( images[0].size(), images[0].depth() );
_backProject.create( images[0].size(), images[0].depth() );
Mat backProject = _backProject.getMat();
histPrepareImages( images, nimages, channels, backProject, dims, hist.size, ranges,
uniform, ptrs, deltas, imsize, uniranges );
const double* _uniranges = uniform ? &uniranges[0] : 0;
@@ -1131,7 +1148,10 @@ void calcBackProject( const Mat* images, int nimages, const int* channels,
CV_Error(CV_StsUnsupportedFormat, "");
}
namespace cv
{
template<typename T, typename BT> static void
calcSparseBackProj_( vector<uchar*>& _ptrs, const vector<int>& _deltas,
Size imsize, const SparseMat& hist, int dims, const float** _ranges,
@@ -1259,11 +1279,12 @@ calcSparseBackProj_8u( vector<uchar*>& _ptrs, const vector<int>& _deltas,
ptrs[i] += deltas[i*2 + 1];
}
}
void calcBackProject( const Mat* images, int nimages, const int* channels,
const SparseMat& hist, Mat& backProject,
const float** ranges, double scale, bool uniform )
}
void cv::calcBackProject( const Mat* images, int nimages, const int* channels,
const SparseMat& hist, Mat& backProject,
const float** ranges, double scale, bool uniform )
{
vector<uchar*> ptrs;
vector<int> deltas;
@@ -1295,13 +1316,14 @@ void calcBackProject( const Mat* images, int nimages, const int* channels,
////////////////// C O M P A R E H I S T O G R A M S ////////////////////////
double compareHist( const Mat& H1, const Mat& H2, int method )
double cv::compareHist( const InputArray& _H1, const InputArray& _H2, int method )
{
Mat H1 = _H1.getMat(), H2 = _H2.getMat();
const Mat* arrays[] = {&H1, &H2, 0};
Mat planes[2];
NAryMatIterator it(arrays, planes);
double result = 0;
int i, len;
int j, len = (int)it.size;
CV_Assert( H1.type() == H2.type() && H1.type() == CV_32F );
@@ -1309,7 +1331,7 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
CV_Assert( it.planes[0].isContinuous() && it.planes[1].isContinuous() );
for( i = 0; i < it.nplanes; i++, ++it )
for( size_t i = 0; i < it.nplanes; i++, ++it )
{
const float* h1 = (const float*)it.planes[0].data;
const float* h2 = (const float*)it.planes[1].data;
@@ -1317,20 +1339,20 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
if( method == CV_COMP_CHISQR )
{
for( i = 0; i < len; i++ )
for( j = 0; j < len; j++ )
{
double a = h1[i] - h2[i];
double b = h1[i] + h2[i];
double a = h1[j] - h2[j];
double b = h1[j] + h2[j];
if( fabs(b) > FLT_EPSILON )
result += a*a/b;
}
}
else if( method == CV_COMP_CORREL )
{
for( i = 0; i < len; i++ )
for( j = 0; j < len; j++ )
{
double a = h1[i];
double b = h2[i];
double a = h1[j];
double b = h2[j];
s12 += a*b;
s1 += a;
@@ -1341,15 +1363,15 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
}
else if( method == CV_COMP_INTERSECT )
{
for( i = 0; i < len; i++ )
result += std::min(h1[i], h2[i]);
for( j = 0; j < len; j++ )
result += std::min(h1[j], h2[j]);
}
else if( method == CV_COMP_BHATTACHARYYA )
{
for( i = 0; i < len; i++ )
for( j = 0; j < len; j++ )
{
double a = h1[i];
double b = h2[i];
double a = h1[j];
double b = h2[j];
result += std::sqrt(a*b);
s1 += a;
s2 += b;
@@ -1361,9 +1383,7 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
if( method == CV_COMP_CORREL )
{
size_t total = 1;
for( i = 0; i < H1.dims; i++ )
total *= H1.size[i];
size_t total = H1.total();
double scale = 1./total;
double num = s12 - s1*s2*scale;
double denom2 = (s11 - s1*s1*scale)*(s22 - s2*s2*scale);
@@ -1380,7 +1400,7 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
}
double compareHist( const SparseMat& H1, const SparseMat& H2, int method )
double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
{
double result = 0;
int i, dims = H1.dims();
@@ -1491,12 +1511,6 @@ double compareHist( const SparseMat& H1, const SparseMat& H2, int method )
}
template<> void Ptr<CvHistogram>::delete_obj()
{ cvReleaseHist(&obj); }
}
const int CV_HIST_DEFAULT_TYPE = CV_32F;
/* Creates new histogram */
@@ -2395,11 +2409,13 @@ CV_IMPL void cvEqualizeHist( const CvArr* srcarr, CvArr* dstarr )
}
void cv::equalizeHist( const Mat& src, Mat& dst )
void cv::equalizeHist( const InputArray& _src, OutputArray _dst )
{
dst.create( src.size(), src.type() );
CvMat _src = src, _dst = dst;
cvEqualizeHist( &_src, &_dst );
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
CvMat _csrc = src, _cdst = dst;
cvEqualizeHist( &_csrc, &_cdst );
}
/* Implementation of RTTI and Generic Functions for CvHistogram */
+36 -27
View File
@@ -1090,44 +1090,53 @@ namespace cv
const int STORAGE_SIZE = 1 << 12;
void HoughLines( const Mat& image, vector<Vec2f>& lines,
double rho, double theta, int threshold,
double srn, double stn )
static void seqToMat(const CvSeq* seq, OutputArray& _arr)
{
CvMemStorage* storage = cvCreateMemStorage(STORAGE_SIZE);
CvMat _image = image;
CvSeq* seq = cvHoughLines2( &_image, storage, srn == 0 && stn == 0 ?
if( seq )
{
_arr.create(1, seq->total, seq->flags, -1, true);
Mat arr = _arr.getMat();
cvCvtSeqToArray(seq, arr.data);
}
else
_arr.release();
}
}
void cv::HoughLines( const InputArray& _image, OutputArray _lines,
double rho, double theta, int threshold,
double srn, double stn )
{
Ptr<CvMemStorage> storage = cvCreateMemStorage(STORAGE_SIZE);
CvMat c_image = _image.getMat();
CvSeq* seq = cvHoughLines2( &c_image, storage, srn == 0 && stn == 0 ?
CV_HOUGH_STANDARD : CV_HOUGH_MULTI_SCALE,
rho, theta, threshold, srn, stn );
Seq<Vec2f>(seq).copyTo(lines);
cvReleaseMemStorage(&storage);
seqToMat(seq, _lines);
}
void HoughLinesP( Mat& image, vector<Vec4i>& lines,
double rho, double theta, int threshold,
double minLineLength, double maxGap )
void cv::HoughLinesP( const InputArray& _image, OutputArray _lines,
double rho, double theta, int threshold,
double minLineLength, double maxGap )
{
CvMemStorage* storage = cvCreateMemStorage(STORAGE_SIZE);
CvMat _image = image;
CvSeq* seq = cvHoughLines2( &_image, storage, CV_HOUGH_PROBABILISTIC,
Ptr<CvMemStorage> storage = cvCreateMemStorage(STORAGE_SIZE);
CvMat c_image = _image.getMat();
CvSeq* seq = cvHoughLines2( &c_image, storage, CV_HOUGH_PROBABILISTIC,
rho, theta, threshold, minLineLength, maxGap );
Seq<Vec4i>(seq).copyTo(lines);
cvReleaseMemStorage(&storage);
seqToMat(seq, _lines);
}
void HoughCircles( const Mat& image, vector<Vec3f>& circles,
int method, double dp, double min_dist,
double param1, double param2,
int minRadius, int maxRadius )
void cv::HoughCircles( const InputArray& _image, OutputArray _circles,
int method, double dp, double min_dist,
double param1, double param2,
int minRadius, int maxRadius )
{
CvMemStorage* storage = cvCreateMemStorage(STORAGE_SIZE);
CvMat _image = image;
CvSeq* seq = cvHoughCircles( &_image, storage, method,
Ptr<CvMemStorage> storage = cvCreateMemStorage(STORAGE_SIZE);
CvMat c_image = _image.getMat();
CvSeq* seq = cvHoughCircles( &c_image, storage, method,
dp, min_dist, param1, param2, minRadius, maxRadius );
Seq<Vec3f>(seq).copyTo(circles);
cvReleaseMemStorage(&storage);
}
seqToMat(seq, _circles);
}
/* End of file. */
+52 -24
View File
@@ -1313,10 +1313,12 @@ typedef void (*ResizeAreaFastFunc)( const Mat& src, Mat& dst,
typedef void (*ResizeAreaFunc)( const Mat& src, Mat& dst,
const DecimateAlpha* xofs, int xofs_count );
}
//////////////////////////////////////////////////////////////////////////////////////////
void resize( const Mat& src, Mat& dst, Size dsize,
double inv_scale_x, double inv_scale_y, int interpolation )
void cv::resize( const InputArray& _src, OutputArray _dst, Size dsize,
double inv_scale_x, double inv_scale_y, int interpolation )
{
static ResizeFunc linear_tab[] =
{
@@ -1420,6 +1422,7 @@ void resize( const Mat& src, Mat& dst, Size dsize,
0, resizeArea_<float, float>, resizeArea_<double, double>, 0
};
Mat src = _src.getMat();
Size ssize = src.size();
CV_Assert( ssize.area() > 0 );
@@ -1434,7 +1437,8 @@ void resize( const Mat& src, Mat& dst, Size dsize,
inv_scale_x = (double)dsize.width/src.cols;
inv_scale_y = (double)dsize.height/src.rows;
}
dst.create(dsize, src.type());
_dst.create(dsize, src.type());
Mat dst = _dst.getMat();
int depth = src.depth(), cn = src.channels();
double scale_x = 1./inv_scale_x, scale_y = 1./inv_scale_y;
@@ -1653,6 +1657,9 @@ void resize( const Mat& src, Mat& dst, Size dsize,
* General warping (affine, perspective, remap) *
\****************************************************************************************/
namespace cv
{
template<typename T>
static void remapNearest( const Mat& _src, Mat& _dst, const Mat& _xy,
int borderType, const Scalar& _borderValue )
@@ -2392,8 +2399,11 @@ typedef void (*RemapFunc)(const Mat& _src, Mat& _dst, const Mat& _xy,
const Mat& _fxy, const void* _wtab,
int borderType, const Scalar& _borderValue);
void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2,
int interpolation, int borderType, const Scalar& borderValue )
}
void cv::remap( const InputArray& _src, OutputArray _dst,
const InputArray& _map1, const InputArray& _map2,
int interpolation, int borderType, const Scalar& borderValue )
{
static RemapNNFunc nn_tab[] =
{
@@ -2425,8 +2435,12 @@ void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2,
remapLanczos4<Cast<float, float>, float, 1>, 0, 0
};
Mat src = _src.getMat(), map1 = _map1.getMat(), map2 = _map2.getMat();
CV_Assert( (!map2.data || map2.size() == map1.size()));
dst.create( map1.size(), src.type() );
_dst.create( map1.size(), src.type() );
Mat dst = _dst.getMat();
CV_Assert(dst.data != src.data);
int depth = src.depth(), map_depth = map1.depth();
@@ -2650,9 +2664,11 @@ void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2,
}
void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2,
int dstm1type, bool nninterpolate )
void cv::convertMaps( const InputArray& _map1, const InputArray& _map2,
OutputArray _dstmap1, OutputArray _dstmap2,
int dstm1type, bool nninterpolate )
{
Mat map1 = _map1.getMat(), map2 = _map2.getMat(), dstmap1, dstmap2;
Size size = map1.size();
const Mat *m1 = &map1, *m2 = &map2;
int m1type = m1->type(), m2type = m2->type();
@@ -2671,11 +2687,16 @@ void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2,
if( dstm1type <= 0 )
dstm1type = m1type == CV_16SC2 ? CV_32FC2 : CV_16SC2;
CV_Assert( dstm1type == CV_16SC2 || dstm1type == CV_32FC1 || dstm1type == CV_32FC2 );
dstmap1.create( size, dstm1type );
_dstmap1.create( size, dstm1type );
dstmap1 = _dstmap1.getMat();
if( !nninterpolate && dstm1type != CV_32FC2 )
dstmap2.create( size, dstm1type == CV_16SC2 ? CV_16UC1 : CV_32FC1 );
{
_dstmap2.create( size, dstm1type == CV_16SC2 ? CV_16UC1 : CV_32FC1 );
dstmap2 = _dstmap2.getMat();
}
else
dstmap2.release();
_dstmap2.release();
if( m1type == dstm1type || (nninterpolate &&
((m1type == CV_16SC2 && dstm1type == CV_32FC2) ||
@@ -2782,10 +2803,13 @@ void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2,
}
void warpAffine( const Mat& src, Mat& dst, const Mat& M0, Size dsize,
int flags, int borderType, const Scalar& borderValue )
void cv::warpAffine( const InputArray& _src, OutputArray _dst,
const InputArray& _M0, Size dsize,
int flags, int borderType, const Scalar& borderValue )
{
dst.create( dsize, src.type() );
Mat src = _src.getMat(), M0 = _M0.getMat();
_dst.create( dsize, src.type() );
Mat dst = _dst.getMat();
CV_Assert( dst.data != src.data && src.cols > 0 && src.rows > 0 );
const int BLOCK_SZ = 64;
@@ -2917,10 +2941,13 @@ void warpAffine( const Mat& src, Mat& dst, const Mat& M0, Size dsize,
}
void warpPerspective( const Mat& src, Mat& dst, const Mat& M0, Size dsize,
int flags, int borderType, const Scalar& borderValue )
void cv::warpPerspective( const InputArray& _src, OutputArray _dst, const InputArray& _M0,
Size dsize, int flags, int borderType, const Scalar& borderValue )
{
dst.create( dsize, src.type() );
Mat src = _src.getMat(), M0 = _M0.getMat();
_dst.create( dsize, src.type() );
Mat dst = _dst.getMat();
CV_Assert( dst.data != src.data && src.cols > 0 && src.rows > 0 );
const int BLOCK_SZ = 32;
@@ -2999,7 +3026,7 @@ void warpPerspective( const Mat& src, Mat& dst, const Mat& M0, Size dsize,
}
Mat getRotationMatrix2D( Point2f center, double angle, double scale )
cv::Mat cv::getRotationMatrix2D( Point2f center, double angle, double scale )
{
angle *= CV_PI/180;
double alpha = cos(angle)*scale;
@@ -3042,7 +3069,7 @@ Mat getRotationMatrix2D( Point2f center, double angle, double scale )
* where:
* cij - matrix coefficients, c22 = 1
*/
Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] )
cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] )
{
Mat M(3, 3, CV_64F), X(8, 1, CV_64F, M.data);
double a[8][8], b[8];
@@ -3087,7 +3114,7 @@ Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] )
* where:
* cij - matrix coefficients
*/
Mat getAffineTransform( const Point2f src[], const Point2f dst[] )
cv::Mat cv::getAffineTransform( const Point2f src[], const Point2f dst[] )
{
Mat M(2, 3, CV_64F), X(6, 1, CV_64F, M.data);
double a[6*6], b[6];
@@ -3110,10 +3137,13 @@ Mat getAffineTransform( const Point2f src[], const Point2f dst[] )
return M;
}
void invertAffineTransform(const Mat& matM, Mat& _iM)
void cv::invertAffineTransform(const InputArray& _matM, OutputArray __iM)
{
Mat matM = _matM.getMat();
CV_Assert(matM.rows == 2 && matM.cols == 3);
_iM.create(2, 3, matM.type());
__iM.create(2, 3, matM.type());
Mat _iM = __iM.getMat();
if( matM.type() == CV_32F )
{
const float* M = (const float*)matM.data;
@@ -3148,8 +3178,6 @@ void invertAffineTransform(const Mat& matM, Mat& _iM)
CV_Error( CV_StsUnsupportedFormat, "" );
}
}
CV_IMPL void
cvResize( const CvArr* srcarr, CvArr* dstarr, int method )
{
+5 -4
View File
@@ -807,10 +807,11 @@ cvInpaint( const CvArr* _input_img, const CvArr* _inpaint_mask, CvArr* _output_i
}
}
void cv::inpaint( const Mat& src, const Mat& mask, Mat& dst,
void cv::inpaint( const InputArray& _src, const InputArray& _mask, OutputArray _dst,
double inpaintRange, int flags )
{
dst.create( src.size(), src.type() );
CvMat _src = src, _mask = mask, _dst = dst;
cvInpaint( &_src, &_mask, &_dst, inpaintRange, flags );
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
CvMat c_src = src, c_mask = _mask.getMat(), c_dst = _dst.getMat();
cvInpaint( &c_src, &c_mask, &c_dst, inpaintRange, flags );
}
+4 -3
View File
@@ -601,13 +601,14 @@ Moments::operator CvMoments() const
return m;
}
}
cv::Moments cv::moments( const Mat& array, bool binaryImage )
cv::Moments cv::moments( const InputArray& _array, bool binaryImage )
{
CvMoments om;
CvMat _array = array;
cvMoments(&_array, &om, binaryImage);
CvMat c_array = _array.getMat();
cvMoments(&c_array, &om, binaryImage);
return om;
}
+39 -32
View File
@@ -821,10 +821,12 @@ template<class Op, class VecOp> struct MorphFilter : BaseFilter
vector<uchar*> ptrs;
VecOp vecOp;
};
}
/////////////////////////////////// External Interface /////////////////////////////////////
Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor)
cv::Ptr<cv::BaseRowFilter> cv::getMorphologyRowFilter(int op, int type, int ksize, int anchor)
{
int depth = CV_MAT_DEPTH(type);
if( anchor < 0 )
@@ -865,7 +867,7 @@ Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int ancho
return Ptr<BaseRowFilter>(0);
}
Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int anchor)
cv::Ptr<cv::BaseColumnFilter> cv::getMorphologyColumnFilter(int op, int type, int ksize, int anchor)
{
int depth = CV_MAT_DEPTH(type);
if( anchor < 0 )
@@ -907,8 +909,9 @@ Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int
}
Ptr<BaseFilter> getMorphologyFilter(int op, int type, const Mat& kernel, Point anchor)
cv::Ptr<cv::BaseFilter> cv::getMorphologyFilter(int op, int type, const InputArray& _kernel, Point anchor)
{
Mat kernel = _kernel.getMat();
int depth = CV_MAT_DEPTH(type);
anchor = normalizeAnchor(anchor, kernel.size());
CV_Assert( op == MORPH_ERODE || op == MORPH_DILATE );
@@ -940,10 +943,11 @@ Ptr<BaseFilter> getMorphologyFilter(int op, int type, const Mat& kernel, Point a
}
Ptr<FilterEngine> createMorphologyFilter( int op, int type, const Mat& kernel,
cv::Ptr<cv::FilterEngine> cv::createMorphologyFilter( int op, int type, const InputArray& _kernel,
Point anchor, int _rowBorderType, int _columnBorderType,
const Scalar& _borderValue )
{
Mat kernel = _kernel.getMat();
anchor = normalizeAnchor(anchor, kernel.size());
Ptr<BaseRowFilter> rowFilter;
@@ -978,7 +982,7 @@ Ptr<FilterEngine> createMorphologyFilter( int op, int type, const Mat& kernel,
}
Mat getStructuringElement(int shape, Size ksize, Point anchor)
cv::Mat cv::getStructuringElement(int shape, Size ksize, Point anchor)
{
int i, j;
int r = 0, c = 0;
@@ -1031,31 +1035,36 @@ Mat getStructuringElement(int shape, Size ksize, Point anchor)
return elem;
}
static void morphOp( int op, const Mat& src, Mat& dst, const Mat& _kernel,
namespace cv
{
static void morphOp( int op, const InputArray& _src, OutputArray& _dst,
const InputArray& _kernel,
Point anchor, int iterations,
int borderType, const Scalar& borderValue )
{
Mat kernel;
Size ksize = _kernel.data ? _kernel.size() : Size(3,3);
Mat src = _src.getMat(), kernel = _kernel.getMat();
Size ksize = kernel.data ? kernel.size() : Size(3,3);
anchor = normalizeAnchor(anchor, ksize);
CV_Assert( anchor.inside(Rect(0, 0, ksize.width, ksize.height)) );
if( iterations == 0 || _kernel.rows*_kernel.cols == 1 )
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
if( iterations == 0 || kernel.rows*kernel.cols == 1 )
{
src.copyTo(dst);
return;
}
dst.create( src.size(), src.type() );
if( !_kernel.data )
if( !kernel.data )
{
kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2));
anchor = Point(iterations, iterations);
iterations = 1;
}
else if( iterations > 1 && countNonZero(_kernel) == _kernel.rows*_kernel.cols )
else if( iterations > 1 && countNonZero(kernel) == kernel.rows*kernel.cols )
{
anchor = Point(anchor.x*iterations, anchor.y*iterations);
kernel = getStructuringElement(MORPH_RECT,
@@ -1064,8 +1073,6 @@ static void morphOp( int op, const Mat& src, Mat& dst, const Mat& _kernel,
anchor);
iterations = 1;
}
else
kernel = _kernel;
Ptr<FilterEngine> f = createMorphologyFilter(op, src.type(),
kernel, anchor, borderType, borderType, borderValue );
@@ -1074,29 +1081,36 @@ static void morphOp( int op, const Mat& src, Mat& dst, const Mat& _kernel,
for( int i = 1; i < iterations; i++ )
f->apply( dst, dst );
}
template<> void Ptr<IplConvKernel>::delete_obj()
{ cvReleaseStructuringElement(&obj); }
}
void erode( const Mat& src, Mat& dst, const Mat& kernel,
Point anchor, int iterations,
int borderType, const Scalar& borderValue )
void cv::erode( const InputArray& src, OutputArray dst, const InputArray& kernel,
Point anchor, int iterations,
int borderType, const Scalar& borderValue )
{
morphOp( MORPH_ERODE, src, dst, kernel, anchor, iterations, borderType, borderValue );
}
void dilate( const Mat& src, Mat& dst, const Mat& kernel,
Point anchor, int iterations,
int borderType, const Scalar& borderValue )
void cv::dilate( const InputArray& src, OutputArray dst, const InputArray& kernel,
Point anchor, int iterations,
int borderType, const Scalar& borderValue )
{
morphOp( MORPH_DILATE, src, dst, kernel, anchor, iterations, borderType, borderValue );
}
void morphologyEx( const Mat& src, Mat& dst, int op, const Mat& kernel,
Point anchor, int iterations, int borderType,
const Scalar& borderValue )
void cv::morphologyEx( const InputArray& _src, OutputArray _dst, int op,
const InputArray& kernel, Point anchor, int iterations,
int borderType, const Scalar& borderValue )
{
Mat temp;
Mat src = _src.getMat(), temp;
_dst.create(src.size(), src.type());
Mat dst = _dst.getMat();
switch( op )
{
case MORPH_ERODE:
@@ -1137,13 +1151,6 @@ void morphologyEx( const Mat& src, Mat& dst, int op, const Mat& kernel,
}
}
template<> void Ptr<IplConvKernel>::delete_obj()
{ cvReleaseStructuringElement(&obj); }
}
CV_IMPL IplConvKernel *
cvCreateStructuringElementEx( int cols, int rows,
int anchorX, int anchorY,
+21 -16
View File
@@ -399,11 +399,15 @@ pyrUp_( const Mat& _src, Mat& _dst )
typedef void (*PyrFunc)(const Mat&, Mat&);
void pyrDown( const Mat& _src, Mat& _dst, const Size& _dsz )
}
void cv::pyrDown( const InputArray& _src, OutputArray _dst, const Size& _dsz )
{
Size dsz = _dsz == Size() ? Size((_src.cols + 1)/2, (_src.rows + 1)/2) : _dsz;
_dst.create( dsz, _src.type() );
int depth = _src.depth();
Mat src = _src.getMat();
Size dsz = _dsz == Size() ? Size((src.cols + 1)/2, (src.rows + 1)/2) : _dsz;
_dst.create( dsz, src.type() );
Mat dst = _dst.getMat();
int depth = src.depth();
PyrFunc func = 0;
if( depth == CV_8U )
func = pyrDown_<FixPtCast<uchar, 8>, PyrDownVec_32s8u>;
@@ -416,14 +420,16 @@ void pyrDown( const Mat& _src, Mat& _dst, const Size& _dsz )
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( _src, _dst );
func( src, dst );
}
void pyrUp( const Mat& _src, Mat& _dst, const Size& _dsz )
void cv::pyrUp( const InputArray& _src, OutputArray _dst, const Size& _dsz )
{
Size dsz = _dsz == Size() ? Size(_src.cols*2, _src.rows*2) : _dsz;
_dst.create( dsz, _src.type() );
int depth = _src.depth();
Mat src = _src.getMat();
Size dsz = _dsz == Size() ? Size(src.cols*2, src.rows*2) : _dsz;
_dst.create( dsz, src.type() );
Mat dst = _dst.getMat();
int depth = src.depth();
PyrFunc func = 0;
if( depth == CV_8U )
func = pyrUp_<FixPtCast<uchar, 6>, NoVec<int, uchar> >;
@@ -436,17 +442,16 @@ void pyrUp( const Mat& _src, Mat& _dst, const Size& _dsz )
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( _src, _dst );
func( src, dst );
}
void buildPyramid( const Mat& _src, vector<Mat>& _dst, int maxlevel )
void cv::buildPyramid( const InputArray& _src, OutputArrayOfArrays _dst, int maxlevel )
{
_dst.resize( maxlevel + 1 );
_dst[0] = _src;
Mat src = _src.getMat();
_dst.create( maxlevel + 1, 1, 0 );
_dst.getMatRef(0) = src;
for( int i = 1; i <= maxlevel; i++ )
pyrDown( _dst[i-1], _dst[i] );
}
pyrDown( _dst.getMatRef(i-1), _dst.getMatRef(i) );
}
CV_IMPL void cvPyrDown( const void* srcarr, void* dstarr, int _filter )
+7 -5
View File
@@ -868,13 +868,15 @@ cvGetQuadrangleSubPix( const void* srcarr, void* dstarr, const CvMat* mat )
}
void cv::getRectSubPix( const Mat& image, Size patchSize, Point2f center,
Mat& patch, int patchType )
void cv::getRectSubPix( const InputArray& _image, Size patchSize, Point2f center,
OutputArray _patch, int patchType )
{
patch.create(patchSize, patchType < 0 ? image.type() :
Mat image = _image.getMat();
_patch.create(patchSize, patchType < 0 ? image.type() :
CV_MAKETYPE(CV_MAT_DEPTH(patchType),image.channels()));
CvMat _image = image, _patch = patch;
cvGetRectSubPix(&_image, &_patch, center);
Mat patch = _patch.getMat();
CvMat _cimage = image, _cpatch = patch;
cvGetRectSubPix(&_cimage, &_cpatch, center);
}
/* End of file. */
+9 -7
View File
@@ -303,10 +303,10 @@ cvWatershed( const CvArr* srcarr, CvArr* dstarr )
}
void cv::watershed( const Mat& src, Mat& markers )
void cv::watershed( const InputArray& src, InputOutputArray markers )
{
CvMat _src = src, _markers = markers;
cvWatershed( &_src, &_markers );
CvMat c_src = src.getMat(), c_markers = markers.getMat();
cvWatershed( &c_src, &c_markers );
}
@@ -523,14 +523,16 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
}
}
void cv::pyrMeanShiftFiltering( const Mat& src, Mat& dst,
void cv::pyrMeanShiftFiltering( const InputArray& _src, OutputArray _dst,
double sp, double sr, int maxLevel,
TermCriteria termcrit )
{
Mat src = _src.getMat();
if( src.empty() )
return;
dst.create( src.size(), src.type() );
CvMat _src = src, _dst = dst;
cvPyrMeanShiftFiltering( &_src, &_dst, sp, sr, maxLevel, termcrit );
_dst.create( src.size(), src.type() );
CvMat c_src = src, c_dst = _dst.getMat();
cvPyrMeanShiftFiltering( &c_src, &c_dst, sp, sr, maxLevel, termcrit );
}
+38 -19
View File
@@ -197,7 +197,9 @@ template<typename ST, typename T> struct ColumnSum : public BaseColumnFilter
};
Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType, int ksize, int anchor)
}
cv::Ptr<cv::BaseRowFilter> cv::getRowSumFilter(int srcType, int sumType, int ksize, int anchor)
{
int sdepth = CV_MAT_DEPTH(srcType), ddepth = CV_MAT_DEPTH(sumType);
CV_Assert( CV_MAT_CN(sumType) == CV_MAT_CN(srcType) );
@@ -232,8 +234,8 @@ Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType, int ksize, int anch
}
Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType, int ksize,
int anchor, double scale)
cv::Ptr<cv::BaseColumnFilter> cv::getColumnSumFilter(int sumType, int dstType, int ksize,
int anchor, double scale)
{
int sdepth = CV_MAT_DEPTH(sumType), ddepth = CV_MAT_DEPTH(dstType);
CV_Assert( CV_MAT_CN(sumType) == CV_MAT_CN(dstType) );
@@ -272,7 +274,7 @@ Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType, int ksize,
}
Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
cv::Ptr<cv::FilterEngine> cv::createBoxFilter( int srcType, int dstType, Size ksize,
Point anchor, bool normalize, int borderType )
{
int sdepth = CV_MAT_DEPTH(srcType);
@@ -292,14 +294,16 @@ Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
}
void boxFilter( const Mat& src, Mat& dst, int ddepth,
void cv::boxFilter( const InputArray& _src, OutputArray _dst, int ddepth,
Size ksize, Point anchor,
bool normalize, int borderType )
{
Mat src = _src.getMat();
int sdepth = src.depth(), cn = src.channels();
if( ddepth < 0 )
ddepth = sdepth;
dst.create( src.size(), CV_MAKETYPE(ddepth, cn) );
_dst.create( src.size(), CV_MAKETYPE(ddepth, cn) );
Mat dst = _dst.getMat();
if( borderType != BORDER_CONSTANT && normalize )
{
if( src.rows == 1 )
@@ -312,7 +316,7 @@ void boxFilter( const Mat& src, Mat& dst, int ddepth,
f->apply( src, dst );
}
void blur( const Mat& src, CV_OUT Mat& dst,
void cv::blur( const InputArray& src, OutputArray dst,
Size ksize, Point anchor, int borderType )
{
boxFilter( src, dst, -1, ksize, anchor, true, borderType );
@@ -322,7 +326,7 @@ void blur( const Mat& src, CV_OUT Mat& dst,
Gaussian Blur
\****************************************************************************************/
Mat getGaussianKernel( int n, double sigma, int ktype )
cv::Mat cv::getGaussianKernel( int n, double sigma, int ktype )
{
const int SMALL_GAUSSIAN_SIZE = 7;
static const float small_gaussian_tab[][SMALL_GAUSSIAN_SIZE] =
@@ -375,7 +379,7 @@ Mat getGaussianKernel( int n, double sigma, int ktype )
}
Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
cv::Ptr<cv::FilterEngine> cv::createGaussianFilter( int type, Size ksize,
double sigma1, double sigma2,
int borderType )
{
@@ -406,17 +410,20 @@ Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
}
void GaussianBlur( const Mat& src, Mat& dst, Size ksize,
void cv::GaussianBlur( const InputArray& _src, OutputArray _dst, Size ksize,
double sigma1, double sigma2,
int borderType )
{
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
if( ksize.width == 1 && ksize.height == 1 )
{
src.copyTo(dst);
return;
}
dst.create( src.size(), src.type() );
if( borderType != BORDER_CONSTANT )
{
if( src.rows == 1 )
@@ -433,6 +440,9 @@ void GaussianBlur( const Mat& src, Mat& dst, Size ksize,
Median Filter
\****************************************************************************************/
namespace cv
{
#if _MSC_VER >= 1200
#pragma warning( disable: 4244 )
#endif
@@ -1207,9 +1217,14 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
}
}
void medianBlur( const Mat& src0, Mat& dst, int ksize )
}
void cv::medianBlur( const InputArray& _src0, OutputArray _dst, int ksize )
{
Mat src0 = _src0.getMat();
_dst.create( src0.size(), src0.type() );
Mat dst = _dst.getMat();
if( ksize <= 1 )
{
src0.copyTo(dst);
@@ -1225,8 +1240,7 @@ void medianBlur( const Mat& src0, Mat& dst, int ksize )
&& src0.depth() > CV_8U
#endif
);
dst.create( src0.size(), src0.type() );
Mat src;
if( useSortNet )
{
@@ -1266,6 +1280,9 @@ void medianBlur( const Mat& src0, Mat& dst, int ksize )
Bilateral Filtering
\****************************************************************************************/
namespace cv
{
static void
bilateralFilter_8u( const Mat& src, Mat& dst, int d,
double sigma_color, double sigma_space,
@@ -1497,12 +1514,16 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
}
}
}
void bilateralFilter( const Mat& src, Mat& dst, int d,
void cv::bilateralFilter( const InputArray& _src, OutputArray _dst, int d,
double sigmaColor, double sigmaSpace,
int borderType )
{
dst.create( src.size(), src.type() );
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
if( src.depth() == CV_8U )
bilateralFilter_8u( src, dst, d, sigmaColor, sigmaSpace, borderType );
else if( src.depth() == CV_32F )
@@ -1512,8 +1533,6 @@ void bilateralFilter( const Mat& src, Mat& dst, int d,
"Bilateral filtering is only implemented for 8u and 32f images" );
}
}
//////////////////////////////////////////////////////////////////////////////////////////
CV_IMPL void
+84 -66
View File
@@ -45,28 +45,17 @@
namespace cv
{
template<typename QT> inline QT sqr(uchar a) { return a*a; }
template<typename QT> inline QT sqr(float a) { return a*a; }
template<typename QT> inline QT sqr(double a) { return a*a; }
template<> inline double sqr(uchar a) { return CV_8TO32F_SQR(a); }
template<typename T, typename ST, typename QT>
void integral_( const Mat& _src, Mat& _sum, Mat& _sqsum, Mat& _tilted )
void integral_( const T* src, size_t srcstep, ST* sum, size_t sumstep,
QT* sqsum, size_t sqsumstep, ST* tilted, size_t tiltedstep,
Size size, int cn )
{
int cn = _src.channels();
Size size = _src.size();
int x, y, k;
const T* src = (const T*)_src.data;
ST* sum = (ST*)_sum.data;
ST* tilted = (ST*)_tilted.data;
QT* sqsum = (QT*)_sqsum.data;
int srcstep = (int)(_src.step/sizeof(T));
int sumstep = (int)(_sum.step/sizeof(ST));
int tiltedstep = (int)(_tilted.step/sizeof(ST));
int sqsumstep = (int)(_sqsum.step/sizeof(QT));
srcstep /= sizeof(T);
sumstep /= sizeof(ST);
tiltedstep /= sizeof(ST);
sqsumstep /= sizeof(QT);
size.width *= cn;
@@ -113,7 +102,7 @@ void integral_( const Mat& _src, Mat& _sum, Mat& _sqsum, Mat& _tilted )
{
T it = src[x];
s += it;
sq += sqr<QT>(it);
sq += (QT)it*it;
ST t = sum[x - sumstep] + s;
QT tq = sqsum[x - sqsumstep] + sq;
sum[x] = t;
@@ -128,45 +117,55 @@ void integral_( const Mat& _src, Mat& _sum, Mat& _sqsum, Mat& _tilted )
ST* buf = _buf;
ST s;
QT sq;
for( k = 0; k < cn; k++, src++, sum++, tilted++, sqsum++, buf++ )
for( k = 0; k < cn; k++, src++, sum++, tilted++, buf++ )
{
sum[-cn] = tilted[-cn] = 0;
sqsum[-cn] = 0;
for( x = 0, s = 0, sq = 0; x < size.width; x += cn )
{
T it = src[x];
buf[x] = tilted[x] = it;
s += it;
sq += sqr<QT>(it);
sq += (QT)it*it;
sum[x] = s;
sqsum[x] = sq;
if( sqsum )
sqsum[x] = sq;
}
if( size.width == cn )
buf[cn] = 0;
if( sqsum )
{
sqsum[-cn] = 0;
sqsum++;
}
}
for( y = 1; y < size.height; y++ )
{
src += srcstep - cn;
sum += sumstep - cn;
sqsum += sqsumstep - cn;
tilted += tiltedstep - cn;
buf += -cn;
if( sqsum )
sqsum += sqsumstep - cn;
for( k = 0; k < cn; k++, src++, sum++, sqsum++, tilted++, buf++ )
for( k = 0; k < cn; k++, src++, sum++, tilted++, buf++ )
{
T it = src[0];
ST t0 = s = it;
QT tq0 = sq = sqr<QT>(it);
QT tq0 = sq = (QT)it*it;
sum[-cn] = 0;
sqsum[-cn] = 0;
if( sqsum )
sqsum[-cn] = 0;
tilted[-cn] = tilted[-tiltedstep];
sum[0] = sum[-sumstep] + t0;
sqsum[0] = sqsum[-sqsumstep] + tq0;
if( sqsum )
sqsum[0] = sqsum[-sqsumstep] + tq0;
tilted[0] = tilted[-tiltedstep] + t0 + buf[cn];
for( x = cn; x < size.width - cn; x += cn )
@@ -174,11 +173,12 @@ void integral_( const Mat& _src, Mat& _sum, Mat& _sqsum, Mat& _tilted )
ST t1 = buf[x];
buf[x - cn] = t1 + t0;
t0 = it = src[x];
tq0 = sqr<QT>(it);
tq0 = (QT)it*it;
s += t0;
sq += tq0;
sum[x] = sum[x - sumstep] + s;
sqsum[x] = sqsum[x - sqsumstep] + sq;
if( sqsum )
sqsum[x] = sqsum[x - sqsumstep] + sq;
t1 += buf[x + cn] + t0 + tilted[x - tiltedstep - cn];
tilted[x] = t1;
}
@@ -188,79 +188,96 @@ void integral_( const Mat& _src, Mat& _sum, Mat& _sqsum, Mat& _tilted )
ST t1 = buf[x];
buf[x - cn] = t1 + t0;
t0 = it = src[x];
tq0 = sqr<QT>(it);
tq0 = (QT)it*it;
s += t0;
sq += tq0;
sum[x] = sum[x - sumstep] + s;
sqsum[x] = sqsum[x - sqsumstep] + sq;
if( sqsum )
sqsum[x] = sqsum[x - sqsumstep] + sq;
tilted[x] = t0 + t1 + tilted[x - tiltedstep - cn];
buf[x] = t0;
}
if( sqsum )
sqsum++;
}
}
}
}
typedef void (*IntegralFunc)(const Mat& _src, Mat& _sum, Mat& _sqsum, Mat& _tilted );
#define DEF_INTEGRAL_FUNC(suffix, T, ST, QT) \
void integral_##suffix( T* src, size_t srcstep, ST* sum, size_t sumstep, QT* sqsum, size_t sqsumstep, \
ST* tilted, size_t tiltedstep, Size size, int cn ) \
{ integral_(src, srcstep, sum, sumstep, sqsum, sqsumstep, tilted, tiltedstep, size, cn); }
static void
integral( const Mat& src, Mat& sum, Mat* _sqsum, Mat* _tilted, int sdepth )
DEF_INTEGRAL_FUNC(8u32s, uchar, int, double)
DEF_INTEGRAL_FUNC(8u32f, uchar, float, double)
DEF_INTEGRAL_FUNC(8u64f, uchar, double, double)
DEF_INTEGRAL_FUNC(32f, float, float, float)
DEF_INTEGRAL_FUNC(32f64f, float, double, double)
DEF_INTEGRAL_FUNC(64f, double, double, double)
typedef void (*IntegralFunc)(const uchar* src, size_t srcstep, uchar* sum, size_t sumstep,
uchar* sqsum, size_t sqsumstep, uchar* tilted, size_t tstep,
Size size, int cn );
}
void cv::integral( const InputArray& _src, OutputArray _sum, OutputArray _sqsum, OutputArray _tilted, int sdepth )
{
Mat src = _src.getMat(), sum, sqsum, tilted;
int depth = src.depth(), cn = src.channels();
Size isize(src.cols + 1, src.rows+1);
Mat sqsum, tilted;
if( sdepth <= 0 )
sdepth = depth == CV_8U ? CV_32S : CV_64F;
sdepth = CV_MAT_DEPTH(sdepth);
sum.create( isize, CV_MAKETYPE(sdepth, cn) );
_sum.create( isize, CV_MAKETYPE(sdepth, cn) );
sum = _sum.getMat();
if( _tilted )
_tilted->create( isize, CV_MAKETYPE(sdepth, cn) );
else
_tilted = &tilted;
if( _tilted.needed() )
{
_tilted.create( isize, CV_MAKETYPE(sdepth, cn) );
tilted = _tilted.getMat();
}
if( !_sqsum )
_sqsum = &sqsum;
if( _sqsum.needed() )
{
_sqsum.create( isize, CV_MAKETYPE(CV_64F, cn) );
sqsum = _sqsum.getMat();
}
if( _sqsum != &sqsum || _tilted->data )
_sqsum->create( isize, CV_MAKETYPE(CV_64F, cn) );
IntegralFunc func = 0;
if( depth == CV_8U && sdepth == CV_32S )
func = integral_<uchar, int, double>;
func = (IntegralFunc)integral_8u32s;
else if( depth == CV_8U && sdepth == CV_32F )
func = integral_<uchar, float, double>;
func = (IntegralFunc)integral_8u32f;
else if( depth == CV_8U && sdepth == CV_64F )
func = integral_<uchar, double, double>;
func = (IntegralFunc)integral_8u64f;
else if( depth == CV_32F && sdepth == CV_32F )
func = integral_<float, float, double>;
func = (IntegralFunc)integral_32f;
else if( depth == CV_32F && sdepth == CV_64F )
func = integral_<float, double, double>;
func = (IntegralFunc)integral_32f64f;
else if( depth == CV_64F && sdepth == CV_64F )
func = integral_<double, double, double>;
func = (IntegralFunc)integral_64f;
else
CV_Error( CV_StsUnsupportedFormat, "" );
func( src, sum, *_sqsum, *_tilted );
func( src.data, src.step, sum.data, sum.step, sqsum.data, sqsum.step,
tilted.data, tilted.step, src.size(), cn );
}
void integral( const Mat& src, Mat& sum, int sdepth )
void cv::integral( const InputArray& src, OutputArray sum, int sdepth )
{
integral( src, sum, 0, 0, sdepth );
integral( src, sum, OutputArray(), OutputArray(), sdepth );
}
void integral( const Mat& src, Mat& sum, Mat& sqsum, int sdepth )
void cv::integral( const InputArray& src, OutputArray sum, OutputArray sqsum, int sdepth )
{
integral( src, sum, &sqsum, 0, sdepth );
}
void integral( const Mat& src, Mat& sum, Mat& sqsum, Mat& tilted, int sdepth )
{
integral( src, sum, &sqsum, &tilted, sdepth );
}
integral( src, sum, sqsum, OutputArray(), sdepth );
}
@@ -283,7 +300,8 @@ cvIntegral( const CvArr* image, CvArr* sumImage,
tilted0 = tilted = cv::cvarrToMat(tiltedSumImage);
ptilted = &tilted;
}
cv::integral( src, sum, psqsum, ptilted, sum.depth() );
cv::integral( src, sum, psqsum ? cv::OutputArray(*psqsum) : cv::OutputArray(),
ptilted ? cv::OutputArray(*ptilted) : cv::OutputArray(), sum.depth() );
CV_Assert( sum.data == sum0.data && sqsum.data == sqsum0.data && tilted.data == tilted0.data );
}
+8 -7
View File
@@ -233,10 +233,11 @@ cv::crossCorr( const Mat& img, const Mat& templ, Mat& corr,
icvCrossCorr( &_img, &_templ, &_corr, anchor, delta, borderType );
}*/
}
/*****************************************************************************************/
void matchTemplate( const Mat& _img, const Mat& _templ, Mat& result, int method )
void cv::matchTemplate( const InputArray& _img, const InputArray& _templ, OutputArray _result, int method )
{
CV_Assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED );
@@ -246,17 +247,19 @@ void matchTemplate( const Mat& _img, const Mat& _templ, Mat& result, int method
method == CV_TM_SQDIFF_NORMED ||
method == CV_TM_CCOEFF_NORMED;
Mat img = _img, templ = _templ;
Mat img = _img.getMat(), templ = _templ.getMat();
if( img.rows < templ.rows || img.cols < templ.cols )
std::swap(img, templ);
CV_Assert( (img.depth() == CV_8U || img.depth() == CV_32F) &&
img.type() == templ.type() );
Size corrSize(img.cols - templ.cols + 1, img.rows - templ.rows + 1);
_result.create(corrSize, CV_32F);
Mat result = _result.getMat();
int cn = img.channels();
crossCorr( img, templ, result,
Size(img.cols - templ.cols + 1, img.rows - templ.rows + 1),
CV_32F, Point(0,0), 0, 0);
crossCorr( img, templ, result, result.size(), result.type(), Point(0,0), 0, 0);
if( method == CV_TM_CCORR )
return;
@@ -368,8 +371,6 @@ void matchTemplate( const Mat& _img, const Mat& _templ, Mat& result, int method
}
}
}
CV_IMPL void
cvMatchTemplate( const CvArr* _img, const CvArr* _templ, CvArr* _result, int method )
+33 -29
View File
@@ -475,20 +475,24 @@ getThreshVal_Otsu_8u( const Mat& _src )
return max_val;
}
double threshold( const Mat& _src, Mat& _dst, double thresh, double maxval, int type )
}
double cv::threshold( const InputArray& _src, OutputArray _dst, double thresh, double maxval, int type )
{
Mat src = _src.getMat();
bool use_otsu = (type & THRESH_OTSU) != 0;
type &= THRESH_MASK;
if( use_otsu )
{
CV_Assert( _src.type() == CV_8UC1 );
thresh = getThreshVal_Otsu_8u(_src);
CV_Assert( src.type() == CV_8UC1 );
thresh = getThreshVal_Otsu_8u(src);
}
_dst.create( _src.size(), _src.type() );
if( _src.depth() == CV_8U )
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
if( src.depth() == CV_8U )
{
int ithresh = cvFloor(thresh);
thresh = ithresh;
@@ -506,16 +510,16 @@ double threshold( const Mat& _src, Mat& _dst, double thresh, double maxval, int
int v = type == THRESH_BINARY ? (ithresh >= 255 ? 0 : imaxval) :
type == THRESH_BINARY_INV ? (ithresh >= 255 ? imaxval : 0) :
type == THRESH_TRUNC ? imaxval : 0;
_dst = Scalar::all(v);
dst = Scalar::all(v);
}
else
_src.copyTo(_dst);
src.copyTo(dst);
}
else
thresh_8u( _src, _dst, (uchar)ithresh, (uchar)imaxval, type );
thresh_8u( src, dst, (uchar)ithresh, (uchar)imaxval, type );
}
else if( _src.depth() == CV_32F )
thresh_32f( _src, _dst, (float)thresh, (float)maxval, type );
else if( src.depth() == CV_32F )
thresh_32f( src, dst, (float)thresh, (float)maxval, type );
else
CV_Error( CV_StsUnsupportedFormat, "" );
@@ -523,31 +527,33 @@ double threshold( const Mat& _src, Mat& _dst, double thresh, double maxval, int
}
void adaptiveThreshold( const Mat& _src, Mat& _dst, double maxValue,
int method, int type, int blockSize, double delta )
void cv::adaptiveThreshold( const InputArray& _src, OutputArray _dst, double maxValue,
int method, int type, int blockSize, double delta )
{
CV_Assert( _src.type() == CV_8UC1 );
Mat src = _src.getMat();
CV_Assert( src.type() == CV_8UC1 );
CV_Assert( blockSize % 2 == 1 && blockSize > 1 );
Size size = _src.size();
Size size = src.size();
_dst.create( size, _src.type() );
_dst.create( size, src.type() );
Mat dst = _dst.getMat();
if( maxValue < 0 )
{
_dst = Scalar(0);
dst = Scalar(0);
return;
}
Mat _mean;
Mat mean;
if( _src.data != _dst.data )
_mean = _dst;
if( src.data != dst.data )
mean = dst;
if( method == ADAPTIVE_THRESH_MEAN_C )
boxFilter( _src, _mean, _src.type(), Size(blockSize, blockSize),
boxFilter( src, mean, src.type(), Size(blockSize, blockSize),
Point(-1,-1), true, BORDER_REPLICATE );
else if( method == ADAPTIVE_THRESH_GAUSSIAN_C )
GaussianBlur( _src, _mean, Size(blockSize, blockSize), 0, 0, BORDER_REPLICATE );
GaussianBlur( src, mean, Size(blockSize, blockSize), 0, 0, BORDER_REPLICATE );
else
CV_Error( CV_StsBadFlag, "Unknown/unsupported adaptive threshold method" );
@@ -565,7 +571,7 @@ void adaptiveThreshold( const Mat& _src, Mat& _dst, double maxValue,
else
CV_Error( CV_StsBadFlag, "Unknown/unsupported threshold type" );
if( _src.isContinuous() && _mean.isContinuous() && _dst.isContinuous() )
if( src.isContinuous() && mean.isContinuous() && dst.isContinuous() )
{
size.width *= size.height;
size.height = 1;
@@ -573,17 +579,15 @@ void adaptiveThreshold( const Mat& _src, Mat& _dst, double maxValue,
for( i = 0; i < size.height; i++ )
{
const uchar* src = _src.data + _src.step*i;
const uchar* mean = _mean.data + _mean.step*i;
uchar* dst = _dst.data + _dst.step*i;
const uchar* sdata = src.data + src.step*i;
const uchar* mdata = mean.data + mean.step*i;
uchar* ddata = dst.data + dst.step*i;
for( j = 0; j < size.width; j++ )
dst[j] = tab[src[j] - mean[j] + 255];
ddata[j] = tab[sdata[j] - mdata[j] + 255];
}
}
}
CV_IMPL double
cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, int type )
{
+60 -64
View File
@@ -42,12 +42,10 @@
#include "precomp.hpp"
namespace cv
{
Mat getDefaultNewCameraMatrix( const Mat& cameraMatrix, Size imgsize,
cv::Mat cv::getDefaultNewCameraMatrix( const InputArray& _cameraMatrix, Size imgsize,
bool centerPrincipalPoint )
{
Mat cameraMatrix = _cameraMatrix.getMat();
if( !centerPrincipalPoint && cameraMatrix.type() == CV_64F )
return cameraMatrix;
@@ -61,35 +59,42 @@ Mat getDefaultNewCameraMatrix( const Mat& cameraMatrix, Size imgsize,
return newCameraMatrix;
}
void initUndistortRectifyMap( const Mat& _cameraMatrix, const Mat& _distCoeffs,
const Mat& matR, const Mat& _newCameraMatrix,
Size size, int m1type, Mat& map1, Mat& map2 )
void cv::initUndistortRectifyMap( const InputArray& _cameraMatrix, const InputArray& _distCoeffs,
const InputArray& _matR, const InputArray& _newCameraMatrix,
Size size, int m1type, OutputArray _map1, OutputArray _map2 )
{
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
Mat matR = _matR.getMat(), newCameraMatrix = _newCameraMatrix.getMat();
if( m1type <= 0 )
m1type = CV_16SC2;
CV_Assert( m1type == CV_16SC2 || m1type == CV_32FC1 || m1type == CV_32FC2 );
map1.create( size, m1type );
_map1.create( size, m1type );
Mat map1 = _map1.getMat(), map2;
if( m1type != CV_32FC2 )
map2.create( size, m1type == CV_16SC2 ? CV_16UC1 : CV_32FC1 );
{
_map2.create( size, m1type == CV_16SC2 ? CV_16UC1 : CV_32FC1 );
map2 = _map2.getMat();
}
else
map2.release();
_map2.release();
Mat_<double> R = Mat_<double>::eye(3, 3), distCoeffs;
Mat_<double> A = Mat_<double>(_cameraMatrix), Ar;
Mat_<double> R = Mat_<double>::eye(3, 3);
Mat_<double> A = Mat_<double>(cameraMatrix), Ar;
if( _newCameraMatrix.data )
Ar = Mat_<double>(_newCameraMatrix);
if( newCameraMatrix.data )
Ar = Mat_<double>(newCameraMatrix);
else
Ar = getDefaultNewCameraMatrix( A, size, true );
if( matR.data )
R = Mat_<double>(matR);
if( _distCoeffs.data )
distCoeffs = Mat_<double>(_distCoeffs);
if( distCoeffs.data )
distCoeffs = Mat_<double>(distCoeffs);
else
{
distCoeffs.create(8, 1);
distCoeffs.create(8, 1, CV_64F);
distCoeffs = 0.;
}
@@ -156,28 +161,33 @@ void initUndistortRectifyMap( const Mat& _cameraMatrix, const Mat& _distCoeffs,
}
void undistort( const Mat& src, Mat& dst, const Mat& _cameraMatrix,
const Mat& _distCoeffs, const Mat& _newCameraMatrix )
void cv::undistort( const InputArray& _src, OutputArray _dst, const InputArray& _cameraMatrix,
const InputArray& _distCoeffs, const InputArray& _newCameraMatrix )
{
dst.create( src.size(), src.type() );
Mat src = _src.getMat(), cameraMatrix = _cameraMatrix.getMat();
Mat distCoeffs = _distCoeffs.getMat(), newCameraMatrix = _newCameraMatrix.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
CV_Assert( dst.data != src.data );
int stripe_size0 = std::min(std::max(1, (1 << 12) / std::max(src.cols, 1)), src.rows);
Mat map1(stripe_size0, src.cols, CV_16SC2), map2(stripe_size0, src.cols, CV_16UC1);
Mat_<double> A, distCoeffs, Ar, I = Mat_<double>::eye(3,3);
Mat_<double> A, Ar, I = Mat_<double>::eye(3,3);
_cameraMatrix.convertTo(A, CV_64F);
if( _distCoeffs.data )
distCoeffs = Mat_<double>(_distCoeffs);
cameraMatrix.convertTo(A, CV_64F);
if( distCoeffs.data )
distCoeffs = Mat_<double>(distCoeffs);
else
{
distCoeffs.create(5, 1);
distCoeffs.create(5, 1, CV_64F);
distCoeffs = 0.;
}
if( _newCameraMatrix.data )
_newCameraMatrix.convertTo(Ar, CV_64F);
if( newCameraMatrix.data )
newCameraMatrix.convertTo(Ar, CV_64F);
else
A.copyTo(Ar);
@@ -196,8 +206,6 @@ void undistort( const Mat& src, Mat& dst, const Mat& _cameraMatrix,
}
}
}
CV_IMPL void
cvUndistort2( const CvArr* srcarr, CvArr* dstarr, const CvMat* Aarr, const CvMat* dist_coeffs, const CvMat* newAarr )
@@ -373,48 +381,34 @@ void cvUndistortPoints( const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatr
}
namespace cv
void cv::undistortPoints( const InputArray& _src, OutputArray _dst,
const InputArray& _cameraMatrix,
const InputArray& _distCoeffs,
const InputArray& _Rmat,
const InputArray& _Pmat )
{
Mat src = _src.getMat(), cameraMatrix = _cameraMatrix.getMat();
Mat distCoeffs = _distCoeffs.getMat(), R = _Rmat.getMat(), P = _Pmat.getMat();
void undistortPoints( const Mat& src, Mat& dst,
const Mat& cameraMatrix, const Mat& distCoeffs,
const Mat& R, const Mat& P )
{
CV_Assert( src.isContinuous() && (src.depth() == CV_32F || src.depth() == CV_64F) &&
((src.rows == 1 && src.channels() == 2) || src.cols*src.channels() == 2));
dst.create(src.size(), src.type());
CvMat _src = src, _dst = dst, _cameraMatrix = cameraMatrix;
CvMat matR, matP, _distCoeffs, *pR=0, *pP=0, *pD=0;
if( R.data )
pR = &(matR = R);
if( P.data )
pP = &(matP = P);
if( distCoeffs.data )
pD = &(_distCoeffs = distCoeffs);
cvUndistortPoints(&_src, &_dst, &_cameraMatrix, pD, pR, pP);
}
void undistortPoints( const Mat& src, std::vector<Point2f>& dst,
const Mat& cameraMatrix, const Mat& distCoeffs,
const Mat& R, const Mat& P )
{
size_t sz = src.cols*src.rows*src.channels()/2;
CV_Assert( src.isContinuous() && src.depth() == CV_32F &&
((src.rows == 1 && src.channels() == 2) || src.cols*src.channels() == 2));
_dst.create(src.size(), src.type(), -1, true);
Mat dst = _dst.getMat();
dst.resize(sz);
CvMat _src = src, _dst = Mat(dst), _cameraMatrix = cameraMatrix;
CvMat matR, matP, _distCoeffs, *pR=0, *pP=0, *pD=0;
CvMat _csrc = src, _cdst = dst, _ccameraMatrix = cameraMatrix;
CvMat matR, matP, _cdistCoeffs, *pR=0, *pP=0, *pD=0;
if( R.data )
pR = &(matR = R);
if( P.data )
pP = &(matP = P);
if( distCoeffs.data )
pD = &(_distCoeffs = distCoeffs);
cvUndistortPoints(&_src, &_dst, &_cameraMatrix, pD, pR, pP);
pD = &(_cdistCoeffs = distCoeffs);
cvUndistortPoints(&_csrc, &_cdst, &_ccameraMatrix, pD, pR, pP);
}
namespace cv
{
static Point2f mapPointSpherical(const Point2f& p, float alpha, Vec4d* J, int projType)
{
@@ -492,11 +486,13 @@ static Point2f invMapPointSpherical(Point2f _p, float alpha, int projType)
return i < maxiter ? Point2f((float)q[0], (float)q[1]) : Point2f(-FLT_MAX, -FLT_MAX);
}
}
float initWideAngleProjMap( const Mat& cameraMatrix0, const Mat& distCoeffs0,
float cv::initWideAngleProjMap( const InputArray& _cameraMatrix0, const InputArray& _distCoeffs0,
Size imageSize, int destImageWidth, int m1type,
Mat& map1, Mat& map2, int projType, double _alpha )
OutputArray _map1, OutputArray _map2, int projType, double _alpha )
{
Mat cameraMatrix0 = _cameraMatrix0.getMat(), distCoeffs0 = _distCoeffs0.getMat();
double k[8] = {0,0,0,0,0,0,0,0}, M[9]={0,0,0,0,0,0,0,0,0};
Mat distCoeffs(distCoeffs0.rows, distCoeffs0.cols, CV_MAKETYPE(CV_64F,distCoeffs0.channels()), k);
Mat cameraMatrix(3,3,CV_64F,M);
@@ -562,15 +558,15 @@ float initWideAngleProjMap( const Mat& cameraMatrix0, const Mat& distCoeffs0,
if(m1type == CV_32FC2)
{
_map1.create(mapxy.size(), mapxy.type());
Mat map1 = _map1.getMat();
mapxy.copyTo(map1);
map2.release();
_map2.release();
}
else
convertMaps(mapxy, Mat(), map1, map2, m1type, false);
convertMaps(mapxy, Mat(), _map1, _map2, m1type, false);
return scale;
}
}
/* End of file */
+7 -5
View File
@@ -195,13 +195,17 @@ static void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, Size srcro
memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width);
}
}
void copyMakeBorder( const Mat& src, Mat& dst, int top, int bottom,
int left, int right, int borderType, const Scalar& value )
void cv::copyMakeBorder( const InputArray& _src, OutputArray _dst, int top, int bottom,
int left, int right, int borderType, const Scalar& value )
{
Mat src = _src.getMat();
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
dst.create( src.rows + top + bottom, src.cols + left + right, src.type() );
_dst.create( src.rows + top + bottom, src.cols + left + right, src.type() );
Mat dst = _dst.getMat();
if( borderType != BORDER_CONSTANT )
copyMakeBorder_8u( src.data, src.step, src.size(),
dst.data, dst.step, dst.size(),
@@ -215,8 +219,6 @@ void copyMakeBorder( const Mat& src, Mat& dst, int top, int bottom,
top, left, (int)src.elemSize(), (uchar*)buf );
}
}
}
CV_IMPL void