static Mat background, foregroundmask, colormask, mScissors, scissorsmask;
static double Z = 1;
+static bool recomputeScissors = true;
void mouseScissors(int evt, int x, int y, int flags, void* param){
if (evt==CV_EVENT_LBUTTONDOWN) {
Prefs.scissorpoints->push_back( Point(x, y) );
+ recomputeScissors = true;
}
else if (evt==CV_EVENT_RBUTTONDOWN) {
nearestid = ipoint;
}
}
- if ( nearestid != -1 )
+ if ( nearestid != -1 ) {
Prefs.scissorpoints->erase( Prefs.scissorpoints->begin() + nearestid );
+ recomputeScissors = true;
+ }
}
}
}
else
scissorsmask = Mat::ones(Props.height, Props.width, CV_8U);
-
- //if ( ! windowclosed_sissors )
- if ( ! isWindowClosed("stickletrack_masking_scissorsmask") )
- imshow("stickletrack_masking_scissorsmask", mScissors);
}
void masking_getCombinedMask(const Mat& origframe, Mat& combinedmask) {
computeColorMask(origframe, colormask);
-
computeScissors(origframe, mScissors);
- computeScissorsMask(scissorsmask);
+ if ( recomputeScissors ) {
+ computeScissorsMask(scissorsmask);
+ recomputeScissors = false;
+ }
+
+ if ( ! isWindowClosed("stickletrack_masking_scissorsmask") )
+ imshow("stickletrack_masking_scissorsmask", mScissors);
+
bitwise_and(foregroundmask, colormask, combinedmask);
bitwise_and(combinedmask, scissorsmask, combinedmask);
}
#include "stickletrack.h"
#include "tracking.h"
-#define BACKSECONDS 30
-
double frametime = 0;
int framenum = 0;
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");
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;
int rotatingTime( int whereyouwant ) {
if ( whereyouwant < 0 )
- return BACKSECONDS*Props.fps + whereyouwant;
+ return comArgs.backBufferSize*Props.fps + whereyouwant;
else
return whereyouwant;
}
void writeTanjaLog (int writeframenum, vector<tag> *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++) {
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) );
exit(1);
}
- Mat frameintime[BACKSECONDS*Props.fps];
+ Mat frameintime[comArgs.backBufferSize*Props.fps];
- tagintime = new vector<tag>*[BACKSECONDS*Props.fps];
+ tagintime = new vector<tag>*[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<tag>;
capture >> frame;
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);
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;
}
- 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 {
return 0;
}
-int main(int ac, char** av) {
- if ( ac != 4 ) {
- cout << "Usage: stickletrack <maxoutputfps> <rescalingfactor> <videofilename>" << endl;
+void showUsage() {
+ cout << "Usage: stickletrack [OPTIONS]... <path to videofile>" << endl;
+ cout << endl << "Available options:" << endl;
+ cout << "-x <rescalingfactor>" << "\t" << "rescale video by a factor <rescalingfactor>" << endl;
+ cout << "-o <maxfps>" << "\t" << "write to log maximally <maxfps> times per second" << endl;
+ cout << "-b <bsize>" << "\t" << "buffer <bsize> 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;
}