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

📄 trsapi.c

📁 微软的基于HMM的人脸识别原代码, 非常经典的说
💻 C
📖 第 1 页 / 共 5 页
字号:
                break;
      };
      if (Trs_FlowStatus==TRS_QUIT) break;
    };
    ptr=ptr->next;                      /* Next test in a list                */
  };

  WrLn("-End testing.\n");

#ifdef ANYLIB
  iplRedirectError(oldStdError);
#endif

  trsTerminateAll();
  return FailsFound;
}

/* --- Return Test Phase Status ---------------------------------------------*/
/*
void Error(const char *str, int level){
  printf("%s\n",str);
  exit(level);
}
*/
/*---------------------------------------------------------------*/
/* --- Timing routines : use Win32 high performance Counter -----*/
/* ---               or  use clock function ---------------------*/
/*---------------------------------------------------------------*/

#define TIMER_STOPPED 0
#define TIMER_RUNNING 1
#define USECS 1000000.0

#if TRUE

/* #define DBG_PRINT(s) printf s*/

#define DBG_PRINT(s)

typedef struct _Timer_t {
   int    state;
   double total;
   double start;
} Timer_t;

static Timer_t       Timer[TRS_MAX_TIMER+1]={{0}};
static int           HighPriorityTimerCount=0;

#if defined USE_WIN32_TIMER && defined WIN32

#ifndef WIN32
    //typedef long long LARGE_INTEGER;
#endif

static double getCounter(void){
	static LARGE_INTEGER tick_counts = {{0,0}};

   if (!QueryPerformanceCounter(&tick_counts)) 
      return (double)clock();
	return ((double)tick_counts.u.HighPart * 65536.0 * 65536.0 +
		(double)tick_counts.u.LowPart);
}

static double getFrequency(void)
{
   static int        first_time = TRUE;
   static double     tick_frequency;
   LARGE_INTEGER     cps;

   if (!first_time) return tick_frequency;

   if (!QueryPerformanceFrequency(&cps))  {
      tick_frequency = (double)CLOCKS_PER_SEC;
   } else {
		tick_frequency = (double)cps.u.HighPart * 65536.0 * 65536.0 +
         (double)cps.u.LowPart;
   }
   first_time = FALSE;
   return tick_frequency;
}

TRSFUN(double, trsClocksPerSec,(void)) {return (double)getFrequency()/100.0;}

#else /* use clock() function */

#define getCounter()        (double)clock()
#define getFrequency()      (double)CLOCKS_PER_SEC

TRSFUN(double, trsClocksPerSec,(void)) {return (double)getFrequency();}

#endif


/*****************************************************************/
/* --- Timer routines -------------------------------------------*/
/*****************************************************************/

TRSFUN(void, trsTimerStart,(int No))
{
   if ((No<0) || (No>TRS_MAX_TIMER)) return;

  if ((No>=TRS_MIN_HP_TIMER) &&                 /* Priority Timers Range    */
      (No<=TRS_MAX_HP_TIMER) &&
      (Timer[No].state !=TIMER_RUNNING))        /* Exclude double start     */
   {
      if (HighPriorityTimerCount==0) trsHighPriority();
      HighPriorityTimerCount++;
   }

   Timer[No].state=TIMER_RUNNING;
   Timer[No].total=0.0;
   Timer[No].start=getCounter();
   DBG_PRINT(("\nIn TimerStart/start: %10.2f ", Timer[No].start));
   return;
}

TRSFUN(void, trsTimerContinue,(int No)) {
   
   if ((No<0) || (No>TRS_MAX_TIMER) || 
      (Timer[No].state ==TIMER_RUNNING)) return;

   /* Priority Timers will raise priority */
   if ((No>=TRS_MIN_HP_TIMER) && (No<=TRS_MAX_HP_TIMER)) {
      if (HighPriorityTimerCount==0) trsHighPriority();
      HighPriorityTimerCount++;
   }

   Timer[No].state=TIMER_RUNNING;
   Timer[No].start=getCounter();
   DBG_PRINT(("\nIn TimerStart/start: %10.2f ", Timer[No].start));
   return;
}

TRSFUN(void, trsTimerStop,(int No))
{
   double tempClock = getCounter();
   DBG_PRINT(("\nIn TimerStop/stop : %10.2f ", tempClock));

   if ((No<0) || (No>TRS_MAX_TIMER) || 
      (Timer[No].state==TIMER_STOPPED)) return;

   /* Priority Timers will raise priority */
   if ((No>=TRS_MIN_HP_TIMER) && (No<=TRS_MAX_HP_TIMER)) {
      HighPriorityTimerCount--;
      if (HighPriorityTimerCount==0) trsNormalPriority();
   }

   Timer[No].state=TIMER_STOPPED;
   Timer[No].total=Timer[No].total+tempClock-Timer[No].start;
   DBG_PRINT(("\nIn TimerStop/total: %10.2f ", Timer[No].total));
   return;
}

TRSFUN(double, trsTimerClock,(int No))
{
   double tempClock = getCounter();

   if ((No<0) || (No>TRS_MAX_TIMER)) return 0;
   if (Timer[No].state==TIMER_STOPPED)
      return Timer[No].total;
   else
      return Timer[No].total-Timer[No].start+tempClock;
}

TRSFUN(double, trsTimerSec,(int No))
{
   return trsTimerClock(No) / getFrequency();
}

TRSFUN(double, trsTimerUSec,(int No))
{
   return trsTimerClock(No) / getFrequency() * USECS;
}

#else

typedef struct _Timer_t {
  clock_t       total;
  clock_t       start;
  int           state;
} Timer_t;

  static Timer_t     Timer[TRS_MAX_TIMER+1]={{0}};
  static int         HighPriorityTimerCount=0;

TRSFUN(double, trsClocksPerSec,(void)) {return (double)CLOCKS_PER_SEC;}

TRSFUN(void,  trsTimerStart,   (int No)){

  if ((No<0) || (No>TRS_MAX_TIMER)) return;
  if ((No>=TRS_MIN_HP_TIMER) &&                 /* Priority Timers Range    */
      (No<=TRS_MAX_HP_TIMER) &&
      (Timer[No].state !=TIMER_RUNNING))        /* Exclude double start     */
  {
    if (HighPriorityTimerCount==0)              /* Current Low Priority     */
      trsHighPriority();
    HighPriorityTimerCount++;
  }
  Timer[No].state=TIMER_RUNNING;
  Timer[No].total=0;
  Timer[No].start=clock();
}

TRSFUN(void,  trsTimerStop,   (int No)){
  clock_t     tempClock;

  tempClock=clock();
  if ((No<0) || (No>TRS_MAX_TIMER)) return;
  if (Timer[No].state==TIMER_STOPPED)           /* Exclude double stop      */
    return;
  else {
    if ((No>=TRS_MIN_HP_TIMER) &&               /* Priority Timers Range    */
        (No<=TRS_MAX_HP_TIMER))                  
    {
      HighPriorityTimerCount--;
      if (HighPriorityTimerCount==0)           /* Last used HP Timer        */
        trsNormalPriority();
    }
    Timer[No].state=TIMER_STOPPED;
    Timer[No].total=Timer[No].total+tempClock-Timer[No].start;
  };
}

TRSFUN(void,  trsTimerContinue,(int No)){

   if ((No<0) || (No>TRS_MAX_TIMER) ||
       (Timer[No].state==TIMER_RUNNING)) return;
  
   if ((No>=TRS_MIN_HP_TIMER) && (No<=TRS_MAX_HP_TIMER))  {
      if (HighPriorityTimerCount==0)          /* Low Priority             */
        trsHighPriority();
      HighPriorityTimerCount++;
    }
   Timer[No].state=TIMER_RUNNING;
   Timer[No].start=clock();
}

TRSFUN(double, trsTimerClock, (int No)){
  clock_t     tempClock;

  tempClock=clock();
  if ((No<0) || (No>TRS_MAX_TIMER)) return 0;
  if (Timer[No].state==TIMER_STOPPED)
    return (double)(Timer[No].total);
  else
    return (double)(Timer[No].total-Timer[No].start+tempClock);
}

TRSFUN(double, trsTimerSec,(int No)) {

  return (double) trsTimerClock(No) / (double) CLOCKS_PER_SEC;
}
#endif

/*****************************************************************/
/* --- End of timer routines ------------------------------------*/
/*****************************************************************/


/* ==========================================================================*/

TRSFUN(int, trsScaleInit,(int start,int end,int step,int steptype,TRSScale_t *scale)){

  switch (steptype) {
    case TRS_STEP_MPY: if  (step==-1) return 0;break;
    case TRS_STEP_DIV: if ((step==-1) || (step==0)) return 0; break;
    case TRS_STEP_ADD: if ((end>start) && (step<0)) return 0;
                       if ((end<start) && (step>0)) return 0;
                       break;
  };
  scale->start    = start;
  scale->end      = end;
  scale->step     = step;
  scale->steptype = steptype;
  scale->current  = start;
  scale->init     = 0;
  return 1;
}

TRSFUN(int, trsScaleNextPoint,(TRSScale_t *scale, int *next)) {

  (*next) =scale->current;

  if (scale->init) {
    switch (scale->steptype) {
      case TRS_STEP_MPY:  (*next) *= scale->step;break;  /* Multiplicative step  */
      case TRS_STEP_ADD:  (*next) += scale->step;break;  /* Additive step        */
      case TRS_STEP_DIV:  (*next) /= scale->step;break;  /* Div step             */
    }

    if ((*next)==scale->current) return 0;           /* Abort infinite Loops */
  } else
    scale->init=1;

  if ((scale->end >= scale->start) && 
      (((*next) > scale->end) || ((*next) < scale->start)))
     return 0;                                       /* Out of range         */
  if ((scale->end <= scale->start) && 
      (((*next) < scale->end) || ((*next) > scale->start)))
     return 0;                                       /* Out of range         */

  scale->current=(*next);
  return 1;
}
#if FALSE
void testScale(void) {
   Scale_t VecOrderScale;
   int start, end, step, steptype,n;

   for (steptype=0;steptype<=2;steptype++) {
     for (step=-10;step<10;step++) {
       for (start=-10;start< 10;start++) {
         for (end=-10;end<10;end++) {
           printf("start=%d; end=%d; step=%d; steptype=%d\n", start,end, step, steptype);
           if (trsScaleInit(start,end,step,steptype,&VecOrderScale)) {
             while (trsScaleNextPoint(&VecOrderScale,&n)) {
               printf("%d ",n);
             }
             printf("\n");
           }
         }
       }
     }
   }
}
#endif

/* ==========================================================================*/

TRSFUN(void, trsPrintHelp,(TRSid_t * ptr,char mode,char *name,char *def,char *help))
{
  FILE       *helpfile;
  int        linecnt=0;
  int        ch,och;
  int        blocklev;
  char       helpname[256];

  if (mode)
  {
    if (mode=='?') trsPrintHeader(ptr,TRUE);
    if ((mode=='h') || (mode=='l') || (mode=='L'))
    {
/*      strcpy(helpname,ExePath);*/
      strcpy(helpname,ptr->file);

      helpfile=fopen(helpname,"r");
      if (!helpfile)
        printf("File %s not found",helpname);
      else
      {
        och=0; ch=0;
        if (mode == 'L') {
          while ( (!feof(helpfile)) )  {
            ch=fgetc(helpfile);
            putchar(ch);
          };
        } else {
          linecnt=1;
          while ( (linecnt<=ptr->line) && (!feof(helpfile)) )  {
            och=ch;
            ch=fgetc(helpfile);
            if (ch==LF) linecnt=linecnt+1;
          };
        };

        if (mode=='h') {
          while ( ((och!='/') || (ch!='*')) && (!feof(helpfile)) ) {
            och=ch;
            ch=fgetc(helpfile);
            if (ch==LF) linecnt=linecnt+1;
          };
          och=fgetc(helpfile);ch=fgetc(helpfile);
          while ( ((och!='*')||(ch!='/')) && (!feof(helpfile)) ) {
            putchar(och);
            och=ch;
            ch=fgetc(helpfile);
            if (ch==LF) {
              linecnt=linecnt+1;
            };
          };
        };

        if (mode=='l') {
          while ( (ch!='{') && (!feof(helpfile)) ) {
            ch=fgetc(helpfile);
            if (ch==LF)  linecnt=linecnt+1;
          };
          blocklev=1;

          while ( !feof(helpfile) ) {
            ch=fgetc(helpfile);
            if (ch=='{') blocklev=blocklev+1;
            if (ch=='}') blocklev=blocklev-1;
            if (blocklev==0) break;
            putchar(ch);
            if (ch==LF) {
              linecnt=linecnt+1;
              printf("%3d ",linecnt);
            };
          };
        };
        fclose(helpfile);
      };
    };
    WrLn("");
  } else {
    printf("  %s - %s\n",name,help);
    if (def)
      printf("  default = [%s]\n",def);
    else
      printf("  default = NONE\n");
    printf("  cmd=[%s]\n",helpprompt);
  }
}

/* --- Input ----------------------------------------------------------------*/

#if !defined _TRSREAD_C

TRSFUN(int, CmdWithoutPrefix,(char *buf, char *prompt, char *dstname,
                             char *type,char *def,    char *help)) {

  if (trsGetKeyArg('B')==NULL)
     trsMoreSize(PageSize);
  printf("%s%s, %s",prompt,dstname,type);
  if (def) printf(", [%s]",def);
  if (ReadSource==TRS_NoInFile)
     printf("?> ");
  else
     printf(" > ");

  ReadSource=TRS_TTYInput;
  FlowStatus=TRS_CONTINUE;
  gets(buf);
  for (;;) {
    switch (buf[0]) {
      case  0  : if (!def) {
                   ReadSource=TRS_DefaultNull;
                   FlowStatus=TRS_CONTINUE;
                   return FALSE;

⌨️ 快捷键说明

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