⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvmat.hpp

📁 用OpenCV编写的人脸识别代码
💻 HPP
📖 第 1 页 / 共 5 页
字号:

/* conversion of data type */
struct  CVAUX_DLL_ENTRY _CvMAT_COPY_
{
    explicit _CvMAT_COPY_( const CvMAT* a );
    operator CvMAT() const;
    CvMAT* a;
};


/* a.op(b), where op = mul, div, min, max ... */
struct  CVAUX_DLL_ENTRY _CvMAT_DOT_OP_ : public _CvMAT_BASE_OP_
{
    explicit _CvMAT_DOT_OP_( const CvMAT* a, const CvMAT* b,
                             int op, double alpha = 1 );
    operator _CvMAT_TMP_() const;

    CvMAT a; /* keep the left operand copy */
    CvMAT* b;
    double alpha;
    int op;
};


/* A.inv()*B or A.pinv()*B */
struct  CVAUX_DLL_ENTRY _CvMAT_SOLVE_ : public _CvMAT_BASE_OP_
{
    explicit _CvMAT_SOLVE_( const CvMAT* a, const CvMAT* b, int method );
    operator _CvMAT_TMP_() const;

    CvMAT* a;
    CvMAT* b;
    int method;
};


/* A <=> B */
struct  CVAUX_DLL_ENTRY _CvMAT_CMP_ : public _CvMAT_BASE_OP_
{
    explicit _CvMAT_CMP_( const CvMAT* a, const CvMAT* b, int cmp_op );
    explicit _CvMAT_CMP_( const CvMAT* a, double alpha, int cmp_op );
    operator _CvMAT_TMP_() const;

    CvMAT* a;
    CvMAT* b;
    double alpha;
    int cmp_op;
};


/************************* _CvMATConstElem_ inline methods ******************************/

inline _CvMATConstElem_::_CvMATConstElem_(const uchar* p, int t) : ptr((uchar*)p), type(t)
{}


inline _CvMATConstElem_::operator CvScalar() const
{
    CvScalar scalar;
    cvRawDataToScalar( ptr, type, &scalar );

    return scalar;
}


inline double _CvMATConstElem_::operator ()( int coi ) const
{   return CvMAT::get( ptr, type, coi );    }


inline _CvMATElemCn_::_CvMATElemCn_( uchar* p, int t, int coi ) :
    ptr(p), type(CV_MAT_DEPTH(t))
{
    if( coi )
    {
        assert( (unsigned)coi < (unsigned)CV_MAT_CN(t) );
        ptr += coi * CV_ELEM_SIZE(type);
    }
}


inline _CvMATElemCn_::operator double() const
{   return CvMAT::get( ptr, type ); }


inline _CvMATElemCn_& _CvMATElemCn_::operator = ( const _CvMATConstElem_& elem )
{
    if( type == elem.type )
        memcpy( ptr, elem.ptr, CV_ELEM_SIZE(type) );
    else
    {
        assert( CV_MAT_CN(elem.type) == 1 );
        CvMAT::set( ptr, type, 0, elem(0));
    }

    return *this;
}


inline _CvMATElemCn_& _CvMATElemCn_::operator = ( const _CvMATElemCn_& elem )
{
    if( type == elem.type )
        memcpy( ptr, elem.ptr, CV_ELEM_SIZE(type) );
    else
        CvMAT::set( ptr, type, 0, (double)elem );
    return *this;
}


inline _CvMATElemCn_& _CvMATElemCn_::operator = ( const CvScalar& scalar )
{   
    CvMAT::set( ptr, type, 0, scalar.val[0] );
    return *this;
}


inline _CvMATElemCn_& _CvMATElemCn_::operator = ( double d )
{   
    CvMAT::set( ptr, type, 0, d );
    return *this;
}


inline _CvMATElemCn_& _CvMATElemCn_::operator = ( float f )
{   
    CvMAT::set( ptr, type, 0, (double)f );
    return *this;
}


inline _CvMATElemCn_& _CvMATElemCn_::operator = ( int i )
{   
    CvMAT::set( ptr, type, 0, i );
    return *this;
}


inline _CvMATElem_::_CvMATElem_( uchar* p, int t ) : _CvMATConstElem_( (const uchar*)p, t )
{}


inline _CvMATElemCn_ _CvMATElem_::operator ()( int coi )
{   return _CvMATElemCn_( ptr, type, coi ); }


inline _CvMATElem_& _CvMATElem_::operator = ( const _CvMATConstElem_& elem )
{
    if( type == elem.type )
        memcpy( ptr, elem.ptr, CV_ELEM_SIZE(type) );
    else
    {
        assert( CV_MAT_CN( type ^ elem.type ) == 0 );
        CvScalar sc = (CvScalar)elem;
        cvScalarToRawData( &sc, ptr, type, 0 );
    }

    return *this;
}


inline _CvMATElem_& _CvMATElem_::operator = ( const _CvMATElem_& elem )
{
    *this = (const _CvMATConstElem_&)elem;
    return *this;
}


inline _CvMATElem_& _CvMATElem_::operator = ( const _CvMATElemCn_& elem )
{
    if( type == elem.type )
        memcpy( ptr, elem.ptr, CV_ELEM_SIZE(type) );
    else
        CvMAT::set( ptr, type, (double)elem );

    return *this;
}


inline _CvMATElem_& _CvMATElem_::operator = ( const CvScalar& scalar )
{
    cvScalarToRawData( &scalar, ptr, type, 0 );
    return *this;
}


inline _CvMATElem_& _CvMATElem_::operator = ( double d )
{
    CvMAT::set( ptr, type, d );
    return *this;
}


inline _CvMATElem_& _CvMATElem_::operator = ( float f )
{
    CvMAT::set( ptr, type, (double)f );
    return *this;
}


inline _CvMATElem_& _CvMATElem_::operator = ( int i )
{
    CvMAT::set( ptr, type, i );
    return *this;
}


/********************************** CvMAT inline methods ********************************/

inline CvMAT::CvMAT()
{
    memset( this, 0, sizeof(*this));
}


inline CvMAT::CvMAT( int rows, int cols, int type, void* data, int step )
{
    cvInitMatHeader( this, rows, cols, type, data, step );
}


inline CvMAT::CvMAT( int rows, int type, void* data, int step )
{
    cvInitMatHeader( this, rows, 1, type, data, step );
}


inline void CvMAT::create( int rows, int cols, int type )
{
    cvInitMatHeader( this, rows, cols, type );
    cvCreateData( this );
}


inline CvMAT::CvMAT( int rows, int cols, int type )
{
    create( rows, cols, type );
}


inline CvMAT::CvMAT( int rows, int type )
{
    create( rows, 1, type );
}


inline CvMAT::CvMAT( const CvMat& mat )
{
    memcpy( this, &mat, sizeof(mat));
    if( refcount )
        (*refcount)++;
}


inline CvMAT::CvMAT( const CvMAT& mat )
{
    memcpy( this, &mat, sizeof(mat));
    if( refcount )
        (*refcount)++;
}


inline CvMAT::CvMAT( const IplImage& img )
{
    cvGetMat( &img, this );
}


inline void CvMAT::release()
{
    if( type != 0 && refcount && --refcount[0] == 0 )
    {
        uchar* ptr = (uchar*)refcount + sizeof(refcount)*2;
        cvFree( (void**)&ptr );
    }
    data.ptr = 0;
    refcount = 0;
}


inline CvMAT::~CvMAT()
{
    release();
}


inline bool CvMAT::istemp() const
{
    return (type & CV_MAT_TEMP_FLAG) != 0;
}


inline CvMAT& CvMAT::operator = ( const CvMAT& mat )
{
    if( this != &mat )
    {
        release();
        memcpy( this, &mat, sizeof(mat));
        if( refcount )
            (*refcount)++;
    }
    return *this;
}


inline CvMAT& CvMAT::operator = ( const CvMat& mat )
{
    *this = (const CvMAT&)mat;
    return *this;
}


inline CvMAT& CvMAT::operator = ( const IplImage& img )
{
    release();
    cvGetMat( &img, this );

    return *this;
}


inline CvMAT& CvMAT::operator = ( double fillval )
{
    cvFillImage( this, fillval );
    return *this;
}


inline CvMAT& CvMAT::operator = ( const CvScalar& fillval )
{
    cvSet( this, fillval );
    return *this;
}


inline CvMAT& CvMAT::operator += ( const CvMat& mat )
{
    cvAdd( this, &mat, this );
    return *this;
}


inline CvMAT& CvMAT::operator += ( double val )
{
    cvAddS( this, cvScalar(val), this );
    return *this;
}


inline CvMAT& CvMAT::operator += ( const CvScalar& val )
{
    cvAddS( this, val, this );
    return *this;
}


inline CvMAT& CvMAT::operator -= ( const CvMat& mat )
{
    cvSub( this, &mat, this );
    return *this;
}


inline CvMAT& CvMAT::operator -= ( double val )
{
    cvSubS( this, cvScalar(val), this );
    return *this;
}


inline CvMAT& CvMAT::operator -= ( const CvScalar& val )
{
    cvSubS( this, val, this );
    return *this;
}


inline CvMAT& CvMAT::operator *= ( const CvMat& mat )
{
    cvMul( this, &mat, this );
    return *this;    
}


inline CvMAT& CvMAT::operator *= ( double val )
{
    cvScale( this, this, val, 0 );
    return *this;
}


inline CvMAT& CvMAT::operator *= ( const CvScalar& val )
{
    cvScaleAdd( this, val, 0, this );
    return *this;
}


inline CvMAT& CvMAT::operator &= ( const CvMat& mat )
{
    cvAnd( this, &mat, this );
    return *this;
}


inline CvMAT& CvMAT::operator &= ( double val )
{
    cvAndS( this, cvScalarAll(val), this );
    return *this;
}


inline CvMAT& CvMAT::operator &= ( const CvScalar& val )
{
    cvAndS( this, val, this );
    return *this;
}


inline CvMAT& CvMAT::operator |= ( const CvMat& mat )
{
    cvOr( this, &mat, this );
    return *this;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -