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; }
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; }
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 */ }
static void _readIGXFileHelper(char *ptr_ig, int *q_no_ig, char c) { int magic, ncols, nrows, maxval; char fname[80]; uchar *tmp; uchar *pri; int *pro; int i; sprintf(fname, ptr_ig, c); pgmReadHeaderFile(fname, &magic, &ncols, &nrows, &maxval); if (ncols!=g_cols+g_slop || nrows!=g_rows) error("IG File '%s' is of the wrong size.", ptr_ig); tmp = (uchar*)pgmReadFile(fname, &ncols, &nrows); pri=(uchar *) tmp; pro=(int *) q_no_ig; for (i=g_rows*(g_cols+g_slop) ; i>0 ; i--) *pro++ = (int) *pri++; free(tmp); }
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; }
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; }
int main(int argc, char *argv[]) { BOOL leftImageHasBeenRead = FALSE; BOOL rightImageHasBeenRead = FALSE; BOOL disparityMapHasBeenRead = FALSE; BOOL do_matching = TRUE; BOOL do_postprocessing = TRUE; int tempCols, tempRows; clock_t time1, time2, time3, time4; char *ptr_ig = NULL; int i; /* Left and right images */ uchar *imgL, *imgR; /* Results after matching the scanlines independently */ uchar *disparity_map1, *depth_discontinuities1; /* Results after postprocessing the first disparity map */ uchar *disparity_map2, *depth_discontinuities2; g_maxdisp = -1; /* Parse command line */ for (i = 1 ; i < argc ; i++) { if (strcmp(argv[i], "-h") == 0) usage(argv[0]); else if (strcmp(argv[i], "-o") == 0) { i++; if (i == argc) error("Missing argument."); setOcclusionPenalty(atoi(argv[i])); } else if (strcmp(argv[i], "-r") == 0) { i++; if (i == argc) error("Missing argument."); setReward(atoi(argv[i])); } else if (strcmp(argv[i], "-d") == 0) { i++; if (i == argc) error("Missing argument."); strcpy(dir_in, argv[i]); } else if (strcmp(argv[i], "-rel") == 0) { i++; if (i == argc) error("Missing argument."); setReliableThreshold(atoi(argv[i])); } else if (strcmp(argv[i], "-alpha") == 0) { i++; if (i == argc) error("Missing argument."); setAlpha(atof(argv[i])); } else if (strcmp(argv[i], "-ma") == 0) { i++; if (i == argc) error("Missing argument."); setMaxAttractionThreshold(atoi(argv[i])); } else if (strcmp(argv[i], "-b") == 0) writeIntermediateResults = TRUE; else if (strcmp(argv[i], "-np") == 0) do_postprocessing = FALSE; else if (strcmp(argv[i], "-jp") == 0) do_matching = FALSE; else if (strcmp(argv[i], "-wpi") == 0) writePostprocessingIntermediateResults = TRUE; else if (!leftImageHasBeenRead) { strcpy(basenameL, argv[i]); leftImageHasBeenRead = TRUE; } else if (strcmp(argv[i], "-ig") == 0) { i++; if (i == argc) error("Missing argument."); strcpy(basename_ig, argv[i]); ptr_ig = (char *) basename_ig; } else if (rightImageHasBeenRead) { g_maxdisp = atoi((argv[i])); g_slop = g_maxdisp + 1; } else if (!rightImageHasBeenRead) { strcpy(basenameR, argv[i]); rightImageHasBeenRead = TRUE; } else if (!disparityMapHasBeenRead) { strcpy(basename_dm_in, argv[i]); disparityMapHasBeenRead = TRUE; } else warning("Unknown argument."); } if (!leftImageHasBeenRead || !rightImageHasBeenRead || (!do_matching && !disparityMapHasBeenRead) || (g_maxdisp == -1) || (g_maxdisp < 14) || (g_maxdisp > 50)) usage(argv[0]); sprintf(fnameL, "%s/%s", dir_in, basenameL); sprintf(fnameR, "%s/%s", dir_in, basenameR); /* Read images (and maybe disparity map and intensity gradients) */ printf("Attempting to read %s and\n" " %s\n", fnameL, fnameR); imgL = pgmReadFile(fnameL, &g_cols, &g_rows); disparity_map1 = malloc(g_rows*g_cols*sizeof(uchar)); if (disparity_map1 == NULL) error("(main) Memory not allocated"); depth_discontinuities1 = malloc(g_rows*g_cols*sizeof(uchar)); if (depth_discontinuities1 == NULL) error("(main) Memory not allocated"); disparity_map2 = malloc(g_rows*g_cols*sizeof(uchar)); if (disparity_map2 == NULL) error("(main) Memory not allocated"); depth_discontinuities2 = malloc(g_rows*g_cols*sizeof(uchar)); if (depth_discontinuities2 == NULL) error("(main) Memory not allocated"); imgR = pgmReadFile(fnameR, &tempCols, &tempRows); if (tempCols != g_cols || tempRows != g_rows) size_error(tempCols, tempRows); printf("Images successfully read. Their size is %3d by %3d\n", g_cols, g_rows); if (!do_matching) { printf("Attempting to read %s\n", basename_dm_in); disparity_map1 = pgmReadFile(basename_dm_in, &tempCols, &tempRows); if (tempCols != g_cols || tempRows != g_rows) size_error(tempCols, tempRows); } printf("Using maximum disparity of %d\n", g_maxdisp); if (do_matching) { time1 = clock(); /* Match scanlines using dynamic programming */ printf("Matching scanlines independently ...\n"); matchScanlines(imgL, imgR, disparity_map1, depth_discontinuities1, ptr_ig); /* Check the time */ time2 = clock(); printf("Done. Independent processing took %4.1f seconds " "of processor time.\n", (((float) time2 - time1)/ CLOCKS_PER_SEC)); } if (do_postprocessing) { time3 = clock(); /* Postprocess disparity map */ printf("Postprocessing disparity map ...\n"); postprocess(imgL, imgR, disparity_map1, disparity_map2, depth_discontinuities2); /* Check the time */ time4 = clock(); printf("Done. Postprocessing took %4.1f seconds of processor time.\n", (((float) time4 - time3)/ CLOCKS_PER_SEC)); } if (do_matching && do_postprocessing) { printf("Total processor time was %4.1f seconds.\n", (((float) time4 - time1)/ CLOCKS_PER_SEC)); } /* Write results */ if (do_matching && writeIntermediateResults) { printf("Writing to %s and %s\n", fname_dm_intermediate, fname_dd_intermediate); pgmWriteFile(fname_dm_intermediate, (unsigned char *) disparity_map1, g_cols, g_rows); pgmWriteFile(fname_dd_intermediate, (unsigned char *) depth_discontinuities1, g_cols, g_rows); } if (do_postprocessing) { printf("Writing to %s and %s\n", fname_dm, fname_dd); pgmWriteFile(fname_dm, (unsigned char *) disparity_map2, g_cols, g_rows); pgmWriteFile(fname_dd, (unsigned char *) depth_discontinuities2, g_cols, g_rows); } printf("\n"); free(imgL); free(imgR); free(disparity_map1); free(depth_discontinuities1); free(disparity_map2); free(depth_discontinuities2); }
/** ============================================================================ * @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 ; }