├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── TEST_ON_UBUNTU1604.png ├── dat.png ├── readme.md ├── result.gif ├── sequence ├── 00000001.jpg ├── 00000002.jpg ├── 00000003.jpg ├── 00000004.jpg ├── 00000005.jpg ├── 00000006.jpg ├── 00000007.jpg ├── 00000008.jpg ├── 00000009.jpg ├── 00000010.jpg ├── 00000011.jpg ├── 00000012.jpg ├── 00000013.jpg ├── 00000014.jpg ├── 00000015.jpg ├── 00000016.jpg ├── 00000017.jpg ├── 00000018.jpg ├── 00000019.jpg ├── 00000020.jpg ├── 00000021.jpg ├── 00000022.jpg ├── 00000023.jpg ├── 00000024.jpg ├── 00000025.jpg ├── 00000026.jpg ├── 00000027.jpg ├── 00000028.jpg ├── 00000029.jpg ├── 00000030.jpg ├── 00000031.jpg ├── 00000032.jpg ├── 00000033.jpg ├── 00000034.jpg ├── 00000035.jpg ├── 00000036.jpg ├── 00000037.jpg ├── 00000038.jpg ├── 00000039.jpg ├── 00000040.jpg ├── 00000041.jpg ├── 00000042.jpg ├── 00000043.jpg ├── 00000044.jpg ├── 00000045.jpg ├── 00000046.jpg ├── 00000047.jpg ├── 00000048.jpg ├── 00000049.jpg ├── 00000050.jpg ├── 00000051.jpg ├── 00000052.jpg ├── 00000053.jpg ├── 00000054.jpg ├── 00000055.jpg ├── 00000056.jpg ├── 00000057.jpg ├── 00000058.jpg ├── 00000059.jpg ├── 00000060.jpg ├── 00000061.jpg ├── 00000062.jpg ├── 00000063.jpg ├── 00000064.jpg ├── 00000065.jpg ├── 00000066.jpg ├── 00000067.jpg ├── 00000068.jpg ├── 00000069.jpg ├── 00000070.jpg ├── 00000071.jpg ├── 00000072.jpg ├── 00000073.jpg ├── 00000074.jpg ├── 00000075.jpg ├── 00000076.jpg ├── 00000077.jpg ├── 00000078.jpg ├── 00000079.jpg ├── 00000080.jpg ├── 00000081.jpg ├── 00000082.jpg ├── 00000083.jpg ├── 00000084.jpg ├── 00000085.jpg ├── 00000086.jpg ├── 00000087.jpg ├── 00000088.jpg ├── 00000089.jpg ├── 00000090.jpg ├── 00000091.jpg ├── 00000092.jpg ├── 00000093.jpg ├── 00000094.jpg ├── 00000095.jpg ├── 00000096.jpg ├── 00000097.jpg ├── 00000098.jpg ├── 00000099.jpg ├── 00000100.jpg ├── 00000101.jpg ├── 00000102.jpg ├── 00000103.jpg ├── 00000104.jpg ├── 00000105.jpg └── groundtruth.txt ├── speed.png └── src ├── dat_tracker.cpp ├── dat_tracker.hpp └── demo.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(DAT) 3 | aux_source_directory(./src/ SRC_LIST) 4 | add_executable(${PROJECT_NAME} ${SRC_LIST}) 5 | 6 | IF (WIN32) 7 | set(OpenCV_DIR D:/opencv310/build) 8 | ENDIF(WIN32) 9 | IF (UNIX) 10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") #c++11 11 | ENDIF (UNIX) 12 | find_package(OpenCV REQUIRED) 13 | target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) 14 | -------------------------------------------------------------------------------- /TEST_ON_UBUNTU1604.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/TEST_ON_UBUNTU1604.png -------------------------------------------------------------------------------- /dat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/dat.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # DAT 2 | This is a C++ reimplementation of algorithm presented in "In Defense of Color-based Model-free Tracking." . 3 | Since the source code contains no multiscale module, we just retain distractor-aware object module which is rather fast. 4 | For more info, visit the autor's [webpage](https://lrs.icg.tugraz.at/members/possegger)!. 5 | 6 | ![dat](dat.png) 7 | 8 | ## Usage 9 | 10 | Simple test can be compiled like: 11 | ``` 12 | cmake 13 | make 14 | .\DAT 15 | ``` 16 | ![result](result.gif) 17 | 18 | For test the **[vot2015](http://votchallenge.net/vot2015/dataset.html)** challenge, please download the [dataset](http://box.vicos.si/vot/vot2015.zip) at first and then unzip to ${DAT}. 19 | ``` 20 | cmake 21 | make 22 | .\DAT vot2015 23 | ``` 24 | 25 | ## Speed 26 | 27 | Test in Windows with Intel i7-4790 28 | 29 | ![speed](speed.png) 30 | 31 | Test in ubuntu 16.04 with Intel i7-6700 32 | 33 | ![speed](TEST_ON_UBUNTU1604.png) 34 | 35 | ## Reference 36 | 37 | ``` 38 | @INPROCEEDINGS{possegger15a, 39 | author = {Horst Possegger and Thomas Mauthner and Horst Bischof}, 40 | title = {In Defense of Color-based Model-free Tracking}, 41 | booktitle = {Proc. IEEE Conference on Computer Vision and Pattern Recognition (CVPR)}, 42 | year = {2015} 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /result.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/result.gif -------------------------------------------------------------------------------- /sequence/00000001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000001.jpg -------------------------------------------------------------------------------- /sequence/00000002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000002.jpg -------------------------------------------------------------------------------- /sequence/00000003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000003.jpg -------------------------------------------------------------------------------- /sequence/00000004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000004.jpg -------------------------------------------------------------------------------- /sequence/00000005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000005.jpg -------------------------------------------------------------------------------- /sequence/00000006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000006.jpg -------------------------------------------------------------------------------- /sequence/00000007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000007.jpg -------------------------------------------------------------------------------- /sequence/00000008.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000008.jpg -------------------------------------------------------------------------------- /sequence/00000009.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000009.jpg -------------------------------------------------------------------------------- /sequence/00000010.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000010.jpg -------------------------------------------------------------------------------- /sequence/00000011.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000011.jpg -------------------------------------------------------------------------------- /sequence/00000012.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000012.jpg -------------------------------------------------------------------------------- /sequence/00000013.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000013.jpg -------------------------------------------------------------------------------- /sequence/00000014.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000014.jpg -------------------------------------------------------------------------------- /sequence/00000015.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000015.jpg -------------------------------------------------------------------------------- /sequence/00000016.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000016.jpg -------------------------------------------------------------------------------- /sequence/00000017.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000017.jpg -------------------------------------------------------------------------------- /sequence/00000018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000018.jpg -------------------------------------------------------------------------------- /sequence/00000019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000019.jpg -------------------------------------------------------------------------------- /sequence/00000020.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000020.jpg -------------------------------------------------------------------------------- /sequence/00000021.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000021.jpg -------------------------------------------------------------------------------- /sequence/00000022.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000022.jpg -------------------------------------------------------------------------------- /sequence/00000023.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000023.jpg -------------------------------------------------------------------------------- /sequence/00000024.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000024.jpg -------------------------------------------------------------------------------- /sequence/00000025.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000025.jpg -------------------------------------------------------------------------------- /sequence/00000026.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000026.jpg -------------------------------------------------------------------------------- /sequence/00000027.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000027.jpg -------------------------------------------------------------------------------- /sequence/00000028.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000028.jpg -------------------------------------------------------------------------------- /sequence/00000029.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000029.jpg -------------------------------------------------------------------------------- /sequence/00000030.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000030.jpg -------------------------------------------------------------------------------- /sequence/00000031.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000031.jpg -------------------------------------------------------------------------------- /sequence/00000032.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000032.jpg -------------------------------------------------------------------------------- /sequence/00000033.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000033.jpg -------------------------------------------------------------------------------- /sequence/00000034.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000034.jpg -------------------------------------------------------------------------------- /sequence/00000035.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000035.jpg -------------------------------------------------------------------------------- /sequence/00000036.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000036.jpg -------------------------------------------------------------------------------- /sequence/00000037.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000037.jpg -------------------------------------------------------------------------------- /sequence/00000038.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000038.jpg -------------------------------------------------------------------------------- /sequence/00000039.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000039.jpg -------------------------------------------------------------------------------- /sequence/00000040.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000040.jpg -------------------------------------------------------------------------------- /sequence/00000041.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000041.jpg -------------------------------------------------------------------------------- /sequence/00000042.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000042.jpg -------------------------------------------------------------------------------- /sequence/00000043.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000043.jpg -------------------------------------------------------------------------------- /sequence/00000044.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000044.jpg -------------------------------------------------------------------------------- /sequence/00000045.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000045.jpg -------------------------------------------------------------------------------- /sequence/00000046.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000046.jpg -------------------------------------------------------------------------------- /sequence/00000047.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000047.jpg -------------------------------------------------------------------------------- /sequence/00000048.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000048.jpg -------------------------------------------------------------------------------- /sequence/00000049.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000049.jpg -------------------------------------------------------------------------------- /sequence/00000050.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000050.jpg -------------------------------------------------------------------------------- /sequence/00000051.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000051.jpg -------------------------------------------------------------------------------- /sequence/00000052.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000052.jpg -------------------------------------------------------------------------------- /sequence/00000053.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000053.jpg -------------------------------------------------------------------------------- /sequence/00000054.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000054.jpg -------------------------------------------------------------------------------- /sequence/00000055.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000055.jpg -------------------------------------------------------------------------------- /sequence/00000056.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000056.jpg -------------------------------------------------------------------------------- /sequence/00000057.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000057.jpg -------------------------------------------------------------------------------- /sequence/00000058.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000058.jpg -------------------------------------------------------------------------------- /sequence/00000059.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000059.jpg -------------------------------------------------------------------------------- /sequence/00000060.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000060.jpg -------------------------------------------------------------------------------- /sequence/00000061.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000061.jpg -------------------------------------------------------------------------------- /sequence/00000062.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000062.jpg -------------------------------------------------------------------------------- /sequence/00000063.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000063.jpg -------------------------------------------------------------------------------- /sequence/00000064.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000064.jpg -------------------------------------------------------------------------------- /sequence/00000065.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000065.jpg -------------------------------------------------------------------------------- /sequence/00000066.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000066.jpg -------------------------------------------------------------------------------- /sequence/00000067.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000067.jpg -------------------------------------------------------------------------------- /sequence/00000068.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000068.jpg -------------------------------------------------------------------------------- /sequence/00000069.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000069.jpg -------------------------------------------------------------------------------- /sequence/00000070.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000070.jpg -------------------------------------------------------------------------------- /sequence/00000071.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000071.jpg -------------------------------------------------------------------------------- /sequence/00000072.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000072.jpg -------------------------------------------------------------------------------- /sequence/00000073.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000073.jpg -------------------------------------------------------------------------------- /sequence/00000074.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000074.jpg -------------------------------------------------------------------------------- /sequence/00000075.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000075.jpg -------------------------------------------------------------------------------- /sequence/00000076.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000076.jpg -------------------------------------------------------------------------------- /sequence/00000077.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000077.jpg -------------------------------------------------------------------------------- /sequence/00000078.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000078.jpg -------------------------------------------------------------------------------- /sequence/00000079.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000079.jpg -------------------------------------------------------------------------------- /sequence/00000080.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000080.jpg -------------------------------------------------------------------------------- /sequence/00000081.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000081.jpg -------------------------------------------------------------------------------- /sequence/00000082.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000082.jpg -------------------------------------------------------------------------------- /sequence/00000083.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000083.jpg -------------------------------------------------------------------------------- /sequence/00000084.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000084.jpg -------------------------------------------------------------------------------- /sequence/00000085.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000085.jpg -------------------------------------------------------------------------------- /sequence/00000086.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000086.jpg -------------------------------------------------------------------------------- /sequence/00000087.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000087.jpg -------------------------------------------------------------------------------- /sequence/00000088.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000088.jpg -------------------------------------------------------------------------------- /sequence/00000089.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000089.jpg -------------------------------------------------------------------------------- /sequence/00000090.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000090.jpg -------------------------------------------------------------------------------- /sequence/00000091.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000091.jpg -------------------------------------------------------------------------------- /sequence/00000092.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000092.jpg -------------------------------------------------------------------------------- /sequence/00000093.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000093.jpg -------------------------------------------------------------------------------- /sequence/00000094.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000094.jpg -------------------------------------------------------------------------------- /sequence/00000095.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000095.jpg -------------------------------------------------------------------------------- /sequence/00000096.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000096.jpg -------------------------------------------------------------------------------- /sequence/00000097.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000097.jpg -------------------------------------------------------------------------------- /sequence/00000098.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000098.jpg -------------------------------------------------------------------------------- /sequence/00000099.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000099.jpg -------------------------------------------------------------------------------- /sequence/00000100.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000100.jpg -------------------------------------------------------------------------------- /sequence/00000101.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000101.jpg -------------------------------------------------------------------------------- /sequence/00000102.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000102.jpg -------------------------------------------------------------------------------- /sequence/00000103.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000103.jpg -------------------------------------------------------------------------------- /sequence/00000104.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000104.jpg -------------------------------------------------------------------------------- /sequence/00000105.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/sequence/00000105.jpg -------------------------------------------------------------------------------- /sequence/groundtruth.txt: -------------------------------------------------------------------------------- 1 | 246,231.5,269.5,231.5,269.5,208.5,246,208.5 2 | 246.38,200.77,246.38,223.76,269.9,223.75,269.89,200.76 3 | 246.26,193.73,246.27,216.71,269.79,216.7,269.78,193.72 4 | 246.76,189.07,246.78,212.04,270.31,212.03,270.3,189.06 5 | 247.77,185.58,247.79,208.54,271.33,208.52,271.32,185.56 6 | 247.52,182.84,247.54,205.79,271.1,205.77,271.08,182.82 7 | 248.28,183.1,248.3,206.04,271.87,206.01,271.85,183.07 8 | 248.95,183.52,248.98,206.45,272.56,206.42,272.54,183.49 9 | 250.12,186.34,250.16,209.26,273.75,209.22,273.72,186.31 10 | 249.67,191.41,249.71,214.32,273.31,214.28,273.28,191.37 11 | 250.55,197.49,250.59,220.38,274.21,220.34,274.17,197.44 12 | 251.93,203.06,251.98,225.95,275.61,225.9,275.56,203.01 13 | 252.31,214.13,252.36,237.01,276,236.96,275.96,214.08 14 | 252.5,211.06,252.56,233.93,276.21,233.87,276.16,211 15 | 253.19,196.39,253.25,219.25,276.92,219.19,276.86,196.33 16 | 253.26,184.97,253.32,207.82,277,207.75,276.94,184.91 17 | 253.33,175.05,253.39,197.89,277.08,197.82,277.02,174.98 18 | 254.89,166.38,254.96,189.21,278.66,189.13,278.59,166.31 19 | 253.46,161.71,253.53,184.53,277.24,184.45,277.17,161.63 20 | 253.11,155.69,253.18,178.5,276.91,178.42,276.83,155.61 21 | 252.86,153.08,252.94,175.87,276.67,175.78,276.6,152.99 22 | 253.23,149.96,253.31,172.74,277.06,172.65,276.98,149.86 23 | 253.61,148.84,253.69,171.62,277.46,171.52,277.37,148.74 24 | 253.98,151.22,254.07,173.99,277.85,173.89,277.76,151.12 25 | 254.36,153.6,254.45,176.36,278.24,176.25,278.14,153.5 26 | 253.88,157.89,253.98,180.64,277.78,180.53,277.68,157.78 27 | 254,162.38,254.1,185.11,277.91,185,277.81,162.26 28 | 254.62,168.86,254.73,191.59,278.55,191.47,278.45,168.74 29 | 255.08,177.35,255.19,200.06,279.02,199.94,278.91,177.23 30 | 254.79,188.84,254.9,211.54,278.75,211.41,278.63,188.71 31 | 254.49,200.32,254.61,223.02,278.47,222.88,278.35,200.19 32 | 256.22,213.49,256.35,236.17,280.22,236.03,280.09,213.35 33 | 256.86,216.75,256.98,239.43,280.86,239.28,280.74,216.61 34 | 258.11,204.89,258.24,227.56,282.14,227.41,282.01,204.75 35 | 259.37,191.7,259.5,214.35,283.41,214.2,283.28,191.55 36 | 260.63,184.5,260.77,207.15,284.68,206.99,284.55,184.35 37 | 261.89,177.31,262.03,199.94,285.96,199.78,285.81,177.15 38 | 263.46,172.2,263.61,194.82,287.55,194.66,287.4,172.04 39 | 265.04,167.09,265.19,189.7,289.14,189.53,288.99,166.92 40 | 264.74,164.86,264.9,187.46,288.86,187.29,288.71,164.68 41 | 266.45,162.79,266.6,185.38,290.58,185.2,290.42,162.61 42 | 268.15,164.47,268.31,187.05,292.3,186.87,292.14,164.29 43 | 269.85,166.15,270.02,188.72,294.02,188.54,293.85,165.97 44 | 270.99,170.47,271.16,193.03,295.17,192.84,295,170.28 45 | 272.12,174.79,272.29,197.34,296.32,197.14,296.15,174.59 46 | 273.25,179.1,273.43,201.65,297.47,201.45,297.29,178.91 47 | 275.56,189.09,275.74,211.62,299.79,211.42,299.61,188.88 48 | 277.61,198.57,277.79,221.09,301.85,220.89,301.67,198.36 49 | 275.66,188.06,275.85,210.57,299.92,210.36,299.73,187.84 50 | 272.1,174.67,272.29,197.17,296.37,196.95,296.18,174.45 51 | 266.53,160.98,266.73,183.47,290.83,183.24,290.63,160.75 52 | 263.47,151.91,263.67,174.39,287.78,174.16,287.58,151.68 53 | 260.41,142.84,260.61,165.31,284.73,165.08,284.53,142.61 54 | 257.35,135.78,257.56,158.24,281.69,158,281.48,135.54 55 | 254.28,128.71,254.5,151.16,278.64,150.92,278.43,128.47 56 | 250.69,124.48,250.91,146.92,275.06,146.68,274.85,124.24 57 | 247.09,121.45,247.31,143.88,271.48,143.63,271.26,121.2 58 | 242.5,119.17,242.72,141.59,266.9,141.34,266.68,118.92 59 | 240.24,120.39,240.46,142.8,264.66,142.54,264.43,120.13 60 | 236.47,122.36,236.71,144.76,260.91,144.5,260.68,122.1 61 | 232.71,124.33,232.95,146.72,257.16,146.45,256.93,124.06 62 | 228.67,130.57,228.91,152.95,253.14,152.68,252.9,130.3 63 | 224.73,136.92,224.97,159.29,249.21,159.01,248.97,136.65 64 | 222.41,145.64,222.66,168,246.91,167.72,246.66,145.36 65 | 218.76,157.03,219.01,179.38,243.27,179.1,243.02,156.75 66 | 215.11,168.42,215.36,190.76,239.64,190.47,239.38,168.13 67 | 211.46,179.81,211.72,202.14,236,201.84,235.74,179.51 68 | 206.41,198.03,206.68,220.35,230.98,220.05,230.71,197.73 69 | 203.47,190.35,203.74,212.66,228.05,212.35,227.78,190.05 70 | 203.9,181.79,204.18,204.09,228.5,203.78,228.23,181.49 71 | 202.34,178.57,202.61,200.86,226.95,200.55,226.67,178.26 72 | 200.77,175.35,201.05,197.63,225.4,197.31,225.12,175.04 73 | 199.2,172.13,199.48,194.4,223.84,194.08,223.56,171.81 74 | 199.15,170.9,199.44,193.16,223.81,192.83,223.52,170.58 75 | 196.9,170.47,197.19,192.72,221.57,192.39,221.28,170.15 76 | 196.89,173.8,197.19,196.03,221.58,195.7,221.29,173.46 77 | 196.89,177.12,197.19,199.34,221.6,199.01,221.3,176.78 78 | 194.39,181.44,194.69,203.66,219.11,203.31,218.81,181.1 79 | 193.88,188.26,194.19,210.47,218.62,210.12,218.31,187.92 80 | 192.28,196.75,192.59,218.95,217.03,218.6,216.72,196.4 81 | 191.38,206.84,191.69,229.03,216.15,228.67,215.83,206.49 82 | 190.1,218.18,190.41,240.36,214.88,240,214.56,217.82 83 | 189.15,230.02,189.47,252.19,213.95,251.83,213.63,229.66 84 | 190.2,221.11,190.53,243.27,215.02,242.9,214.7,220.75 85 | 189.76,213.21,190.09,235.35,214.59,234.98,214.26,212.83 86 | 192.72,204.79,193.06,226.92,217.57,226.54,217.24,204.41 87 | 191.88,197.67,192.22,219.79,216.75,219.41,216.41,197.29 88 | 192.3,190.3,192.64,212.41,217.18,212.03,216.83,189.91 89 | 192.71,186.27,193.05,208.37,217.6,207.98,217.26,185.88 90 | 193.12,185.23,193.47,207.32,218.03,206.93,217.68,184.84 91 | 193.53,184.2,193.89,206.28,218.46,205.88,218.11,183.8 92 | 191.82,184.24,192.18,206.32,216.76,205.91,216.4,183.84 93 | 196,187.69,196.36,209.75,220.96,209.34,220.6,187.28 94 | 194.81,191.63,195.18,213.69,219.79,213.28,219.42,191.22 95 | 195.95,195.75,196.32,217.79,220.94,217.37,220.57,195.33 96 | 195.59,203.61,195.97,225.64,220.6,225.22,220.23,203.19 97 | 195.24,211.47,195.61,233.5,220.26,233.07,219.88,211.05 98 | 197.1,221.9,197.49,243.91,222.14,243.48,221.76,221.47 99 | 198.57,229.92,198.96,251.92,223.63,251.48,223.24,229.48 100 | 201.79,216.69,202.18,238.68,226.86,238.24,226.47,216.25 101 | 204.34,205.79,204.73,227.77,229.43,227.33,229.03,205.35 102 | 207.89,195.4,208.29,217.37,232.99,216.92,232.6,194.95 103 | 209.44,187,209.84,208.96,234.56,208.51,234.16,186.55 104 | 213.81,180.26,214.21,202.21,238.94,201.75,238.54,179.8 105 | 217.08,196.95,241.83,196.49,241.42,174.55,216.67,175.01 106 | -------------------------------------------------------------------------------- /speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foolwood/DAT/f3387fbee6c68d5c9bdde3b724db6d0fbb1e54be/speed.png -------------------------------------------------------------------------------- /src/dat_tracker.cpp: -------------------------------------------------------------------------------- 1 | #include "dat_tracker.hpp" 2 | 3 | void DAT_TRACKER::tracker_dat_initialize(cv::Mat I, cv::Rect region){ 4 | 5 | double cx = region.x + double(region.width - 1) / 2.0; 6 | double cy = region.y + double(region.height - 1) / 2.0; 7 | double w = region.width; 8 | double h = region.height; 9 | 10 | cv::Point target_pos(round(cx),round(cy)); 11 | cv::Size target_sz(round(w),round(h)); 12 | 13 | scale_factor_ = std::min(1.0, round(10.0 * double(cfg.img_scale_target_diagonal) / cv::norm(cv::Point(target_sz.width,target_sz.height))) / 10.0); 14 | target_pos.x = target_pos.x * scale_factor_; target_pos.y = target_pos.y * scale_factor_; 15 | target_sz.width = target_sz.width * scale_factor_; target_sz.height = target_sz.height * scale_factor_; 16 | 17 | cv::Mat img; 18 | cv::resize(I, img, cv::Size(), scale_factor_, scale_factor_); 19 | switch (cfg.color_space) { 20 | case 1: //1rgb 21 | img.copyTo(img); 22 | break; 23 | case 2: //2lab 24 | cv::cvtColor(img, img, CV_BGR2Lab); 25 | break; 26 | case 3: //3hsv 27 | cv::cvtColor(img, img, CV_BGR2HSV); 28 | break; 29 | case 4: //4gray 30 | cv::cvtColor(img, img, CV_BGR2GRAY); 31 | break; 32 | default: 33 | std::cout << "int_variable does not equal any of the above cases" << std::endl; 34 | } 35 | cv::Size surr_sz(floor(cfg.surr_win_factor * target_sz.width), 36 | floor(cfg.surr_win_factor * target_sz.height)); 37 | cv::Rect surr_rect = pos2rect(target_pos, surr_sz, img.size()); 38 | cv::Rect obj_rect_surr = pos2rect(target_pos, target_sz, img.size()); 39 | obj_rect_surr.x -= surr_rect.x; 40 | obj_rect_surr.y -= surr_rect.y; 41 | cv::Mat surr_win = getSubwindow(img, target_pos, surr_sz); 42 | cv::Mat prob_map; 43 | getForegroundBackgroundProbs(surr_win, obj_rect_surr, cfg.num_bins, cfg.bin_mapping, prob_lut_, prob_map); 44 | 45 | prob_lut_distractor_ = prob_lut_.clone(); 46 | prob_lut_masked_ = prob_lut_.clone(); 47 | adaptive_threshold_ = getAdaptiveThreshold(prob_map, obj_rect_surr); 48 | 49 | target_pos_history_.push_back(cv::Point(target_pos.x / scale_factor_, target_pos.y / scale_factor_)); 50 | target_sz_history_.push_back(cv::Size(target_sz.width / scale_factor_, target_sz.height / scale_factor_)); 51 | } 52 | 53 | cv::Rect DAT_TRACKER::tracker_dat_update(cv::Mat I){ 54 | 55 | cv::Mat img_preprocessed; 56 | cv::resize(I, img_preprocessed, cv::Size(), scale_factor_, scale_factor_); 57 | cv::Mat img; 58 | switch (cfg.color_space) { 59 | case 1://1rgb 60 | img_preprocessed.copyTo(img); 61 | break; 62 | case 2://2lab 63 | cv::cvtColor(img_preprocessed, img, CV_BGR2Lab); 64 | break; 65 | case 3://3hsv 66 | cv::cvtColor(img_preprocessed, img, CV_BGR2HSV); 67 | break; 68 | case 4://4gray 69 | cv::cvtColor(img_preprocessed, img, CV_BGR2GRAY); 70 | break; 71 | default: 72 | std::cout << "int_variable does not equal any of the above cases" << std::endl; 73 | } 74 | cv::Point prev_pos = target_pos_history_.back(); 75 | cv::Size prev_sz = target_sz_history_.back(); 76 | 77 | if (cfg.motion_estimation_history_size > 0) 78 | prev_pos = prev_pos + getMotionPrediction(target_pos_history_, cfg.motion_estimation_history_size); 79 | 80 | cv::Point2f target_pos(prev_pos.x*scale_factor_, prev_pos.y*scale_factor_); 81 | cv::Size target_sz(prev_sz.width*scale_factor_, prev_sz.height*scale_factor_); 82 | 83 | cv::Size search_sz; 84 | search_sz.width = floor(target_sz.width + cfg.search_win_padding*std::max(target_sz.width, target_sz.height)); 85 | search_sz.height = floor(target_sz.height + cfg.search_win_padding*std::max(target_sz.width, target_sz.height)); 86 | cv::Rect search_rect = pos2rect(target_pos, search_sz); 87 | cv::Mat search_win, padded_search_win; 88 | getSubwindowMasked(img, target_pos, search_sz, search_win, padded_search_win); 89 | 90 | // Apply probability LUT 91 | cv::Mat pm_search = getForegroundProb(search_win, prob_lut_, cfg.bin_mapping); 92 | cv::Mat pm_search_dist; 93 | if (cfg.distractor_aware) { 94 | pm_search_dist = getForegroundProb(search_win, prob_lut_distractor_, cfg.bin_mapping); 95 | pm_search = (pm_search + pm_search_dist)/2.; 96 | } 97 | pm_search.setTo(0, padded_search_win); 98 | 99 | // Cosine / Hanning window 100 | cv::Mat cos_win = CalculateHann(search_sz); 101 | 102 | std::vector hypotheses; 103 | std::vector vote_scores; 104 | std::vector dist_scores; 105 | getNMSRects(pm_search, target_sz, cfg.nms_scale, cfg.nms_overlap, 106 | cfg.nms_score_factor, cos_win, cfg.nms_include_center_vote, 107 | hypotheses, vote_scores, dist_scores); 108 | 109 | std::vector candidate_centers; 110 | std::vector candidate_scores; 111 | for (int i = 0; i < hypotheses.size(); ++i) { 112 | candidate_centers.push_back(cv::Point2f(float(hypotheses[i].x) + float(hypotheses[i].width) / 2., 113 | float(hypotheses[i].y) + float(hypotheses[i].height) / 2.)); 114 | candidate_scores.push_back(vote_scores[i] * dist_scores[i]); 115 | } 116 | int best_candidate = max_element(candidate_scores.begin(), candidate_scores.end()) - candidate_scores.begin(); 117 | 118 | target_pos = candidate_centers[best_candidate]; 119 | 120 | std::vector distractors; 121 | std::vector distractor_overlap; 122 | if (hypotheses.size() > 1) { 123 | distractors.clear(); 124 | distractor_overlap.clear(); 125 | cv::Rect target_rect = pos2rect(target_pos, target_sz, pm_search.size()); 126 | for (int i = 0; i < hypotheses.size(); ++i){ 127 | if (i != best_candidate) { 128 | distractors.push_back(hypotheses[i]); 129 | distractor_overlap.push_back(intersectionOverUnion(target_rect, distractors.back())); 130 | } 131 | } 132 | } else { 133 | distractors.clear(); 134 | distractor_overlap.clear(); 135 | } 136 | 137 | // Localization visualization 138 | if (cfg.show_figures) { 139 | cv::Mat pm_search_color; 140 | pm_search.convertTo(pm_search_color,CV_8UC1,255); 141 | applyColorMap(pm_search_color, pm_search_color, cv::COLORMAP_JET); 142 | for (size_t i = 0; i < hypotheses.size(); ++i){ 143 | cv::rectangle(pm_search_color, hypotheses[i], cv::Scalar(0, 255, 255 * (i != best_candidate)), 2); 144 | } 145 | cv::imshow("Search Window", pm_search_color); 146 | cv::waitKey(1); 147 | } 148 | 149 | // Appearance update 150 | // Get current target position within full(possibly downscaled) image coorinates 151 | cv::Point2f target_pos_img; 152 | target_pos_img.x = target_pos.x + search_rect.x; 153 | target_pos_img.y = target_pos.y + search_rect.y; 154 | if (cfg.prob_lut_update_rate > 0) { 155 | // Extract surrounding region 156 | cv::Size surr_sz; 157 | surr_sz.width = floor(cfg.surr_win_factor * target_sz.width); 158 | surr_sz.height = floor(cfg.surr_win_factor * target_sz.height); 159 | cv::Rect surr_rect = pos2rect(target_pos_img, surr_sz, img.size()); 160 | cv::Rect obj_rect_surr = pos2rect(target_pos_img, target_sz, img.size()); 161 | obj_rect_surr.x -= surr_rect.x; 162 | obj_rect_surr.y -= surr_rect.y; 163 | 164 | cv::Mat surr_win = getSubwindow(img, target_pos_img, surr_sz); 165 | 166 | cv::Mat prob_lut_bg; 167 | getForegroundBackgroundProbs(surr_win, obj_rect_surr, cfg.num_bins, prob_lut_bg); 168 | 169 | cv::Mat prob_map; 170 | if (cfg.distractor_aware) { 171 | // Handle distractors 172 | if (distractors.size() > 1) { 173 | cv::Rect obj_rect = pos2rect(target_pos, target_sz, search_win.size()); 174 | cv::Mat prob_lut_dist = getForegroundDistractorProbs(search_win, obj_rect, distractors, cfg.num_bins); 175 | 176 | prob_lut_distractor_ = (1 - cfg.prob_lut_update_rate) * prob_lut_distractor_ + cfg.prob_lut_update_rate * prob_lut_dist; 177 | } 178 | else { 179 | // If there are no distractors, trigger decay of distractor LUT 180 | prob_lut_distractor_ = (1 - cfg.prob_lut_update_rate) * prob_lut_distractor_ + cfg.prob_lut_update_rate * prob_lut_bg; 181 | } 182 | 183 | // Only update if distractors are not overlapping too much 184 | if (distractors.empty() || (*max_element(distractor_overlap.begin(), distractor_overlap.end()) < 0.1)) { 185 | prob_lut_ = (1 - cfg.prob_lut_update_rate) * prob_lut_ + cfg.prob_lut_update_rate * prob_lut_bg; 186 | } 187 | 188 | prob_map = getForegroundProb(surr_win, prob_lut_, cfg.bin_mapping); 189 | cv::Mat dist_map = getForegroundProb(surr_win, prob_lut_distractor_, cfg.bin_mapping); 190 | prob_map = .5 * prob_map + .5 * dist_map; 191 | } 192 | else { // No distractor - awareness 193 | prob_lut_ = (1 - cfg.prob_lut_update_rate) * prob_lut_ + cfg.prob_lut_update_rate * prob_lut_bg; 194 | prob_map = getForegroundProb(surr_win, prob_lut_, cfg.bin_mapping); 195 | } 196 | // Update adaptive threshold 197 | adaptive_threshold_ = getAdaptiveThreshold(prob_map, obj_rect_surr); 198 | } 199 | 200 | // Store current location 201 | target_pos.x = target_pos.x + search_rect.x ; 202 | target_pos.y = target_pos.y + search_rect.y; 203 | cv::Point target_pos_original; 204 | cv::Size target_sz_original; 205 | target_pos_original.x = target_pos.x / scale_factor_; 206 | target_pos_original.y = target_pos.y / scale_factor_; 207 | target_sz_original.width = target_sz.width / scale_factor_; 208 | target_sz_original.height = target_sz.height / scale_factor_; 209 | 210 | target_pos_history_.push_back(target_pos_original); 211 | target_sz_history_.push_back(target_sz_original); 212 | 213 | // Report current location 214 | cv::Rect location = pos2rect(target_pos_history_.back(), target_sz_history_.back(), I.size()); 215 | 216 | // Adapt image scale factor 217 | scale_factor_ = std::min(1.0, round(10.0 * double(cfg.img_scale_target_diagonal) / cv::norm(cv::Point(target_sz_original.width, target_sz_original.height))) / 10.0); 218 | return location; 219 | } 220 | 221 | void DAT_TRACKER::getNMSRects(cv::Mat prob_map, cv::Size obj_sz, double scale, 222 | double overlap, double score_frac, cv::Mat dist_map, bool include_inner, 223 | std::vector &top_rects, std::vector &top_vote_scores, std::vector &top_dist_scores){ 224 | int height = prob_map.rows; 225 | int width = prob_map.cols; 226 | cv::Size rect_sz(floor(obj_sz.width * scale), floor(obj_sz.height * scale)); 227 | int o_x, o_y; 228 | if (include_inner) { 229 | o_x = round(std::max(1.0, rect_sz.width*0.2)); 230 | o_y = round(std::max(1.0, rect_sz.height*0.2)); 231 | } 232 | 233 | int stepx = std::max(1, int(round(rect_sz.width * (1.0 - overlap)))); 234 | int stepy = std::max(1, int(round(rect_sz.height * (1.0 - overlap)))); 235 | 236 | std::vector posx, posy; 237 | for (int i = 0; i <= (width -1 - rect_sz.width); i += stepx) 238 | { 239 | posx.push_back(i); 240 | } 241 | for (int i = 0; i <= (height -1 - rect_sz.height); i += stepy) 242 | { 243 | posy.push_back(i); 244 | } 245 | cv::Mat xgv(posx); cv::Mat ygv(posy); cv::Mat x; cv::Mat y; 246 | cv::repeat(xgv.reshape(1, 1), ygv.total(), 1, x); 247 | cv::repeat(ygv.reshape(1, 1).t(), 1, xgv.total(), y); 248 | 249 | cv::Mat r = x + rect_sz.width;; 250 | cv::Mat b = y + rect_sz.height; 251 | r.setTo(width-1, r > (width-1)); 252 | b.setTo(height-1, b > (height-1)); 253 | 254 | std::vector boxes; 255 | int n = x.rows*x.cols; 256 | int *p_x = x.ptr(0); 257 | int *p_y = y.ptr(0); 258 | int *p_r = r.ptr(0); 259 | int *p_b = b.ptr(0); 260 | for (int i = 0; i < n; ++i) 261 | boxes.push_back(cv::Rect(p_x[i], p_y[i], p_r[i] - p_x[i], p_b[i] - p_y[i])); 262 | 263 | std::vector boxes_inner; 264 | if (include_inner) { 265 | for (int i = 0; i < n; ++i) 266 | boxes_inner.push_back(cv::Rect(p_x[i] + o_x, p_y[i] + o_y, p_r[i] - p_x[i] - 2 * o_x, p_b[i] - p_y[i] - 2 * o_y)); 267 | } 268 | 269 | // Linear indices 270 | cv::Mat l = x; 271 | cv::Mat t = y; 272 | int h = height + 1; 273 | int w = width + 1; 274 | std::vectorbl, br, tl, tr; 275 | 276 | int *p_l = l.ptr(0); 277 | int *p_t = t.ptr(0); 278 | for (int i = 0; i < n; ++i){ 279 | bl.push_back(cv::Point(p_l[i], p_b[i])); 280 | br.push_back(cv::Point(p_r[i], p_b[i])); 281 | tl.push_back(cv::Point(p_l[i], p_t[i])); 282 | tr.push_back(cv::Point(p_r[i], p_t[i])); 283 | } 284 | cv::Size rect_sz_inner; 285 | std::vectorbl_inner, br_inner, tl_inner, tr_inner; 286 | if (include_inner){ 287 | rect_sz_inner.width = rect_sz.width - 2 * o_x; 288 | rect_sz_inner.height = rect_sz.height - 2 *o_y; 289 | 290 | for (int i = 0; i < n; ++i){ 291 | bl_inner.push_back(cv::Point(p_l[i]+o_x, p_b[i]-o_y)); 292 | br_inner.push_back(cv::Point(p_r[i]-o_x, p_b[i]-o_y)); 293 | tl_inner.push_back(cv::Point(p_l[i]+o_x, p_t[i]+o_y)); 294 | tr_inner.push_back(cv::Point(p_r[i]-o_x, p_t[i]+o_y)); 295 | } 296 | } 297 | 298 | cv::Mat intProbMap; 299 | cv::integral(prob_map, intProbMap); 300 | cv::Mat intDistMap; 301 | cv::integral(dist_map, intDistMap); 302 | 303 | std::vector v_scores(n, 0); 304 | std::vector d_scores(n, 0); 305 | for (int i = 0; i < bl.size(); ++i){ 306 | v_scores[i] = intProbMap.at(br[i]) - intProbMap.at(bl[i]) - intProbMap.at(tr[i]) + intProbMap.at(tl[i]); 307 | d_scores[i] = intDistMap.at(br[i]) - intDistMap.at(bl[i]) - intDistMap.at(tr[i]) + intDistMap.at(tl[i]); 308 | } 309 | std::vector scores_inner(n, 0); 310 | if (include_inner){ 311 | for (int i = 0; i < bl.size(); ++i){ 312 | scores_inner[i] = intProbMap.at(br_inner[i]) - intProbMap.at(bl_inner[i]) - intProbMap.at(tr_inner[i]) + intProbMap.at(tl_inner[i]); 313 | v_scores[i] = v_scores[i] / double(rect_sz.area()) + scores_inner[i] / double(rect_sz_inner.area()); 314 | } 315 | } 316 | 317 | top_rects.clear();; 318 | top_vote_scores.clear(); 319 | top_dist_scores.clear(); 320 | int midx = max_element(v_scores.begin(), v_scores.end()) - v_scores.begin(); 321 | double ms = v_scores[midx]; 322 | 323 | double best_score = ms; 324 | 325 | while (ms > score_frac * best_score){ 326 | prob_map(boxes[midx]) = cv::Scalar(0.0); 327 | top_rects.push_back(boxes[midx]); 328 | top_vote_scores.push_back(v_scores[midx]); 329 | top_dist_scores.push_back(d_scores[midx]); 330 | boxes.erase(boxes.begin() + midx); 331 | if (include_inner) 332 | boxes_inner.erase(boxes_inner.begin() + midx); 333 | 334 | bl.erase(bl.begin() + midx); 335 | br.erase(br.begin() + midx); 336 | tl.erase(tl.begin() + midx); 337 | tr.erase(tr.begin() + midx); 338 | if (include_inner){ 339 | bl_inner.erase(bl_inner.begin() + midx); 340 | br_inner.erase(br_inner.begin() + midx); 341 | tl_inner.erase(tl_inner.begin() + midx); 342 | tr_inner.erase(tr_inner.begin() + midx); 343 | } 344 | 345 | cv::integral(prob_map, intProbMap); 346 | cv::integral(dist_map, intDistMap); 347 | 348 | v_scores.resize(bl.size(), 0); 349 | d_scores.resize(bl.size(), 0); 350 | for (int i = 0; i < bl.size(); ++i){ 351 | v_scores[i] = intProbMap.at(br[i]) - intProbMap.at(bl[i]) - intProbMap.at(tr[i]) + intProbMap.at(tl[i]); 352 | d_scores[i] = intDistMap.at(br[i]) - intDistMap.at(bl[i]) - intDistMap.at(tr[i]) + intDistMap.at(tl[i]); 353 | } 354 | scores_inner.resize(bl.size(), 0); 355 | if (include_inner){ 356 | for (int i = 0; i < bl.size(); ++i){ 357 | scores_inner[i] = intProbMap.at(br_inner[i]) - intProbMap.at(bl_inner[i]) - intProbMap.at(tr_inner[i]) + intProbMap.at(tl_inner[i]); 358 | v_scores[i] = v_scores[i] / (rect_sz.area()) + scores_inner[i] / (rect_sz_inner.area()); 359 | } 360 | } 361 | midx = max_element(v_scores.begin(), v_scores.end()) - v_scores.begin(); 362 | ms = v_scores[midx]; 363 | } 364 | } 365 | 366 | double DAT_TRACKER::intersectionOverUnion(cv::Rect target_rect, cv::Rect candidates) { 367 | return double((target_rect & candidates).area()) / double(target_rect.area() + candidates.area() - (target_rect & candidates).area()); 368 | } 369 | 370 | cv::Mat DAT_TRACKER::getForegroundDistractorProbs(cv::Mat frame, cv::Rect obj_rect, std::vector distractors, int num_bins) { 371 | int imgCount = 1; 372 | int dims = 3; 373 | const int sizes[] = { num_bins, num_bins, num_bins }; 374 | const int channels[] = { 0, 1, 2 }; 375 | float rRange[] = { 0, 256 }; 376 | float gRange[] = { 0, 256 }; 377 | float bRange[] = { 0, 256 }; 378 | const float *ranges[] = { rRange, gRange, bRange }; 379 | 380 | cv::Mat Md(frame.size(), CV_8UC1, cv::Scalar(0)); 381 | cv::Mat Mo(frame.size(), CV_8UC1, cv::Scalar(0)); 382 | for (int i = 0; i < distractors.size(); ++i) { 383 | Mo(distractors[i]) = true; 384 | } 385 | Mo(obj_rect) = true; 386 | 387 | cv::Mat obj_hist, distr_hist; 388 | cv::calcHist(&frame, imgCount, channels, Md, distr_hist, dims, sizes, ranges); 389 | cv::calcHist(&frame, imgCount, channels, Mo, obj_hist, dims, sizes, ranges); 390 | cv::Mat prob_lut = (obj_hist*distractors.size() + 1) / (distr_hist + obj_hist*distractors.size() + 2); 391 | return prob_lut; 392 | } 393 | 394 | cv::Mat DAT_TRACKER::CalculateHann(cv::Size sz) { 395 | cv::Mat temp1(cv::Size(sz.width, 1), CV_32FC1); 396 | cv::Mat temp2(cv::Size(sz.height, 1), CV_32FC1); 397 | float *p1 = temp1.ptr(0); 398 | float *p2 = temp2.ptr(0); 399 | for (int i = 0; i < sz.width; ++i) 400 | p1[i] = 0.5*(1 - cos(_2PI*i / (sz.width - 1))); 401 | for (int i = 0; i < sz.height; ++i) 402 | p2[i] = 0.5*(1 - cos(_2PI*i / (sz.height - 1))); 403 | return temp2.t()*temp1; 404 | } 405 | 406 | cv::Mat DAT_TRACKER::getForegroundProb(cv::Mat frame, cv::Mat prob_lut, cv::Mat bin_mapping){ 407 | cv::Mat frame_bin; 408 | cv::Mat prob_map(frame.size(), CV_32FC1); 409 | cv::LUT(frame, bin_mapping, frame_bin); 410 | float *p_prob_map = prob_map.ptr(0); 411 | cv::MatIterator_ it, end; 412 | for (it = frame_bin.begin(), end = frame_bin.end(); it != end; ++it) 413 | { 414 | *p_prob_map++ = prob_lut.at((*it)[0], (*it)[1], (*it)[2]); 415 | } 416 | return prob_map; 417 | } 418 | 419 | void DAT_TRACKER::getSubwindowMasked(cv::Mat im, cv::Point pos, cv::Size sz, cv::Mat &out, cv::Mat &mask){ 420 | 421 | int xs_1 = floor(pos.x) + 1 - floor(double(sz.width) / 2.); 422 | int xs_2 = floor(pos.x) + sz.width - floor(double(sz.width) / 2.); 423 | int ys_1 = floor(pos.y) + 1 - floor(double(sz.height) / 2.); 424 | int ys_2 = floor(pos.y) + sz.height - floor(double(sz.height) / 2.); 425 | 426 | out = getSubwindow(im, pos, sz); 427 | 428 | cv::Rect bbox(xs_1, ys_1, sz.width, sz.height); 429 | bbox = bbox&cv::Rect(0, 0, im.cols - 1, im.rows - 1); 430 | bbox.x = bbox.x - xs_1; 431 | bbox.y = bbox.y - ys_1; 432 | mask = cv::Mat(sz, CV_8UC1,cv::Scalar(1)); 433 | mask(bbox) = cv::Scalar(0.0); 434 | } 435 | 436 | cv::Point DAT_TRACKER::getMotionPrediction(std::vectorvalues, int maxNumFrames){ 437 | cv::Point2f pred(0, 0); 438 | if (values.size() < 3){ 439 | pred.x = 0; pred.y = 0; 440 | } 441 | else { 442 | maxNumFrames = maxNumFrames + 2; 443 | double A1 = 0.8; 444 | double A2 = -1; 445 | 446 | std::vector V; 447 | for (int i = std::max(0, int(int(values.size()) - maxNumFrames)); i < values.size(); ++i) 448 | V.push_back(values[i]); 449 | 450 | std::vector P; 451 | for (int i = 2; i < V.size(); ++i){ 452 | P.push_back(cv::Point2f(A1*(V[i].x - V[i - 2].x) + A2*(V[i - 1].x - V[i - 2].x), 453 | A1*(V[i].y - V[i - 2].y) + A2*(V[i - 1].y - V[i - 2].y))); 454 | } 455 | for (int i = 0; i < P.size(); ++i){ 456 | pred.x += P[i].x; 457 | pred.y += P[i].y; 458 | } 459 | pred.x = pred.x / P.size(); 460 | pred.y = pred.y / P.size(); 461 | } 462 | return pred; 463 | } 464 | 465 | void DAT_TRACKER::getForegroundBackgroundProbs(cv::Mat frame, cv::Rect obj_rect, int num_bins, cv::Mat bin_mapping, cv::Mat &prob_lut, cv::Mat &prob_map) { 466 | int imgCount = 1; 467 | const int channels[] = { 0, 1, 2 }; 468 | cv::Mat mask = cv::Mat(); 469 | int dims = 3; 470 | const int sizes[] = { num_bins, num_bins, num_bins }; 471 | float bRange[] = { 0, 256 }; 472 | float gRange[] = { 0, 256 }; 473 | float rRange[] = { 0, 256 }; 474 | const float *ranges[] = { bRange, gRange, rRange }; 475 | 476 | cv::Mat surr_hist, obj_hist; 477 | cv::calcHist(&frame, imgCount, channels, mask, surr_hist, dims, sizes, ranges); 478 | 479 | int obj_col = round(obj_rect.x); 480 | int obj_row = round(obj_rect.y); 481 | int obj_width = round(obj_rect.width); 482 | int obj_height = round(obj_rect.height); 483 | 484 | if ((obj_col + obj_width) > (frame.cols - 1)) 485 | obj_width = (frame.cols - 1) - obj_col; 486 | if ((obj_row + obj_height) > (frame.rows-1)) 487 | obj_height = (frame.rows-1) - obj_row; 488 | 489 | cv::Mat obj_win; 490 | cv::Rect obj_region(std::max(0, obj_col), std::max(0, obj_row), 491 | obj_col + obj_width + 1 - std::max(0, obj_col), obj_row + obj_height + 1 - std::max(0, obj_row)); 492 | obj_win = frame(obj_region); 493 | cv::calcHist(&obj_win, imgCount, channels, mask, obj_hist, dims, sizes, ranges); 494 | prob_lut = (obj_hist + 1.) / (surr_hist + 2.); 495 | 496 | prob_map = cv::Mat(frame.size(), CV_32FC1); 497 | cv::Mat frame_bin; 498 | cv::LUT(frame, bin_mapping, frame_bin); 499 | 500 | float *p_prob_map = prob_map.ptr(0); 501 | cv::MatIterator_ it, end; 502 | for (it = frame_bin.begin(), end = frame_bin.end(); it != end; ++it) 503 | { 504 | *p_prob_map++ = prob_lut.at((*it)[0], (*it)[1], (*it)[2]); 505 | } 506 | } 507 | 508 | 509 | void DAT_TRACKER::getForegroundBackgroundProbs(cv::Mat frame, cv::Rect obj_rect, int num_bins, cv::Mat &prob_lut) { 510 | int imgCount = 1; 511 | const int channels[] = { 0, 1, 2 }; 512 | cv::Mat mask = cv::Mat(); 513 | int dims = 3; 514 | const int sizes[] = { num_bins, num_bins, num_bins }; 515 | float bRange[] = { 0, 256 }; 516 | float gRange[] = { 0, 256 }; 517 | float rRange[] = { 0, 256 }; 518 | const float *ranges[] = { bRange, gRange, rRange }; 519 | 520 | cv::Mat surr_hist, obj_hist; 521 | cv::calcHist(&frame, imgCount, channels, mask, surr_hist, dims, sizes, ranges); 522 | 523 | int obj_col = round(obj_rect.x); 524 | int obj_row = round(obj_rect.y); 525 | int obj_width = round(obj_rect.width); 526 | int obj_height = round(obj_rect.height); 527 | 528 | if ((obj_col + obj_width) > (frame.cols - 1)) 529 | obj_width = (frame.cols - 1) - obj_col; 530 | if ((obj_row + obj_height) > (frame.rows - 1)) 531 | obj_height = (frame.rows - 1) - obj_row; 532 | 533 | cv::Mat obj_win; 534 | frame(cv::Rect(std::max(0, obj_col), std::max(0, obj_row), obj_width + 1, obj_height + 1)).copyTo(obj_win); 535 | cv::calcHist(&obj_win, imgCount, channels, mask, obj_hist, dims, sizes, ranges); 536 | prob_lut = (obj_hist + 1) / (surr_hist + 2); 537 | } 538 | 539 | 540 | double DAT_TRACKER::getAdaptiveThreshold(cv::Mat prob_map, cv::Rect obj_coords){ 541 | obj_coords.width++; obj_coords.width = std::min(prob_map.cols - obj_coords.x, obj_coords.width); 542 | obj_coords.height++; obj_coords.height = std::min(prob_map.rows - obj_coords.y, obj_coords.height); 543 | cv::Mat obj_prob_map = prob_map(obj_coords); 544 | int bins = 21; 545 | float range[] = { -0.025, 1.025 }; 546 | const float* histRange = { range }; 547 | bool uniform = true; bool accumulate = false; 548 | 549 | cv::Mat H_obj, H_dist; 550 | /// Compute the histograms: 551 | cv::calcHist(&obj_prob_map, 1, 0, cv::Mat(), H_obj, 1, &bins, &histRange, uniform, accumulate); 552 | 553 | H_obj = H_obj / cv::sum(H_obj)[0]; 554 | cv::Mat cum_H_obj = H_obj.clone(); 555 | for (int i = 1; i < cum_H_obj.rows; ++i) 556 | cum_H_obj.at(i, 0) += cum_H_obj.at(i-1, 0); 557 | 558 | cv::calcHist(&prob_map, 1, 0, cv::Mat(), H_dist, 1, &bins, &histRange, uniform, accumulate); 559 | H_dist = H_dist - H_obj; 560 | H_dist = H_dist / cv::sum(H_dist)[0]; 561 | cv::Mat cum_H_dist = H_dist.clone(); 562 | for (int i = 1; i < cum_H_dist.rows; ++i) 563 | cum_H_dist.at(i, 0) += cum_H_dist.at(i - 1, 0); 564 | 565 | cv::Mat k(cum_H_obj.size(), cum_H_obj.type(), cv::Scalar(0.0)); 566 | for (int i = 0; i < (k.rows-1); ++i) 567 | k.at(i, 0) = cum_H_obj.at(i + 1, 0) - cum_H_obj.at(i, 0); 568 | cv::Mat cum_H_obj_lt = (cum_H_obj < (1 - cum_H_dist)); 569 | cum_H_obj_lt.convertTo(cum_H_obj_lt, CV_32FC1, 1.0/255); 570 | cv::Mat x = abs(cum_H_obj - (1 - cum_H_dist)) + cum_H_obj_lt + (1 - k); 571 | float xmin = 100; 572 | int min_index = 0; 573 | for (int i = 0; i < x.rows; ++i) { 574 | if (xmin > x.at(i, 0)) 575 | { 576 | xmin = x.at(i, 0); 577 | min_index = i; 578 | } 579 | } 580 | //Final threshold result should lie between 0.4 and 0.7 to be not too restrictive 581 | double threshold = std::max(.4, std::min(.7, cfg.adapt_thresh_prob_bins[min_index])); 582 | return threshold; 583 | } 584 | 585 | cv::Rect DAT_TRACKER::pos2rect(cv::Point obj_center, cv::Size obj_size, cv::Size win_size){ 586 | cv::Rect rect(round(obj_center.x - obj_size.width / 2), round(obj_center.y - obj_size.height / 2), obj_size.width, obj_size.height); 587 | cv::Rect border(0, 0, win_size.width - 1, win_size.height - 1); 588 | return rect&border; 589 | } 590 | 591 | cv::Rect DAT_TRACKER::pos2rect(cv::Point obj_center, cv::Size obj_size){ 592 | cv::Rect rect(round(obj_center.x - obj_size.width / 2), round(obj_center.y - obj_size.height / 2), obj_size.width, obj_size.height); 593 | return rect; 594 | } 595 | 596 | dat_cfg DAT_TRACKER::default_parameters_dat(dat_cfg cfg){ 597 | for (double i = 0; i <= 20; i++) 598 | cfg.adapt_thresh_prob_bins.push_back(i*0.05); 599 | 600 | cv::Mat lookUpTable(1, 256, CV_8U); 601 | uchar* p = lookUpTable.data; 602 | for (int i = 0; i < 256; ++i) 603 | p[i] = uchar(i / (256 / cfg.num_bins)); 604 | cfg.bin_mapping = lookUpTable; 605 | return cfg; 606 | } 607 | 608 | cv::Mat DAT_TRACKER::getSubwindow(const cv::Mat &frame, cv::Point centerCoor, cv::Size sz) { 609 | cv::Mat subWindow; 610 | cv::Point lefttop(std::min(frame.cols - 1, std::max(-sz.width + 1, centerCoor.x - cvFloor(float(sz.width) / 2.0) + 1)), 611 | std::min(frame.rows - 1, std::max(-sz.height + 1, centerCoor.y - cvFloor(float(sz.height) / 2.0) + 1))); 612 | cv::Point rightbottom(lefttop.x + sz.width - 1, lefttop.y + sz.height - 1); 613 | 614 | cv::Rect border(-std::min(lefttop.x, 0), -std::min(lefttop.y, 0), 615 | std::max(rightbottom.x - frame.cols + 1, 0), std::max(rightbottom.y - frame.rows + 1, 0)); 616 | cv::Point lefttopLimit(std::max(lefttop.x, 0), std::max(lefttop.y, 0)); 617 | cv::Point rightbottomLimit(std::min(rightbottom.x, frame.cols - 1), std::min(rightbottom.y, frame.rows - 1)); 618 | 619 | rightbottomLimit.x += 1; 620 | rightbottomLimit.y += 1; 621 | cv::Rect roiRect(lefttopLimit, rightbottomLimit); 622 | 623 | frame(roiRect).copyTo(subWindow); 624 | 625 | if (border != cv::Rect(0, 0, 0, 0)) 626 | cv::copyMakeBorder(subWindow, subWindow, border.y, border.height, border.x, border.width, cv::BORDER_REPLICATE); 627 | return subWindow; 628 | } 629 | -------------------------------------------------------------------------------- /src/dat_tracker.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DAT_TRACKER_HPP_ 2 | #define DAT_TRACKER_HPP_ 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define _PI 3.141592653589793 15 | #define _2PI 6.283185307179586 16 | 17 | 18 | struct dat_cfg { 19 | bool show_figures = false; 20 | int img_scale_target_diagonal = 75; 21 | double search_win_padding = 2; 22 | double surr_win_factor = 1.9; 23 | int color_space = 1; //1rgb 2lab 3hsv 4gray 24 | int num_bins = 16; 25 | cv::Mat bin_mapping; //getBinMapping(cfg.num_bins); 26 | double prob_lut_update_rate = 0.05; 27 | bool distractor_aware = true; 28 | std::vector adapt_thresh_prob_bins; // 0:0.05 : 1; 29 | int motion_estimation_history_size = 5; 30 | 31 | int nms_scale = 1; 32 | double nms_overlap = 0.9; 33 | double nms_score_factor = 0.5; 34 | bool nms_include_center_vote = true; 35 | }; 36 | 37 | class DAT_TRACKER 38 | { 39 | public: 40 | DAT_TRACKER(){ cfg = default_parameters_dat(cfg); }; 41 | ~DAT_TRACKER(){} 42 | 43 | void tracker_dat_initialize(cv::Mat I, cv::Rect region); 44 | 45 | cv::Rect tracker_dat_update(cv::Mat I); 46 | 47 | protected: 48 | void getNMSRects(cv::Mat prob_map, cv::Size obj_sz, double scale, 49 | double overlap, double score_frac, cv::Mat dist_map, bool include_inner, 50 | std::vector &top_rects, std::vector &top_vote_scores, std::vector &top_dist_scores); 51 | 52 | void getForegroundBackgroundProbs(cv::Mat frame, cv::Rect obj_rect, int num_bins, cv::Mat bin_mapping, cv::Mat &prob_lut, cv::Mat &prob_map); 53 | 54 | void getForegroundBackgroundProbs(cv::Mat frame, cv::Rect obj_rect, int num_bins, cv::Mat &prob_lut); 55 | 56 | cv::Mat getForegroundDistractorProbs(cv::Mat frame, cv::Rect obj_rect, std::vector distractors, int num_bins); 57 | 58 | double getAdaptiveThreshold(cv::Mat prob_map, cv::Rect obj_rect_surr); 59 | 60 | cv::Mat getForegroundProb(cv::Mat frame, cv::Mat prob_lut, cv::Mat bin_mapping); 61 | 62 | cv::Mat CalculateHann(cv::Size sz); 63 | 64 | double intersectionOverUnion(cv::Rect target_rect, cv::Rect candidates); 65 | 66 | void getSubwindowMasked(cv::Mat im, cv::Point pos, cv::Size sz, cv::Mat &out, cv::Mat &mask); 67 | 68 | cv::Point getMotionPrediction(std::vectorvalues, int maxNumFrames); 69 | 70 | cv::Rect pos2rect(cv::Point obj_center, cv::Size obj_size, cv::Size win_size); 71 | 72 | cv::Rect pos2rect(cv::Point obj_center, cv::Size obj_size); 73 | 74 | cv::Mat getSubwindow(const cv::Mat &frame, cv::Point centerCoor, cv::Size sz); 75 | 76 | dat_cfg default_parameters_dat(dat_cfg cfg); 77 | 78 | private: 79 | dat_cfg cfg; 80 | double scale_factor_; 81 | cv::Mat prob_lut_; 82 | cv::Mat prob_lut_distractor_; 83 | cv::Mat prob_lut_masked_; 84 | double adaptive_threshold_; 85 | std::vectortarget_pos_history_; 86 | std::vectortarget_sz_history_; 87 | }; 88 | 89 | #endif /* DAT_TRACKER_HPP_ */ -------------------------------------------------------------------------------- /src/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "dat_tracker.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | cv::Rect poly2rect(std::vector polygon); 14 | std::vector poly2rect(std::vector > polygon_v); 15 | std::vector getgroundtruth(std::string txt_file); 16 | 17 | 18 | //int main(){ 19 | // std::string video_base_path = "."; 20 | // std::vector videos = { "bag", "ball1", "ball2", "basketball", "birds1", "birds2", 21 | // "blanket", "bmx", "bolt1", "bolt2", "book", "butterfly", "car1", "car2", "crossing", "dinosaur", 22 | // "fernando", "fish1", "fish2", "fish3", "fish4", "girl", "glove", "godfather", "graduate", 23 | // "gymnastics1", "gymnastics2", "gymnastics3", "gymnastics4", "hand", "handball1", "handball2", 24 | // "helicopter","iceskater1","iceskater2","leaves","marching","matrix","motocross1", 25 | // "motocross2","nature","octopus","pedestrian1","pedestrian2","rabbit","racing","road", 26 | // "shaking","sheep","singer1","singer2","singer3","soccer1","soccer2","soldier", 27 | // "sphere","tiger","traffic","tunnel","wiper" }; 28 | // 29 | // //std::vector videos = {"birds2"}; 30 | // std::vector time_v; 31 | // std::vector frame_v; 32 | // for (int v = 0; v < videos.size(); ++v) { 33 | // std::string video = videos[v]; 34 | // std::string pattern_jpg = video_base_path + "\\" + video + "\\*.jpg"; 35 | // std::string txt_base_path = video_base_path + "\\" + video + "\\groundtruth.txt"; 36 | // 37 | // std::vector image_files; 38 | // cv::glob(pattern_jpg, image_files); 39 | // std::sort(image_files.begin(), image_files.end()); 40 | // if (image_files.size() == 0) 41 | // return -1; 42 | // 43 | // std::vector groundtruth_rect; 44 | // groundtruth_rect = getgroundtruth(txt_base_path); 45 | // 46 | // DAT_TRACKER dat; 47 | // 48 | // cv::Rect location = groundtruth_rect[0]; 49 | // cv::Mat image; 50 | // std::vector result_rects; 51 | // int64 tic, toc; 52 | // double time = 0; 53 | // bool show_visualization = true; 54 | // 55 | // for (unsigned int frame = 0; frame < image_files.size(); ++frame) { 56 | // image = cv::imread(image_files[frame]); 57 | // tic = cv::getTickCount(); 58 | // if (frame == 0){ 59 | // dat.tracker_dat_initialize(image, location); 60 | // } 61 | // else { 62 | // location = dat.tracker_dat_update(image); 63 | // } 64 | // 65 | // toc = cv::getTickCount() - tic; 66 | // time += toc; 67 | // result_rects.push_back(location); 68 | // 69 | // if (show_visualization) { 70 | // cv::putText(image, std::to_string(frame + 1), cv::Point(20, 40), 6, 1, 71 | // cv::Scalar(0, 255, 255), 2); 72 | // cv::rectangle(image, groundtruth_rect[frame], cv::Scalar(0, 255, 0), 2); 73 | // cv::rectangle(image, location, cv::Scalar(0, 0, 255), 2); 74 | // cv::imshow(video, image); 75 | // 76 | // char key = cv::waitKey(1); 77 | // if (key == 27 || key == 'q' || key == 'Q') 78 | // break; 79 | // } 80 | // } 81 | // time = time / double(cv::getTickFrequency()); 82 | // double fps = double(result_rects.size()) / time; 83 | // time_v.push_back(time); 84 | // frame_v.push_back(result_rects.size()); 85 | // printf("\t%2d / %2d video: %12s\tFPS: %3.2f\n", v + 1, videos.size(), video, fps); 86 | // cv::destroyAllWindows(); 87 | // } 88 | // printf("\t\t\tAverage FPS: %3.2f\n", std::accumulate(frame_v.begin(), frame_v.end(), 0.0) / std::accumulate(time_v.begin(), time_v.end(), 0.0)); 89 | // return 0; 90 | //} 91 | 92 | 93 | int main(){ 94 | 95 | std::string video_base_path = "."; 96 | std::string pattern_jpg = video_base_path + "/sequence/*.jpg"; 97 | std::string txt_base_path = video_base_path + "/sequence/groundtruth.txt"; 98 | 99 | std::vector image_files; 100 | cv::glob(pattern_jpg, image_files); 101 | if (image_files.size() == 0) 102 | return -1; 103 | 104 | std::vector groundtruth_rect; 105 | groundtruth_rect = getgroundtruth(txt_base_path); 106 | //for (size_t i = 0; i < groundtruth_rect.size(); ++i) 107 | // std::cout << i+1 << '\t' < result_rects; 114 | int64 tic, toc; 115 | double time = 0; 116 | bool show_visualization = true; 117 | 118 | for (unsigned int frame = 0; frame < image_files.size(); ++frame) { 119 | image = cv::imread(image_files[frame]); 120 | tic = cv::getTickCount(); 121 | if (frame == 0){ 122 | dat.tracker_dat_initialize(image, location); 123 | } 124 | else { 125 | location = dat.tracker_dat_update(image); 126 | } 127 | 128 | toc = cv::getTickCount() - tic; 129 | time += toc; 130 | result_rects.push_back(location); 131 | 132 | if (show_visualization) { 133 | cv::putText(image, std::to_string(frame + 1), cv::Point(20, 40), 6, 1, 134 | cv::Scalar(0, 255, 255), 2); 135 | cv::rectangle(image, groundtruth_rect[frame], cv::Scalar(0, 255, 0), 2); 136 | cv::rectangle(image, location, cv::Scalar(0, 128, 255), 2); 137 | cv::imshow("DAT", image); 138 | 139 | char key = cv::waitKey(1); 140 | if (key == 27 || key == 'q' || key == 'Q') 141 | break; 142 | } 143 | } 144 | time = time / double(cv::getTickFrequency()); 145 | double fps = double(result_rects.size()) / time; 146 | std::cout << "fps:" << fps << std::endl; 147 | cv::destroyAllWindows(); 148 | 149 | return 0; 150 | } 151 | 152 | cv::Rect poly2rect(std::vector polygon){ 153 | // POLY2RECT Convert polygon to rectangle 154 | // Compute axis aligned bounding boxes with correct area and center 155 | double cx = double(polygon[0].x + polygon[1].x + polygon[2].x + polygon[3].x) / 4.; 156 | double cy = double(polygon[0].y + polygon[1].y + polygon[2].y + polygon[3].y) / 4.; 157 | double x1 = std::min(std::min(std::min(polygon[0].x, polygon[1].x), polygon[2].x), polygon[3].x); 158 | double x2 = std::max(std::max(std::max(polygon[0].x, polygon[1].x), polygon[2].x), polygon[3].x); 159 | double y1 = std::min(std::min(std::min(polygon[0].y, polygon[1].y), polygon[2].y), polygon[3].y); 160 | double y2 = std::max(std::max(std::max(polygon[0].y, polygon[1].y), polygon[2].y), polygon[3].y); 161 | double A1 = norm(polygon[1] - polygon[2])*norm(polygon[2] - polygon[3]); 162 | double A2 = (x2 - x1) * (y2 - y1); 163 | double s = sqrt(A1 / A2); 164 | double w = s * (x2 - x1) + 1; 165 | double h = s * (y2 - y1) + 1; 166 | cv::Rect rect(round(cx - w / 2.) - 1, round(cy - h / 2.) - 1, round(w), round(h)); 167 | return rect; 168 | 169 | } 170 | 171 | std::vector poly2rect(std::vector > polygon_v){ 172 | // POLY2RECT Convert polygon to rectangle 173 | // Compute axis aligned bounding boxes with correct area and center 174 | std::vector rect_v; 175 | for (unsigned int i = 0; i < polygon_v.size(); ++i) { 176 | rect_v.push_back(poly2rect(polygon_v[i])); 177 | } 178 | return rect_v; 179 | 180 | } 181 | 182 | std::vector getgroundtruth(std::string txt_file) { 183 | std::vector rects; 184 | std::ifstream gt; 185 | gt.open(txt_file.c_str()); 186 | if (!gt.is_open()) 187 | std::cout << "Ground truth file " << txt_file 188 | << " can not be read" << std::endl; 189 | std::string line; 190 | float x1, y1, x2, y2, x3, y3, x4, y4; 191 | while (getline(gt, line)) { 192 | std::replace(line.begin(), line.end(), ',', ' '); 193 | std::stringstream ss; 194 | ss.str(line); 195 | ss >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; 196 | std::vectorpolygon; 197 | polygon.push_back(cv::Point2f(x1, y1)); 198 | polygon.push_back(cv::Point2f(x2, y2)); 199 | polygon.push_back(cv::Point2f(x3, y3)); 200 | polygon.push_back(cv::Point2f(x4, y4)); 201 | rects.push_back(poly2rect(polygon)); //0-index 202 | } 203 | gt.close(); 204 | return rects; 205 | } 206 | 207 | 208 | --------------------------------------------------------------------------------