]> git.treefish.org Git - stickletrack.git/blobdiff - stickletrack.cpp
windows stay closed and stickletrack exits properly if tracking screen is closes.
[stickletrack.git] / stickletrack.cpp
index 7462af79d348ec4545b131b87f7bf987317de6bd..da812df1dec9a78ea97a7614dec2cab3d98d311b 100755 (executable)
 #include <ctime>
 #include <iomanip>
 
+// needed for _mkdir
+#if defined(_WIN32)
+#include <direct.h>
+#endif
+
 #include "masking.h"
 #include "stickletrack.h"
 #include "tracking.h"
@@ -57,6 +62,13 @@ void genBaseDir() {
   cout << "Using " << Props.basedir << " for data output." << endl;
 }
 
+bool isWindowClosed (const char* name) {
+  if ( cvGetWindowHandle(name) == NULL )
+    return true;
+  else
+    return false;
+}
+
 void beforeExit() {
   cout << "Exitting ..." << endl;
 
@@ -351,7 +363,7 @@ int process(VideoCapture& capture) {
   char filename[200];
   bool pleaseExit = false;
 
-  namedWindow("original", CV_WINDOW_KEEPRATIO);
+  namedWindow("stickletrack_original", CV_WINDOW_KEEPRATIO);
     
   Mat frame, origframe, combinedmask;
 
@@ -437,7 +449,8 @@ int process(VideoCapture& capture) {
 
       gotoframe = framenum + 1;
  
-      imshow("original", origframe/255.0);
+      if ( ! isWindowClosed("stickletrack_original") )
+       imshow("stickletrack_original", origframe/255.0);
     }
     
     drawTimes(tracking_getFrame());
@@ -446,7 +459,8 @@ int process(VideoCapture& capture) {
       circle( tracking_getFrame(), Point2f(tags[nearestTags[0]].x, tags[nearestTags[0]].y), Props.diagonal / 100.0, Scalar(0,0,255), -1, 8 );
     }
    
-    tracking_showFrame();
+    if ( tracking_showFrame() )
+      pleaseExit = true;
 
     char key;
 
@@ -503,8 +517,6 @@ int main(int ac, char** av) {
     cerr << "Failed to open a video device or video file!\n" << endl;
     return 1;
   }
-
-   cout << "Exit with q if you want to save your data!!!" << endl;
   
   return process(capture);
 }