ats.h

来自「微软的基于HMM的人脸识别原代码, 非常经典的说」· C头文件 代码 · 共 532 行 · 第 1/2 页

H
532
字号
                       long lLen,
                       double dbAcc);
/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    atsCompare1Db, atsCompare1Dc, atsCompare1Dfl
//    Purpose:
//      Comparing two 1D array and writing results to SUM & LST files
//    Context:
//    Parameters:
//      ArrayAct - actual array
//      ArrayExp - expected array
//      lLen     - lenght of this arrays
//      Tol      - tolerable limit
//    Returns:
//      Number of differents elements
//    Notes:
//F*/
long atsCompare1Db(  uchar* ArrayAct, uchar* ArrayExp, long  lLen, int    Tol );
long atsCompare1Dc(  char*  ArrayAct, char*  ArrayExp, long  lLen, int    Tol );
long atsCompare1Dfl( float* ArrayAct, float* ArrayExp, long  lLen, double Tol );


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    atsFindFirstErr
//    Purpose:
//      Finds first point in the ROI where the images differs much
//    Context:
//    Parameters:
//      imgA - first image
//      imgB - second image
//      eps  - maximal allowed difference between images
//    Returns:
//      First "bad" point coordinates (they are counted from ROI origin).
//F*/
CvPoint  atsFindFirstErr( IplImage* imgA, IplImage* imgB, double eps );

#ifndef WIN32
#define __inline static
#endif

/* Compare two angles in (0..360) */
__inline double atsCompareAngles( double angle1, double angle2 )
{
    double err = fabs(angle1 - angle2);
    double err1 = fabs(err - 360);
    return err < err1 ? err : err1;
}

/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ats1flInitGrad
//    Purpose:
//      Initialazing float array by gradient randomize value (every previous
//      value least next value)
//    Context:
//    Parameters:
//      Min  - minimal bound
//      Max  - maximum bound
//      pDst - destination array
//      lLen - size of array
//    Returns:
//    Notes:
//F*/
void ats1flInitGrad( double Min, double Max, float* pDst, long lLen );


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ataGetTickCount
//    Purpose: Returns the number of processor tics from turn on the processor
//    Context:
//    Parameters:
//    Returns:
//    Notes:
//F*/
#pragma warning(disable : 4035) /* conditional expression is constant    */
                                /* for no warnings in _ASSERT            */
__inline int64 atsGetTickCount()
{
#ifdef WIN32
    __asm{
        _emit 0fh;
        _emit 31h;
    }
#else
    __asm("rdtsc\n\r");
#endif
}
#pragma warning(once : 4035) /* conditional expression is constant    */
                             /* for no warnings in _ASSERT            */

__inline int atsRound( double val )
{
    static const int magic = 0x59C00000;
    double temp = (val + 1e-7) + *((float*)&magic);
    return *((int*)&temp);
}

/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:      atsTimerStart
//    Purpose:   Setting privileges level for task highest
//    Context:   
//    Parameters:
//    Returns:   
//    Notes:     
//F*/
void atsTimerStart( int timer );

/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:      atsTimerStop
//    Purpose:   Cleaning privileges level for task highest
//    Context:   
//    Parameters:
//    Returns:   
//    Notes:     
//F*/
void atsTimerStop( int timer );


extern char* atsTimingClass;  /* string "Timing" */
extern char* atsAlgoClass;    /* string "Algorithm" */
extern int   atsCPUFreq;      /* CPU frequency (MHz) */

#define  ATS_TICS_TO_USECS(tics)    (((double)(tics))/atsCPUFreq)

/******************************************************************************/
/*                     Extended random number generation                      */
/******************************************************************************/

typedef struct
{
    unsigned  seed;
    int       ia, ib;  /* for integer random numbers */
    float     fa, fb;  /* for float random numbers */
    int       shift;   /* if (upper - lower) is power of two */
    int       mask;    /* float mask */
} AtsRandState;

unsigned  atsGetSeed( void );  /* get seed using processor tick counter */

/* will generate random numbers in [lower,upper) */
void  atsRandInit( AtsRandState* state, double lower, double upper, unsigned seed );
void  atsRandSetBounds( AtsRandState* state, double lower, double upper );
void  atsRandSetFloatBits( AtsRandState* state, int bits );
float atsRand32f( AtsRandState* state );
void  atsbRand32f( AtsRandState* state, float* vect, int len );
int   atsRand32s( AtsRandState* state );
void  atsbRand32s( AtsRandState* state, int* vect, int len );
void  atsbRand16s( AtsRandState* state, short* vect, int len );
void  atsbRand8u( AtsRandState* state, uchar* vect, int len );
void  atsbRand8s( AtsRandState* state, char* vect, int len );
void  atsbRand64d( AtsRandState* state, double* vect, int len );

/* simply returns seed */
int   atsRandPlain32s( AtsRandState* state );
/* return float: 0..1 */
float atsRandPlane32f( AtsRandState* state );

int   atsIsNaN( double x );

/******************************************************************************/
/*                                Data input/output                           */
/******************************************************************************/

float*  atsReadMatrix( const char* filename, int* m, int* n );
void    atsWriteMatrix( const char* filename, int m, int n, float* data );


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:      atsInitModuleTestData
//    Purpose:   Init system path to test data
//    Context:   
//    Parameters:
//              module           - path to module (argv[0])
//              path_from_module - path from module
//    Returns:   
//    Notes:     
//F*/
void atsInitModuleTestData( char* module, char* path_from_module );

/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:      atsGetTestDataPath
//    Purpose:   Init buffer by path to test data file
//    Context:   
//    Parameters:
//              buffer    - buffer to init
//              folder    - test data folder (may be NULL)
//              filename  - data file (may be NULL)
//              extention - file extention (may be NULL)
//    Returns:
//              returns pointer to buffer
//    Notes:     
//F*/
char* atsGetTestDataPath( char* buffer, char* folder, char* filename, char* extention );


/******************************************************************************/
/*                                 Defines                                    */
/******************************************************************************/

#define ATS_SWAP( a, b, temp )  ((temp) = (a), (a) = (b), (b) = temp)
#define ATS_RANGE( x, a, b )  ((a) <= (x) && (x) < (b))

/* min & max without jumps */
#define ATS_MIN(a, b)  ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
#define ATS_MAX(a, b)  ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))

/* Converts float to 2-complement representation for integer comparing */
#define ATS_TOGGLE_FLT(x)  (((x)&0x7fffffff)^(((int)(x))>>31))

#define ATS_DIM(a)         (sizeof(a)/sizeof((a)[0]))


/* Increases the <value> by adding or multiplying by the <delta> */
#define ATS_INCREASE( value, delta_type, delta ) \
    ((value) = (delta_type) == 0 ? (value)+(delta) : (value)*(delta))


#define ATS_TIC_MAX  0x7fffffffffffffffI64

#define ATS_START_TIMING() int64 temp = atsGetTickCount();
#define ATS_END_TIMING()   temp = atsGetTickCount() - temp; tics = ATS_MIN( tics, temp );

#define ATS_MEASURE( act ) \
    ATS_START_TIMING()     \
    (act);                 \
    ATS_END_TIMING()

#define ATS_COOLMEASURE(func)                       \
{                                                   \
    int i,j;                                        \
    int64 time_min = 0;                           \
                                                    \
    atsTimerStart( 0 );                             \
	for(j=0;j<10;j++)                              \
    {                                               \
		int64 temp = atsGetTickCount();           \
		for(i=0;i<10;i++) func;                     \
		temp = atsGetTickCount() - temp;            \
		if(!time_min) time_min = temp;              \
		else time_min = ATS_MIN( time_min, temp );  \
	}                                               \
    atsTimerStop( 0 );                              \
                                                    \
    tics = (time_min) / 10;                         \
}


#undef NULL
#define NULL 0

#define ATS_CON TW_CON | TW_RUN | TW_DEBUG | TW_RERUN
#define ATS_LST TW_LST | TW_RUN | TW_DEBUG | TW_RERUN
#define ATS_SUM TW_SUM | TW_RUN | TW_DEBUG | TW_RERUN

#define USECS 1000000
#define CPU   1000000


#ifdef __cplusplus
}
#endif



#endif /* _ATS_H_ */

/* End of file. */

⌨️ 快捷键说明

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