9 int main(int argc, char *argv[])
11 //load region, images and prepare for output
12 std::string region, images, output;
13 int visualize_delay = -1;
18 static struct option long_options[] = {
19 {"debug", no_argument, 0, 'd' },
20 {"help", no_argument, 0, 'h' },
21 {"output", required_argument, 0, 'o' },
22 {"visualize", optional_argument, 0, 'v' },
26 int c = getopt_long(argc, argv, "dhv::o:",
27 long_options, &option_index);
33 tracker.m_debug = true;
36 std::cerr << "Usage: \n"
37 << argv[0] << " [options]\n"
38 << argv[0] << " [options] <directory>\n"
39 << argv[0] << " [options] <path/to/region.txt or groundtruth.txt> <path/to/images.txt> [path/to/output.txt]\n"
41 << " --visualize | -v [delay_ms]\n"
42 << " --output | -o <outout.txt>\n"
50 visualize_delay = optarg ? atol(optarg) : 1;
55 switch (argc - optind) {
57 if (chdir(argv[optind]) == -1) {
63 region = access("groundtruth.txt", F_OK) == 0 ? "groundtruth.txt" : "region.txt";
64 images = "images.txt";
66 output = "output.txt";
71 region = std::string(argv[optind + 0]);
72 images = std::string(argv[optind + 1]);
74 if ((argc - optind) == 3)
75 output = std::string(argv[optind + 2]);
77 output = std::string(dirname(argv[optind + 0])) + "/output.txt";
81 std::cerr << "Too many arguments\n";
84 VOT vot_io(region, images, output);
88 //img = firts frame, initPos = initial position in the first frame
89 cv::Rect init_rect = vot_io.getInitRectangle();
90 vot_io.outputBoundingBox(init_rect);
91 vot_io.getNextImage(image);
93 tracker.init(image, init_rect);
98 while (vot_io.getNextImage(image) == 1){
99 double time_profile_counter = cv::getCPUTickCount();
100 tracker.track(image);
101 time_profile_counter = cv::getCPUTickCount() - time_profile_counter;
102 std::cout << " -> speed : " << time_profile_counter/((double)cvGetTickFrequency()*1000) << "ms. per frame" << std::endl;
103 avg_time += time_profile_counter/((double)cvGetTickFrequency()*1000);
106 bb = tracker.getBBox();
107 vot_io.outputBoundingBox(cv::Rect(bb.cx - bb.w/2., bb.cy - bb.h/2., bb.w, bb.h));
109 if (visualize_delay >= 0) {
110 cv::rectangle(image, cv::Rect(bb.cx - bb.w/2., bb.cy - bb.h/2., bb.w, bb.h), CV_RGB(0,255,0), 2);
111 cv::imshow("output", image);
112 int ret = cv::waitKey(visualize_delay);
113 if (visualize_delay > 0 && ret != -1 && ret != 255)
117 // std::stringstream s;
119 // int countTmp = frames;
120 // s << "imgs" << "/img" << (countTmp/10000);
121 // countTmp = countTmp%10000;
122 // s << (countTmp/1000);
123 // countTmp = countTmp%1000;
124 // s << (countTmp/100);
125 // countTmp = countTmp%100;
126 // s << (countTmp/10);
127 // countTmp = countTmp%10;
131 // //set image output parameters
132 // std::vector<int> compression_params;
133 // compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
134 // compression_params.push_back(90);
135 // cv::imwrite(ss.c_str(), image, compression_params);
138 std::cout << "Average processing speed " << avg_time/frames << "ms. (" << 1./(avg_time/frames)*1000 << " fps)" << std::endl;