]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - main_trax.cpp
Updating support for TraX protocol.
[hercules2020/kcf.git] / main_trax.cpp
1 #include <stdlib.h>
2
3 #include <trax/opencv.hpp>
4 #include "kcf.h"
5
6 int main()
7 {
8     trax::Image img;
9     trax::Region reg;
10
11     KCF_Tracker tracker;
12     cv::Mat image;
13         cv::Rect rectangle;
14
15     trax::Server handle(trax::Configuration(TRAX_IMAGE_PATH | TRAX_IMAGE_MEMORY | TRAX_IMAGE_BUFFER, TRAX_REGION_RECTANGLE), trax_no_log);
16
17         std::cout << handle.configuration().format_region << " " << TRAX_SUPPORTS(handle.configuration().format_region, TRAX_REGION_POLYGON) << std::endl;
18
19     while(true)
20     {
21
22         trax::Properties prop;
23
24         int tr = handle.wait(img, reg, prop);
25
26          if (tr == TRAX_INITIALIZE) {
27
28             rectangle = trax::region_to_rect(reg);
29             image = trax::image_to_mat(img);
30
31             // Dynamically configure tracker
32             tracker.m_use_scale = prop.get("use_scale", true);
33             tracker.m_use_color = prop.get("use_color", true);
34             tracker.m_use_subpixel_localization = prop.get("use_subpixel_localization", true);
35             tracker.m_use_subgrid_scale = prop.get("use_subgrid_scale", true);
36             tracker.m_use_multithreading = prop.get("use_multithreading", true);
37             tracker.m_use_cnfeat = prop.get("use_cnfeat", true);
38
39                         tracker.init(image, rectangle);
40
41         } else if (tr == TRAX_FRAME) {
42
43             image = trax::image_to_mat(img);
44                         tracker.track(image);
45                         BBox_c bb = tracker.getBBox();
46                         rectangle = bb.get_rect();
47
48         } else {
49             break;
50         }
51
52         trax::Region status = trax::rect_to_region(rectangle);
53         handle.reply(status, trax::Properties());
54
55     }
56
57     return EXIT_SUCCESS;
58 }