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

📄 klt.c

📁 KLT: An Implementation of the Kanade-Lucas-Tomasi Feature Tracker KLT: An Implementation of the
💻 C
📖 第 1 页 / 共 2 页
字号:
  fprintf(stderr, "\tbordery = %d\n", tc->bordery);  fprintf(stderr, "\tnPyramidLevels = %d\n", tc->nPyramidLevels);  fprintf(stderr, "\tsubsampling = %d\n", tc->subsampling);  fprintf(stderr, "\n\tpyramid_last = %s\n", (tc->pyramid_last!=NULL) ?          "points to old image" : "NULL");  fprintf(stderr, "\tpyramid_last_gradx = %s\n",           (tc->pyramid_last_gradx!=NULL) ?          "points to old image" : "NULL");  fprintf(stderr, "\tpyramid_last_grady = %s\n",          (tc->pyramid_last_grady!=NULL) ?          "points to old image" : "NULL");  fprintf(stderr, "\n\n");}/********************************************************************* * KLTChangeTCPyramid * */void KLTChangeTCPyramid(  KLT_TrackingContext tc,  int search_range){  float window_halfwidth;  float subsampling;  /* Check window size (and correct if necessary) */  if (tc->window_width % 2 != 1) {    tc->window_width = tc->window_width+1;    KLTWarning("(KLTChangeTCPyramid) Window width must be odd.  "               "Changing to %d.\n", tc->window_width);  }  if (tc->window_height % 2 != 1) {    tc->window_height = tc->window_height+1;    KLTWarning("(KLTChangeTCPyramid) Window height must be odd.  "               "Changing to %d.\n", tc->window_height);  }  if (tc->window_width < 3) {    tc->window_width = 3;    KLTWarning("(KLTChangeTCPyramid) Window width must be at least three.  \n"               "Changing to %d.\n", tc->window_width);  }  if (tc->window_height < 3) {    tc->window_height = 3;    KLTWarning("(KLTChangeTCPyramid) Window height must be at least three.  \n"               "Changing to %d.\n", tc->window_height);  }  window_halfwidth = min(tc->window_width,tc->window_height)/2.0f;  subsampling = ((float) search_range) / window_halfwidth;  if (subsampling < 1.0)  {		/* 1.0 = 0+1 */    tc->nPyramidLevels = 1;  } else if (subsampling <= 3.0)  {	/* 3.0 = 2+1 */    tc->nPyramidLevels = 2;    tc->subsampling = 2;  } else if (subsampling <= 5.0)  {	/* 5.0 = 4+1 */    tc->nPyramidLevels = 2;    tc->subsampling = 4;  } else if (subsampling <= 9.0)  {	/* 9.0 = 8+1 */    tc->nPyramidLevels = 2;    tc->subsampling = 8;  } else {    /* The following lines are derived from the formula:       search_range =        window_halfwidth * \sum_{i=0}^{nPyramidLevels-1} 8^i,       which is the same as:       search_range =        window_halfwidth * (8^nPyramidLevels - 1)/(8 - 1).       Then, the value is rounded up to the nearest integer. */    float val = (float) (log(7.0*subsampling+1.0)/log(8.0));    tc->nPyramidLevels = (int) (val + 0.99);    tc->subsampling = 8;  }}/********************************************************************* * NOTE:  Manually must ensure consistency with _KLTComputePyramid() */ static float _pyramidSigma(  KLT_TrackingContext tc){  return (tc->pyramid_sigma_fact * tc->subsampling);}/********************************************************************* * Updates border, which is dependent upon  * smooth_sigma_fact, pyramid_sigma_fact, window_size, and subsampling */void KLTUpdateTCBorder(  KLT_TrackingContext tc){  float val;  int pyramid_gauss_hw;  int smooth_gauss_hw;  int gauss_width, gaussderiv_width;  int num_levels = tc->nPyramidLevels;  int n_invalid_pixels;  int window_hw;  int ss = tc->subsampling;  int ss_power;  int border;  int i;  /* Check window size (and correct if necessary) */  if (tc->window_width % 2 != 1) {    tc->window_width = tc->window_width+1;    KLTWarning("(KLTUpdateTCBorder) Window width must be odd.  "               "Changing to %d.\n", tc->window_width);  }  if (tc->window_height % 2 != 1) {    tc->window_height = tc->window_height+1;    KLTWarning("(KLTUpdateTCBorder) Window height must be odd.  "               "Changing to %d.\n", tc->window_height);  }  if (tc->window_width < 3) {    tc->window_width = 3;    KLTWarning("(KLTUpdateTCBorder) Window width must be at least three.  \n"               "Changing to %d.\n", tc->window_width);  }  if (tc->window_height < 3) {    tc->window_height = 3;    KLTWarning("(KLTUpdateTCBorder) Window height must be at least three.  \n"               "Changing to %d.\n", tc->window_height);  }  window_hw = max(tc->window_width, tc->window_height)/2;  /* Find widths of convolution windows */  _KLTGetKernelWidths(_KLTComputeSmoothSigma(tc),                      &gauss_width, &gaussderiv_width);  smooth_gauss_hw = gauss_width/2;  _KLTGetKernelWidths(_pyramidSigma(tc),                      &gauss_width, &gaussderiv_width);  pyramid_gauss_hw = gauss_width/2;  /* Compute the # of invalid pixels at each level of the pyramid.     n_invalid_pixels is computed with respect to the ith level        of the pyramid.  So, e.g., if n_invalid_pixels = 5 after        the first iteration, then there are 5 invalid pixels in        level 1, which translated means 5*subsampling invalid pixels        in the original level 0. */  n_invalid_pixels = smooth_gauss_hw;  for (i = 1 ; i < num_levels ; i++)  {    val = ((float) n_invalid_pixels + pyramid_gauss_hw) / ss;    n_invalid_pixels = (int) (val + 0.99);  /* Round up */  }  /* ss_power = ss^(num_levels-1) */  ss_power = 1;  for (i = 1 ; i < num_levels ; i++)    ss_power *= ss;  /* Compute border by translating invalid pixels back into */  /* original image */  border = (n_invalid_pixels + window_hw) * ss_power;  tc->borderx = border;  tc->bordery = border;}/********************************************************************* * KLTFreeTrackingContext * KLTFreeFeatureList * KLTFreeFeatureHistory * KLTFreeFeatureTable */void KLTFreeTrackingContext(  KLT_TrackingContext tc){  if (tc->pyramid_last)            _KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last);  if (tc->pyramid_last_gradx)      _KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_gradx);  if (tc->pyramid_last_grady)      _KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_grady);  free(tc);}void KLTFreeFeatureList(  KLT_FeatureList fl){  /* for affine mapping */  int indx;  for (indx = 0 ; indx < fl->nFeatures ; indx++)  {    /* free image and gradient  */    _KLTFreeFloatImage(fl->feature[indx]->aff_img);    _KLTFreeFloatImage(fl->feature[indx]->aff_img_gradx);    _KLTFreeFloatImage(fl->feature[indx]->aff_img_grady);    fl->feature[indx]->aff_img = NULL;    fl->feature[indx]->aff_img_gradx = NULL;    fl->feature[indx]->aff_img_grady = NULL;  }    free(fl);}void KLTFreeFeatureHistory(  KLT_FeatureHistory fh){  free(fh);}void KLTFreeFeatureTable(  KLT_FeatureTable ft){
  free(ft->feature[0][0]);  /* this plugs a memory leak found by Stefan Wachter */  free(ft->feature);  free(ft);}/********************************************************************* * KLTStopSequentialMode */void KLTStopSequentialMode(  KLT_TrackingContext tc){  tc->sequentialMode = FALSE;  _KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last);  _KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_gradx);  _KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_grady);  tc->pyramid_last = NULL;  tc->pyramid_last_gradx = NULL;  tc->pyramid_last_grady = NULL;}/********************************************************************* * KLTCountRemainingFeatures */int KLTCountRemainingFeatures(  KLT_FeatureList fl){  int count = 0;  int i;  for (i = 0 ; i < fl->nFeatures ; i++)    if (fl->feature[i]->val >= 0)      count++;  return count;}/********************************************************************* * KLTSetVerbosity */void KLTSetVerbosity(  int verbosity){  KLT_verbose = verbosity;}

⌨️ 快捷键说明

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