]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blobdiff - main_vot.cpp
Call cudaStreamSynchronize before debug prints
[hercules2020/kcf.git] / main_vot.cpp
index d3f5a83259f80614b04abdaab802dda0e26bfdec..27c776fd8644646c6c01bfdeb15fc7510159f61e 100644 (file)
@@ -2,6 +2,7 @@
 #include <getopt.h>
 #include <libgen.h>
 #include <unistd.h>
+#include <iomanip>
 
 #include "kcf.h"
 #include "vot.hpp"
 double calcAccuracy(std::string line, cv::Rect bb_rect, cv::Rect &groundtruth_rect)
 {
     std::vector<float> numbers;
-    std::istringstream s( line );
+    std::istringstream s(line);
     float x;
     char ch;
 
-    while (s >> x){
+    while (s >> x) {
         numbers.push_back(x);
         s >> ch;
     }
@@ -22,11 +23,11 @@ double calcAccuracy(std::string line, cv::Rect bb_rect, cv::Rect &groundtruth_re
     double y1 = std::min(numbers[1], std::min(numbers[3], std::min(numbers[5], numbers[7])));
     double y2 = std::max(numbers[1], std::max(numbers[3], std::max(numbers[5], numbers[7])));
 
-    groundtruth_rect = cv::Rect(x1, y1, x2-x1, y2-y1);
+    groundtruth_rect = cv::Rect(x1, y1, x2 - x1, y2 - y1);
 
     double rects_intersection = (groundtruth_rect & bb_rect).area();
     double rects_union = (groundtruth_rect | bb_rect).area();
-    double accuracy = rects_intersection/rects_union;
+    double accuracy = rects_intersection / rects_union;
 
     return accuracy;
 }
@@ -42,6 +43,7 @@ int main(int argc, char *argv[])
         int option_index = 0;
         static struct option long_options[] = {
             {"debug",     no_argument,       0,  'd' },
+            {"visualDebug", no_argument, 0, 'p'},
             {"help",      no_argument,       0,  'h' },
             {"output",    required_argument, 0,  'o' },
             {"visualize", optional_argument, 0,  'v' },
@@ -49,8 +51,7 @@ int main(int argc, char *argv[])
             {0,           0,                 0,  0 }
         };
 
-        int c = getopt_long(argc, argv, "dhv::f::o:",
-                        long_options, &option_index);
+        int c = getopt_long(argc, argv, "dphv::f::o:", long_options, &option_index);
         if (c == -1)
             break;
 
@@ -58,6 +59,10 @@ int main(int argc, char *argv[])
         case 'd':
             tracker.m_debug = true;
             break;
+        case 'p':
+            tracker.m_visual_debug = true;
+            visualize_delay = 500;
+            break;
         case 'h':
             std::cerr << "Usage: \n"
                       << argv[0] << " [options]\n"
@@ -67,7 +72,7 @@ int main(int argc, char *argv[])
                       << " --visualize | -v[delay_ms]\n"
                       << " --output    | -o <output.txt>\n"
                       << " --debug     | -d\n"
-                      << " --fit       | -f[WxH]\n";
+                      << " --fit       | -f[W[xH]]\n";
             exit(0);
             break;
         case 'o':
@@ -77,14 +82,17 @@ int main(int argc, char *argv[])
             visualize_delay = optarg ? atol(optarg) : 1;
             break;
         case 'f':
-            std::string sizes = optarg ? optarg : "128x128";
-            std::string delimiter = "x";
-            size_t pos = sizes.find(delimiter);
-            std::string first_argument = sizes.substr(0, pos);
-            sizes.erase(0, pos + delimiter.length());
-
-            fit_size_x = stol(first_argument);
-           fit_size_y = stol(sizes);
+            if (!optarg) {
+                fit_size_x = fit_size_y = 0;
+            } else {
+                char tail;
+                if (sscanf(optarg, "%d%c", &fit_size_x, &tail) == 1) {
+                    fit_size_y = fit_size_x;
+                } else if (sscanf(optarg, "%dx%d%c", &fit_size_x, &fit_size_y, &tail) != 2) {
+                    fprintf(stderr, "Cannot parse -f argument: %s\n", optarg);
+                    return 1;
+                }
+            }
             break;
         }
     }
@@ -123,7 +131,6 @@ int main(int argc, char *argv[])
     // if groundtruth.txt is used use intersection over union (IOU) to calculate tracker accuracy
     std::ifstream groundtruth_stream;
     if (region.compare("groundtruth.txt") == 0) {
-        std::cout << region << std::endl;
         groundtruth_stream.open(region.c_str());
         std::string line;
         std::getline(groundtruth_stream, line);
@@ -142,11 +149,15 @@ int main(int argc, char *argv[])
     cv::Rect bb_rect;
     double avg_time = 0., sum_accuracy = 0.;
     int frames = 0;
+
+    std::cout << std::fixed << std::setprecision(2);
+
     while (vot_io.getNextImage(image) == 1){
         double time_profile_counter = cv::getCPUTickCount();
         tracker.track(image);
         time_profile_counter = cv::getCPUTickCount() - time_profile_counter;
-         std::cout << "  -> speed : " <<  time_profile_counter/((double)cvGetTickFrequency()*1000) << "ms. per frame";
+         std::cout << "  -> speed : " <<  time_profile_counter/((double)cvGetTickFrequency()*1000) << "ms per frame, "
+                      "response : " << tracker.getFilterResponse();
         avg_time += time_profile_counter/((double)cvGetTickFrequency()*1000);
         frames++;
 
@@ -172,7 +183,7 @@ int main(int argc, char *argv[])
             cv::rectangle(image, bb_rect, CV_RGB(0,255,0), 2);
             cv::imshow("output", image);
             int ret = cv::waitKey(visualize_delay);
-            if (visualize_delay > 0 && ret != -1 && ret != 255)
+            if (visualize_delay > 0 && ret != -1 && ret < 128)
                 break;
         }
 
@@ -197,11 +208,12 @@ int main(int argc, char *argv[])
 //        cv::imwrite(ss.c_str(), image, compression_params);
     }
 
-    std::cout << "Average processing speed " << avg_time/frames <<  "ms. (" << 1./(avg_time/frames)*1000 << " fps)" << std::endl;
+    std::cout << "Average processing speed: " << avg_time / frames << "ms (" << 1. / (avg_time / frames) * 1000 << " fps)";
     if (groundtruth_stream.is_open()) {
-        std::cout << "Average accuracy: " << sum_accuracy/frames << std::endl;
+        std::cout << "Average accuracy: " << sum_accuracy/frames << std::endl;
         groundtruth_stream.close();
     }
+    std::cout << std::endl;
 
     return EXIT_SUCCESS;
 }