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

📄 dhid.c

📁 学习跟踪的好程序
💻 C
字号:
/**********************************************************************Finds the 150 best features in an image and tracks them through the next two images.  The sequential mode is set in order to speedprocessing.  The features are stored in a feature table, which is thensaved to a text file; each feature list is also written to a PPM file.**********************************************************************/#include <stdlib.h>#include <stdio.h>#include "pnmio.h"#include "klt.h"/* #define REPLACE */void main(){  unsigned char *img1, *img2;  char fnamein[100], fnameout[100];  KLT_TrackingContext tc;  KLT_FeatureList fl;  KLT_FeatureTable ft;  int nFeatures = 500, nFrames = 5;  int ncols, nrows;  int i;  tc = KLTCreateTrackingContext();  fl = KLTCreateFeatureList(nFeatures);  ft = KLTCreateFeatureTable(nFrames, nFeatures);  tc->sequentialMode = TRUE;  img1 = pgmReadFile("images/img_0001.pgm", NULL, &ncols, &nrows);  img2 = (unsigned char *) malloc(ncols*nrows*sizeof(unsigned char));  KLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);  KLTStoreFeatureList(fl, ft, 0);  KLTWriteFeatureListToPPM(fl, img1, ncols, nrows, "feat0.ppm");  for (i = 1 ; i < nFrames ; i++)  {    sprintf(fnamein, "images/img_%04d.pgm", i+1);    pgmReadFile(fnamein, img2, &ncols, &nrows);    KLTTrackFeatures(tc, img1, img2, ncols, nrows, fl);#ifdef REPLACE    KLTReplaceLostFeatures(tc, img2, ncols, nrows, fl);#endif    KLTStoreFeatureList(fl, ft, i);    sprintf(fnameout, "feat%d.ppm", i);    KLTWriteFeatureListToPPM(fl, img2, ncols, nrows, fnameout);  }  KLTWriteFeatureTable(ft, "features.txt", "%5.1f");  KLTWriteFeatureTable(ft, "features.ft", NULL);  /* write to matlab output file */  {
	  int j,feat; FILE *fp;	  fp = fopen("features.m","w");	  for (feat = 0 ; feat < ft->nFeatures ; feat++)		if (ft->feature[feat][nFrames-1]->val == 0) {		  fprintf(fp,"%d",ft->feature[feat][0]->val);		  for (j=0; j < nFrames; j++)				fprintf(fp, " %.1f %.1f", ft->feature[feat][j]->x, ft->feature[feat][j]->y);		  fprintf(fp,"\n");		}	  fclose(fp);  }}

⌨️ 快捷键说明

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