Example #1
0
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;
}
Example #2
0
void KLTTracker::init(
        const CImg<uint8_t>& img,
        int numFeatures) {
    tracks.clear();
    
    if (tCtx != nullptr) {
        KLTFreeTrackingContext(tCtx);
    }
    
    tCtx = KLTCreateTrackingContext();

    if (curFL != nullptr) {
        KLTFreeFeatureList(curFL);
    }

    curFL = KLTCreateFeatureList(numFeatures);

    KLTSelectGoodFeatures(tCtx, const_cast<uint8_t*>(img.data()),
            img.width(), img.height(), curFL);

    tracks.resize(curFL->nFeatures);

    for (int i = 0; i < curFL->nFeatures; i++) {
        const auto& f = curFL->feature[i];

        if (f->val >= 0) {
            tracks[i].push_back(Eigen::Vector2f(f->x, f->y));
        }
    }
}
int main()
#endif
{
  unsigned char *img1, *img2;
  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  int nFeatures = 100;
  int ncols, nrows;

  tc = KLTCreateTrackingContext();
  fl = KLTCreateFeatureList(nFeatures);

  img1 = pgmReadFile("img0.pgm", NULL, &ncols, &nrows);
  img2 = pgmReadFile("img1.pgm", NULL, &ncols, &nrows);

  KLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);

  KLTWriteFeatureListToPPM(fl, img1, ncols, nrows, "feat1.ppm");
  KLTWriteFeatureList(fl, "feat1.txt", "%3d");

  KLTTrackFeatures(tc, img1, img2, ncols, nrows, fl);
  KLTReplaceLostFeatures(tc, img2, ncols, nrows, fl);

  KLTWriteFeatureListToPPM(fl, img2, ncols, nrows, "feat2.ppm");
  KLTWriteFeatureList(fl, "feat2.txt", "%3d");

  return 0;
}
Example #4
0
KLT_FeatureList KLTReadFeatureList(
  KLT_FeatureList fl_in,
  char *fname)
{
  FILE *fp;
  KLT_FeatureList fl;
  int nFeatures;
  structureType id;
  int indx;
  KLT_BOOL binary; 		/* whether file is binary or text */
  int i;

  fp = fopen(fname, "rb");
  if (fp == NULL)  KLTError("(KLTReadFeatureList) Can't open file '%s' "
                            "for reading", fname);
  if (KLT_verbose >= 1) 
    fprintf(stderr,  "(KLT) Reading feature list from '%s'\n", fname);
  id = _readHeader(fp, NULL, &nFeatures, &binary);
  if (id != FEATURE_LIST) 
    KLTError("(KLTReadFeatureList) File '%s' does not contain "
             "a FeatureList", fname);

  if (fl_in == NULL)  {
    fl = KLTCreateFeatureList(nFeatures);
    fl->nFeatures = nFeatures;
  }
  else  {
    fl = fl_in;
    if (fl->nFeatures != nFeatures)
      KLTError("(KLTReadFeatureList) The feature list passed "
               "does not contain the same number of features as "
               "the feature list in file '%s' ", fname);
  }

  if (!binary) {  /* text file */
    for (i = 0 ; i < fl->nFeatures ; i++)  {
      fscanf(fp, "%d |", &indx);
      if (indx != i) KLTError("(KLTReadFeatureList) Bad index at i = %d"
                              "-- %d", i, indx);
      _readFeatureTxt(fp, fl->feature[i]);
    }
  } else {  /* binary file */
    for (i = 0 ; i < fl->nFeatures ; i++)  {
      _readFeatureBin(fp, fl->feature[i]);
    }
  }

  fclose(fp);

  return fl;
}
Example #5
0
int main()
#endif
{
  unsigned char *img1, *img2;
  char fnamein[100], fnameout[100];
  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  KLT_FeatureTable ft;
  int nFeatures = 150, nFrames = 10;
  int ncols, nrows;
  int i;

  tc = KLTCreateTrackingContext();
  fl = KLTCreateFeatureList(nFeatures);
  ft = KLTCreateFeatureTable(nFrames, nFeatures);
  tc->sequentialMode = TRUE;
  tc->writeInternalImages = FALSE;
  tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */
 
  img1 = pgmReadFile("img0.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, "img%d.pgm", i);
    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);

  KLTFreeFeatureTable(ft);
  KLTFreeFeatureList(fl);
  KLTFreeTrackingContext(tc);
  free(img1);
  free(img2);

  return 0;
}
Example #6
0
void main()
{
  unsigned char *img1, *img2;
  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  int nFeatures = 100;
  int ncols, nrows;
  int i;

  tc = KLTCreateTrackingContext();
  KLTPrintTrackingContext(tc);
  fl = KLTCreateFeatureList(nFeatures);

  img1 = pgmReadFile("img0.pgm", NULL, &ncols, &nrows);
  img2 = pgmReadFile("img1.pgm", NULL, &ncols, &nrows);

  KLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);

  printf("\nIn first image:\n");
  for (i = 0 ; i < fl->nFeatures ; i++)  {
    printf("Feature #%d:  (%f,%f) with value of %d\n",
           i, fl->feature[i]->x, fl->feature[i]->y,
           fl->feature[i]->val);
  }

  KLTWriteFeatureListToPPM(fl, img1, ncols, nrows, "feat1.ppm");
  KLTWriteFeatureList(fl, "feat1.txt", "%3d");

  KLTTrackFeatures(tc, img1, img2, ncols, nrows, fl);

  printf("\nIn second image:\n");
  for (i = 0 ; i < fl->nFeatures ; i++)  {
    printf("Feature #%d:  (%f,%f) with value of %d\n",
           i, fl->feature[i]->x, fl->feature[i]->y,
           fl->feature[i]->val);
  }

  KLTWriteFeatureListToPPM(fl, img2, ncols, nrows, "feat2.ppm");
  KLTWriteFeatureList(fl, "feat2.fl", NULL);      /* binary file */
  KLTWriteFeatureList(fl, "feat2.txt", "%5.1f");  /* text file   */
}
Example #7
0
int main( int argc, const char* argv[] )
{
  unsigned char *img1, *img2;
  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  //KLT_FeatureTable ft;
  int ncols, nrows;
  int i, j;
  FILE *fp;

  int nFeatures = 430;
  int sFrame = 0;
  int eFrame = 0;
  char *fmt  = "%d";
  char *base;
  char fname[1024];
  char ffmt[1024];

  if( argc == 1 ) {
    printf( "Usage: %s  <basename_of_pgm_files>"
            "  [-fmt <pgm_sequence_format = %s>]"
	    "  [-ef <index_of_end_frame = %d>]"
	    "  [-np <#_of_tracking_points = %d>]"
	    "  [-sf <index_of_start_frame = %d>]\n"
	    "Ex) %s ../hotel/hotel.seq -fmt %%d -ef 100 -np 430 -sf 0\n"
	    "Ex) %s ../castle/castle. -fmt %%03d -ef 27 -np 110 -sf 0\n"
	    "Ex) %s ../medusa/medusa -fmt %%03d -sf 110 -ef 180 -np 830\n",
	    argv[0], fmt, eFrame, nFeatures, sFrame, argv[0], argv[0], argv[0] );
    return 0;
  }
  for( i = 1; i < argc; ++i ) {
    if( !strcmp( argv[i], "-sf" ) ) {
      sFrame = atoi( argv[++i] );
    } 
    else if( !strcmp( argv[i], "-ef" ) ) {
      eFrame = atoi( argv[++i] );
    } 
    else if( !strcmp( argv[i], "-np" ) ) {
      nFeatures = atoi( argv[++i] );
    } 
    else if( !strcmp( argv[i], "-fmt" ) ) {
      fmt = (char *)argv[++i];
    } 
    else {
      base = (char *)argv[i];
    }
  }
  sprintf(ffmt, "%%s%s%%s\0", fmt);
  
  tc = KLTCreateTrackingContext();
  tc->mindist = 15; // See klt.c for default values
  tc->window_width  = 50; 
  tc->window_height = 50;
  tc->max_residue = 30;
  tc->min_determinant = 0.001;
  //tc->min_eigenvalue = 3;
  //tc->borderx = 50;
  //tc->bordery = 50;
  //tc->affine_window_width = 51;
  //tc->affine_window_height = 51;
  KLTChangeTCPyramid(tc, 15);
  KLTUpdateTCBorder(tc);
  KLTPrintTrackingContext(tc);

  fl = KLTCreateFeatureList(nFeatures);
  //ft = KLTCreateFeatureTable(nFrames, nFeatures);
  tc->sequentialMode = TRUE;
  tc->writeInternalImages = FALSE;
  tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */

  i = sFrame;
  sprintf(fname, ffmt, base, i, ".pgm");
  img1 = pgmReadFile(fname, NULL, &ncols, &nrows);
  KLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);
  // write
  sprintf(fname, ffmt, base, i, ".feat.ppm");   /* ppm file    */
  KLTWriteFeatureListToPPM(fl, img1, ncols, nrows, fname);
  //sprintf(fname, ffmt, base, i, ".feat.fl");  /* binary file */
  //KLTWriteFeatureList(fl, fname, NULL);
  sprintf(fname, ffmt, base, i, ".feat.txt");   /* text file   */
  //KLTWriteFeatureList(fl, fname, "%5.1f");
  MyKLTWriteFeatureList(fl, fname);
  
  for (i = sFrame+1; i <= eFrame; i++) {
    sprintf(fname, ffmt, base, i, ".pgm");
    img2 = pgmReadFile(fname, NULL, &ncols, &nrows);
    KLTTrackFeatures(tc, img1, img2, ncols, nrows, fl);
#ifdef REPLACE
    KLTReplaceLostFeatures(tc, img2, ncols, nrows, fl);
#endif

    // write
    sprintf(fname, ffmt, base, i, ".feat.ppm");   /* ppm file    */
    KLTWriteFeatureListToPPM(fl, img1, ncols, nrows, fname);
    //sprintf(fname, ffmt, base, i, ".feat.fl");  /* binary file */
    //KLTWriteFeatureList(fl, fname, NULL);
    sprintf(fname, ffmt, base, i, ".feat.txt");   /* text file   */
    //KLTWriteFeatureList(fl, fname, "%5.1f");
    MyKLTWriteFeatureList(fl, fname);

    img1 = img2;
  }
 
  sprintf(fname, ffmt, base, eFrame, ".feat.ppm");
  KLTWriteFeatureListToPPM(fl, img1, ncols, nrows, fname);

  //KLTFreeFeatureTable(ft);
  KLTFreeFeatureList(fl);
  KLTFreeTrackingContext(tc);
  free(img1);
  //free(img2);
  return 0;
}
Example #8
0
File: main.c Project: Imara90/ESLab
int main(int argc, char ** argv)
{
    //Timer appTimer;
    //initTimer(&appTimer, "APP Time");

    unsigned char *img1, *img2;
    char fnamein[100], fnameout[100];
    KLT_TrackingContext tc;
    KLT_FeatureList fl;
    KLT_FeatureTable ft;
    int nFeatures;
    int nFrames;
    int ncols, nrows;
    int i;

    if(argc == 3)
    {
        nFeatures = atoi(argv[1]);
        nFrames = atoi(argv[2]);
    }
    else
    {
        nFeatures = 512;
        nFrames = 10;
    }

    tc = KLTCreateTrackingContext();
    fl = KLTCreateFeatureList(nFeatures);
    ft = KLTCreateFeatureTable(nFrames, nFeatures);
    tc->sequentialMode = TRUE;
    tc->writeInternalImages = FALSE;
    tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */

    //startTimer(&appTimer);
    img1 = pgmReadFile("img0.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, "img%d.pgm", i);
        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);
    }
    //stopTimer(&appTimer);
    //printTime(appTimer);
    //printf("Frames per second = %4.2f\n", nFrames / getTime(appTimer) *1000 );

    KLTWriteFeatureTable(ft, "features.txt", "%5.1f");
    KLTWriteFeatureTable(ft, "features.ft", NULL);

    KLTFreeFeatureTable(ft);
    KLTFreeFeatureList(fl);
    KLTFreeTrackingContext(tc);
    free(img1);
    free(img2);

    return 0;
}
Example #9
0
//-------------------------------------------------------------------
  void klt_tracker_t::init(std::string& params)
  {
    //
    core::config_parser_t config;
    //
    if(config.load(core::ini, params))
    {
    printf("KLT::OPENED config file\n");
    //
    nfeatures_ = config.get<int>("kltconf.nFeatures", 150);
    //
    nrows_ = config.get<int>("kltconf.nrows", 240);
    //
    ncols_ = config.get<int>("kltconf.ncols", 320);
    //
    fl_ = KLTCreateFeatureList(nfeatures_);    
    //
    tc_->mindist = config.get<int>("kltconf.mindist", 20);
    //
    tc_->window_width  = config.get<int>("kltconf.window_width", 9);
    //
    tc_->window_height = config.get<int>("kltconf.window_height", 9);
    //
    tc_->sequentialMode         = 
      config.get<KLT_BOOL>("kltconf.sequentialMode", 1);
    //
    tc_->lighting_insensitive   =
      config.get<KLT_BOOL>("kltconf.lighting_insensitive",0);
    //
    tc_->writeInternalImages    = 
      config.get<KLT_BOOL>("kltconf.writeInternalImages", 0);
    //
    tc_->affineConsistencyCheck = 
      config.get<int>("kltconf.affineConsistencyCheck", 2); 
    //
    KLTSetVerbosity(config.get<int>("kltconf.verbosity", 0));
    }
    else
    {
    printf("KLT::cannot find config file %s\n",params);
    //
    nfeatures_ = 150;
    //
    nrows_ = 240;
    //
    ncols_ = 320;
    //
    fl_ = KLTCreateFeatureList(nfeatures_);    
    //
    tc_->mindist = 20;
    //
    tc_->window_width  = 9;
    //
    tc_->window_height = 9;
    //
    tc_->sequentialMode         = 1;
    //
    tc_->writeInternalImages    = 0;
    //
    tc_->affineConsistencyCheck = 2;
    //
    KLTSetVerbosity(0);
    }

    //
    printf("KLT initialized: %d %d\n", nrows_, ncols_);
    KLTPrintTrackingContext(tc_);
    //
    npixels_ = static_cast<size_t>(nrows_*ncols_);
    //allocate images, the raw way
    img_pre_ = new core::uint8_t[npixels_];
  }
Example #10
0
FeatureVector *KLTFeatureRetrievalGrey(unsigned char **GreyArray,int nCols,int nRows, int nFrames,int nFeatures)
{
  unsigned char *img1, *img2;
  FeatureVector *host_feature;
  int i,j;

  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  KLT_FeatureTable ft;

  if (nFrames < 2) return NULL;
  if (nFeatures < 3) return NULL;

  host_feature = new FeatureVector[nFrames];
  for (i=0;i<nFrames;i++) host_feature[i].Create(nFeatures);

  img1 = &(GreyArray[0][0]);

  tc = KLTCreateTrackingContext();
  fl = KLTCreateFeatureList(nFeatures);
  ft = KLTCreateFeatureTable(nFrames, nFeatures);

  tc->sequentialMode = TRUE;
  tc->writeInternalImages = FALSE;
  tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */

  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, "img%d.pgm", i);
	img2 = &(GreyArray[i][0]);
    KLTTrackFeatures(tc, img1, img2, nCols, nRows, fl);
//    KLTReplaceLostFeatures(tc, img2, ncols, nrows, fl);
    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);

    for (j = 0 ; j < ft->nFeatures ; j++)  
	{
      for (i = 0 ; i < ft->nFrames ; i++)
	  {
		host_feature[i].vertex[j][0] = ft->feature[j][i]->x;
		host_feature[i].vertex[j][1] = ft->feature[j][i]->y;
		if (ft->feature[j][i]->val>=0) host_feature[i].isValid[j] = 1;
			else host_feature[i].isValid[j] = ft->feature[j][i]->val;
		
	  }
    }  

  KLTFreeFeatureTable(ft);
  KLTFreeFeatureList(fl);
  KLTFreeTrackingContext(tc);
  
  return host_feature;
}
Example #11
0
FeatureVector *KLTFeatureRetrievalListMin(IMGList *RGBImgList,int nCols,int nRows, int nFrames,int nFeatures,int nMinFeatures)
{
  unsigned char *img1, *img2;
  IMGList *pImg,*GreyArray=NULL,**GreyArryTable;
  FeatureVector *host_feature;
  int i,j,nFeatCount,maxID;

  KLT_TrackingContext tc;
  KLT_FeatureList fl,fl_pre;
  KLT_FeatureTable ft;

  if (nFrames < 2) return NULL;
  if (nFeatures < 3) return NULL;
  if (!RGBImgList) return NULL;
  if (nFeatures<nMinFeatures) return NULL;


  host_feature = new FeatureVector[nFrames];
  for (i=0;i<nFrames;i++) host_feature[i].Create(nFeatures);

  GreyArryTable = new IMGList*[nFrames];

  pImg = RGBImgList;
  for (i=0;i<nFrames;i++)
  {
	  GreyArray = new IMGList(nCols,nRows,1);
	  GreyArryTable[i] = GreyArray;
	  _RGB_ToGray(pImg->Img,GreyArryTable[i]->Img,nCols*nRows);
	  GO_NEXT(pImg);
  }


  tc = KLTCreateTrackingContext();
  fl = KLTCreateFeatureList(nFeatures);
  fl_pre = KLTCreateFeatureList(nFeatures);
  ft = KLTCreateFeatureTable(nFrames, nFeatures);
	  
  	  img1 = GreyArryTable[0]->Img;

	  tc->sequentialMode = TRUE;
	  tc->writeInternalImages = FALSE;
	  tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */

	  KLTSelectGoodFeatures(tc, img1, nCols, nRows, fl);
	  KLTStoreFeatureList(fl, ft, 0);

	  for (i = 1; i < nFrames ; i++)  
	  {
		img2 = GreyArryTable[i]->Img;
		
		printf("Tracking %dth frame\n",i);
		KLTTrackFeatures(tc, img1, img2, nCols, nRows, fl);
		
		nFeatCount = 0;
		for (j=0;j<fl->nFeatures;j++)
			if (fl->feature[j]->val>=0) nFeatCount++;

		if (nFeatCount<nMinFeatures)
		{
			for (j=0;j<fl->nFeatures;j++)
				if (fl->feature[j]->val<0) 
					host_feature[i].isValid[j] = 13083;

			KLTReplaceLostFeatures(tc, img2, nCols, nRows, fl);
			KLTStoreFeatureList(fl, ft, i);
		}
		else
			KLTStoreFeatureList(fl, ft, i);
	  }

	  maxID = 0;
	  for (j = 0 ; j < ft->nFeatures ; j++)  
	  {
		  for (i=0;i<nFrames;i++)
		  {
				host_feature[i].vertex[j][0] = ft->feature[j][i]->x;
				host_feature[i].vertex[j][1] = ft->feature[j][i]->y;
				if (host_feature[i].isValid[j] ==13083) maxID++;
				if (ft->feature[j][i]->val>=0) 
				{
					host_feature[i].isValid[j] = maxID;
					if (i==nFrames-1)  {
						maxID++; 
						printf("Boundary ID = %d\n",maxID);
						continue;}
				}
				else 
				{
					host_feature[i].isValid[j] = ft->feature[j][i]->val;
					if (i>0)
					{
						if (ft->feature[j][i-1]->val>=0)
						{
								maxID++;
								printf("Internal ID = %d\n",maxID);
						}
					}
				}
		  }
	  }

	  KLTFreeFeatureTable(ft);
	  KLTFreeFeatureList(fl);
	  KLTFreeFeatureList(fl_pre);
	  KLTFreeTrackingContext(tc);

  for (i=0;i<nFrames;i++)
  {
	  pImg = GreyArryTable[i];
	  delete pImg;
  }
  delete[] GreyArryTable;

  return host_feature;
}
Example #12
0
FeatureVector *KLTFeatureRetrievalList(IMGList *RGBImgList,int nCols,int nRows, int nFrames,int nFeatures)
{
  unsigned char *img1, *img2;
  IMGList *pImg,*GreyArray=NULL,**GreyArryTable;
  FeatureVector *host_feature;
  int i,j;

  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  KLT_FeatureTable ft;

  if (nFrames < 2) return NULL;
  if (nFeatures < 3) return NULL;
  if (!RGBImgList) return NULL;
  

  host_feature = new FeatureVector[nFrames];
  for (i=0;i<nFrames;i++) host_feature[i].Create(nFeatures);


  GreyArryTable = new IMGList*[nFrames];

  pImg = RGBImgList;
  for (i=0;i<nFrames;i++)
  {
	  GreyArray = new IMGList(nCols,nRows,1);
	  GreyArryTable[i] = GreyArray;
	  _RGB_ToGray(pImg->Img,GreyArryTable[i]->Img,nCols*nRows);
	  GO_NEXT(pImg);
  }

  img1 = GreyArryTable[0]->Img;

  tc = KLTCreateTrackingContext();
  fl = KLTCreateFeatureList(nFeatures);
  ft = KLTCreateFeatureTable(nFrames, nFeatures);
  tc->sequentialMode = TRUE;
  tc->writeInternalImages = FALSE;
  tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */

  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, "img%d.pgm", i);
	img2 = GreyArryTable[i]->Img;;
    KLTTrackFeatures(tc, img1, img2, nCols, nRows, fl);
//    KLTReplaceLostFeatures(tc, img2, ncols, nrows, fl);
    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);

    for (j = 0 ; j < ft->nFeatures ; j++)  
	{
      for (i = 0 ; i < ft->nFrames ; i++)
	  {
		host_feature[i].vertex[j][0] = ft->feature[j][i]->x;
		host_feature[i].vertex[j][1] = ft->feature[j][i]->y;
		if (ft->feature[j][i]->val>=0) host_feature[i].isValid[j] = 1;
			else host_feature[i].isValid[j] = ft->feature[j][i]->val;
		
	  }
    }  

  KLTFreeFeatureTable(ft);
  KLTFreeFeatureList(fl);
  KLTFreeTrackingContext(tc);

  for (i=0;i<nFrames;i++)
  {
	  pImg = GreyArryTable[i];
	  delete pImg;
  }
  delete[] GreyArryTable;

  return host_feature;

}
Example #13
0
/** ============================================================================
 *  @func   pool_notify_Execute
 *
 *  @desc   This function implements the execute phase for this application.
 *
 *  @modif  None
 *  ============================================================================
 */
NORMAL_API
DSP_STATUS
pool_notify_Execute (IN Uint32 numIterations, Uint8 processorId, IN Char8 * strFeatures, IN Char8 * strFrames)
{
    DSP_STATUS  status    = DSP_SOK ;

    long long start;
	
	// Variables for klt
    unsigned char *img1, *img2;
    char fnamein[100], fnameout[100];
    KLT_TrackingContext tc;
    KLT_FeatureList fl;
    KLT_FeatureTable ft;
    int ncols, nrows;
    int i;
    int nFeatures;
    int nFrames;


#if defined(DSP)
    unsigned char *buf_dsp;
#endif

#ifdef DEBUG
    printf ("Entered pool_notify_Execute ()\n") ;
#endif

    nFeatures = atoi(strFeatures);
    nFrames = atoi(strFrames);


    unit_init();

    start = get_usec();

	tc = KLTCreateTrackingContext();
    fl = KLTCreateFeatureList(nFeatures);
    ft = KLTCreateFeatureTable(nFrames, nFeatures);
    tc->sequentialMode = TRUE;
    tc->writeInternalImages = FALSE;
    tc->affineConsistencyCheck = -1;  /* set this to 2 to turn on affine consistency check */

    //startTimer(&appTimer);
    img1 = pgmReadFile("img0.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, "img%d.pgm", i);
        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);
    }
    //stopTimer(&appTimer);
    //printTime(appTimer);
    //printf("Frames per second = %4.2f\n", nFrames / getTime(appTimer) *1000 );

    KLTWriteFeatureTable(ft, "features.txt", "%5.1f");
    KLTWriteFeatureTable(ft, "features.ft", NULL);

    KLTFreeFeatureTable(ft);
    KLTFreeFeatureList(fl);
    KLTFreeTrackingContext(tc);
    free(img1);
    free(img2);




#if !defined(DSP)
    printf(" Result is %d \n", sum_dsp(pool_notify_DataBuf,pool_notify_BufferSize));
#endif

#if defined(DSP)
    POOL_writeback (POOL_makePoolId(processorId, SAMPLE_POOL_ID),
                    pool_notify_DataBuf,
                    pool_notify_BufferSize);

    POOL_translateAddr ( POOL_makePoolId(processorId, SAMPLE_POOL_ID),
                         (void*)&buf_dsp,
                         AddrType_Dsp,
                         (Void *) pool_notify_DataBuf,
                         AddrType_Usr) ;
    NOTIFY_notify (processorId,pool_notify_IPS_ID,pool_notify_IPS_EVENTNO,1);

    sem_wait(&sem);
#endif

    printf("Sum execution time %lld us.\n", get_usec()-start);

    return status ;
}