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

📄 cvmat.hpp

📁 Simple ellipse fitting example on C++Builder6 + OpenCV1.0.
💻 HPP
📖 第 1 页 / 共 5 页
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                        Intel License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of Intel Corporation may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef _CVMAT_HPP_
#define _CVMAT_HPP_

#if 0 && (defined __cplusplus && (_MSC_VER>=1200 || defined __BORLANDC__ || defined __GNUC__))

#if _MSC_VER >= 1200
#pragma warning( disable: 4710 ) /* suppress "function ... is not inlined" */
#endif

#include <string.h>
#include <stdio.h>

#undef min
#undef max

/****************************************************************************************\
*                            C++ - like operations on CvScalar                           *
\****************************************************************************************/

inline CvScalar& operator += ( CvScalar& a, const CvScalar& b )
{
    double t0 = a.val[0] + b.val[0];
    double t1 = a.val[1] + b.val[1];
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = a.val[2] + b.val[2];
    t1 = a.val[3] + b.val[3];
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar& operator -= ( CvScalar& a, const CvScalar& b )
{
    double t0 = a.val[0] - b.val[0];
    double t1 = a.val[1] - b.val[1];
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = a.val[2] - b.val[2];
    t1 = a.val[3] - b.val[3];
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar& operator *= ( CvScalar& a, double b )
{
    double t0 = a.val[0] * b;
    double t1 = a.val[1] * b;
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = a.val[2] * b;
    t1 = a.val[3] * b;
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar& operator /= ( CvScalar& a, double b )
{
    double inv_b = 1./b;
    double t0 = a.val[0] * inv_b;
    double t1 = a.val[1] * inv_b;
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = a.val[2] * inv_b;
    t1 = a.val[3] * inv_b;
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar& operator *= ( CvScalar& a, const CvScalar& b )
{
    double t0 = a.val[0]*b.val[0] - a.val[1]*b.val[1] -
                a.val[2]*b.val[2] - a.val[3]*b.val[3];

    double t1 = a.val[0]*b.val[1] + a.val[1]*b.val[0] +
                a.val[2]*b.val[3] - a.val[3]*b.val[2];

    double t2 = a.val[0]*b.val[2] - a.val[1]*b.val[3] +
                a.val[2]*b.val[0] + a.val[3]*b.val[1];

    double t3 = a.val[0]*b.val[3] + a.val[1]*b.val[2] -
                a.val[2]*b.val[1] + a.val[3]*b.val[0];

    a.val[0] = t0;
    a.val[1] = t1;
    a.val[2] = t2;
    a.val[3] = t3;

    return a;
}


inline CvScalar& operator /= ( CvScalar& a, const CvScalar& b )
{
    double inv_d = -1./(b.val[0]*b.val[0] + b.val[1]*b.val[1] +
                        b.val[2]*b.val[2] + b.val[3]*b.val[3]);
    return a *= cvScalar( b.val[0] * -inv_d, b.val[1] * inv_d,
                          b.val[2] * inv_d, b.val[3] * inv_d );
}


inline CvScalar& operator += ( CvScalar& a, double b )
{
    a.val[0] += b;
    return a;
}


inline CvScalar& operator -= ( CvScalar& a, double b )
{
    a.val[0] -= b;
    return a;
}


inline CvScalar operator + ( const CvScalar& a, const CvScalar& b )
{
    return cvScalar( a.val[0] + b.val[0], a.val[1] + b.val[1],
                     a.val[2] + b.val[2], a.val[3] + b.val[3] );
}


inline CvScalar operator - ( const CvScalar& a, const CvScalar& b )
{
    return cvScalar( a.val[0] - b.val[0], a.val[1] - b.val[1],
                     a.val[2] - b.val[2], a.val[3] - b.val[3] );
}


inline CvScalar operator + ( const CvScalar& a, double b )
{
    return cvScalar( a.val[0] + b, a.val[1], a.val[2], a.val[3] );
}


inline CvScalar operator - ( const CvScalar& a, double b )
{
    return cvScalar( a.val[0] - b, a.val[1], a.val[2], a.val[3] );
}


inline CvScalar operator + ( double a, const CvScalar& b )
{
    return cvScalar( a + b.val[0], b.val[1], b.val[2], b.val[3] );
}


inline CvScalar operator - ( double a, const CvScalar& b )
{
    return cvScalar( a - b.val[0], -b.val[1], -b.val[2], -b.val[3] );
}


inline CvScalar operator - ( const CvScalar& b )
{
    return cvScalar( -b.val[0], -b.val[1], -b.val[2], -b.val[3] );
}


inline CvScalar operator * ( const CvScalar& a, const CvScalar& b )
{
    CvScalar c = a;

    return (c *= b);
}


inline CvScalar operator * ( const CvScalar& a, double b )
{
    return cvScalar( a.val[0]*b, a.val[1]*b, a.val[2]*b, a.val[3]*b );
}


inline CvScalar operator * ( double a, const CvScalar& b )
{
    return cvScalar( b.val[0]*a, b.val[1]*a, b.val[2]*a, b.val[3]*a );
}


inline CvScalar operator / ( const CvScalar& a, const CvScalar& b )
{
    CvScalar c = a;
    return (c /= b);
}


inline CvScalar operator / ( const CvScalar& a, double b )
{
    double inv_b = 1./b;
    return cvScalar( a.val[0]*inv_b, a.val[1]*inv_b,
                     a.val[2]*inv_b, a.val[3]*inv_b );
}


inline CvScalar operator / ( double a, const CvScalar& b )
{
    double inv_d = -a/(b.val[0]*b.val[0] + b.val[1]*b.val[1] +
                       b.val[2]*b.val[2] + b.val[3]*b.val[3]);
    return cvScalar( b.val[0] * -inv_d, b.val[1] * inv_d,
                     b.val[2] * inv_d, b.val[3] * inv_d );
}


inline CvScalar& operator &= ( CvScalar& a, const CvScalar& b )
{
    int t0 = cvRound(a.val[0]) & cvRound(b.val[0]);
    int t1 = cvRound(a.val[1]) & cvRound(b.val[1]);
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = cvRound(a.val[2]) & cvRound(b.val[2]);
    t1 = cvRound(a.val[3]) & cvRound(b.val[3]);
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar& operator |= ( CvScalar& a, const CvScalar& b )
{
    int t0 = cvRound(a.val[0]) | cvRound(b.val[0]);
    int t1 = cvRound(a.val[1]) | cvRound(b.val[1]);
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = cvRound(a.val[2]) | cvRound(b.val[2]);
    t1 = cvRound(a.val[3]) | cvRound(b.val[3]);
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar& operator ^= ( CvScalar& a, const CvScalar& b )
{
    int t0 = cvRound(a.val[0]) ^ cvRound(b.val[0]);
    int t1 = cvRound(a.val[1]) ^ cvRound(b.val[1]);
    a.val[0] = t0;
    a.val[1] = t1;

    t0 = cvRound(a.val[2]) ^ cvRound(b.val[2]);
    t1 = cvRound(a.val[3]) ^ cvRound(b.val[3]);
    a.val[2] = t0;
    a.val[3] = t1;

    return a;
}


inline CvScalar operator & ( const CvScalar& a, const CvScalar& b )
{
    CvScalar c = a;
    return (c &= b);
}


inline CvScalar operator | ( const CvScalar& a, const CvScalar& b )
{
    CvScalar c = a;
    return (c |= b);
}


inline CvScalar operator ^ ( const CvScalar& a, const CvScalar& b )
{
    CvScalar c = a;
    return (c ^= b);
}


inline CvScalar operator ~ ( const CvScalar& a )
{
    return cvScalar( ~cvRound(a.val[0]), ~cvRound(a.val[1]),
                     ~cvRound(a.val[2]), ~cvRound(a.val[3])); 
}


/****************************************************************************************\
*                                   C++ Matrix Class                                     *
\****************************************************************************************/

struct  _CvMATConstElem_;
struct  _CvMATElem_;
struct  _CvMATElemCn_;

struct  _CvMAT_T_;
struct  _CvMAT_MUL_;
struct  _CvMAT_INV_;
struct  _CvMAT_SCALE_;
struct  _CvMAT_SCALE_SHIFT_;
struct  _CvMAT_ADD_;
struct  _CvMAT_ADD_EX_;
struct  _CvMAT_MUL_ADD_;
struct  _CvMAT_LOGIC_;
struct  _CvMAT_UN_LOGIC_;
struct  _CvMAT_NOT_;
struct  _CvMAT_CVT_;
struct  _CvMAT_COPY_;
struct  _CvMAT_DOT_OP_;
struct  _CvMAT_SOLVE_;
struct  _CvMAT_CMP_;

class CV_EXPORTS CvMAT : public CvMat
{
protected:

public:
    /* helper methods for retrieving/setting matrix elements */
    static double get( const uchar* ptr, int type, int coi = 0 );
    static void set( uchar* ptr, int type, int coi, double d );
    static void set( uchar* ptr, int type, int coi, int i );
    static void set( uchar* ptr, int type, double d );
    static void set( uchar* ptr, int type, int i );

    /******************* constructors ********************/
    /* empty */
    explicit CvMAT();

    /* creation */
    explicit CvMAT( int rows, int cols, int type, void* data, int step = CV_AUTOSTEP );
    explicit CvMAT( int rows, int type, void* data, int step = CV_AUTOSTEP );
    explicit CvMAT( int rows, int cols, int type );
    explicit CvMAT( int rows, int type );
    
    /* extracting part of an existing matrix */
    explicit CvMAT( const CvMat& mat, CvRect rect ); /* submatrix */
    explicit CvMAT( const CvMat& mat, int k, int i ); /* submatrix:
                                                    k == 0 - i-th row
                                                    k > 0 - i-th column
                                                    k < 0 - i-th diagonal */
    /* copying */
    CvMAT( const CvMat& mat );
    CvMAT( const CvMAT& mat );
    CvMAT( const IplImage& img );

    /* CvMAT b = op(a1,a2,...) */
    explicit CvMAT( const _CvMAT_T_& mat_t );
    explicit CvMAT( const _CvMAT_INV_& inv_mat );
    explicit CvMAT( const _CvMAT_ADD_& mat_add );
    explicit CvMAT( const _CvMAT_ADD_EX_& mat_add );
    explicit CvMAT( const _CvMAT_SCALE_& scale_mat );
    explicit CvMAT( const _CvMAT_SCALE_SHIFT_& scale_shift_mat );
    explicit CvMAT( const _CvMAT_MUL_& mmul );
    explicit CvMAT( const _CvMAT_MUL_ADD_& mmuladd );
    explicit CvMAT( const _CvMAT_LOGIC_& mat_logic );
    explicit CvMAT( const _CvMAT_UN_LOGIC_& mat_logic );
    explicit CvMAT( const _CvMAT_NOT_& not_mat );
    explicit CvMAT( const _CvMAT_COPY_& mat_copy );
    explicit CvMAT( const _CvMAT_CVT_& mat_copy );
    explicit CvMAT( const _CvMAT_DOT_OP_& dot_mul );
    explicit CvMAT( const _CvMAT_SOLVE_& solve_mat );
    explicit CvMAT( const _CvMAT_CMP_& cmp_mat );

    /* desctructor */
    ~CvMAT();

    /* copying and filling with a constant */
    CvMAT& operator = ( const CvMAT& mat );
    CvMAT& operator = ( const CvMat& mat );
    CvMAT& operator = ( const IplImage& img );
    CvMAT& operator = ( double fillval );
    CvMAT& operator = ( const CvScalar& fillval );
    
    /* b = op(a1, a2,...) */
    CvMAT& operator = ( const _CvMAT_T_& mat_t );
    CvMAT& operator = ( const _CvMAT_INV_& inv_mat );
    CvMAT& operator = ( const _CvMAT_ADD_& mat_add );

⌨️ 快捷键说明

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