├── MRCF_Demo_single_seq.m ├── README.md ├── configSeqs_demo_for_MRCF.m ├── external_libs ├── mexResize │ ├── MxArray.cpp │ ├── MxArray.hpp │ ├── compile.m │ ├── libopencv_core.a │ ├── libopencv_core.so │ ├── libopencv_imgproc.a │ ├── libopencv_imgproc.so │ ├── mexResize.cpp │ ├── mexResize.mexa64 │ ├── mexResize.mexw64 │ ├── opencv2 │ │ ├── core │ │ │ ├── core.hpp │ │ │ ├── core_c.h │ │ │ ├── devmem2d.hpp │ │ │ ├── eigen.hpp │ │ │ ├── gpumat.hpp │ │ │ ├── internal.hpp │ │ │ ├── mat.hpp │ │ │ ├── opengl_interop.hpp │ │ │ ├── operations.hpp │ │ │ ├── types_c.h │ │ │ ├── version.hpp │ │ │ └── wimage.hpp │ │ ├── features2d │ │ │ └── features2d.hpp │ │ ├── flann │ │ │ ├── all_indices.h │ │ │ ├── allocator.h │ │ │ ├── any.h │ │ │ ├── autotuned_index.h │ │ │ ├── composite_index.h │ │ │ ├── config.h │ │ │ ├── defines.h │ │ │ ├── dist.h │ │ │ ├── dummy.h │ │ │ ├── dynamic_bitset.h │ │ │ ├── flann.hpp │ │ │ ├── flann_base.hpp │ │ │ ├── general.h │ │ │ ├── ground_truth.h │ │ │ ├── hdf5.h │ │ │ ├── heap.h │ │ │ ├── hierarchical_clustering_index.h │ │ │ ├── index_testing.h │ │ │ ├── kdtree_index.h │ │ │ ├── kdtree_single_index.h │ │ │ ├── kmeans_index.h │ │ │ ├── linear_index.h │ │ │ ├── logger.h │ │ │ ├── lsh_index.h │ │ │ ├── lsh_table.h │ │ │ ├── matrix.h │ │ │ ├── miniflann.hpp │ │ │ ├── nn_index.h │ │ │ ├── object_factory.h │ │ │ ├── params.h │ │ │ ├── random.h │ │ │ ├── result_set.h │ │ │ ├── sampling.h │ │ │ ├── saving.h │ │ │ ├── simplex_downhill.h │ │ │ └── timer.h │ │ ├── imgproc │ │ │ ├── imgproc.hpp │ │ │ ├── imgproc_c.h │ │ │ └── types_c.h │ │ ├── opencv.hpp │ │ └── opencv_modules.hpp │ ├── opencv_core242.dll │ ├── opencv_core242.lib │ ├── opencv_imgproc242.dll │ └── opencv_imgproc242.lib └── mtimesx │ ├── license.txt │ ├── mtimesx.c │ ├── mtimesx.m │ ├── mtimesx.mexa64 │ ├── mtimesx.mexw64 │ ├── mtimesx_RealTimesReal.c │ ├── mtimesx_build.m │ ├── mtimesx_sparse.m │ ├── mtimesx_test_ddequal.m │ ├── mtimesx_test_ddspeed.m │ ├── mtimesx_test_dsequal.m │ ├── mtimesx_test_dsspeed.m │ ├── mtimesx_test_nd.m │ ├── mtimesx_test_sdequal.m │ ├── mtimesx_test_sdspeed.m │ ├── mtimesx_test_ssequal.m │ └── mtimesx_test_ssspeed.m ├── feature_extraction ├── average_feature_region.m ├── extract_features.m ├── fhog.m ├── get_CNN_features_VGG19.m ├── get_cnn_layers.m ├── get_colorspace.m ├── get_colorspace_backup.m ├── get_feature_extract_info.m ├── get_fhog.m ├── get_pixels.m ├── get_table_feature.m ├── init_features.m ├── integralVecImage.m ├── load_cnn.m ├── lookup_tables │ ├── CNnorm.mat │ ├── intensityChannelNorm11.mat │ ├── intensityChannelNorm16.mat │ └── intensityChannelNorm6.mat ├── sample_patch.m ├── set_cnn_input_size.m └── table_lookup.m ├── implementation ├── argmin_g.m ├── init_default_params.m ├── init_feature_params.m ├── interpolate_dft.m ├── resizeDFT2.m ├── resp_newton.m ├── scale_filter │ └── get_scale_sample.m ├── shift_sample.m ├── shift_sample_scale.m └── tracker.m ├── results ├── DTB70.png ├── UAV123@10fps.png ├── UAVDT.png ├── VisDrone2018.png ├── VisDrone2020.png └── setup.png ├── run_MRCF.m ├── seq ├── wakeboard7 │ ├── 000001.jpg │ ├── 000002.jpg │ ├── 000003.jpg │ ├── 000004.jpg │ ├── 000005.jpg │ ├── 000006.jpg │ ├── 000007.jpg │ ├── 000008.jpg │ ├── 000009.jpg │ ├── 000010.jpg │ ├── 000011.jpg │ ├── 000012.jpg │ ├── 000013.jpg │ ├── 000014.jpg │ ├── 000015.jpg │ ├── 000016.jpg │ ├── 000017.jpg │ ├── 000018.jpg │ ├── 000019.jpg │ ├── 000020.jpg │ ├── 000021.jpg │ ├── 000022.jpg │ ├── 000023.jpg │ ├── 000024.jpg │ ├── 000025.jpg │ ├── 000026.jpg │ ├── 000027.jpg │ ├── 000028.jpg │ ├── 000029.jpg │ ├── 000030.jpg │ ├── 000031.jpg │ ├── 000032.jpg │ ├── 000033.jpg │ ├── 000034.jpg │ ├── 000035.jpg │ ├── 000036.jpg │ ├── 000037.jpg │ ├── 000038.jpg │ ├── 000039.jpg │ ├── 000040.jpg │ ├── 000041.jpg │ ├── 000042.jpg │ ├── 000043.jpg │ ├── 000044.jpg │ ├── 000045.jpg │ ├── 000046.jpg │ ├── 000047.jpg │ ├── 000048.jpg │ ├── 000049.jpg │ ├── 000050.jpg │ ├── 000051.jpg │ ├── 000052.jpg │ ├── 000053.jpg │ ├── 000054.jpg │ ├── 000055.jpg │ ├── 000056.jpg │ ├── 000057.jpg │ ├── 000058.jpg │ ├── 000059.jpg │ ├── 000060.jpg │ ├── 000061.jpg │ ├── 000062.jpg │ ├── 000063.jpg │ ├── 000064.jpg │ ├── 000065.jpg │ ├── 000066.jpg │ └── 000067.jpg └── wakeboard7_gt.txt └── utils ├── calcRectInt.m ├── choose_video.m ├── choose_video_UAV.m ├── configSeqs_demo.m ├── construct_circular_cone.m ├── construct_regwindow.m ├── get_sequence_frame.m ├── get_sequence_info.m ├── get_sequence_results.m ├── get_subwindow_no_window.m ├── gradientMex.cpp ├── gradientMex.mexa64 ├── gradientMex.mexmaci64 ├── gradientMex.mexw64 ├── load_video_info.m ├── load_video_info_UAV123.m ├── load_video_information.m ├── precision_plot_save.m ├── report_tracking_result.m ├── splitSeqTRE.m └── wrappers.hpp /MRCF_Demo_single_seq.m: -------------------------------------------------------------------------------- 1 | 2 | % This script runs the implementation of MRCF for visual tracking. 3 | % Some functions are borrowed from other papers (SRDCF, UAV123 Benchmark) 4 | % and their copyright belongs to the paper's authors. 5 | 6 | clear; clc; close all; 7 | addpath(genpath('.')); 8 | 9 | pathAnno = '.\seq\'; 10 | seqs = configSeqs_demo_for_MRCF; 11 | 12 | idx = 1; 13 | 14 | for idxSeq=1:length(seqs) 15 | s = seqs{idxSeq}; 16 | 17 | video_path = s.path; 18 | 19 | s.len = s.endFrame - s.startFrame + 1; 20 | s.s_frames = cell(s.len,1); 21 | nz = strcat('%0',num2str(s.nz),'d'); %number of zeros in the name of image 22 | for i=1:s.len 23 | image_no = s.startFrame + (i-1); 24 | id = sprintf(nz,image_no); 25 | s.s_frames{i} = strcat(s.path,id,'.',s.ext); 26 | end 27 | 28 | img = imread(s.s_frames{1}); 29 | [imgH,imgW,ch]=size(img); 30 | 31 | rect_anno = dlmread([pathAnno s.name '_gt.txt']); 32 | numSeg = 20; 33 | 34 | [subSeqs, subAnno]=splitSeqTRE(s,numSeg,rect_anno); 35 | 36 | subS = subSeqs{1}; 37 | subSeqs=[]; 38 | subSeqs{1} = subS; 39 | 40 | subA = subAnno{1}; 41 | subAnno=[]; 42 | subAnno{1} = subA; 43 | results = []; 44 | 45 | subS = subSeqs{idx}; 46 | 47 | subS.name = [subS.name '_' num2str(idx)]; 48 | 49 | res = run_MRCF(subS, 0, 0); 50 | 51 | res.len = subS.len; 52 | res.annoBegin = subS.annoBegin; 53 | res.startFrame = subS.startFrame; 54 | 55 | results{idx} = res; 56 | 57 | % Load video information 58 | ground_truth = subAnno{1}; 59 | 60 | gt_boxes = [ground_truth(:,1:2), ground_truth(:,1:2) + ground_truth(:,3:4) - ones(size(ground_truth,1), 2)]; 61 | 62 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multi-Regularized Correlation Filter for UAV Tracking and Self-Localization 2 | 3 | Matlab implementation of our Multi-Regularized Correlation Filter (MRCF). 4 | 5 | | **Test passed** | 6 | | ------------------------------------------------------------ | 7 | | [![matlab-2019a](https://img.shields.io/badge/matlab-2019a-yellow.svg)](https://www.mathworks.com/products/matlab.html) | 8 | 9 | 10 | # Abstract 11 | >As a sort of model-free tracking approach, discriminative correlation filter (DCF)-based trackers have shown prominent performance in unmanned aerial vehicle (UAV) tracking. Nevertheless, typical DCFs acquire all samples oriented to filter training merely from the current frame by cyclic shift operation in the spatial domain but ignore the consistency between samples across the timeline. The lack of temporal cues restricts the performance of DCFs under object appearance variations arising from object/UAV motion, scale variations, and viewpoint changes. Besides, many existing methods commonly neglect the channel discrepancy in object position estimation and generally treat all channels equally, thus limiting the further promotion of the tracking discriminability. To these concerns, this work proposes a novel tracking approach based on a multi-regularized correlation filter, i.e., MRCF tracker. By regularizing the deviation of responses and the reliability of channels, the tracker enables smooth response variations and adaptive channel weight distributions simultaneously, leading to favorable adaption to object appearance variations and enhancement of discriminability. Exhaustive experiments on five authoritative UAV-specific benchmarks validate the competitiveness and efficiency of MRCF against top-ranked trackers. Furthermore, we apply our proposed tracker to monocular UAV self-localization under air-ground robot coordination. Evaluations indicate the practicability of the presented method in UAV localization applications. 12 | 13 | ![](./results/setup.png) 14 | 15 | # Reference 16 | 17 | > @ARTICLE{Ye_2021_TIE, 18 | > author={J. {Ye} and C. {Fu} and F. {Lin} and F. {Ding} and S. {An} and G. {Lu}}, 19 | > journal={IEEE Transactions on Industrial Electronics}, 20 | > title={{Multi-Regularized Correlation Filter for UAV Tracking and Self-Localization}}, 21 | > year={2021}, 22 | > volume={}, 23 | > number={}, 24 | > pages={1-10}, 25 | > } 26 | 27 | # Contact 28 | Junjie Ye 29 | 30 | Email: ye.jun.jie@tongji.edu.cn 31 | 32 | Changhong Fu 33 | 34 | Email: changhongfu@tongji.edu.cn 35 | 36 | # Demonstration running instructions 37 | 38 | >Running demonstration of this tracker is very easy so long as you have MATLAB. Just download the package, extract it and follow two steps: 39 | > 40 | >1. Config seq name in `configSeqs_demo_for_MRCF.m`, 41 | > 42 | >2. Run `MRCF_Demo_single_seq.m`, 43 | > and the MRCF Demo should be running. 44 | 45 | # Results on UAV datasets 46 | 47 | ### UAVDT 48 | 49 | ![](./results/UAVDT.png) 50 | 51 | ### UAV123@10fps 52 | 53 | ![](./results/UAV123@10fps.png) 54 | 55 | ### VisDrone2018-test-dev 56 | 57 | ![](./results/VisDrone2018.png) 58 | 59 | ### DTB70 60 | 61 | ![](./results/DTB70.png) 62 | 63 | ### VisDrone2020-SOT 64 | 65 | ![](./results/VisDrone2020.png) 66 | 67 | # Acknowledgements 68 | 69 | We thank the contribution of `Hamed Kiani`, `Feng Li`, `Martin Danelljan` for their previous work BACF, STRCF and ECO. The feature extraction modules are borrowed from the ECO tracker (https://github.com/martin-danelljan/ECO) and STRCF tracker (https://github.com/lifeng9472/STRCF) and some of the parameter settings and functions are borrowed from BACF (www.hamedkiani.com/bacf.html) and STRCF. 70 | 71 | -------------------------------------------------------------------------------- /configSeqs_demo_for_MRCF.m: -------------------------------------------------------------------------------- 1 | function seqs=configSeqs_demo_for_MRCF 2 | 3 | seqUAV123_10fps_wakeboard7 = { struct('name','wakeboard7','path','.\seq\wakeboard7\','startFrame',1,'endFrame',67,'nz',6,'ext','jpg','init_rect',[0,0,0,0])}; 4 | seqs = seqUAV123_10fps_wakeboard7; 5 | -------------------------------------------------------------------------------- /external_libs/mexResize/compile.m: -------------------------------------------------------------------------------- 1 | 2 | % Compiles the mexResize function. 3 | 4 | % Try to use the included mex files first. If they do not work, you can try 5 | % to compile it yourself with this script. If the bellow mex command does 6 | % not work, try to link to your own OpenCV installation. 7 | 8 | if ispc 9 | mex -lopencv_core242 -lopencv_imgproc242 -L./ -I./ mexResize.cpp MxArray.cpp 10 | else 11 | mex -lopencv_core -lopencv_imgproc -L./ -I./ mexResize.cpp MxArray.cpp 12 | end -------------------------------------------------------------------------------- /external_libs/mexResize/libopencv_core.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/libopencv_core.a -------------------------------------------------------------------------------- /external_libs/mexResize/libopencv_core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/libopencv_core.so -------------------------------------------------------------------------------- /external_libs/mexResize/libopencv_imgproc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/libopencv_imgproc.a -------------------------------------------------------------------------------- /external_libs/mexResize/libopencv_imgproc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/libopencv_imgproc.so -------------------------------------------------------------------------------- /external_libs/mexResize/mexResize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mex.h" 5 | #include "MxArray.hpp" 6 | #include 7 | 8 | #include 9 | 10 | using namespace std; 11 | using namespace cv; 12 | 13 | /* 14 | * Use opencv function to resample image quickly 15 | */ 16 | 17 | // matlab entry point 18 | // dst = resize(src, scale) 19 | // image should be color with double values 20 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { 21 | if (nrhs < 2){ 22 | mexErrMsgTxt("Wrong number of inputs"); 23 | } 24 | if (nlhs != 1){ 25 | mexErrMsgTxt("Wrong number of outputs"); 26 | } 27 | 28 | vector rhs(prhs,prhs+nrhs); 29 | 30 | //convert input data to opencv matrix 31 | Mat img = rhs[0].toMat(); 32 | Mat imgr; 33 | Size s = rhs[1].toSize(); 34 | Size newSize = Size(s.height,s.width); 35 | Size oldSize = img.size(); 36 | //interpolation method 37 | int interpolation = INTER_LINEAR; 38 | 39 | //if interpolation method provided set it 40 | if(nrhs == 3){ 41 | string interp = rhs[2].toString(); 42 | if(interp.compare("antialias") == 0){ 43 | interpolation = INTER_AREA; 44 | }else if(interp.compare("linear") == 0){ 45 | interpolation = INTER_LINEAR; 46 | }else if(interp.compare("auto") == 0){ //if we are zooming, use linear else use area interpolation 47 | //old array has width and height swapped, newArray does not 48 | if(newSize.width > oldSize.height){ 49 | interpolation = INTER_LINEAR; 50 | }else{ 51 | interpolation = INTER_AREA; 52 | } 53 | }else{ 54 | mexErrMsgTxt("Invalid interpolation provided, valid is linear (default), antialias, auto"); 55 | } 56 | } 57 | 58 | //use opencv resize function 59 | resize(img,imgr,newSize,0,0,interpolation); 60 | //convert back to matlab representation 61 | plhs[0] = MxArray(imgr); 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /external_libs/mexResize/mexResize.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/mexResize.mexa64 -------------------------------------------------------------------------------- /external_libs/mexResize/mexResize.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/mexResize.mexw64 -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/core/devmem2d.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 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other GpuMaterials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef __OPENCV_CORE_DevMem2D_HPP__ 44 | #define __OPENCV_CORE_DevMem2D_HPP__ 45 | 46 | #ifdef __cplusplus 47 | 48 | #ifdef __CUDACC__ 49 | #define __CV_GPU_HOST_DEVICE__ __host__ __device__ __forceinline__ 50 | #else 51 | #define __CV_GPU_HOST_DEVICE__ 52 | #endif 53 | 54 | namespace cv 55 | { 56 | namespace gpu 57 | { 58 | // Simple lightweight structures that encapsulates information about an image on device. 59 | // It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile 60 | 61 | template struct StaticAssert; 62 | template <> struct StaticAssert {static __CV_GPU_HOST_DEVICE__ void check(){}}; 63 | 64 | template struct DevPtr 65 | { 66 | typedef T elem_type; 67 | typedef int index_type; 68 | 69 | enum { elem_size = sizeof(elem_type) }; 70 | 71 | T* data; 72 | 73 | __CV_GPU_HOST_DEVICE__ DevPtr() : data(0) {} 74 | __CV_GPU_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {} 75 | 76 | __CV_GPU_HOST_DEVICE__ size_t elemSize() const { return elem_size; } 77 | __CV_GPU_HOST_DEVICE__ operator T*() { return data; } 78 | __CV_GPU_HOST_DEVICE__ operator const T*() const { return data; } 79 | }; 80 | 81 | template struct PtrSz : public DevPtr 82 | { 83 | __CV_GPU_HOST_DEVICE__ PtrSz() : size(0) {} 84 | __CV_GPU_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr(data_), size(size_) {} 85 | 86 | size_t size; 87 | }; 88 | 89 | template struct PtrStep : public DevPtr 90 | { 91 | __CV_GPU_HOST_DEVICE__ PtrStep() : step(0) {} 92 | __CV_GPU_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr(data_), step(step_) {} 93 | 94 | /** \brief stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! */ 95 | size_t step; 96 | 97 | __CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr::data + y * step); } 98 | __CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr::data + y * step); } 99 | 100 | __CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } 101 | __CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } 102 | }; 103 | 104 | template struct PtrStepSz : public PtrStep 105 | { 106 | __CV_GPU_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {} 107 | __CV_GPU_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_) 108 | : PtrStep(data_, step_), cols(cols_), rows(rows_) {} 109 | 110 | int cols; 111 | int rows; 112 | }; 113 | 114 | template struct DevMem2D_ : public PtrStepSz 115 | { 116 | DevMem2D_() {} 117 | DevMem2D_(int rows_, int cols_, T* data_, size_t step_) : PtrStepSz(rows_, cols_, data_, step_) {} 118 | 119 | template 120 | explicit DevMem2D_(const DevMem2D_& d) : PtrStepSz(d.rows, d.cols, (T*)d.data, d.step) {} 121 | }; 122 | 123 | template struct PtrElemStep_ : public PtrStep 124 | { 125 | PtrElemStep_(const DevMem2D_& mem) : PtrStep(mem.data, mem.step) 126 | { 127 | StaticAssert<256 % sizeof(T) == 0>::check(); 128 | 129 | PtrStep::step /= PtrStep::elem_size; 130 | } 131 | __CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return PtrStep::data + y * PtrStep::step; } 132 | __CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return PtrStep::data + y * PtrStep::step; } 133 | 134 | __CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } 135 | __CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } 136 | }; 137 | 138 | template struct PtrStep_ : public PtrStep 139 | { 140 | PtrStep_() {} 141 | PtrStep_(const DevMem2D_& mem) : PtrStep(mem.data, mem.step) {} 142 | }; 143 | 144 | typedef DevMem2D_ DevMem2Db; 145 | typedef DevMem2Db DevMem2D; 146 | typedef DevMem2D_ DevMem2Df; 147 | typedef DevMem2D_ DevMem2Di; 148 | 149 | typedef PtrStep PtrStepb; 150 | typedef PtrStep PtrStepf; 151 | typedef PtrStep PtrStepi; 152 | 153 | typedef PtrElemStep_ PtrElemStep; 154 | typedef PtrElemStep_ PtrElemStepf; 155 | typedef PtrElemStep_ PtrElemStepi; 156 | } 157 | } 158 | 159 | #endif // __cplusplus 160 | 161 | #endif /* __OPENCV_GPU_DevMem2D_HPP__ */ 162 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/core/eigen.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 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef __OPENCV_CORE_EIGEN_HPP__ 44 | #define __OPENCV_CORE_EIGEN_HPP__ 45 | 46 | #ifdef __cplusplus 47 | 48 | #include "opencv2/core/core_c.h" 49 | #include "opencv2/core/core.hpp" 50 | 51 | #if defined _MSC_VER && _MSC_VER >= 1200 52 | #pragma warning( disable: 4714 ) //__forceinline is not inlined 53 | #pragma warning( disable: 4127 ) //conditional expression is constant 54 | #pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data 55 | #endif 56 | 57 | namespace cv 58 | { 59 | 60 | template 61 | void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst ) 62 | { 63 | if( !(src.Flags & Eigen::RowMajorBit) ) 64 | { 65 | Mat _src(src.cols(), src.rows(), DataType<_Tp>::type, 66 | (void*)src.data(), src.stride()*sizeof(_Tp)); 67 | transpose(_src, dst); 68 | } 69 | else 70 | { 71 | Mat _src(src.rows(), src.cols(), DataType<_Tp>::type, 72 | (void*)src.data(), src.stride()*sizeof(_Tp)); 73 | _src.copyTo(dst); 74 | } 75 | } 76 | 77 | template 78 | void cv2eigen( const Mat& src, 79 | Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) 80 | { 81 | CV_DbgAssert(src.rows == _rows && src.cols == _cols); 82 | if( !(dst.Flags & Eigen::RowMajorBit) ) 83 | { 84 | Mat _dst(src.cols, src.rows, DataType<_Tp>::type, 85 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 86 | if( src.type() == _dst.type() ) 87 | transpose(src, _dst); 88 | else if( src.cols == src.rows ) 89 | { 90 | src.convertTo(_dst, _dst.type()); 91 | transpose(_dst, _dst); 92 | } 93 | else 94 | Mat(src.t()).convertTo(_dst, _dst.type()); 95 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 96 | } 97 | else 98 | { 99 | Mat _dst(src.rows, src.cols, DataType<_Tp>::type, 100 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 101 | src.convertTo(_dst, _dst.type()); 102 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 103 | } 104 | } 105 | 106 | template 107 | void cv2eigen( const Mat& src, 108 | Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) 109 | { 110 | dst.resize(src.rows, src.cols); 111 | if( !(dst.Flags & Eigen::RowMajorBit) ) 112 | { 113 | Mat _dst(src.cols, src.rows, DataType<_Tp>::type, 114 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 115 | if( src.type() == _dst.type() ) 116 | transpose(src, _dst); 117 | else if( src.cols == src.rows ) 118 | { 119 | src.convertTo(_dst, _dst.type()); 120 | transpose(_dst, _dst); 121 | } 122 | else 123 | Mat(src.t()).convertTo(_dst, _dst.type()); 124 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 125 | } 126 | else 127 | { 128 | Mat _dst(src.rows, src.cols, DataType<_Tp>::type, 129 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 130 | src.convertTo(_dst, _dst.type()); 131 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 132 | } 133 | } 134 | 135 | 136 | template 137 | void cv2eigen( const Mat& src, 138 | Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) 139 | { 140 | CV_Assert(src.cols == 1); 141 | dst.resize(src.rows); 142 | 143 | if( !(dst.Flags & Eigen::RowMajorBit) ) 144 | { 145 | Mat _dst(src.cols, src.rows, DataType<_Tp>::type, 146 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 147 | if( src.type() == _dst.type() ) 148 | transpose(src, _dst); 149 | else 150 | Mat(src.t()).convertTo(_dst, _dst.type()); 151 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 152 | } 153 | else 154 | { 155 | Mat _dst(src.rows, src.cols, DataType<_Tp>::type, 156 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 157 | src.convertTo(_dst, _dst.type()); 158 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 159 | } 160 | } 161 | 162 | 163 | template 164 | void cv2eigen( const Mat& src, 165 | Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) 166 | { 167 | CV_Assert(src.rows == 1); 168 | dst.resize(src.cols); 169 | if( !(dst.Flags & Eigen::RowMajorBit) ) 170 | { 171 | Mat _dst(src.cols, src.rows, DataType<_Tp>::type, 172 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 173 | if( src.type() == _dst.type() ) 174 | transpose(src, _dst); 175 | else 176 | Mat(src.t()).convertTo(_dst, _dst.type()); 177 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 178 | } 179 | else 180 | { 181 | Mat _dst(src.rows, src.cols, DataType<_Tp>::type, 182 | dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); 183 | src.convertTo(_dst, _dst.type()); 184 | CV_DbgAssert(_dst.data == (uchar*)dst.data()); 185 | } 186 | } 187 | 188 | } 189 | 190 | #endif 191 | 192 | #endif 193 | 194 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/core/version.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 | // 40 | //M*/ 41 | 42 | /* 43 | definition of the current version of OpenCV 44 | Usefull to test in user programs 45 | */ 46 | 47 | #ifndef __OPENCV_VERSION_HPP__ 48 | #define __OPENCV_VERSION_HPP__ 49 | 50 | #define CV_MAJOR_VERSION 2 51 | #define CV_MINOR_VERSION 4 52 | #define CV_SUBMINOR_VERSION 2 53 | 54 | #define CVAUX_STR_EXP(__A) #__A 55 | #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) 56 | #define CV_VERSION CVAUX_STR(CV_MAJOR_VERSION) "." CVAUX_STR(CV_MINOR_VERSION) "." CVAUX_STR(CV_SUBMINOR_VERSION) 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/all_indices.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). 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 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | *************************************************************************/ 28 | 29 | 30 | #ifndef OPENCV_FLANN_ALL_INDICES_H_ 31 | #define OPENCV_FLANN_ALL_INDICES_H_ 32 | 33 | #include "general.h" 34 | 35 | #include "nn_index.h" 36 | #include "kdtree_index.h" 37 | #include "kdtree_single_index.h" 38 | #include "kmeans_index.h" 39 | #include "composite_index.h" 40 | #include "linear_index.h" 41 | #include "hierarchical_clustering_index.h" 42 | #include "lsh_index.h" 43 | #include "autotuned_index.h" 44 | 45 | 46 | namespace cvflann 47 | { 48 | 49 | template 50 | struct index_creator 51 | { 52 | static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) 53 | { 54 | flann_algorithm_t index_type = get_param(params, "algorithm"); 55 | 56 | NNIndex* nnIndex; 57 | switch (index_type) { 58 | case FLANN_INDEX_LINEAR: 59 | nnIndex = new LinearIndex(dataset, params, distance); 60 | break; 61 | case FLANN_INDEX_KDTREE_SINGLE: 62 | nnIndex = new KDTreeSingleIndex(dataset, params, distance); 63 | break; 64 | case FLANN_INDEX_KDTREE: 65 | nnIndex = new KDTreeIndex(dataset, params, distance); 66 | break; 67 | case FLANN_INDEX_KMEANS: 68 | nnIndex = new KMeansIndex(dataset, params, distance); 69 | break; 70 | case FLANN_INDEX_COMPOSITE: 71 | nnIndex = new CompositeIndex(dataset, params, distance); 72 | break; 73 | case FLANN_INDEX_AUTOTUNED: 74 | nnIndex = new AutotunedIndex(dataset, params, distance); 75 | break; 76 | case FLANN_INDEX_HIERARCHICAL: 77 | nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); 78 | break; 79 | case FLANN_INDEX_LSH: 80 | nnIndex = new LshIndex(dataset, params, distance); 81 | break; 82 | default: 83 | throw FLANNException("Unknown index type"); 84 | } 85 | 86 | return nnIndex; 87 | } 88 | }; 89 | 90 | template 91 | struct index_creator 92 | { 93 | static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) 94 | { 95 | flann_algorithm_t index_type = get_param(params, "algorithm"); 96 | 97 | NNIndex* nnIndex; 98 | switch (index_type) { 99 | case FLANN_INDEX_LINEAR: 100 | nnIndex = new LinearIndex(dataset, params, distance); 101 | break; 102 | case FLANN_INDEX_KMEANS: 103 | nnIndex = new KMeansIndex(dataset, params, distance); 104 | break; 105 | case FLANN_INDEX_HIERARCHICAL: 106 | nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); 107 | break; 108 | case FLANN_INDEX_LSH: 109 | nnIndex = new LshIndex(dataset, params, distance); 110 | break; 111 | default: 112 | throw FLANNException("Unknown index type"); 113 | } 114 | 115 | return nnIndex; 116 | } 117 | }; 118 | 119 | template 120 | struct index_creator 121 | { 122 | static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) 123 | { 124 | flann_algorithm_t index_type = get_param(params, "algorithm"); 125 | 126 | NNIndex* nnIndex; 127 | switch (index_type) { 128 | case FLANN_INDEX_LINEAR: 129 | nnIndex = new LinearIndex(dataset, params, distance); 130 | break; 131 | case FLANN_INDEX_HIERARCHICAL: 132 | nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); 133 | break; 134 | case FLANN_INDEX_LSH: 135 | nnIndex = new LshIndex(dataset, params, distance); 136 | break; 137 | default: 138 | throw FLANNException("Unknown index type"); 139 | } 140 | 141 | return nnIndex; 142 | } 143 | }; 144 | 145 | template 146 | NNIndex* create_index_by_type(const Matrix& dataset, const IndexParams& params, const Distance& distance) 147 | { 148 | return index_creator::create(dataset, params,distance); 151 | } 152 | 153 | } 154 | 155 | #endif /* OPENCV_FLANN_ALL_INDICES_H_ */ 156 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/allocator.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_ALLOCATOR_H_ 32 | #define OPENCV_FLANN_ALLOCATOR_H_ 33 | 34 | #include 35 | #include 36 | 37 | 38 | namespace cvflann 39 | { 40 | 41 | /** 42 | * Allocates (using C's malloc) a generic type T. 43 | * 44 | * Params: 45 | * count = number of instances to allocate. 46 | * Returns: pointer (of type T*) to memory buffer 47 | */ 48 | template 49 | T* allocate(size_t count = 1) 50 | { 51 | T* mem = (T*) ::malloc(sizeof(T)*count); 52 | return mem; 53 | } 54 | 55 | 56 | /** 57 | * Pooled storage allocator 58 | * 59 | * The following routines allow for the efficient allocation of storage in 60 | * small chunks from a specified pool. Rather than allowing each structure 61 | * to be freed individually, an entire pool of storage is freed at once. 62 | * This method has two advantages over just using malloc() and free(). First, 63 | * it is far more efficient for allocating small objects, as there is 64 | * no overhead for remembering all the information needed to free each 65 | * object or consolidating fragmented memory. Second, the decision about 66 | * how long to keep an object is made at the time of allocation, and there 67 | * is no need to track down all the objects to free them. 68 | * 69 | */ 70 | 71 | const size_t WORDSIZE=16; 72 | const size_t BLOCKSIZE=8192; 73 | 74 | class PooledAllocator 75 | { 76 | /* We maintain memory alignment to word boundaries by requiring that all 77 | allocations be in multiples of the machine wordsize. */ 78 | /* Size of machine word in bytes. Must be power of 2. */ 79 | /* Minimum number of bytes requested at a time from the system. Must be multiple of WORDSIZE. */ 80 | 81 | 82 | int remaining; /* Number of bytes left in current block of storage. */ 83 | void* base; /* Pointer to base of current block of storage. */ 84 | void* loc; /* Current location in block to next allocate memory. */ 85 | int blocksize; 86 | 87 | 88 | public: 89 | int usedMemory; 90 | int wastedMemory; 91 | 92 | /** 93 | Default constructor. Initializes a new pool. 94 | */ 95 | PooledAllocator(int blockSize = BLOCKSIZE) 96 | { 97 | blocksize = blockSize; 98 | remaining = 0; 99 | base = NULL; 100 | 101 | usedMemory = 0; 102 | wastedMemory = 0; 103 | } 104 | 105 | /** 106 | * Destructor. Frees all the memory allocated in this pool. 107 | */ 108 | ~PooledAllocator() 109 | { 110 | void* prev; 111 | 112 | while (base != NULL) { 113 | prev = *((void**) base); /* Get pointer to prev block. */ 114 | ::free(base); 115 | base = prev; 116 | } 117 | } 118 | 119 | /** 120 | * Returns a pointer to a piece of new memory of the given size in bytes 121 | * allocated from the pool. 122 | */ 123 | void* allocateMemory(int size) 124 | { 125 | int blockSize; 126 | 127 | /* Round size up to a multiple of wordsize. The following expression 128 | only works for WORDSIZE that is a power of 2, by masking last bits of 129 | incremented size to zero. 130 | */ 131 | size = (size + (WORDSIZE - 1)) & ~(WORDSIZE - 1); 132 | 133 | /* Check whether a new block must be allocated. Note that the first word 134 | of a block is reserved for a pointer to the previous block. 135 | */ 136 | if (size > remaining) { 137 | 138 | wastedMemory += remaining; 139 | 140 | /* Allocate new storage. */ 141 | blockSize = (size + sizeof(void*) + (WORDSIZE-1) > BLOCKSIZE) ? 142 | size + sizeof(void*) + (WORDSIZE-1) : BLOCKSIZE; 143 | 144 | // use the standard C malloc to allocate memory 145 | void* m = ::malloc(blockSize); 146 | if (!m) { 147 | fprintf(stderr,"Failed to allocate memory.\n"); 148 | return NULL; 149 | } 150 | 151 | /* Fill first word of new block with pointer to previous block. */ 152 | ((void**) m)[0] = base; 153 | base = m; 154 | 155 | int shift = 0; 156 | //int shift = (WORDSIZE - ( (((size_t)m) + sizeof(void*)) & (WORDSIZE-1))) & (WORDSIZE-1); 157 | 158 | remaining = blockSize - sizeof(void*) - shift; 159 | loc = ((char*)m + sizeof(void*) + shift); 160 | } 161 | void* rloc = loc; 162 | loc = (char*)loc + size; 163 | remaining -= size; 164 | 165 | usedMemory += size; 166 | 167 | return rloc; 168 | } 169 | 170 | /** 171 | * Allocates (using this pool) a generic type T. 172 | * 173 | * Params: 174 | * count = number of instances to allocate. 175 | * Returns: pointer (of type T*) to memory buffer 176 | */ 177 | template 178 | T* allocate(size_t count = 1) 179 | { 180 | T* mem = (T*) this->allocateMemory((int)(sizeof(T)*count)); 181 | return mem; 182 | } 183 | 184 | }; 185 | 186 | } 187 | 188 | #endif //OPENCV_FLANN_ALLOCATOR_H_ 189 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/composite_index.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_COMPOSITE_INDEX_H_ 32 | #define OPENCV_FLANN_COMPOSITE_INDEX_H_ 33 | 34 | #include "general.h" 35 | #include "nn_index.h" 36 | #include "kdtree_index.h" 37 | #include "kmeans_index.h" 38 | 39 | namespace cvflann 40 | { 41 | 42 | /** 43 | * Index parameters for the CompositeIndex. 44 | */ 45 | struct CompositeIndexParams : public IndexParams 46 | { 47 | CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, 48 | flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 ) 49 | { 50 | (*this)["algorithm"] = FLANN_INDEX_KMEANS; 51 | // number of randomized trees to use (for kdtree) 52 | (*this)["trees"] = trees; 53 | // branching factor 54 | (*this)["branching"] = branching; 55 | // max iterations to perform in one kmeans clustering (kmeans tree) 56 | (*this)["iterations"] = iterations; 57 | // algorithm used for picking the initial cluster centers for kmeans tree 58 | (*this)["centers_init"] = centers_init; 59 | // cluster boundary index. Used when searching the kmeans tree 60 | (*this)["cb_index"] = cb_index; 61 | } 62 | }; 63 | 64 | 65 | /** 66 | * This index builds a kd-tree index and a k-means index and performs nearest 67 | * neighbour search both indexes. This gives a slight boost in search performance 68 | * as some of the neighbours that are missed by one index are found by the other. 69 | */ 70 | template 71 | class CompositeIndex : public NNIndex 72 | { 73 | public: 74 | typedef typename Distance::ElementType ElementType; 75 | typedef typename Distance::ResultType DistanceType; 76 | 77 | /** 78 | * Index constructor 79 | * @param inputData dataset containing the points to index 80 | * @param params Index parameters 81 | * @param d Distance functor 82 | * @return 83 | */ 84 | CompositeIndex(const Matrix& inputData, const IndexParams& params = CompositeIndexParams(), 85 | Distance d = Distance()) : index_params_(params) 86 | { 87 | kdtree_index_ = new KDTreeIndex(inputData, params, d); 88 | kmeans_index_ = new KMeansIndex(inputData, params, d); 89 | 90 | } 91 | 92 | CompositeIndex(const CompositeIndex&); 93 | CompositeIndex& operator=(const CompositeIndex&); 94 | 95 | virtual ~CompositeIndex() 96 | { 97 | delete kdtree_index_; 98 | delete kmeans_index_; 99 | } 100 | 101 | /** 102 | * @return The index type 103 | */ 104 | flann_algorithm_t getType() const 105 | { 106 | return FLANN_INDEX_COMPOSITE; 107 | } 108 | 109 | /** 110 | * @return Size of the index 111 | */ 112 | size_t size() const 113 | { 114 | return kdtree_index_->size(); 115 | } 116 | 117 | /** 118 | * \returns The dimensionality of the features in this index. 119 | */ 120 | size_t veclen() const 121 | { 122 | return kdtree_index_->veclen(); 123 | } 124 | 125 | /** 126 | * \returns The amount of memory (in bytes) used by the index. 127 | */ 128 | int usedMemory() const 129 | { 130 | return kmeans_index_->usedMemory() + kdtree_index_->usedMemory(); 131 | } 132 | 133 | /** 134 | * \brief Builds the index 135 | */ 136 | void buildIndex() 137 | { 138 | Logger::info("Building kmeans tree...\n"); 139 | kmeans_index_->buildIndex(); 140 | Logger::info("Building kdtree tree...\n"); 141 | kdtree_index_->buildIndex(); 142 | } 143 | 144 | /** 145 | * \brief Saves the index to a stream 146 | * \param stream The stream to save the index to 147 | */ 148 | void saveIndex(FILE* stream) 149 | { 150 | kmeans_index_->saveIndex(stream); 151 | kdtree_index_->saveIndex(stream); 152 | } 153 | 154 | /** 155 | * \brief Loads the index from a stream 156 | * \param stream The stream from which the index is loaded 157 | */ 158 | void loadIndex(FILE* stream) 159 | { 160 | kmeans_index_->loadIndex(stream); 161 | kdtree_index_->loadIndex(stream); 162 | } 163 | 164 | /** 165 | * \returns The index parameters 166 | */ 167 | IndexParams getParameters() const 168 | { 169 | return index_params_; 170 | } 171 | 172 | /** 173 | * \brief Method that searches for nearest-neighbours 174 | */ 175 | void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) 176 | { 177 | kmeans_index_->findNeighbors(result, vec, searchParams); 178 | kdtree_index_->findNeighbors(result, vec, searchParams); 179 | } 180 | 181 | private: 182 | /** The k-means index */ 183 | KMeansIndex* kmeans_index_; 184 | 185 | /** The kd-tree index */ 186 | KDTreeIndex* kdtree_index_; 187 | 188 | /** The index parameters */ 189 | const IndexParams index_params_; 190 | }; 191 | 192 | } 193 | 194 | #endif //OPENCV_FLANN_COMPOSITE_INDEX_H_ 195 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/config.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). 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 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | *************************************************************************/ 28 | 29 | 30 | #ifndef OPENCV_FLANN_CONFIG_H_ 31 | #define OPENCV_FLANN_CONFIG_H_ 32 | 33 | #ifdef FLANN_VERSION_ 34 | #undef FLANN_VERSION_ 35 | #endif 36 | #define FLANN_VERSION_ "1.6.10" 37 | 38 | #endif /* OPENCV_FLANN_CONFIG_H_ */ 39 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/defines.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). 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 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | *************************************************************************/ 28 | 29 | 30 | #ifndef OPENCV_FLANN_DEFINES_H_ 31 | #define OPENCV_FLANN_DEFINES_H_ 32 | 33 | #include "config.h" 34 | 35 | #ifdef FLANN_EXPORT 36 | #undef FLANN_EXPORT 37 | #endif 38 | #ifdef WIN32 39 | /* win32 dll export/import directives */ 40 | #ifdef FLANN_EXPORTS 41 | #define FLANN_EXPORT __declspec(dllexport) 42 | #elif defined(FLANN_STATIC) 43 | #define FLANN_EXPORT 44 | #else 45 | #define FLANN_EXPORT __declspec(dllimport) 46 | #endif 47 | #else 48 | /* unix needs nothing */ 49 | #define FLANN_EXPORT 50 | #endif 51 | 52 | 53 | #ifdef FLANN_DEPRECATED 54 | #undef FLANN_DEPRECATED 55 | #endif 56 | #ifdef __GNUC__ 57 | #define FLANN_DEPRECATED __attribute__ ((deprecated)) 58 | #elif defined(_MSC_VER) 59 | #define FLANN_DEPRECATED __declspec(deprecated) 60 | #else 61 | #pragma message("WARNING: You need to implement FLANN_DEPRECATED for this compiler") 62 | #define FLANN_DEPRECATED 63 | #endif 64 | 65 | 66 | #undef FLANN_PLATFORM_32_BIT 67 | #undef FLANN_PLATFORM_64_BIT 68 | #if defined __amd64__ || defined __x86_64__ || defined _WIN64 || defined _M_X64 69 | #define FLANN_PLATFORM_64_BIT 70 | #else 71 | #define FLANN_PLATFORM_32_BIT 72 | #endif 73 | 74 | 75 | #undef FLANN_ARRAY_LEN 76 | #define FLANN_ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) 77 | 78 | namespace cvflann { 79 | 80 | /* Nearest neighbour index algorithms */ 81 | enum flann_algorithm_t 82 | { 83 | FLANN_INDEX_LINEAR = 0, 84 | FLANN_INDEX_KDTREE = 1, 85 | FLANN_INDEX_KMEANS = 2, 86 | FLANN_INDEX_COMPOSITE = 3, 87 | FLANN_INDEX_KDTREE_SINGLE = 4, 88 | FLANN_INDEX_HIERARCHICAL = 5, 89 | FLANN_INDEX_LSH = 6, 90 | FLANN_INDEX_SAVED = 254, 91 | FLANN_INDEX_AUTOTUNED = 255, 92 | 93 | // deprecated constants, should use the FLANN_INDEX_* ones instead 94 | LINEAR = 0, 95 | KDTREE = 1, 96 | KMEANS = 2, 97 | COMPOSITE = 3, 98 | KDTREE_SINGLE = 4, 99 | SAVED = 254, 100 | AUTOTUNED = 255 101 | }; 102 | 103 | 104 | 105 | enum flann_centers_init_t 106 | { 107 | FLANN_CENTERS_RANDOM = 0, 108 | FLANN_CENTERS_GONZALES = 1, 109 | FLANN_CENTERS_KMEANSPP = 2, 110 | 111 | // deprecated constants, should use the FLANN_CENTERS_* ones instead 112 | CENTERS_RANDOM = 0, 113 | CENTERS_GONZALES = 1, 114 | CENTERS_KMEANSPP = 2 115 | }; 116 | 117 | enum flann_log_level_t 118 | { 119 | FLANN_LOG_NONE = 0, 120 | FLANN_LOG_FATAL = 1, 121 | FLANN_LOG_ERROR = 2, 122 | FLANN_LOG_WARN = 3, 123 | FLANN_LOG_INFO = 4 124 | }; 125 | 126 | enum flann_distance_t 127 | { 128 | FLANN_DIST_EUCLIDEAN = 1, 129 | FLANN_DIST_L2 = 1, 130 | FLANN_DIST_MANHATTAN = 2, 131 | FLANN_DIST_L1 = 2, 132 | FLANN_DIST_MINKOWSKI = 3, 133 | FLANN_DIST_MAX = 4, 134 | FLANN_DIST_HIST_INTERSECT = 5, 135 | FLANN_DIST_HELLINGER = 6, 136 | FLANN_DIST_CHI_SQUARE = 7, 137 | FLANN_DIST_CS = 7, 138 | FLANN_DIST_KULLBACK_LEIBLER = 8, 139 | FLANN_DIST_KL = 8, 140 | 141 | // deprecated constants, should use the FLANN_DIST_* ones instead 142 | EUCLIDEAN = 1, 143 | MANHATTAN = 2, 144 | MINKOWSKI = 3, 145 | MAX_DIST = 4, 146 | HIST_INTERSECT = 5, 147 | HELLINGER = 6, 148 | CS = 7, 149 | KL = 8, 150 | KULLBACK_LEIBLER = 8 151 | }; 152 | 153 | enum flann_datatype_t 154 | { 155 | FLANN_INT8 = 0, 156 | FLANN_INT16 = 1, 157 | FLANN_INT32 = 2, 158 | FLANN_INT64 = 3, 159 | FLANN_UINT8 = 4, 160 | FLANN_UINT16 = 5, 161 | FLANN_UINT32 = 6, 162 | FLANN_UINT64 = 7, 163 | FLANN_FLOAT32 = 8, 164 | FLANN_FLOAT64 = 9 165 | }; 166 | 167 | enum 168 | { 169 | FLANN_CHECKS_UNLIMITED = -1, 170 | FLANN_CHECKS_AUTOTUNED = -2 171 | }; 172 | 173 | } 174 | 175 | #endif /* OPENCV_FLANN_DEFINES_H_ */ 176 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/dummy.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef OPENCV_FLANN_DUMMY_H_ 3 | #define OPENCV_FLANN_DUMMY_H_ 4 | 5 | namespace cvflann 6 | { 7 | 8 | #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS 9 | __declspec(dllexport) 10 | #endif 11 | void dummyfunc(); 12 | 13 | } 14 | 15 | 16 | #endif /* OPENCV_FLANN_DUMMY_H_ */ 17 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/dynamic_bitset.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | /*********************************************************************** 32 | * Author: Vincent Rabaud 33 | *************************************************************************/ 34 | 35 | #ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_ 36 | #define OPENCV_FLANN_DYNAMIC_BITSET_H_ 37 | 38 | #ifndef FLANN_USE_BOOST 39 | # define FLANN_USE_BOOST 0 40 | #endif 41 | //#define FLANN_USE_BOOST 1 42 | #if FLANN_USE_BOOST 43 | #include 44 | typedef boost::dynamic_bitset<> DynamicBitset; 45 | #else 46 | 47 | #include 48 | 49 | #include "dist.h" 50 | 51 | namespace cvflann { 52 | 53 | /** Class re-implementing the boost version of it 54 | * This helps not depending on boost, it also does not do the bound checks 55 | * and has a way to reset a block for speed 56 | */ 57 | class DynamicBitset 58 | { 59 | public: 60 | /** @param default constructor 61 | */ 62 | DynamicBitset() 63 | { 64 | } 65 | 66 | /** @param only constructor we use in our code 67 | * @param the size of the bitset (in bits) 68 | */ 69 | DynamicBitset(size_t sz) 70 | { 71 | resize(sz); 72 | reset(); 73 | } 74 | 75 | /** Sets all the bits to 0 76 | */ 77 | void clear() 78 | { 79 | std::fill(bitset_.begin(), bitset_.end(), 0); 80 | } 81 | 82 | /** @brief checks if the bitset is empty 83 | * @return true if the bitset is empty 84 | */ 85 | bool empty() const 86 | { 87 | return bitset_.empty(); 88 | } 89 | 90 | /** @param set all the bits to 0 91 | */ 92 | void reset() 93 | { 94 | std::fill(bitset_.begin(), bitset_.end(), 0); 95 | } 96 | 97 | /** @brief set one bit to 0 98 | * @param 99 | */ 100 | void reset(size_t index) 101 | { 102 | bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_)); 103 | } 104 | 105 | /** @brief sets a specific bit to 0, and more bits too 106 | * This function is useful when resetting a given set of bits so that the 107 | * whole bitset ends up being 0: if that's the case, we don't care about setting 108 | * other bits to 0 109 | * @param 110 | */ 111 | void reset_block(size_t index) 112 | { 113 | bitset_[index / cell_bit_size_] = 0; 114 | } 115 | 116 | /** @param resize the bitset so that it contains at least size bits 117 | * @param size 118 | */ 119 | void resize(size_t sz) 120 | { 121 | size_ = sz; 122 | bitset_.resize(sz / cell_bit_size_ + 1); 123 | } 124 | 125 | /** @param set a bit to true 126 | * @param index the index of the bit to set to 1 127 | */ 128 | void set(size_t index) 129 | { 130 | bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_); 131 | } 132 | 133 | /** @param gives the number of contained bits 134 | */ 135 | size_t size() const 136 | { 137 | return size_; 138 | } 139 | 140 | /** @param check if a bit is set 141 | * @param index the index of the bit to check 142 | * @return true if the bit is set 143 | */ 144 | bool test(size_t index) const 145 | { 146 | return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0; 147 | } 148 | 149 | private: 150 | std::vector bitset_; 151 | size_t size_; 152 | static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t); 153 | }; 154 | 155 | } // namespace cvflann 156 | 157 | #endif 158 | 159 | #endif // OPENCV_FLANN_DYNAMIC_BITSET_H_ 160 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/general.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_GENERAL_H_ 32 | #define OPENCV_FLANN_GENERAL_H_ 33 | 34 | #include "defines.h" 35 | #include 36 | #include 37 | 38 | namespace cvflann 39 | { 40 | 41 | class FLANNException : public std::runtime_error 42 | { 43 | public: 44 | FLANNException(const char* message) : std::runtime_error(message) { } 45 | 46 | FLANNException(const std::string& message) : std::runtime_error(message) { } 47 | }; 48 | 49 | } 50 | 51 | 52 | #endif /* OPENCV_FLANN_GENERAL_H_ */ 53 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/ground_truth.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_GROUND_TRUTH_H_ 32 | #define OPENCV_FLANN_GROUND_TRUTH_H_ 33 | 34 | #include "dist.h" 35 | #include "matrix.h" 36 | 37 | 38 | namespace cvflann 39 | { 40 | 41 | template 42 | void find_nearest(const Matrix& dataset, typename Distance::ElementType* query, int* matches, int nn, 43 | int skip = 0, Distance distance = Distance()) 44 | { 45 | typedef typename Distance::ElementType ElementType; 46 | typedef typename Distance::ResultType DistanceType; 47 | int n = nn + skip; 48 | 49 | std::vector match(n); 50 | std::vector dists(n); 51 | 52 | dists[0] = distance(dataset[0], query, dataset.cols); 53 | match[0] = 0; 54 | int dcnt = 1; 55 | 56 | for (size_t i=1; i=1 && dists[j] 84 | void compute_ground_truth(const Matrix& dataset, const Matrix& testset, Matrix& matches, 85 | int skip=0, Distance d = Distance()) 86 | { 87 | for (size_t i=0; i(dataset, testset[i], matches[i], (int)matches.cols, skip, d); 89 | } 90 | } 91 | 92 | 93 | } 94 | 95 | #endif //OPENCV_FLANN_GROUND_TRUTH_H_ 96 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/hdf5.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). 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 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | *************************************************************************/ 28 | 29 | 30 | #ifndef OPENCV_FLANN_HDF5_H_ 31 | #define OPENCV_FLANN_HDF5_H_ 32 | 33 | #include 34 | 35 | #include "matrix.h" 36 | 37 | 38 | namespace cvflann 39 | { 40 | 41 | namespace 42 | { 43 | 44 | template 45 | hid_t get_hdf5_type() 46 | { 47 | throw FLANNException("Unsupported type for IO operations"); 48 | } 49 | 50 | template<> 51 | hid_t get_hdf5_type() { return H5T_NATIVE_CHAR; } 52 | template<> 53 | hid_t get_hdf5_type() { return H5T_NATIVE_UCHAR; } 54 | template<> 55 | hid_t get_hdf5_type() { return H5T_NATIVE_SHORT; } 56 | template<> 57 | hid_t get_hdf5_type() { return H5T_NATIVE_USHORT; } 58 | template<> 59 | hid_t get_hdf5_type() { return H5T_NATIVE_INT; } 60 | template<> 61 | hid_t get_hdf5_type() { return H5T_NATIVE_UINT; } 62 | template<> 63 | hid_t get_hdf5_type() { return H5T_NATIVE_LONG; } 64 | template<> 65 | hid_t get_hdf5_type() { return H5T_NATIVE_ULONG; } 66 | template<> 67 | hid_t get_hdf5_type() { return H5T_NATIVE_FLOAT; } 68 | template<> 69 | hid_t get_hdf5_type() { return H5T_NATIVE_DOUBLE; } 70 | } 71 | 72 | 73 | #define CHECK_ERROR(x,y) if ((x)<0) throw FLANNException((y)); 74 | 75 | template 76 | void save_to_file(const cvflann::Matrix& dataset, const std::string& filename, const std::string& name) 77 | { 78 | 79 | #if H5Eset_auto_vers == 2 80 | H5Eset_auto( H5E_DEFAULT, NULL, NULL ); 81 | #else 82 | H5Eset_auto( NULL, NULL ); 83 | #endif 84 | 85 | herr_t status; 86 | hid_t file_id; 87 | file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); 88 | if (file_id < 0) { 89 | file_id = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); 90 | } 91 | CHECK_ERROR(file_id,"Error creating hdf5 file."); 92 | 93 | hsize_t dimsf[2]; // dataset dimensions 94 | dimsf[0] = dataset.rows; 95 | dimsf[1] = dataset.cols; 96 | 97 | hid_t space_id = H5Screate_simple(2, dimsf, NULL); 98 | hid_t memspace_id = H5Screate_simple(2, dimsf, NULL); 99 | 100 | hid_t dataset_id; 101 | #if H5Dcreate_vers == 2 102 | dataset_id = H5Dcreate2(file_id, name.c_str(), get_hdf5_type(), space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); 103 | #else 104 | dataset_id = H5Dcreate(file_id, name.c_str(), get_hdf5_type(), space_id, H5P_DEFAULT); 105 | #endif 106 | 107 | if (dataset_id<0) { 108 | #if H5Dopen_vers == 2 109 | dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); 110 | #else 111 | dataset_id = H5Dopen(file_id, name.c_str()); 112 | #endif 113 | } 114 | CHECK_ERROR(dataset_id,"Error creating or opening dataset in file."); 115 | 116 | status = H5Dwrite(dataset_id, get_hdf5_type(), memspace_id, space_id, H5P_DEFAULT, dataset.data ); 117 | CHECK_ERROR(status, "Error writing to dataset"); 118 | 119 | H5Sclose(memspace_id); 120 | H5Sclose(space_id); 121 | H5Dclose(dataset_id); 122 | H5Fclose(file_id); 123 | 124 | } 125 | 126 | 127 | template 128 | void load_from_file(cvflann::Matrix& dataset, const std::string& filename, const std::string& name) 129 | { 130 | herr_t status; 131 | hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); 132 | CHECK_ERROR(file_id,"Error opening hdf5 file."); 133 | 134 | hid_t dataset_id; 135 | #if H5Dopen_vers == 2 136 | dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); 137 | #else 138 | dataset_id = H5Dopen(file_id, name.c_str()); 139 | #endif 140 | CHECK_ERROR(dataset_id,"Error opening dataset in file."); 141 | 142 | hid_t space_id = H5Dget_space(dataset_id); 143 | 144 | hsize_t dims_out[2]; 145 | H5Sget_simple_extent_dims(space_id, dims_out, NULL); 146 | 147 | dataset = cvflann::Matrix(new T[dims_out[0]*dims_out[1]], dims_out[0], dims_out[1]); 148 | 149 | status = H5Dread(dataset_id, get_hdf5_type(), H5S_ALL, H5S_ALL, H5P_DEFAULT, dataset[0]); 150 | CHECK_ERROR(status, "Error reading dataset"); 151 | 152 | H5Sclose(space_id); 153 | H5Dclose(dataset_id); 154 | H5Fclose(file_id); 155 | } 156 | 157 | 158 | #ifdef HAVE_MPI 159 | 160 | namespace mpi 161 | { 162 | /** 163 | * Loads a the hyperslice corresponding to this processor from a hdf5 file. 164 | * @param flann_dataset Dataset where the data is loaded 165 | * @param filename HDF5 file name 166 | * @param name Name of dataset inside file 167 | */ 168 | template 169 | void load_from_file(cvflann::Matrix& dataset, const std::string& filename, const std::string& name) 170 | { 171 | MPI_Comm comm = MPI_COMM_WORLD; 172 | MPI_Info info = MPI_INFO_NULL; 173 | 174 | int mpi_size, mpi_rank; 175 | MPI_Comm_size(comm, &mpi_size); 176 | MPI_Comm_rank(comm, &mpi_rank); 177 | 178 | herr_t status; 179 | 180 | hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); 181 | H5Pset_fapl_mpio(plist_id, comm, info); 182 | hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, plist_id); 183 | CHECK_ERROR(file_id,"Error opening hdf5 file."); 184 | H5Pclose(plist_id); 185 | hid_t dataset_id; 186 | #if H5Dopen_vers == 2 187 | dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); 188 | #else 189 | dataset_id = H5Dopen(file_id, name.c_str()); 190 | #endif 191 | CHECK_ERROR(dataset_id,"Error opening dataset in file."); 192 | 193 | hid_t space_id = H5Dget_space(dataset_id); 194 | hsize_t dims[2]; 195 | H5Sget_simple_extent_dims(space_id, dims, NULL); 196 | 197 | hsize_t count[2]; 198 | hsize_t offset[2]; 199 | 200 | hsize_t item_cnt = dims[0]/mpi_size+(dims[0]%mpi_size==0 ? 0 : 1); 201 | hsize_t cnt = (mpi_rank(), memspace_id, space_id, plist_id, dataset.data); 219 | CHECK_ERROR(status, "Error reading dataset"); 220 | 221 | H5Pclose(plist_id); 222 | H5Sclose(space_id); 223 | H5Sclose(memspace_id); 224 | H5Dclose(dataset_id); 225 | H5Fclose(file_id); 226 | } 227 | } 228 | #endif // HAVE_MPI 229 | } // namespace cvflann::mpi 230 | 231 | #endif /* OPENCV_FLANN_HDF5_H_ */ 232 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/heap.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_HEAP_H_ 32 | #define OPENCV_FLANN_HEAP_H_ 33 | 34 | #include 35 | #include 36 | 37 | namespace cvflann 38 | { 39 | 40 | /** 41 | * Priority Queue Implementation 42 | * 43 | * The priority queue is implemented with a heap. A heap is a complete 44 | * (full) binary tree in which each parent is less than both of its 45 | * children, but the order of the children is unspecified. 46 | */ 47 | template 48 | class Heap 49 | { 50 | 51 | /** 52 | * Storage array for the heap. 53 | * Type T must be comparable. 54 | */ 55 | std::vector heap; 56 | int length; 57 | 58 | /** 59 | * Number of element in the heap 60 | */ 61 | int count; 62 | 63 | 64 | 65 | public: 66 | /** 67 | * Constructor. 68 | * 69 | * Params: 70 | * sz = heap size 71 | */ 72 | 73 | Heap(int sz) 74 | { 75 | length = sz; 76 | heap.reserve(length); 77 | count = 0; 78 | } 79 | 80 | /** 81 | * 82 | * Returns: heap size 83 | */ 84 | int size() 85 | { 86 | return count; 87 | } 88 | 89 | /** 90 | * Tests if the heap is empty 91 | * 92 | * Returns: true is heap empty, false otherwise 93 | */ 94 | bool empty() 95 | { 96 | return size()==0; 97 | } 98 | 99 | /** 100 | * Clears the heap. 101 | */ 102 | void clear() 103 | { 104 | heap.clear(); 105 | count = 0; 106 | } 107 | 108 | struct CompareT 109 | { 110 | bool operator()(const T& t_1, const T& t_2) const 111 | { 112 | return t_2 < t_1; 113 | } 114 | }; 115 | 116 | /** 117 | * Insert a new element in the heap. 118 | * 119 | * We select the next empty leaf node, and then keep moving any larger 120 | * parents down until the right location is found to store this element. 121 | * 122 | * Params: 123 | * value = the new element to be inserted in the heap 124 | */ 125 | void insert(T value) 126 | { 127 | /* If heap is full, then return without adding this element. */ 128 | if (count == length) { 129 | return; 130 | } 131 | 132 | heap.push_back(value); 133 | static CompareT compareT; 134 | std::push_heap(heap.begin(), heap.end(), compareT); 135 | ++count; 136 | } 137 | 138 | 139 | 140 | /** 141 | * Returns the node of minimum value from the heap (top of the heap). 142 | * 143 | * Params: 144 | * value = out parameter used to return the min element 145 | * Returns: false if heap empty 146 | */ 147 | bool popMin(T& value) 148 | { 149 | if (count == 0) { 150 | return false; 151 | } 152 | 153 | value = heap[0]; 154 | static CompareT compareT; 155 | std::pop_heap(heap.begin(), heap.end(), compareT); 156 | heap.pop_back(); 157 | --count; 158 | 159 | return true; /* Return old last node. */ 160 | } 161 | }; 162 | 163 | } 164 | 165 | #endif //OPENCV_FLANN_HEAP_H_ 166 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/linear_index.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_LINEAR_INDEX_H_ 32 | #define OPENCV_FLANN_LINEAR_INDEX_H_ 33 | 34 | #include "general.h" 35 | #include "nn_index.h" 36 | 37 | namespace cvflann 38 | { 39 | 40 | struct LinearIndexParams : public IndexParams 41 | { 42 | LinearIndexParams() 43 | { 44 | (* this)["algorithm"] = FLANN_INDEX_LINEAR; 45 | } 46 | }; 47 | 48 | template 49 | class LinearIndex : public NNIndex 50 | { 51 | public: 52 | 53 | typedef typename Distance::ElementType ElementType; 54 | typedef typename Distance::ResultType DistanceType; 55 | 56 | 57 | LinearIndex(const Matrix& inputData, const IndexParams& params = LinearIndexParams(), 58 | Distance d = Distance()) : 59 | dataset_(inputData), index_params_(params), distance_(d) 60 | { 61 | } 62 | 63 | LinearIndex(const LinearIndex&); 64 | LinearIndex& operator=(const LinearIndex&); 65 | 66 | flann_algorithm_t getType() const 67 | { 68 | return FLANN_INDEX_LINEAR; 69 | } 70 | 71 | 72 | size_t size() const 73 | { 74 | return dataset_.rows; 75 | } 76 | 77 | size_t veclen() const 78 | { 79 | return dataset_.cols; 80 | } 81 | 82 | 83 | int usedMemory() const 84 | { 85 | return 0; 86 | } 87 | 88 | void buildIndex() 89 | { 90 | /* nothing to do here for linear search */ 91 | } 92 | 93 | void saveIndex(FILE*) 94 | { 95 | /* nothing to do here for linear search */ 96 | } 97 | 98 | 99 | void loadIndex(FILE*) 100 | { 101 | /* nothing to do here for linear search */ 102 | 103 | index_params_["algorithm"] = getType(); 104 | } 105 | 106 | void findNeighbors(ResultSet& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/) 107 | { 108 | ElementType* data = dataset_.data; 109 | for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) { 110 | DistanceType dist = distance_(data, vec, dataset_.cols); 111 | resultSet.addPoint(dist, (int)i); 112 | } 113 | } 114 | 115 | IndexParams getParameters() const 116 | { 117 | return index_params_; 118 | } 119 | 120 | private: 121 | /** The dataset */ 122 | const Matrix dataset_; 123 | /** Index parameters */ 124 | IndexParams index_params_; 125 | /** Index distance */ 126 | Distance distance_; 127 | 128 | }; 129 | 130 | } 131 | 132 | #endif // OPENCV_FLANN_LINEAR_INDEX_H_ 133 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/logger.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_LOGGER_H 32 | #define OPENCV_FLANN_LOGGER_H 33 | 34 | #include 35 | #include 36 | 37 | #include "defines.h" 38 | 39 | 40 | namespace cvflann 41 | { 42 | 43 | class Logger 44 | { 45 | Logger() : stream(stdout), logLevel(FLANN_LOG_WARN) {} 46 | 47 | ~Logger() 48 | { 49 | if ((stream!=NULL)&&(stream!=stdout)) { 50 | fclose(stream); 51 | } 52 | } 53 | 54 | static Logger& instance() 55 | { 56 | static Logger logger; 57 | return logger; 58 | } 59 | 60 | void _setDestination(const char* name) 61 | { 62 | if (name==NULL) { 63 | stream = stdout; 64 | } 65 | else { 66 | stream = fopen(name,"w"); 67 | if (stream == NULL) { 68 | stream = stdout; 69 | } 70 | } 71 | } 72 | 73 | int _log(int level, const char* fmt, va_list arglist) 74 | { 75 | if (level > logLevel ) return -1; 76 | int ret = vfprintf(stream, fmt, arglist); 77 | return ret; 78 | } 79 | 80 | public: 81 | /** 82 | * Sets the logging level. All messages with lower priority will be ignored. 83 | * @param level Logging level 84 | */ 85 | static void setLevel(int level) { instance().logLevel = level; } 86 | 87 | /** 88 | * Sets the logging destination 89 | * @param name Filename or NULL for console 90 | */ 91 | static void setDestination(const char* name) { instance()._setDestination(name); } 92 | 93 | /** 94 | * Print log message 95 | * @param level Log level 96 | * @param fmt Message format 97 | * @return 98 | */ 99 | static int log(int level, const char* fmt, ...) 100 | { 101 | va_list arglist; 102 | va_start(arglist, fmt); 103 | int ret = instance()._log(level,fmt,arglist); 104 | va_end(arglist); 105 | return ret; 106 | } 107 | 108 | #define LOG_METHOD(NAME,LEVEL) \ 109 | static int NAME(const char* fmt, ...) \ 110 | { \ 111 | va_list ap; \ 112 | va_start(ap, fmt); \ 113 | int ret = instance()._log(LEVEL, fmt, ap); \ 114 | va_end(ap); \ 115 | return ret; \ 116 | } 117 | 118 | LOG_METHOD(fatal, FLANN_LOG_FATAL) 119 | LOG_METHOD(error, FLANN_LOG_ERROR) 120 | LOG_METHOD(warn, FLANN_LOG_WARN) 121 | LOG_METHOD(info, FLANN_LOG_INFO) 122 | 123 | private: 124 | FILE* stream; 125 | int logLevel; 126 | }; 127 | 128 | } 129 | 130 | #endif //OPENCV_FLANN_LOGGER_H 131 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/matrix.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_DATASET_H_ 32 | #define OPENCV_FLANN_DATASET_H_ 33 | 34 | #include 35 | 36 | #include "general.h" 37 | 38 | namespace cvflann 39 | { 40 | 41 | /** 42 | * Class that implements a simple rectangular matrix stored in a memory buffer and 43 | * provides convenient matrix-like access using the [] operators. 44 | */ 45 | template 46 | class Matrix 47 | { 48 | public: 49 | typedef T type; 50 | 51 | size_t rows; 52 | size_t cols; 53 | size_t stride; 54 | T* data; 55 | 56 | Matrix() : rows(0), cols(0), stride(0), data(NULL) 57 | { 58 | } 59 | 60 | Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) : 61 | rows(rows_), cols(cols_), stride(stride_), data(data_) 62 | { 63 | if (stride==0) stride = cols; 64 | } 65 | 66 | /** 67 | * Convenience function for deallocating the storage data. 68 | */ 69 | FLANN_DEPRECATED void free() 70 | { 71 | fprintf(stderr, "The cvflann::Matrix::free() method is deprecated " 72 | "and it does not do any memory deallocation any more. You are" 73 | "responsible for deallocating the matrix memory (by doing" 74 | "'delete[] matrix.data' for example)"); 75 | } 76 | 77 | /** 78 | * Operator that return a (pointer to a) row of the data. 79 | */ 80 | T* operator[](size_t index) const 81 | { 82 | return data+index*stride; 83 | } 84 | }; 85 | 86 | 87 | class UntypedMatrix 88 | { 89 | public: 90 | size_t rows; 91 | size_t cols; 92 | void* data; 93 | flann_datatype_t type; 94 | 95 | UntypedMatrix(void* data_, long rows_, long cols_) : 96 | rows(rows_), cols(cols_), data(data_) 97 | { 98 | } 99 | 100 | ~UntypedMatrix() 101 | { 102 | } 103 | 104 | 105 | template 106 | Matrix as() 107 | { 108 | return Matrix((T*)data, rows, cols); 109 | } 110 | }; 111 | 112 | 113 | 114 | } 115 | 116 | #endif //OPENCV_FLANN_DATASET_H_ 117 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/miniflann.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 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef _OPENCV_MINIFLANN_HPP_ 44 | #define _OPENCV_MINIFLANN_HPP_ 45 | 46 | #ifdef __cplusplus 47 | 48 | #include "opencv2/core/core.hpp" 49 | #include "opencv2/flann/defines.h" 50 | 51 | namespace cv 52 | { 53 | 54 | namespace flann 55 | { 56 | 57 | struct CV_EXPORTS IndexParams 58 | { 59 | IndexParams(); 60 | ~IndexParams(); 61 | 62 | std::string getString(const std::string& key, const std::string& defaultVal=std::string()) const; 63 | int getInt(const std::string& key, int defaultVal=-1) const; 64 | double getDouble(const std::string& key, double defaultVal=-1) const; 65 | 66 | void setString(const std::string& key, const std::string& value); 67 | void setInt(const std::string& key, int value); 68 | void setDouble(const std::string& key, double value); 69 | void setFloat(const std::string& key, float value); 70 | void setBool(const std::string& key, bool value); 71 | void setAlgorithm(int value); 72 | 73 | void getAll(std::vector& names, 74 | std::vector& types, 75 | std::vector& strValues, 76 | std::vector& numValues) const; 77 | 78 | void* params; 79 | }; 80 | 81 | struct CV_EXPORTS KDTreeIndexParams : public IndexParams 82 | { 83 | KDTreeIndexParams(int trees=4); 84 | }; 85 | 86 | struct CV_EXPORTS LinearIndexParams : public IndexParams 87 | { 88 | LinearIndexParams(); 89 | }; 90 | 91 | struct CV_EXPORTS CompositeIndexParams : public IndexParams 92 | { 93 | CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, 94 | cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2 ); 95 | }; 96 | 97 | struct CV_EXPORTS AutotunedIndexParams : public IndexParams 98 | { 99 | AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01, 100 | float memory_weight = 0, float sample_fraction = 0.1); 101 | }; 102 | 103 | struct CV_EXPORTS KMeansIndexParams : public IndexParams 104 | { 105 | KMeansIndexParams(int branching = 32, int iterations = 11, 106 | cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2 ); 107 | }; 108 | 109 | struct CV_EXPORTS LshIndexParams : public IndexParams 110 | { 111 | LshIndexParams(int table_number, int key_size, int multi_probe_level); 112 | }; 113 | 114 | struct CV_EXPORTS SavedIndexParams : public IndexParams 115 | { 116 | SavedIndexParams(const std::string& filename); 117 | }; 118 | 119 | struct CV_EXPORTS SearchParams : public IndexParams 120 | { 121 | SearchParams( int checks = 32, float eps = 0, bool sorted = true ); 122 | }; 123 | 124 | class CV_EXPORTS_W Index 125 | { 126 | public: 127 | CV_WRAP Index(); 128 | CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); 129 | virtual ~Index(); 130 | 131 | CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); 132 | CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices, 133 | OutputArray dists, int knn, const SearchParams& params=SearchParams()); 134 | 135 | CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices, 136 | OutputArray dists, double radius, int maxResults, 137 | const SearchParams& params=SearchParams()); 138 | 139 | CV_WRAP virtual void save(const std::string& filename) const; 140 | CV_WRAP virtual bool load(InputArray features, const std::string& filename); 141 | CV_WRAP virtual void release(); 142 | CV_WRAP cvflann::flann_distance_t getDistance() const; 143 | CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const; 144 | 145 | protected: 146 | cvflann::flann_distance_t distType; 147 | cvflann::flann_algorithm_t algo; 148 | int featureType; 149 | void* index; 150 | }; 151 | 152 | } } // namespace cv::flann 153 | 154 | #endif // __cplusplus 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/nn_index.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_NNINDEX_H 32 | #define OPENCV_FLANN_NNINDEX_H 33 | 34 | #include 35 | 36 | #include "general.h" 37 | #include "matrix.h" 38 | #include "result_set.h" 39 | #include "params.h" 40 | 41 | namespace cvflann 42 | { 43 | 44 | /** 45 | * Nearest-neighbour index base class 46 | */ 47 | template 48 | class NNIndex 49 | { 50 | typedef typename Distance::ElementType ElementType; 51 | typedef typename Distance::ResultType DistanceType; 52 | 53 | public: 54 | 55 | virtual ~NNIndex() {} 56 | 57 | /** 58 | * \brief Builds the index 59 | */ 60 | virtual void buildIndex() = 0; 61 | 62 | /** 63 | * \brief Perform k-nearest neighbor search 64 | * \param[in] queries The query points for which to find the nearest neighbors 65 | * \param[out] indices The indices of the nearest neighbors found 66 | * \param[out] dists Distances to the nearest neighbors found 67 | * \param[in] knn Number of nearest neighbors to return 68 | * \param[in] params Search parameters 69 | */ 70 | virtual void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) 71 | { 72 | assert(queries.cols == veclen()); 73 | assert(indices.rows >= queries.rows); 74 | assert(dists.rows >= queries.rows); 75 | assert(int(indices.cols) >= knn); 76 | assert(int(dists.cols) >= knn); 77 | 78 | #if 0 79 | KNNResultSet resultSet(knn); 80 | for (size_t i = 0; i < queries.rows; i++) { 81 | resultSet.init(indices[i], dists[i]); 82 | findNeighbors(resultSet, queries[i], params); 83 | } 84 | #else 85 | KNNUniqueResultSet resultSet(knn); 86 | for (size_t i = 0; i < queries.rows; i++) { 87 | resultSet.clear(); 88 | findNeighbors(resultSet, queries[i], params); 89 | if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices[i], dists[i], knn); 90 | else resultSet.copy(indices[i], dists[i], knn); 91 | } 92 | #endif 93 | } 94 | 95 | /** 96 | * \brief Perform radius search 97 | * \param[in] query The query point 98 | * \param[out] indices The indinces of the neighbors found within the given radius 99 | * \param[out] dists The distances to the nearest neighbors found 100 | * \param[in] radius The radius used for search 101 | * \param[in] params Search parameters 102 | * \returns Number of neighbors found 103 | */ 104 | virtual int radiusSearch(const Matrix& query, Matrix& indices, Matrix& dists, float radius, const SearchParams& params) 105 | { 106 | if (query.rows != 1) { 107 | fprintf(stderr, "I can only search one feature at a time for range search\n"); 108 | return -1; 109 | } 110 | assert(query.cols == veclen()); 111 | assert(indices.cols == dists.cols); 112 | 113 | int n = 0; 114 | int* indices_ptr = NULL; 115 | DistanceType* dists_ptr = NULL; 116 | if (indices.cols > 0) { 117 | n = (int)indices.cols; 118 | indices_ptr = indices[0]; 119 | dists_ptr = dists[0]; 120 | } 121 | 122 | RadiusUniqueResultSet resultSet((DistanceType)radius); 123 | resultSet.clear(); 124 | findNeighbors(resultSet, query[0], params); 125 | if (n>0) { 126 | if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices_ptr, dists_ptr, n); 127 | else resultSet.copy(indices_ptr, dists_ptr, n); 128 | } 129 | 130 | return (int)resultSet.size(); 131 | } 132 | 133 | /** 134 | * \brief Saves the index to a stream 135 | * \param stream The stream to save the index to 136 | */ 137 | virtual void saveIndex(FILE* stream) = 0; 138 | 139 | /** 140 | * \brief Loads the index from a stream 141 | * \param stream The stream from which the index is loaded 142 | */ 143 | virtual void loadIndex(FILE* stream) = 0; 144 | 145 | /** 146 | * \returns number of features in this index. 147 | */ 148 | virtual size_t size() const = 0; 149 | 150 | /** 151 | * \returns The dimensionality of the features in this index. 152 | */ 153 | virtual size_t veclen() const = 0; 154 | 155 | /** 156 | * \returns The amount of memory (in bytes) used by the index. 157 | */ 158 | virtual int usedMemory() const = 0; 159 | 160 | /** 161 | * \returns The index type (kdtree, kmeans,...) 162 | */ 163 | virtual flann_algorithm_t getType() const = 0; 164 | 165 | /** 166 | * \returns The index parameters 167 | */ 168 | virtual IndexParams getParameters() const = 0; 169 | 170 | 171 | /** 172 | * \brief Method that searches for nearest-neighbours 173 | */ 174 | virtual void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) = 0; 175 | }; 176 | 177 | } 178 | 179 | #endif //OPENCV_FLANN_NNINDEX_H 180 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/object_factory.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_OBJECT_FACTORY_H_ 32 | #define OPENCV_FLANN_OBJECT_FACTORY_H_ 33 | 34 | #include 35 | 36 | namespace cvflann 37 | { 38 | 39 | class CreatorNotFound 40 | { 41 | }; 42 | 43 | template 46 | class ObjectFactory 47 | { 48 | typedef ObjectFactory ThisClass; 49 | typedef std::map ObjectRegistry; 50 | 51 | // singleton class, private constructor 52 | ObjectFactory() {} 53 | 54 | public: 55 | 56 | bool subscribe(UniqueIdType id, ObjectCreator creator) 57 | { 58 | if (object_registry.find(id) != object_registry.end()) return false; 59 | 60 | object_registry[id] = creator; 61 | return true; 62 | } 63 | 64 | bool unregister(UniqueIdType id) 65 | { 66 | return object_registry.erase(id) == 1; 67 | } 68 | 69 | ObjectCreator create(UniqueIdType id) 70 | { 71 | typename ObjectRegistry::const_iterator iter = object_registry.find(id); 72 | 73 | if (iter == object_registry.end()) { 74 | throw CreatorNotFound(); 75 | } 76 | 77 | return iter->second; 78 | } 79 | 80 | static ThisClass& instance() 81 | { 82 | static ThisClass the_factory; 83 | return the_factory; 84 | } 85 | private: 86 | ObjectRegistry object_registry; 87 | }; 88 | 89 | } 90 | 91 | #endif /* OPENCV_FLANN_OBJECT_FACTORY_H_ */ 92 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/params.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). 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 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | *************************************************************************/ 28 | 29 | 30 | #ifndef OPENCV_FLANN_PARAMS_H_ 31 | #define OPENCV_FLANN_PARAMS_H_ 32 | 33 | #include "any.h" 34 | #include "general.h" 35 | #include 36 | #include 37 | 38 | 39 | namespace cvflann 40 | { 41 | 42 | typedef std::map IndexParams; 43 | 44 | struct SearchParams : public IndexParams 45 | { 46 | SearchParams(int checks = 32, float eps = 0, bool sorted = true ) 47 | { 48 | // how many leafs to visit when searching for neighbours (-1 for unlimited) 49 | (*this)["checks"] = checks; 50 | // search for eps-approximate neighbours (default: 0) 51 | (*this)["eps"] = eps; 52 | // only for radius search, require neighbours sorted by distance (default: true) 53 | (*this)["sorted"] = sorted; 54 | } 55 | }; 56 | 57 | 58 | template 59 | T get_param(const IndexParams& params, std::string name, const T& default_value) 60 | { 61 | IndexParams::const_iterator it = params.find(name); 62 | if (it != params.end()) { 63 | return it->second.cast(); 64 | } 65 | else { 66 | return default_value; 67 | } 68 | } 69 | 70 | template 71 | T get_param(const IndexParams& params, std::string name) 72 | { 73 | IndexParams::const_iterator it = params.find(name); 74 | if (it != params.end()) { 75 | return it->second.cast(); 76 | } 77 | else { 78 | throw FLANNException(std::string("Missing parameter '")+name+std::string("' in the parameters given")); 79 | } 80 | } 81 | 82 | inline void print_params(const IndexParams& params) 83 | { 84 | IndexParams::const_iterator it; 85 | 86 | for(it=params.begin(); it!=params.end(); ++it) { 87 | std::cout << it->first << " : " << it->second << std::endl; 88 | } 89 | } 90 | 91 | 92 | 93 | } 94 | 95 | 96 | #endif /* OPENCV_FLANN_PARAMS_H_ */ 97 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/random.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_RANDOM_H 32 | #define OPENCV_FLANN_RANDOM_H 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "general.h" 39 | 40 | namespace cvflann 41 | { 42 | 43 | /** 44 | * Seeds the random number generator 45 | * @param seed Random seed 46 | */ 47 | inline void seed_random(unsigned int seed) 48 | { 49 | srand(seed); 50 | } 51 | 52 | /* 53 | * Generates a random double value. 54 | */ 55 | /** 56 | * Generates a random double value. 57 | * @param high Upper limit 58 | * @param low Lower limit 59 | * @return Random double value 60 | */ 61 | inline double rand_double(double high = 1.0, double low = 0) 62 | { 63 | return low + ((high-low) * (std::rand() / (RAND_MAX + 1.0))); 64 | } 65 | 66 | /** 67 | * Generates a random integer value. 68 | * @param high Upper limit 69 | * @param low Lower limit 70 | * @return Random integer value 71 | */ 72 | inline int rand_int(int high = RAND_MAX, int low = 0) 73 | { 74 | return low + (int) ( double(high-low) * (std::rand() / (RAND_MAX + 1.0))); 75 | } 76 | 77 | /** 78 | * Random number generator that returns a distinct number from 79 | * the [0,n) interval each time. 80 | */ 81 | class UniqueRandom 82 | { 83 | std::vector vals_; 84 | int size_; 85 | int counter_; 86 | 87 | public: 88 | /** 89 | * Constructor. 90 | * @param n Size of the interval from which to generate 91 | * @return 92 | */ 93 | UniqueRandom(int n) 94 | { 95 | init(n); 96 | } 97 | 98 | /** 99 | * Initializes the number generator. 100 | * @param n the size of the interval from which to generate random numbers. 101 | */ 102 | void init(int n) 103 | { 104 | // create and initialize an array of size n 105 | vals_.resize(n); 106 | size_ = n; 107 | for (int i = 0; i < size_; ++i) vals_[i] = i; 108 | 109 | // shuffle the elements in the array 110 | std::random_shuffle(vals_.begin(), vals_.end()); 111 | 112 | counter_ = 0; 113 | } 114 | 115 | /** 116 | * Return a distinct random integer in greater or equal to 0 and less 117 | * than 'n' on each call. It should be called maximum 'n' times. 118 | * Returns: a random integer 119 | */ 120 | int next() 121 | { 122 | if (counter_ == size_) { 123 | return -1; 124 | } 125 | else { 126 | return vals_[counter_++]; 127 | } 128 | } 129 | }; 130 | 131 | } 132 | 133 | #endif //OPENCV_FLANN_RANDOM_H 134 | 135 | 136 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/sampling.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). 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 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | *************************************************************************/ 28 | 29 | 30 | #ifndef OPENCV_FLANN_SAMPLING_H_ 31 | #define OPENCV_FLANN_SAMPLING_H_ 32 | 33 | #include "matrix.h" 34 | #include "random.h" 35 | 36 | namespace cvflann 37 | { 38 | 39 | template 40 | Matrix random_sample(Matrix& srcMatrix, long size, bool remove = false) 41 | { 42 | Matrix newSet(new T[size * srcMatrix.cols], size,srcMatrix.cols); 43 | 44 | T* src,* dest; 45 | for (long i=0; i 63 | Matrix random_sample(const Matrix& srcMatrix, size_t size) 64 | { 65 | UniqueRandom rand((int)srcMatrix.rows); 66 | Matrix newSet(new T[size * srcMatrix.cols], size,srcMatrix.cols); 67 | 68 | T* src,* dest; 69 | for (size_t i=0; i 33 | #include 34 | 35 | #include "general.h" 36 | #include "nn_index.h" 37 | 38 | #ifdef FLANN_SIGNATURE_ 39 | #undef FLANN_SIGNATURE_ 40 | #endif 41 | #define FLANN_SIGNATURE_ "FLANN_INDEX" 42 | 43 | namespace cvflann 44 | { 45 | 46 | template 47 | struct Datatype {}; 48 | template<> 49 | struct Datatype { static flann_datatype_t type() { return FLANN_INT8; } }; 50 | template<> 51 | struct Datatype { static flann_datatype_t type() { return FLANN_INT16; } }; 52 | template<> 53 | struct Datatype { static flann_datatype_t type() { return FLANN_INT32; } }; 54 | template<> 55 | struct Datatype { static flann_datatype_t type() { return FLANN_UINT8; } }; 56 | template<> 57 | struct Datatype { static flann_datatype_t type() { return FLANN_UINT16; } }; 58 | template<> 59 | struct Datatype { static flann_datatype_t type() { return FLANN_UINT32; } }; 60 | template<> 61 | struct Datatype { static flann_datatype_t type() { return FLANN_FLOAT32; } }; 62 | template<> 63 | struct Datatype { static flann_datatype_t type() { return FLANN_FLOAT64; } }; 64 | 65 | 66 | /** 67 | * Structure representing the index header. 68 | */ 69 | struct IndexHeader 70 | { 71 | char signature[16]; 72 | char version[16]; 73 | flann_datatype_t data_type; 74 | flann_algorithm_t index_type; 75 | size_t rows; 76 | size_t cols; 77 | }; 78 | 79 | /** 80 | * Saves index header to stream 81 | * 82 | * @param stream - Stream to save to 83 | * @param index - The index to save 84 | */ 85 | template 86 | void save_header(FILE* stream, const NNIndex& index) 87 | { 88 | IndexHeader header; 89 | memset(header.signature, 0, sizeof(header.signature)); 90 | strcpy(header.signature, FLANN_SIGNATURE_); 91 | memset(header.version, 0, sizeof(header.version)); 92 | strcpy(header.version, FLANN_VERSION_); 93 | header.data_type = Datatype::type(); 94 | header.index_type = index.getType(); 95 | header.rows = index.size(); 96 | header.cols = index.veclen(); 97 | 98 | std::fwrite(&header, sizeof(header),1,stream); 99 | } 100 | 101 | 102 | /** 103 | * 104 | * @param stream - Stream to load from 105 | * @return Index header 106 | */ 107 | inline IndexHeader load_header(FILE* stream) 108 | { 109 | IndexHeader header; 110 | size_t read_size = fread(&header,sizeof(header),1,stream); 111 | 112 | if (read_size!=(size_t)1) { 113 | throw FLANNException("Invalid index file, cannot read"); 114 | } 115 | 116 | if (strcmp(header.signature,FLANN_SIGNATURE_)!=0) { 117 | throw FLANNException("Invalid index file, wrong signature"); 118 | } 119 | 120 | return header; 121 | 122 | } 123 | 124 | 125 | template 126 | void save_value(FILE* stream, const T& value, size_t count = 1) 127 | { 128 | fwrite(&value, sizeof(value),count, stream); 129 | } 130 | 131 | template 132 | void save_value(FILE* stream, const cvflann::Matrix& value) 133 | { 134 | fwrite(&value, sizeof(value),1, stream); 135 | fwrite(value.data, sizeof(T),value.rows*value.cols, stream); 136 | } 137 | 138 | template 139 | void save_value(FILE* stream, const std::vector& value) 140 | { 141 | size_t size = value.size(); 142 | fwrite(&size, sizeof(size_t), 1, stream); 143 | fwrite(&value[0], sizeof(T), size, stream); 144 | } 145 | 146 | template 147 | void load_value(FILE* stream, T& value, size_t count = 1) 148 | { 149 | size_t read_cnt = fread(&value, sizeof(value), count, stream); 150 | if (read_cnt != count) { 151 | throw FLANNException("Cannot read from file"); 152 | } 153 | } 154 | 155 | template 156 | void load_value(FILE* stream, cvflann::Matrix& value) 157 | { 158 | size_t read_cnt = fread(&value, sizeof(value), 1, stream); 159 | if (read_cnt != 1) { 160 | throw FLANNException("Cannot read from file"); 161 | } 162 | value.data = new T[value.rows*value.cols]; 163 | read_cnt = fread(value.data, sizeof(T), value.rows*value.cols, stream); 164 | if (read_cnt != (size_t)(value.rows*value.cols)) { 165 | throw FLANNException("Cannot read from file"); 166 | } 167 | } 168 | 169 | 170 | template 171 | void load_value(FILE* stream, std::vector& value) 172 | { 173 | size_t size; 174 | size_t read_cnt = fread(&size, sizeof(size_t), 1, stream); 175 | if (read_cnt!=1) { 176 | throw FLANNException("Cannot read from file"); 177 | } 178 | value.resize(size); 179 | read_cnt = fread(&value[0], sizeof(T), size, stream); 180 | if (read_cnt != size) { 181 | throw FLANNException("Cannot read from file"); 182 | } 183 | } 184 | 185 | } 186 | 187 | #endif /* OPENCV_FLANN_SAVING_H_ */ 188 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/flann/simplex_downhill.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 6 | * 7 | * THE BSD LICENSE 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | *************************************************************************/ 30 | 31 | #ifndef OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ 32 | #define OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ 33 | 34 | namespace cvflann 35 | { 36 | 37 | /** 38 | Adds val to array vals (and point to array points) and keeping the arrays sorted by vals. 39 | */ 40 | template 41 | void addValue(int pos, float val, float* vals, T* point, T* points, int n) 42 | { 43 | vals[pos] = val; 44 | for (int i=0; i0 && vals[j] 69 | float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL ) 70 | { 71 | const int MAX_ITERATIONS = 10; 72 | 73 | assert(n>0); 74 | 75 | T* p_o = new T[n]; 76 | T* p_r = new T[n]; 77 | T* p_e = new T[n]; 78 | 79 | int alpha = 1; 80 | 81 | int iterations = 0; 82 | 83 | bool ownVals = false; 84 | if (vals == NULL) { 85 | ownVals = true; 86 | vals = new float[n+1]; 87 | for (int i=0; i MAX_ITERATIONS) break; 97 | 98 | // compute average of simplex points (except the highest point) 99 | for (int j=0; j=vals[0])&&(val_r=vals[n]) { 151 | for (int i=0; i 35 | 36 | 37 | namespace cvflann 38 | { 39 | 40 | /** 41 | * A start-stop timer class. 42 | * 43 | * Can be used to time portions of code. 44 | */ 45 | class StartStopTimer 46 | { 47 | clock_t startTime; 48 | 49 | public: 50 | /** 51 | * Value of the timer. 52 | */ 53 | double value; 54 | 55 | 56 | /** 57 | * Constructor. 58 | */ 59 | StartStopTimer() 60 | { 61 | reset(); 62 | } 63 | 64 | /** 65 | * Starts the timer. 66 | */ 67 | void start() 68 | { 69 | startTime = clock(); 70 | } 71 | 72 | /** 73 | * Stops the timer and updates timer value. 74 | */ 75 | void stop() 76 | { 77 | clock_t stopTime = clock(); 78 | value += ( (double)stopTime - startTime) / CLOCKS_PER_SEC; 79 | } 80 | 81 | /** 82 | * Resets the timer value to 0. 83 | */ 84 | void reset() 85 | { 86 | value = 0; 87 | } 88 | 89 | }; 90 | 91 | } 92 | 93 | #endif // FLANN_TIMER_H 94 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/opencv.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 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef __OPENCV_ALL_HPP__ 44 | #define __OPENCV_ALL_HPP__ 45 | 46 | #include "opencv2/core/core_c.h" 47 | #include "opencv2/core/core.hpp" 48 | #include "opencv2/imgproc/imgproc_c.h" 49 | #include "opencv2/imgproc/imgproc.hpp" 50 | #include "opencv2/features2d/features2d.hpp" 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv2/opencv_modules.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ** File generated automatically, do not modify ** 3 | * 4 | * This file defines the list of modules available in current build configuration 5 | * 6 | * 7 | */ 8 | 9 | #define HAVE_OPENCV_CALIB3D 10 | #define HAVE_OPENCV_CONTRIB 11 | #define HAVE_OPENCV_CORE 12 | #define HAVE_OPENCV_FEATURES2D 13 | #define HAVE_OPENCV_FLANN 14 | #define HAVE_OPENCV_GPU 15 | #define HAVE_OPENCV_HIGHGUI 16 | #define HAVE_OPENCV_IMGPROC 17 | #define HAVE_OPENCV_LEGACY 18 | #define HAVE_OPENCV_ML 19 | #define HAVE_OPENCV_NONFREE 20 | #define HAVE_OPENCV_OBJDETECT 21 | #define HAVE_OPENCV_PHOTO 22 | #define HAVE_OPENCV_STITCHING 23 | #define HAVE_OPENCV_TS 24 | #define HAVE_OPENCV_VIDEO 25 | #define HAVE_OPENCV_VIDEOSTAB 26 | 27 | 28 | -------------------------------------------------------------------------------- /external_libs/mexResize/opencv_core242.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/opencv_core242.dll -------------------------------------------------------------------------------- /external_libs/mexResize/opencv_core242.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/opencv_core242.lib -------------------------------------------------------------------------------- /external_libs/mexResize/opencv_imgproc242.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/opencv_imgproc242.dll -------------------------------------------------------------------------------- /external_libs/mexResize/opencv_imgproc242.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mexResize/opencv_imgproc242.lib -------------------------------------------------------------------------------- /external_libs/mtimesx/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, James Tursa 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /external_libs/mtimesx/mtimesx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mtimesx/mtimesx.c -------------------------------------------------------------------------------- /external_libs/mtimesx/mtimesx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mtimesx/mtimesx.m -------------------------------------------------------------------------------- /external_libs/mtimesx/mtimesx.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mtimesx/mtimesx.mexa64 -------------------------------------------------------------------------------- /external_libs/mtimesx/mtimesx.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/external_libs/mtimesx/mtimesx.mexw64 -------------------------------------------------------------------------------- /external_libs/mtimesx/mtimesx_sparse.m: -------------------------------------------------------------------------------- 1 | % mtimesx_sparse does sparse matrix multiply of two inputs 2 | %****************************************************************************** 3 | % 4 | % MATLAB (R) is a trademark of The Mathworks (R) Corporation 5 | % 6 | % Function: mtimesx_sparse 7 | % Filename: mtimesx_sparse.m 8 | % Programmer: James Tursa 9 | % Version: 1.00 10 | % Date: September 27, 2009 11 | % Copyright: (c) 2009 by James Tursa, All Rights Reserved 12 | % 13 | % This code uses the BSD License: 14 | % 15 | % Redistribution and use in source and binary forms, with or without 16 | % modification, are permitted provided that the following conditions are 17 | % met: 18 | % 19 | % * Redistributions of source code must retain the above copyright 20 | % notice, this list of conditions and the following disclaimer. 21 | % * Redistributions in binary form must reproduce the above copyright 22 | % notice, this list of conditions and the following disclaimer in 23 | % the documentation and/or other materials provided with the distribution 24 | % 25 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | % POSSIBILITY OF SUCH DAMAGE. 36 | % 37 | %-- 38 | % 39 | % mtimesx_sparse is a helper function for mtimesx and is not intended to be called 40 | % directly by the user. 41 | % 42 | % --------------------------------------------------------------------------------------------------------------------------------- 43 | 44 | function result = mtimesx_sparse(a,transa,b,transb) 45 | if( transa == 'N' ) 46 | if( transb == 'N' ) 47 | result = a * b; 48 | elseif( transb == 'G' ) 49 | result = a * conj(b); 50 | elseif( transb == 'T' ) 51 | result = a * b.'; 52 | else 53 | result = a * b'; 54 | end 55 | elseif( transa == 'G' ) 56 | if( transb == 'N' ) 57 | result = conj(a) * b; 58 | elseif( transb == 'G' ) 59 | result = conj(a) * conj(b); 60 | elseif( transb == 'T' ) 61 | result = conj(a) * b.'; 62 | else 63 | result = conj(a) * b'; 64 | end 65 | elseif( transa == 'T' ) 66 | if( transb == 'N' ) 67 | result = a.' * b; 68 | elseif( transb == 'G' ) 69 | result = a.' * conj(b); 70 | elseif( transb == 'T' ) 71 | result = a.' * b.'; 72 | else 73 | result = a.' * b'; 74 | end 75 | else 76 | if( transb == 'N' ) 77 | result = a' * b; 78 | elseif( transb == 'G' ) 79 | result = a' * conj(b); 80 | elseif( transb == 'T' ) 81 | result = a' * b.'; 82 | else 83 | result = a' * b'; 84 | end 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /feature_extraction/average_feature_region.m: -------------------------------------------------------------------------------- 1 | function [ region_image ] = average_feature_region(im, region_size) 2 | % compute cell wise averages, where a cell is a region_size*region_sized 3 | % region in the image. Input can be uint8t, single or double matrices 4 | % of arbitrary dimension 5 | 6 | region_area = region_size.^2; 7 | 8 | if isa(im,'double') || isa(im,'single') || isa(im,'gpuArray') 9 | maxval = 1.0; 10 | elseif isa(im,'unit8') 11 | maxval = 255; 12 | end 13 | 14 | % compute the integral image 15 | iImage = integralVecImage(im); 16 | 17 | % region indices 18 | i1 = (region_size:region_size:size(im,1)) + 1; 19 | i2 = (region_size:region_size:size(im,2)) + 1; 20 | 21 | % sum over region, divided by number of elements, and normalize to [0,1] 22 | % range if integer image 23 | region_image = (iImage(i1,i2,:,:) - iImage(i1,i2-region_size,:,:) - iImage(i1-region_size,i2,:,:) + iImage(i1-region_size,i2-region_size,:,:)) ./ (region_area * maxval); 24 | 25 | end 26 | 27 | -------------------------------------------------------------------------------- /feature_extraction/extract_features.m: -------------------------------------------------------------------------------- 1 | function res_feat = extract_features(image, pos, scales, features, gparams, extract_info) 2 | 3 | % Sample image patches at given position and scales. Then extract features 4 | % from these patches. 5 | % Requires that cell size and image sample size is set for each feature. 6 | 7 | if ~iscell(features) 8 | error('Wrong input'); 9 | end 10 | 11 | if ~isfield(gparams, 'use_gpu') 12 | gparams.use_gpu = false; 13 | end 14 | if ~isfield(gparams, 'data_type') 15 | gparams.data_type = zeros(1, 'single'); 16 | end 17 | if nargin < 6 18 | % Find used image sample size 19 | extract_info = get_feature_extract_info(features); 20 | end 21 | 22 | num_features = length(features); 23 | num_scales = length(scales); 24 | num_sizes = length(extract_info.img_sample_sizes); 25 | 26 | % Extract image patches 27 | img_samples = cell(num_sizes,1); 28 | for sz_ind = 1:num_sizes 29 | img_sample_sz = extract_info.img_sample_sizes{sz_ind}; 30 | img_input_sz = extract_info.img_input_sizes{sz_ind}; 31 | img_samples{sz_ind} = zeros(img_input_sz(1), img_input_sz(2), size(image,3), num_scales, 'uint8'); 32 | for scale_ind = 1:num_scales 33 | img_samples{sz_ind}(:,:,:,scale_ind) = get_pixels(image, pos, round(img_sample_sz*scales(scale_ind)),img_input_sz); 34 | end 35 | end 36 | 37 | % Find the number of feature blocks and total dimensionality 38 | num_feature_blocks = 0; 39 | total_dim = 0; 40 | for feat_ind = 1:num_features 41 | num_feature_blocks = num_feature_blocks + length(features{feat_ind}.fparams.nDim); 42 | total_dim = total_dim + sum(features{feat_ind}.fparams.nDim); 43 | end 44 | 45 | feature_map = cell(1, 1, num_feature_blocks); 46 | 47 | % Extract feature maps for each feature in the list 48 | ind = 1; 49 | CNN_ind = -1; 50 | for feat_ind = 1:num_features 51 | feat = features{feat_ind}; 52 | 53 | % get the image patch index 54 | img_sample_ind = cellfun(@(sz) isequal(feat.img_sample_sz, sz), extract_info.img_sample_sizes); 55 | 56 | % do feature computation 57 | if feat.is_cell 58 | num_blocks = length(feat.fparams.nDim); 59 | feature_map(ind:ind+num_blocks-1) = feat.getFeature(img_samples{img_sample_ind}, feat.fparams, gparams); 60 | CNN_ind = ind; 61 | else 62 | num_blocks = 1; 63 | feature_map{ind} = feat.getFeature(img_samples{img_sample_ind}, feat.fparams, gparams); 64 | end 65 | 66 | ind = ind + num_blocks; 67 | end 68 | 69 | % Do CNN feature normalization per channel 70 | if(CNN_ind ~= -1) 71 | CNN_feat = {feature_map{CNN_ind}}; 72 | delta = 1e-7; 73 | 74 | for i = 1:numel(CNN_feat) 75 | min_ele = repmat(min(min(CNN_feat{i},[],2),[],1), [size(CNN_feat{i},1),size(CNN_feat{i},2),1,1]); 76 | max_ele = repmat(max(max(CNN_feat{i},[],2),[],1), [size(CNN_feat{i},1),size(CNN_feat{i},2),1,1]) + delta; 77 | CNN_feat{i} = ( CNN_feat{i} - min_ele ) ./ (max_ele - min_ele); 78 | end 79 | end 80 | 81 | % Combine the features. In particular, the hand-crafted features are concatnated together 82 | % along the channels. 83 | if(CNN_ind ~= -1) 84 | res_feat = cell(2, 1); 85 | res_feat{2} = CNN_feat{1}; 86 | end 87 | 88 | % concatnate the grayscale and HOG features only when the input is the grayscale 89 | % image. 90 | if(CNN_ind ~=-1) 91 | if(num_features == 3) 92 | res_feat{1} = cat(3,feature_map{1}, feature_map{2}); 93 | else 94 | res_feat{1} = cat(3,feature_map{1}, feature_map{2}, feature_map{3}); 95 | end 96 | else 97 | if(num_features == 3) 98 | res_feat{1} = cat(3,feature_map{1}, feature_map{2}, feature_map{3}); 99 | else 100 | res_feat{1} = cat(3,feature_map{1}, feature_map{2}); 101 | end 102 | end 103 | 104 | end -------------------------------------------------------------------------------- /feature_extraction/fhog.m: -------------------------------------------------------------------------------- 1 | function H = fhog( I, binSize, nOrients, clip, crop ) 2 | % Efficiently compute Felzenszwalb's HOG (FHOG) features. 3 | % 4 | % A fast implementation of the HOG variant used by Felzenszwalb et al. 5 | % in their work on discriminatively trained deformable part models. 6 | % http://www.cs.berkeley.edu/~rbg/latent/index.html 7 | % Gives nearly identical results to features.cc in code release version 5 8 | % but runs 4x faster (over 125 fps on VGA color images). 9 | % 10 | % The computed HOG features are 3*nOrients+5 dimensional. There are 11 | % 2*nOrients contrast sensitive orientation channels, nOrients contrast 12 | % insensitive orientation channels, 4 texture channels and 1 all zeros 13 | % channel (used as a 'truncation' feature). Using the standard value of 14 | % nOrients=9 gives a 32 dimensional feature vector at each cell. This 15 | % variant of HOG, refered to as FHOG, has been shown to achieve superior 16 | % performance to the original HOG features. For details please refer to 17 | % work by Felzenszwalb et al. (see link above). 18 | % 19 | % This function is essentially a wrapper for calls to gradientMag() 20 | % and gradientHist(). Specifically, it is equivalent to the following: 21 | % [M,O] = gradientMag( I,0,0,0,1 ); softBin = -1; useHog = 2; 22 | % H = gradientHist(M,O,binSize,nOrients,softBin,useHog,clip); 23 | % See gradientHist() for more general usage. 24 | % 25 | % This code requires SSE2 to compile and run (most modern Intel and AMD 26 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 27 | % 28 | % USAGE 29 | % H = fhog( I, [binSize], [nOrients], [clip], [crop] ) 30 | % 31 | % INPUTS 32 | % I - [hxw] color or grayscale input image (must have type single) 33 | % binSize - [8] spatial bin size 34 | % nOrients - [9] number of orientation bins 35 | % clip - [.2] value at which to clip histogram bins 36 | % crop - [0] if true crop boundaries 37 | % 38 | % OUTPUTS 39 | % H - [h/binSize w/binSize nOrients*3+5] computed hog features 40 | % 41 | % EXAMPLE 42 | % I=imResample(single(imread('peppers.png'))/255,[480 640]); 43 | % tic, for i=1:100, H=fhog(I,8,9); end; disp(100/toc) % >125 fps 44 | % figure(1); im(I); V=hogDraw(H,25,1); figure(2); im(V) 45 | % 46 | % EXAMPLE 47 | % % comparison to features.cc (requires DPM code release version 5) 48 | % I=imResample(single(imread('peppers.png'))/255,[480 640]); Id=double(I); 49 | % tic, for i=1:100, H1=features(Id,8); end; disp(100/toc) 50 | % tic, for i=1:100, H2=fhog(I,8,9,.2,1); end; disp(100/toc) 51 | % figure(1); montage2(H1); figure(2); montage2(H2); 52 | % D=abs(H1-H2); mean(D(:)) 53 | % 54 | % See also hog, hogDraw, gradientHist 55 | % 56 | % Piotr's Image&Video Toolbox Version 3.23 57 | % Copyright 2013 Piotr Dollar. [pdollar-at-caltech.edu] 58 | % Please email me if you find bugs, or have suggestions or questions! 59 | % Licensed under the Simplified BSD License [see external/bsd.txt] 60 | 61 | %Note: modified to be more self-contained 62 | 63 | if( nargin<2 ), binSize=8; end 64 | if( nargin<3 ), nOrients=9; end 65 | if( nargin<4 ), clip=.2; end 66 | if( nargin<5 ), crop=0; end 67 | 68 | softBin = -1; useHog = 2; b = binSize; 69 | 70 | [M,O]=gradientMex('gradientMag',I,0,1); 71 | 72 | H = gradientMex('gradientHist',M,O,binSize,nOrients,softBin,useHog,clip); 73 | 74 | if( crop ), e=mod(size(I),b) 1 37 | colorspace = average_feature_region(t_colorspace,gparam.cell_size); 38 | else 39 | colorspace = t_colorspace; 40 | end; 41 | end 42 | 43 | -------------------------------------------------------------------------------- /feature_extraction/get_colorspace_backup.m: -------------------------------------------------------------------------------- 1 | function [ feature_map ] = get_colorspace( im, fparam, gparam ) 2 | 3 | % Get a color space feature. Currently implements 'gray' and 'rgb'. 4 | 5 | if isfield(fparam, 'cell_size') 6 | cell_size = fparam.cell_size; 7 | else 8 | cell_size = gparam.cell_size; 9 | end 10 | 11 | [im_height, im_width, num_im_chan, num_images] = size(im); 12 | 13 | single_im = single(im)/255; 14 | 15 | if strcmpi(fparam.colorspace,'gray') 16 | if num_im_chan == 3 17 | if num_images == 1 18 | feature_map = rgb2gray(single_im) - 0.5; 19 | else 20 | feature_map = zeros(im_height, im_width, 1, num_images, 'single'); 21 | for k = 1:num_images 22 | feature_map(:,:,:,k) = rgb2gray(single_im(:,:,:,k)) - 0.5; 23 | end 24 | end 25 | elseif num_im_chan == 1 26 | feature_map = single_im - 0.5; 27 | else 28 | except = MException('get_colorspace','Invalid input data, must have 1 or 3 dimensions'); 29 | throw(except); 30 | end 31 | elseif strcmpi(fparam.colorspace,'rgb') 32 | if num_im_chan == 3 33 | feature_map = single_im - 0.5; 34 | else 35 | except = MException('get_colorspace','Invalid input data, must have 3 dimensions for rgb'); 36 | throw(except); 37 | end 38 | end 39 | 40 | if gparam.use_gpu 41 | feature_map = gpuArray(feature_map); 42 | end 43 | 44 | if cell_size > 1 45 | feature_map = average_feature_region(feature_map, cell_size); 46 | end 47 | end 48 | 49 | -------------------------------------------------------------------------------- /feature_extraction/get_feature_extract_info.m: -------------------------------------------------------------------------------- 1 | function extract_info = get_feature_extract_info(features) 2 | 3 | % Find used image sample size 4 | extract_info.img_sample_sizes = {}; 5 | extract_info.img_input_sizes = {}; 6 | for feat_ind = 1:length(features) 7 | % if not equals any previously stored size 8 | if ~any(cellfun(@(sz) isequal(features{feat_ind}.img_sample_sz, sz), extract_info.img_sample_sizes)) 9 | extract_info.img_sample_sizes{end+1} = features{feat_ind}.img_sample_sz; 10 | extract_info.img_input_sizes{end+1} = features{feat_ind}.img_input_sz; 11 | end 12 | end -------------------------------------------------------------------------------- /feature_extraction/get_fhog.m: -------------------------------------------------------------------------------- 1 | function [ feature_image ] = get_fhog( im, fparam, gparam ) 2 | 3 | % Extract FHOG features using pdollar toolbox. 4 | 5 | if ~isfield(fparam, 'nOrients') 6 | fparam.nOrients = 9; 7 | end 8 | if isfield(fparam, 'cell_size') 9 | cell_size = fparam.cell_size; 10 | else 11 | cell_size = gparam.cell_size; 12 | end 13 | 14 | [im_height, im_width, num_im_chan, num_images] = size(im); 15 | feature_image = zeros(floor(im_height/cell_size), floor(im_width/cell_size), fparam.nDim, num_images, 'like', gparam.data_type); 16 | 17 | for k = 1:num_images 18 | hog_image = fhog(single(im(:,:,:,k)), cell_size, fparam.nOrients); 19 | 20 | %the last dimension is all 0 so we can discard it 21 | feature_image(:,:,:,k) = hog_image(:,:,1:end-1); 22 | end 23 | end -------------------------------------------------------------------------------- /feature_extraction/get_pixels.m: -------------------------------------------------------------------------------- 1 | function [ resized_patch ] = get_pixels( im, pos, sz, resize_target ) 2 | 3 | if isscalar(sz), %square sub-window 4 | sz = [sz, sz]; 5 | end; 6 | 7 | %make sure the size is not to small 8 | if sz(1) < 1 9 | sz(1) = 2; 10 | end; 11 | if sz(2) < 1 12 | sz(2) = 2; 13 | end; 14 | 15 | 16 | xs = floor(pos(2)) + (1:sz(2)) - floor(sz(2)/2); 17 | ys = floor(pos(1)) + (1:sz(1)) - floor(sz(1)/2); 18 | 19 | %check for out-of-bounds coordinates, and set them to the values at 20 | %the borders 21 | xs(xs < 1) = 1; 22 | ys(ys < 1) = 1; 23 | xs(xs > size(im,2)) = size(im,2); 24 | ys(ys > size(im,1)) = size(im,1); 25 | 26 | %extract image 27 | im_patch = im(ys, xs, :); 28 | 29 | if isempty(resize_target) 30 | resized_patch = im_patch; 31 | else 32 | resized_patch = mexResize(im_patch,resize_target,'auto'); 33 | end 34 | 35 | end 36 | 37 | -------------------------------------------------------------------------------- /feature_extraction/get_table_feature.m: -------------------------------------------------------------------------------- 1 | function [ feature_map ] = get_table_feature( im, fparam, gparam) 2 | %get per-pixel features using a lookup table, if the gparam feature cell 3 | %size is set to something large than one, the resulting data will be 4 | %averaged in cells of the specified size. 5 | % 6 | %tables are loaded dynamically when needed from the lookup_tables folder, 7 | %and stored in a persistent variable 8 | 9 | persistent tables; 10 | 11 | if isempty(tables) 12 | tables = {}; 13 | end 14 | 15 | if isfield(fparam, 'cell_size') 16 | cell_size = fparam.cell_size; 17 | else 18 | cell_size = gparam.cell_size; 19 | end 20 | 21 | tab_ind = 0; 22 | for k = 1:length(tables) 23 | if isfield(tables{k}, fparam.tablename) 24 | tab_ind = k; 25 | break; 26 | end 27 | end 28 | 29 | if tab_ind == 0 30 | tables{end+1} = load(['lookup_tables/' fparam.tablename]); 31 | tab_ind = length(tables); 32 | end 33 | 34 | if strcmp(tables{tab_ind}.inputType,'color') 35 | if size(im,3) ~= 3 36 | except = MException('cannot get colorfeature from non color image'); 37 | raise(except); 38 | end 39 | elseif strcmp(tables{tab_ind}.inputType,'gray') 40 | if size(im,3) == 3 41 | im_gray = zeros(size(im,1),size(im,2),1,size(im,4),'uint8'); 42 | for k = 1:size(im,4) 43 | im_gray(:,:,:,k) = rgb2gray(im(:,:,:,k)); 44 | end 45 | im = im_gray; 46 | end 47 | end 48 | 49 | % Extract features from table 50 | if gparam.use_gpu 51 | feature_map = gpuArray(table_lookup(im,tables{tab_ind}.(fparam.tablename))); 52 | else 53 | feature_map = table_lookup(im,tables{tab_ind}.(fparam.tablename)); 54 | end 55 | 56 | if cell_size > 1 57 | feature_map = average_feature_region(feature_map, cell_size); 58 | end 59 | 60 | end 61 | 62 | -------------------------------------------------------------------------------- /feature_extraction/integralVecImage.m: -------------------------------------------------------------------------------- 1 | function intImage = integralVecImage(I) 2 | 3 | % Compute the integral image of I. 4 | 5 | if ~isempty(I) 6 | intImage = zeros(size(I,1)+1, size(I,2)+1, size(I,3), size(I,4), 'like', I); 7 | intImage(2:end, 2:end, :, :) = cumsum(cumsum(I,1),2); 8 | else 9 | intImage = []; 10 | end 11 | 12 | -------------------------------------------------------------------------------- /feature_extraction/load_cnn.m: -------------------------------------------------------------------------------- 1 | function net = load_cnn(fparams, im_size) 2 | 3 | net = load(['./feature_extraction/networks/' fparams.nn_name]); 4 | net = vl_simplenn_tidy(net); 5 | net.layers = net.layers(1:max(fparams.output_layer)); 6 | 7 | if strcmpi(fparams.input_size_mode, 'cnn_default') 8 | base_input_sz = net.meta.normalization.imageSize(1:2); 9 | elseif strcmpi(fparams.input_size_mode, 'adaptive') 10 | base_input_sz = im_size(1:2); 11 | else 12 | error('Unknown input_size_mode'); 13 | end 14 | 15 | net.meta.normalization.imageSize(1:2) = round(base_input_sz .* fparams.input_size_scale); 16 | net.meta.normalization.averageImageOrig = net.meta.normalization.averageImage; 17 | 18 | if isfield(net.meta,'inputSize') 19 | net.meta.inputSize = base_input_sz; 20 | end 21 | 22 | if size(net.meta.normalization.averageImage,1) > 1 || size(net.meta.normalization.averageImage,2) > 1 23 | net.meta.normalization.averageImage = imresize(single(net.meta.normalization.averageImage), net.meta.normalization.imageSize(1:2)); 24 | end 25 | 26 | net.info = vl_simplenn_display(net); 27 | end -------------------------------------------------------------------------------- /feature_extraction/lookup_tables/CNnorm.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/feature_extraction/lookup_tables/CNnorm.mat -------------------------------------------------------------------------------- /feature_extraction/lookup_tables/intensityChannelNorm11.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/feature_extraction/lookup_tables/intensityChannelNorm11.mat -------------------------------------------------------------------------------- /feature_extraction/lookup_tables/intensityChannelNorm16.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/feature_extraction/lookup_tables/intensityChannelNorm16.mat -------------------------------------------------------------------------------- /feature_extraction/lookup_tables/intensityChannelNorm6.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/feature_extraction/lookup_tables/intensityChannelNorm6.mat -------------------------------------------------------------------------------- /feature_extraction/sample_patch.m: -------------------------------------------------------------------------------- 1 | function resized_patch = sample_patch(im, pos, sample_sz, output_sz, gparams) 2 | 3 | if nargin < 4 4 | output_sz = []; 5 | end 6 | if nargin < 5 || ~isfield(gparams, 'use_mexResize') 7 | gparams.use_mexResize = false; 8 | end 9 | 10 | % Pos should be integer when input, but floor in just in case. 11 | pos = floor(pos); 12 | 13 | % Downsample factor 14 | resize_factor = min(sample_sz ./ output_sz); 15 | df = max(floor(resize_factor - 0.1), 1); 16 | if df > 1 17 | % pos = 1 + of + df * (npos - 1) 18 | 19 | % compute offset and new center position 20 | os = mod(pos - 1, df); 21 | pos = (pos - 1 - os) / df + 1; 22 | 23 | % new sample size 24 | sample_sz = sample_sz / df; 25 | 26 | % donwsample image 27 | im = im(1+os(1):df:end, 1+os(2):df:end, :); 28 | end 29 | 30 | % make sure the size is not too small and round it 31 | sample_sz = max(round(sample_sz), 2); 32 | 33 | xs = pos(2) + (1:sample_sz(2)) - floor((sample_sz(2)+1)/2); 34 | ys = pos(1) + (1:sample_sz(1)) - floor((sample_sz(1)+1)/2); 35 | 36 | %check for out-of-bounds coordinates, and set them to the values at 37 | %the borders 38 | xs(xs < 1) = 1; 39 | ys(ys < 1) = 1; 40 | xs(xs > size(im,2)) = size(im,2); 41 | ys(ys > size(im,1)) = size(im,1); 42 | 43 | %extract image 44 | im_patch = im(ys, xs, :); 45 | 46 | if isempty(output_sz) || isequal(sample_sz(:), output_sz(:)) 47 | resized_patch = im_patch; 48 | else 49 | if gparams.use_mexResize 50 | resized_patch = mexResize(im_patch, output_sz, 'linear'); 51 | else 52 | resized_patch = imresize(im_patch, output_sz, 'bilinear', 'Antialiasing',false); 53 | end 54 | end 55 | 56 | end 57 | 58 | -------------------------------------------------------------------------------- /feature_extraction/set_cnn_input_size.m: -------------------------------------------------------------------------------- 1 | function net = set_cnn_input_size(net, im_size) 2 | 3 | net.meta.normalization.imageSize(1:2) = round(im_size(1:2)); 4 | net.meta.normalization.averageImage = imresize(single(net.meta.normalization.averageImageOrig), net.meta.normalization.imageSize(1:2)); 5 | 6 | net.info = vl_simplenn_display(net); 7 | end -------------------------------------------------------------------------------- /feature_extraction/table_lookup.m: -------------------------------------------------------------------------------- 1 | function out=table_lookup(im,table) 2 | 3 | if isa(im,'uint8') 4 | im = int32(im); 5 | end; 6 | 7 | [im_height, im_width, num_im_chan, num_images] = size(im); 8 | 9 | den = int32(8); 10 | fac = int32(32); 11 | offset = int32(1); 12 | 13 | if num_im_chan == 3 14 | RR=im(:,:,1,:);GG=im(:,:,2,:);BB=im(:,:,3,:); 15 | index_im = offset + idivide(RR,den) + fac*idivide(GG,den) + fac*fac*idivide(BB,den); 16 | out = permute(reshape(table(index_im(:),:), im_height, im_width, num_images, size(table,2)), [1 2 4 3]); 17 | else 18 | out = permute(reshape(table(im(:)+1,:), im_height, im_width, num_images, size(table,2)), [1 2 4 3]); 19 | end; 20 | -------------------------------------------------------------------------------- /implementation/argmin_g.m: -------------------------------------------------------------------------------- 1 | function T = argmin_g(w0, zeta, X, T) 2 | lhd= 1 ./ (w0 .^2 + zeta); % left hand 3 | 4 | % compute T for each channel 5 | for i = 1:size(X,3) 6 | T(:,:,i) = lhd .* X(:,:,i); 7 | end 8 | end 9 | 10 | 11 | -------------------------------------------------------------------------------- /implementation/init_default_params.m: -------------------------------------------------------------------------------- 1 | function params = init_default_params(params) 2 | 3 | % Initialize default parameters 4 | default_params.use_gpu = false; 5 | default_params.gpu_id = []; 6 | default_params.clamp_position = false; 7 | 8 | def_param_names = fieldnames(default_params); 9 | for k = 1:numel(def_param_names) 10 | param_name = def_param_names{k}; 11 | if ~isfield(params, param_name) 12 | params.(param_name) = default_params.(param_name); 13 | end 14 | end 15 | 16 | params.visualization = params.visualization; -------------------------------------------------------------------------------- /implementation/init_feature_params.m: -------------------------------------------------------------------------------- 1 | function feature_params = init_feature_params(features, feature_info) 2 | 3 | % Initialize some feature parameters. 4 | num_features = length(features); 5 | feature_params.compressed_dim_block = cell(num_features, 1); 6 | 7 | for k = 1:num_features 8 | if ~isfield(features{k}.fparams, 'compressed_dim') 9 | features{k}.fparams.compressed_dim = features{k}.fparams.nDim; 10 | end 11 | 12 | feature_params.compressed_dim_block{k} = features{k}.fparams.compressed_dim(:); 13 | end 14 | 15 | feature_params.compressed_dim = cell2mat(feature_params.compressed_dim_block); -------------------------------------------------------------------------------- /implementation/interpolate_dft.m: -------------------------------------------------------------------------------- 1 | function xf = interpolate_dft(xf, interp1_fs, interp2_fs) 2 | 3 | % Performs the implicit interpolation in the Fourier domain of a sample by 4 | % multiplying with the Fourier coefficients of the interpolation function. 5 | 6 | xf = cellfun(@(xf, interp1_fs, interp2_fs) bsxfun(@times, bsxfun(@times, xf, interp1_fs), interp2_fs), ... 7 | xf, interp1_fs, interp2_fs, 'uniformoutput', false); 8 | -------------------------------------------------------------------------------- /implementation/resizeDFT2.m: -------------------------------------------------------------------------------- 1 | function resizeddft = resizeDFT2(inputdft, desiredSize) 2 | 3 | [imh, imw, n1, n2] = size(inputdft); 4 | imsz = [imh, imw]; 5 | 6 | if any(desiredSize ~= imsz) 7 | minsz = min(imsz, desiredSize); 8 | 9 | scaling = prod(desiredSize)/prod(imsz); 10 | 11 | resizeddft = complex(zeros([desiredSize n1 n2], 'single')); 12 | 13 | mids = ceil(minsz/2); 14 | mide = floor((minsz-1)/2) - 1; 15 | 16 | resizeddft(1:mids(1), 1:mids(2), :, :) = scaling * inputdft(1:mids(1), 1:mids(2), :, :); 17 | resizeddft(1:mids(1), end - mide(2):end, :, :) = scaling * inputdft(1:mids(1), end - mide(2):end, :, :); 18 | resizeddft(end - mide(1):end, 1:mids(2), :, :) = scaling * inputdft(end - mide(1):end, 1:mids(2), :, :); 19 | resizeddft(end - mide(1):end, end - mide(2):end, :, :) = scaling * inputdft(end - mide(1):end, end - mide(2):end, :, :); 20 | else 21 | resizeddft = inputdft; 22 | end 23 | end -------------------------------------------------------------------------------- /implementation/resp_newton.m: -------------------------------------------------------------------------------- 1 | function [disp_row, disp_col, sind] = resp_newton(response, responsef, iterations, ky, kx, use_sz) 2 | 3 | [max_resp_row, max_row] = max(response, [], 1); 4 | [init_max_response, max_col] = max(max_resp_row, [], 2); 5 | max_row_perm = permute(max_row, [2 3 1]); 6 | col = max_col(:)'; 7 | row = max_row_perm(sub2ind(size(max_row_perm), col, 1:size(response,3))); 8 | 9 | trans_row = mod(row - 1 + floor((use_sz(1)-1)/2), use_sz(1)) - floor((use_sz(1)-1)/2); 10 | trans_col = mod(col - 1 + floor((use_sz(2)-1)/2), use_sz(2)) - floor((use_sz(2)-1)/2); 11 | init_pos_y = permute(2*pi * trans_row / use_sz(1), [1 3 2]); 12 | init_pos_x = permute(2*pi * trans_col / use_sz(2), [1 3 2]); 13 | max_pos_y = init_pos_y; 14 | max_pos_x = init_pos_x; 15 | 16 | % pre-compute complex exponential 17 | exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); 18 | exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); 19 | 20 | % gradient_step_size = gradient_step_size / prod(use_sz); 21 | 22 | ky2 = ky.*ky; 23 | kx2 = kx.*kx; 24 | 25 | iter = 1; 26 | while iter <= iterations 27 | % Compute gradient 28 | ky_exp_ky = bsxfun(@times, ky, exp_iky); 29 | kx_exp_kx = bsxfun(@times, kx, exp_ikx); 30 | y_resp = mtimesx(exp_iky, responsef, 'speed'); 31 | resp_x = mtimesx(responsef, exp_ikx, 'speed'); 32 | grad_y = -imag(mtimesx(ky_exp_ky, resp_x, 'speed')); 33 | grad_x = -imag(mtimesx(y_resp, kx_exp_kx, 'speed')); 34 | ival = 1i * mtimesx(exp_iky, resp_x, 'speed'); 35 | H_yy = real(-mtimesx(bsxfun(@times, ky2, exp_iky), resp_x, 'speed') + ival); 36 | H_xx = real(-mtimesx(y_resp, bsxfun(@times, kx2, exp_ikx), 'speed') + ival); 37 | H_xy = real(-mtimesx(ky_exp_ky, mtimesx(responsef, kx_exp_kx, 'speed'), 'speed')); 38 | det_H = H_yy .* H_xx - H_xy .* H_xy; 39 | 40 | % Compute new position using newtons method 41 | max_pos_y = max_pos_y - (H_xx .* grad_y - H_xy .* grad_x) ./ det_H; 42 | max_pos_x = max_pos_x - (H_yy .* grad_x - H_xy .* grad_y) ./ det_H; 43 | 44 | % Evaluate maximum 45 | exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); 46 | exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); 47 | 48 | iter = iter + 1; 49 | end 50 | max_response = 1 / prod(use_sz) * real(mtimesx(mtimesx(exp_iky, responsef, 'speed'), exp_ikx, 'speed')); 51 | 52 | % check for scales that have not increased in score 53 | ind = max_response < init_max_response; 54 | max_response(ind) = init_max_response(ind); 55 | max_pos_y(ind) = init_pos_y(ind); 56 | max_pos_x(ind) = init_pos_x(ind); 57 | 58 | [max_scale_response, sind] = max(max_response(:)); 59 | disp_row = (mod(max_pos_y(1,1,sind) + pi, 2*pi) - pi) / (2*pi) * use_sz(1); 60 | disp_col = (mod(max_pos_x(1,1,sind) + pi, 2*pi) - pi) / (2*pi) * use_sz(2); 61 | end -------------------------------------------------------------------------------- /implementation/scale_filter/get_scale_sample.m: -------------------------------------------------------------------------------- 1 | function out = get_scale_sample(im, pos, base_target_sz, scaleFactors, scale_window, scale_model_sz) 2 | 3 | % out = get_scale_sample(im, pos, base_target_sz, scaleFactors, scale_window, scale_model_sz) 4 | % 5 | % Extracts a sample for the scale filter at the current 6 | % location and scale. 7 | 8 | nScales = length(scaleFactors); 9 | 10 | for s = 1:nScales 11 | patch_sz = floor(base_target_sz * scaleFactors(s)); 12 | 13 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 14 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 15 | 16 | % check for out-of-bounds coordinates, and set them to the values at 17 | % the borders 18 | xs(xs < 1) = 1; 19 | ys(ys < 1) = 1; 20 | xs(xs > size(im,2)) = size(im,2); 21 | ys(ys > size(im,1)) = size(im,1); 22 | 23 | % extract image 24 | im_patch = im(ys, xs, :); 25 | 26 | % resize image to model size 27 | im_patch_resized = mexResize(im_patch, scale_model_sz, 'auto'); 28 | 29 | % extract scale features 30 | temp_hog = fhog(single(im_patch_resized), 4); 31 | temp = temp_hog(:,:,1:31); 32 | 33 | if s == 1 34 | out = zeros(numel(temp), nScales, 'single'); 35 | end 36 | 37 | % window 38 | out(:,s) = temp(:) * scale_window(s); 39 | end -------------------------------------------------------------------------------- /implementation/shift_sample.m: -------------------------------------------------------------------------------- 1 | function xf = shift_sample(xf, shift, kx, ky) 2 | 3 | % Shift a sample in the Fourier domain. The shift should be normalized to 4 | % the range [-pi, pi]. 5 | 6 | shift_exp_y =exp((1i * shift(1)) * ky); 7 | shift_exp_x = exp((1i * shift(2)) * kx); 8 | xf =bsxfun(@times, bsxfun(@times, xf, shift_exp_y), shift_exp_x); -------------------------------------------------------------------------------- /implementation/shift_sample_scale.m: -------------------------------------------------------------------------------- 1 | function out = shift_sample_scale(im, pos, base_target_sz,xs,recovered_scale,scaleFactors,scale_window,scale_model_sz) 2 | nScales = length(scaleFactors); 3 | out = zeros(size(xs,1), nScales, 'single'); 4 | shift_pos=recovered_scale-ceil(nScales/2); 5 | if shift_pos==0 6 | out=xs; 7 | elseif shift_pos>0 8 | for j=1:nScales-shift_pos 9 | out(:,j)=xs(:,j+shift_pos)/(scale_window(j+shift_pos)+1e-5)*scale_window(j); 10 | end 11 | for i=1:shift_pos 12 | patch_sz = floor(base_target_sz * scaleFactors(nScales-shift_pos+i)); 13 | patch_sz = max(patch_sz, 2); 14 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 15 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 16 | % check for out-of-bounds coordinates, and set them to the values at 17 | % the borders 18 | xs(xs < 1) = 1; 19 | ys(ys < 1) = 1; 20 | xs(xs > size(im,2)) = size(im,2); 21 | ys(ys > size(im,1)) = size(im,1); 22 | 23 | % extract image 24 | im_patch = im(ys, xs, :); 25 | 26 | % resize image to model size 27 | im_patch_resized = mexResize(im_patch, scale_model_sz, 'auto'); 28 | 29 | % extract scale features 30 | temp_hog = fhog(single(im_patch_resized), 4); 31 | 32 | 33 | temp(:,:,1:31) = temp_hog(:,:,1:31); 34 | out(:,nScales-shift_pos+i)=temp(:); 35 | % window 36 | out(:,nScales-shift_pos+i) = temp(:) * scale_window(nScales-shift_pos+i); 37 | end 38 | else 39 | for j=1:nScales+shift_pos 40 | out(:,j-shift_pos)=xs(:,j)/(scale_window(j)+1e-5).*scale_window(j-shift_pos); 41 | end 42 | for i=1:-shift_pos 43 | patch_sz = floor(base_target_sz * scaleFactors(i)); 44 | patch_sz = max(patch_sz, 2); 45 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 46 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 47 | % check for out-of-bounds coordinates, and set them to the values at 48 | % the borders 49 | xs(xs < 1) = 1; 50 | ys(ys < 1) = 1; 51 | xs(xs > size(im,2)) = size(im,2); 52 | ys(ys > size(im,1)) = size(im,1); 53 | 54 | % extract image 55 | im_patch = im(ys, xs, :); 56 | 57 | % resize image to model size 58 | im_patch_resized = mexResize(im_patch, scale_model_sz, 'auto'); 59 | 60 | % extract scale features 61 | temp_hog = fhog(single(im_patch_resized), 4); 62 | 63 | 64 | temp(:,:,1:31) = temp_hog(:,:,1:31); 65 | 66 | % window 67 | out(:,i) = temp(:) * scale_window(i); 68 | out(:,i)=temp(:); 69 | end 70 | end 71 | 72 | -------------------------------------------------------------------------------- /implementation/tracker.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/implementation/tracker.m -------------------------------------------------------------------------------- /results/DTB70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/results/DTB70.png -------------------------------------------------------------------------------- /results/UAV123@10fps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/results/UAV123@10fps.png -------------------------------------------------------------------------------- /results/UAVDT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/results/UAVDT.png -------------------------------------------------------------------------------- /results/VisDrone2018.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/results/VisDrone2018.png -------------------------------------------------------------------------------- /results/VisDrone2020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/results/VisDrone2020.png -------------------------------------------------------------------------------- /results/setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/results/setup.png -------------------------------------------------------------------------------- /run_MRCF.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/run_MRCF.m -------------------------------------------------------------------------------- /seq/wakeboard7/000001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000001.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000002.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000003.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000004.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000005.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000006.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000007.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000008.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000008.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000009.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000009.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000010.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000010.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000011.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000011.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000012.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000012.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000013.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000013.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000014.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000014.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000015.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000015.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000016.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000016.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000017.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000017.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000018.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000019.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000020.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000020.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000021.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000021.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000022.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000022.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000023.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000023.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000024.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000024.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000025.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000025.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000026.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000026.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000027.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000027.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000028.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000028.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000029.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000029.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000030.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000030.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000031.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000031.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000032.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000032.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000033.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000033.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000034.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000034.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000035.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000035.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000036.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000036.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000037.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000037.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000038.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000038.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000039.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000039.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000040.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000040.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000041.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000041.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000042.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000042.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000043.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000043.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000044.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000044.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000045.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000045.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000046.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000046.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000047.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000047.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000048.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000048.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000049.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000049.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000050.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000050.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000051.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000051.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000052.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000052.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000053.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000053.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000054.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000054.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000055.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000055.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000056.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000056.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000057.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000057.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000058.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000058.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000059.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000059.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000060.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000060.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000061.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000061.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000062.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000062.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000063.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000063.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000064.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000064.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000065.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000065.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000066.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000066.jpg -------------------------------------------------------------------------------- /seq/wakeboard7/000067.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/seq/wakeboard7/000067.jpg -------------------------------------------------------------------------------- /seq/wakeboard7_gt.txt: -------------------------------------------------------------------------------- 1 | 623,299,11,38 2 | 624,296,11,38 3 | 624,293,11,38 4 | 624,290,11,38 5 | 622,286,11,41 6 | 621,284,12,41 7 | 622,277,12,44 8 | 625,271,12,44 9 | 627,265,12,44 10 | 632,257,13,46 11 | 640,250,13,46 12 | 648,243,13,48 13 | 654,236,13,48 14 | 660,229,13,48 15 | 664,225,13,48 16 | 667,219,13,48 17 | 669,213,13,48 18 | 672,203,13,50 19 | 675,197,14,51 20 | 684,189,15,53 21 | 693,184,15,55 22 | 701,175,16,50 23 | 706,169,17,48 24 | 709,163,17,54 25 | 709,162,17,55 26 | 709,160,17,57 27 | 709,159,18,63 28 | 714,159,22,66 29 | 720,164,24,64 30 | 726,167,24,64 31 | 729,169,24,64 32 | 733,170,24,65 33 | 733,171,28,65 34 | 734,170,30,64 35 | 736,165,31,65 36 | 738,162,33,64 37 | 743,157,35,65 38 | 745,150,38,62 39 | 747,143,41,64 40 | 763,141,39,64 41 | 774,138,39,63 42 | 786,134,38,63 43 | 800,131,41,61 44 | 814,130,41,64 45 | 826,128,43,64 46 | 842,127,42,65 47 | 857,128,42,65 48 | 873,127,45,65 49 | 884,128,45,64 50 | 893,131,45,64 51 | 897,138,45,64 52 | 894,144,43,62 53 | 888,153,43,61 54 | 886,159,42,61 55 | 888,168,41,59 56 | 895,177,41,59 57 | 905,189,39,58 58 | 924,204,38,57 59 | 940,222,38,57 60 | 959,241,35,53 61 | 965,255,35,56 62 | 961,265,36,54 63 | 955,275,34,54 64 | 947,282,34,54 65 | 939,290,32,54 66 | 935,296,32,52 67 | 940,303,30,52 68 | -------------------------------------------------------------------------------- /utils/calcRectInt.m: -------------------------------------------------------------------------------- 1 | function overlap = calcRectInt(A,B) 2 | % 3 | %each row is a rectangle. 4 | % A(i,:) = [x y w h] 5 | % B(j,:) = [x y w h] 6 | % overlap(i,j) = area of intersection 7 | % normoverlap(i,j) = overlap(i,j) / (area(i)+area(j)-overlap) 8 | % 9 | % Same as built-in rectint, but faster and uses less memory (since avoids repmat). 10 | 11 | 12 | lena = size(A, 1); 13 | lenb = size(B, 1); 14 | lena = min(lena, lenb); 15 | A = A(1:lena, :); 16 | B = B(1:lena, :); 17 | leftA = A(:,1); 18 | bottomA = A(:,2); 19 | rightA = leftA + A(:,3) - 1; 20 | topA = bottomA + A(:,4) - 1; 21 | 22 | leftB = B(:,1); 23 | bottomB = B(:,2); 24 | rightB = leftB + B(:,3) - 1; 25 | topB = bottomB + B(:,4) - 1; 26 | 27 | tmp = (max(0, min(rightA, rightB) - max(leftA, leftB)+1 )) .* (max(0, min(topA, topB) - max(bottomA, bottomB)+1 )); 28 | areaA = A(:,3) .* A(:,4); 29 | areaB = B(:,3) .* B(:,4); 30 | overlap = tmp./(areaA+areaB-tmp); 31 | % if tmp > 0 32 | % 33 | % overlap = tmp; 34 | % 35 | % areaA = A(3) .* A(4); 36 | % areaB = B(3) .* B(4); 37 | % overlap = tmp./(areaA+areaB-tmp); 38 | % else 39 | % overlap = 0; 40 | % end 41 | -------------------------------------------------------------------------------- /utils/choose_video.m: -------------------------------------------------------------------------------- 1 | function video_path = choose_video(base_path) 2 | 3 | % video_path = choose_video(base_path) 4 | 5 | %process path to make sure it's uniform 6 | if ispc(), base_path = strrep(base_path, '\', '/'); end 7 | if base_path(end) ~= '/', base_path(end+1) = '/'; end 8 | 9 | %list all sub-folders 10 | contents = dir(base_path); 11 | names = {}; 12 | for k = 1:numel(contents), 13 | name = contents(k).name; 14 | if isdir([base_path name]) && ~strcmp(name, '.') && ~strcmp(name, '..'), 15 | names{end+1} = name; %#ok 16 | end 17 | end 18 | 19 | %no sub-folders found 20 | if isempty(names), video_path = []; return; end 21 | 22 | %choice GUI 23 | choice = listdlg('ListString',names, 'Name','Choose video', 'SelectionMode','single'); 24 | 25 | if isempty(choice), %user cancelled 26 | video_path = []; 27 | else 28 | % video_path = [base_path names{choice} '/']; 29 | video_path = names{choice}; 30 | end 31 | 32 | end 33 | 34 | -------------------------------------------------------------------------------- /utils/choose_video_UAV.m: -------------------------------------------------------------------------------- 1 | function video_name = choose_video_UAV(base_path) 2 | %CHOOSE_VIDEO 3 | % Allows the user to choose a video (groundtruth.txt in the given path). 4 | % 5 | % Joao F. Henriques, 2014 6 | % http://www.isr.uc.pt/~henriques/ 7 | % 8 | % Modified by Fuling Lin (fuling.lin@outlook.com) 9 | % 10 | %process path to make sure it's uniform 11 | if ispc(), base_path = strrep(base_path, '\', '/'); end 12 | if base_path(end) ~= '/', base_path(end+1) = '/'; end 13 | 14 | %list all sub-folders 15 | dirOutput = dir(fullfile(base_path, '*.txt')); 16 | contents = {dirOutput.name}'; 17 | names = {}; 18 | for k = 1:numel(contents), 19 | name = contents{k}(1:end-4); 20 | names{end+1} = name; 21 | end 22 | 23 | %=================================================================== 24 | % uncomment following scripts if you test on the entire benchmark 25 | % names(strcmpi('Jogging', names)) = []; 26 | % names(end+1:end+2) = {'Jogging.1', 'Jogging.2'}; 27 | % 28 | % names(strcmpi('Skating2', names)) = []; 29 | % names(end+1:end+2) = {'Skating2.1', 'Skating2.2'}; 30 | %=================================================================== 31 | 32 | %no sub-folders found 33 | if isempty(names), video_name = []; return; end 34 | 35 | %choice GUI 36 | choice = listdlg('ListString',names, 'Name','Choose video', 'SelectionMode','single'); 37 | 38 | if isempty(choice), %user cancelled 39 | video_name = []; 40 | else 41 | video_name = names{choice}; 42 | end 43 | 44 | end 45 | 46 | -------------------------------------------------------------------------------- /utils/construct_circular_cone.m: -------------------------------------------------------------------------------- 1 | function reg_window=construct_circular_cone(sz) 2 | x = linspace(-sqrt(2)/2,sqrt(2)/2,sz(1)); 3 | y = linspace(-sqrt(2)/2,sqrt(2)/2,sz(2)); 4 | [xx,yy] = ndgrid(x,y); 5 | reg_window =1 - sqrt((xx.^2 + yy.^2)); 6 | 7 | end -------------------------------------------------------------------------------- /utils/construct_regwindow.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/utils/construct_regwindow.m -------------------------------------------------------------------------------- /utils/get_sequence_frame.m: -------------------------------------------------------------------------------- 1 | function [seq, im] = get_sequence_frame(seq) 2 | 3 | seq.frame = seq.frame + 1; 4 | 5 | if strcmpi(seq.format, 'otb') 6 | if seq.frame > seq.num_frames 7 | im = []; 8 | else 9 | im = imread(seq.image_files{seq.frame}); 10 | end 11 | elseif strcmpi(seq.format, 'vot') 12 | [seq.handle, image_file] = seq.handle.frame(seq.handle); 13 | if isempty(image_file) 14 | im = []; 15 | else 16 | im = imread(image_file); 17 | end 18 | else 19 | error('Uknown sequence format'); 20 | end -------------------------------------------------------------------------------- /utils/get_sequence_info.m: -------------------------------------------------------------------------------- 1 | function [seq, init_image] = get_sequence_info(seq) 2 | 3 | if ~isfield(seq, 'format') || isempty(seq.format) 4 | if isempty(seq) 5 | seq.format = 'vot'; 6 | else 7 | seq.format = 'otb'; 8 | end 9 | end 10 | 11 | seq.frame = 0; 12 | 13 | if strcmpi(seq.format, 'otb') 14 | seq.image_files = seq.s_frames; 15 | seq = rmfield(seq, 's_frames'); 16 | seq.init_sz = [seq.init_rect(1,4), seq.init_rect(1,3)]; 17 | seq.init_pos = [seq.init_rect(1,2), seq.init_rect(1,1)] + (seq.init_sz - 1)/2; 18 | seq.num_frames = numel(seq.image_files); 19 | seq.rect_position = zeros(seq.num_frames, 4); 20 | init_image = imread(seq.image_files{1}); 21 | elseif strcmpi(seq.format, 'vot') 22 | [seq.handle, init_image_file, init_region] = vot('polygon'); 23 | 24 | if isempty(init_image_file) 25 | init_image = []; 26 | return; 27 | end 28 | 29 | init_image = imread(init_image_file); 30 | 31 | bb_scale = 1; 32 | 33 | % If the provided region is a polygon ... 34 | if numel(init_region) > 4 35 | % Init with an axis aligned bounding box with correct area and center 36 | % coordinate 37 | cx = mean(init_region(1:2:end)); 38 | cy = mean(init_region(2:2:end)); 39 | x1 = min(init_region(1:2:end)); 40 | x2 = max(init_region(1:2:end)); 41 | y1 = min(init_region(2:2:end)); 42 | y2 = max(init_region(2:2:end)); 43 | A1 = norm(init_region(1:2) - init_region(3:4)) * norm(init_region(3:4) - init_region(5:6)); 44 | A2 = (x2 - x1) * (y2 - y1); 45 | s = sqrt(A1/A2); 46 | w = s * (x2 - x1) + 1; 47 | h = s * (y2 - y1) + 1; 48 | else 49 | cx = init_region(1) + (init_region(3) - 1)/2; 50 | cy = init_region(2) + (init_region(4) - 1)/2; 51 | w = init_region(3); 52 | h = init_region(4); 53 | end 54 | 55 | init_c = [cy cx]; 56 | init_sz = bb_scale * [h w]; 57 | 58 | im_size = size(init_image); 59 | 60 | seq.init_pos = init_c; 61 | seq.init_sz = min(max(round(init_sz), [1 1]), im_size(1:2)); 62 | seq.num_frames = Inf; 63 | seq.region = init_region; 64 | else 65 | error('Uknown sequence format'); 66 | end -------------------------------------------------------------------------------- /utils/get_sequence_results.m: -------------------------------------------------------------------------------- 1 | function [seq, results] = get_sequence_results(seq) 2 | 3 | if strcmpi(seq.format, 'otb') 4 | results.type = 'rect'; 5 | results.res = seq.rect_position; 6 | elseif strcmpi(seq.format, 'vot') 7 | seq.handle.quit(seq.handle); 8 | else 9 | error('Uknown sequence format'); 10 | end 11 | 12 | if isfield(seq, 'time') 13 | results.fps = seq.num_frames / seq.time; 14 | else 15 | results.fps = NaN; 16 | end -------------------------------------------------------------------------------- /utils/get_subwindow_no_window.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/utils/get_subwindow_no_window.m -------------------------------------------------------------------------------- /utils/gradientMex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/utils/gradientMex.mexa64 -------------------------------------------------------------------------------- /utils/gradientMex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/utils/gradientMex.mexmaci64 -------------------------------------------------------------------------------- /utils/gradientMex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/utils/gradientMex.mexw64 -------------------------------------------------------------------------------- /utils/load_video_info.m: -------------------------------------------------------------------------------- 1 | function [seq, ground_truth] = load_video_info(video_path,video,ground_truth_base_path) 2 | 3 | seqs=configSeqs; 4 | seq.video_path = strcat(video_path, video); 5 | i=1; 6 | while ~strcmpi(seqs{i}.name,video) 7 | i=i+1; 8 | end 9 | 10 | seq.VidName = seqs{i}.name; 11 | seq.st_frame = seqs{i}.startFrame; 12 | seq.en_frame = seqs{i}.endFrame; 13 | 14 | seq.ground_truth_fileName = seqs{i}.name; 15 | ground_truth = dlmread([ground_truth_base_path seq.ground_truth_fileName '.txt']); 16 | 17 | 18 | %ground_truth = dlmread([video_path '/groundtruth_rect.txt']); 19 | 20 | seq.format = 'otb'; 21 | seq.len = size(ground_truth, 1); 22 | seq.init_rect = ground_truth(1,:); 23 | seq.ground_truth = ground_truth; 24 | 25 | img_path = [video_path video '\']; 26 | %img_path = [video_path '/img/']; 27 | 28 | if exist([img_path num2str(1, '%06i.png')], 'file'), 29 | img_files = num2str((1:seq.len)', [img_path '%06i.png']); 30 | elseif exist([img_path num2str(1, '%06i.jpg')], 'file'), 31 | img_files = num2str((1:seq.len)', [img_path '%06i.jpg']); 32 | elseif exist([img_path num2str(1, '%06i.bmp')], 'file'), 33 | img_files = num2str((1:seq.len)', [img_path '%06i.bmp']); 34 | else 35 | error('No image files to load.') 36 | end 37 | 38 | seq.s_frames = cellstr(img_files); 39 | 40 | end 41 | 42 | -------------------------------------------------------------------------------- /utils/load_video_info_UAV123.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/MRCF-Tracker/fc1a02e661adf44efbe0407f3b78c93d52ba0b33/utils/load_video_info_UAV123.m -------------------------------------------------------------------------------- /utils/load_video_information.m: -------------------------------------------------------------------------------- 1 | function seq = load_video_information(type) % OTB100, UAV123_10fps, UAV123, UAV123_20L 2 | 3 | switch type 4 | case 'OTB100' 5 | video_base_path = 'D:\Res\tracking_data\OTB100'; 6 | video_name = choose_video_OTB(video_base_path); 7 | seq = load_video_info_OTB([video_base_path '\' video_name]); 8 | seq.video_name = video_name; 9 | seq.st_frame = 1; 10 | seq.en_frame = seq.len; 11 | case 'UAV123_10fps' 12 | database_folder = 'D:\Res\tracking_data\UAV123_10fps\data_seq\UAV123_10fps'; 13 | ground_truth_folder = 'D:\Res\tracking_data\UAV123_10fps\anno\UAV123_10fps'; 14 | video_name = choose_video_UAV(ground_truth_folder); 15 | seq = load_video_info_UAV123(video_name, database_folder, ground_truth_folder, type); 16 | seq.video_name = video_name; 17 | case 'UAV123' 18 | database_folder = 'D:\Res\tracking_data\UAV123\data_seq\UAV123'; 19 | ground_truth_folder = 'D:\Res\tracking_data\UAV123\anno\UAV123'; 20 | video_name = choose_video_UAV(ground_truth_folder); 21 | seq = load_video_info_UAV123(video_name, database_folder, ground_truth_folder, type); 22 | seq.video_name = video_name; 23 | case 'UAV123_20L' 24 | database_folder = 'D:\Res\tracking_data\UAV123\data_seq\UAV123'; 25 | ground_truth_folder = 'D:\Res\tracking_data\UAV123\anno\UAV20L'; 26 | video_name = choose_video_UAV(ground_truth_folder); 27 | seq = load_video_info_UAV123(video_name, database_folder, ground_truth_folder, type); 28 | seq.video_name = video_name; 29 | end -------------------------------------------------------------------------------- /utils/precision_plot_save.m: -------------------------------------------------------------------------------- 1 | function precisions = precision_plot_save(positions, ground_truth, title, savedir, show) 2 | 3 | %PRECISION_PLOT 4 | % Calculates precision for a series of distance thresholds (percentage of 5 | % frames where the distance to the ground truth is within the threshold). 6 | % The results are shown in a new figure if SHOW is true. 7 | % 8 | % Accepts positions and ground truth as Nx2 matrices (for N frames), and 9 | % a title string. 10 | % 11 | % Joao F. Henriques, 2014 12 | % http://www.isr.uc.pt/~henriques/ 13 | 14 | 15 | max_threshold = 50; %used for graphs in the paper 16 | 17 | 18 | precisions = zeros(max_threshold, 1); 19 | 20 | if size(positions,1) ~= size(ground_truth,1), 21 | % fprintf('%12s - Number of ground truth frames does not match number of tracked frames.\n', title) 22 | 23 | %just ignore any extra frames, in either results or ground truth 24 | n = min(size(positions,1), size(ground_truth,1)); 25 | positions(n+1:end,:) = []; 26 | ground_truth(n+1:end,:) = []; 27 | end 28 | 29 | center = [positions(:,1)+(positions(:,3)-1)/2 positions(:,2)+(positions(:,4)-1)/2]; 30 | centerGT = [ground_truth(:,1)+(ground_truth(:,3)-1)/2 ground_truth(:,2)+(ground_truth(:,4)-1)/2]; 31 | 32 | % calculate distances to ground truth over all frames 33 | % distances = sqrt((positions(:,1) - ground_truth(:,1)).^2 + ... 34 | % (positions(:,2) - ground_truth(:,2)).^2); 35 | 36 | distances = sqrt((center(:,1) - centerGT(:,1)).^2 + ... 37 | (center(:,2) - centerGT(:,2)).^2); 38 | distances(isnan(distances)) = []; 39 | % compute precisions 40 | for p = 1:max_threshold 41 | precisions(p) = nnz(distances <= p) / numel(distances); 42 | end 43 | 44 | % plot the precisions 45 | if show == 1 46 | han = figure('Name',['Precisions - ' title]); 47 | set(han,'DefaultFigureVisible','on'); 48 | plot(precisions, 'k-', 'LineWidth',2); 49 | xlabel('Threshold'), ylabel('Precision'); 50 | saveas(han,[savedir, title,'.png']); 51 | else 52 | han = figure('Name',['Precisions - ' title]); 53 | set(han,'DefaultFigureVisible','off'); 54 | plot(precisions, 'k-', 'LineWidth',2); 55 | xlabel('Threshold'), ylabel('Precision'); 56 | saveas(han,[savedir, title,'.png']); 57 | end 58 | 59 | end 60 | 61 | -------------------------------------------------------------------------------- /utils/report_tracking_result.m: -------------------------------------------------------------------------------- 1 | function seq = report_tracking_result(seq, result) 2 | 3 | if strcmpi(seq.format, 'otb') 4 | seq.rect_position(seq.frame,:) = round([result.center_pos([2,1]) - (result.target_size([2,1]) - 1)/2, result.target_size([2,1])]); 5 | elseif strcmpi(seq.format, 'vot') 6 | if seq.frame > 1 7 | bb_scale = 1; 8 | sz = result.target_size / bb_scale; 9 | tl = result.center_pos - (sz - 1)/2; 10 | br = result.center_pos + (sz - 1)/2; 11 | x1 = tl(2); y1 = tl(1); 12 | x2 = br(2); y2 = br(1); 13 | result_box = round(double([x1 y1 x2 y1 x2 y2 x1 y2])); 14 | if any(isnan(result_box) | isinf(result_box)) 15 | error('Illegal values in the result.') 16 | end 17 | % if any(result_box < 0) 18 | % error('Negative values') 19 | % end 20 | seq.handle = seq.handle.report(seq.handle, result_box); 21 | end 22 | else 23 | error('Uknown sequence format'); 24 | end -------------------------------------------------------------------------------- /utils/splitSeqTRE.m: -------------------------------------------------------------------------------- 1 | function [subSeqs, subAnno]=splitSeqTRE(seq,segNum,rect_anno) 2 | %20 segments for each sequences 3 | %first, excluding all the occ/out-of-view frames 4 | %then, sampling 5 | 6 | minNum = 20; 7 | 8 | fileName = ['initOmit/' seq.name '.txt']; 9 | IdxExclude = []; 10 | if exist(fileName) 11 | IdxExclude=load(fileName)-seq.startFrame+1; 12 | end 13 | Idx = 1:seq.len; 14 | for j = 1:size(IdxExclude,1) 15 | Idx(IdxExclude(j,1):IdxExclude(j,2))=0; 16 | end 17 | Idx = Idx(find(Idx>0)); 18 | 19 | for i=1:length(Idx) 20 | r = rect_anno(Idx(i),:); 21 | 22 | if r(1)<=0 | r(2)<=0 | r(3)<=0 | r(4)<=0 | isnan(sum(r)) 23 | Idx(i) = 0; 24 | end 25 | end 26 | 27 | Idx = Idx(find(Idx>0)); 28 | 29 | for i = length(Idx):-1:1 30 | if seq.len - Idx(i) + 1 >= minNum 31 | endSeg = Idx(i); 32 | endSegIdx = i; 33 | break; 34 | end 35 | end 36 | 37 | startFrIdxOne = [floor(1:endSegIdx/(segNum-1):endSegIdx) endSegIdx] ; 38 | 39 | % endSeg = seq.len-minNum+1; 40 | 41 | subAnno=[]; 42 | subSeqs=[]; 43 | 44 | for i = 1:length(startFrIdxOne) 45 | index = Idx(startFrIdxOne(i)); 46 | subS.path = seq.path; 47 | subS.nz = seq.nz; 48 | subS.ext = seq.ext; 49 | 50 | subS.startFrame = index+seq.startFrame-1; 51 | subS.endFrame = seq.endFrame; 52 | 53 | subS.len = subS.endFrame - subS.startFrame + 1; 54 | 55 | subS.annoBegin = seq.startFrame; 56 | subS.init_rect = rect_anno(index,:); 57 | anno = rect_anno(index:end,:); 58 | 59 | subS.s_frames = seq.s_frames(index:end); 60 | 61 | subS.name = seq.name; 62 | % subS.nameIdx = [seq.name '_' num2str(i)]; 63 | 64 | subAnno{i} = anno; 65 | subSeqs{i}=subS; 66 | end 67 | 68 | -------------------------------------------------------------------------------- /utils/wrappers.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Piotr's Computer Vision Matlab Toolbox Version 3.00 3 | * Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 4 | * Licensed under the Simplified BSD License [see external/bsd.txt] 5 | *******************************************************************************/ 6 | #ifndef _WRAPPERS_HPP_ 7 | #define _WRAPPERS_HPP_ 8 | #ifdef MATLAB_MEX_FILE 9 | 10 | // wrapper functions if compiling from Matlab 11 | #include "mex.h" 12 | inline void wrError(const char *errormsg) { mexErrMsgTxt(errormsg); } 13 | inline void* wrCalloc( size_t num, size_t size ) { return mxCalloc(num,size); } 14 | inline void* wrMalloc( size_t size ) { return mxMalloc(size); } 15 | inline void wrFree( void * ptr ) { mxFree(ptr); } 16 | 17 | #else 18 | 19 | // wrapper functions if compiling from C/C++ 20 | inline void wrError(const char *errormsg) { throw errormsg; } 21 | inline void* wrCalloc( size_t num, size_t size ) { return calloc(num,size); } 22 | inline void* wrMalloc( size_t size ) { return malloc(size); } 23 | inline void wrFree( void * ptr ) { free(ptr); } 24 | 25 | #endif 26 | 27 | // platform independent aligned memory allocation (see also alFree) 28 | void* alMalloc( size_t size, int alignment ) { 29 | const size_t pSize = sizeof(void*), a = alignment-1; 30 | void *raw = wrMalloc(size + a + pSize); 31 | void *aligned = (void*) (((size_t) raw + pSize + a) & ~a); 32 | *(void**) ((size_t) aligned-pSize) = raw; 33 | return aligned; 34 | } 35 | 36 | // platform independent alignned memory de-allocation (see also alMalloc) 37 | void alFree(void* aligned) { 38 | void* raw = *(void**)((char*)aligned-sizeof(void*)); 39 | wrFree(raw); 40 | } 41 | 42 | #endif 43 | --------------------------------------------------------------------------------