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. To
5 achieve the needed performance we try various ways of parallelization
6 of the algorithm including execution on the GPU. The aim is also to
7 modify the code according to the PRedictable Execution Model (PREM).
9 Stable version of the tracker is available from a [CTU server][2],
10 development happens at [GitHub][iig].
12 [1]: http://hercules2020.eu/
13 [2]: http://rtime.felk.cvut.cz/gitweb/hercules2020/kcf.git
14 [iig]: https://github.com/CTU-IIG/kcf
15 [3]: https://github.com/Shanigen/kcf
17 <!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
20 - [Prerequisites](#prerequisites)
21 - [Compilation](#compilation)
22 - [Compile all supported versions](#compile-all-supported-versions)
23 - [Using cmake gui](#using-cmake-gui)
24 - [Command line](#command-line)
27 - [Automated testing](#automated-testing)
29 - [References](#references)
32 <!-- markdown-toc end -->
37 The code depends on OpenCV (version 2.4 or 3.x) library. [CMake][13]
38 (optionally with [Ninja][8]) is used for building. Depending on the
39 version to be compiled you need to have development packages for
40 [FFTW][4], [CUDA][5] or [OpenMP][6] installed.
42 On TX2, the following command should install what's needed:
44 $ apt install cmake ninja-build libopencv-dev libfftw3-dev
47 [4]: http://www.fftw.org/
48 [5]: https://developer.nvidia.com/cuda-downloads
49 [6]: http://www.openmp.org/
50 [13]: https://cmake.org/
54 There are multiple ways how to compile the code.
56 ### Compile all supported versions
59 $ git submodule update --init
63 This will create several `build-*` directories and compile different
64 versions in them. If prerequisites of some builds are missing, the
65 `-k` option ensures that the errors are ignored. This uses [Ninja][8]
66 build system, which is useful when building naively on TX2, because
67 builds with `ninja` are faster (better parallelized) than with `make`.
69 To build only a specific version run `make <version>`. For example,
70 CUDA-based version can be compiled with:
76 [8]: https://ninja-build.org/
81 $ git submodule update --init
86 - Use the just created build directory as "Where to build the
89 - Choose desired build options. Each option has a comment briefly
90 explaining what it does.
91 - Press "Generate" and close the window.
99 $ git submodule update --init
102 $ cmake [options] .. # see the tables below
106 The `cmake` options below allow to select, which version to build.
108 The following table shows how to configure different FFT
111 |Option| Description |
113 | `-DFFT=OpenCV` | Use OpenCV to calculate FFT.|
114 | `-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.|
115 | `-DFFT=cuFFTW` | Use cuFFTW interface to cuFFT library.|
116 | `-DFFT=cuFFT` | Use cuFFT. This version also uses pure CUDA implementation of `ComplexMat` class and Gaussian correlation.|
118 With all of these FFT version additional options can be added:
120 |Option| Description |
122 | `-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. |
123 | `-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.|
124 | `-DCUDA_DEBUG=ON` | Adds calls cudaDeviceSynchronize after every CUDA function and kernel call.|
125 | `-DOpenCV_DIR=/opt/opencv-3.3/share/OpenCV` | Compile against a custom OpenCV version. |
126 | `-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.|
128 See also the top-level `Makefile` for other useful cmake parameters
129 such as extra compiler flags etc.
133 No matter which method is used to compile the code, the result will be
136 It operates on an image sequence created according to [VOT 2014
137 methodology][10]. You can find some image sequences in [vot2016
140 The binary can be run as follows:
142 1. `./kcf_vot [options]`
144 The program looks for `groundtruth.txt` or `region.txt` and
145 `images.txt` files in current directory.
147 - `images.txt` contains a list of images to process, each on a
149 - `groundtruth.txt` contains the correct location of the tracked
150 object in each image as four corner points listed clockwise
151 starting from bottom left corner. Only the first line from this
153 - `region.txt` is an alternative way of specifying the location of
154 the object to track via its bounding box (top_left_x, top_left_y,
155 width, height) in the first frame.
157 2. `./kcf_vot [options] <directory>`
159 Looks for `groundtruth.txt` or `region.txt` and `images.txt` files
160 in the given `directory`.
162 3. `./kcf_vot [options] <path/to/region.txt or groundtruth.txt> <path/to/images.txt> [path/to/output.txt]`
164 By default the program generates file `output.txt` containing the
165 bounding boxes of the tracked object in the format "top_left_x,
166 top_left_y, width, height".
168 [10]: http://www.votchallenge.net/
169 [11]: http://www.votchallenge.net/vot2016/dataset.html
173 | Options | Description |
174 | ------- | ----------- |
175 | --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. |
176 | --visualize, -v[delay_ms] | Visualize the output, optionally with specified delay. If the delay is 0 the program will wait for a key press. |
177 | --output, -o <output.txt> | Specify name of output file. |
178 | --debug, -d | Generate debug output. |
182 The tracker comes with a test suite based on [vot2016 datatset][11].
183 You can run the test suite as follows:
185 make vot2016 # This download the datased (about 1GB of data)
188 The above command run all tests in parallel and displays the results
189 in a table. If you want to measure performance, do not run multiple
190 tests together. This can be achieved by:
195 You can test only a subset of builds or image sequences by setting
196 BUILDS, TESTSEQ or TESTFLAGS make variables. For instance:
198 make build.ninja BUILDS="cufft cufft-big fftw" TESTSEQ="bmx ball1"
205 * Vít Karafiát, Michal Sojka
207 [Original C++ implementation of the KCF tracker][12] was written by
208 Tomas Vojir and is reimplementation of the algorithm presented in
209 "High-Speed Tracking with Kernelized Correlation Filters" paper \[1].
211 [12]: https://github.com/vojirt/kcf/blob/master/README.md
215 \[1] João F. Henriques, Rui Caseiro, Pedro Martins, Jorge Batista,
216 “High-Speed Tracking with Kernelized Correlation Filters“, IEEE
217 Transactions on Pattern Analysis and Machine Intelligence, 2015
221 Copyright (c) 2014, Tomáš Vojíř\
222 Copyright (c) 2018, Vít Karafiát\
223 Copyright (c) 2018, Michal Sojka
225 Permission to use, copy, modify, and distribute this software for research
226 purposes is hereby granted, provided that the above copyright notice and
227 this permission notice appear in all copies.
229 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
230 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
231 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
232 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
233 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
234 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
235 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
237 <!-- Local Variables: -->
238 <!-- markdown-toc-user-toc-structure-manipulation-fn: cdr -->