├── CMakeLists.txt ├── README.md ├── cmake └── FindTBB.cmake ├── exampleDSKCF.bat └── src ├── 3rdparty ├── cv_ext │ ├── init_box_selector.cpp │ ├── init_box_selector.hpp │ ├── math_spectrums.cpp │ ├── math_spectrums.hpp │ ├── psr.hpp │ ├── shift.cpp │ ├── shift.hpp │ ├── tracker_run.cpp │ └── tracker_run.hpp ├── piotr │ ├── README.md │ ├── gradientMex.hpp │ └── src │ │ ├── gradientMex.cpp │ │ ├── sse.hpp │ │ └── wrappers.hpp └── tclap │ ├── AUTHORS │ ├── COPYING │ ├── ChangeLog │ ├── INSTALL │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ └── tclap │ ├── Arg.h │ ├── ArgException.h │ ├── ArgTraits.h │ ├── CmdLine.h │ ├── CmdLineInterface.h │ ├── CmdLineOutput.h │ ├── Constraint.h │ ├── DocBookOutput.h │ ├── HelpVisitor.h │ ├── IgnoreRestVisitor.h │ ├── Makefile.am │ ├── Makefile.in │ ├── MultiArg.h │ ├── MultiSwitchArg.h │ ├── OptionalUnlabeledTracker.h │ ├── StandardTraits.h │ ├── StdOutput.h │ ├── SwitchArg.h │ ├── UnlabeledMultiArg.h │ ├── UnlabeledValueArg.h │ ├── ValueArg.h │ ├── ValuesConstraint.h │ ├── VersionVisitor.h │ ├── Visitor.h │ ├── XorHandler.h │ └── ZshCompletionOutput.h ├── cf_libs ├── common │ ├── DepthHistogram.cpp │ ├── DepthHistogram.h │ ├── KalmanFilter1D.cpp │ ├── KalmanFilter1D.h │ ├── KalmanFilter2D.cpp │ ├── KalmanFilter2D.h │ ├── Typedefs.hpp │ ├── cf_tracker.hpp │ ├── circularbuffer.hpp │ ├── cv_ext.hpp │ ├── feature_channels.hpp │ ├── mat_consts.hpp │ ├── math_helper.cpp │ ├── math_helper.hpp │ ├── optional.hpp │ └── tracker_debug.hpp ├── dskcf │ ├── ColourFeatureChannelProcessor.cpp │ ├── ColourFeatureChannelProcessor.h │ ├── ConcatenateFeatureChannelProcessor.cpp │ ├── ConcatenateFeatureChannelProcessor.h │ ├── DepthFeatureChannelProcessor.cpp │ ├── DepthFeatureChannelProcessor.h │ ├── DepthSegmenter.cpp │ ├── DepthSegmenter.hpp │ ├── FeatureChannelProcessor.hpp │ ├── FeatureExtractor.cpp │ ├── FeatureExtractor.hpp │ ├── LinearFeatureChannelProcessor.cpp │ ├── LinearFeatureChannelProcessor.h │ ├── OcclusionHandler.cpp │ ├── OcclusionHandler.hpp │ ├── ScaleAnalyser.cpp │ ├── ScaleAnalyser.hpp │ ├── ScaleChangeObserver.hpp │ ├── dskcf_tracker.cpp │ ├── dskcf_tracker.hpp │ ├── dskcf_tracker_run.cpp │ └── dskcf_tracker_run.hpp └── kcf │ ├── DepthWeightKCFTracker.cpp │ ├── DepthWeightKCFTracker.h │ ├── GaussianKernel.cpp │ ├── GaussianKernel.hpp │ ├── HOGFeatureExtractor.cpp │ ├── HOGFeatureExtractor.hpp │ ├── Kernel.cpp │ ├── Kernel.hpp │ ├── kcf_debug.hpp │ ├── kcf_tracker.cpp │ └── kcf_tracker.hpp ├── doxygen_dummy.hpp ├── main ├── image_acquisition.cpp ├── image_acquisition.hpp └── main_dskcf.cpp └── mainpage.dox /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # License Agreement (3-clause BSD License) 2 | # Copyright (c) 2015, Klaus Haag, all rights reserved. 3 | # Third party copyrights and patents are property of their respective owners. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, 6 | # are permitted provided that the following conditions are met: 7 | # 8 | # * Redistributions of source code must retain the above copyright notice, 9 | # this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation 13 | # and/or other materials provided with the distribution. 14 | # 15 | # * Neither the names of the copyright holders nor the names of the contributors 16 | # may be used to endorse or promote products derived from this software 17 | # without specific prior written permission. 18 | # 19 | # This software is provided by the copyright holders and contributors "as is" and 20 | # any express or implied warranties, including, but not limited to, the implied 21 | # warranties of merchantability and fitness for a particular purpose are disclaimed. 22 | # In no event shall copyright holders or contributors be liable for any direct, 23 | # indirect, incidental, special, exemplary, or consequential damages 24 | # (including, but not limited to, procurement of substitute goods or services; 25 | # loss of use, data, or profits; or business interruption) however caused 26 | # and on any theory of liability, whether in contract, strict liability, 27 | # or tort (including negligence or otherwise) arising in any way out of 28 | # the use of this software, even if advised of the possibility of such damage. 29 | 30 | project(CfTracking) 31 | 32 | cmake_minimum_required(VERSION 2.8.7) 33 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") 34 | 35 | # add c++11 support 36 | if(CMAKE_COMPILER_IS_GNUCC) 37 | ADD_DEFINITIONS ( -std=c++11 -Wall ) 38 | endif(CMAKE_COMPILER_IS_GNUCC) 39 | 40 | # add OpenCV 41 | set(OPENCV_DIR_HINT "") 42 | 43 | if(WIN32) 44 | get_filename_component(OPENCV_DIR_PLATFORM $ENV{OPENCV_DIR} DIRECTORY) 45 | get_filename_component(OPENCV_DIR_HINT ${OPENCV_DIR_PLATFORM} DIRECTORY) 46 | endif(WIN32) 47 | 48 | set(OpenCV_STATIC OFF) 49 | find_package(OpenCV REQUIRED HINTS ${OPENCV_DIR_HINT}) 50 | find_package(TBB REQUIRED) 51 | 52 | # add 3rdparty source 53 | set(CF_TCLAP_DIR "src/3rdparty/tclap") 54 | set(CF_CV_EXT_DIR "src/3rdparty/cv_ext") 55 | set(CF_PIOTR_DIR "src/3rdparty/piotr") 56 | 57 | include_directories(${OpenCV_DIR}/include) 58 | include_directories(${TBB_INCLUDE_DIRS}) 59 | include_directories(${CF_TCLAP_DIR} 60 | ${CF_CV_EXT_DIR} 61 | ${CF_PIOTR_DIR} 62 | ${CF_PIOTR_DIR}/src 63 | src/main) 64 | 65 | include_directories(src/cf_libs/kcf 66 | src/cf_libs/dsst 67 | src/cf_libs/common 68 | src/cf_libs/dskcf) 69 | 70 | set(CF_PIOTR_SOURCES 71 | ${CF_PIOTR_DIR}/gradientMex.hpp 72 | ${CF_PIOTR_DIR}/src/gradientMex.cpp 73 | ${CF_PIOTR_DIR}/src/sse.hpp 74 | ${CF_PIOTR_DIR}/src/wrappers.hpp) 75 | 76 | set(CF_LIB_COMMON_SOURCES 77 | src/cf_libs/common/feature_channels.hpp 78 | src/cf_libs/common/mat_consts.hpp 79 | src/cf_libs/common/math_helper.hpp 80 | src/cf_libs/common/math_helper.cpp 81 | src/cf_libs/common/cf_tracker.hpp 82 | src/cf_libs/common/tracker_debug.hpp 83 | src/cf_libs/common/cv_ext.hpp 84 | src/cf_libs/common/optional.hpp 85 | src/cf_libs/common/Typedefs.hpp 86 | ${CF_CV_EXT_DIR}/shift.cpp 87 | ${CF_CV_EXT_DIR}/shift.hpp 88 | ${CF_CV_EXT_DIR}/math_spectrums.cpp 89 | ${CF_CV_EXT_DIR}/math_spectrums.hpp 90 | ${CF_CV_EXT_DIR}/psr.hpp 91 | ${CF_PIOTR_SOURCES}) 92 | 93 | set(CF_MAIN_SOURCES 94 | src/main/image_acquisition.hpp 95 | src/main/image_acquisition.cpp 96 | ${CF_CV_EXT_DIR}/init_box_selector.hpp 97 | ${CF_CV_EXT_DIR}/init_box_selector.cpp 98 | ${CF_CV_EXT_DIR}/tracker_run.hpp 99 | ${CF_CV_EXT_DIR}/tracker_run.cpp 100 | ${CF_TCLAP_DIR}/tclap/CmdLine.h) 101 | 102 | add_executable(DSKCFcpp 103 | src/main/main_dskcf.cpp 104 | src/cf_libs/kcf/kcf_debug.hpp 105 | src/cf_libs/kcf/kcf_tracker.hpp 106 | src/cf_libs/dskcf/dskcf_tracker_run.cpp 107 | src/cf_libs/dskcf/dskcf_tracker_run.hpp 108 | src/cf_libs/dskcf/dskcf_tracker.cpp 109 | src/cf_libs/dskcf/dskcf_tracker.hpp 110 | src/cf_libs/dskcf/DepthSegmenter.cpp 111 | src/cf_libs/dskcf/DepthSegmenter.hpp 112 | src/cf_libs/dskcf/FeatureExtractor.cpp 113 | src/cf_libs/dskcf/FeatureExtractor.hpp 114 | src/cf_libs/dskcf/FeatureChannelProcessor.hpp 115 | src/cf_libs/dskcf/OcclusionHandler.cpp 116 | src/cf_libs/dskcf/OcclusionHandler.hpp 117 | src/cf_libs/dskcf/ScaleAnalyser.cpp 118 | src/cf_libs/dskcf/ScaleAnalyser.hpp 119 | src/cf_libs/dskcf/ScaleChangeObserver.hpp 120 | src/cf_libs/kcf/GaussianKernel.cpp 121 | src/cf_libs/kcf/GaussianKernel.hpp 122 | src/cf_libs/kcf/HOGFeatureExtractor.cpp 123 | src/cf_libs/kcf/HOGFeatureExtractor.hpp 124 | src/cf_libs/kcf/Kernel.hpp 125 | src/cf_libs/kcf/Kernel.cpp 126 | src/cf_libs/kcf/kcf_tracker.hpp 127 | src/cf_libs/kcf/kcf_tracker.cpp 128 | src/cf_libs/dskcf/LinearFeatureChannelProcessor.cpp 129 | src/cf_libs/dskcf/LinearFeatureChannelProcessor.h 130 | src/cf_libs/dskcf/ConcatenateFeatureChannelProcessor.cpp 131 | src/cf_libs/dskcf/ConcatenateFeatureChannelProcessor.h 132 | src/cf_libs/dskcf/ColourFeatureChannelProcessor.cpp 133 | src/cf_libs/dskcf/ColourFeatureChannelProcessor.h 134 | src/cf_libs/dskcf/DepthFeatureChannelProcessor.cpp 135 | src/cf_libs/dskcf/DepthFeatureChannelProcessor.h 136 | src/cf_libs/common/KalmanFilter2D.cpp 137 | src/cf_libs/common/KalmanFilter2D.h 138 | src/cf_libs/common/circularbuffer.hpp 139 | src/cf_libs/common/KalmanFilter1D.cpp 140 | src/cf_libs/common/KalmanFilter1D.h 141 | src/cf_libs/common/DepthHistogram.cpp 142 | src/cf_libs/common/DepthHistogram.h 143 | src/cf_libs/kcf/DepthWeightKCFTracker.cpp 144 | src/cf_libs/kcf/DepthWeightKCFTracker.h 145 | ${CF_MAIN_SOURCES} 146 | ${CF_LIB_COMMON_SOURCES}) 147 | 148 | 149 | #set_property(TARGET ${TBB_LIBRARIES} PROPERTY DBG_POSTFIX _debug) 150 | #message("BUILD TYPE = '${CMAKE_BUILD_TYPE}'") 151 | #target_link_libraries( DSKCFcpp ${OpenCV_LIBS} optimized ${TBB_tbb_LIBRARY_RELEASE} debug ${TBB_tbb_LIBRARY_RELEASE}) 152 | #target_link_libraries( DSKCFcpp ${OpenCV_LIBS} optimized ${TBB_tbb_LIBRARY_RELEASE}) 153 | #target_link_libraries( DSKCFcpp ${OpenCV_LIBS} debug ${TBB_tbb_LIBRARY_RELEASE}) 154 | 155 | set(TBB_LIBRARIES optimized ${TBB_LIBRARY} ${TBB_tbb_LIBRARY_RELEASE} debug ${TBB_tbb_LIBRARY_DEBUG}) 156 | message("FINALLL TBB_LIBRARIES = '${TBB_LIBRARIES}'") 157 | target_link_libraries(DSKCFcpp ${OpenCV_LIBS} ${TBB_LIBRARIES}) 158 | #IF(CMAKE_BUILD_TYPE MATCHES Release) 159 | # message("RELEASE") 160 | # target_link_libraries(DSKCFcpp ${OpenCV_LIBS} ${TBB_tbb_LIBRARY_RELEASE}) 161 | #ELSE() 162 | # message("DEBUG") 163 | # target_link_libraries(DSKCFcpp ${OpenCV_LIBS} ${TBB_tbb_LIBRARY_DEBUG}) 164 | #ENDIF(CMAKE_BUILD_TYPE MATCHES Release) 165 | 166 | -------------------------------------------------------------------------------- /exampleDSKCF.bat: -------------------------------------------------------------------------------- 1 | ::Example on how to use the compiled C++ dskcf (bat script for windows platform) 2 | ::BE SURE YOU DEFINE CORRECTLY THE NEXT VARIABLES FOR THIS BAT SCRIPT 3 | 4 | ::Set top directory and a string.... 5 | set topResultsDir=C:\myDevelopments\JRTIP_DSKCF_releaseCPP\resDir 6 | set topResultsDirSTRING=C:/myDevelopments/JRTIP_DSKCF_releaseCPP/resDir 7 | ::Set data directory 8 | set dataDirectory=C:/myDevelopments/JRTIP_DSKCF_releaseCPP/dataPrincetonValidation 9 | ::Set compiled file 10 | set myDSKCFexe=C:\myDevelopments\ds-kcf-cJournalVersion\compiledDSKCF_VS12\Release\DSKCFcpp.exe 11 | ::Set 12 | 13 | 14 | 15 | ::generate directories for all the sequences in the validation set 16 | ::echo %topResultsDir% 17 | ::pause 18 | mkdir %topResultsDir%\bear_front 19 | mkdir %topResultsDir%\child_no1 20 | mkdir %topResultsDir%\zcup_move_1 21 | mkdir %topResultsDir%\face_occ5 22 | mkdir %topResultsDir%\new_ex_occ4 23 | 24 | :: NOW USE DSKCF, HERE SAVING ALSO IMAGING ON THE DISK AND DISPLAYING AS WELL.....THIS MAY SLOW DOWN A BIT THE TRACKER..... 25 | 26 | %myDSKCFexe% -b 178,162,121,156 -d -e %topResultsDirSTRING%/bear_front/ -o %topResultsDirSTRING%/bear_front/bear_front.txt -s %dataDirectory%/bear_front/rgb -i /%%.06d.png --depth_sequence %dataDirectory%/bear_front/depth --depth_image_name_expansion /%%.06d.png 27 | %myDSKCFexe% -b 238,186,58,156 -d -e %topResultsDirSTRING%/child_no1/ -o %topResultsDirSTRING%/child_no1/child_no1.txt -s %dataDirectory%/child_no1/rgb -i /%%.06d.png --depth_sequence %dataDirectory%/child_no1/depth --depth_image_name_expansion /%%.06d.png 28 | %myDSKCFexe% -b 236,295,73,139 -d -e %topResultsDirSTRING%/zcup_move_1/ -o %topResultsDirSTRING%/zcup_move_1/zcup_move_1.txt -s %dataDirectory%/zcup_move_1/rgb -i /%%.06d.png --depth_sequence %dataDirectory%/zcup_move_1/depth --depth_image_name_expansion /%%.06d.png 29 | %myDSKCFexe% -b 242,186,79,101 -d -e %topResultsDirSTRING%/face_occ5/ -o %topResultsDirSTRING%/face_occ5/face_occ5.txt -s %dataDirectory%/face_occ5/rgb -i /%%.06d.png --depth_sequence %dataDirectory%/face_occ5/depth --depth_image_name_expansion /%%.06d.png 30 | %myDSKCFexe% -b 109,214,84,266 -d -e %topResultsDirSTRING%/new_ex_occ4/ -o %topResultsDirSTRING%/new_ex_occ4/new_ex_occ4.txt -s %dataDirectory%/new_ex_occ4/rgb -i /%%.06d.png --depth_sequence %dataDirectory%/new_ex_occ4/depth --depth_image_name_expansion /%%.06d.png 31 | 32 | 33 | ::pause 34 | 35 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/init_box_selector.cpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // License Agreement 10 | // For Open Source Computer Vision Library 11 | // (3-clause BSD License) 12 | // 13 | // Copyright (C) 2000-2015, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. 16 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 17 | // Copyright (C) 2015, OpenCV Foundation, all rights reserved. 18 | // Copyright (C) 2015, Itseez Inc., all rights reserved. 19 | // Third party copyrights are property of their respective owners. 20 | // 21 | // Redistribution and use in source and binary forms, with or without modification, 22 | // are permitted provided that the following conditions are met: 23 | // 24 | // * Redistributions of source code must retain the above copyright notice, 25 | // this list of conditions and the following disclaimer. 26 | // 27 | // * Redistributions in binary form must reproduce the above copyright notice, 28 | // this list of conditions and the following disclaimer in the documentation 29 | // and/or other materials provided with the distribution. 30 | // 31 | // * Neither the names of the copyright holders nor the names of the contributors 32 | // may be used to endorse or promote products derived from this software 33 | // without specific prior written permission. 34 | // 35 | // This software is provided by the copyright holders and contributors "as is" and 36 | // any express or implied warranties, including, but not limited to, the implied 37 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 38 | // In no event shall copyright holders or contributors be liable for any direct, 39 | // indirect, incidental, special, exemplary, or consequential damages 40 | // (including, but not limited to, procurement of substitute goods or services; 41 | // loss of use, data, or profits; or business interruption) however caused 42 | // and on any theory of liability, whether in contract, strict liability, 43 | // or tort (including negligence or otherwise) arising in any way out of 44 | // the use of this software, even if advised of the possibility of such damage. 45 | //M*/ 46 | 47 | /* 48 | // Original file: https://github.com/Itseez/opencv_contrib/blob/292b8fa6aa403fb7ad6d2afadf4484e39d8ca2f1/modules/tracking/samples/tracker.cpp 49 | // + Author: Klaus Haag 50 | // * Refactor file: Move target selection to separate class/file 51 | */ 52 | 53 | #include "init_box_selector.hpp" 54 | 55 | void InitBoxSelector::onMouse(int event, int x, int y, int, void*) 56 | { 57 | if (!selectObject) 58 | { 59 | switch (event) 60 | { 61 | case cv::EVENT_LBUTTONDOWN: 62 | //set origin of the bounding box 63 | startSelection = true; 64 | initBox.x = x; 65 | initBox.y = y; 66 | break; 67 | case cv::EVENT_LBUTTONUP: 68 | //set width and height of the bounding box 69 | initBox.width = std::abs(x - initBox.x); 70 | initBox.height = std::abs(y - initBox.y); 71 | startSelection = false; 72 | selectObject = true; 73 | break; 74 | case cv::EVENT_MOUSEMOVE: 75 | if (startSelection && !selectObject) 76 | { 77 | //draw the bounding box 78 | cv::Mat currentFrame; 79 | image.copyTo(currentFrame); 80 | cv::rectangle(currentFrame, cv::Point((int)initBox.x, (int)initBox.y), cv::Point(x, y), cv::Scalar(255, 0, 0), 2, 1); 81 | cv::imshow(windowTitle.c_str(), currentFrame); 82 | } 83 | break; 84 | } 85 | } 86 | } 87 | 88 | bool InitBoxSelector::selectBox(cv::Mat& frame, cv::Rect& initBox) 89 | { 90 | frame.copyTo(image); 91 | startSelection = false; 92 | selectObject = false; 93 | cv::imshow(windowTitle.c_str(), image); 94 | cv::setMouseCallback(windowTitle.c_str(), onMouse, 0); 95 | 96 | while (selectObject == false) 97 | { 98 | char c = (char)cv::waitKey(10); 99 | 100 | if (c == 27) 101 | return false; 102 | } 103 | 104 | initBox = InitBoxSelector::initBox; 105 | cv::setMouseCallback(windowTitle.c_str(), 0, 0); 106 | cv::destroyWindow(windowTitle.c_str()); 107 | return true; 108 | } 109 | 110 | const std::string InitBoxSelector::windowTitle = "Draw Bounding Box"; 111 | bool InitBoxSelector::startSelection = false; 112 | bool InitBoxSelector::selectObject = false; 113 | cv::Mat InitBoxSelector::image; 114 | cv::Rect InitBoxSelector::initBox; 115 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/init_box_selector.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // License Agreement 10 | // For Open Source Computer Vision Library 11 | // (3-clause BSD License) 12 | // 13 | // Copyright (C) 2000-2015, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. 16 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 17 | // Copyright (C) 2015, OpenCV Foundation, all rights reserved. 18 | // Copyright (C) 2015, Itseez Inc., all rights reserved. 19 | // Third party copyrights are property of their respective owners. 20 | // 21 | // Redistribution and use in source and binary forms, with or without modification, 22 | // are permitted provided that the following conditions are met: 23 | // 24 | // * Redistributions of source code must retain the above copyright notice, 25 | // this list of conditions and the following disclaimer. 26 | // 27 | // * Redistributions in binary form must reproduce the above copyright notice, 28 | // this list of conditions and the following disclaimer in the documentation 29 | // and/or other materials provided with the distribution. 30 | // 31 | // * Neither the names of the copyright holders nor the names of the contributors 32 | // may be used to endorse or promote products derived from this software 33 | // without specific prior written permission. 34 | // 35 | // This software is provided by the copyright holders and contributors "as is" and 36 | // any express or implied warranties, including, but not limited to, the implied 37 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 38 | // In no event shall copyright holders or contributors be liable for any direct, 39 | // indirect, incidental, special, exemplary, or consequential damages 40 | // (including, but not limited to, procurement of substitute goods or services; 41 | // loss of use, data, or profits; or business interruption) however caused 42 | // and on any theory of liability, whether in contract, strict liability, 43 | // or tort (including negligence or otherwise) arising in any way out of 44 | // the use of this software, even if advised of the possibility of such damage. 45 | //M*/ 46 | 47 | /* 48 | // Original file: https://github.com/Itseez/opencv_contrib/blob/292b8fa6aa403fb7ad6d2afadf4484e39d8ca2f1/modules/tracking/samples/tracker.cpp 49 | // + Author: Klaus Haag 50 | // * Refactor file: Move target selection to separate class/file 51 | */ 52 | 53 | #ifndef INIT_BOX_SELECTOR_HPP_ 54 | #define INIT_BOX_SELECTOR_HPP_ 55 | 56 | #include "opencv2/highgui/highgui.hpp" 57 | #include "opencv2/opencv.hpp" 58 | 59 | class InitBoxSelector 60 | { 61 | public: 62 | static bool selectBox(cv::Mat& frame, cv::Rect& initBox); 63 | 64 | private: 65 | static void onMouse(int event, int x, int y, int, void*); 66 | static bool startSelection; 67 | static bool selectObject; 68 | static cv::Rect initBox; 69 | static cv::Mat image; 70 | static const std::string windowTitle; 71 | }; 72 | 73 | #endif /* INIT_BOX_SELECTOR_H_ */ 74 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/math_spectrums.cpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // Intel License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000, Intel Corporation, all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of Intel Corporation may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the Intel Corporation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | //M*/ 40 | 41 | // Author: Intel 42 | // Original file: https://github.com/Itseez/opencv/blob/46a6f70d88bf816525a3ded80e69237d1960152f/modules/core/src/dxt.cpp 43 | // + Klaus Haag (converted mulSpectrums to divSpectrums) 44 | 45 | // TODO: 46 | // * vectorize 47 | // * check precision errors for float (casting to double 48 | // may not be necessary) 49 | // * check inconsistency for float for real parts only 50 | // (not casted to double) 51 | // * needs more testing (conjB == true) is untested 52 | 53 | #include "math_spectrums.hpp" 54 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/math_spectrums.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // Intel License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000, Intel Corporation, all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of Intel Corporation may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the Intel Corporation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | //M*/ 40 | 41 | // Author: Intel 42 | // Original file: https://github.com/Itseez/opencv/blob/46a6f70d88bf816525a3ded80e69237d1960152f/modules/core/src/dxt.cpp 43 | // + Klaus Haag: 44 | // * Converted mulSpectrums to divSpectrums 45 | // * Converted mulSpectrums to addRealToSpectrum 46 | // * Converted mulSpectrums to sumRealOfSpectrum 47 | // 48 | 49 | #ifndef MATH_SPECTRUMS_HPP_ 50 | #define MATH_SPECTRUMS_HPP_ 51 | 52 | #include 53 | 54 | template 55 | cv::Mat addRealToSpectrum(T summand, cv::InputArray _numeratorA, int flags = 0) 56 | { 57 | cv::Mat srcA = _numeratorA.getMat(); 58 | int cn = srcA.channels(), type = srcA.type(); 59 | int rows = srcA.rows, cols = srcA.cols; 60 | int j; 61 | 62 | CV_Assert(type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2); 63 | 64 | cv::Mat dst; 65 | dst.create(srcA.rows, srcA.cols, type); 66 | 67 | bool is_1d = (flags & cv::DFT_ROWS) || (rows == 1 || (cols == 1 && 68 | srcA.isContinuous() && dst.isContinuous())); 69 | 70 | if (is_1d && !(flags & cv::DFT_ROWS)) 71 | cols = cols + rows - 1, rows = 1; 72 | 73 | int ncols = cols*cn; 74 | int j0 = cn == 1; 75 | int j1 = ncols - (cols % 2 == 0 && cn == 1); 76 | 77 | const T* dataA = srcA.ptr(); 78 | T* dataC = dst.ptr(); 79 | 80 | size_t stepA = srcA.step / sizeof(dataA[0]); 81 | size_t stepC = dst.step / sizeof(dataC[0]); 82 | 83 | if (!is_1d && cn == 1) 84 | { 85 | for (int k = 0; k < ((cols % 2) ? 1 : 2); k++) 86 | { 87 | if (k == 1) 88 | dataA += cols - 1, dataC += cols - 1; 89 | 90 | dataC[0] = dataA[0] + summand; 91 | 92 | if (rows % 2 == 0) 93 | dataC[(rows - 1)*stepC] = dataA[(rows - 1)*stepA] + summand; 94 | 95 | for (j = 1; j <= rows - 2; j += 2) 96 | { 97 | dataC[j*stepC] = dataA[j*stepA] + summand; 98 | dataC[(j + 1)*stepC] = dataA[(j + 1)*stepA]; 99 | } 100 | 101 | if (k == 1) 102 | dataA -= cols - 1, dataC -= cols - 1; 103 | } 104 | } 105 | 106 | for (; rows--; dataA += stepA, dataC += stepC) 107 | { 108 | if (is_1d && cn == 1) 109 | { 110 | dataC[0] = dataA[0] + summand; 111 | 112 | if (cols % 2 == 0) 113 | dataC[j1] = dataA[j1] + summand; 114 | } 115 | 116 | for (j = j0; j < j1; j += 2) 117 | { 118 | dataC[j] = dataA[j] + summand; 119 | dataC[j + 1] = dataA[j + 1]; 120 | } 121 | } 122 | 123 | return dst; 124 | } 125 | 126 | template 127 | T sumRealOfSpectrum(cv::InputArray _numeratorA, int flags = 0) 128 | { 129 | cv::Mat srcA = _numeratorA.getMat(); 130 | T sum_ = 0; 131 | int cn = srcA.channels(), type = srcA.type(); 132 | int rows = srcA.rows, cols = srcA.cols; 133 | int j; 134 | CV_Assert(type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2); 135 | 136 | bool is_1d = (flags & cv::DFT_ROWS) || (rows == 1 || (cols == 1 && 137 | srcA.isContinuous())); 138 | 139 | if (is_1d && !(flags & cv::DFT_ROWS)) 140 | cols = cols + rows - 1, rows = 1; 141 | 142 | T multiplier = 1; 143 | 144 | if (cn == 1) 145 | multiplier = 2; 146 | 147 | int ncols = cols*cn; 148 | int j0 = cn == 1; 149 | int j1 = ncols - (cols % 2 == 0 && cn == 1); 150 | 151 | const T* dataA = srcA.ptr(); 152 | size_t stepA = srcA.step / sizeof(dataA[0]); 153 | 154 | if (!is_1d && cn == 1) 155 | { 156 | for (int k = 0; k < ((cols % 2) ? 1 : 2); k++) 157 | { 158 | if (k == 1) 159 | dataA += cols - 1; 160 | 161 | sum_ += dataA[0]; 162 | 163 | if (rows % 2 == 0) 164 | sum_ += dataA[(rows - 1)*stepA]; 165 | 166 | for (j = 1; j <= rows - 2; j += 2) 167 | { 168 | sum_ += multiplier * dataA[j*stepA]; 169 | } 170 | 171 | if (k == 1) 172 | dataA -= cols - 1; 173 | } 174 | } 175 | 176 | for (; rows--; dataA += stepA) 177 | { 178 | if (is_1d && cn == 1) 179 | { 180 | sum_ += dataA[0]; 181 | 182 | if (cols % 2 == 0) 183 | sum_ += dataA[j1]; 184 | } 185 | 186 | for (j = j0; j < j1; j += 2) 187 | { 188 | sum_ += multiplier * dataA[j]; 189 | } 190 | } 191 | 192 | return sum_; 193 | } 194 | 195 | #endif 196 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/psr.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcamplan/DSKCF_CPP/e80be58ea8820b1325b443d7c8fc4c4f7e551e62/src/3rdparty/cv_ext/psr.hpp -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/shift.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright (c) 2012, Willow Garage, Inc. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * * Neither the name of Willow Garage, Inc. nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * File: shift.cpp 35 | * Author: Hilton Bristow 36 | * Created: Aug 23, 2012 37 | * + Author: Klaus Haag (split into header/source file) 38 | */ 39 | 40 | //#ifndef SHIFT_HPP_ 41 | //#define SHIFT_HPP_ 42 | 43 | #include 44 | #include 45 | #include 46 | #include "shift.hpp" 47 | 48 | /*! @brief shift the values in a matrix by an (x,y) offset 49 | * 50 | * Given a matrix and an integer (x,y) offset, the matrix will be shifted 51 | * such that: 52 | * 53 | * src(a,b) ---> dst(a+y,b+x) 54 | * 55 | * In the case of a non-integer offset, (e.g. cv::Point2f(-2.1, 3.7)), 56 | * the shift will be calculated with subpixel precision using bilinear 57 | * interpolation. 58 | * 59 | * All valid OpenCV datatypes are supported. If the source datatype is 60 | * fixed-point, and a non-integer offset is supplied, the output will 61 | * be a floating point matrix to preserve subpixel accuracy. 62 | * 63 | * All border types are supported. If no border type is supplied, the 64 | * function defaults to BORDER_CONSTANT with 0-padding. 65 | * 66 | * The function supports in-place operation. 67 | * 68 | * Some common examples are provided following: 69 | * \code 70 | * // read an image from file 71 | * Mat mat = imread(filename); 72 | * Mat dst; 73 | * 74 | * // Perform Matlab-esque 'circshift' in-place 75 | * shift(mat, mat, Point(5, 5), BORDER_WRAP); 76 | * 77 | * // Perform shift with subpixel accuracy, padding the missing pixels with 1s 78 | * // NOTE: if mat is of type CV_8U, then it will be converted to type CV_32F 79 | * shift(mat, mat, Point2f(-13.7, 3.28), BORDER_CONSTANT, 1); 80 | * 81 | * // Perform subpixel shift, preserving the boundary values 82 | * shift(mat, dst, Point2f(0.093, 0.125), BORDER_REPLICATE); 83 | * 84 | * // Perform a vanilla shift, integer offset, very fast 85 | * shift(mat, dst, Point(2, 2)); 86 | * \endcode 87 | * 88 | * @param src the source matrix 89 | * @param dst the destination matrix, can be the same as source 90 | * @param delta the amount to shift the matrix in (x,y) coordinates. Can be 91 | * integer of floating point precision 92 | * @param fill the method used to fill the null entries, defaults to BORDER_CONSTANT 93 | * @param value the value of the null entries if the fill type is BORDER_CONSTANT 94 | */ 95 | 96 | void shift(const cv::Mat& src, cv::Mat& dst, cv::Point2f delta, int fill, cv::Scalar value) { 97 | // error checking 98 | CV_Assert(fabs(delta.x) < src.cols && fabs(delta.y) < src.rows); 99 | 100 | // split the shift into integer and subpixel components 101 | cv::Point2i deltai(static_cast(ceil(delta.x)), static_cast(ceil(delta.y))); 102 | cv::Point2f deltasub(fabs(delta.x - deltai.x), fabs(delta.y - deltai.y)); 103 | 104 | // INTEGER SHIFT 105 | // first create a border around the parts of the Mat that will be exposed 106 | int t = 0, b = 0, l = 0, r = 0; 107 | if (deltai.x > 0) l = deltai.x; 108 | if (deltai.x < 0) r = -deltai.x; 109 | if (deltai.y > 0) t = deltai.y; 110 | if (deltai.y < 0) b = -deltai.y; 111 | cv::Mat padded; 112 | cv::copyMakeBorder(src, padded, t, b, l, r, fill, value); 113 | 114 | // SUBPIXEL SHIFT 115 | float eps = std::numeric_limits::epsilon(); 116 | if (deltasub.x > eps || deltasub.y > eps) { 117 | switch (src.depth()) { 118 | case CV_32F: 119 | { 120 | cv::Matx dx(1 - deltasub.x, deltasub.x); 121 | cv::Matx dy(1 - deltasub.y, deltasub.y); 122 | sepFilter2D(padded, padded, -1, dx, dy, cv::Point(0, 0), 0, cv::BORDER_CONSTANT); 123 | break; 124 | } 125 | case CV_64F: 126 | { 127 | cv::Matx dx(1 - deltasub.x, deltasub.x); 128 | cv::Matx dy(1 - deltasub.y, deltasub.y); 129 | sepFilter2D(padded, padded, -1, dx, dy, cv::Point(0, 0), 0, cv::BORDER_CONSTANT); 130 | break; 131 | } 132 | default: 133 | { 134 | cv::Matx dx(1 - deltasub.x, deltasub.x); 135 | cv::Matx dy(1 - deltasub.y, deltasub.y); 136 | padded.convertTo(padded, CV_32F); 137 | sepFilter2D(padded, padded, CV_32F, dx, dy, cv::Point(0, 0), 0, cv::BORDER_CONSTANT); 138 | break; 139 | } 140 | } 141 | } 142 | 143 | // construct the region of interest around the new matrix 144 | cv::Rect roi = cv::Rect(std::max(-deltai.x, 0), std::max(-deltai.y, 0), 0, 0) + src.size(); 145 | dst = padded(roi); 146 | } 147 | 148 | //#endif /* SHIFT_HPP_ */ 149 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/shift.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright (c) 2012, Willow Garage, Inc. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * * Neither the name of Willow Garage, Inc. nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * File: shift.hpp 35 | * Author: Hilton Bristow 36 | * Created: Aug 23, 2012 37 | * + Author: Klaus Haag (split into header/source file) 38 | */ 39 | 40 | #ifndef SHIFT_HPP_ 41 | #define SHIFT_HPP_ 42 | 43 | #include 44 | 45 | void shift(const cv::Mat& src, cv::Mat& dst, cv::Point2f delta, 46 | int fill = cv::BORDER_CONSTANT, 47 | cv::Scalar value = cv::Scalar(0, 0, 0, 0)); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/3rdparty/cv_ext/tracker_run.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // License Agreement 10 | // For Open Source Computer Vision Library 11 | // (3-clause BSD License) 12 | // 13 | // Copyright (C) 2000-2015, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. 16 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 17 | // Copyright (C) 2015, OpenCV Foundation, all rights reserved. 18 | // Copyright (C) 2015, Itseez Inc., all rights reserved. 19 | // Third party copyrights are property of their respective owners. 20 | // 21 | // Redistribution and use in source and binary forms, with or without modification, 22 | // are permitted provided that the following conditions are met: 23 | // 24 | // * Redistributions of source code must retain the above copyright notice, 25 | // this list of conditions and the following disclaimer. 26 | // 27 | // * Redistributions in binary form must reproduce the above copyright notice, 28 | // this list of conditions and the following disclaimer in the documentation 29 | // and/or other materials provided with the distribution. 30 | // 31 | // * Neither the names of the copyright holders nor the names of the contributors 32 | // may be used to endorse or promote products derived from this software 33 | // without specific prior written permission. 34 | // 35 | // This software is provided by the copyright holders and contributors "as is" and 36 | // any express or implied warranties, including, but not limited to, the implied 37 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 38 | // In no event shall copyright holders or contributors be liable for any direct, 39 | // indirect, incidental, special, exemplary, or consequential damages 40 | // (including, but not limited to, procurement of substitute goods or services; 41 | // loss of use, data, or profits; or business interruption) however caused 42 | // and on any theory of liability, whether in contract, strict liability, 43 | // or tort (including negligence or otherwise) arising in any way out of 44 | // the use of this software, even if advised of the possibility of such damage. 45 | //M*/ 46 | 47 | /* 48 | // Original file: https://github.com/Itseez/opencv_contrib/blob/292b8fa6aa403fb7ad6d2afadf4484e39d8ca2f1/modules/tracking/samples/tracker.cpp 49 | // Modified by Klaus Haag file: https://github.com/klahaag/cf_tracking/blob/master/src/3rdparty/cv_ext/tracker_run.cpp 50 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 51 | // * Add a variety of additional features to visualize tracker, save results according to RGBD dataset (see details below) and to save processing 52 | // time as in the DS-KCF paper 53 | // Princeton RGBD data: Shuran Song and Jianxiong Xiao. Tracking Revisited using RGBD Camera: Baseline and Benchmark. 2013. 54 | */ 55 | 56 | #ifndef TRACKER_RUN_HPP_ 57 | #define TRACKER_RUN_HPP_ 58 | 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include "cf_tracker.hpp" 64 | #include "tracker_debug.hpp" 65 | #include "image_acquisition.hpp" 66 | 67 | struct Parameters{ 68 | std::string sequencePathRGB; 69 | std::string sequencePathDepth; 70 | std::string outputFilePath; 71 | std::string imgExportPath; 72 | std::string expansionRGB; 73 | std::string expansionDepth; 74 | cv::Rect initBb; 75 | int deviceRGB; 76 | int deviceDepth; 77 | int startFrame; 78 | bool showOutput; 79 | bool paused; 80 | bool repeat; 81 | bool isMockSequenceRGB; 82 | bool isMockSequenceDepth; 83 | bool useDepth; 84 | }; 85 | 86 | class TrackerRun 87 | { 88 | public: 89 | TrackerRun(std::string windowTitle); 90 | virtual ~TrackerRun(); 91 | bool start(int argc, const char** argv); 92 | void setTrackerDebug(TrackerDebug* debug); 93 | 94 | private: 95 | Parameters parseCmdArgs(int argc, const char** argv); 96 | bool init(); 97 | bool run(); 98 | bool update(); 99 | void printResults(const cv::Rect_& boundingBox, bool isConfident, bool isTracked); 100 | void printResultsTiming(const std::vector &singleFrameTiming); 101 | 102 | protected: 103 | virtual CfTracker* parseTrackerParas(TCLAP::CmdLine& cmd, int argc, const char** argv) = 0; 104 | private: 105 | std::array< cv::Mat, 2 > _image; 106 | CfTracker* _tracker; 107 | std::string _windowTitle; 108 | Parameters _paras; 109 | cv::Rect_ _boundingBox; 110 | std::array< ImageAcquisition, 2 > _cap; 111 | std::ofstream _resultsFile,_resultsFileTime; 112 | TCLAP::CmdLine _cmd; 113 | TrackerDebug* _debug; 114 | int _frameIdx; 115 | bool _isPaused; 116 | bool _isStep; 117 | bool _exit; 118 | bool _hasInitBox; 119 | bool _isTrackerInitialzed; 120 | bool _targetOnFrame; 121 | bool _updateAtPos; 122 | int _imageIndex; 123 | std::vector< double > frameTime; 124 | }; 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /src/3rdparty/piotr/README.md: -------------------------------------------------------------------------------- 1 | This module provides the FHOG implementation from 2 | http://vision.ucsd.edu/~pdollar/toolbox/doc/ 3 | with an OpenCV integration. 4 | -------------------------------------------------------------------------------- /src/3rdparty/piotr/src/sse.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Piotr Dollar 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those 26 | of the authors and should not be interpreted as representing official policies, 27 | either expressed or implied, of the FreeBSD Project. 28 | */ 29 | 30 | /******************************************************************************* 31 | * Piotr's Computer Vision Matlab Toolbox Version 3.23 32 | * Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 33 | * Licensed under the Simplified BSD License [see above] 34 | * Project page: http://vision.ucsd.edu/~pdollar/toolbox/doc/ 35 | * Original file: https://github.com/pdollar/toolbox/blob/612f9a0451a6abbe2a64768c9e6654692929102e/channels/private/sse.hpp 36 | 37 | + author: Klaus Haag: Move external license into this source file 38 | + author: Luka Cehovin: Fix equal results on AMD and Intel CPUs 39 | *******************************************************************************/ 40 | #ifndef _SSE_HPP_ 41 | #define _SSE_HPP_ 42 | #include // SSE2:, SSE3:, SSE4: 43 | 44 | #define RETf inline __m128 45 | #define RETi inline __m128i 46 | 47 | // set, load and store values 48 | RETf SET(const float &x) { return _mm_set1_ps(x); } 49 | RETf SET(float x, float y, float z, float w) { return _mm_set_ps(x, y, z, w); } 50 | RETi SET(const int &x) { return _mm_set1_epi32(x); } 51 | RETf LD(const float &x) { return _mm_load_ps(&x); } 52 | RETf LDu(const float &x) { return _mm_loadu_ps(&x); } 53 | RETf STR(float &x, const __m128 y) { _mm_store_ps(&x, y); return y; } 54 | RETf STR1(float &x, const __m128 y) { _mm_store_ss(&x, y); return y; } 55 | RETf STRu(float &x, const __m128 y) { _mm_storeu_ps(&x, y); return y; } 56 | RETf STR(float &x, const float y) { return STR(x, SET(y)); } 57 | 58 | // arithmetic operators 59 | RETi ADD(const __m128i x, const __m128i y) { return _mm_add_epi32(x, y); } 60 | RETf ADD(const __m128 x, const __m128 y) { return _mm_add_ps(x, y); } 61 | RETf ADD(const __m128 x, const __m128 y, const __m128 z) { 62 | return ADD(ADD(x, y), z); 63 | } 64 | RETf ADD(const __m128 a, const __m128 b, const __m128 c, const __m128 &d) { 65 | return ADD(ADD(ADD(a, b), c), d); 66 | } 67 | RETf SUB(const __m128 x, const __m128 y) { return _mm_sub_ps(x, y); } 68 | RETf MUL(const __m128 x, const __m128 y) { return _mm_mul_ps(x, y); } 69 | RETf MUL(const __m128 x, const float y) { return MUL(x, SET(y)); } 70 | RETf MUL(const float x, const __m128 y) { return MUL(SET(x), y); } 71 | RETf INC(__m128 &x, const __m128 y) { return x = ADD(x, y); } 72 | RETf INC(float &x, const __m128 y) { __m128 t = ADD(LD(x), y); return STR(x, t); } 73 | RETf DEC(__m128 &x, const __m128 y) { return x = SUB(x, y); } 74 | RETf DEC(float &x, const __m128 y) { __m128 t = SUB(LD(x), y); return STR(x, t); } 75 | RETf MIN_SSE(const __m128 x, const __m128 y) { return _mm_min_ps(x, y); } 76 | RETf RCP(const __m128 x) { return _mm_rcp_ps(x); } 77 | RETf RCPSQRT(const __m128 x) { return _mm_rsqrt_ps(x); } 78 | 79 | RETf SQRT(const __m128 x) { return _mm_sqrt_ps(x); } 80 | RETf MAX_SSE(const __m128 x, const __m128 y) { return _mm_max_ps(x, y); } 81 | RETf DIV(const __m128 x, const __m128 y) { return _mm_div_ps(x, y); } 82 | RETf DIV(const __m128 x, const float y) { return DIV(x, SET(y)); } 83 | RETf DIV(const float x, const __m128 y) { return DIV(SET(x), y); } 84 | 85 | // logical operators 86 | RETf AND(const __m128 x, const __m128 y) { return _mm_and_ps(x, y); } 87 | RETi AND(const __m128i x, const __m128i y) { return _mm_and_si128(x, y); } 88 | RETf ANDNOT(const __m128 x, const __m128 y) { return _mm_andnot_ps(x, y); } 89 | RETf OR(const __m128 x, const __m128 y) { return _mm_or_ps(x, y); } 90 | RETf XOR(const __m128 x, const __m128 y) { return _mm_xor_ps(x, y); } 91 | 92 | // comparison operators 93 | RETf CMPGT(const __m128 x, const __m128 y) { return _mm_cmpgt_ps(x, y); } 94 | RETf CMPLT(const __m128 x, const __m128 y) { return _mm_cmplt_ps(x, y); } 95 | RETi CMPGT(const __m128i x, const __m128i y) { return _mm_cmpgt_epi32(x, y); } 96 | RETi CMPLT(const __m128i x, const __m128i y) { return _mm_cmplt_epi32(x, y); } 97 | 98 | // conversion operators 99 | RETf CVT(const __m128i x) { return _mm_cvtepi32_ps(x); } 100 | RETi CVT(const __m128 x) { return _mm_cvttps_epi32(x); } 101 | 102 | #undef RETf 103 | #undef RETi 104 | #endif 105 | -------------------------------------------------------------------------------- /src/3rdparty/piotr/src/wrappers.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Piotr Dollar 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those 26 | of the authors and should not be interpreted as representing official policies, 27 | either expressed or implied, of the FreeBSD Project. 28 | */ 29 | 30 | /******************************************************************************* 31 | * Piotr's Computer Vision Matlab Toolbox Version 3.00 32 | * Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 33 | * Licensed under the Simplified BSD License [see above] 34 | * Project page: http://vision.ucsd.edu/~pdollar/toolbox/doc/ 35 | * Original file: https://github.com/pdollar/toolbox/blob/612f9a0451a6abbe2a64768c9e6654692929102e/channels/private/wrappers.hpp 36 | 37 | + author: Klaus Haag: Move external license into this source file 38 | *******************************************************************************/ 39 | #ifndef WRAPPERS_HPP_ 40 | #define WRAPPERS_HPP_ 41 | 42 | #ifdef MATLAB_MEX_FILE 43 | 44 | // wrapper functions if compiling from Matlab 45 | #include "mex.h" 46 | inline void wrError(const char *errormsg) { mexErrMsgTxt(errormsg); } 47 | inline void* wrCalloc(size_t num, size_t size) { return mxCalloc(num, size); } 48 | inline void* wrMalloc(size_t size) { return mxMalloc(size); } 49 | inline void wrFree(void * ptr) { mxFree(ptr); } 50 | 51 | #else 52 | 53 | #include 54 | // wrapper functions if compiling from C/C++ 55 | inline void wrError(const char *errormsg) { throw errormsg; } 56 | inline void* wrCalloc(size_t num, size_t size) { return calloc(num, size); } 57 | inline void* wrMalloc(size_t size) { return malloc(size); } 58 | inline void wrFree(void * ptr) { free(ptr); } 59 | 60 | #endif 61 | 62 | // platform independent aligned memory allocation (see also alFree) 63 | inline void* alMalloc(size_t size, int alignment) { 64 | const size_t pSize = sizeof(void*); 65 | const size_t a = alignment - 1; 66 | void *raw = wrMalloc(size + a + pSize); 67 | void *aligned = (void*)(((size_t)raw + pSize + a) & ~a); 68 | *(void**)((size_t)aligned - pSize) = raw; 69 | return aligned; 70 | } 71 | 72 | // platform independent alignned memory de-allocation (see also alMalloc) 73 | inline void alFree(void* aligned) { 74 | const size_t pSize = sizeof(void*); 75 | void* raw = *(void**)((char*)aligned - pSize); 76 | wrFree(raw); 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | original author: Michael E. Smoot 3 | invaluable contributions: Daniel Aarno 4 | more contributions: Erik Zeek 5 | more contributions: Fabien Carmagnac (Tinbergen-AM) 6 | outstanding editing: Carol Smoot 7 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/COPYING: -------------------------------------------------------------------------------- 1 | 2 | 3 | Copyright (c) 2003 Michael E. Smoot 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = tclap 2 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/README: -------------------------------------------------------------------------------- 1 | 2 | TCLAP - Templatized Command Line Argument Parser 3 | 4 | This is a simple C++ library that facilitates parsing command line 5 | arguments in a type independent manner. It doesn't conform exactly 6 | to either the GNU or POSIX standards, although it is close. See 7 | docs/manual.html for descriptions of how things work or look at the 8 | simple examples in the examples dir. 9 | 10 | To find out what the latest changes are read the NEWS file in this directory. 11 | 12 | 13 | Any and all feedback is welcome to: Mike Smoot 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/ArgException.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ArgException.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_ARG_EXCEPTION_H 25 | #define TCLAP_ARG_EXCEPTION_H 26 | 27 | #include 28 | #include 29 | 30 | namespace TCLAP { 31 | 32 | /** 33 | * A simple class that defines and argument exception. Should be caught 34 | * whenever a CmdLine is created and parsed. 35 | */ 36 | class ArgException : public std::exception 37 | { 38 | public: 39 | 40 | /** 41 | * Constructor. 42 | * \param text - The text of the exception. 43 | * \param id - The text identifying the argument source. 44 | * \param td - Text describing the type of ArgException it is. 45 | * of the exception. 46 | */ 47 | ArgException( const std::string& text = "undefined exception", 48 | const std::string& id = "undefined", 49 | const std::string& td = "Generic ArgException") 50 | : std::exception(), 51 | _errorText(text), 52 | _argId( id ), 53 | _typeDescription(td) 54 | { } 55 | 56 | /** 57 | * Destructor. 58 | */ 59 | virtual ~ArgException() throw() { } 60 | 61 | /** 62 | * Returns the error text. 63 | */ 64 | std::string error() const { return ( _errorText ); } 65 | 66 | /** 67 | * Returns the argument id. 68 | */ 69 | std::string argId() const 70 | { 71 | if ( _argId == "undefined" ) 72 | return " "; 73 | else 74 | return ( "Argument: " + _argId ); 75 | } 76 | 77 | /** 78 | * Returns the arg id and error text. 79 | */ 80 | const char* what() const throw() 81 | { 82 | static std::string ex; 83 | ex = _argId + " -- " + _errorText; 84 | return ex.c_str(); 85 | } 86 | 87 | /** 88 | * Returns the type of the exception. Used to explain and distinguish 89 | * between different child exceptions. 90 | */ 91 | std::string typeDescription() const 92 | { 93 | return _typeDescription; 94 | } 95 | 96 | 97 | private: 98 | 99 | /** 100 | * The text of the exception message. 101 | */ 102 | std::string _errorText; 103 | 104 | /** 105 | * The argument related to this exception. 106 | */ 107 | std::string _argId; 108 | 109 | /** 110 | * Describes the type of the exception. Used to distinguish 111 | * between different child exceptions. 112 | */ 113 | std::string _typeDescription; 114 | 115 | }; 116 | 117 | /** 118 | * Thrown from within the child Arg classes when it fails to properly 119 | * parse the argument it has been passed. 120 | */ 121 | class ArgParseException : public ArgException 122 | { 123 | public: 124 | /** 125 | * Constructor. 126 | * \param text - The text of the exception. 127 | * \param id - The text identifying the argument source 128 | * of the exception. 129 | */ 130 | ArgParseException( const std::string& text = "undefined exception", 131 | const std::string& id = "undefined" ) 132 | : ArgException( text, 133 | id, 134 | std::string( "Exception found while parsing " ) + 135 | std::string( "the value the Arg has been passed." )) 136 | { } 137 | }; 138 | 139 | /** 140 | * Thrown from CmdLine when the arguments on the command line are not 141 | * properly specified, e.g. too many arguments, required argument missing, etc. 142 | */ 143 | class CmdLineParseException : public ArgException 144 | { 145 | public: 146 | /** 147 | * Constructor. 148 | * \param text - The text of the exception. 149 | * \param id - The text identifying the argument source 150 | * of the exception. 151 | */ 152 | CmdLineParseException( const std::string& text = "undefined exception", 153 | const std::string& id = "undefined" ) 154 | : ArgException( text, 155 | id, 156 | std::string( "Exception found when the values ") + 157 | std::string( "on the command line do not meet ") + 158 | std::string( "the requirements of the defined ") + 159 | std::string( "Args." )) 160 | { } 161 | }; 162 | 163 | /** 164 | * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. 165 | * same flag as another Arg, same name, etc. 166 | */ 167 | class SpecificationException : public ArgException 168 | { 169 | public: 170 | /** 171 | * Constructor. 172 | * \param text - The text of the exception. 173 | * \param id - The text identifying the argument source 174 | * of the exception. 175 | */ 176 | SpecificationException( const std::string& text = "undefined exception", 177 | const std::string& id = "undefined" ) 178 | : ArgException( text, 179 | id, 180 | std::string("Exception found when an Arg object ")+ 181 | std::string("is improperly defined by the ") + 182 | std::string("developer." )) 183 | { } 184 | 185 | }; 186 | 187 | class ExitException { 188 | public: 189 | ExitException(int estat) : _estat(estat) {} 190 | 191 | int getExitStatus() const { return _estat; } 192 | 193 | private: 194 | int _estat; 195 | }; 196 | 197 | } // namespace TCLAP 198 | 199 | #endif 200 | 201 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/ArgTraits.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ArgTraits.h 6 | * 7 | * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | // This is an internal tclap file, you should probably not have to 24 | // include this directly 25 | 26 | #ifndef TCLAP_ARGTRAITS_H 27 | #define TCLAP_ARGTRAITS_H 28 | 29 | namespace TCLAP { 30 | 31 | // We use two empty structs to get compile type specialization 32 | // function to work 33 | 34 | /** 35 | * A value like argument value type is a value that can be set using 36 | * operator>>. This is the default value type. 37 | */ 38 | struct ValueLike { 39 | typedef ValueLike ValueCategory; 40 | virtual ~ValueLike() {} 41 | }; 42 | 43 | /** 44 | * A string like argument value type is a value that can be set using 45 | * operator=(string). Usefull if the value type contains spaces which 46 | * will be broken up into individual tokens by operator>>. 47 | */ 48 | struct StringLike { 49 | virtual ~StringLike() {} 50 | }; 51 | 52 | /** 53 | * A class can inherit from this object to make it have string like 54 | * traits. This is a compile time thing and does not add any overhead 55 | * to the inherenting class. 56 | */ 57 | struct StringLikeTrait { 58 | typedef StringLike ValueCategory; 59 | virtual ~StringLikeTrait() {} 60 | }; 61 | 62 | /** 63 | * A class can inherit from this object to make it have value like 64 | * traits. This is a compile time thing and does not add any overhead 65 | * to the inherenting class. 66 | */ 67 | struct ValueLikeTrait { 68 | typedef ValueLike ValueCategory; 69 | virtual ~ValueLikeTrait() {} 70 | }; 71 | 72 | /** 73 | * Arg traits are used to get compile type specialization when parsing 74 | * argument values. Using an ArgTraits you can specify the way that 75 | * values gets assigned to any particular type during parsing. The two 76 | * supported types are StringLike and ValueLike. 77 | */ 78 | template 79 | struct ArgTraits { 80 | typedef typename T::ValueCategory ValueCategory; 81 | virtual ~ArgTraits() {} 82 | //typedef ValueLike ValueCategory; 83 | }; 84 | 85 | #endif 86 | 87 | } // namespace 88 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/CmdLineInterface.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: CmdLineInterface.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_COMMANDLINE_INTERFACE_H 24 | #define TCLAP_COMMANDLINE_INTERFACE_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace TCLAP { 34 | 35 | class Arg; 36 | class CmdLineOutput; 37 | class XorHandler; 38 | 39 | /** 40 | * The base class that manages the command line definition and passes 41 | * along the parsing to the appropriate Arg classes. 42 | */ 43 | class CmdLineInterface 44 | { 45 | public: 46 | 47 | /** 48 | * Destructor 49 | */ 50 | virtual ~CmdLineInterface() {} 51 | 52 | /** 53 | * Adds an argument to the list of arguments to be parsed. 54 | * \param a - Argument to be added. 55 | */ 56 | virtual void add( Arg& a )=0; 57 | 58 | /** 59 | * An alternative add. Functionally identical. 60 | * \param a - Argument to be added. 61 | */ 62 | virtual void add( Arg* a )=0; 63 | 64 | /** 65 | * Add two Args that will be xor'd. 66 | * If this method is used, add does 67 | * not need to be called. 68 | * \param a - Argument to be added and xor'd. 69 | * \param b - Argument to be added and xor'd. 70 | */ 71 | virtual void xorAdd( Arg& a, Arg& b )=0; 72 | 73 | /** 74 | * Add a list of Args that will be xor'd. If this method is used, 75 | * add does not need to be called. 76 | * \param xors - List of Args to be added and xor'd. 77 | */ 78 | virtual void xorAdd( std::vector& xors )=0; 79 | 80 | /** 81 | * Parses the command line. 82 | * \param argc - Number of arguments. 83 | * \param argv - Array of arguments. 84 | */ 85 | virtual void parse(int argc, const char * const * argv)=0; 86 | 87 | /** 88 | * Parses the command line. 89 | * \param args - A vector of strings representing the args. 90 | * args[0] is still the program name. 91 | */ 92 | void parse(std::vector& args); 93 | 94 | /** 95 | * Returns the CmdLineOutput object. 96 | */ 97 | virtual CmdLineOutput* getOutput()=0; 98 | 99 | /** 100 | * \param co - CmdLineOutput object that we want to use instead. 101 | */ 102 | virtual void setOutput(CmdLineOutput* co)=0; 103 | 104 | /** 105 | * Returns the version string. 106 | */ 107 | virtual std::string& getVersion()=0; 108 | 109 | /** 110 | * Returns the program name string. 111 | */ 112 | virtual std::string& getProgramName()=0; 113 | 114 | /** 115 | * Returns the argList. 116 | */ 117 | virtual std::list& getArgList()=0; 118 | 119 | /** 120 | * Returns the XorHandler. 121 | */ 122 | virtual XorHandler& getXorHandler()=0; 123 | 124 | /** 125 | * Returns the delimiter string. 126 | */ 127 | virtual char getDelimiter()=0; 128 | 129 | /** 130 | * Returns the message string. 131 | */ 132 | virtual std::string& getMessage()=0; 133 | 134 | /** 135 | * Indicates whether or not the help and version switches were created 136 | * automatically. 137 | */ 138 | virtual bool hasHelpAndVersion()=0; 139 | 140 | /** 141 | * Resets the instance as if it had just been constructed so that the 142 | * instance can be reused. 143 | */ 144 | virtual void reset()=0; 145 | }; 146 | 147 | } //namespace 148 | 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/CmdLineOutput.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: CmdLineOutput.h 6 | * 7 | * Copyright (c) 2004, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_CMDLINEOUTPUT_H 24 | #define TCLAP_CMDLINEOUTPUT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace TCLAP { 34 | 35 | class CmdLineInterface; 36 | class ArgException; 37 | 38 | /** 39 | * The interface that any output object must implement. 40 | */ 41 | class CmdLineOutput 42 | { 43 | 44 | public: 45 | 46 | /** 47 | * Virtual destructor. 48 | */ 49 | virtual ~CmdLineOutput() {} 50 | 51 | /** 52 | * Generates some sort of output for the USAGE. 53 | * \param c - The CmdLine object the output is generated for. 54 | */ 55 | virtual void usage(CmdLineInterface& c)=0; 56 | 57 | /** 58 | * Generates some sort of output for the version. 59 | * \param c - The CmdLine object the output is generated for. 60 | */ 61 | virtual void version(CmdLineInterface& c)=0; 62 | 63 | /** 64 | * Generates some sort of output for a failure. 65 | * \param c - The CmdLine object the output is generated for. 66 | * \param e - The ArgException that caused the failure. 67 | */ 68 | virtual void failure( CmdLineInterface& c, 69 | ArgException& e )=0; 70 | 71 | }; 72 | 73 | } //namespace TCLAP 74 | #endif 75 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/Constraint.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Constraint.h 5 | * 6 | * Copyright (c) 2005, Michael E. Smoot 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_CONSTRAINT_H 23 | #define TCLAP_CONSTRAINT_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * The interface that defines the interaction between the Arg and Constraint. 36 | */ 37 | template 38 | class Constraint 39 | { 40 | 41 | public: 42 | /** 43 | * Returns a description of the Constraint. 44 | */ 45 | virtual std::string description() const =0; 46 | 47 | /** 48 | * Returns the short ID for the Constraint. 49 | */ 50 | virtual std::string shortID() const =0; 51 | 52 | /** 53 | * The method used to verify that the value parsed from the command 54 | * line meets the constraint. 55 | * \param value - The value that will be checked. 56 | */ 57 | virtual bool check(const T& value) const =0; 58 | 59 | /** 60 | * Destructor. 61 | * Silences warnings about Constraint being a base class with virtual 62 | * functions but without a virtual destructor. 63 | */ 64 | virtual ~Constraint() { ; } 65 | }; 66 | 67 | } //namespace TCLAP 68 | #endif 69 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/HelpVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: HelpVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | #ifndef TCLAP_HELP_VISITOR_H 23 | #define TCLAP_HELP_VISITOR_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Visitor object that calls the usage method of the given CmdLineOutput 33 | * object for the specified CmdLine object. 34 | */ 35 | class HelpVisitor: public Visitor 36 | { 37 | private: 38 | /** 39 | * Prevent accidental copying. 40 | */ 41 | HelpVisitor(const HelpVisitor& rhs); 42 | HelpVisitor& operator=(const HelpVisitor& rhs); 43 | 44 | protected: 45 | 46 | /** 47 | * The CmdLine the output will be generated for. 48 | */ 49 | CmdLineInterface* _cmd; 50 | 51 | /** 52 | * The output object. 53 | */ 54 | CmdLineOutput** _out; 55 | 56 | public: 57 | 58 | /** 59 | * Constructor. 60 | * \param cmd - The CmdLine the output will be generated for. 61 | * \param out - The type of output. 62 | */ 63 | HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) 64 | : Visitor(), _cmd( cmd ), _out( out ) { } 65 | 66 | /** 67 | * Calls the usage method of the CmdLineOutput for the 68 | * specified CmdLine. 69 | */ 70 | void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } 71 | 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/IgnoreRestVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: IgnoreRestVisitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_IGNORE_REST_VISITOR_H 24 | #define TCLAP_IGNORE_REST_VISITOR_H 25 | 26 | #include 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | /** 32 | * A Vistor that tells the CmdLine to begin ignoring arguments after 33 | * this one is parsed. 34 | */ 35 | class IgnoreRestVisitor: public Visitor 36 | { 37 | public: 38 | 39 | /** 40 | * Constructor. 41 | */ 42 | IgnoreRestVisitor() : Visitor() {} 43 | 44 | /** 45 | * Sets Arg::_ignoreRest. 46 | */ 47 | void visit() { Arg::beginIgnoring(); } 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | libtclapincludedir = $(includedir)/tclap 3 | 4 | libtclapinclude_HEADERS = \ 5 | CmdLineInterface.h \ 6 | ArgException.h \ 7 | CmdLine.h \ 8 | XorHandler.h \ 9 | MultiArg.h \ 10 | UnlabeledMultiArg.h \ 11 | ValueArg.h \ 12 | UnlabeledValueArg.h \ 13 | Visitor.h Arg.h \ 14 | HelpVisitor.h \ 15 | SwitchArg.h \ 16 | MultiSwitchArg.h \ 17 | VersionVisitor.h \ 18 | IgnoreRestVisitor.h \ 19 | CmdLineOutput.h \ 20 | StdOutput.h \ 21 | DocBookOutput.h \ 22 | ZshCompletionOutput.h \ 23 | OptionalUnlabeledTracker.h \ 24 | Constraint.h \ 25 | ValuesConstraint.h \ 26 | ArgTraits.h \ 27 | StandardTraits.h 28 | 29 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/MultiSwitchArg.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: MultiSwitchArg.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. 9 | * All rights reverved. 10 | * 11 | * See the file COPYING in the top directory of this distribution for 12 | * more information. 13 | * 14 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | *****************************************************************************/ 23 | 24 | 25 | #ifndef TCLAP_MULTI_SWITCH_ARG_H 26 | #define TCLAP_MULTI_SWITCH_ARG_H 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace TCLAP { 34 | 35 | /** 36 | * A multiple switch argument. If the switch is set on the command line, then 37 | * the getValue method will return the number of times the switch appears. 38 | */ 39 | class MultiSwitchArg : public SwitchArg 40 | { 41 | protected: 42 | 43 | /** 44 | * The value of the switch. 45 | */ 46 | int _value; 47 | 48 | /** 49 | * Used to support the reset() method so that ValueArg can be 50 | * reset to their constructed value. 51 | */ 52 | int _default; 53 | 54 | public: 55 | 56 | /** 57 | * MultiSwitchArg constructor. 58 | * \param flag - The one character flag that identifies this 59 | * argument on the command line. 60 | * \param name - A one word name for the argument. Can be 61 | * used as a long flag on the command line. 62 | * \param desc - A description of what the argument is for or 63 | * does. 64 | * \param init - Optional. The initial/default value of this Arg. 65 | * Defaults to 0. 66 | * \param v - An optional visitor. You probably should not 67 | * use this unless you have a very good reason. 68 | */ 69 | MultiSwitchArg(const std::string& flag, 70 | const std::string& name, 71 | const std::string& desc, 72 | int init = 0, 73 | Visitor* v = NULL); 74 | 75 | 76 | /** 77 | * MultiSwitchArg constructor. 78 | * \param flag - The one character flag that identifies this 79 | * argument on the command line. 80 | * \param name - A one word name for the argument. Can be 81 | * used as a long flag on the command line. 82 | * \param desc - A description of what the argument is for or 83 | * does. 84 | * \param parser - A CmdLine parser object to add this Arg to 85 | * \param init - Optional. The initial/default value of this Arg. 86 | * Defaults to 0. 87 | * \param v - An optional visitor. You probably should not 88 | * use this unless you have a very good reason. 89 | */ 90 | MultiSwitchArg(const std::string& flag, 91 | const std::string& name, 92 | const std::string& desc, 93 | CmdLineInterface& parser, 94 | int init = 0, 95 | Visitor* v = NULL); 96 | 97 | 98 | /** 99 | * Handles the processing of the argument. 100 | * This re-implements the SwitchArg version of this method to set the 101 | * _value of the argument appropriately. 102 | * \param i - Pointer the the current argument in the list. 103 | * \param args - Mutable list of strings. Passed 104 | * in from main(). 105 | */ 106 | virtual bool processArg(int* i, std::vector& args); 107 | 108 | /** 109 | * Returns int, the number of times the switch has been set. 110 | */ 111 | int getValue(); 112 | 113 | /** 114 | * Returns the shortID for this Arg. 115 | */ 116 | std::string shortID(const std::string& val) const; 117 | 118 | /** 119 | * Returns the longID for this Arg. 120 | */ 121 | std::string longID(const std::string& val) const; 122 | 123 | void reset(); 124 | 125 | }; 126 | 127 | ////////////////////////////////////////////////////////////////////// 128 | //BEGIN MultiSwitchArg.cpp 129 | ////////////////////////////////////////////////////////////////////// 130 | inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, 131 | const std::string& name, 132 | const std::string& desc, 133 | int init, 134 | Visitor* v ) 135 | : SwitchArg(flag, name, desc, false, v), 136 | _value( init ), 137 | _default( init ) 138 | { } 139 | 140 | inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, 141 | const std::string& name, 142 | const std::string& desc, 143 | CmdLineInterface& parser, 144 | int init, 145 | Visitor* v ) 146 | : SwitchArg(flag, name, desc, false, v), 147 | _value( init ), 148 | _default( init ) 149 | { 150 | parser.add( this ); 151 | } 152 | 153 | inline int MultiSwitchArg::getValue() { return _value; } 154 | 155 | inline bool MultiSwitchArg::processArg(int *i, std::vector& args) 156 | { 157 | if ( _ignoreable && Arg::ignoreRest() ) 158 | return false; 159 | 160 | if ( argMatches( args[*i] )) 161 | { 162 | // so the isSet() method will work 163 | _alreadySet = true; 164 | 165 | // Matched argument: increment value. 166 | ++_value; 167 | 168 | _checkWithVisitor(); 169 | 170 | return true; 171 | } 172 | else if ( combinedSwitchesMatch( args[*i] ) ) 173 | { 174 | // so the isSet() method will work 175 | _alreadySet = true; 176 | 177 | // Matched argument: increment value. 178 | ++_value; 179 | 180 | // Check for more in argument and increment value. 181 | while ( combinedSwitchesMatch( args[*i] ) ) 182 | ++_value; 183 | 184 | _checkWithVisitor(); 185 | 186 | return false; 187 | } 188 | else 189 | return false; 190 | } 191 | 192 | inline std::string 193 | MultiSwitchArg::shortID(const std::string& val) const 194 | { 195 | return Arg::shortID(val) + " ... "; 196 | } 197 | 198 | inline std::string 199 | MultiSwitchArg::longID(const std::string& val) const 200 | { 201 | return Arg::longID(val) + " (accepted multiple times)"; 202 | } 203 | 204 | inline void 205 | MultiSwitchArg::reset() 206 | { 207 | MultiSwitchArg::_value = MultiSwitchArg::_default; 208 | } 209 | 210 | ////////////////////////////////////////////////////////////////////// 211 | //END MultiSwitchArg.cpp 212 | ////////////////////////////////////////////////////////////////////// 213 | 214 | } //namespace TCLAP 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/OptionalUnlabeledTracker.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: OptionalUnlabeledTracker.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H 25 | #define TCLAP_OPTIONAL_UNLABELED_TRACKER_H 26 | 27 | #include 28 | 29 | namespace TCLAP { 30 | 31 | class OptionalUnlabeledTracker 32 | { 33 | 34 | public: 35 | 36 | static void check( bool req, const std::string& argName ); 37 | 38 | static void gotOptional() { alreadyOptionalRef() = true; } 39 | 40 | static bool& alreadyOptional() { return alreadyOptionalRef(); } 41 | 42 | private: 43 | 44 | static bool& alreadyOptionalRef() { static bool ct = false; return ct; } 45 | }; 46 | 47 | 48 | inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) 49 | { 50 | if ( OptionalUnlabeledTracker::alreadyOptional() ) 51 | throw( SpecificationException( 52 | "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", 53 | argName ) ); 54 | 55 | if ( !req ) 56 | OptionalUnlabeledTracker::gotOptional(); 57 | } 58 | 59 | 60 | } // namespace TCLAP 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/StandardTraits.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: StandardTraits.h 6 | * 7 | * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | // This is an internal tclap file, you should probably not have to 24 | // include this directly 25 | 26 | #ifndef TCLAP_STANDARD_TRAITS_H 27 | #define TCLAP_STANDARD_TRAITS_H 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include // To check for long long 31 | #endif 32 | 33 | // If Microsoft has already typedef'd wchar_t as an unsigned 34 | // short, then compiles will break because it's as if we're 35 | // creating ArgTraits twice for unsigned short. Thus... 36 | #ifdef _MSC_VER 37 | #ifndef _NATIVE_WCHAR_T_DEFINED 38 | #define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS 39 | #endif 40 | #endif 41 | 42 | namespace TCLAP { 43 | 44 | // ====================================================================== 45 | // Integer types 46 | // ====================================================================== 47 | 48 | /** 49 | * longs have value-like semantics. 50 | */ 51 | template<> 52 | struct ArgTraits { 53 | typedef ValueLike ValueCategory; 54 | }; 55 | 56 | /** 57 | * ints have value-like semantics. 58 | */ 59 | template<> 60 | struct ArgTraits { 61 | typedef ValueLike ValueCategory; 62 | }; 63 | 64 | /** 65 | * shorts have value-like semantics. 66 | */ 67 | template<> 68 | struct ArgTraits { 69 | typedef ValueLike ValueCategory; 70 | }; 71 | 72 | /** 73 | * chars have value-like semantics. 74 | */ 75 | template<> 76 | struct ArgTraits { 77 | typedef ValueLike ValueCategory; 78 | }; 79 | 80 | #ifdef HAVE_LONG_LONG 81 | /** 82 | * long longs have value-like semantics. 83 | */ 84 | template<> 85 | struct ArgTraits { 86 | typedef ValueLike ValueCategory; 87 | }; 88 | #endif 89 | 90 | // ====================================================================== 91 | // Unsigned integer types 92 | // ====================================================================== 93 | 94 | /** 95 | * unsigned longs have value-like semantics. 96 | */ 97 | template<> 98 | struct ArgTraits { 99 | typedef ValueLike ValueCategory; 100 | }; 101 | 102 | /** 103 | * unsigned ints have value-like semantics. 104 | */ 105 | template<> 106 | struct ArgTraits { 107 | typedef ValueLike ValueCategory; 108 | }; 109 | 110 | /** 111 | * unsigned shorts have value-like semantics. 112 | */ 113 | template<> 114 | struct ArgTraits { 115 | typedef ValueLike ValueCategory; 116 | }; 117 | 118 | /** 119 | * unsigned chars have value-like semantics. 120 | */ 121 | template<> 122 | struct ArgTraits { 123 | typedef ValueLike ValueCategory; 124 | }; 125 | 126 | // Microsoft implements size_t awkwardly. 127 | #if defined(_MSC_VER) && defined(_M_X64) 128 | /** 129 | * size_ts have value-like semantics. 130 | */ 131 | template<> 132 | struct ArgTraits { 133 | typedef ValueLike ValueCategory; 134 | }; 135 | #endif 136 | 137 | 138 | #ifdef HAVE_LONG_LONG 139 | /** 140 | * unsigned long longs have value-like semantics. 141 | */ 142 | template<> 143 | struct ArgTraits { 144 | typedef ValueLike ValueCategory; 145 | }; 146 | #endif 147 | 148 | // ====================================================================== 149 | // Float types 150 | // ====================================================================== 151 | 152 | /** 153 | * floats have value-like semantics. 154 | */ 155 | template<> 156 | struct ArgTraits { 157 | typedef ValueLike ValueCategory; 158 | }; 159 | 160 | /** 161 | * doubles have value-like semantics. 162 | */ 163 | template<> 164 | struct ArgTraits { 165 | typedef ValueLike ValueCategory; 166 | }; 167 | 168 | // ====================================================================== 169 | // Other types 170 | // ====================================================================== 171 | 172 | /** 173 | * bools have value-like semantics. 174 | */ 175 | template<> 176 | struct ArgTraits { 177 | typedef ValueLike ValueCategory; 178 | }; 179 | 180 | 181 | /** 182 | * wchar_ts have value-like semantics. 183 | */ 184 | #ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS 185 | template<> 186 | struct ArgTraits { 187 | typedef ValueLike ValueCategory; 188 | }; 189 | #endif 190 | 191 | /** 192 | * Strings have string like argument traits. 193 | */ 194 | template<> 195 | struct ArgTraits { 196 | typedef StringLike ValueCategory; 197 | }; 198 | 199 | template 200 | void SetString(T &dst, const std::string &src) 201 | { 202 | dst = src; 203 | } 204 | 205 | } // namespace 206 | 207 | #endif 208 | 209 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/ValuesConstraint.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /****************************************************************************** 4 | * 5 | * file: ValuesConstraint.h 6 | * 7 | * Copyright (c) 2005, Michael E. Smoot 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_VALUESCONSTRAINT_H 24 | #define TCLAP_VALUESCONSTRAINT_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef HAVE_CONFIG_H 31 | #include 32 | #else 33 | #define HAVE_SSTREAM 34 | #endif 35 | 36 | #if defined(HAVE_SSTREAM) 37 | #include 38 | #elif defined(HAVE_STRSTREAM) 39 | #include 40 | #else 41 | #error "Need a stringstream (sstream or strstream) to compile!" 42 | #endif 43 | 44 | namespace TCLAP { 45 | 46 | /** 47 | * A Constraint that constrains the Arg to only those values specified 48 | * in the constraint. 49 | */ 50 | template 51 | class ValuesConstraint : public Constraint 52 | { 53 | 54 | public: 55 | 56 | /** 57 | * Constructor. 58 | * \param allowed - vector of allowed values. 59 | */ 60 | ValuesConstraint(std::vector& allowed); 61 | 62 | /** 63 | * Virtual destructor. 64 | */ 65 | virtual ~ValuesConstraint() {} 66 | 67 | /** 68 | * Returns a description of the Constraint. 69 | */ 70 | virtual std::string description() const; 71 | 72 | /** 73 | * Returns the short ID for the Constraint. 74 | */ 75 | virtual std::string shortID() const; 76 | 77 | /** 78 | * The method used to verify that the value parsed from the command 79 | * line meets the constraint. 80 | * \param value - The value that will be checked. 81 | */ 82 | virtual bool check(const T& value) const; 83 | 84 | protected: 85 | 86 | /** 87 | * The list of valid values. 88 | */ 89 | std::vector _allowed; 90 | 91 | /** 92 | * The string used to describe the allowed values of this constraint. 93 | */ 94 | std::string _typeDesc; 95 | 96 | }; 97 | 98 | template 99 | ValuesConstraint::ValuesConstraint(std::vector& allowed) 100 | : _allowed(allowed), 101 | _typeDesc("") 102 | { 103 | for ( unsigned int i = 0; i < _allowed.size(); i++ ) 104 | { 105 | 106 | #if defined(HAVE_SSTREAM) 107 | std::ostringstream os; 108 | #elif defined(HAVE_STRSTREAM) 109 | std::ostrstream os; 110 | #else 111 | #error "Need a stringstream (sstream or strstream) to compile!" 112 | #endif 113 | 114 | os << _allowed[i]; 115 | 116 | std::string temp( os.str() ); 117 | 118 | if ( i > 0 ) 119 | _typeDesc += "|"; 120 | _typeDesc += temp; 121 | } 122 | } 123 | 124 | template 125 | bool ValuesConstraint::check( const T& val ) const 126 | { 127 | if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) 128 | return false; 129 | else 130 | return true; 131 | } 132 | 133 | template 134 | std::string ValuesConstraint::shortID() const 135 | { 136 | return _typeDesc; 137 | } 138 | 139 | template 140 | std::string ValuesConstraint::description() const 141 | { 142 | return _typeDesc; 143 | } 144 | 145 | 146 | } //namespace TCLAP 147 | #endif 148 | 149 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/VersionVisitor.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 2 | 3 | /****************************************************************************** 4 | * 5 | * file: VersionVisitor.h 6 | * 7 | * Copyright (c) 2003, Michael E. Smoot . 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | 24 | #ifndef TCLAP_VERSION_VISITOR_H 25 | #define TCLAP_VERSION_VISITOR_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace TCLAP { 32 | 33 | /** 34 | * A Vistor that will call the version method of the given CmdLineOutput 35 | * for the specified CmdLine object and then exit. 36 | */ 37 | class VersionVisitor: public Visitor 38 | { 39 | private: 40 | /** 41 | * Prevent accidental copying 42 | */ 43 | VersionVisitor(const VersionVisitor& rhs); 44 | VersionVisitor& operator=(const VersionVisitor& rhs); 45 | 46 | protected: 47 | 48 | /** 49 | * The CmdLine of interest. 50 | */ 51 | CmdLineInterface* _cmd; 52 | 53 | /** 54 | * The output object. 55 | */ 56 | CmdLineOutput** _out; 57 | 58 | public: 59 | 60 | /** 61 | * Constructor. 62 | * \param cmd - The CmdLine the output is generated for. 63 | * \param out - The type of output. 64 | */ 65 | VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) 66 | : Visitor(), _cmd( cmd ), _out( out ) { } 67 | 68 | /** 69 | * Calls the version method of the output object using the 70 | * specified CmdLine. 71 | */ 72 | void visit() { 73 | (*_out)->version(*_cmd); 74 | throw ExitException(0); 75 | } 76 | 77 | }; 78 | 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/Visitor.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: Visitor.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * All rights reverved. 8 | * 9 | * See the file COPYING in the top directory of this distribution for 10 | * more information. 11 | * 12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | *****************************************************************************/ 21 | 22 | 23 | #ifndef TCLAP_VISITOR_H 24 | #define TCLAP_VISITOR_H 25 | 26 | namespace TCLAP { 27 | 28 | /** 29 | * A base class that defines the interface for visitors. 30 | */ 31 | class Visitor 32 | { 33 | public: 34 | 35 | /** 36 | * Constructor. Does nothing. 37 | */ 38 | Visitor() { } 39 | 40 | /** 41 | * Destructor. Does nothing. 42 | */ 43 | virtual ~Visitor() { } 44 | 45 | /** 46 | * Does nothing. Should be overridden by child. 47 | */ 48 | virtual void visit() { } 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/3rdparty/tclap/tclap/XorHandler.h: -------------------------------------------------------------------------------- 1 | 2 | /****************************************************************************** 3 | * 4 | * file: XorHandler.h 5 | * 6 | * Copyright (c) 2003, Michael E. Smoot . 7 | * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 8 | * All rights reverved. 9 | * 10 | * See the file COPYING in the top directory of this distribution for 11 | * more information. 12 | * 13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | * DEALINGS IN THE SOFTWARE. 20 | * 21 | *****************************************************************************/ 22 | 23 | #ifndef TCLAP_XORHANDLER_H 24 | #define TCLAP_XORHANDLER_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace TCLAP { 33 | 34 | /** 35 | * This class handles lists of Arg's that are to be XOR'd on the command 36 | * line. This is used by CmdLine and you shouldn't ever use it. 37 | */ 38 | class XorHandler 39 | { 40 | protected: 41 | 42 | /** 43 | * The list of of lists of Arg's to be or'd together. 44 | */ 45 | std::vector< std::vector > _orList; 46 | 47 | public: 48 | 49 | /** 50 | * Constructor. Does nothing. 51 | */ 52 | XorHandler( ) : _orList(std::vector< std::vector >()) {} 53 | 54 | /** 55 | * Add a list of Arg*'s that will be orred together. 56 | * \param ors - list of Arg* that will be xor'd. 57 | */ 58 | void add( std::vector& ors ); 59 | 60 | /** 61 | * Checks whether the specified Arg is in one of the xor lists and 62 | * if it does match one, returns the size of the xor list that the 63 | * Arg matched. If the Arg matches, then it also sets the rest of 64 | * the Arg's in the list. You shouldn't use this. 65 | * \param a - The Arg to be checked. 66 | */ 67 | int check( const Arg* a ); 68 | 69 | /** 70 | * Returns the XOR specific short usage. 71 | */ 72 | std::string shortUsage(); 73 | 74 | /** 75 | * Prints the XOR specific long usage. 76 | * \param os - Stream to print to. 77 | */ 78 | void printLongUsage(std::ostream& os); 79 | 80 | /** 81 | * Simply checks whether the Arg is contained in one of the arg 82 | * lists. 83 | * \param a - The Arg to be checked. 84 | */ 85 | bool contains( const Arg* a ); 86 | 87 | std::vector< std::vector >& getXorList(); 88 | 89 | }; 90 | 91 | 92 | ////////////////////////////////////////////////////////////////////// 93 | //BEGIN XOR.cpp 94 | ////////////////////////////////////////////////////////////////////// 95 | inline void XorHandler::add( std::vector& ors ) 96 | { 97 | _orList.push_back( ors ); 98 | } 99 | 100 | inline int XorHandler::check( const Arg* a ) 101 | { 102 | // iterate over each XOR list 103 | for ( int i = 0; static_cast(i) < _orList.size(); i++ ) 104 | { 105 | // if the XOR list contains the arg.. 106 | ArgVectorIterator ait = std::find( _orList[i].begin(), 107 | _orList[i].end(), a ); 108 | if ( ait != _orList[i].end() ) 109 | { 110 | // first check to see if a mutually exclusive switch 111 | // has not already been set 112 | for ( ArgVectorIterator it = _orList[i].begin(); 113 | it != _orList[i].end(); 114 | it++ ) 115 | if ( a != (*it) && (*it)->isSet() ) 116 | throw(CmdLineParseException( 117 | "Mutually exclusive argument already set!", 118 | (*it)->toString())); 119 | 120 | // go through and set each arg that is not a 121 | for ( ArgVectorIterator it = _orList[i].begin(); 122 | it != _orList[i].end(); 123 | it++ ) 124 | if ( a != (*it) ) 125 | (*it)->xorSet(); 126 | 127 | // return the number of required args that have now been set 128 | if ( (*ait)->allowMore() ) 129 | return 0; 130 | else 131 | return static_cast(_orList[i].size()); 132 | } 133 | } 134 | 135 | if ( a->isRequired() ) 136 | return 1; 137 | else 138 | return 0; 139 | } 140 | 141 | inline bool XorHandler::contains( const Arg* a ) 142 | { 143 | for ( int i = 0; static_cast(i) < _orList.size(); i++ ) 144 | for ( ArgVectorIterator it = _orList[i].begin(); 145 | it != _orList[i].end(); 146 | it++ ) 147 | if ( a == (*it) ) 148 | return true; 149 | 150 | return false; 151 | } 152 | 153 | inline std::vector< std::vector >& XorHandler::getXorList() 154 | { 155 | return _orList; 156 | } 157 | 158 | 159 | 160 | ////////////////////////////////////////////////////////////////////// 161 | //END XOR.cpp 162 | ////////////////////////////////////////////////////////////////////// 163 | 164 | } //namespace TCLAP 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /src/cf_libs/common/DepthHistogram.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 34 | the depth histogram presented in [1] is implemented within this class 35 | 36 | References: 37 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 38 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 39 | */ 40 | #ifndef CFTRACKING_HISTOGRAM_H 41 | #define CFTRACKING_HISTOGRAM_H 42 | 43 | #include 44 | 45 | #include 46 | 47 | class DepthHistogram 48 | { 49 | public: 50 | struct Labels{ std::vector< int > labels; std::vector< float > centers; std::vector< int > labelsC;}; 51 | 52 | DepthHistogram(); 53 | 54 | const std::vector< int > getPeaks() const; 55 | const std::vector< int > getPeaks( const int minimumPeakdistance, const double minimumPeakHeight = 0.005 ) const; 56 | const DepthHistogram::Labels getLabels( const std::vector< int > & peaks ) const; 57 | 58 | const int depthToBin( const double depth ) const; 59 | const double binToDepth( const float bin ) const; 60 | const int depthToLabel( const double depth, const std::vector< int > & labels ) const; 61 | //const double depthToCentroid( const double depth, const Labels & labels ) const; 62 | const int depthToPeak( const double depth, const std::vector< int > & peaks ) const; 63 | const int depthToCentroid( const double depth, const std::vector< float > & centroids ) const; 64 | 65 | const bool empty() const; 66 | const size_t size() const; 67 | const double minimum() const; 68 | const double maximum() const; 69 | const float estStep() const; 70 | 71 | const float operator[]( const uint i ) const; 72 | 73 | static const DepthHistogram createHistogram( const uint step, const cv::Mat & region, const cv::Mat1b & mask ); 74 | void visualise( const std::string & string ); 75 | private: 76 | cv::Mat1f m_bins; 77 | double m_minimum, m_maximum; 78 | float estimatedStep; 79 | 80 | const Labels kmeans( const std::vector< float > & centroids ) const; 81 | }; 82 | 83 | #endif //CFTRACKING_HISTOGRAM_H 84 | -------------------------------------------------------------------------------- /src/cf_libs/common/KalmanFilter1D.cpp: -------------------------------------------------------------------------------- 1 | #include "KalmanFilter1D.h" 2 | 3 | KalmanFilter1D::KalmanFilter1D() 4 | { 5 | } 6 | 7 | KalmanFilter1D::~KalmanFilter1D() 8 | { 9 | 10 | } 11 | 12 | void KalmanFilter1D::initialise( const double position ) 13 | { 14 | this->m_filter.init( 2, 1, 0, CV_64F ); 15 | this->m_filter.transitionMatrix = (cv::Mat_< double >( 2, 2 ) << 1,1, 0,1); 16 | this->m_filter.statePre.at< double >( 0 ) = position; 17 | this->m_filter.statePre.at< double >( 1 ) = 0; 18 | this->m_filter.statePost.at< double >( 0 ) = position; 19 | this->m_filter.statePost.at< double >( 1 ) = 0; 20 | cv::setIdentity( this->m_filter.measurementMatrix ); 21 | cv::setIdentity( this->m_filter.processNoiseCov, cv::Scalar::all( 1e-4 ) ); 22 | cv::setIdentity( this->m_filter.measurementNoiseCov, cv::Scalar::all( 1e-4 ) ); 23 | cv::setIdentity( this->m_filter.errorCovPost, cv::Scalar::all( 0.1 ) ); 24 | } 25 | 26 | const double KalmanFilter1D::getPrediction() 27 | { 28 | return this->m_filter.predict().at< double >( 0 ); 29 | } 30 | 31 | const double KalmanFilter1D::getEstimate( const double & measurement ) 32 | { 33 | cv::Mat1d measurementMatrix( 1, 1 ); 34 | measurementMatrix( 0 ) = measurement; 35 | 36 | return this->m_filter.correct( measurementMatrix ).at< double >( 0 ); 37 | } 38 | -------------------------------------------------------------------------------- /src/cf_libs/common/KalmanFilter1D.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of Kalman filter used in [1] 34 | 35 | References: 36 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 37 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 38 | */ 39 | #ifndef CFTRACKING_KALMANFILTER1D_H 40 | #define CFTRACKING_KALMANFILTER1D_H 41 | 42 | 43 | #include 44 | 45 | class KalmanFilter1D 46 | { 47 | public: 48 | KalmanFilter1D(); 49 | ~KalmanFilter1D(); 50 | 51 | void initialise( const double position ); 52 | 53 | const double getPrediction(); 54 | const double getEstimate( const double & measurement ); 55 | private: 56 | cv::KalmanFilter m_filter; 57 | }; 58 | 59 | 60 | #endif //CFTRACKING_KALMANFILTER1D_H 61 | -------------------------------------------------------------------------------- /src/cf_libs/common/KalmanFilter2D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "KalmanFilter2D.h" 3 | 4 | KalmanFilter2D::KalmanFilter2D() 5 | { 6 | } 7 | 8 | KalmanFilter2D::~KalmanFilter2D() 9 | { 10 | } 11 | 12 | void KalmanFilter2D::initialise( const cv::Point_< double > & position ) 13 | { 14 | this->m_filter.init( 4, 2, 0, CV_64F ); 15 | this->m_filter.transitionMatrix = (cv::Mat_< double >( 4, 4 ) << 1,0,1,0, 0,1,0,1, 0,0,1,0, 0,0,0,1); 16 | this->m_filter.statePre.at< double >( 0 ) = position.x; 17 | this->m_filter.statePre.at< double >( 1 ) = position.y; 18 | this->m_filter.statePre.at< double >( 2 ) = 0; 19 | this->m_filter.statePre.at< double >( 3 ) = 0; 20 | this->m_filter.statePost.at< double >( 0 ) = position.x; 21 | this->m_filter.statePost.at< double >( 1 ) = position.y; 22 | this->m_filter.statePost.at< double >( 2 ) = 0; 23 | this->m_filter.statePost.at< double >( 3 ) = 0; 24 | cv::setIdentity( this->m_filter.measurementMatrix ); 25 | cv::setIdentity( this->m_filter.processNoiseCov, cv::Scalar::all( 1e-4 ) ); 26 | cv::setIdentity( this->m_filter.measurementNoiseCov, cv::Scalar::all( 1e-4 ) ); 27 | cv::setIdentity( this->m_filter.errorCovPost, cv::Scalar::all( 0.1 ) ); 28 | } 29 | 30 | const cv::Point_< double > KalmanFilter2D::getPrediction() 31 | { 32 | cv::Point_< double > result; 33 | cv::Mat1d prediction = this->m_filter.predict(); 34 | 35 | result.x = prediction( 0 ); result.y = prediction( 1 ); 36 | 37 | return result; 38 | } 39 | 40 | const cv::Point_< double > KalmanFilter2D::getEstimate( const cv::Point_< double > & measurement ) 41 | { 42 | cv::Point_< double > result; 43 | cv::Mat1d measurementMatrix( 2, 1 ); 44 | 45 | measurementMatrix( 0 ) = measurement.x; measurementMatrix( 1 ) = measurement.y; 46 | 47 | cv::Mat1d estimate = this->m_filter.correct( measurementMatrix ); 48 | 49 | result.x = estimate( 0 ); result.y = estimate( 1 ); 50 | 51 | return result; 52 | } -------------------------------------------------------------------------------- /src/cf_libs/common/KalmanFilter2D.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of Kalman filter used in [1] 34 | 35 | References: 36 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 37 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 38 | */ 39 | 40 | #ifndef CFTRACKING_KALMANFILTER_H 41 | #define CFTRACKING_KALMANFILTER_H 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | class KalmanFilter2D 48 | { 49 | public: 50 | KalmanFilter2D(); 51 | ~KalmanFilter2D(); 52 | 53 | void initialise( const cv::Point_< double > & position ); 54 | 55 | const cv::Point_< double > getPrediction(); 56 | const cv::Point_< double > getEstimate( const cv::Point_< double > & measurement ); 57 | private: 58 | cv::KalmanFilter m_filter; 59 | }; 60 | 61 | #endif //CFTRACKING_KALMANFILTER_H 62 | -------------------------------------------------------------------------------- /src/cf_libs/common/Typedefs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _TYPEDEFS_HPP_ 2 | #define _TYPEDEFS_HPP_ 3 | 4 | typedef cv::Rect_< double > Rect; 5 | typedef cv::Point_< double > Point; 6 | typedef cv::Size_< double > Size; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/cf_libs/common/cf_tracker.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/common/cf_tracker.hpp 34 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 35 | // * We modified the original code of Klaus Haag by re-organizing the code to be fit within the DS-KCF framework 36 | */ 37 | 38 | #ifndef TRACKER_HPP_ 39 | #define TRACKER_HPP_ 40 | 41 | #include "opencv2/core/core.hpp" 42 | #include "tracker_debug.hpp" 43 | 44 | #include 45 | 46 | class CfTracker 47 | { 48 | public: 49 | virtual ~CfTracker() {}; 50 | 51 | /** 52 | * Updates the model using the the object located in the given bounding box. 53 | * 54 | * @param[in] frame The RGB and depth component of the current frame. 55 | * @param[in,out] boundingBox The bounding box of the tracked object. 56 | * 57 | * @returns True if the model was successfully updated, false otherwise. 58 | */ 59 | virtual bool update(const std::array< cv::Mat, 2 > & frame, cv::Rect_& boundingBox) = 0; 60 | 61 | /** 62 | * Updates the model using the the object located in the given bounding box. 63 | * 64 | * @param[in] frame The RGB and depth component of the current frame. 65 | * @param[in,out] boundingBox The bounding box of the tracked object. 66 | * 67 | * @returns True if the model was successfully updated, false otherwise. 68 | */ 69 | virtual bool update(const std::array< cv::Mat, 2 > & frame, cv::Rect_& boundingBox, std::vector &timePerformanceVector) = 0; 70 | 71 | /** 72 | * Initialises the model using the the object located in the given bounding box. 73 | * 74 | * @param[in] frame The RGB and depth component of the current frame. 75 | * @param[in,out] boundingBox The bounding box of the tracked object. 76 | * 77 | * @returns True if the model was successfully initialised, false otherwise. 78 | */ 79 | virtual bool reinit(const std::array< cv::Mat, 2 > & frame, cv::Rect_& boundingBox) = 0; 80 | 81 | virtual TrackerDebug* getTrackerDebug() = 0; 82 | virtual const std::string getId() = 0; 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/cf_libs/common/circularbuffer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jake on 08/08/15. 3 | // 4 | 5 | #ifndef CFTRACKING_CIRCULARBUFFER_HPP 6 | #define CFTRACKING_CIRCULARBUFFER_HPP 7 | 8 | #include 9 | #include 10 | 11 | template< class T, uint N > 12 | class circularbuffer 13 | { 14 | public: 15 | circularbuffer() 16 | { 17 | this->index = 0; 18 | } 19 | 20 | void push_back( const T & value ) 21 | { 22 | this->buffer[ this->index ] = value; 23 | 24 | this->index = ( this->index + 1 ) % N; 25 | } 26 | 27 | void push_back( T && value ) 28 | { 29 | this->buffer[ this->index ] = std::move( value ); 30 | 31 | this->index = ( this->index + 1 ) % N; 32 | } 33 | 34 | typename std::array< T, N >::const_iterator begin() const 35 | { 36 | return this->buffer.begin(); 37 | } 38 | 39 | typename std::array< T, N >::const_iterator end() const 40 | { 41 | return this->buffer.end(); 42 | }; 43 | 44 | typename std::array< T, N >::iterator begin() 45 | { 46 | return this->buffer.begin(); 47 | } 48 | 49 | typename std::array< T, N >::iterator end() 50 | { 51 | return this->buffer.end(); 52 | }; 53 | private: 54 | uint index; 55 | std::array< T, N > buffer; 56 | }; 57 | 58 | #endif //CFTRACKING_CIRCULARBUFFER_HPP 59 | -------------------------------------------------------------------------------- /src/cf_libs/common/cv_ext.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | #ifndef CV_EXT_HPP_ 33 | #define CV_EXT_HPP_ 34 | 35 | #include "math_spectrums.hpp" 36 | #include "shift.hpp" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/cf_libs/common/feature_channels.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/common/feature_channels.hpp 34 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 35 | // * We modified the original code of Klaus Haag by re-organizing the code to be fit within the DS-KCF framework 36 | */ 37 | #ifndef FHOG_FEATURE_CHANNELS_H_ 38 | #define FHOG_FEATURE_CHANNELS_H_ 39 | 40 | #include "opencv2/core/core.hpp" 41 | #include "math_helper.hpp" 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | class FeatureChannels_ 50 | { 51 | public: 52 | FeatureChannels_( const size_t channelCount = 31 ) 53 | { 54 | this->channels.resize( channelCount ); 55 | } 56 | 57 | virtual ~FeatureChannels_() 58 | { 59 | } 60 | 61 | static std::shared_ptr< FeatureChannels_ > concatFeatures( const std::shared_ptr< FeatureChannels_ > & left, const std::shared_ptr< FeatureChannels_ > & right ) 62 | { 63 | CV_Assert( left->numberOfChannels() == right->numberOfChannels() ); 64 | std::shared_ptr< FeatureChannels_ > result = std::make_shared< FeatureChannels_ >( left->numberOfChannels() + right->numberOfChannels() ); 65 | 66 | std::copy( left->channels.begin(), left->channels.end(), result->channels.begin() ); 67 | std::copy( right->channels.begin(), right->channels.end(), result->channels.begin() + left->numberOfChannels() ); 68 | 69 | return result; 70 | } 71 | 72 | static void mulValueFeatures(std::shared_ptr& m, const double & value) 73 | { 74 | tbb::parallel_for_each( m->channels.begin(), m->channels.end(), 75 | [value]( cv::Mat & m_ ) -> void 76 | { 77 | m_ *= value; 78 | } 79 | ); 80 | } 81 | 82 | static void addFeatures(std::shared_ptr& A, const std::shared_ptr& B) 83 | { 84 | CV_Assert( A->numberOfChannels() == B->numberOfChannels() ); 85 | 86 | tbb::parallel_for< size_t >( 0, A->numberOfChannels(), 1, 87 | [&A, &B]( size_t index ) -> void 88 | { 89 | A->channels[ index ] += B->channels[ index ]; 90 | } 91 | ); 92 | } 93 | 94 | static cv::Mat sumFeatures(const std::shared_ptr& x) 95 | { 96 | cv::Mat result = x->channels[0].clone(); 97 | 98 | for (size_t i = 1; i < x->numberOfChannels(); ++i) 99 | { 100 | result += x->channels[i]; 101 | } 102 | 103 | return result; 104 | } 105 | 106 | static void mulFeatures(std::shared_ptr& features, const cv::Mat& m) 107 | { 108 | tbb::parallel_for_each( features->channels.begin(), features->channels.end(), 109 | [&m]( cv::Mat & channel ) -> void 110 | { 111 | channel = channel.mul( m ); 112 | } 113 | ); 114 | } 115 | 116 | static std::shared_ptr dftFeatures( const std::shared_ptr& features, int flags = 0) 117 | { 118 | auto result = std::make_shared( features->numberOfChannels() ); 119 | 120 | tbb::parallel_for< size_t >( 0, result->numberOfChannels(), 1, 121 | [&features,&result,&flags]( size_t index ) -> void 122 | { 123 | cv::dft( features->channels[ index ], result->channels[ index ], flags ); 124 | } 125 | ); 126 | 127 | return result; 128 | } 129 | 130 | static std::shared_ptr idftFeatures( const std::shared_ptr& features) 131 | { 132 | auto result = std::make_shared( features->numberOfChannels() ); 133 | 134 | tbb::parallel_for< size_t >( 0, result->numberOfChannels(), 1, 135 | [&features,&result]( size_t index ) -> void 136 | { 137 | cv::idft( features->channels[ index ], result->channels[ index ], cv::DFT_REAL_OUTPUT | cv::DFT_SCALE ); 138 | } 139 | ); 140 | 141 | return result; 142 | } 143 | 144 | static double squaredNormFeaturesNoCcs(const std::shared_ptr& Af) 145 | { 146 | int n = Af->channels[0].rows * Af->channels[0].cols; 147 | double sum_ = 0; 148 | cv::Mat elemMul; 149 | 150 | for (size_t i = 0; i < Af->numberOfChannels(); ++i) 151 | { 152 | mulSpectrums(Af->channels[i], Af->channels[i], elemMul, 0, true); 153 | sum_ += static_cast< double >(cv::sum(elemMul)[0]); 154 | } 155 | 156 | return sum_ / n; 157 | } 158 | 159 | static std::shared_ptr mulSpectrumsFeatures( const std::shared_ptr& Af, const std::shared_ptr& Bf, bool conjBf) 160 | { 161 | CV_Assert( Af->numberOfChannels() == Bf->numberOfChannels() ); 162 | 163 | auto result = std::make_shared( Af->numberOfChannels() ); 164 | 165 | tbb::parallel_for< size_t >( 0, Af->numberOfChannels(), 1, 166 | [&Af, &Bf, &result, conjBf]( size_t index ) -> void 167 | { 168 | mulSpectrums( Af->channels[ index ], Bf->channels[ index ], result->channels[ index ], 0, conjBf ); 169 | } 170 | ); 171 | 172 | return result; 173 | } 174 | 175 | const size_t numberOfChannels() const 176 | { 177 | return this->channels.size(); 178 | } 179 | 180 | std::vector< cv::Mat > channels; 181 | }; 182 | 183 | typedef FeatureChannels_ FC; 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /src/cf_libs/common/mat_consts.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | #ifndef MAT_CONSTS_H_ 33 | #define MAT_CONSTS_H_ 34 | 35 | namespace mat_consts 36 | { 37 | template 38 | struct constants 39 | { 40 | const static T c0_5; 41 | const static T c2_0; 42 | }; 43 | 44 | template const T constants::c0_5 = static_cast(0.5); 45 | template const T constants::c2_0 = static_cast(2.0); 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/cf_libs/common/optional.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _OPTIONAL_HPP_ 2 | #define _OPTIONAL_HPP_ 3 | 4 | #include 5 | #include 6 | 7 | template< class T > 8 | class optional 9 | { 10 | public: 11 | class bad_optional_access : public std::exception 12 | { 13 | virtual const char * what() const throw() 14 | { 15 | return "Optional value not set"; 16 | } 17 | }; 18 | 19 | optional() 20 | { 21 | } 22 | 23 | optional( const optional< T > & value ) 24 | { 25 | this->m_value = std::make_shared< T >( value.m_value ); 26 | } 27 | 28 | optional( optional< T > && value ) 29 | { 30 | this->m_value = std::move( value.m_value ); 31 | } 32 | 33 | optional( const T & value ) 34 | { 35 | this->m_value = std::make_shared< T >( value ); 36 | } 37 | 38 | optional( T && value ) 39 | { 40 | this->m_value = std::make_shared< T >( std::move( value ) ); 41 | } 42 | 43 | ~optional() 44 | { 45 | } 46 | 47 | optional< T > & operator=( const optional< T > & value ) 48 | { 49 | this->m_value = std::make_shared< T >( value->value ); 50 | 51 | return *this; 52 | } 53 | 54 | optional< T > & operator=( optional< T > && value ) 55 | { 56 | this->m_value = std::move( value->m_value ); 57 | 58 | return *this; 59 | } 60 | 61 | optional< T > & operator=( const T & value ) 62 | { 63 | this->m_value = std::make_shared< T >( value ); 64 | 65 | return *this; 66 | } 67 | 68 | optional< T > & operator=( T && value ) 69 | { 70 | this->m_value = std::make_shared< T >( std::move( value->m_value ) ); 71 | 72 | return *this; 73 | } 74 | 75 | const T * operator->() const 76 | { 77 | return this->m_value.get(); 78 | } 79 | 80 | T * operator->() 81 | { 82 | return this->m_value.get(); 83 | } 84 | 85 | const T & operator*() const 86 | { 87 | return *this->m_value; 88 | } 89 | 90 | T & operator*() 91 | { 92 | return *this->m_value; 93 | } 94 | 95 | operator bool() const 96 | { 97 | return ( this->m_value != nullptr ); 98 | } 99 | 100 | T & value() 101 | { 102 | if( this->m_value ) 103 | { 104 | return *this->m_value; 105 | } 106 | else 107 | { 108 | throw bad_optional_access(); 109 | } 110 | } 111 | 112 | const T & value() const 113 | { 114 | if( this->m_value ) 115 | { 116 | return *this->m_value; 117 | } 118 | else 119 | { 120 | throw bad_optional_access(); 121 | } 122 | } 123 | private: 124 | std::shared_ptr< T > m_value; 125 | }; 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /src/cf_libs/common/tracker_debug.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | #ifndef TRACKER_DEBUG_HPP_ 33 | #define TRACKER_DEBUG_HPP_ 34 | 35 | class TrackerDebug 36 | { 37 | public: 38 | virtual ~TrackerDebug(){} 39 | 40 | virtual void init(std::string outputFilePath) = 0; 41 | virtual void printOnImage(cv::Mat& image) = 0; 42 | virtual void printConsoleOutput() = 0; 43 | virtual void printToFile() = 0; 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/ColourFeatureChannelProcessor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ColourFeatureChannelProcessor.h" 3 | 4 | const std::vector< std::shared_ptr< FC > > ColourFeatureChannelProcessor::concatenate( 5 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const 6 | { 7 | #ifdef WIN32 8 | std::vector< std::shared_ptr< FC > > result( 1 ); 9 | 10 | result[ 0 ] = featureChannels[ 0 ]; 11 | 12 | return result; 13 | #else 14 | return { featureChannels[ 0 ] }; 15 | #endif 16 | } 17 | 18 | const std::vector< cv::Mat > ColourFeatureChannelProcessor::concatenate( const std::vector< cv::Mat > & frame ) const 19 | { 20 | #ifdef WIN32 21 | std::vector< cv::Mat > result( 1 ); 22 | 23 | result[ 0 ] = frame[ 0 ]; 24 | 25 | return result; 26 | #else 27 | return { frame[ 0 ] }; 28 | #endif 29 | } 30 | 31 | const double ColourFeatureChannelProcessor::concatenate( const std::vector< double > & maxResponses ) const 32 | { 33 | return maxResponses[ 0 ]; 34 | } 35 | 36 | const cv::Point_< double > ColourFeatureChannelProcessor::concatenate( const std::vector< cv::Point_< double > > & positions ) const 37 | { 38 | return positions[ 0 ]; 39 | } 40 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/ColourFeatureChannelProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 34 | the feature concatenation (color+depth) presented in [1] is performed within this class 35 | 36 | References: 37 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 38 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 39 | */ 40 | #ifndef CFTRACKING_COLOURFEATURECHANNELPROCESSOR_H 41 | #define CFTRACKING_COLOURFEATURECHANNELPROCESSOR_H 42 | 43 | #include "FeatureChannelProcessor.hpp" 44 | 45 | class ColourFeatureChannelProcessor : public FeatureChannelProcessor 46 | { 47 | public: 48 | virtual const std::vector< std::shared_ptr< FC > > concatenate( 49 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const; 50 | virtual const std::vector< cv::Mat > concatenate( const std::vector< cv::Mat > & frame ) const; 51 | virtual const double concatenate( const std::vector< double > & maxResponses ) const; 52 | virtual const cv::Point_< double > concatenate( const std::vector< cv::Point_< double > > & positions ) const; 53 | }; 54 | 55 | 56 | #endif //CFTRACKING_COLOURFEATURECHANNELPROCESSOR_H 57 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/ConcatenateFeatureChannelProcessor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ConcatenateFeatureChannelProcessor.h" 3 | #include 4 | 5 | const std::vector< std::shared_ptr< FC > > ConcatenateFeatureChannelProcessor::concatenate( 6 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const 7 | { 8 | #ifdef WIN32 9 | std::vector< std::shared_ptr< FC > > result( 1 ); 10 | result[ 0 ] = featureChannels[ 0 ]; 11 | #else 12 | std::vector< std::shared_ptr< FC > > result = { featureChannels[ 0 ] }; 13 | #endif 14 | 15 | for( uint i = 1; i < featureChannels.size(); i++ ) 16 | { 17 | result[ 0 ] = FC::concatFeatures( result[ 0 ], featureChannels[ i ] ); 18 | } 19 | 20 | return result; 21 | } 22 | 23 | const std::vector< cv::Mat > ConcatenateFeatureChannelProcessor::concatenate( 24 | const std::vector< cv::Mat > & frame ) const 25 | { 26 | #ifdef WIN32 27 | std::vector< cv::Mat > result( 1 ); 28 | 29 | result[ 0 ] = frame[ 1 ]; 30 | 31 | return result; 32 | #else 33 | return { frame[ 1 ] }; 34 | #endif 35 | } 36 | 37 | const double ConcatenateFeatureChannelProcessor::concatenate( const std::vector< double > & maxResponses ) const 38 | { 39 | return std::accumulate( maxResponses.begin(), maxResponses.end(), 0.0 ) / static_cast< double >( maxResponses.size() ); 40 | } 41 | 42 | const cv::Point_< double > ConcatenateFeatureChannelProcessor::concatenate( const std::vector< cv::Point_< double > > & positions ) const 43 | { 44 | return positions[ 0 ]; 45 | } 46 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/ConcatenateFeatureChannelProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 34 | the feature concatenation (color+depth) presented in [1] is performed within this class 35 | 36 | References: 37 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 38 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 39 | */ 40 | 41 | #ifndef CFTRACKING_CONCATENATEFEATURECHANNELPROCESSOR_H 42 | #define CFTRACKING_CONCATENATEFEATURECHANNELPROCESSOR_H 43 | 44 | #include "FeatureChannelProcessor.hpp" 45 | 46 | class ConcatenateFeatureChannelProcessor : public FeatureChannelProcessor 47 | { 48 | public: 49 | virtual const std::vector< std::shared_ptr< FC > > concatenate( 50 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const; 51 | virtual const std::vector< cv::Mat > concatenate( const std::vector< cv::Mat > & frame ) const; 52 | virtual const double concatenate( const std::vector< double > & maxResponses ) const; 53 | virtual const cv::Point_< double > concatenate( const std::vector< cv::Point_< double > > & positions ) const; 54 | }; 55 | 56 | 57 | #endif //CFTRACKING_CONCATENATEFEATURECHANNELPROCESSOR_H 58 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/DepthFeatureChannelProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "DepthFeatureChannelProcessor.h" 2 | 3 | const std::vector< std::shared_ptr< FC > > DepthFeatureChannelProcessor::concatenate( 4 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const 5 | { 6 | #ifdef WIN32 7 | std::vector< std::shared_ptr< FC > > result( 1 ); 8 | 9 | result[ 0 ] = featureChannels[ 1 ]; 10 | 11 | return result; 12 | #else 13 | return { featureChannels[ 1 ] }; 14 | #endif 15 | } 16 | 17 | const std::vector< cv::Mat > DepthFeatureChannelProcessor::concatenate( const std::vector< cv::Mat > & frame ) const 18 | { 19 | #ifdef WIN32 20 | std::vector< cv::Mat > result( 1 ); 21 | 22 | result[ 0 ] = frame[ 1 ]; 23 | 24 | return result; 25 | #else 26 | return { frame[ 1 ] }; 27 | #endif 28 | } 29 | 30 | const double DepthFeatureChannelProcessor::concatenate( const std::vector< double > & maxResponses ) const 31 | { 32 | return maxResponses[ 0 ]; 33 | } 34 | 35 | const cv::Point_< double > DepthFeatureChannelProcessor::concatenate( 36 | const std::vector< cv::Point_< double > > & positions ) const 37 | { 38 | return positions[ 0 ]; 39 | } 40 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/DepthFeatureChannelProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 34 | the depth feature processor presented in [1] is performed within this class 35 | 36 | References: 37 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 38 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 39 | */ 40 | 41 | #ifndef CFTRACKING_DEPTHFEATURECHANNELPROCESSOR_H 42 | #define CFTRACKING_DEPTHFEATURECHANNELPROCESSOR_H 43 | 44 | #include "FeatureChannelProcessor.hpp" 45 | 46 | class DepthFeatureChannelProcessor : public FeatureChannelProcessor 47 | { 48 | virtual const std::vector< std::shared_ptr< FC > > concatenate( 49 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const; 50 | virtual const std::vector< cv::Mat > concatenate( const std::vector< cv::Mat > & frame ) const; 51 | virtual const double concatenate( const std::vector< double > & maxResponses ) const; 52 | virtual const cv::Point_< double > concatenate( const std::vector< cv::Point_< double > > & positions ) const; 53 | }; 54 | 55 | 56 | #endif //CFTRACKING_DEPTHFEATURECHANNELPROCESSOR_H 57 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/FeatureChannelProcessor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _FEATURECHANNELPROCESSOR_HPP_ 2 | #define _FEATURECHANNELPROCESSOR_HPP_ 3 | 4 | /* 5 | // License Agreement (3-clause BSD License) 6 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 7 | // Third party copyrights and patents are property of their respective owners. 8 | // 9 | // Redistribution and use in source and binary forms, with or without modification, 10 | // are permitted provided that the following conditions are met: 11 | // 12 | // * Redistributions of source code must retain the above copyright notice, 13 | // this list of conditions and the following disclaimer. 14 | // 15 | // * Redistributions in binary form must reproduce the above copyright notice, 16 | // this list of conditions and the following disclaimer in the documentation 17 | // and/or other materials provided with the distribution. 18 | // 19 | // * Neither the names of the copyright holders nor the names of the contributors 20 | // may be used to endorse or promote products derived from this software 21 | // without specific prior written permission. 22 | // 23 | // This software is provided by the copyright holders and contributors "as is" and 24 | // any express or implied warranties, including, but not limited to, the implied 25 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 26 | // In no event shall copyright holders or contributors be liable for any direct, 27 | // indirect, incidental, special, exemplary, or consequential damages 28 | // (including, but not limited to, procurement of substitute goods or services; 29 | // loss of use, data, or profits; or business interruption) however caused 30 | // and on any theory of liability, whether in contract, strict liability, 31 | // or tort (including negligence or otherwise) arising in any way out of 32 | // the use of this software, even if advised of the possibility of such damage. 33 | */ 34 | 35 | /* 36 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 37 | this class is a template class with virtual methods only. Other classes are derived from this class, such as 38 | ColourFeatureChannelProcessor 39 | 40 | References: 41 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 42 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 43 | */ 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | #include "feature_channels.hpp" 50 | 51 | /** 52 | * FeatureChannelProcessor is responsible for taking a collection of feature channels and processing them. 53 | */ 54 | class FeatureChannelProcessor 55 | { 56 | public: 57 | /** 58 | * Concatenate the feature channels. 59 | * 60 | * @param featureChannels The input collection of feature channels to be processed. 61 | * 62 | * @returns A new collection of processed feature channels. 63 | */ 64 | virtual const std::vector< std::shared_ptr< FC > > concatenate( 65 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const = 0; 66 | 67 | /** 68 | * Process the frame so that each element of the resulting collection is associated with the element in the feature channel collection. 69 | * 70 | * @param frame The collection of images for the current frame. 71 | * 72 | * @returns A collection ordered so that each element matches its associated feature channel. 73 | */ 74 | virtual const std::vector< cv::Mat > concatenate( const std::vector< cv::Mat > & frame ) const = 0; 75 | 76 | /** 77 | * Combine the maximum responses of each feature channel. 78 | * 79 | * @param maxResponses The maximum responses for each feature channel. 80 | * 81 | * @returns The combined maximum response. 82 | */ 83 | virtual const double concatenate( const std::vector< double > & maxResponses ) const = 0; 84 | 85 | /** 86 | * Combine the positions of each tracker 87 | * 88 | * @param positions The positions given my each tracker's detect call 89 | * 90 | * @returns The combined position 91 | */ 92 | virtual const cv::Point_< double > concatenate( const std::vector< cv::Point_< double > > & positions ) const = 0; 93 | }; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/FeatureExtractor.cpp: -------------------------------------------------------------------------------- 1 | #include "FeatureExtractor.hpp" 2 | 3 | FeatureExtractor::FeatureExtractor() 4 | { 5 | } 6 | 7 | FeatureExtractor::~FeatureExtractor() 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/FeatureExtractor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _FEATURE_EXTRACTOR_HPP_ 2 | #define _FEATURE_EXTRACTOR_HPP_ 3 | 4 | /* 5 | // License Agreement (3-clause BSD License) 6 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 7 | // Third party copyrights and patents are property of their respective owners. 8 | // 9 | // Redistribution and use in source and binary forms, with or without modification, 10 | // are permitted provided that the following conditions are met: 11 | // 12 | // * Redistributions of source code must retain the above copyright notice, 13 | // this list of conditions and the following disclaimer. 14 | // 15 | // * Redistributions in binary form must reproduce the above copyright notice, 16 | // this list of conditions and the following disclaimer in the documentation 17 | // and/or other materials provided with the distribution. 18 | // 19 | // * Neither the names of the copyright holders nor the names of the contributors 20 | // may be used to endorse or promote products derived from this software 21 | // without specific prior written permission. 22 | // 23 | // This software is provided by the copyright holders and contributors "as is" and 24 | // any express or implied warranties, including, but not limited to, the implied 25 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 26 | // In no event shall copyright holders or contributors be liable for any direct, 27 | // indirect, incidental, special, exemplary, or consequential damages 28 | // (including, but not limited to, procurement of substitute goods or services; 29 | // loss of use, data, or profits; or business interruption) however caused 30 | // and on any theory of liability, whether in contract, strict liability, 31 | // or tort (including negligence or otherwise) arising in any way out of 32 | // the use of this software, even if advised of the possibility of such damage. 33 | */ 34 | 35 | /* 36 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 37 | this class is a template class with virtual methods only. Other classes as for example 38 | HOGFeatureExtractor are derived from this class 39 | 40 | References: 41 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 42 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 43 | */ 44 | 45 | #include 46 | #include "feature_channels.hpp" 47 | #include 48 | 49 | class FeatureExtractor 50 | { 51 | public: 52 | FeatureExtractor(); 53 | virtual ~FeatureExtractor(); 54 | 55 | virtual std::shared_ptr< FC > getFeatures( const cv::Mat & image, const cv::Rect_< double > & boundingBox ) const = 0; 56 | 57 | private: 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/LinearFeatureChannelProcessor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "LinearFeatureChannelProcessor.h" 3 | #include 4 | 5 | const std::vector< std::shared_ptr< FC > > LinearFeatureChannelProcessor::concatenate( const std::vector< std::shared_ptr< FC > > & featureChannels ) const 6 | { 7 | return featureChannels; 8 | } 9 | 10 | const std::vector< cv::Mat > LinearFeatureChannelProcessor::concatenate( const std::vector< cv::Mat > & frame ) const 11 | { 12 | return frame; 13 | } 14 | 15 | const double LinearFeatureChannelProcessor::concatenate( const std::vector< double > & maxResponses ) const 16 | { 17 | return std::accumulate( maxResponses.begin(), maxResponses.end(), 0.0 ) / static_cast< double >( maxResponses.size() ); 18 | } 19 | 20 | const cv::Point_< double > LinearFeatureChannelProcessor::concatenate( const std::vector< cv::Point_< double > > & positions ) const 21 | { 22 | return std::accumulate( positions.begin(), positions.end(), cv::Point_< double >( 0, 0 ) ) * ( 1.0 / static_cast< double >( positions.size() ) ); 23 | } 24 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/LinearFeatureChannelProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 34 | this class is is used to obtain a linear combination of features 35 | 36 | References: 37 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 38 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 39 | */ 40 | #ifndef CFTRACKING_LINEARFEATURECHANNELPROCESSOR_H 41 | #define CFTRACKING_LINEARFEATURECHANNELPROCESSOR_H 42 | 43 | #include "FeatureChannelProcessor.hpp" 44 | 45 | 46 | class LinearFeatureChannelProcessor : public FeatureChannelProcessor 47 | { 48 | public: 49 | virtual const std::vector< std::shared_ptr< FC > > concatenate( 50 | const std::vector< std::shared_ptr< FC > > & featureChannels ) const; 51 | virtual const std::vector< cv::Mat > concatenate( const std::vector< cv::Mat > & frame ) const; 52 | virtual const double concatenate( const std::vector< double > & maxResponses ) const; 53 | virtual const cv::Point_< double > concatenate( const std::vector< cv::Point_< double > > & positions ) const; 54 | }; 55 | 56 | 57 | #endif //CFTRACKING_LINEARFEATURECHANNELPROCESSOR_H 58 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/ScaleAnalyser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _SCALEANALYSIS_HPP_ 2 | #define _SCALEANALYSIS_HPP_ 3 | /* 4 | // License Agreement (3-clause BSD License) 5 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 6 | // Third party copyrights and patents are property of their respective owners. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, 9 | // are permitted provided that the following conditions are met: 10 | // 11 | // * Redistributions of source code must retain the above copyright notice, 12 | // this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright notice, 15 | // this list of conditions and the following disclaimer in the documentation 16 | // and/or other materials provided with the distribution. 17 | // 18 | // * Neither the names of the copyright holders nor the names of the contributors 19 | // may be used to endorse or promote products derived from this software 20 | // without specific prior written permission. 21 | // 22 | // This software is provided by the copyright holders and contributors "as is" and 23 | // any express or implied warranties, including, but not limited to, the implied 24 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 25 | // In no event shall copyright holders or contributors be liable for any direct, 26 | // indirect, incidental, special, exemplary, or consequential damages 27 | // (including, but not limited to, procurement of substitute goods or services; 28 | // loss of use, data, or profits; or business interruption) however caused 29 | // and on any theory of liability, whether in contract, strict liability, 30 | // or tort (including negligence or otherwise) arising in any way out of 31 | // the use of this software, even if advised of the possibility of such damage. 32 | */ 33 | 34 | /* 35 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 36 | the scale change module presented in [1] is performed within this class 37 | 38 | References: 39 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 40 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 41 | */ 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include "DepthSegmenter.hpp" 51 | #include "ScaleChangeObserver.hpp" 52 | //This include file creates circular dependencies 53 | //FIX ME! 54 | //#include "kcf_tracker.hpp" 55 | class KcfTracker; 56 | 57 | /** 58 | * ScaleAnalyser implements the detection and handling of scale changes as describe in section 3.2 of \cite DSKCF. 59 | */ 60 | class ScaleAnalyser 61 | { 62 | public: 63 | ScaleAnalyser( DepthSegmenter * depthSegmenter, double padding ); 64 | ScaleAnalyser( const std::vector< double > & scales, const double outputSigmaFactor, const int cellSize, double padding ); 65 | 66 | cv::Rect_< double > init( const cv::Mat & image, const cv::Rect_< double > & boundingBox ); 67 | cv::Rect_< double > update( const cv::Mat & image, const cv::Rect_< double > & boundingBox ); 68 | 69 | double getScaleFactor() const; 70 | 71 | void registerScaleChangeObserver( ScaleChangeObserver * observer ); 72 | void clearObservers(); 73 | 74 | std::vector< std::shared_ptr< KcfTracker > > createModelScales( std::shared_ptr< KcfTracker > tracker ); 75 | 76 | static cv::Mat2d scaleImageFourier( const cv::Mat2d & image, const cv::Size2i & size ); 77 | static cv::Mat2d scaleImageFourierShift( const cv::Mat2d & image, const cv::Size2i & size ); 78 | private: 79 | size_t m_i; 80 | int m_cellSize; 81 | double m_padding; 82 | double m_outputSigmaFactor; 83 | double m_minStep; 84 | double m_step; 85 | double m_currentDepth; 86 | double m_initialDepth; 87 | double m_scaleFactor; 88 | 89 | DepthSegmenter * m_depthSegmenter; 90 | 91 | std::vector< double > m_scales; 92 | std::vector< cv::Size_< double > > m_windowSizes; 93 | std::vector< cv::Size_< double > > m_targetSizes; 94 | std::vector< cv::Point_< double > > m_targetPositions; 95 | std::vector< double > m_outputSigmas; 96 | std::vector< cv::Mat2d > m_yfs; 97 | std::vector< cv::Mat1d > m_cosineWindows; 98 | std::vector< ScaleChangeObserver* > m_observers; 99 | }; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/ScaleChangeObserver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _SCALECHANGEOBSERVER_HPP_ 2 | #define _SCALECHANGEOBSERVER_HPP_ 3 | /* 4 | // License Agreement (3-clause BSD License) 5 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 6 | // Third party copyrights and patents are property of their respective owners. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, 9 | // are permitted provided that the following conditions are met: 10 | // 11 | // * Redistributions of source code must retain the above copyright notice, 12 | // this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright notice, 15 | // this list of conditions and the following disclaimer in the documentation 16 | // and/or other materials provided with the distribution. 17 | // 18 | // * Neither the names of the copyright holders nor the names of the contributors 19 | // may be used to endorse or promote products derived from this software 20 | // without specific prior written permission. 21 | // 22 | // This software is provided by the copyright holders and contributors "as is" and 23 | // any express or implied warranties, including, but not limited to, the implied 24 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 25 | // In no event shall copyright holders or contributors be liable for any direct, 26 | // indirect, incidental, special, exemplary, or consequential damages 27 | // (including, but not limited to, procurement of substitute goods or services; 28 | // loss of use, data, or profits; or business interruption) however caused 29 | // and on any theory of liability, whether in contract, strict liability, 30 | // or tort (including negligence or otherwise) arising in any way out of 31 | // the use of this software, even if advised of the possibility of such damage. 32 | */ 33 | 34 | /* 35 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 36 | the scaling system presented in [1] is implemented within this class 37 | 38 | References: 39 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 40 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 41 | */ 42 | 43 | #include "Typedefs.hpp" 44 | 45 | /** 46 | * ScaleChangeObserver is an abstract class. 47 | * This class is designed to be derived by any class which needs to observe 48 | * a ScaleAnalyser. An instance of ScaleChangeObserver should only be 49 | * registered to observe a single ScaleAnalyser. 50 | */ 51 | class ScaleChangeObserver 52 | { 53 | public: 54 | /** 55 | * onScaleChange is called whenever a scale change has been detected. 56 | * @param targetSize The new size of the target object's bounding box. 57 | * @param windowSize The new padded size of the bounding box around the target. 58 | * @param yf The new gaussian shaped labels for this scale. 59 | * @param cosineWindow The new cosine window for this scale. 60 | * 61 | * @warning If an instance of this class is registered to observe multiple 62 | * ScaleAnalyser, then this method will likely cause a crash. 63 | */ 64 | virtual void onScaleChange( const Size & targetSize, const Size & windowSize, const cv::Mat2d & yf, const cv::Mat1d & cosineWindow ) = 0; 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/dskcf_tracker.cpp: -------------------------------------------------------------------------------- 1 | #include "dskcf_tracker.hpp" 2 | 3 | #include "GaussianKernel.hpp" 4 | #include "HOGFeatureExtractor.hpp" 5 | #include "ConcatenateFeatureChannelProcessor.h" 6 | 7 | typedef cv::Rect_< double > Rect; 8 | 9 | DskcfTracker::DskcfTracker() 10 | { 11 | std::shared_ptr< Kernel > kernel = std::make_shared< GaussianKernel >(); 12 | std::shared_ptr< FeatureExtractor > features = std::make_shared< HOGFeatureExtractor >(); 13 | std::shared_ptr< FeatureChannelProcessor > processor = std::make_shared< ConcatenateFeatureChannelProcessor >(); 14 | 15 | this->m_occlusionHandler = std::make_shared< OcclusionHandler >(KcfParameters(), kernel, features, processor); 16 | } 17 | 18 | DskcfTracker::~DskcfTracker() 19 | { 20 | } 21 | 22 | bool DskcfTracker::update(const std::array< cv::Mat, 2 > & frame, Rect & boundingBox) 23 | { 24 | Point position = centerPoint(boundingBox); 25 | 26 | boundingBox = (this->m_occlusionHandler->detect(frame, position)); 27 | 28 | position = centerPoint(boundingBox); 29 | 30 | this->m_occlusionHandler->update(frame, position); 31 | 32 | return !this->m_occlusionHandler->isOccluded(); 33 | } 34 | 35 | bool DskcfTracker::update(const std::array< cv::Mat, 2 > & frame, cv::Rect_& boundingBox, std::vector &timePerformanceVector) 36 | 37 | { 38 | int64 tStart = cv::getTickCount(); 39 | 40 | Point position = centerPoint(boundingBox); 41 | 42 | boundingBox = (this->m_occlusionHandler->detect(frame, position)); 43 | 44 | position = centerPoint(boundingBox); 45 | 46 | this->m_occlusionHandler->update(frame, position); 47 | 48 | int64 tStop = cv::getTickCount(); 49 | 50 | int lastElement = (int)timePerformanceVector.size() - 1; 51 | timePerformanceVector = this->m_occlusionHandler->singleFrameProTime; 52 | //re-init the vector 53 | this->m_occlusionHandler->singleFrameProTime = std::vector(8, 0); 54 | timePerformanceVector[lastElement] = tStop - tStart; 55 | 56 | return !this->m_occlusionHandler->isOccluded(); 57 | 58 | } 59 | 60 | bool DskcfTracker::reinit(const std::array< cv::Mat, 2 > & frame, Rect & boundingBox) 61 | { 62 | std::shared_ptr< Kernel > kernel = std::make_shared< GaussianKernel >(); 63 | std::shared_ptr< FeatureExtractor > features = std::make_shared< HOGFeatureExtractor >(); 64 | std::shared_ptr< FeatureChannelProcessor > processor = std::make_shared< ConcatenateFeatureChannelProcessor >(); 65 | 66 | this->m_occlusionHandler = std::make_shared< OcclusionHandler >(KcfParameters(), kernel, features, processor); 67 | 68 | this->m_occlusionHandler->init(frame, boundingBox); 69 | 70 | return true; 71 | } 72 | 73 | TrackerDebug* DskcfTracker::getTrackerDebug() 74 | { 75 | return nullptr; 76 | } 77 | 78 | const std::string DskcfTracker::getId() 79 | { 80 | return "DSKCF"; 81 | } 82 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/dskcf_tracker.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _DSKCF_TRACKER_HPP_ 2 | #define _DSKCF_TRACKER_HPP_ 3 | /* 4 | // License Agreement (3-clause BSD License) 5 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 6 | // Third party copyrights and patents are property of their respective owners. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, 9 | // are permitted provided that the following conditions are met: 10 | // 11 | // * Redistributions of source code must retain the above copyright notice, 12 | // this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright notice, 15 | // this list of conditions and the following disclaimer in the documentation 16 | // and/or other materials provided with the distribution. 17 | // 18 | // * Neither the names of the copyright holders nor the names of the contributors 19 | // may be used to endorse or promote products derived from this software 20 | // without specific prior written permission. 21 | // 22 | // This software is provided by the copyright holders and contributors "as is" and 23 | // any express or implied warranties, including, but not limited to, the implied 24 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 25 | // In no event shall copyright holders or contributors be liable for any direct, 26 | // indirect, incidental, special, exemplary, or consequential damages 27 | // (including, but not limited to, procurement of substitute goods or services; 28 | // loss of use, data, or profits; or business interruption) however caused 29 | // and on any theory of liability, whether in contract, strict liability, 30 | // or tort (including negligence or otherwise) arising in any way out of 31 | // the use of this software, even if advised of the possibility of such damage. 32 | */ 33 | 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "cf_tracker.hpp" 41 | #include "kcf_tracker.hpp" 42 | #include "math_helper.hpp" 43 | #include "DepthSegmenter.hpp" 44 | #include "ScaleAnalyser.hpp" 45 | #include "FeatureExtractor.hpp" 46 | #include "OcclusionHandler.hpp" 47 | #include "ScaleChangeObserver.hpp" 48 | 49 | /** 50 | * DskcfTracker implements a depth scaling kernelised correlation filter as 51 | * described in \cite DSKCF. 52 | * 53 | * [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 54 | * DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 55 | */ 56 | class DskcfTracker : public CfTracker 57 | { 58 | public: 59 | DskcfTracker(); 60 | virtual ~DskcfTracker(); 61 | virtual bool update(const std::array< cv::Mat, 2 > & frame, cv::Rect_< double > & boundingBox); 62 | virtual bool update(const std::array< cv::Mat, 2 > & frame, cv::Rect_& boundingBox, std::vector &timePerformanceVector); 63 | virtual bool reinit(const std::array< cv::Mat, 2 > & frame, cv::Rect_< double > & boundingBox); 64 | 65 | virtual TrackerDebug* getTrackerDebug(); 66 | virtual const std::string getId(); 67 | private: 68 | 69 | /** The occlusion handler associated with this object */ 70 | std::shared_ptr< OcclusionHandler > m_occlusionHandler; 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/dskcf_tracker_run.cpp: -------------------------------------------------------------------------------- 1 | #include "dskcf_tracker_run.hpp" 2 | #include "dskcf_tracker.hpp" 3 | 4 | DskcfTrackerRun::DskcfTrackerRun() : TrackerRun( "DSKCF" ) 5 | { 6 | } 7 | 8 | DskcfTrackerRun::~DskcfTrackerRun() 9 | { 10 | } 11 | 12 | CfTracker * DskcfTrackerRun::parseTrackerParas(TCLAP::CmdLine& cmd, int argc, const char** argv) 13 | { 14 | TCLAP::SwitchArg rawDepth( "", "raw_depth", "", cmd, false ); 15 | TCLAP::SwitchArg rawColour( "", "raw_colour", "", cmd, false ); 16 | TCLAP::SwitchArg rawConcatenate( "", "raw_concatenate", "", cmd, false ); 17 | TCLAP::SwitchArg rawLinear( "", "raw_linear", "", cmd, false ); 18 | TCLAP::SwitchArg hogColour( "", "hog_colour", "", cmd, false ); 19 | TCLAP::SwitchArg hogDepth( "", "hog_depth", "", cmd, false ); 20 | TCLAP::SwitchArg hogConcatenate( "", "hog_concatenate", "", cmd, true ); 21 | TCLAP::SwitchArg hogLinear( "", "hog_linear", "", cmd, false ); 22 | 23 | cmd.parse( argc, argv ); 24 | 25 | return new DskcfTracker( ); 26 | } 27 | -------------------------------------------------------------------------------- /src/cf_libs/dskcf/dskcf_tracker_run.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _DSKCF_TRACKER_RUN_HPP_ 2 | #define _DSKCF_TRACKER_RUN_HPP_ 3 | 4 | /* 5 | // License Agreement (3-clause BSD License) 6 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 7 | // Third party copyrights and patents are property of their respective owners. 8 | // 9 | // Redistribution and use in source and binary forms, with or without modification, 10 | // are permitted provided that the following conditions are met: 11 | // 12 | // * Redistributions of source code must retain the above copyright notice, 13 | // this list of conditions and the following disclaimer. 14 | // 15 | // * Redistributions in binary form must reproduce the above copyright notice, 16 | // this list of conditions and the following disclaimer in the documentation 17 | // and/or other materials provided with the distribution. 18 | // 19 | // * Neither the names of the copyright holders nor the names of the contributors 20 | // may be used to endorse or promote products derived from this software 21 | // without specific prior written permission. 22 | // 23 | // This software is provided by the copyright holders and contributors "as is" and 24 | // any express or implied warranties, including, but not limited to, the implied 25 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 26 | // In no event shall copyright holders or contributors be liable for any direct, 27 | // indirect, incidental, special, exemplary, or consequential damages 28 | // (including, but not limited to, procurement of substitute goods or services; 29 | // loss of use, data, or profits; or business interruption) however caused 30 | // and on any theory of liability, whether in contract, strict liability, 31 | // or tort (including negligence or otherwise) arising in any way out of 32 | // the use of this software, even if advised of the possibility of such damage. 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | #include "tracker_run.hpp" 40 | 41 | class DskcfTrackerRun : public TrackerRun 42 | { 43 | public: 44 | DskcfTrackerRun(); 45 | virtual ~DskcfTrackerRun(); 46 | protected: 47 | virtual CfTracker* parseTrackerParas(TCLAP::CmdLine& cmd, int argc, const char** argv); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/DepthWeightKCFTracker.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "DepthWeightKCFTracker.h" 3 | #include "math_helper.hpp" 4 | 5 | DepthWeightKCFTracker::DepthWeightKCFTracker( KcfParameters paras, std::shared_ptr< Kernel > kernel ) : KcfTracker( paras, kernel ) 6 | { 7 | this->m_cellSize = paras.cellSize; 8 | } 9 | 10 | DepthWeightKCFTracker::~DepthWeightKCFTracker() 11 | { 12 | } 13 | 14 | const DetectResult DepthWeightKCFTracker::detect( const cv::Mat & image, const std::shared_ptr< FC > & features, 15 | const cv::Point_< double > & position, const double depth, const double std ) const 16 | { 17 | //If this is a depth map, give the depth weighted max response. 18 | //Otherwise give the default kcf max response. 19 | if( image.type() == CV_16UC1 ) 20 | { 21 | DetectResult result; 22 | Response newResponse = this->getResponse( image, features, cv::Point_< double >( position.x, position.y ) ); 23 | std::vector< cv::MatIterator_< double > > pixels; 24 | 25 | for( cv::MatIterator_< double > itr = newResponse.response.begin(); itr != newResponse.response.end(); itr++ ) 26 | { 27 | pixels.push_back( itr ); 28 | } 29 | 30 | std::sort( pixels.begin(), pixels.end(), 31 | []( cv::MatIterator_< double > a, cv::MatIterator_< double > b ) -> bool 32 | { 33 | return (*a) > (*b); 34 | } 35 | ); 36 | 37 | double absoluteMax=*pixels[ 0 ]; 38 | 39 | for( int i = 0; i < std::min< int >( 20, pixels.size() ); i++ ) 40 | { 41 | cv::Point_< double > subDelta = subPixelDelta< double >( newResponse.response, pixels[ i ].pos() ); 42 | 43 | if( subDelta.x > newResponse.response.cols / 2 ) 44 | { 45 | subDelta.x -= newResponse.response.cols; 46 | } 47 | 48 | if( subDelta.y > newResponse.response.rows / 2 ) 49 | { 50 | subDelta.y -= newResponse.response.rows; 51 | } 52 | 53 | cv::Point posImagePlane = position + ( this->m_cellSize * subDelta ); 54 | posImagePlane.x = std::max( 0, std::min( image.cols - 1, posImagePlane.x ) ); 55 | posImagePlane.y = std::max( 0, std::min( image.rows - 1, posImagePlane.y ) ); 56 | double _depth = image.at< ushort >( posImagePlane ); 57 | 58 | *pixels[ i ] *= weightDistanceLogisticOnDepth( depth, _depth, std ); 59 | } 60 | 61 | auto itr = std::max_element( pixels.begin(), pixels.begin()+20, []( cv::MatIterator_< double > a, cv::MatIterator_< double > b ) -> bool { return (*a) < (*b); } ); 62 | newResponse.maxResponse = **itr; 63 | newResponse.maxResponsePosition = itr->pos(); 64 | cv::Point_< double > subDelta = subPixelDelta< double >( newResponse.response, newResponse.maxResponsePosition ); 65 | 66 | if( subDelta.x > newResponse.response.cols / 2 ) 67 | { 68 | subDelta.x -= newResponse.response.cols; 69 | } 70 | 71 | if( subDelta.y > newResponse.response.rows / 2 ) 72 | { 73 | subDelta.y -= newResponse.response.rows; 74 | }; 75 | 76 | 77 | result.maxResponse = absoluteMax; 78 | result.position = position + ( this->m_cellSize * subDelta ); 79 | 80 | return result; 81 | } 82 | else 83 | { 84 | return KcfTracker::detect( image, features, position ); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/DepthWeightKCFTracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2016, Jake Hall, Massimo Camplan, Sion Hannuna. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | This class represents a C++ implementation of the DS-KCF Tracker [1]. In particular 34 | the weighted response based on depth data presented in [1] is performed within this class 35 | 36 | References: 37 | [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T. Burghardt, A. Paiement, L. Tao, 38 | DS-KCF: A ~real-time tracker for RGB-D data, Journal of Real-Time Image Processing 39 | */ 40 | #ifndef CFTRACKING_DEPTHWEIGHTKCFTRACKER_H 41 | #define CFTRACKING_DEPTHWEIGHTKCFTRACKER_H 42 | 43 | #include "kcf_tracker.hpp" 44 | 45 | class DepthWeightKCFTracker : public KcfTracker 46 | { 47 | public: 48 | DepthWeightKCFTracker( KcfParameters paras, std::shared_ptr< Kernel > kernel ); 49 | virtual ~DepthWeightKCFTracker(); 50 | 51 | const DetectResult detect( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & position, const double depth, const double std ) const; 52 | private: 53 | int m_cellSize; 54 | }; 55 | 56 | 57 | #endif //CFTRACKING_DEPTHWEIGHTKCFTRACKER_H 58 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/GaussianKernel.cpp: -------------------------------------------------------------------------------- 1 | #include "GaussianKernel.hpp" 2 | 3 | GaussianKernel::GaussianKernel() 4 | { 5 | this->sigma = 0.5; 6 | } 7 | 8 | cv::Mat GaussianKernel::correlation(const std::shared_ptr< FC > & xf, const std::shared_ptr< FC > & yf) const 9 | { 10 | double xx, yy, numel; 11 | cv::Mat xy, kf; 12 | std::shared_ptr< FC > xyf, realXy; 13 | 14 | if (xf == yf) 15 | { 16 | yy = xx = FC::squaredNormFeaturesNoCcs(xf); 17 | } 18 | else 19 | { 20 | xx = FC::squaredNormFeaturesNoCcs(xf); 21 | yy = FC::squaredNormFeaturesNoCcs(yf); 22 | } 23 | 24 | xyf = FC::mulSpectrumsFeatures(xf, yf, true); 25 | realXy = FC::idftFeatures(xyf); 26 | 27 | xy = FC::sumFeatures(realXy); 28 | 29 | numel = static_cast(xf->channels[0].total() * xf->numberOfChannels()); 30 | this->calculateGaussianTerm(xy, numel, xx, yy); 31 | 32 | dft(xy, kf, cv::DFT_COMPLEX_OUTPUT); 33 | 34 | return kf; 35 | } 36 | 37 | void GaussianKernel::calculateGaussianTerm(cv::Mat & xy, double numel, double xx, double yy) const 38 | { 39 | int width = xy.cols; 40 | int height = xy.rows; 41 | 42 | width *= height; 43 | height = 1; 44 | 45 | const double summands = xx + yy; 46 | const double fraction = -1 / (this->sigma * this->sigma); 47 | 48 | for (int row = 0; row < height; ++row) 49 | { 50 | double* xyd = xy.ptr< double >(row); 51 | 52 | for (int col = 0; col < width; ++col) 53 | { 54 | xyd[col] = (summands - 2 * xyd[col]) / numel; 55 | 56 | if (xyd[col] < 0) 57 | { 58 | xyd[col] = 0; 59 | } 60 | 61 | xyd[col] *= fraction; 62 | xyd[col] = exp(xyd[col]); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/GaussianKernel.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _GAUSSIANKERNEL_HPP_ 2 | #define _GAUSSIANKERNEL_HPP_ 3 | 4 | /* 5 | // License Agreement (3-clause BSD License) 6 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 7 | // Third party copyrights and patents are property of their respective owners. 8 | // 9 | // Redistribution and use in source and binary forms, with or without modification, 10 | // are permitted provided that the following conditions are met: 11 | // 12 | // * Redistributions of source code must retain the above copyright notice, 13 | // this list of conditions and the following disclaimer. 14 | // 15 | // * Redistributions in binary form must reproduce the above copyright notice, 16 | // this list of conditions and the following disclaimer in the documentation 17 | // and/or other materials provided with the distribution. 18 | // 19 | // * Neither the names of the copyright holders nor the names of the contributors 20 | // may be used to endorse or promote products derived from this software 21 | // without specific prior written permission. 22 | // 23 | // This software is provided by the copyright holders and contributors "as is" and 24 | // any express or implied warranties, including, but not limited to, the implied 25 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 26 | // In no event shall copyright holders or contributors be liable for any direct, 27 | // indirect, incidental, special, exemplary, or consequential damages 28 | // (including, but not limited to, procurement of substitute goods or services; 29 | // loss of use, data, or profits; or business interruption) however caused 30 | // and on any theory of liability, whether in contract, strict liability, 31 | // or tort (including negligence or otherwise) arising in any way out of 32 | // the use of this software, even if advised of the possibility of such damage. 33 | */ 34 | 35 | /* 36 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/kcf/kcf_tracker.hpp 37 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 38 | // * We modified the original code of Klaus Haag, such that different classes are used for the different KCF components 39 | // In this case this class is used to calculate the GuassianKernel as in [1] for the KCF core filtering 40 | 41 | It is implemented closely to the Matlab implementation by the original authors: 42 | http://home.isr.uc.pt/~henriques/circulant/ 43 | However, some implementation details differ and some difference in performance 44 | has to be expected. 45 | 46 | This specific implementation features the scale adaption, sub-pixel 47 | accuracy for the correlation response evaluation and a more robust 48 | filter update scheme [2] used by Henriques, et al. in the VOT Challenge 2014. 49 | 50 | As default scale adaption, the tracker uses the 1D scale filter 51 | presented in [3]. The scale filter can be found in scale_estimator.hpp. 52 | Additionally, target loss detection is implemented according to [4]. 53 | 54 | Every complex matrix is as default in CCS packed form: 55 | see : https://software.intel.com/en-us/node/504243 56 | and http://docs.opencv.org/modules/core/doc/operations_on_arrays.html 57 | 58 | References: 59 | [1] J. Henriques, et al., 60 | "High-Speed Tracking with Kernelized Correlation Filters," 61 | PAMI, 2015. 62 | 63 | [2] M. Danelljan, et al., 64 | �Adaptive Color Attributes for Real-Time Visual Tracking,� 65 | in Proc. CVPR, 2014. 66 | 67 | [3] M. Danelljan, 68 | "Accurate Scale Estimation for Robust Visual Tracking," 69 | Proceedings of the British Machine Vision Conference BMVC, 2014. 70 | 71 | [4] D. Bolme, et al., 72 | �Visual Object Tracking using Adaptive Correlation Filters,� 73 | in Proc. CVPR, 2010. 74 | */ 75 | 76 | 77 | #include "Kernel.hpp" 78 | 79 | class GaussianKernel : public Kernel 80 | { 81 | public: 82 | GaussianKernel(); 83 | 84 | virtual cv::Mat correlation(const std::shared_ptr< FC > & xf, const std::shared_ptr< FC > & yf) const; 85 | private: 86 | double sigma; 87 | 88 | void calculateGaussianTerm(cv::Mat & xy, double numel, double xx, double yy) const; 89 | }; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/HOGFeatureExtractor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "HOGFeatureExtractor.hpp" 4 | #include "gradientMex.hpp" 5 | 6 | HOGFeatureExtractor::HOGFeatureExtractor() 7 | { 8 | this->m_cellSize = 4; 9 | } 10 | 11 | HOGFeatureExtractor::~HOGFeatureExtractor() 12 | { 13 | } 14 | 15 | std::shared_ptr< FC > HOGFeatureExtractor::getFeatures( const cv::Mat & image, 16 | const cv::Rect_< double > & boundingBox ) const 17 | { 18 | cv::Mat patch; 19 | 20 | if( getSubWindow< double >( image, patch, boundingBox.size(), centerPoint( boundingBox ) ) ) 21 | { 22 | cv::Mat patchResizedFloat; 23 | patch.convertTo(patchResizedFloat, CV_32FC(3)); 24 | 25 | auto features = std::make_shared< FC >(); 26 | piotr::cvFhog< double, FC >(patchResizedFloat, features, this->m_cellSize); 27 | 28 | return features; 29 | } 30 | else 31 | { 32 | std::cerr << "Error : HOGFeatureExtractor::getFeatures : getSubWindow failed!" << std::endl; 33 | } 34 | 35 | return nullptr; 36 | } 37 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/HOGFeatureExtractor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _HOGFEATURES_HPP_ 2 | #define _HOGFEATURES_HPP_ 3 | 4 | /* 5 | // License Agreement (3-clause BSD License) 6 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 7 | // Third party copyrights and patents are property of their respective owners. 8 | // 9 | // Redistribution and use in source and binary forms, with or without modification, 10 | // are permitted provided that the following conditions are met: 11 | // 12 | // * Redistributions of source code must retain the above copyright notice, 13 | // this list of conditions and the following disclaimer. 14 | // 15 | // * Redistributions in binary form must reproduce the above copyright notice, 16 | // this list of conditions and the following disclaimer in the documentation 17 | // and/or other materials provided with the distribution. 18 | // 19 | // * Neither the names of the copyright holders nor the names of the contributors 20 | // may be used to endorse or promote products derived from this software 21 | // without specific prior written permission. 22 | // 23 | // This software is provided by the copyright holders and contributors "as is" and 24 | // any express or implied warranties, including, but not limited to, the implied 25 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 26 | // In no event shall copyright holders or contributors be liable for any direct, 27 | // indirect, incidental, special, exemplary, or consequential damages 28 | // (including, but not limited to, procurement of substitute goods or services; 29 | // loss of use, data, or profits; or business interruption) however caused 30 | // and on any theory of liability, whether in contract, strict liability, 31 | // or tort (including negligence or otherwise) arising in any way out of 32 | // the use of this software, even if advised of the possibility of such damage. 33 | */ 34 | 35 | /* 36 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/kcf/kcf_tracker.hpp 37 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 38 | // * We modified the original code of Klaus Haag, such that different classes are used for the different KCF components 39 | // In this case this class is used to calculate the HOG features as in [1] for the KCF core filtering 40 | 41 | It is implemented closely to the Matlab implementation by the original authors: 42 | http://home.isr.uc.pt/~henriques/circulant/ 43 | However, some implementation details differ and some difference in performance 44 | has to be expected. 45 | 46 | This specific implementation features the scale adaption, sub-pixel 47 | accuracy for the correlation response evaluation and a more robust 48 | filter update scheme [2] used by Henriques, et al. in the VOT Challenge 2014. 49 | 50 | As default scale adaption, the tracker uses the 1D scale filter 51 | presented in [3]. The scale filter can be found in scale_estimator.hpp. 52 | Additionally, target loss detection is implemented according to [4]. 53 | 54 | Every complex matrix is as default in CCS packed form: 55 | see : https://software.intel.com/en-us/node/504243 56 | and http://docs.opencv.org/modules/core/doc/operations_on_arrays.html 57 | 58 | References: 59 | [1] J. Henriques, et al., 60 | "High-Speed Tracking with Kernelized Correlation Filters," 61 | PAMI, 2015. 62 | 63 | [2] M. Danelljan, et al., 64 | �Adaptive Color Attributes for Real-Time Visual Tracking,� 65 | in Proc. CVPR, 2014. 66 | 67 | [3] M. Danelljan, 68 | "Accurate Scale Estimation for Robust Visual Tracking," 69 | Proceedings of the British Machine Vision Conference BMVC, 2014. 70 | 71 | [4] D. Bolme, et al., 72 | �Visual Object Tracking using Adaptive Correlation Filters,� 73 | in Proc. CVPR, 2010. 74 | */ 75 | 76 | #include "FeatureExtractor.hpp" 77 | #include "feature_channels.hpp" 78 | 79 | class HOGFeatureExtractor : public FeatureExtractor 80 | { 81 | public: 82 | HOGFeatureExtractor(); 83 | virtual ~HOGFeatureExtractor(); 84 | 85 | virtual std::shared_ptr< FC > getFeatures( 86 | const cv::Mat & image, 87 | const cv::Rect_< double > & boundingBox 88 | ) const; 89 | private: 90 | int m_cellSize; 91 | }; 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/Kernel.cpp: -------------------------------------------------------------------------------- 1 | #include "Kernel.hpp" 2 | 3 | Kernel::Kernel() 4 | { 5 | } 6 | 7 | Kernel::~Kernel() 8 | { 9 | } -------------------------------------------------------------------------------- /src/cf_libs/kcf/Kernel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/kcf/kcf_tracker.hpp 34 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 35 | // * We modified the original code of Klaus Haag, such that different classes are used for the different KCF components 36 | 37 | It is implemented closely to the Matlab implementation by the original authors: 38 | http://home.isr.uc.pt/~henriques/circulant/ 39 | However, some implementation details differ and some difference in performance 40 | has to be expected. 41 | 42 | This specific implementation features the scale adaption, sub-pixel 43 | accuracy for the correlation response evaluation and a more robust 44 | filter update scheme [2] used by Henriques, et al. in the VOT Challenge 2014. 45 | 46 | As default scale adaption, the tracker uses the 1D scale filter 47 | presented in [3]. The scale filter can be found in scale_estimator.hpp. 48 | Additionally, target loss detection is implemented according to [4]. 49 | 50 | Every complex matrix is as default in CCS packed form: 51 | see : https://software.intel.com/en-us/node/504243 52 | and http://docs.opencv.org/modules/core/doc/operations_on_arrays.html 53 | 54 | References: 55 | [1] J. Henriques, et al., 56 | "High-Speed Tracking with Kernelized Correlation Filters," 57 | PAMI, 2015. 58 | 59 | [2] M. Danelljan, et al., 60 | �Adaptive Color Attributes for Real-Time Visual Tracking,� 61 | in Proc. CVPR, 2014. 62 | 63 | [3] M. Danelljan, 64 | "Accurate Scale Estimation for Robust Visual Tracking," 65 | Proceedings of the British Machine Vision Conference BMVC, 2014. 66 | 67 | [4] D. Bolme, et al., 68 | �Visual Object Tracking using Adaptive Correlation Filters,� 69 | in Proc. CVPR, 2010. 70 | */ 71 | 72 | #ifndef _KERNEL_HPP_ 73 | #define _KERNEL_HPP_ 74 | 75 | #include 76 | #include "feature_channels.hpp" 77 | 78 | class Kernel 79 | { 80 | public: 81 | Kernel(); 82 | virtual ~Kernel(); 83 | 84 | virtual cv::Mat correlation( const std::shared_ptr< FC > & xf, const std::shared_ptr< FC > & yf ) const = 0; 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/kcf_debug.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/kcf/kcf_debug.hpp 34 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 35 | // * We modified the original code of Klaus Haag, such that different classes are used for the different KCF components 36 | // in a more modular way, to support DS-KCF code 37 | */ 38 | 39 | #ifndef KCF_DEBUG_HPP_ 40 | #define KCF_DEBUG_HPP_ 41 | 42 | #include "opencv2/imgproc/imgproc.hpp" 43 | #include "opencv2/core/core.hpp" 44 | #include 45 | #include 46 | 47 | #include "tracker_debug.hpp" 48 | 49 | template 50 | class KcfDebug : public TrackerDebug 51 | { 52 | public: 53 | KcfDebug() : 54 | _maxResponse(0), 55 | _psrClamped(0), 56 | _RESPONSE_TITLE( "Response" ) 57 | { 58 | _SUB_WINDOW_TITLE[ 0 ] = "SUB WINDOW RGB"; 59 | _SUB_WINDOW_TITLE[ 1 ] = "SUB WINDOW DEPTH"; 60 | } 61 | 62 | virtual ~KcfDebug() 63 | { 64 | if (_outputFile.is_open()) 65 | { 66 | _outputFile.close(); 67 | } 68 | } 69 | 70 | virtual void init(std::string outputFilePath) 71 | { 72 | namedWindow(_SUB_WINDOW_TITLE[ 0 ], cv::WINDOW_NORMAL); 73 | namedWindow(_SUB_WINDOW_TITLE[ 1 ], cv::WINDOW_NORMAL); 74 | namedWindow(_RESPONSE_TITLE, cv::WINDOW_NORMAL); 75 | _outputFile.open(outputFilePath.c_str()); 76 | } 77 | 78 | virtual void printOnImage(cv::Mat& image) 79 | { 80 | _ss.str(""); 81 | _ss.clear(); 82 | _ss << "Max Response: " << _maxResponse; 83 | putText(image, _ss.str(), cv::Point(20, 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, cv::Scalar(255, 0, 0)); 84 | 85 | _ss.str(""); 86 | _ss.clear(); 87 | _ss << "PSR Clamped: " << _psrClamped; 88 | putText(image, _ss.str(), cv::Point(20, 80), cv::FONT_HERSHEY_TRIPLEX, 0.5, cv::Scalar(255, 0, 0)); 89 | } 90 | 91 | virtual void printConsoleOutput() 92 | { 93 | } 94 | 95 | virtual void printToFile() 96 | { 97 | _outputFile << _maxResponse << "," << _psrClamped << std::endl; 98 | } 99 | 100 | void showPatch(const cv::Mat& patchResized) 101 | { 102 | imshow(_SUB_WINDOW_TITLE[ _windowIndex ], patchResized); 103 | _windowIndex = ( _windowIndex + 1 ) % 2; 104 | } 105 | 106 | void setPsr(T psrClamped) 107 | { 108 | _psrClamped = psrClamped; 109 | std::cout << "PSR: " << psrClamped << std::endl; 110 | } 111 | 112 | void showResponse(const cv::Mat& response, T maxResponse) 113 | { 114 | cv::Mat responseOutput = response.clone(); 115 | _maxResponse = maxResponse; 116 | imshow(_RESPONSE_TITLE, responseOutput); 117 | } 118 | 119 | private: 120 | std::array _SUB_WINDOW_TITLE; 121 | const std::string _RESPONSE_TITLE; 122 | T _maxResponse; 123 | T _psrClamped; 124 | std::stringstream _ss; 125 | std::ofstream _outputFile; 126 | int _windowIndex; 127 | }; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/kcf_tracker.cpp: -------------------------------------------------------------------------------- 1 | #include "kcf_tracker.hpp" 2 | 3 | KcfParameters::KcfParameters() 4 | { 5 | this->padding = 2.5; 6 | this->lambda = 0.0001; 7 | this->outputSigmaFactor = 0.05; 8 | this->interpFactor = 0.02; 9 | this->cellSize = 4; 10 | } 11 | 12 | KcfTracker::KcfTracker(KcfParameters paras, std::shared_ptr< Kernel > kernel ) : 13 | m_xf( nullptr ), 14 | m_kernel( kernel ) 15 | { 16 | m_isInitialized = false; 17 | m_lambda = paras.lambda; 18 | m_interpFactor = paras.interpFactor; 19 | m_cellSize = paras.cellSize; 20 | m_frameID = 1; 21 | } 22 | 23 | KcfTracker::~KcfTracker() 24 | { 25 | } 26 | 27 | void KcfTracker::init( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & position ) 28 | { 29 | TrainingData trainingData = getTrainingData( image, features ); 30 | 31 | this->m_frameID = 0; 32 | this->m_isInitialized = false; 33 | 34 | divideSpectrumsNoCcs< double >( trainingData.numeratorf, trainingData.denominatorf, this->m_alphaf ); 35 | this->m_alphaNumeratorf = trainingData.numeratorf; 36 | this->m_alphaDenominatorf = trainingData.denominatorf; 37 | this->m_xf = trainingData.xf; 38 | this->m_isInitialized = true; 39 | } 40 | 41 | const KcfTracker::TrainingData KcfTracker::getTrainingData( const cv::Mat & image, const std::shared_ptr< FC > & features ) const 42 | { 43 | TrainingData result; 44 | result.xf = FC::dftFeatures( features, cv::DFT_COMPLEX_OUTPUT ); 45 | cv::Mat kf = this->m_kernel->correlation( result.xf, result.xf ); 46 | cv::Mat kfLambda = kf + this->m_lambda; 47 | mulSpectrums( this->m_yf, kf, result.numeratorf, 0 ); 48 | mulSpectrums( kf, kfLambda, result.denominatorf, 0 ); 49 | 50 | return result; 51 | } 52 | 53 | void KcfTracker::update( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & position ) 54 | { 55 | ++m_frameID; 56 | 57 | if( m_isInitialized ) 58 | { 59 | this->updateModel( image, features ); 60 | } 61 | } 62 | 63 | const DetectResult KcfTracker::detectModel( const cv::Mat & image, const std::shared_ptr< FC > & features, const Point & newPos ) const 64 | { 65 | DetectResult result; 66 | Response newResponse = this->getResponse( image, features, newPos ); 67 | 68 | cv::Point_< double > subDelta = subPixelDelta< double >( newResponse.response, newResponse.maxResponsePosition ); 69 | 70 | if( subDelta.y >= newResponse.response.rows / 2 ) 71 | { 72 | subDelta.y -= newResponse.response.rows; 73 | } 74 | if( subDelta.x >= newResponse.response.cols / 2 ) 75 | { 76 | subDelta.x -= newResponse.response.cols; 77 | } 78 | double posDeltaX = m_cellSize * subDelta.x; 79 | double posDeltaY = m_cellSize * subDelta.y; 80 | result.position.x = newPos.x + posDeltaX; 81 | result.position.y = newPos.y + posDeltaY; 82 | 83 | result.maxResponse = newResponse.maxResponse; 84 | 85 | return result; 86 | } 87 | 88 | void KcfTracker::updateModel( const cv::Mat & image, const std::shared_ptr< FC > & features ) 89 | { 90 | TrainingData trainingData = getTrainingData( image, features ); 91 | 92 | this->m_alphaNumeratorf = ( 1 - m_interpFactor ) * m_alphaNumeratorf + m_interpFactor * trainingData.numeratorf; 93 | this->m_alphaDenominatorf = ( 1 - m_interpFactor ) * m_alphaDenominatorf + m_interpFactor * trainingData.denominatorf; 94 | 95 | FC::mulValueFeatures( this->m_xf, ( 1 - this->m_interpFactor ) ); 96 | FC::mulValueFeatures( trainingData.xf, this->m_interpFactor ); 97 | FC::addFeatures( this->m_xf, trainingData.xf ); 98 | divideSpectrumsNoCcs< double >( m_alphaNumeratorf, m_alphaDenominatorf, this->m_alphaf ); 99 | } 100 | 101 | const KcfTracker::Response KcfTracker::getResponse( const cv::Mat & image, const std::shared_ptr< FC > & features, const Point & pos ) const 102 | { 103 | Response result; 104 | 105 | result.response = this->detectResponse( image, features, pos ); 106 | minMaxLoc( result.response, 0, &result.maxResponse, 0, &result.maxResponsePosition ); 107 | 108 | return result; 109 | } 110 | 111 | const cv::Mat KcfTracker::detectResponse( const cv::Mat & image, const std::shared_ptr< FC > & features, const Point & pos ) const 112 | { 113 | cv::Mat responsef; 114 | cv::Mat1d response; 115 | 116 | std::shared_ptr< FC > zf = FC::dftFeatures( features, cv::DFT_COMPLEX_OUTPUT ); 117 | cv::Mat kzf = this->m_kernel->correlation( zf, this->m_xf ); 118 | 119 | mulSpectrums( this->m_alphaf, kzf, responsef, 0, false ); 120 | idft( responsef, response, cv::DFT_REAL_OUTPUT | cv::DFT_SCALE ); 121 | 122 | return response; 123 | } 124 | 125 | const DetectResult KcfTracker::detect( const cv::Mat & image, const std::shared_ptr< FC > & features, const Point & position ) const 126 | { 127 | return this->detectModel( image, features, position ); 128 | } 129 | 130 | void KcfTracker::onScaleChange( const Size & targetSize, const Size & windowSize, const cv::Mat2d & yf, const cv::Mat1d & cosineWindow ) 131 | { 132 | this->m_cosineWindow = cosineWindow; 133 | this->m_yf = yf; 134 | 135 | //If the model is initialised, resize it 136 | if( this->m_isInitialized ) 137 | { 138 | cv::Size2i modelSize( 139 | cvFloor( windowSize.width / this->m_cellSize ), 140 | cvFloor( windowSize.height / this->m_cellSize ) 141 | ); 142 | 143 | tbb::parallel_for_each( this->m_xf->channels.begin(), this->m_xf->channels.end(), 144 | [modelSize]( cv::Mat & channel ) 145 | { 146 | channel = ScaleAnalyser::scaleImageFourierShift( channel, modelSize ); 147 | } 148 | ); 149 | 150 | this->m_alphaNumeratorf = ScaleAnalyser::scaleImageFourierShift( this->m_alphaNumeratorf, modelSize ); 151 | this->m_alphaDenominatorf = ScaleAnalyser::scaleImageFourierShift( this->m_alphaDenominatorf, modelSize ); 152 | } 153 | } 154 | 155 | std::shared_ptr< KcfTracker > KcfTracker::duplicate() const 156 | { 157 | std::shared_ptr< KcfTracker > result = std::make_shared< KcfTracker >( KcfParameters(), this->m_kernel ); 158 | 159 | result->m_xf = this->m_xf; 160 | result->m_alphaNumeratorf = this->m_alphaNumeratorf; 161 | result->m_alphaDenominatorf = this->m_alphaDenominatorf; 162 | result->m_alphaf = this->m_alphaf; 163 | result->m_cosineWindow = this->m_cosineWindow; 164 | result->m_yf = this->m_yf; 165 | 166 | result->m_frameID = this->m_frameID; 167 | result->m_isInitialized = this->m_isInitialized; 168 | 169 | result->m_lambda = this->m_lambda; 170 | result->m_interpFactor = this->m_interpFactor; 171 | result->m_cellSize = this->m_cellSize; 172 | 173 | result->m_kernel = this->m_kernel; 174 | 175 | return result; 176 | } 177 | -------------------------------------------------------------------------------- /src/cf_libs/kcf/kcf_tracker.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/cf_libs/kcf/kcf_tracker.hpp 34 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 35 | // * We modified the original code of Klaus Haag, such that different classes are used for the different KCF components 36 | // in a more modular way, to support DS-KCF code 37 | 38 | It is implemented closely to the Matlab implementation by the original authors: 39 | http://home.isr.uc.pt/~henriques/circulant/ 40 | However, some implementation details differ and some difference in performance 41 | has to be expected. 42 | 43 | This specific implementation features the scale adaption, sub-pixel 44 | accuracy for the correlation response evaluation and a more robust 45 | filter update scheme [2] used by Henriques, et al. in the VOT Challenge 2014. 46 | 47 | As default scale adaption, the tracker uses the 1D scale filter 48 | presented in [3]. The scale filter can be found in scale_estimator.hpp. 49 | Additionally, target loss detection is implemented according to [4]. 50 | 51 | Every complex matrix is as default in CCS packed form: 52 | see : https://software.intel.com/en-us/node/504243 53 | and http://docs.opencv.org/modules/core/doc/operations_on_arrays.html 54 | 55 | References: 56 | [1] J. Henriques, et al., 57 | "High-Speed Tracking with Kernelized Correlation Filters," 58 | PAMI, 2015. 59 | 60 | [2] M. Danelljan, et al., 61 | �Adaptive Color Attributes for Real-Time Visual Tracking,� 62 | in Proc. CVPR, 2014. 63 | 64 | [3] M. Danelljan, 65 | "Accurate Scale Estimation for Robust Visual Tracking," 66 | Proceedings of the British Machine Vision Conference BMVC, 2014. 67 | 68 | [4] D. Bolme, et al., 69 | �Visual Object Tracking using Adaptive Correlation Filters,� 70 | in Proc. CVPR, 2010. 71 | */ 72 | 73 | #ifndef KCF_TRACKER_HPP_ 74 | #define KCF_TRACKER_HPP_ 75 | 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | 84 | #include "cv_ext.hpp" 85 | #include "feature_channels.hpp" 86 | #include "gradientMex.hpp" 87 | #include "mat_consts.hpp" 88 | #include "math_helper.hpp" 89 | #include "cf_tracker.hpp" 90 | #include "kcf_debug.hpp" 91 | #include "ScaleAnalyser.hpp" 92 | #include "Kernel.hpp" 93 | #include "ScaleChangeObserver.hpp" 94 | #include "optional.hpp" 95 | 96 | struct KcfParameters 97 | { 98 | double padding; 99 | double lambda; 100 | double outputSigmaFactor; 101 | double interpFactor; 102 | int cellSize; 103 | 104 | KcfParameters(); 105 | }; 106 | 107 | struct DetectResult { cv::Point_< double > position;double maxResponse; }; 108 | 109 | class KcfTracker : public ScaleChangeObserver 110 | { 111 | friend class KCFTest; 112 | public: 113 | KcfTracker( KcfParameters paras, std::shared_ptr< Kernel > kernel ); 114 | virtual ~KcfTracker(); 115 | 116 | void init( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & position ); 117 | void update( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & position ); 118 | virtual void onScaleChange( const cv::Size_< double > & targetSize, const cv::Size_< double > & windowSize, const cv::Mat2d & yf, const cv::Mat1d & cosineWindow ); 119 | 120 | const DetectResult detect( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & position ) const; 121 | std::shared_ptr< KcfTracker > duplicate() const; 122 | private: 123 | bool m_isInitialized; 124 | int m_frameID; 125 | int m_cellSize; 126 | double m_lambda; 127 | double m_interpFactor; 128 | cv::Mat1d m_cosineWindow; 129 | cv::Mat2d m_alphaNumeratorf; 130 | cv::Mat2d m_alphaDenominatorf; 131 | cv::Mat2d m_alphaf; 132 | cv::Mat2d m_yf; 133 | std::shared_ptr< FC > m_xf; 134 | std::shared_ptr< Kernel > m_kernel; 135 | 136 | void updateModel( const cv::Mat & image, const std::shared_ptr< FC > & features ); 137 | protected: 138 | struct Response { cv::Mat1d response; double maxResponse; cv::Point maxResponsePosition; }; 139 | struct TrainingData { std::shared_ptr< FC > xf; cv::Mat numeratorf, denominatorf; }; 140 | 141 | const TrainingData getTrainingData( const cv::Mat & image, const std::shared_ptr< FC > & features ) const; 142 | const DetectResult detectModel( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & newPos ) const; 143 | const Response getResponse( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & pos ) const; 144 | const cv::Mat detectResponse( const cv::Mat & image, const std::shared_ptr< FC > & features, const cv::Point_< double > & pos ) const; 145 | }; 146 | 147 | #endif /* KCF_TRACKER_H_ */ 148 | -------------------------------------------------------------------------------- /src/doxygen_dummy.hpp: -------------------------------------------------------------------------------- 1 | namespace std { template class shared_ptr { T *ref; }; } 2 | -------------------------------------------------------------------------------- /src/main/image_acquisition.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | #include "image_acquisition.hpp" 33 | 34 | ImageAcquisition::ImageAcquisition() 35 | { 36 | } 37 | 38 | ImageAcquisition& ImageAcquisition::operator>>(CV_OUT cv::Mat& image) 39 | { 40 | if (_paras.isMock) 41 | _mockCap >> image; 42 | else 43 | _cvCap >> image; 44 | 45 | return *this; 46 | } 47 | 48 | void ImageAcquisition::release() 49 | { 50 | if (!_paras.isMock) 51 | _cvCap.release(); 52 | } 53 | 54 | bool ImageAcquisition::isOpened() 55 | { 56 | if (_paras.isMock) 57 | return _mockCap.isOpened(); 58 | else 59 | return _cvCap.isOpened(); 60 | } 61 | 62 | void ImageAcquisition::set(int key, int value) 63 | { 64 | if (!_paras.isMock) 65 | _cvCap.set(key, value); 66 | } 67 | 68 | void ImageAcquisition::open(ImgAcqParas paras) 69 | { 70 | _paras = paras; 71 | 72 | if (_paras.isMock) 73 | { 74 | _mockCap.open(); 75 | } 76 | else 77 | { 78 | if (_paras.sequencePath.empty()) 79 | _cvCap.open(_paras.device); 80 | else 81 | { 82 | std::string sequenceExpansion = 83 | _paras.sequencePath + _paras.expansionStr; 84 | 85 | _cvCap.open(sequenceExpansion); 86 | } 87 | } 88 | } 89 | 90 | ImageAcquisition::~ImageAcquisition() 91 | { 92 | } 93 | 94 | double ImageAcquisition::get(int key) 95 | { 96 | if (!_paras.isMock) 97 | return _cvCap.get(key); 98 | 99 | return 0.0; 100 | } 101 | 102 | void VideoCaptureMock::release() 103 | { 104 | } 105 | 106 | bool VideoCaptureMock::isOpened() 107 | { 108 | return isOpen; 109 | } 110 | 111 | VideoCaptureMock& VideoCaptureMock::operator>>(CV_OUT cv::Mat& image) 112 | { 113 | image = _staticImage; 114 | return *this; 115 | } 116 | 117 | void VideoCaptureMock::open() 118 | { 119 | isOpen = true; 120 | } 121 | 122 | VideoCaptureMock::~VideoCaptureMock() 123 | { 124 | } 125 | 126 | VideoCaptureMock::VideoCaptureMock() : isOpen(false) 127 | { 128 | _staticImage = cv::Mat(360, 640, CV_8UC3); 129 | cv::randu(_staticImage, cv::Scalar::all(0), cv::Scalar::all(255)); 130 | } 131 | -------------------------------------------------------------------------------- /src/main/image_acquisition.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // License Agreement (3-clause BSD License) 3 | // Copyright (c) 2015, Klaus Haag, all rights reserved. 4 | // Third party copyrights and patents are property of their respective owners. 5 | // 6 | // Redistribution and use in source and binary forms, with or without modification, 7 | // are permitted provided that the following conditions are met: 8 | // 9 | // * Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the documentation 14 | // and/or other materials provided with the distribution. 15 | // 16 | // * Neither the names of the copyright holders nor the names of the contributors 17 | // may be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // This software is provided by the copyright holders and contributors "as is" and 21 | // any express or implied warranties, including, but not limited to, the implied 22 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 23 | // In no event shall copyright holders or contributors be liable for any direct, 24 | // indirect, incidental, special, exemplary, or consequential damages 25 | // (including, but not limited to, procurement of substitute goods or services; 26 | // loss of use, data, or profits; or business interruption) however caused 27 | // and on any theory of liability, whether in contract, strict liability, 28 | // or tort (including negligence or otherwise) arising in any way out of 29 | // the use of this software, even if advised of the possibility of such damage. 30 | */ 31 | 32 | /* 33 | // Original file: https://github.com/klahaag/cf_tracking/blob/master/src/ 34 | // + Authors: Jake Hall, Massimo Camplan, Sion Hannuna 35 | // * We modified the original code of Klaus Haag by adding a new constructor fo rthe ImgAcqParas 36 | */ 37 | 38 | #ifndef IMAGE_ACQUISITION_HPP_ 39 | #define IMAGE_ACQUISITION_HPP_ 40 | 41 | #include "opencv2/highgui/highgui.hpp" 42 | 43 | class ImgAcqParas 44 | { 45 | public: 46 | bool isMock; 47 | int device; 48 | std::string sequencePath; 49 | std::string expansionStr; 50 | 51 | ImgAcqParas() 52 | { 53 | this->isMock = false; 54 | this->device = -1; 55 | this->sequencePath = ""; 56 | this->expansionStr = ""; 57 | } 58 | }; 59 | 60 | class VideoCaptureMock 61 | { 62 | public: 63 | VideoCaptureMock(); 64 | 65 | virtual ~VideoCaptureMock(); 66 | 67 | void open(); 68 | 69 | VideoCaptureMock& operator >> (CV_OUT cv::Mat& image); 70 | 71 | bool isOpened(); 72 | 73 | void release(); 74 | 75 | private: 76 | bool isOpen; 77 | cv::Mat _staticImage; 78 | }; 79 | 80 | class ImageAcquisition 81 | { 82 | public: 83 | ImageAcquisition(); 84 | 85 | virtual ~ImageAcquisition(); 86 | 87 | void open(ImgAcqParas paras); 88 | 89 | void set(int key, int value); 90 | 91 | double get(int key); 92 | 93 | bool isOpened(); 94 | 95 | void release(); 96 | 97 | ImageAcquisition& operator >> (CV_OUT cv::Mat& image); 98 | 99 | private: 100 | cv::VideoCapture _cvCap; 101 | ImgAcqParas _paras; 102 | VideoCaptureMock _mockCap; 103 | }; 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /src/main/main_dskcf.cpp: -------------------------------------------------------------------------------- 1 | #include "dskcf_tracker_run.hpp" 2 | 3 | int main( int argc, const char** argv ) 4 | { 5 | DskcfTrackerRun main; 6 | 7 | if( main.start( argc, argv ) ) 8 | { 9 | return 0; 10 | } 11 | else 12 | { 13 | return -1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | \mainpage The mainpage documentation 3 | 4 | This is a simple example of a mainpage you can create yourself. 5 | Place this inside of a file called `mainpage.dox` and use doxygen. 6 | If you specified `INPUT` or `FILE_PATTERNS` in your Doxyfile please 7 | add `.dox` to your file patterns or `mainpage.dox` to your INPUT files. 8 | */ 9 | --------------------------------------------------------------------------------