X-Git-Url: http://git.treefish.org/~alex/stickletrack.git/blobdiff_plain/9f9e04b576a579d96e339cb2339a71f4405af50b..6ef674a0c32b5ef389a97b80486c56be6b75b6e5:/stickletrack.cpp diff --git a/stickletrack.cpp b/stickletrack.cpp index 7022276..85deb6d 100755 --- a/stickletrack.cpp +++ b/stickletrack.cpp @@ -19,8 +19,6 @@ #include "stickletrack.h" #include "tracking.h" -#define BACKSECONDS 30 - double frametime = 0; int framenum = 0; @@ -45,10 +43,17 @@ static vector **tagintime; static int tagintimeidx=0; static int moresleep=0; static int gotoframe=0; -static int maxoutputfps; -static double rescalingfactor; static ofstream tanjaLogFile; +struct comargs { + int backBufferSize; + char *videoFileName; + int maxOutputFPS; + double rescalingFactor; +}; + +static comargs comArgs; + void genBaseDir() { #if defined(_WIN32) Props.basedir = getenv("HOMEDRIVE"); @@ -201,7 +206,7 @@ int timeWarp(int x, int y) { int wannago = startClickFrame + 10*horiMove*Props.fps/Props.width; int maxgo = min(ilatetagintime, Props.totframes); - int mingo = max(1, ilatetagintime - BACKSECONDS*Props.fps + 2); + int mingo = max(1, ilatetagintime - comArgs.backBufferSize*Props.fps + 2); if (wannago > maxgo) return maxgo; @@ -213,7 +218,7 @@ int timeWarp(int x, int y) { int rotatingTime( int whereyouwant ) { if ( whereyouwant < 0 ) - return BACKSECONDS*Props.fps + whereyouwant; + return comArgs.backBufferSize*Props.fps + whereyouwant; else return whereyouwant; } @@ -312,7 +317,7 @@ void mouseTracking(int evt, int x, int y, int flags, void* param){ void writeTanjaLog (int writeframenum, vector *tagstowrite) { stringstream outline; - if ( writeframenum%(Props.fps/maxoutputfps) == 0 ) { + if ( writeframenum%(Props.fps/comArgs.maxOutputFPS) == 0 ) { if ( tagstowrite->size() >= Prefs.manyfish ) { outline << (double)writeframenum/Props.fps; for ( int itag = 0; itag < Prefs.manyfish; itag++) { @@ -368,8 +373,8 @@ int process(VideoCapture& capture) { Mat frame, origframe, combinedmask; Props.fps = capture.get(CV_CAP_PROP_FPS); - Props.width = capture.get(CV_CAP_PROP_FRAME_WIDTH)*rescalingfactor; - Props.height = capture.get(CV_CAP_PROP_FRAME_HEIGHT)*rescalingfactor; + Props.width = capture.get(CV_CAP_PROP_FRAME_WIDTH)*comArgs.rescalingFactor; + Props.height = capture.get(CV_CAP_PROP_FRAME_HEIGHT)*comArgs.rescalingFactor; Props.totframes = capture.get(CV_CAP_PROP_FRAME_COUNT); Props.diagonal = sqrt( pow(Props.width, 2) + pow(Props.height, 2) ); @@ -382,11 +387,11 @@ int process(VideoCapture& capture) { exit(1); } - Mat frameintime[BACKSECONDS*Props.fps]; + Mat frameintime[comArgs.backBufferSize*Props.fps]; - tagintime = new vector*[BACKSECONDS*Props.fps]; + tagintime = new vector*[comArgs.backBufferSize*Props.fps]; - for (int iback = 0; iback < BACKSECONDS*Props.fps; iback++) + for (int iback = 0; iback < comArgs.backBufferSize*Props.fps; iback++) tagintime[iback] = new vector; capture >> frame; @@ -435,7 +440,7 @@ int process(VideoCapture& capture) { break; frame.convertTo(origframe, CV_32FC3); - resize(origframe, origframe, Size(0,0), rescalingfactor, rescalingfactor); + resize(origframe, origframe, Size(0,0), comArgs.rescalingFactor, comArgs.rescalingFactor); masking_getCombinedMask(origframe, combinedmask); @@ -448,10 +453,10 @@ int process(VideoCapture& capture) { frameintime[tagintimeidx] = origframe; ilatetagintime = framenum; - tagintimeidx = (tagintimeidx+1)%(BACKSECONDS*Props.fps); + tagintimeidx = (tagintimeidx+1)%(comArgs.backBufferSize*Props.fps); - if ( ilatetagintime >= BACKSECONDS*Props.fps-1 ) - writeTanjaLog( framenum - (BACKSECONDS*Props.fps-1), tagintime[ tagintimeidx ] ); + if ( ilatetagintime >= comArgs.backBufferSize*Props.fps-1 ) + writeTanjaLog( framenum - (comArgs.backBufferSize*Props.fps-1), tagintime[ tagintimeidx ] ); } gotoframe = framenum + 1; @@ -486,11 +491,11 @@ int process(VideoCapture& capture) { } - if ( ilatetagintime >= BACKSECONDS*Props.fps-1 ) { - int timeidx = (tagintimeidx+1)%(BACKSECONDS*Props.fps); - for ( int itime = 0; itime < BACKSECONDS*Props.fps-1; itime++ ) { - writeTanjaLog( framenum+1+itime - (BACKSECONDS*Props.fps-1), tagintime[ timeidx ] ); - timeidx = (timeidx+1)%(BACKSECONDS*Props.fps); + if ( ilatetagintime >= comArgs.backBufferSize*Props.fps-1 ) { + int timeidx = (tagintimeidx+1)%(comArgs.backBufferSize*Props.fps); + for ( int itime = 0; itime < comArgs.backBufferSize*Props.fps-1; itime++ ) { + writeTanjaLog( framenum+1+itime - (comArgs.backBufferSize*Props.fps-1), tagintime[ timeidx ] ); + timeidx = (timeidx+1)%(comArgs.backBufferSize*Props.fps); } } else { @@ -507,20 +512,50 @@ int process(VideoCapture& capture) { return 0; } -int main(int ac, char** av) { - if ( ac != 4 ) { - cout << "Usage: stickletrack " << endl; +void showUsage() { + cout << "Usage: stickletrack [OPTIONS]... " << endl; + cout << endl << "Available options:" << endl; + cout << "-x " << "\t" << "rescale video by a factor " << endl; + cout << "-o " << "\t" << "write to log maximally times per second" << endl; + cout << "-b " << "\t" << "buffer seconds for going back in time" << endl; +} + +bool parseComArgs (int ac, char** av) { + if ( ac < 2 || ac%2 ) { + showUsage(); exit(0); } - maxoutputfps = atoi( av[1] ); - rescalingfactor = atof( av[2] ); + comArgs.videoFileName = NULL; + comArgs.rescalingFactor = 1.0; + comArgs.maxOutputFPS = 25; + comArgs.backBufferSize = 10; + + for (int i = 1; i < ac-1; i++) + if (i + 1 != ac) + if (av[i] == "-x") { + comArgs.rescalingFactor = atof(av[i + 1]); + } else if (av[i] == "-o") { + comArgs.maxOutputFPS = atoi(av[i + 1]); + } else if (av[i] == "-b") { + comArgs.backBufferSize = atoi(av[i + 1]); + } else { + cout << "Unknown command line parameters!\n"; + showUsage(); + exit(0); + } + + comArgs.videoFileName = av[ac-1]; +} + +int main(int ac, char** av) { + parseComArgs(ac, av); - capture.open( av[3] ); + capture.open( comArgs.videoFileName ); genBaseDir(); - if (!capture.isOpened()) { + if (!capture.isOpened()) { cerr << "Failed to open a video device or video file!\n" << endl; return 1; }