1 # KCF tracker – parallel and PREM implementations
3 The goal of this project is modify KCF tracker for use in the
4 [HERCULES][1] project, where it will run on NVIDIA TX2 board. The
5 differences from the [original version][orig] are:
6 * To achieve the needed performance on TX2, we try various ways of
7 parallelizing the algorithm, including execution on the GPU.
8 * The tracker is extended to track rotating objects.
9 * The aim is also to modify the code to comply with the PRedictable
10 Execution Model (PREM).
12 Stable version of the tracker is available from a [CTU server][2],
13 development happens at [GitHub][iig].
15 [1]: http://hercules2020.eu/
16 [2]: http://rtime.felk.cvut.cz/gitweb/hercules2020/kcf.git
17 [iig]: https://github.com/CTU-IIG/kcf
18 [3]: https://github.com/Shanigen/kcf
19 [orig]: https://github.com/vojirt/kcf
21 <!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
24 - [Prerequisites](#prerequisites)
25 - [Compilation](#compilation)
26 - [Compile all supported versions](#compile-all-supported-versions)
27 - [Using cmake gui](#using-cmake-gui)
28 - [Command line](#command-line)
31 - [Automated testing](#automated-testing)
33 - [References](#references)
36 <!-- markdown-toc end -->
41 The code depends on OpenCV (version 2.4 or 3.x) library. [CMake][13]
42 (optionally with [Ninja][8]) is used for building. Depending on the
43 version to be compiled you need to have development packages for
44 [FFTW][4], [CUDA][5] or [OpenMP][6] installed.
46 On TX2, the following command should install what's needed:
48 $ apt install cmake ninja-build libopencv-dev libfftw3-dev
51 [4]: http://www.fftw.org/
52 [5]: https://developer.nvidia.com/cuda-downloads
53 [6]: http://www.openmp.org/
54 [13]: https://cmake.org/
58 There are multiple ways how to compile the code.
60 ### Compile all supported versions
63 $ git submodule update --init
67 This will create several `build-*` directories and compile different
68 versions in them. If prerequisites of some builds are missing, the
69 `-k` option ensures that the errors are ignored. This uses [Ninja][8]
70 build system, which is useful when building naively on TX2, because
71 builds with `ninja` are faster (better parallelized) than with `make`.
73 To build only a specific version run `make <version>`. For example,
74 CUDA-based version can be compiled with:
80 [8]: https://ninja-build.org/
85 $ git submodule update --init
90 - Use the just created build directory as "Where to build the
93 - Choose desired build options. Each option has a comment briefly
94 explaining what it does.
95 - Press "Generate" and close the window.
103 $ git submodule update --init
106 $ cmake [options] .. # see the tables below
110 The `cmake` options below allow to select, which version to build.
112 The following table shows how to configure different FFT
115 |Option| Description |
117 | `-DFFT=OpenCV` | Use OpenCV to calculate FFT.|
118 | `-DFFT=fftw` | Use fftw and its `plan_many` and "New-array execute" functions. If `std::async`, OpenMP or cuFFTW is not used the plans will use 2 threads by default.|
119 | `-DFFT=cuFFTW` | Use cuFFTW interface to cuFFT library.|
120 | `-DFFT=cuFFT` | Use cuFFT. This version also uses pure CUDA implementation of `ComplexMat` class and Gaussian correlation.|
122 With all of these FFT version additional options can be added:
124 |Option| Description |
126 | `-DBIG_BATCH=ON` | Concatenate matrices of different scales to one big matrix and perform all computations on this matrix. This improves performance of GPU FFT offloading. |
127 | `-DOPENMP=ON` | Parallelize certain operation with OpenMP. With `-DBIG_BATCH=OFF` it runs computations for differenct scales in parallel, with `-DBIG_BATCH=ON` it parallelizes the feature extraction, which runs on the CPU. With `fftw`, Ffftw's plans will execute in parallel.|
128 | `-DCUDA_DEBUG=ON` | Adds calls cudaDeviceSynchronize after every CUDA function and kernel call.|
129 | `-DOpenCV_DIR=/opt/opencv-3.3/share/OpenCV` | Compile against a custom OpenCV version. |
130 | `-DASYNC=ON` | Use C++ `std::async` to run computations for different scales in parallel. This mode of parallelization was present in the original implementation. Here, it is superseeded with -DOPENMP. This doesn't work with `BIG_BATCH` mode.|
132 See also the top-level `Makefile` for other useful cmake parameters
133 such as extra compiler flags etc.
137 No matter which method is used to compile the code, the result will be
140 It operates on an image sequence created according to [VOT 2014
141 methodology][10]. You can find some image sequences in [vot2016
144 The binary can be run as follows:
146 1. `./kcf_vot [options]`
148 The program looks for `groundtruth.txt` or `region.txt` and
149 `images.txt` files in current directory.
151 - `images.txt` contains a list of images to process, each on a
153 - `groundtruth.txt` contains the correct location of the tracked
154 object in each image as four corner points listed clockwise
155 starting from bottom left corner. Only the first line from this
157 - `region.txt` is an alternative way of specifying the location of
158 the object to track via its bounding box (top_left_x, top_left_y,
159 width, height) in the first frame.
161 2. `./kcf_vot [options] <directory>`
163 Looks for `groundtruth.txt` or `region.txt` and `images.txt` files
164 in the given `directory`.
166 3. `./kcf_vot [options] <path/to/region.txt or groundtruth.txt> <path/to/images.txt> [path/to/output.txt]`
168 By default the program generates file `output.txt` containing the
169 bounding boxes of the tracked object in the format "top_left_x,
170 top_left_y, width, height".
172 [10]: http://www.votchallenge.net/
173 [11]: http://www.votchallenge.net/vot2016/dataset.html
177 | Options | Description |
178 | ------- | ----------- |
179 | --fit, -f[W[xH]] | Specifies the dimension to which the extracted patches should be scaled. Best performance is achieved for powers of two; the smaller number the higher performance but worse accuracy. No dimension or zero rounds the dimensions to the nearest smaller power of 2, a single dimension `W` will result in patch size of `W`×`W`. The numbers should be divisible by 4. |
180 | --visualize, -v[delay_ms] | Visualize the output, optionally with specified delay. If the delay is 0 the program will wait for a key press. |
181 | --output, -o <output.txt> | Specify name of output file. |
182 | --debug, -d | Generate debug output. |
183 | --visual_debug, -p[p\|r] | Show graphical window with debugging information (either **p**atch or filter **r**esponse). |
187 The tracker comes with a test suite based on [vot2016 datatset][11].
188 You can run the test suite as follows:
190 make vot2016 # This downloads the dataset (about 1GB of data)
193 The above command run all tests in parallel and displays the results
194 in a table. If you want to measure performance, do not run multiple
195 tests together. This can be achieved by:
200 You can test only a subset of builds or image sequences by setting
201 BUILDS, TESTSEQ or TESTFLAGS make variables. For instance:
203 make build.ninja BUILDS="cufft cufft-big fftw" TESTSEQ="bmx ball1"
210 * Vít Karafiát, Michal Sojka
212 [Original C++ implementation of the KCF tracker][12] was written by
213 Tomas Vojir and is reimplementation of the algorithm presented in
214 "High-Speed Tracking with Kernelized Correlation Filters" paper \[1].
216 [12]: https://github.com/vojirt/kcf/blob/master/README.md
220 \[1] João F. Henriques, Rui Caseiro, Pedro Martins, Jorge Batista,
221 “High-Speed Tracking with Kernelized Correlation Filters“, IEEE
222 Transactions on Pattern Analysis and Machine Intelligence, 2015
226 Copyright (c) 2014, Tomáš Vojíř\
227 Copyright (c) 2018, Vít Karafiát\
228 Copyright (c) 2018, Michal Sojka
230 Permission to use, copy, modify, and distribute this software for research
231 purposes is hereby granted, provided that the above copyright notice and
232 this permission notice appear in all copies.
234 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
235 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
236 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
237 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
238 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
239 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
240 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
242 <!-- Local Variables: -->
243 <!-- markdown-toc-user-toc-structure-manipulation-fn: cdr -->