int main() #endif { KLT_FeatureList fl; KLT_FeatureHistory fh; KLT_FeatureTable ft; int i; ft = KLTReadFeatureTable(NULL, "features.txt"); fl = KLTCreateFeatureList(ft->nFeatures); KLTExtractFeatureList(fl, ft, 1); KLTWriteFeatureList(fl, "feat1.txt", "%3d"); KLTReadFeatureList(fl, "feat1.txt"); KLTStoreFeatureList(fl, ft, 2); KLTWriteFeatureTable(ft, "ft2.txt", "%3d"); fh = KLTCreateFeatureHistory(ft->nFrames); KLTExtractFeatureHistory(fh, ft, 5); printf("The feature history of feature number 5:\n\n"); for (i = 0 ; i < fh->nFrames ; i++) printf("%d: (%5.1f,%5.1f) = %d\n", i, fh->feature[i]->x, fh->feature[i]->y, fh->feature[i]->val); KLTStoreFeatureHistory(fh, ft, 8); KLTWriteFeatureTable(ft, "ft3.txt", "%6.1f"); return 0; }
KLT_FeatureHistory KLTReadFeatureHistory( KLT_FeatureHistory fh_in, char *fname) { FILE *fp; KLT_FeatureHistory fh; int nFrames; structureType id; int indx; KLT_BOOL binary; /* whether file is binary or text */ int i; fp = fopen(fname, "rb"); if (fp == NULL) KLTError("(KLTReadFeatureHistory) Can't open file '%s' " "for reading", fname); if (KLT_verbose >= 1) fprintf(stderr, "(KLT) Reading feature history from '%s'\n", fname); id = _readHeader(fp, &nFrames, NULL, &binary); if (id != FEATURE_HISTORY) KLTError("(KLTReadFeatureHistory) File '%s' does not contain " "a FeatureHistory", fname); if (fh_in == NULL) { fh = KLTCreateFeatureHistory(nFrames); fh->nFrames = nFrames; } else { fh = fh_in; if (fh->nFrames != nFrames) KLTError("(KLTReadFeatureHistory) The feature history passed " "does not contain the same number of frames as " "the feature history in file '%s' ", fname); } if (!binary) { /* text file */ for (i = 0 ; i < fh->nFrames ; i++) { fscanf(fp, "%d |", &indx); if (indx != i) KLTError("(KLTReadFeatureHistory) Bad index at i = %d" "-- %d", i, indx); _readFeatureTxt(fp, fh->feature[i]); } } else { /* binary file */ for (i = 0 ; i < fh->nFrames ; i++) { _readFeatureBin(fp, fh->feature[i]); } } fclose(fp); return fh; }