├── READEME.txt ├── README.md ├── Release ├── UAV-Detect.exe └── UAV-Detect.pdb ├── UAV-Detect.sdf ├── UAV-Detect.sln ├── UAV-Detect.v12.suo └── UAV-Detect ├── DPM ├── auxiliary │ ├── cvPrint.cpp │ ├── getCurrentTime.cpp │ └── yuSaveMat.cpp ├── fastDPM │ ├── FastDPM.cpp │ └── FastDPM.h ├── include │ ├── PM_type.h │ └── pthread.h └── source │ ├── analyze_model.cpp │ ├── apply_rules.cpp │ ├── apply_rules2.cpp │ ├── apply_rules3.cpp │ ├── bboxpred_get.cpp │ ├── bboxpred_input.cpp │ ├── bounded_dt.cpp │ ├── bounded_dt2.cpp │ ├── clipboxes.cpp │ ├── cvPermutate.cpp │ ├── detections_trees2.cpp │ ├── draw_img.cpp │ ├── fconv.cpp │ ├── featpyramid.cpp │ ├── featpyramid2.cpp │ ├── features.cpp │ ├── features14_2.cpp │ ├── flipfeat.cpp │ ├── get_score_size.cpp │ ├── loadPyramid.cpp │ ├── load_model.cpp │ ├── loc_feat.cpp │ ├── model_get_block.cpp │ ├── nms.cpp │ ├── pDollar_nms.cpp │ ├── parse_detections.cpp │ ├── reduceboxes.cpp │ ├── sum_score.cpp │ ├── yuInd2Sub.cpp │ └── yuStdDirFiles.cpp ├── KCF ├── include │ ├── boxextractor.h │ ├── dirent.h │ ├── ffttools.hpp │ ├── fhog.hpp │ ├── kcftracker.hpp │ ├── labdata.hpp │ ├── recttools.hpp │ └── tracker.h └── source │ ├── boxextractor.cpp │ ├── fhog.cpp │ └── kcftracker.cpp ├── Release ├── FastDPM.obj ├── UAV-Detect.log ├── UAV-Detect.tlog │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── UAV-Detect.lastbuildstate │ ├── cl.command.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ └── link.write.1.tlog ├── UAVtest.obj ├── analyze_model.obj ├── apply_rules.obj ├── apply_rules2.obj ├── apply_rules3.obj ├── bboxpred_get.obj ├── bboxpred_input.obj ├── bounded_dt.obj ├── bounded_dt2.obj ├── boxextractor.obj ├── clipboxes.obj ├── cvPermutate.obj ├── cvPrint.obj ├── detections_trees2.obj ├── draw_img.obj ├── fconv.obj ├── featpyramid.obj ├── featpyramid2.obj ├── features.obj ├── features14_2.obj ├── fhog.obj ├── flipfeat.obj ├── getCurrentTime.obj ├── get_score_size.obj ├── kcftracker.obj ├── loadPyramid.obj ├── load_model.obj ├── loc_feat.obj ├── model_get_block.obj ├── nms.obj ├── pDollar_nms.obj ├── parse_detections.obj ├── reduceboxes.obj ├── sum_score.obj ├── vc120.pdb ├── yuInd2Sub.obj ├── yuSaveMat.obj └── yuStdDirFiles.obj ├── UAV-Detect.vcxproj ├── UAV-Detect.vcxproj.filters ├── UAV-Detect.vcxproj.user ├── UAV_2.txt ├── UAVtest.cpp ├── bicycle.txt ├── data ├── 000084.jpg ├── 1.flv ├── 1.png ├── 2.avi ├── dpm.jpg └── test1.flv ├── model.txt ├── model_inriaperson.txt ├── output.txt ├── pthreadVC2.dll └── uav_data ├── 1.avi ├── 2.avi ├── 3.avi ├── 4.avi ├── 5.avi ├── 6.avi ├── uav_1.avi └── uav_2.avi /READEME.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/READEME.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **无人机监测(识别和跟踪)** 2 | 3 | --- 4 | --- 5 | 6 | 7 | **1.整体思路:由于识别速度不高,采用识别后在跟踪。将KCF跟踪算法和DPM模型结合** 8 | 9 | 10 | **2.需要解决的问题如下:** 11 | 12 | 13 | - (1).目标出入检测区域,识别和跟踪的交替时间处理。 14 | 15 | 16 | - (2).可以同时识别多个目标,但还未能跟踪多个目标。 17 | 18 | 19 | - (3).目标出入时的检测。 20 | 21 | 22 | - (4).六旋翼模型训练。 23 | 24 | 25 | - (5).算法优化。 26 | 27 | 28 | **3.问题处理安排:** 29 | 30 | 31 | - (1).DPM和KCF融合。2016-3-15 32 | 33 | 34 | - (2).KCF的box属性解决目标出入检测问题。2016-3-16 35 | 36 | 37 | - (3).Debug模式改为Release模式,识别速度明显提高(2.5s-0.8s)。2016-3-17 38 | 39 | 40 | - (4).训练无人机模型:400张正样本,500张负样本,识别成功。2016-4-1 41 | -------------------------------------------------------------------------------- /Release/UAV-Detect.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/Release/UAV-Detect.exe -------------------------------------------------------------------------------- /Release/UAV-Detect.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/Release/UAV-Detect.pdb -------------------------------------------------------------------------------- /UAV-Detect.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect.sdf -------------------------------------------------------------------------------- /UAV-Detect.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UAV-Detect", "UAV-Detect\UAV-Detect.vcxproj", "{06A7628F-EFDD-4BC5-903A-D17047704551}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {06A7628F-EFDD-4BC5-903A-D17047704551}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {06A7628F-EFDD-4BC5-903A-D17047704551}.Debug|Win32.Build.0 = Debug|Win32 16 | {06A7628F-EFDD-4BC5-903A-D17047704551}.Release|Win32.ActiveCfg = Release|Win32 17 | {06A7628F-EFDD-4BC5-903A-D17047704551}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /UAV-Detect.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect.v12.suo -------------------------------------------------------------------------------- /UAV-Detect/DPM/auxiliary/cvPrint.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/DPM/auxiliary/cvPrint.cpp -------------------------------------------------------------------------------- /UAV-Detect/DPM/auxiliary/getCurrentTime.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | #include "Windows.h" 3 | 4 | int PM_type::yuGetCurrentTime( char flag ) 5 | { 6 | SYSTEMTIME system; 7 | GetLocalTime( &system ); 8 | int seconds = system.wHour*3600 + system.wMinute*60 + system.wSecond; 9 | if( flag=='S' ) return seconds; 10 | int Mseconds = 1000*seconds + system.wMilliseconds; 11 | return Mseconds; 12 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/auxiliary/yuSaveMat.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | void PM_type::yuSaveMat(string Name, const cv::Mat &mm) 4 | { 5 | string Name2 = Name + ".xml"; 6 | cv::FileStorage fs(Name2, cv::FileStorage::WRITE); 7 | fs< detections; // results 16 | 17 | //void show( Mat &the_img, bool specification=false ); 18 | 19 | /* All useful stuff have been declared above. */ 20 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 | /* Below are not supposed to be used. */ 24 | 25 | public: 26 | MODEL model; 27 | FEATURE_PYRAMID pyra; 28 | 29 | cv::Mat img_color; 30 | 31 | bool hints; 32 | int start_clock; 33 | int end_clock; 34 | int prag_start; 35 | int prag_end; 36 | 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /UAV-Detect/DPM/include/PM_type.h: -------------------------------------------------------------------------------- 1 | #ifndef PM_TYPE_H 2 | #define PM_TYPE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include // only for Intel processor 13 | 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | 20 | #include "pthread.h" 21 | 22 | #ifndef MIN 23 | #define MIN(x,y) (xy?x:y) 28 | #endif 29 | 30 | #ifndef INT_INF 31 | //#define INT_INF INT_MAX // int32 ranges [-2147483648,2147483647] 32 | // the c runtime file has defined INT_MAX & INT_MIN & FLT_MAX & FLT_MIN 33 | #define INT_INF (int)1e8 34 | #endif 35 | 36 | #ifndef FLOAT_INF 37 | //#define FLOAT_INF float(3e38/10000) // in fact, float32 ranges (4e38,4e38) 38 | //#define FLOAT_INF numeric_limits::infinity() // 1.#INF 39 | #define FLOAT_INF (float)1e20 40 | #endif 41 | 42 | namespace PM_type 43 | { 44 | 45 | template struct AlignedArr 46 | { 47 | T x[num]; 48 | AlignedArr() { memset(x,0,num*sizeof(T)); } 49 | AlignedArr( const AlignedArr *rhs ) { memcpy(x,rhs->x,num*sizeof(T)); } 50 | void operator = ( const AlignedArr rhs ) { memcpy(x,rhs.x,num*sizeof(T)); } 51 | T & operator [] (int i) { return x[i]; } 52 | int size() { return num; } 53 | }; 54 | 55 | typedef AlignedArr INTS_2; 56 | typedef AlignedArr INTS_3; 57 | typedef AlignedArr INTS_4; 58 | typedef AlignedArr FLOATS_2; 59 | typedef AlignedArr FLOATS_4; 60 | typedef AlignedArr FLOATS_7; 61 | 62 | const int SSS = 4; // deformation rules will be applied within the 4-elem proximity 63 | typedef AlignedArr FLOATS_SSS; 64 | 65 | 66 | 67 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | struct MODEL 69 | { 70 | string Class, year, note; 71 | char type; 72 | int numfilters, numblocks, numsymbols, sbin, interval, start; 73 | int maxsize[2], minsize[2]; 74 | float thresh; 75 | // for temporary use in some functions 76 | int TheRoot; 77 | 78 | struct FILTERS{ 79 | int blocklabel; 80 | int size[2]; 81 | bool flip; 82 | int symbol; 83 | }; 84 | vector filters; 85 | 86 | struct RULES{ 87 | char type; 88 | int i; 89 | vector lhs, rhs; // left hand symbols & right hand symbols 90 | int detwindow[2], shiftwindow[2]; 91 | vector blocks; 92 | struct{ 93 | int blocklabel; 94 | }offset; 95 | struct{ 96 | int blocklabel; 97 | }loc; 98 | struct{ 99 | int blocklabel; 100 | bool flip; 101 | }def; 102 | vector anchor; 103 | // for temporary use in some functions 104 | vector Ix, Iy; 105 | }; 106 | vector > rules; 107 | 108 | struct SYMBOLS{ 109 | char type; 110 | int filter; 111 | // for temporary use in some functions 112 | vector score; 113 | }; 114 | vector symbols; 115 | 116 | struct BLOCKS{ 117 | vector w; 118 | vector lb; 119 | float learn, reg_mult; 120 | int dim, shape[3]; 121 | char type; 122 | }; 123 | vector blocks; 124 | 125 | struct{ 126 | int sbin, dim, truncation_dim; 127 | bool extra_octave; 128 | float bias; 129 | }features; 130 | 131 | struct{ 132 | vector slave_problem_time; 133 | vector data_mining_time; 134 | vector pos_latent_time; 135 | vector filter_usage; 136 | }stats; 137 | 138 | struct BBOXPRED{ 139 | cv::Mat x1, y1, x2, y2; 140 | }; 141 | vector bboxpred; 142 | 143 | //-----------------model-analysis------------------------------------------- 144 | vector x_filters; // extracted filters from model's storage block 145 | struct RULE_DATA{ 146 | RULES rule; // the structural rule for each component model 147 | vector sym_terminal; 148 | vector sym_nonTerminal; 149 | vector filter_index; // filter index for each terminal part symbol appeared in the component 150 | vector model_bias; // model bias for each level 151 | vector defcoeff; // deformation coefficients for each part 152 | vector anchor; // anchor positions for each part 153 | int numparts; cv::Mat loc_w; float bias; int num_levels; // auxiliary 154 | // for temporary use in some functions 155 | vector DXDEF; 156 | vector DYDEF; 157 | }; 158 | vector RuleData; 159 | 160 | }; 161 | 162 | // "block_types.m" : 'F'(HOG filter), 'P'(HOG PCA filter (used by cascade)), 'D'(Separable Quadratic Deformation), 'O'(Other: offets, ...) 163 | enum { block_types_Filter = 'F', block_types_PCAFilter = 'P', block_types_SepQuadDef = 'D', block_types_Other = 'O' }; 164 | 165 | // "model_types.m:" : 'M'(Mixture of star models with latent orientation), 'G'(General grammar model (no specific structure)) 166 | enum { model_types_MixStar = 'M', model_types_Grammar = 'G' }; 167 | 168 | struct FEATURE_PYRAMID{ 169 | vector feat; 170 | vector scales; 171 | int imsize[2]; 172 | int num_levels; 173 | int padx, pady; 174 | }; 175 | 176 | 177 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 178 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 179 | int yuGetCurrentTime( char flag = 'S' ); 180 | void yuSaveMat(string Name, const cv::Mat &mm); 181 | void cvPrint(const cv::Mat &A, int chann); 182 | 183 | void load_model( const string FileName, MODEL &model ); 184 | 185 | void model_get_block(MODEL &model, MODEL::FILTERS &obj, cv::Mat &f); 186 | void model_get_block(MODEL &model, int bl, cv::Mat &f); 187 | cv::Mat model_get_block( MODEL &model, int bl, bool flip = false ); 188 | 189 | void flipfeat(cv:: Mat &f, int method ); 190 | void cvPermutate( cv::Mat &f, int *new_row_idx, int *new_col_idx, int *new_dim_idx ); 191 | void yuInd2Sub( const int Ind, const int *Sz, int &Row, int &Col, int &Dim ); 192 | 193 | cv::Mat features( const cv::Mat &image, const int sbin, const int pad[2] ); 194 | cv::Mat features14_2( const cv::Mat &image, const int sbin, const int pad[2] ); 195 | 196 | #define FEATURES PM_type::features 197 | //#define FEATURES PM_type::features14_2 198 | 199 | void featpyramid( const cv::Mat &im, MODEL &model, FEATURE_PYRAMID &pyra ); 200 | void featpyramid2( const cv::Mat &im, const MODEL &model, FEATURE_PYRAMID &pyra ); // backup 201 | 202 | void analyze_model( MODEL &model ); 203 | void get_defcache( MODEL::RULE_DATA &RuleData, const int s ); 204 | void update_ruleData( MODEL &model, int num_levels ); 205 | void loc_feat( const MODEL &model, int num_levels, cv::Mat &f ); 206 | 207 | void fconv(const vector &Feats, const cv::Mat &Filter, vector &Response, int lev1, int lev2, vector &ScoreSz); 208 | void bounded_dt(const cv::Mat &vals, FLOATS_4 &defcoeff, cv::Mat &M, cv::Mat &Ix, cv::Mat &Iy); 209 | void bounded_dt2(const cv::Mat &vals, FLOATS_SSS &DXDEF, FLOATS_SSS &DYDEF, cv::Mat &M, cv::Mat &Ix, cv::Mat &Iy); 210 | void sum_score(cv::Mat &rootScore, const cv::Mat &partScore, int anchorx, int anchory, int padx, int pady); 211 | vector get_score_size(const vector &feats, const vector &filters); 212 | 213 | void apply_rules( MODEL &model, const FEATURE_PYRAMID &pyra ); 214 | void apply_rules2( MODEL &model, FEATURE_PYRAMID &pyra ); 215 | void apply_rules3( MODEL &model, FEATURE_PYRAMID &pyra ); 216 | 217 | void detection_trees2( MODEL &model, int padx, int pady, vectorscales, 218 | vector Xv, vector Yv, vector Lv, vector Cs, vector Sv, 219 | cv::Mat &Dets, cv::Mat &Boxes); 220 | inline int pow2(int p) { return (1< parse_detections( MODEL &model, FEATURE_PYRAMID &pyra, float thresh ); 230 | void draw_img(cv::Mat &img, vector &detections, float ElapsedTime); 231 | 232 | 233 | } 234 | extern cv::Point2f UL_INIT, BR_INIT; 235 | 236 | #endif -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/analyze_model.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | void PM_type::analyze_model( MODEL &model ) 4 | { 5 | if( model.numfilters!=model.filters.size() ) 6 | throw runtime_error(""); 7 | model.x_filters.resize( model.numfilters ); 8 | for( int i=0; i!=model.numfilters; i++ ) 9 | model_get_block( model, model.filters[i], model.x_filters[i] ); 10 | // 11 | int comps = model.rules[0].size(); 12 | model.RuleData.resize( comps ); 13 | for( int component=0; component(0) * model.features.bias; 36 | RuleData.loc_w = model_get_block( model, RuleData.rule.loc.blocklabel ); 37 | } 38 | else{ 39 | MODEL::RULES &r = model.rules[symbol][0]; 40 | cv::Mat defcoeff = model_get_block(model, r.def.blocklabel, r.def.flip); 41 | float *pt = defcoeff.ptr(0); 42 | for( int j=0; j<4; j++ ) 43 | RuleData.defcoeff[i-1][j] = *(pt++); 44 | } 45 | } 46 | get_defcache( RuleData, PM_type::SSS ); 47 | } 48 | } 49 | 50 | void PM_type::update_ruleData( MODEL &model, int num_levels ) 51 | { 52 | int comps = model.RuleData.size(); 53 | for( int component=0; component(0); 60 | RuleData.model_bias.resize( num_levels ); 61 | for( int i=0; i &defcoeff = RuleData.defcoeff; 69 | int sz = defcoeff.size(); 70 | RuleData.DXDEF.resize( sz ); 71 | RuleData.DYDEF.resize( sz ); 72 | for( int i=0; i &filters = model.x_filters; 15 | vector ScoreSz = get_score_size( pyra.feat, filters ); 16 | 17 | for( unsigned component=0; component ix, iy; int oy = 0, ox = 0; 61 | //for(int tmpy=starty;tmpy<=endy;tmpy+=step)if( tmpy<0)oy++;else iy.push_back(tmpy); 62 | //for(int tmpx=startx;tmpx<=endx;tmpx+=step)if(tmpx<0)ox++;else ix.push_back( tmpx ); 63 | //Mat sp( iy.size(), ix.size(), CV_32FC1 ); 64 | //for( int k1=0; k1!=sp.rows; k1++ ) 65 | // for( int k2=0; k2!=sp.cols; k2++ ) 66 | // sp.at(k1,k2) = pscore.at(iy[k1],ix[k2]); 67 | //Mat stmp( score.rows, score.cols, CV_32FC1, Scalar(-FLOAT_INF) ); 68 | //sp.copyTo( stmp(Rect(ox,oy,sp.cols,sp.rows)) ); 69 | //score = score + stmp; 70 | } 71 | } 72 | } 73 | 74 | // symbol_score: apply the very structural rule of this mixture star model 75 | int rootSym1 = model.RuleData[0].sym_nonTerminal[0]; 76 | for( unsigned component=1; component ScoreSz; 19 | } ThreadRules; 20 | 21 | struct ThreadParam{ 22 | int comp; 23 | int filterIndex; 24 | }; 25 | 26 | void * thread_each_part( void *p ) 27 | { 28 | MODEL *model = ThreadRules.model; 29 | const FEATURE_PYRAMID *pyra = ThreadRules.pyra; 30 | 31 | ThreadParam *pData = (ThreadParam*)p; 32 | int comp = pData->comp; 33 | MODEL::RULE_DATA &RuleData = model->RuleData[comp]; 34 | int f = pData->filterIndex; 35 | //printf("\n>>thread(%d) begins",f); 36 | 37 | int partFilterIndex = RuleData.filter_index[f]; 38 | int partSymbol = RuleData.sym_terminal[f]; 39 | int partNonTerminal = RuleData.sym_nonTerminal[f]; 40 | int num_levels = pyra->num_levels, interval = model->interval; 41 | 42 | // filter response of each part ( including root part ) 43 | const vector &filters = model->x_filters; 44 | vector &SymScore = model->symbols[partSymbol].score; 45 | SymScore.resize( num_levels ); 46 | if( f==0 ) 47 | fconv( pyra->feat, filters[partFilterIndex], SymScore, interval, num_levels, ThreadRules.ScoreSz ); 48 | else 49 | fconv( pyra->feat, filters[partFilterIndex], SymScore, 0, num_levels-interval, ThreadRules.ScoreSz ); 50 | 51 | if( f==0 ){ 52 | //printf("\n>>thread(%d) ends",f); 53 | return NULL; 54 | } 55 | 56 | // apply deformation rule 57 | vector &SymNtScore = model->symbols[partNonTerminal].score; 58 | vector &Ix = model->rules[partNonTerminal][0].Ix; 59 | vector &Iy = model->rules[partNonTerminal][0].Iy; 60 | SymNtScore.resize( num_levels ); 61 | Ix.resize( num_levels ); 62 | Iy.resize( num_levels ); 63 | for( int lv=0; lv>thread(%d) ends",f); 70 | return NULL; 71 | } 72 | } 73 | 74 | using namespace APPLY_RULES2; 75 | 76 | 77 | void PM_type::apply_rules2( MODEL &model, FEATURE_PYRAMID &pyra ) 78 | { 79 | const vector &filters = model.x_filters; 80 | vector ScoreSz = get_score_size( pyra.feat, filters ); 81 | 82 | for( unsigned component=0; component Threads( numThreads ); 89 | vector Ps( numThreads ); 90 | for( int f=0; f ScoreSz; 19 | } ThreadRules; 20 | 21 | struct ThreadParam{ 22 | int comp; 23 | int filterIndex; 24 | }; 25 | 26 | void * thread_each_part( void *p ) 27 | { 28 | MODEL *model = ThreadRules.model; 29 | const FEATURE_PYRAMID *pyra = ThreadRules.pyra; 30 | 31 | ThreadParam *pData = (ThreadParam*)p; 32 | int comp = pData->comp; 33 | MODEL::RULE_DATA &RuleData = model->RuleData[comp]; 34 | int f = pData->filterIndex; 35 | //printf("\n>>thread(%d) begins",f); 36 | 37 | int partFilterIndex = RuleData.filter_index[f]; 38 | int partSymbol = RuleData.sym_terminal[f]; 39 | int partNonTerminal = RuleData.sym_nonTerminal[f]; 40 | int num_levels = pyra->num_levels, interval = model->interval; 41 | 42 | // filter response of each part ( including root part ) 43 | const vector &filters = model->x_filters; 44 | vector &SymScore = model->symbols[partSymbol].score; 45 | SymScore.resize( num_levels ); 46 | if( f==0 ) 47 | fconv( pyra->feat, filters[partFilterIndex], SymScore, interval, num_levels, ThreadRules.ScoreSz ); 48 | else 49 | fconv( pyra->feat, filters[partFilterIndex], SymScore, 0, num_levels-interval, ThreadRules.ScoreSz ); 50 | 51 | if( f==0 ){ 52 | //printf("\n>>thread(%d) ends",f); 53 | return NULL; 54 | } 55 | 56 | // apply deformation rule 57 | vector &SymNtScore = model->symbols[partNonTerminal].score; 58 | vector &Ix = model->rules[partNonTerminal][0].Ix; 59 | vector &Iy = model->rules[partNonTerminal][0].Iy; 60 | SymNtScore.resize( num_levels ); 61 | Ix.resize( num_levels ); 62 | Iy.resize( num_levels ); 63 | for( int lv=0; lv>thread(%d) ends",f); 70 | return NULL; 71 | } 72 | 73 | void * thread_each_component( void *p ) 74 | { 75 | MODEL *model = ThreadRules.model; 76 | const FEATURE_PYRAMID *pyra = ThreadRules.pyra; 77 | 78 | ThreadParam *pData = (ThreadParam*)p; 79 | int comp = pData->comp; 80 | MODEL::RULE_DATA &RuleData = model->RuleData[comp]; 81 | 82 | int rootSymbol = RuleData.sym_terminal[0]; 83 | int rootNonTerminal = RuleData.sym_nonTerminal[0]; 84 | int num_levels = pyra->num_levels, interval = model->interval; 85 | int padx = pyra->padx, pady = pyra->pady; 86 | 87 | vector &RootNtScore = model->symbols[rootNonTerminal].score; 88 | RootNtScore.resize( num_levels ); 89 | vector &RootScore = model->symbols[rootSymbol].score; 90 | 91 | for( int lv=interval; lvsymbols[RuleData.sym_nonTerminal[part + 1]].score[partlv]; 97 | sum_score( score, pscore, RuleData.anchor[part][0], RuleData.anchor[part][1], padx, pady ); 98 | } 99 | } 100 | 101 | return NULL; 102 | } 103 | 104 | } 105 | 106 | using namespace APPLY_RULES3; 107 | 108 | void PM_type::apply_rules3( MODEL &model, FEATURE_PYRAMID &pyra ) 109 | { 110 | const vector &filters = model.x_filters; 111 | const int numThreads = filters.size(); // one filter corresponds to one part 112 | vector Threads(numThreads); 113 | vector ThreadData(numThreads); 114 | int idx = 0; 115 | ThreadRules.model = &model; 116 | ThreadRules.pyra = &pyra; 117 | ThreadRules.ScoreSz = get_score_size( pyra.feat, filters ); 118 | 119 | // calculate filter response and apply deformation rules 120 | const int comps = model.RuleData.size(); 121 | for( int component=0; component cinds; 30 | const int *pt = compPt; 31 | for( int i=0; i max_val) { 32 | max_val = val; 33 | argmax = j; 34 | } 35 | vals_off += step; 36 | } 37 | *outpt = max_val; 38 | *Ipt = argmax; 39 | outpt += step; 40 | Ipt += step; 41 | } 42 | } 43 | 44 | // matlab entry point 45 | // [M, Ix, Iy] = bounded_dt(vals, ax, bx, ay, by, s) 46 | void PM_type::bounded_dt(const cv::Mat &vals, FLOATS_4 &defcoeff, cv::Mat &M, cv::Mat &Ix, cv::Mat &Iy) 47 | { 48 | float ax = defcoeff[0], bx = defcoeff[1], ay = defcoeff[2], by = defcoeff[3]; 49 | const int s = 4; 50 | 51 | // storage allocation 52 | int Rows = vals.rows, Cols = vals.cols; 53 | if( !Rows || !Cols ) 54 | throw runtime_error(""); 55 | M.create( Rows, Cols, CV_32FC1 ); 56 | Ix.create( Rows, Cols, CV_32SC1 ); 57 | Iy.create( Rows, Cols, CV_32SC1 ); 58 | cv::Mat tmpM(Rows, Cols, CV_32FC1); 59 | cv::Mat tmpIy(Rows, Cols, CV_32SC1); 60 | 61 | const float *vPt = (float*)vals.data; int vStep = vals.step1(); 62 | float *mPt = (float*)M.data; int mStep = M.step1(); 63 | int *ixPt = (int*)Ix.data; int ixStep = Ix.step1(); 64 | int *iyPt = (int*)Iy.data; int iyStep = Iy.step1(); 65 | float *tmPt = (float*)tmpM.data; int tmStep = tmpM.step1(); 66 | int *tyPt = (int*)tmpIy.data; int tyStep = tmpIy.step1(); 67 | 68 | for( int c=0; c max_val) { 30 | max_val = val; 31 | argmax = j; 32 | } 33 | vals_off += step; 34 | } 35 | *outpt = max_val; 36 | *Ipt = argmax; 37 | outpt += step; 38 | Ipt += step; 39 | } 40 | } 41 | 42 | // matlab entry point 43 | // [M, Ix, Iy] = bounded_dt(vals, ax, bx, ay, by, s) 44 | void PM_type::bounded_dt2(const cv::Mat &vals, FLOATS_SSS &DXDEF, FLOATS_SSS &DYDEF, cv::Mat &M, cv::Mat &Ix, cv::Mat &Iy) 45 | { 46 | const int s = PM_type::SSS; 47 | 48 | // storage allocation 49 | int Rows = vals.rows, Cols = vals.cols; 50 | if( !Rows || !Cols ) 51 | throw runtime_error(""); 52 | M.create( Rows, Cols, CV_32FC1 ); 53 | Ix.create( Rows, Cols, CV_32SC1 ); 54 | Iy.create( Rows, Cols, CV_32SC1 ); 55 | cv::Mat tmpM(Rows, Cols, CV_32FC1); 56 | cv::Mat tmpIy(Rows, Cols, CV_32SC1); 57 | 58 | const float *vPt = (float*)vals.data; int vStep = vals.step1(); 59 | float *mPt = (float*)M.data; int mStep = M.step1(); 60 | int *ixPt = (int*)Ix.data; int ixStep = Ix.step1(); 61 | int *iyPt = (int*)Iy.data; int iyStep = Iy.step1(); 62 | float *tmPt = (float*)tmpM.data; int tmStep = tmpM.step1(); 63 | int *tyPt = (int*)tmpIy.data; int tyStep = tmpIy.step1(); 64 | 65 | for( int c=0; c(i) ) 25 | continue; 26 | ds.row(i).copyTo( ds_cpy.row(j) ); 27 | j++; 28 | } 29 | ds.create( ds_cpy.rows, ds_cpy.cols, ds_cpy.type() ); 30 | ds_cpy.copyTo(ds); 31 | // 32 | if( !bs.empty() ){ 33 | cv::Mat bs_cpy(bs.rows - cnt, bs.cols, bs.type()); 34 | int j = 0; 35 | for( int i=0; i(i) ) 37 | continue; 38 | bs.row(i).copyTo( bs_cpy.row(j) ); 39 | j++; 40 | } 41 | bs.create( bs_cpy.rows, bs_cpy.cols, bs_cpy.type() ); 42 | bs_cpy.copyTo(bs); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/cvPermutate.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | void PM_type::cvPermutate(cv::Mat &f, int *new_row_idx, int *new_col_idx, int *new_dim_idx) 4 | { 5 | int Rows = f.rows, Cols = f.cols, Chns = f.channels(); 6 | 7 | // task can be down in 3 steps: 8 | 9 | // 1st step: f = f(:,:,new_dim_idx); 10 | if( new_dim_idx!=NULL ){ 11 | int *from_to = new int [Chns*2](); 12 | for( int i=0; i!=Chns; i++ ){ 13 | from_to[2*i] = new_dim_idx[i]; 14 | from_to[2*i+1] = i; 15 | } 16 | cv::Mat g = f.clone(); 17 | mixChannels( &g, 1, &f, 1, from_to, Chns ); 18 | g.release(); 19 | } 20 | 21 | // 2nd step: f = f(:,new_col_idx,:); 22 | if( new_col_idx!=NULL ){ 23 | cv::Mat f2(Rows, Cols*Chns, CV_MAKETYPE(f.depth(), 1), f.data); 24 | cv::Mat g2 = f2.clone(); 25 | for( int i=0; i!=Cols; i++ ){ 26 | int f_col_start = i * Chns; 27 | int f_col_end = f_col_start + Chns; 28 | int g_col_start = new_col_idx[i] * Chns; 29 | int g_col_end = g_col_start + Chns; 30 | cv::Mat f_col_block = f2.colRange(f_col_start, f_col_end); 31 | cv::Mat g_col_block = g2.colRange(g_col_start, g_col_end); 32 | g_col_block.copyTo( f_col_block ); 33 | } 34 | g2.release(); 35 | } 36 | 37 | // 3rd step: f = f(new_row_idx,:,:); 38 | if( new_row_idx!=NULL ){ 39 | cv::Mat g3 = f.clone(); 40 | for( int i=0; i!=Rows; i++ ){ 41 | cv::Mat f_row = f.row(i); 42 | cv::Mat g_row = g3.row(new_row_idx[i]); 43 | g_row.copyTo( f_row ); 44 | } 45 | g3.release(); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/detections_trees2.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | using namespace PM_type; 3 | 4 | void PM_type::detection_trees2( MODEL &model, int padx, int pady, vectorscales, 5 | vector Xv, vector Yv, vector Lv, vector Cs, vector Sv, 6 | cv::Mat &Dets, cv::Mat &Boxes) 7 | { 8 | int dim = Sv.size(); 9 | Dets = cv::Mat::zeros(dim, 4 + 3, CV_32FC1); // 4+3 is bounding box, level, component, score 10 | float *dets = (float*)Dets.data; 11 | int numparts = model.RuleData[0].numparts; 12 | Boxes = cv::Mat::zeros(dim, 4 * (1 + numparts), CV_32FC1); 13 | float *boxes = (float*)Boxes.data; 14 | // 15 | const float sbin = (float)model.sbin; 16 | for( int i=0; i(party,partx); 53 | int rhs_y = Iy.at(party,partx); 54 | // 55 | filter_index = ruleData.filter_index[idx]; 56 | x1 = ( rhs_x - padx ) * scale; 57 | y1 = ( rhs_y - pady ) * scale; 58 | x2 = x1 + model.x_filters[filter_index].cols * scale - 1; 59 | y2 = y1 + model.x_filters[filter_index].rows * scale - 1; 60 | *(boxes++) = x1; *(boxes++) = y1; *(boxes++) = x2; *(boxes++) = y2; 61 | } 62 | } 63 | return; 64 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/draw_img.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | cv::Point2f UL_INIT, BR_INIT; 3 | void PM_type::draw_img(cv::Mat &img, vector &detections, float ElapsedTime) 4 | { 5 | char buf[100]; 6 | const cv::Scalar drawColor = CV_RGB(255, 0, 0); 7 | const cv::Scalar fontColor = CV_RGB(200, 0, 255); 8 | const float fontScale = 1; 9 | const int fontFace = CV_FONT_HERSHEY_PLAIN; 10 | 11 | printf(">>> %-9s %-9s %-9s %-9s %-5s %-9s %-9s\n","x1","y1","x2","y2","level","component","score"); 12 | for( unsigned i=0; i0 ){ 46 | printf("Elapsed time for total program = %gs\n",ElapsedTime); 47 | memset( buf, 0, 100 ); 48 | sprintf_s( buf, "elapsed_time = %gs", ElapsedTime ); 49 | string msg(buf); 50 | int baseline = 0; 51 | cv::Size textSize = cv::getTextSize(msg, fontFace, fontScale, 1, &baseline); 52 | cv::Point txtOrig(5, (detections.size() + 1)*(textSize.height + 3)); 53 | putText( img, msg, txtOrig, fontFace, fontScale, fontColor ); 54 | } 55 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/fconv.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | void fconv_1(const cv::Mat &A, const cv::Mat &F, cv::Mat &R); 4 | void fconv_SSE(const cv::Mat &A, const cv::Mat &F, cv::Mat &R); 5 | 6 | void PM_type::fconv(const vector &Feats, const cv::Mat &Filter, vector &Response, int lev1, int lev2, vector &ScoreSz) 7 | // The filter response of Filter on HOG feature map Feats 8 | { 9 | Response.resize( Feats.size() ); 10 | for( int i=lev1; i(0,0); 55 | const float *A_src0 = A.ptr(0,0); 56 | 57 | __m128 a,b,c; 58 | for( int rr=0; rr(rr,cc); 63 | float *R_src = R_scr1 + cc; 64 | // An acceleration trick of using SSE programming >>> 65 | __m128 v = _mm_setzero_ps(); 66 | const float *B_off = F_src; 67 | for( int rp=0; rp *MatArr; 5 | PM_type::FEATURE_PYRAMID *pyra; 6 | int interval, level, len; 7 | int *pads, *binSz; 8 | }; 9 | 10 | void * getFeat( void *p ) 11 | { 12 | getFeat_data *D = (getFeat_data*)p; 13 | int level = D->level; 14 | int interval = D->interval; 15 | int *binSz = D->binSz; 16 | int len = D->len; 17 | int *pads = D->pads; 18 | vector &feat = D->pyra->feat; 19 | vector *MatArr = D->MatArr; 20 | //printf("thread-%d begins\n",level); 21 | for( int i=0; i BinSz( SZ, sbin ); 75 | 76 | // resized images for each level 77 | static vector MatArr; 78 | MatArr.resize( SZ ); 79 | // the second octave 80 | MatArr[interval] = im; pyra.scales[interval] = 1.f; 81 | sc = 1.f/sc; float scf = sc;for( int i=1; i=SZ ) break; 92 | pyrDown( MatArr[lv-interval], MatArr[lv] ); pyra.scales[lv] = pyra.scales[lv-interval] * 0.5f; 93 | } 94 | } 95 | 96 | // Create threads to process each level features 97 | //getFeat_data data; data.MatArr = &MatArr; data.interval = interval; data.pads = pads; data.sbin = sbin; data.pyra = &pyra; 98 | getFeat_data data[2]; 99 | for( int i=0; i<2; i++ ){ data[i].MatArr = &MatArr; data[i].interval = interval; data[i].pads = pads; data[i].binSz = &BinSz[0]; data[i].pyra = &pyra; } 100 | data[0].level = 0; data[0].len = 5; 101 | data[1].level = data[0].len; data[1].len = 8; 102 | pthread_t threads[2]; 103 | for( int i=0; i<2; i++ ) pthread_create( threads+i, NULL, getFeat, &(data[i]) ); 104 | 105 | // Process the rest levels in the main thread 106 | for( int i=data[1].level+data[1].len; i0 ){ 65 | // Optional (sbin/4) x (sbin/4) features 66 | //pyra.feat[i] = features( scaled, sbin/4, pads ); 67 | pyra.feat[i] = FEATURES( scaled, sbin/4, pads ); 68 | pyra.scales[i] = 4 * scale_factor; 69 | } 70 | // (sbin/2) x (sbin/2) features 71 | //pyra.feat[i+extra_interval] = features( scaled, sbin/2, pads ); 72 | pyra.feat[i+extra_interval] = FEATURES( scaled, sbin/2, pads ); 73 | pyra.scales[i+extra_interval] = 2 * scale_factor; 74 | // sbin x sbin HOG features 75 | //pyra.feat[i+extra_interval+interval] = features( scaled, sbin, pads ); 76 | pyra.feat[i+extra_interval+interval] = FEATURES( scaled, sbin, pads ); 77 | pyra.scales[i+extra_interval+interval] = scale_factor; 78 | // Remaining pyramid octaves 79 | for( int j=i+interval; j rc; 27 | if( rc.size()!=f.cols ){ 28 | rc.resize( f.cols ); 29 | for( int i=0; i!=rc.size(); i++ ) 30 | rc[i] = rc.size() - 1 - i; 31 | } 32 | 33 | int *p = p1; 34 | if( f.channels()==32 ) 35 | p = p2; 36 | 37 | if( method!=0 ) 38 | cvPermutate( f, NULL, &rc[0], NULL ); 39 | else 40 | cvPermutate( f, NULL, &rc[0], p ); 41 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/get_score_size.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | // get the normalized sizes for each level convolution response 4 | 5 | vector PM_type::get_score_size(const vector &feats, const vector &filters) 6 | { 7 | int num_levels = feats.size(); 8 | int num_filters = filters.size(); 9 | vector ScoreSz( num_levels ); 10 | for( int i=0; isz[0] ) 20 | sz[0] = Rows; 21 | if( Cols>sz[1] ) 22 | sz[1] = Cols; 23 | } 24 | ScoreSz[i][0] = sz[0]; 25 | ScoreSz[i][1] = sz[1]; 26 | } 27 | return ScoreSz; 28 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/loadPyramid.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/DPM/source/loadPyramid.cpp -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/load_model.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | 4 | inline 5 | void yuCheck( bool val ) 6 | { 7 | if( !val ){ 8 | printf("Check failure in loadModel()! Please check the model file.\n"); 9 | throw runtime_error(""); 10 | } 11 | } 12 | 13 | inline 14 | ifstream& operator>>( ifstream &ifs, int &val ) 15 | { 16 | // infinite numbers can be written into file with "inf" markup( both in matlab and in c++ ), 17 | // but when reading from the file, the "inf" markup is not recognized as a number 18 | string tmpS; 19 | ifs>>tmpS; 20 | if( tmpS=="Inf" || tmpS=="inf" ) 21 | val = INT_INF; 22 | else if( tmpS=="-Inf" || tmpS=="-inf" ) 23 | val = -INT_INF; 24 | else 25 | val = (int)atoi( tmpS.c_str() ); 26 | 27 | return ifs; 28 | } 29 | 30 | inline 31 | ifstream& operator>>( ifstream &ifs, float &val ) 32 | { 33 | string tmpS; 34 | ifs>>tmpS; 35 | if( tmpS=="Inf" || tmpS=="inf" ) 36 | val = FLOAT_INF; 37 | else if( tmpS=="-Inf" || tmpS=="-inf" ) 38 | val = -FLOAT_INF; 39 | else 40 | val = (float)atof( tmpS.c_str() ); 41 | 42 | return ifs; 43 | } 44 | 45 | //============================================= 46 | void PM_type::load_model( const string FileName, MODEL &model ) 47 | // load a DPM model from the file 48 | { 49 | ifstream MF( FileName.c_str() ); 50 | if( !MF ){ 51 | cout<<"Cannot open model file!"<>Title; 60 | yuCheck(Title=="class"); 61 | MF>>model.Class; 62 | // year 63 | MF>>Title; 64 | yuCheck(Title=="year"); 65 | MF>>model.year; 66 | // note 67 | MF>>Title; 68 | yuCheck(Title=="note"); 69 | MF>>model.note; 70 | 71 | // filters 72 | MF>>Title; 73 | yuCheck(Title=="filters"); 74 | MF>>Sz; 75 | model.filters.resize( Sz ); 76 | for( unsigned i=0; i>tmpS; 79 | MF>>Title; 80 | yuCheck(Title=="blocklabel"); 81 | MF>>F.blocklabel; 82 | MF>>Title; 83 | yuCheck(Title=="size"); 84 | MF>>F.size[0]>>F.size[1]; 85 | MF>>Title; 86 | yuCheck(Title=="flip"); 87 | MF>>tmp; 88 | F.flip = (tmp!=0); 89 | MF>>Title; 90 | yuCheck(Title=="symbol"); 91 | MF>>F.symbol; 92 | // -1 93 | F.blocklabel--; 94 | F.symbol--; 95 | model.filters[i] = F; 96 | } 97 | 98 | // rules 99 | MF>>Title; 100 | yuCheck(Title=="rules"); 101 | MF>>Sz; 102 | model.rules.resize( Sz ); 103 | for( unsigned i=0; i>tmpS; 105 | MF>>Sz; 106 | model.rules[i].resize( Sz ); 107 | for( unsigned j=0; j>tmpS; 110 | MF>>Title; 111 | yuCheck(Title=="type"); 112 | MF>>R.type; 113 | MF>>Title; 114 | yuCheck(Title=="lhs"); 115 | MF>>Sz; 116 | R.lhs.resize( Sz ); 117 | for( unsigned k=0; k>R.lhs[k]; 119 | MF>>Title; 120 | yuCheck(Title=="rhs"); 121 | MF>>Sz; 122 | R.rhs.resize( Sz ); 123 | for( unsigned k=0; k>R.rhs[k]; 125 | MF>>Title; 126 | yuCheck(Title=="detwindow"); 127 | MF>>R.detwindow[0]>>R.detwindow[1]; 128 | MF>>Title; 129 | yuCheck(Title=="shiftwindow"); 130 | MF>>R.shiftwindow[0]>>R.shiftwindow[1]; 131 | MF>>Title; 132 | yuCheck(Title=="i"); 133 | MF>>R.i; 134 | MF>>Title; 135 | yuCheck(Title=="anchor"); 136 | MF>>Sz; 137 | R.anchor.resize( Sz ); 138 | for( unsigned k=0; k>tmp; 140 | yuCheck(tmp==k+1); 141 | MF>>R.anchor[k][0]>>R.anchor[k][1]>>R.anchor[k][2]; 142 | } 143 | MF>>Title; 144 | yuCheck(Title=="offset.blocklabel"); 145 | MF>>R.offset.blocklabel; 146 | MF>>Title; 147 | yuCheck(Title=="loc.blocklabel"); 148 | MF>>R.loc.blocklabel; 149 | MF>>Title; 150 | yuCheck(Title=="blocks"); 151 | MF>>Sz; 152 | R.blocks.resize( Sz ); 153 | for( unsigned k=0; k>R.blocks[k]; 155 | MF>>Title; 156 | yuCheck(Title=="def.blocklabel"); 157 | MF>>R.def.blocklabel; 158 | MF>>Title; 159 | yuCheck(Title=="def.flip"); 160 | MF>>tmp; 161 | R.def.flip = (tmp!=0); 162 | // -1 163 | for( unsigned k=0; k>Title; 177 | yuCheck(Title=="symbols"); 178 | MF>>Sz; 179 | model.symbols.resize( Sz ); 180 | for( unsigned i=0; i>tmpS; 183 | MF>>Title; 184 | yuCheck(Title=="type"); 185 | MF>>SS.type; 186 | MF>>Title; 187 | yuCheck(Title=="filter"); 188 | MF>>SS.filter; 189 | // -1 190 | SS.filter--; 191 | model.symbols[i] = SS; 192 | } 193 | 194 | // numfilters 195 | MF>>Title; 196 | yuCheck(Title=="numfilters"); 197 | MF>>model.numfilters; 198 | MF>>Title; 199 | yuCheck(Title=="numblocks"); 200 | MF>>model.numblocks; 201 | MF>>Title; 202 | yuCheck(Title=="numsymbols"); 203 | MF>>model.numsymbols; 204 | MF>>Title; 205 | yuCheck(Title=="start"); 206 | MF>>model.start; 207 | MF>>Title; 208 | yuCheck(Title=="maxsize"); 209 | MF>>model.maxsize[0]>>model.maxsize[1]; 210 | MF>>Title; 211 | yuCheck(Title=="minsize"); 212 | MF>>model.minsize[0]>>model.minsize[1]; 213 | MF>>Title; 214 | yuCheck(Title=="interval"); 215 | MF>>model.interval; 216 | MF>>Title; 217 | yuCheck(Title=="sbin"); 218 | MF>>model.sbin; 219 | MF>>Title; 220 | yuCheck(Title=="thresh"); 221 | MF>>model.thresh; 222 | MF>>Title; 223 | yuCheck(Title=="type"); 224 | MF>>model.type; 225 | // -1 226 | model.start--; 227 | 228 | // blocks 229 | MF>>Title; 230 | yuCheck(Title=="blocks"); 231 | MF>>Sz; 232 | model.blocks.resize( Sz ); 233 | for( unsigned i=0; i>tmpS; 236 | MF>>Title; 237 | yuCheck(Title=="w"); 238 | MF>>Sz; 239 | B.w.resize( Sz ); 240 | for( int k=0; k>B.w[k]; 242 | MF>>Title; 243 | yuCheck(Title=="lb"); 244 | MF>>Sz; 245 | B.lb.resize( Sz ); 246 | for( int k=0; k>B.lb[k]; 248 | MF>>Title; 249 | yuCheck(Title=="learn"); 250 | MF>>B.learn; 251 | MF>>Title; 252 | yuCheck(Title=="reg_mult"); 253 | MF>>B.reg_mult; 254 | MF>>Title; 255 | yuCheck(Title=="dim"); 256 | MF>>B.dim; 257 | MF>>Title; 258 | yuCheck(Title=="shape"); 259 | MF>>Sz; 260 | B.shape[0] = B.shape[1] = B.shape[2] = 1; 261 | for( int k=0; k>B.shape[k]; 263 | MF>>Title; 264 | yuCheck(Title=="type"); 265 | MF>>B.type; 266 | // 267 | model.blocks[i] = B; 268 | } 269 | 270 | // features 271 | MF>>Title; 272 | yuCheck(Title=="features"); 273 | MF>>Title; 274 | yuCheck(Title=="sbin"); 275 | MF>>model.features.sbin; 276 | MF>>Title; 277 | yuCheck(Title=="dim"); 278 | MF>>model.features.dim; 279 | MF>>Title; 280 | yuCheck(Title=="truncation_dim"); 281 | MF>>model.features.truncation_dim; 282 | MF>>Title; 283 | yuCheck(Title=="extra_octave"); 284 | MF>>tmp; 285 | model.features.extra_octave = (tmp!=0); 286 | MF>>Title; 287 | yuCheck(Title=="bias"); 288 | MF>>model.features.bias; 289 | 290 | // stats 291 | MF>>Title; 292 | yuCheck(Title=="stats"); 293 | MF>>Title; 294 | yuCheck(Title=="slave_problem_time"); 295 | MF>>Sz; 296 | model.stats.slave_problem_time.resize( Sz ); 297 | for( int i=0; i>model.stats.slave_problem_time[i]; 299 | MF>>Title; 300 | yuCheck(Title=="data_mining_time"); 301 | MF>>Sz; 302 | model.stats.data_mining_time.resize( Sz ); 303 | for( int i=0; i>model.stats.data_mining_time[i]; 305 | MF>>Title; 306 | yuCheck(Title=="pos_latent_time"); 307 | MF>>Sz; 308 | model.stats.pos_latent_time.resize( Sz ); 309 | for( int i=0; i>model.stats.pos_latent_time[i]; 311 | MF>>Title; 312 | yuCheck(Title=="filter_usage"); 313 | MF>>Sz; 314 | model.stats.filter_usage.resize( Sz ); 315 | for( int i=0; i>model.stats.filter_usage[i]; 317 | 318 | // bboxpred 319 | MF>>Title; 320 | yuCheck(Title=="bboxpred"); 321 | MF>>Sz; 322 | model.bboxpred.resize( Sz ); 323 | for( unsigned i=0; i>tmpS; 326 | MF>>Title; 327 | yuCheck(Title=="x1"); 328 | MF>>Sz; 329 | B2.x1.create( Sz, 1, CV_32FC1 ); 330 | float *pt = (float*)B2.x1.data; 331 | for( int k=0; k>pt[k]; 333 | MF>>Title; 334 | yuCheck(Title=="y1"); 335 | MF>>Sz; 336 | B2.y1.create( Sz, 1, CV_32FC1 ); 337 | pt = (float*)B2.y1.data; 338 | for( int k=0; k>pt[k]; 340 | MF>>Title; 341 | yuCheck(Title=="x2"); 342 | MF>>Sz; 343 | B2.x2.create( Sz, 1, CV_32FC1 ); 344 | pt = (float*)B2.x2.data; 345 | for( int k=0; k>pt[k]; 347 | MF>>Title; 348 | yuCheck(Title=="y2"); 349 | MF>>Sz; 350 | B2.y2.create( Sz, 1, CV_32FC1 ); 351 | pt = (float*)B2.y2.data; 352 | for( int k=0; k>pt[k]; 354 | model.bboxpred[i] = B2; 355 | } 356 | 357 | 358 | MF.close(); 359 | return; 360 | 361 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/loc_feat.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | namespace PM_type{ 4 | void loc_feat(const MODEL &model, int num_levels, cv::Mat &f) 5 | //% Location and scale features. 6 | //% f = loc_feat(model, num_levels) 7 | //% 8 | //% Compute a feature indicating if level i is in the first octave of 9 | //% the feature pyramid, the second octave, or above. This could be 10 | //% generalized to a "location feature" instead of just a scale feature. 11 | //% 12 | //% Return value 13 | //% f = [f_1, ..., f_i, ..., f_num_levels], 14 | //% where f_i is the 3x1 vector = 15 | //% [1; 0; 0] if 1 <= i <= model.interval 16 | //% [0; 1; 0] if model.interval+1 <= i <= 2*model.interval 17 | //% [0; 0; 1] if 2*model.interval+1 <= i <= num_levels 18 | //% 19 | //% Arguments 20 | //% model Model used for detection 21 | //% num_levels Number of levels in the feature pyramid 22 | { 23 | f.create( 3, num_levels, CV_32FC1 ); 24 | f = cv::Scalar(0); 25 | 26 | int b = 0; 27 | int e = MIN( num_levels, model.interval ); 28 | f(cv::Rect(b, 0, e - b, 1)) = cv::Scalar(1); 29 | 30 | b = e; 31 | e = MIN( num_levels, 2*e ); 32 | f(cv::Rect(b, 1, e - b, 1)) = cv::Scalar(1); 33 | 34 | b = e; 35 | f(cv::Rect(b, 2, f.cols - b, 1)) = cv::Scalar(1); 36 | 37 | return; 38 | } 39 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/model_get_block.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | void PM_type::model_get_block(MODEL &model, MODEL::FILTERS &obj, cv::Mat &f) 4 | { 5 | int bl = obj.blocklabel; 6 | char type = model.blocks[bl].type; 7 | int *shape = model.blocks[bl].shape; 8 | vector &w = model.blocks[bl].w; 9 | 10 | int dim = shape[0] * shape[1] * shape[2]; 11 | if( dim!=w.size() ) 12 | throw runtime_error(""); 13 | 14 | cv::Mat f0(shape[0], shape[1], CV_32FC(shape[2]), &w[0]); 15 | f.create( shape[0], shape[1], CV_32FC(shape[2]) ); 16 | f0.copyTo(f); 17 | 18 | // Flip (if needed) according to block type 19 | switch(type){ 20 | case block_types_Filter: 21 | if(obj.flip ) 22 | flipfeat( f, 0 ); 23 | break; 24 | case block_types_PCAFilter: 25 | if(obj.flip ) 26 | flipfeat( f, 1 ); 27 | break; 28 | case block_types_SepQuadDef: 29 | if(obj.flip ){ 30 | int r,c,d; 31 | yuInd2Sub( 1, shape, r, c, d ); 32 | float *pt = f.ptr(r,c); 33 | pt[d] = -pt[d]; 34 | } 35 | break; 36 | default: 37 | break; 38 | } 39 | 40 | return; 41 | } 42 | 43 | void PM_type::model_get_block(MODEL &model, int bl, cv::Mat &f) 44 | { 45 | char type = model.blocks[bl].type; 46 | int *shape = model.blocks[bl].shape; 47 | vector &w = model.blocks[bl].w; 48 | 49 | int dim = shape[0] * shape[1] * shape[2]; 50 | if( dim!=w.size() ) 51 | throw runtime_error(""); 52 | 53 | cv::Mat f0(shape[0], shape[1], CV_32FC(shape[2]), &w[0]); 54 | f.create( shape[0], shape[1], CV_32FC(shape[2]) ); 55 | f0.copyTo(f); 56 | 57 | return; 58 | } 59 | 60 | cv::Mat PM_type::model_get_block(MODEL &model, int bl, bool flip) 61 | { 62 | char type = model.blocks[bl].type; 63 | int *shape = model.blocks[bl].shape; 64 | vector &w = model.blocks[bl].w; 65 | 66 | int dim = shape[0] * shape[1] * shape[2]; 67 | if( dim!=w.size() ) 68 | throw runtime_error(""); 69 | 70 | cv::Mat f0(shape[0], shape[1], CV_32FC(shape[2]), &w[0]); 71 | cv::Mat f(shape[0], shape[1], CV_32FC(shape[2])); 72 | f0.copyTo(f); 73 | 74 | // Flip (if needed) according to block type 75 | switch(type){ 76 | case block_types_Filter: 77 | if(flip ) 78 | flipfeat( f, 0 ); 79 | break; 80 | case block_types_PCAFilter: 81 | if(flip ) 82 | flipfeat( f, 1 ); 83 | break; 84 | case block_types_SepQuadDef: 85 | if(flip ){ 86 | int r,c,d; 87 | yuInd2Sub( 1, shape, r, c, d ); 88 | float *pt = f.ptr(r,c); 89 | pt[d] = -pt[d]; 90 | } 91 | break; 92 | default: 93 | break; 94 | } 95 | 96 | return f; 97 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/nms.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | cv::Mat PM_type::nms(const cv::Mat &boxes, float overlap) 4 | //% Non-maximum suppression. 5 | //% pick = nms(boxes, overlap) 6 | //% 7 | //% Greedily select high-scoring detections and skip detections that are 8 | //% significantly covered by a previously selected detection. 9 | //% 10 | //% Return value 11 | //% pick Indices of locally maximal detections 12 | //% 13 | //% Arguments 14 | //% boxes Detection bounding boxes (see pascal_test.m) 15 | //% overlap Overlap threshold for suppression 16 | //% For a selected box Bi, all boxes Bj that are covered by 17 | //% more than overlap are suppressed. Note that 'covered' is 18 | //% is |Bi \cap Bj| / |Bj|, not the PASCAL intersection over 19 | //% union measure. 20 | { 21 | if( boxes.empty() ) 22 | return boxes; 23 | 24 | cv::Mat x1 = boxes.col(0); 25 | cv::Mat y1 = boxes.col(1); 26 | cv::Mat x2 = boxes.col(2); 27 | cv::Mat y2 = boxes.col(3); 28 | cv::Mat s = boxes.col(boxes.cols - 1); 29 | 30 | cv::Mat area = x2 - x1 + 1; 31 | area = area.mul(y2-y1+1); 32 | 33 | vector Ind( s.rows, 0 ); 34 | cv::Mat Idx(s.rows, 1, CV_32SC1, &Ind[0]); 35 | sortIdx( s, Idx, CV_SORT_EVERY_COLUMN+CV_SORT_ASCENDING ); 36 | 37 | vector pick; 38 | while( !Ind.empty() ){ 39 | int last = Ind.size() - 1; 40 | int i = Ind[last]; 41 | pick.push_back(i); 42 | 43 | vector suppress( 1, last ); 44 | for( int pos=0; pos(i), x1.at(j)); 47 | float yy1 = std::max(y1.at(i), y1.at(j)); 48 | float xx2 = std::min(x2.at(i), x2.at(j)); 49 | float yy2 = std::min(y2.at(i), y2.at(j)); 50 | float w = xx2-xx1+1; 51 | float h = yy2-yy1+1; 52 | if( w>0 && h>0 ){ 53 | // compute overlap 54 | float area_intersection = w * h; 55 | float o1 = area_intersection / area.at(j); 56 | float o2 = area_intersection / area.at(i); 57 | float o = std::max(o1,o2); 58 | if( o>overlap ) 59 | suppress.push_back(pos); 60 | } 61 | } 62 | 63 | std::set supp( suppress.begin(), suppress.end() ); 64 | vector Ind2; 65 | for( int i=0; i!=Ind.size(); i++ ){ 66 | if( supp.find(i)==supp.end() ) 67 | Ind2.push_back( Ind[i] ); 68 | } 69 | Ind = Ind2; 70 | 71 | } 72 | 73 | cv::Mat ret(pick.size(), boxes.cols, boxes.type()); 74 | for( unsigned i=0; i Ind( n, 0 ); 10 | cv::Mat Idx(n, 1, CV_32SC1, &Ind[0]); 11 | const cv::Mat &score = bbs.col(bbs.cols - 1); 12 | sortIdx( score, Idx, CV_SORT_EVERY_COLUMN+CV_SORT_DESCENDING ); 13 | 14 | // for each i suppress all j st j>i and area-overlap>overlap 15 | vector kp( n, true ); 16 | const cv::Mat &xs = bbs.col(0); // xstart 17 | const cv::Mat &ys = bbs.col(1); // ystart 18 | const cv::Mat &xe = bbs.col(2); // xend 19 | const cv::Mat &ye = bbs.col(3); // yend 20 | 21 | cv::Mat w = xe - xs; 22 | cv::Mat h = ye - ys; 23 | cv::Mat as = w.mul(h); 24 | for(int ii=0; ii(i),xe.at(j)) - MAX(xs.at(i),xs.at(j)); 32 | if(iw<0 ) 33 | continue; 34 | //float ih = MIN(ye[i],ye[j]) - MAX(ys[i],ys[j]); 35 | float ih = MIN(ye.at(i),ye.at(j)) - MAX(ys.at(i),ys.at(j)); 36 | if(ih<0 ) 37 | continue; 38 | float o = iw * ih; 39 | //float u = MIN(as[i],as[j]); 40 | float u = MIN(as.at(i),as.at(j)); 41 | float ratio = o / u; 42 | if(ratio>overlap ) 43 | kp[j] = false; 44 | } 45 | } 46 | 47 | int cnt = 0; 48 | for(int i=0; i PM_type::parse_detections( MODEL &model, FEATURE_PYRAMID &pyra, float thresh ) 4 | { 5 | vector Result; 6 | 7 | // Find scores above the threshold 8 | vector Xs, Ys, Ls; 9 | vector Ss; 10 | for(int level=model.interval; level thresh; 13 | for( int y=0; y(y,0); 15 | for( int x=0; x(y,x) ); 21 | } 22 | pt++; 23 | } 24 | } 25 | } 26 | 27 | // Exit if no detection 28 | if(Xs.empty()) return Result; 29 | 30 | // Sort by scores 31 | vector ord( Xs.size() ); 32 | cv::Mat ord_mat(1, Xs.size(), CV_32SC1, &ord[0]); 33 | cv::Mat Ss_mat(1, Ss.size(), CV_32FC1, &Ss[0]); 34 | sortIdx( Ss_mat, ord_mat, CV_SORT_EVERY_ROW+CV_SORT_DESCENDING ); 35 | // 36 | vector tmpvec( ord.size() ); 37 | for( unsigned i=0; itmpvecf( ord.size() ); 47 | for( unsigned i=0; i Cs; 53 | Cs.resize( Ss.size(), 0 ); 54 | for( unsigned i=0; i(y,x) != s ) 61 | throw runtime_error(""); 62 | for( unsigned component=1; component(y,x) >= s ){ Cs[i] = component; break; } 66 | } 67 | } 68 | 69 | // Compute detection windows 70 | cv::Mat ds, bs; 71 | detection_trees2( model, pyra.padx, pyra.pady, pyra.scales, Xs, Ys, Ls, Cs, Ss, ds, bs ); 72 | clipboxes(pyra.imsize, ds, bs); 73 | bboxpred_get(model,ds,bs); 74 | cv::Mat numb; 75 | clipboxes(pyra.imsize, ds, numb); 76 | /* method 1 */ 77 | cv::Mat dets = nms(ds, 0.5f); 78 | /* method 2 */ 79 | //Mat dets = pDollar_nms( ds, 0.5f ); 80 | 81 | int Cols = dets.cols; 82 | if( Cols!=7 ) 83 | throw runtime_error(""); 84 | Result.resize( dets.rows ); 85 | float *pt = (float*)dets.data; 86 | for( int i=0; i [10 20 110 120] 9 | //% Index end-1 is the component label and index end is the 10 | //% detection score. 11 | //% 12 | //% This function assumes that model is a mixture model where 13 | //% each component always places exactly the same number of filters. 14 | //% 15 | //% Return value 16 | //% b Filter bounding boxes with unused filter columns removed 17 | //% Arguments 18 | //% model Object model 19 | //% bs Filter bounding boxes 20 | { 21 | // Only reduce boxes for mixtures of star models 22 | if(model.type!=model_types_MixStar ) 23 | return; 24 | 25 | int n = model.rules[model.start][0].rhs.size(); 26 | // n*4+2 := 4 coordinates per boxes plus the component index and score as well as level-index 27 | cv::Mat b(bs.rows, n * 4 + 3, bs.type(), cv::Scalar(0)); 28 | 29 | cv::Mat bs_col = bs.col(bs.cols - 3); 30 | double maxc = 0; 31 | minMaxLoc( bs_col, NULL, &maxc ); 32 | cv::Mat bs_int; 33 | bs_col.convertTo( bs_int, CV_32SC1 ); 34 | 35 | for(int idx=1; idx<=(int)maxc; idx++ ){ 36 | vector Ind; 37 | for(int i=0; i(i)==idx ) 39 | Ind.push_back(i); 40 | if(Ind.empty()) 41 | continue; 42 | 43 | cv::Mat tmp(Ind.size(), bs.cols, bs.type()); 44 | for(unsigned i=0; i resv; 48 | for(int j=0; j0 ){ 52 | resv.push_back(j); 53 | resv.push_back(j+1); 54 | resv.push_back(j+2); 55 | resv.push_back(j+3); 56 | } 57 | } 58 | resv.push_back( bs.cols-3 ); 59 | resv.push_back( bs.cols-2 ); 60 | resv.push_back( bs.cols-1 ); 61 | if(resv.size()!=b.cols ) 62 | throw runtime_error(""); 63 | 64 | cv::Mat tmp_resv(Ind.size(), b.cols, b.type()); 65 | for( int i=0; i!=resv.size(); i++ ) 66 | tmp.col( resv[i] ).copyTo( tmp_resv.col(i) ); 67 | 68 | for( int i=0; i!=Ind.size(); i++ ) 69 | tmp_resv.row(i).copyTo( b.row(Ind[i]) ); 70 | } 71 | 72 | bs.create( b.rows, b.cols, bs.type() ); 73 | b.copyTo(bs); 74 | } 75 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/sum_score.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | // add part_score (2X resolution) to root_score by subsampling 4 | 5 | void PM_type::sum_score(cv::Mat &rootScore, const cv::Mat &partScore, int anchorx, int anchory, int padx, int pady) 6 | { 7 | int rRows = rootScore.rows, rCols = rootScore.cols; 8 | int pRows = partScore.rows, pCols = partScore.cols; 9 | 10 | cv::Mat tmp(rRows, rCols, CV_32FC1, cv::Scalar(-FLOAT_INF)); 11 | 12 | float *rpt = (float*)tmp.data; 13 | float *ppt = (float*)partScore.data; 14 | int rstep = tmp.step1(); 15 | int pstep = partScore.step1(); 16 | 17 | int startx = anchorx - padx; 18 | int starty = anchory - pady; 19 | 20 | for(int ry=0; ry=pRows ) 23 | continue; 24 | float *pt1 = rpt + ry*rstep; 25 | float *pt2 = ppt + py*pstep; 26 | for(int rx=0; rx=pCols) 29 | continue; 30 | pt1[rx] = pt2[px]; 31 | } 32 | } 33 | 34 | rootScore = rootScore + tmp; 35 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/yuInd2Sub.cpp: -------------------------------------------------------------------------------- 1 | #include "PM_type.h" 2 | 3 | void PM_type::yuInd2Sub(const int Ind, const int *Sz, int &Row, int &Col, int &Dim) 4 | { 5 | int Area = Sz[0] * Sz[1]; 6 | Dim = Ind / Area; 7 | int Res = Ind - Dim * Area; 8 | Col = Res / Sz[0]; 9 | Row = Res - Col*Sz[0]; 10 | } -------------------------------------------------------------------------------- /UAV-Detect/DPM/source/yuStdDirFiles.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/DPM/source/yuStdDirFiles.cpp -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/boxextractor.h: -------------------------------------------------------------------------------- 1 | #ifndef BOXEXTRACTOR_H 2 | #define BOXEXTRACTOR_H 3 | #include 4 | #include 5 | using namespace std; 6 | using namespace cv; 7 | 8 | 9 | class BoxExtractor { 10 | public: 11 | BoxExtractor(); 12 | Rect extract(Mat img); 13 | Rect extract(const std::string& windowName, Mat img); 14 | 15 | struct handlerT{ 16 | bool isDrawing; 17 | Rect box; 18 | Mat image; 19 | 20 | // initializer list 21 | handlerT() : isDrawing(false) {}; 22 | }params; 23 | 24 | private: 25 | static void mouseHandler(int event, int x, int y, int flags, void *param); 26 | void opencv_mouse_callback(int event, int x, int y, int, void *param); 27 | }; 28 | 29 | #endif // BOXEXTRACTOR_H 30 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/ffttools.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Christian Bailer 3 | Contact address: Christian.Bailer@dfki.de 4 | Department Augmented Vision DFKI 5 | 6 | License Agreement 7 | For Open Source Computer Vision Library 8 | (3-clause BSD License) 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the names of the copyright holders nor the names of the contributors 21 | may be used to endorse or promote products derived from this software 22 | without specific prior written permission. 23 | 24 | This software is provided by the copyright holders and contributors "as is" and 25 | any express or implied warranties, including, but not limited to, the implied 26 | warranties of merchantability and fitness for a particular purpose are disclaimed. 27 | In no event shall copyright holders or contributors be liable for any direct, 28 | indirect, incidental, special, exemplary, or consequential damages 29 | (including, but not limited to, procurement of substitute goods or services; 30 | loss of use, data, or profits; or business interruption) however caused 31 | and on any theory of liability, whether in contract, strict liability, 32 | or tort (including negligence or otherwise) arising in any way out of 33 | the use of this software, even if advised of the possibility of such damage. 34 | */ 35 | 36 | #pragma once 37 | 38 | //#include 39 | 40 | #ifndef _OPENCV_FFTTOOLS_HPP_ 41 | #define _OPENCV_FFTTOOLS_HPP_ 42 | #endif 43 | 44 | //NOTE: FFTW support is still shaky, disabled for now. 45 | /*#ifdef USE_FFTW 46 | #include 47 | #endif*/ 48 | 49 | namespace FFTTools 50 | { 51 | // Previous declarations, to avoid warnings 52 | cv::Mat fftd(cv::Mat img, bool backwards = false); 53 | cv::Mat real(cv::Mat img); 54 | cv::Mat imag(cv::Mat img); 55 | cv::Mat magnitude(cv::Mat img); 56 | cv::Mat complexMultiplication(cv::Mat a, cv::Mat b); 57 | cv::Mat complexDivision(cv::Mat a, cv::Mat b); 58 | void rearrange(cv::Mat &img); 59 | void normalizedLogTransform(cv::Mat &img); 60 | 61 | 62 | cv::Mat fftd(cv::Mat img, bool backwards) 63 | { 64 | /* 65 | #ifdef USE_FFTW 66 | 67 | fftw_complex * fm = (fftw_complex*) fftw_malloc(sizeof (fftw_complex) * img.cols * img.rows); 68 | 69 | fftw_plan p = fftw_plan_dft_2d(img.rows, img.cols, fm, fm, backwards ? 1 : -1, 0 * FFTW_ESTIMATE); 70 | 71 | 72 | if (img.channels() == 1) 73 | { 74 | for (int i = 0; i < img.rows; i++) 75 | for (int j = 0; j < img.cols; j++) 76 | { 77 | fm[i * img.cols + j][0] = img.at(i, j); 78 | fm[i * img.cols + j][1] = 0; 79 | } 80 | } 81 | else 82 | { 83 | assert(img.channels() == 2); 84 | for (int i = 0; i < img.rows; i++) 85 | for (int j = 0; j < img.cols; j++) 86 | { 87 | fm[i * img.cols + j][0] = img.at (i, j)[0]; 88 | fm[i * img.cols + j][1] = img.at (i, j)[1]; 89 | } 90 | } 91 | fftw_execute(p); 92 | cv::Mat res(img.rows, img.cols, CV_64FC2); 93 | 94 | 95 | for (int i = 0; i < img.rows; i++) 96 | for (int j = 0; j < img.cols; j++) 97 | { 98 | res.at (i, j)[0] = fm[i * img.cols + j][0]; 99 | res.at (i, j)[1] = fm[i * img.cols + j][1]; 100 | 101 | // _iout(fm[i * img.cols + j][0]); 102 | } 103 | 104 | if (backwards)res *= 1.d / (float) (res.cols * res.rows); 105 | 106 | fftw_free(p); 107 | fftw_free(fm); 108 | return res; 109 | 110 | #else 111 | */ 112 | if (img.channels() == 1) 113 | { 114 | cv::Mat planes[] = {cv::Mat_ (img), cv::Mat_::zeros(img.size())}; 115 | //cv::Mat planes[] = {cv::Mat_ (img), cv::Mat_::zeros(img.size())}; 116 | cv::merge(planes, 2, img); 117 | } 118 | cv::dft(img, img, backwards ? (cv::DFT_INVERSE | cv::DFT_SCALE) : 0 ); 119 | 120 | return img; 121 | 122 | /*#endif*/ 123 | 124 | } 125 | 126 | cv::Mat real(cv::Mat img) 127 | { 128 | std::vector planes; 129 | cv::split(img, planes); 130 | return planes[0]; 131 | } 132 | 133 | cv::Mat imag(cv::Mat img) 134 | { 135 | std::vector planes; 136 | cv::split(img, planes); 137 | return planes[1]; 138 | } 139 | 140 | cv::Mat magnitude(cv::Mat img) 141 | { 142 | cv::Mat res; 143 | std::vector planes; 144 | cv::split(img, planes); // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I)) 145 | if (planes.size() == 1) res = cv::abs(img); 146 | else if (planes.size() == 2) cv::magnitude(planes[0], planes[1], res); // planes[0] = magnitude 147 | else assert(0); 148 | return res; 149 | } 150 | 151 | cv::Mat complexMultiplication(cv::Mat a, cv::Mat b) 152 | { 153 | std::vector pa; 154 | std::vector pb; 155 | cv::split(a, pa); 156 | cv::split(b, pb); 157 | 158 | std::vector pres; 159 | pres.push_back(pa[0].mul(pb[0]) - pa[1].mul(pb[1])); 160 | pres.push_back(pa[0].mul(pb[1]) + pa[1].mul(pb[0])); 161 | 162 | cv::Mat res; 163 | cv::merge(pres, res); 164 | 165 | return res; 166 | } 167 | 168 | cv::Mat complexDivision(cv::Mat a, cv::Mat b) 169 | { 170 | std::vector pa; 171 | std::vector pb; 172 | cv::split(a, pa); 173 | cv::split(b, pb); 174 | 175 | cv::Mat divisor = 1. / (pb[0].mul(pb[0]) + pb[1].mul(pb[1])); 176 | 177 | std::vector pres; 178 | 179 | pres.push_back((pa[0].mul(pb[0]) + pa[1].mul(pb[1])).mul(divisor)); 180 | pres.push_back((pa[1].mul(pb[0]) + pa[0].mul(pb[1])).mul(divisor)); 181 | 182 | cv::Mat res; 183 | cv::merge(pres, res); 184 | return res; 185 | } 186 | 187 | void rearrange(cv::Mat &img) 188 | { 189 | // img = img(cv::Rect(0, 0, img.cols & -2, img.rows & -2)); 190 | int cx = img.cols / 2; 191 | int cy = img.rows / 2; 192 | 193 | cv::Mat q0(img, cv::Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant 194 | cv::Mat q1(img, cv::Rect(cx, 0, cx, cy)); // Top-Right 195 | cv::Mat q2(img, cv::Rect(0, cy, cx, cy)); // Bottom-Left 196 | cv::Mat q3(img, cv::Rect(cx, cy, cx, cy)); // Bottom-Right 197 | 198 | cv::Mat tmp; // swap quadrants (Top-Left with Bottom-Right) 199 | q0.copyTo(tmp); 200 | q3.copyTo(q0); 201 | tmp.copyTo(q3); 202 | q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left) 203 | q2.copyTo(q1); 204 | tmp.copyTo(q2); 205 | } 206 | /* 207 | template < typename type> 208 | cv::Mat fouriertransFull(const cv::Mat & in) 209 | { 210 | return fftd(in); 211 | 212 | cv::Mat planes[] = {cv::Mat_ (in), cv::Mat_::zeros(in.size())}; 213 | cv::Mat t; 214 | assert(planes[0].depth() == planes[1].depth()); 215 | assert(planes[0].size == planes[1].size); 216 | cv::merge(planes, 2, t); 217 | cv::dft(t, t); 218 | 219 | //cv::normalize(a, a, 0, 1, CV_MINMAX); 220 | //cv::normalize(t, t, 0, 1, CV_MINMAX); 221 | 222 | // cv::imshow("a",real(a)); 223 | // cv::imshow("b",real(t)); 224 | // cv::waitKey(0); 225 | 226 | return t; 227 | }*/ 228 | 229 | void normalizedLogTransform(cv::Mat &img) 230 | { 231 | img = cv::abs(img); 232 | img += cv::Scalar::all(1); 233 | cv::log(img, img); 234 | // cv::normalize(img, img, 0, 1, CV_MINMAX); 235 | } 236 | 237 | } 238 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/fhog.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) 2010-2013, University of Nizhny Novgorod, 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 the copyright holders 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 | //Modified from latentsvm module's "_lsvmc_latentsvm.h". 44 | 45 | 46 | /*****************************************************************************/ 47 | /* Latent SVM prediction API */ 48 | /*****************************************************************************/ 49 | 50 | #ifndef _FHOG_H_ 51 | #define _FHOG_H_ 52 | 53 | #include 54 | //#include "_lsvmc_types.h" 55 | //#include "_lsvmc_error.h" 56 | //#include "_lsvmc_routine.h" 57 | 58 | //#include "opencv2/imgproc.hpp" 59 | #include "opencv2/imgproc/imgproc_c.h" 60 | 61 | 62 | //modified from "_lsvmc_types.h" 63 | 64 | // DataType: STRUCT featureMap 65 | // FEATURE MAP DESCRIPTION 66 | // Rectangular map (sizeX x sizeY), 67 | // every cell stores feature vector (dimension = numFeatures) 68 | // map - matrix of feature vectors 69 | // to set and get feature vectors (i,j) 70 | // used formula map[(j * sizeX + i) * p + k], where 71 | // k - component of feature vector in cell (i, j) 72 | typedef struct{ 73 | int sizeX; 74 | int sizeY; 75 | int numFeatures; 76 | float *map; 77 | } CvLSVMFeatureMapCaskade; 78 | 79 | 80 | #include "float.h" 81 | 82 | #define PI CV_PI 83 | 84 | #define EPS 0.000001 85 | 86 | #define F_MAX FLT_MAX 87 | #define F_MIN -FLT_MAX 88 | 89 | // The number of elements in bin 90 | // The number of sectors in gradient histogram building 91 | #define NUM_SECTOR 9 92 | 93 | // The number of levels in image resize procedure 94 | // We need Lambda levels to resize image twice 95 | #define LAMBDA 10 96 | 97 | // Block size. Used in feature pyramid building procedure 98 | #define SIDE_LENGTH 8 99 | 100 | #define VAL_OF_TRUNCATE 0.2f 101 | 102 | 103 | //modified from "_lsvm_error.h" 104 | #define LATENT_SVM_OK 0 105 | #define LATENT_SVM_MEM_NULL 2 106 | #define DISTANCE_TRANSFORM_OK 1 107 | #define DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR -1 108 | #define DISTANCE_TRANSFORM_ERROR -2 109 | #define DISTANCE_TRANSFORM_EQUAL_POINTS -3 110 | #define LATENT_SVM_GET_FEATURE_PYRAMID_FAILED -4 111 | #define LATENT_SVM_SEARCH_OBJECT_FAILED -5 112 | #define LATENT_SVM_FAILED_SUPERPOSITION -6 113 | #define FILTER_OUT_OF_BOUNDARIES -7 114 | #define LATENT_SVM_TBB_SCHEDULE_CREATION_FAILED -8 115 | #define LATENT_SVM_TBB_NUMTHREADS_NOT_CORRECT -9 116 | #define FFT_OK 2 117 | #define FFT_ERROR -10 118 | #define LSVM_PARSER_FILE_NOT_FOUND -11 119 | 120 | 121 | 122 | /* 123 | // Getting feature map for the selected subimage 124 | // 125 | // API 126 | // int getFeatureMaps(const IplImage * image, const int k, featureMap **map); 127 | // INPUT 128 | // image - selected subimage 129 | // k - size of cells 130 | // OUTPUT 131 | // map - feature map 132 | // RESULT 133 | // Error status 134 | */ 135 | int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMapCaskade **map); 136 | 137 | 138 | /* 139 | // Feature map Normalization and Truncation 140 | // 141 | // API 142 | // int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa); 143 | // INPUT 144 | // map - feature map 145 | // alfa - truncation threshold 146 | // OUTPUT 147 | // map - truncated and normalized feature map 148 | // RESULT 149 | // Error status 150 | */ 151 | int normalizeAndTruncate(CvLSVMFeatureMapCaskade *map, const float alfa); 152 | 153 | /* 154 | // Feature map reduction 155 | // In each cell we reduce dimension of the feature vector 156 | // according to original paper special procedure 157 | // 158 | // API 159 | // int PCAFeatureMaps(featureMap *map) 160 | // INPUT 161 | // map - feature map 162 | // OUTPUT 163 | // map - feature map 164 | // RESULT 165 | // Error status 166 | */ 167 | int PCAFeatureMaps(CvLSVMFeatureMapCaskade *map); 168 | 169 | 170 | //modified from "lsvmc_routine.h" 171 | 172 | int allocFeatureMapObject(CvLSVMFeatureMapCaskade **obj, const int sizeX, const int sizeY, 173 | const int p); 174 | 175 | int freeFeatureMapObject (CvLSVMFeatureMapCaskade **obj); 176 | 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/kcftracker.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Tracker based on Kernelized Correlation Filter (KCF) [1] and Circulant Structure with Kernels (CSK) [2]. 4 | CSK is implemented by using raw gray level features, since it is a single-channel filter. 5 | KCF is implemented by using HOG features (the default), since it extends CSK to multiple channels. 6 | 7 | [1] J. F. Henriques, R. Caseiro, P. Martins, J. Batista, 8 | "High-Speed Tracking with Kernelized Correlation Filters", TPAMI 2015. 9 | 10 | [2] J. F. Henriques, R. Caseiro, P. Martins, J. Batista, 11 | "Exploiting the Circulant Structure of Tracking-by-detection with Kernels", ECCV 2012. 12 | 13 | Authors: Joao Faro, Christian Bailer, Joao F. Henriques 14 | Contacts: joaopfaro@gmail.com, Christian.Bailer@dfki.de, henriques@isr.uc.pt 15 | Institute of Systems and Robotics - University of Coimbra / Department Augmented Vision DFKI 16 | 17 | 18 | Constructor parameters, all boolean: 19 | hog: use HOG features (default), otherwise use raw pixels 20 | fixed_window: fix window size (default), otherwise use ROI size (slower but more accurate) 21 | multiscale: use multi-scale tracking (default; cannot be used with fixed_window = true) 22 | 23 | Default values are set for all properties of the tracker depending on the above choices. 24 | Their values can be customized further before calling init(): 25 | interp_factor: linear interpolation factor for adaptation 26 | sigma: gaussian kernel bandwidth 27 | lambda: regularization 28 | cell_size: HOG cell size 29 | padding: horizontal area surrounding the target, relative to its size 30 | output_sigma_factor: bandwidth of gaussian target 31 | template_size: template size in pixels, 0 to use ROI size 32 | scale_step: scale step for multi-scale estimation, 1 to disable it 33 | scale_weight: to downweight detection scores of other scales for added stability 34 | 35 | For speed, the value (template_size/cell_size) should be a power of 2 or a product of small prime numbers. 36 | 37 | Inputs to init(): 38 | image is the initial frame. 39 | roi is a cv::Rect with the target positions in the initial frame 40 | 41 | Inputs to update(): 42 | image is the current frame. 43 | 44 | Outputs of update(): 45 | cv::Rect with target positions for the current frame 46 | 47 | 48 | By downloading, copying, installing or using the software you agree to this license. 49 | If you do not agree to this license, do not download, install, 50 | copy or use the software. 51 | 52 | 53 | License Agreement 54 | For Open Source Computer Vision Library 55 | (3-clause BSD License) 56 | 57 | Redistribution and use in source and binary forms, with or without modification, 58 | are permitted provided that the following conditions are met: 59 | 60 | * Redistributions of source code must retain the above copyright notice, 61 | this list of conditions and the following disclaimer. 62 | 63 | * Redistributions in binary form must reproduce the above copyright notice, 64 | this list of conditions and the following disclaimer in the documentation 65 | and/or other materials provided with the distribution. 66 | 67 | * Neither the names of the copyright holders nor the names of the contributors 68 | may be used to endorse or promote products derived from this software 69 | without specific prior written permission. 70 | 71 | This software is provided by the copyright holders and contributors "as is" and 72 | any express or implied warranties, including, but not limited to, the implied 73 | warranties of merchantability and fitness for a particular purpose are disclaimed. 74 | In no event shall copyright holders or contributors be liable for any direct, 75 | indirect, incidental, special, exemplary, or consequential damages 76 | (including, but not limited to, procurement of substitute goods or services; 77 | loss of use, data, or profits; or business interruption) however caused 78 | and on any theory of liability, whether in contract, strict liability, 79 | or tort (including negligence or otherwise) arising in any way out of 80 | the use of this software, even if advised of the possibility of such damage. 81 | */ 82 | 83 | #pragma once 84 | 85 | #include "tracker.h" 86 | 87 | #ifndef _OPENCV_KCFTRACKER_HPP_ 88 | #define _OPENCV_KCFTRACKER_HPP_ 89 | #endif 90 | 91 | class KCFTracker : public Tracker 92 | { 93 | public: 94 | // Constructor 95 | KCFTracker(bool hog = true, bool fixed_window = true, bool multiscale = true, bool lab = true); 96 | 97 | // Initialize tracker 98 | virtual void init(const cv::Rect &roi, cv::Mat image); 99 | 100 | // Update position based on the new frame 101 | virtual cv::Rect update(cv::Mat image); 102 | 103 | float interp_factor; // linear interpolation factor for adaptation 104 | float sigma; // gaussian kernel bandwidth 105 | float lambda; // regularization 106 | int cell_size; // HOG cell size 107 | int cell_sizeQ; // cell size^2, to avoid repeated operations 108 | float padding; // extra area surrounding the target 109 | float output_sigma_factor; // bandwidth of gaussian target 110 | int template_size; // template size 111 | float scale_step; // scale step for multi-scale estimation 112 | float scale_weight; // to downweight detection scores of other scales for added stability 113 | 114 | protected: 115 | // Detect object in the current frame. 116 | cv::Point2f detect(cv::Mat z, cv::Mat x, float &peak_value); 117 | 118 | // train tracker with a single image 119 | void train(cv::Mat x, float train_interp_factor); 120 | 121 | // Evaluates a Gaussian kernel with bandwidth SIGMA for all relative shifts between input images X and Y, which must both be MxN. They must also be periodic (ie., pre-processed with a cosine window). 122 | cv::Mat gaussianCorrelation(cv::Mat x1, cv::Mat x2); 123 | 124 | // Create Gaussian Peak. Function called only in the first frame. 125 | cv::Mat createGaussianPeak(int sizey, int sizex); 126 | 127 | // Obtain sub-window from image, with replication-padding and extract features 128 | cv::Mat getFeatures(const cv::Mat & image, bool inithann, float scale_adjust = 1.0f); 129 | 130 | // Initialize Hanning window. Function called only in the first frame. 131 | bool createHanningMats(); 132 | 133 | // Calculate sub-pixel peak for one dimension 134 | float subPixelPeak(float left, float center, float right); 135 | 136 | cv::Mat _alphaf; 137 | cv::Mat _prob; 138 | cv::Mat _tmpl; 139 | cv::Mat _num; 140 | cv::Mat _den; 141 | cv::Mat _labCentroids; 142 | 143 | private: 144 | int size_patch[3]; 145 | cv::Mat hann; 146 | cv::Size _tmpl_sz; 147 | float _scale; 148 | int _gaussian_size; 149 | bool _hogfeatures; 150 | bool _labfeatures; 151 | }; 152 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/labdata.hpp: -------------------------------------------------------------------------------- 1 | const int nClusters = 15; 2 | float data[nClusters][3] = { 3 | {161.317504, 127.223401, 128.609333}, 4 | {142.922425, 128.666965, 127.532319}, 5 | {67.879757, 127.721830, 135.903311}, 6 | {92.705062, 129.965717, 137.399500}, 7 | {120.172257, 128.279647, 127.036493}, 8 | {195.470568, 127.857070, 129.345415}, 9 | {41.257102, 130.059468, 132.675336}, 10 | {12.014861, 129.480555, 127.064714}, 11 | {226.567086, 127.567831, 136.345727}, 12 | {154.664210, 131.676606, 156.481669}, 13 | {121.180447, 137.020793, 153.433743}, 14 | {87.042204, 137.211742, 98.614874}, 15 | {113.809537, 106.577104, 157.818094}, 16 | {81.083293, 170.051905, 148.904079}, 17 | {45.015485, 138.543124, 102.402528} 18 | }; -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/recttools.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Christian Bailer 3 | Contact address: Christian.Bailer@dfki.de 4 | Department Augmented Vision DFKI 5 | 6 | License Agreement 7 | For Open Source Computer Vision Library 8 | (3-clause BSD License) 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | * Neither the names of the copyright holders nor the names of the contributors 21 | may be used to endorse or promote products derived from this software 22 | without specific prior written permission. 23 | 24 | This software is provided by the copyright holders and contributors "as is" and 25 | any express or implied warranties, including, but not limited to, the implied 26 | warranties of merchantability and fitness for a particular purpose are disclaimed. 27 | In no event shall copyright holders or contributors be liable for any direct, 28 | indirect, incidental, special, exemplary, or consequential damages 29 | (including, but not limited to, procurement of substitute goods or services; 30 | loss of use, data, or profits; or business interruption) however caused 31 | and on any theory of liability, whether in contract, strict liability, 32 | or tort (including negligence or otherwise) arising in any way out of 33 | the use of this software, even if advised of the possibility of such damage. 34 | */ 35 | 36 | #pragma once 37 | 38 | //#include 39 | #include 40 | 41 | #ifndef _OPENCV_RECTTOOLS_HPP_ 42 | #define _OPENCV_RECTTOOLS_HPP_ 43 | #endif 44 | 45 | namespace RectTools 46 | { 47 | 48 | template 49 | inline cv::Vec center(const cv::Rect_ &rect) 50 | { 51 | return cv::Vec (rect.x + rect.width / (t) 2, rect.y + rect.height / (t) 2); 52 | } 53 | 54 | template 55 | inline t x2(const cv::Rect_ &rect) 56 | { 57 | return rect.x + rect.width; 58 | } 59 | 60 | template 61 | inline t y2(const cv::Rect_ &rect) 62 | { 63 | return rect.y + rect.height; 64 | } 65 | 66 | template 67 | inline void resize(cv::Rect_ &rect, float scalex, float scaley = 0) 68 | { 69 | if (!scaley)scaley = scalex; 70 | rect.x -= rect.width * (scalex - 1.f) / 2.f; 71 | rect.width *= scalex; 72 | 73 | rect.y -= rect.height * (scaley - 1.f) / 2.f; 74 | rect.height *= scaley; 75 | 76 | } 77 | 78 | template 79 | inline void limit(cv::Rect_ &rect, cv::Rect_ limit) 80 | { 81 | if (rect.x + rect.width > limit.x + limit.width)rect.width = (limit.x + limit.width - rect.x); 82 | if (rect.y + rect.height > limit.y + limit.height)rect.height = (limit.y + limit.height - rect.y); 83 | if (rect.x < limit.x) 84 | { 85 | rect.width -= (limit.x - rect.x); 86 | rect.x = limit.x; 87 | } 88 | if (rect.y < limit.y) 89 | { 90 | rect.height -= (limit.y - rect.y); 91 | rect.y = limit.y; 92 | } 93 | if(rect.width<0)rect.width=0; 94 | if(rect.height<0)rect.height=0; 95 | } 96 | 97 | template 98 | inline void limit(cv::Rect_ &rect, t width, t height, t x = 0, t y = 0) 99 | { 100 | limit(rect, cv::Rect_ (x, y, width, height)); 101 | } 102 | 103 | template 104 | inline cv::Rect getBorder(const cv::Rect_ &original, cv::Rect_ & limited) 105 | { 106 | cv::Rect_ res; 107 | res.x = limited.x - original.x; 108 | res.y = limited.y - original.y; 109 | res.width = x2(original) - x2(limited); 110 | res.height = y2(original) - y2(limited); 111 | assert(res.x >= 0 && res.y >= 0 && res.width >= 0 && res.height >= 0); 112 | return res; 113 | } 114 | 115 | inline cv::Mat subwindow(const cv::Mat &in, const cv::Rect & window, int borderType = cv::BORDER_CONSTANT) 116 | { 117 | cv::Rect cutWindow = window; 118 | RectTools::limit(cutWindow, in.cols, in.rows); 119 | if (cutWindow.height <= 0 || cutWindow.width <= 0)assert(0); //return cv::Mat(window.height,window.width,in.type(),0) ; 120 | cv::Rect border = RectTools::getBorder(window, cutWindow); 121 | cv::Mat res = in(cutWindow); 122 | 123 | if (border != cv::Rect(0, 0, 0, 0)) 124 | { 125 | cv::copyMakeBorder(res, res, border.y, border.height, border.x, border.width, borderType); 126 | } 127 | return res; 128 | } 129 | 130 | inline cv::Mat getGrayImage(cv::Mat img) 131 | { 132 | cv::cvtColor(img, img, CV_BGR2GRAY); 133 | img.convertTo(img, CV_32F, 1 / 255.f); 134 | return img; 135 | } 136 | 137 | } 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/include/tracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: BasicTracker.h 3 | * Author: Joao F. Henriques, Joao Faro, Christian Bailer 4 | * Contact address: henriques@isr.uc.pt, joaopfaro@gmail.com, Christian.Bailer@dfki.de 5 | * Instute of Systems and Robotics- University of COimbra / Department Augmented Vision DFKI 6 | * 7 | * This source code is provided for for research purposes only. For a commercial license or a different use case please contact us. 8 | * You are not allowed to publish the unmodified sourcecode on your own e.g. on your webpage. Please refer to the official download page instead. 9 | * If you want to publish a modified/extended version e.g. because you wrote a publication with a modified version of the sourcecode you need our 10 | * permission (Please contact us for the permission). 11 | * 12 | * We reserve the right to change the license of this sourcecode anytime to BSD, GPL or LGPL. 13 | * By using the sourcecode you agree to possible restrictions and requirements of these three license models so that the license can be changed 14 | * anytime without you knowledge. 15 | */ 16 | 17 | 18 | 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | class Tracker 25 | { 26 | public: 27 | Tracker() {} 28 | virtual ~Tracker() { } 29 | 30 | virtual void init(const cv::Rect &roi, cv::Mat image) = 0; 31 | virtual cv::Rect update( cv::Mat image)=0; 32 | 33 | 34 | protected: 35 | cv::Rect_ _roi; 36 | }; 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/source/boxextractor.cpp: -------------------------------------------------------------------------------- 1 | #include "boxextractor.h" 2 | #include 3 | #include 4 | BoxExtractor::BoxExtractor() 5 | { 6 | } 7 | 8 | void BoxExtractor::mouseHandler(int event, int x, int y, int flags, void *param){ 9 | BoxExtractor *self = static_cast(param); 10 | self->opencv_mouse_callback(event, x, y, flags, param); 11 | } 12 | 13 | void BoxExtractor::opencv_mouse_callback(int event, int x, int y, int, void *param){ 14 | handlerT * data = (handlerT*)param; 15 | switch (event){ 16 | // update the selected bounding box 17 | case EVENT_MOUSEMOVE: 18 | if (data->isDrawing){ 19 | data->box.width = x - data->box.x; 20 | data->box.height = y - data->box.y; 21 | } 22 | break; 23 | 24 | // start to select the bounding box 25 | case EVENT_LBUTTONDOWN: 26 | data->isDrawing = true; 27 | data->box = cvRect(x, y, 0, 0); 28 | break; 29 | 30 | // cleaning up the selected bounding box 31 | case EVENT_LBUTTONUP: 32 | data->isDrawing = false; 33 | if (data->box.width < 0){ 34 | data->box.x += data->box.width; 35 | data->box.width *= -1; 36 | } 37 | if (data->box.height < 0){ 38 | data->box.y += data->box.height; 39 | data->box.height *= -1; 40 | } 41 | break; 42 | } 43 | } 44 | 45 | Rect BoxExtractor::extract(Mat img){ 46 | return extract("Bounding Box Extractor", img); 47 | } 48 | 49 | Rect BoxExtractor::extract(const std::string& windowName, Mat img){ 50 | 51 | int key = 0; 52 | 53 | // show the image and give feedback to user 54 | //imshow(windowName, img); 55 | //printf("Select an object to track and then press SPACE/BACKSPACE/ENTER button!\n"); 56 | 57 | // copy the data, rectangle should be drawn in the fresh image 58 | params.image = img.clone(); 59 | 60 | // select the object 61 | setMouseCallback(windowName, mouseHandler, (void *)¶ms); 62 | 63 | 64 | // draw the selected object 65 | rectangle( 66 | params.image, 67 | params.box, 68 | Scalar(255, 0, 0), 2, 1 69 | ); 70 | 71 | // show the image bouding box 72 | imshow(windowName, params.image); 73 | 74 | // reset the image 75 | params.image = img.clone(); 76 | 77 | //get keyboard event 78 | 79 | 80 | 81 | return params.box; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/source/fhog.cpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, University of Nizhny Novgorod, 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 the copyright holders 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 | //Modified from latentsvm module's "lsvmc_featurepyramid.cpp". 44 | 45 | //#include "precomp.hpp" 46 | //#include "_lsvmc_latentsvm.h" 47 | //#include "_lsvmc_resizeimg.h" 48 | 49 | #include "fhog.hpp" 50 | 51 | 52 | #ifdef HAVE_TBB 53 | #include "tbb.h" 54 | #include "parallel_for.h" 55 | #include "blocked_range.h" 56 | #endif 57 | 58 | #ifndef max 59 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 60 | #endif 61 | 62 | #ifndef min 63 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 64 | #endif 65 | 66 | 67 | /* 68 | // Getting feature map for the selected subimage 69 | // 70 | // API 71 | // int getFeatureMaps(const IplImage * image, const int k, featureMap **map); 72 | // INPUT 73 | // image - selected subimage 74 | // k - size of cells 75 | // OUTPUT 76 | // map - feature map 77 | // RESULT 78 | // Error status 79 | */ 80 | int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMapCaskade **map) 81 | { 82 | int sizeX, sizeY; 83 | int p, px, stringSize; 84 | int height, width, numChannels; 85 | int i, j, kk, c, ii, jj, d; 86 | float * datadx, * datady; 87 | 88 | int ch; 89 | float magnitude, x, y, tx, ty; 90 | 91 | IplImage * dx, * dy; 92 | int *nearest; 93 | float *w, a_x, b_x; 94 | 95 | float kernel[3] = {-1.f, 0.f, 1.f}; 96 | CvMat kernel_dx = cvMat(1, 3, CV_32F, kernel); 97 | CvMat kernel_dy = cvMat(3, 1, CV_32F, kernel); 98 | 99 | float * r; 100 | int * alfa; 101 | 102 | float boundary_x[NUM_SECTOR + 1]; 103 | float boundary_y[NUM_SECTOR + 1]; 104 | float max, dotProd; 105 | int maxi; 106 | 107 | height = image->height; 108 | width = image->width ; 109 | 110 | numChannels = image->nChannels; 111 | 112 | dx = cvCreateImage(cvSize(image->width, image->height), 113 | IPL_DEPTH_32F, 3); 114 | dy = cvCreateImage(cvSize(image->width, image->height), 115 | IPL_DEPTH_32F, 3); 116 | 117 | sizeX = width / k; 118 | sizeY = height / k; 119 | px = 3 * NUM_SECTOR; 120 | p = px; 121 | stringSize = sizeX * p; 122 | allocFeatureMapObject(map, sizeX, sizeY, p); 123 | 124 | cvFilter2D(image, dx, &kernel_dx, cvPoint(-1, 0)); 125 | cvFilter2D(image, dy, &kernel_dy, cvPoint(0, -1)); 126 | 127 | float arg_vector; 128 | for(i = 0; i <= NUM_SECTOR; i++) 129 | { 130 | arg_vector = ( (float) i ) * ( (float)(PI) / (float)(NUM_SECTOR) ); 131 | boundary_x[i] = cosf(arg_vector); 132 | boundary_y[i] = sinf(arg_vector); 133 | }/*for(i = 0; i <= NUM_SECTOR; i++) */ 134 | 135 | r = (float *)malloc( sizeof(float) * (width * height)); 136 | alfa = (int *)malloc( sizeof(int ) * (width * height * 2)); 137 | 138 | for(j = 1; j < height - 1; j++) 139 | { 140 | datadx = (float*)(dx->imageData + dx->widthStep * j); 141 | datady = (float*)(dy->imageData + dy->widthStep * j); 142 | for(i = 1; i < width - 1; i++) 143 | { 144 | c = 0; 145 | x = (datadx[i * numChannels + c]); 146 | y = (datady[i * numChannels + c]); 147 | 148 | r[j * width + i] =sqrtf(x * x + y * y); 149 | for(ch = 1; ch < numChannels; ch++) 150 | { 151 | tx = (datadx[i * numChannels + ch]); 152 | ty = (datady[i * numChannels + ch]); 153 | magnitude = sqrtf(tx * tx + ty * ty); 154 | if(magnitude > r[j * width + i]) 155 | { 156 | r[j * width + i] = magnitude; 157 | c = ch; 158 | x = tx; 159 | y = ty; 160 | } 161 | }/*for(ch = 1; ch < numChannels; ch++)*/ 162 | 163 | max = boundary_x[0] * x + boundary_y[0] * y; 164 | maxi = 0; 165 | for (kk = 0; kk < NUM_SECTOR; kk++) 166 | { 167 | dotProd = boundary_x[kk] * x + boundary_y[kk] * y; 168 | if (dotProd > max) 169 | { 170 | max = dotProd; 171 | maxi = kk; 172 | } 173 | else 174 | { 175 | if (-dotProd > max) 176 | { 177 | max = -dotProd; 178 | maxi = kk + NUM_SECTOR; 179 | } 180 | } 181 | } 182 | alfa[j * width * 2 + i * 2 ] = maxi % NUM_SECTOR; 183 | alfa[j * width * 2 + i * 2 + 1] = maxi; 184 | }/*for(i = 0; i < width; i++)*/ 185 | }/*for(j = 0; j < height; j++)*/ 186 | 187 | nearest = (int *)malloc(sizeof(int ) * k); 188 | w = (float*)malloc(sizeof(float) * (k * 2)); 189 | 190 | for(i = 0; i < k / 2; i++) 191 | { 192 | nearest[i] = -1; 193 | }/*for(i = 0; i < k / 2; i++)*/ 194 | for(i = k / 2; i < k; i++) 195 | { 196 | nearest[i] = 1; 197 | }/*for(i = k / 2; i < k; i++)*/ 198 | 199 | for(j = 0; j < k / 2; j++) 200 | { 201 | b_x = k / 2 + j + 0.5f; 202 | a_x = k / 2 - j - 0.5f; 203 | w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x)); 204 | w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x)); 205 | }/*for(j = 0; j < k / 2; j++)*/ 206 | for(j = k / 2; j < k; j++) 207 | { 208 | a_x = j - k / 2 + 0.5f; 209 | b_x =-j + k / 2 - 0.5f + k; 210 | w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x)); 211 | w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x)); 212 | }/*for(j = k / 2; j < k; j++)*/ 213 | 214 | for(i = 0; i < sizeY; i++) 215 | { 216 | for(j = 0; j < sizeX; j++) 217 | { 218 | for(ii = 0; ii < k; ii++) 219 | { 220 | for(jj = 0; jj < k; jj++) 221 | { 222 | if ((i * k + ii > 0) && 223 | (i * k + ii < height - 1) && 224 | (j * k + jj > 0) && 225 | (j * k + jj < width - 1)) 226 | { 227 | d = (k * i + ii) * width + (j * k + jj); 228 | (*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 ]] += 229 | r[d] * w[ii * 2] * w[jj * 2]; 230 | (*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += 231 | r[d] * w[ii * 2] * w[jj * 2]; 232 | if ((i + nearest[ii] >= 0) && 233 | (i + nearest[ii] <= sizeY - 1)) 234 | { 235 | (*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 ] ] += 236 | r[d] * w[ii * 2 + 1] * w[jj * 2 ]; 237 | (*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += 238 | r[d] * w[ii * 2 + 1] * w[jj * 2 ]; 239 | } 240 | if ((j + nearest[jj] >= 0) && 241 | (j + nearest[jj] <= sizeX - 1)) 242 | { 243 | (*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] += 244 | r[d] * w[ii * 2] * w[jj * 2 + 1]; 245 | (*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += 246 | r[d] * w[ii * 2] * w[jj * 2 + 1]; 247 | } 248 | if ((i + nearest[ii] >= 0) && 249 | (i + nearest[ii] <= sizeY - 1) && 250 | (j + nearest[jj] >= 0) && 251 | (j + nearest[jj] <= sizeX - 1)) 252 | { 253 | (*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] += 254 | r[d] * w[ii * 2 + 1] * w[jj * 2 + 1]; 255 | (*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] += 256 | r[d] * w[ii * 2 + 1] * w[jj * 2 + 1]; 257 | } 258 | } 259 | }/*for(jj = 0; jj < k; jj++)*/ 260 | }/*for(ii = 0; ii < k; ii++)*/ 261 | }/*for(j = 1; j < sizeX - 1; j++)*/ 262 | }/*for(i = 1; i < sizeY - 1; i++)*/ 263 | 264 | cvReleaseImage(&dx); 265 | cvReleaseImage(&dy); 266 | 267 | 268 | free(w); 269 | free(nearest); 270 | 271 | free(r); 272 | free(alfa); 273 | 274 | return LATENT_SVM_OK; 275 | } 276 | 277 | /* 278 | // Feature map Normalization and Truncation 279 | // 280 | // API 281 | // int normalizeAndTruncate(featureMap *map, const float alfa); 282 | // INPUT 283 | // map - feature map 284 | // alfa - truncation threshold 285 | // OUTPUT 286 | // map - truncated and normalized feature map 287 | // RESULT 288 | // Error status 289 | */ 290 | int normalizeAndTruncate(CvLSVMFeatureMapCaskade *map, const float alfa) 291 | { 292 | int i,j, ii; 293 | int sizeX, sizeY, p, pos, pp, xp, pos1, pos2; 294 | float * partOfNorm; // norm of C(i, j) 295 | float * newData; 296 | float valOfNorm; 297 | 298 | sizeX = map->sizeX; 299 | sizeY = map->sizeY; 300 | partOfNorm = (float *)malloc (sizeof(float) * (sizeX * sizeY)); 301 | 302 | p = NUM_SECTOR; 303 | xp = NUM_SECTOR * 3; 304 | pp = NUM_SECTOR * 12; 305 | 306 | for(i = 0; i < sizeX * sizeY; i++) 307 | { 308 | valOfNorm = 0.0f; 309 | pos = i * map->numFeatures; 310 | for(j = 0; j < p; j++) 311 | { 312 | valOfNorm += map->map[pos + j] * map->map[pos + j]; 313 | }/*for(j = 0; j < p; j++)*/ 314 | partOfNorm[i] = valOfNorm; 315 | }/*for(i = 0; i < sizeX * sizeY; i++)*/ 316 | 317 | sizeX -= 2; 318 | sizeY -= 2; 319 | 320 | newData = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp)); 321 | //normalization 322 | for(i = 1; i <= sizeY; i++) 323 | { 324 | for(j = 1; j <= sizeX; j++) 325 | { 326 | valOfNorm = sqrtf( 327 | partOfNorm[(i )*(sizeX + 2) + (j )] + 328 | partOfNorm[(i )*(sizeX + 2) + (j + 1)] + 329 | partOfNorm[(i + 1)*(sizeX + 2) + (j )] + 330 | partOfNorm[(i + 1)*(sizeX + 2) + (j + 1)]) + FLT_EPSILON; 331 | pos1 = (i ) * (sizeX + 2) * xp + (j ) * xp; 332 | pos2 = (i-1) * (sizeX ) * pp + (j-1) * pp; 333 | for(ii = 0; ii < p; ii++) 334 | { 335 | newData[pos2 + ii ] = map->map[pos1 + ii ] / valOfNorm; 336 | }/*for(ii = 0; ii < p; ii++)*/ 337 | for(ii = 0; ii < 2 * p; ii++) 338 | { 339 | newData[pos2 + ii + p * 4] = map->map[pos1 + ii + p] / valOfNorm; 340 | }/*for(ii = 0; ii < 2 * p; ii++)*/ 341 | valOfNorm = sqrtf( 342 | partOfNorm[(i )*(sizeX + 2) + (j )] + 343 | partOfNorm[(i )*(sizeX + 2) + (j + 1)] + 344 | partOfNorm[(i - 1)*(sizeX + 2) + (j )] + 345 | partOfNorm[(i - 1)*(sizeX + 2) + (j + 1)]) + FLT_EPSILON; 346 | for(ii = 0; ii < p; ii++) 347 | { 348 | newData[pos2 + ii + p ] = map->map[pos1 + ii ] / valOfNorm; 349 | }/*for(ii = 0; ii < p; ii++)*/ 350 | for(ii = 0; ii < 2 * p; ii++) 351 | { 352 | newData[pos2 + ii + p * 6] = map->map[pos1 + ii + p] / valOfNorm; 353 | }/*for(ii = 0; ii < 2 * p; ii++)*/ 354 | valOfNorm = sqrtf( 355 | partOfNorm[(i )*(sizeX + 2) + (j )] + 356 | partOfNorm[(i )*(sizeX + 2) + (j - 1)] + 357 | partOfNorm[(i + 1)*(sizeX + 2) + (j )] + 358 | partOfNorm[(i + 1)*(sizeX + 2) + (j - 1)]) + FLT_EPSILON; 359 | for(ii = 0; ii < p; ii++) 360 | { 361 | newData[pos2 + ii + p * 2] = map->map[pos1 + ii ] / valOfNorm; 362 | }/*for(ii = 0; ii < p; ii++)*/ 363 | for(ii = 0; ii < 2 * p; ii++) 364 | { 365 | newData[pos2 + ii + p * 8] = map->map[pos1 + ii + p] / valOfNorm; 366 | }/*for(ii = 0; ii < 2 * p; ii++)*/ 367 | valOfNorm = sqrtf( 368 | partOfNorm[(i )*(sizeX + 2) + (j )] + 369 | partOfNorm[(i )*(sizeX + 2) + (j - 1)] + 370 | partOfNorm[(i - 1)*(sizeX + 2) + (j )] + 371 | partOfNorm[(i - 1)*(sizeX + 2) + (j - 1)]) + FLT_EPSILON; 372 | for(ii = 0; ii < p; ii++) 373 | { 374 | newData[pos2 + ii + p * 3 ] = map->map[pos1 + ii ] / valOfNorm; 375 | }/*for(ii = 0; ii < p; ii++)*/ 376 | for(ii = 0; ii < 2 * p; ii++) 377 | { 378 | newData[pos2 + ii + p * 10] = map->map[pos1 + ii + p] / valOfNorm; 379 | }/*for(ii = 0; ii < 2 * p; ii++)*/ 380 | }/*for(j = 1; j <= sizeX; j++)*/ 381 | }/*for(i = 1; i <= sizeY; i++)*/ 382 | //truncation 383 | for(i = 0; i < sizeX * sizeY * pp; i++) 384 | { 385 | if(newData [i] > alfa) newData [i] = alfa; 386 | }/*for(i = 0; i < sizeX * sizeY * pp; i++)*/ 387 | //swop data 388 | 389 | map->numFeatures = pp; 390 | map->sizeX = sizeX; 391 | map->sizeY = sizeY; 392 | 393 | free (map->map); 394 | free (partOfNorm); 395 | 396 | map->map = newData; 397 | 398 | return LATENT_SVM_OK; 399 | } 400 | /* 401 | // Feature map reduction 402 | // In each cell we reduce dimension of the feature vector 403 | // according to original paper special procedure 404 | // 405 | // API 406 | // int PCAFeatureMaps(featureMap *map) 407 | // INPUT 408 | // map - feature map 409 | // OUTPUT 410 | // map - feature map 411 | // RESULT 412 | // Error status 413 | */ 414 | int PCAFeatureMaps(CvLSVMFeatureMapCaskade *map) 415 | { 416 | int i,j, ii, jj, k; 417 | int sizeX, sizeY, p, pp, xp, yp, pos1, pos2; 418 | float * newData; 419 | float val; 420 | float nx, ny; 421 | 422 | sizeX = map->sizeX; 423 | sizeY = map->sizeY; 424 | p = map->numFeatures; 425 | pp = NUM_SECTOR * 3 + 4; 426 | yp = 4; 427 | xp = NUM_SECTOR; 428 | 429 | nx = 1.0f / sqrtf((float)(xp * 2)); 430 | ny = 1.0f / sqrtf((float)(yp )); 431 | 432 | newData = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp)); 433 | 434 | for(i = 0; i < sizeY; i++) 435 | { 436 | for(j = 0; j < sizeX; j++) 437 | { 438 | pos1 = ((i)*sizeX + j)*p; 439 | pos2 = ((i)*sizeX + j)*pp; 440 | k = 0; 441 | for(jj = 0; jj < xp * 2; jj++) 442 | { 443 | val = 0; 444 | for(ii = 0; ii < yp; ii++) 445 | { 446 | val += map->map[pos1 + yp * xp + ii * xp * 2 + jj]; 447 | }/*for(ii = 0; ii < yp; ii++)*/ 448 | newData[pos2 + k] = val * ny; 449 | k++; 450 | }/*for(jj = 0; jj < xp * 2; jj++)*/ 451 | for(jj = 0; jj < xp; jj++) 452 | { 453 | val = 0; 454 | for(ii = 0; ii < yp; ii++) 455 | { 456 | val += map->map[pos1 + ii * xp + jj]; 457 | }/*for(ii = 0; ii < yp; ii++)*/ 458 | newData[pos2 + k] = val * ny; 459 | k++; 460 | }/*for(jj = 0; jj < xp; jj++)*/ 461 | for(ii = 0; ii < yp; ii++) 462 | { 463 | val = 0; 464 | for(jj = 0; jj < 2 * xp; jj++) 465 | { 466 | val += map->map[pos1 + yp * xp + ii * xp * 2 + jj]; 467 | }/*for(jj = 0; jj < xp; jj++)*/ 468 | newData[pos2 + k] = val * nx; 469 | k++; 470 | } /*for(ii = 0; ii < yp; ii++)*/ 471 | }/*for(j = 0; j < sizeX; j++)*/ 472 | }/*for(i = 0; i < sizeY; i++)*/ 473 | //swop data 474 | 475 | map->numFeatures = pp; 476 | 477 | free (map->map); 478 | 479 | map->map = newData; 480 | 481 | return LATENT_SVM_OK; 482 | } 483 | 484 | 485 | //modified from "lsvmc_routine.cpp" 486 | 487 | int allocFeatureMapObject(CvLSVMFeatureMapCaskade **obj, const int sizeX, 488 | const int sizeY, const int numFeatures) 489 | { 490 | int i; 491 | (*obj) = (CvLSVMFeatureMapCaskade *)malloc(sizeof(CvLSVMFeatureMapCaskade)); 492 | (*obj)->sizeX = sizeX; 493 | (*obj)->sizeY = sizeY; 494 | (*obj)->numFeatures = numFeatures; 495 | (*obj)->map = (float *) malloc(sizeof (float) * 496 | (sizeX * sizeY * numFeatures)); 497 | for(i = 0; i < sizeX * sizeY * numFeatures; i++) 498 | { 499 | (*obj)->map[i] = 0.0f; 500 | } 501 | return LATENT_SVM_OK; 502 | } 503 | 504 | int freeFeatureMapObject (CvLSVMFeatureMapCaskade **obj) 505 | { 506 | if(*obj == NULL) return LATENT_SVM_MEM_NULL; 507 | free((*obj)->map); 508 | free(*obj); 509 | (*obj) = NULL; 510 | return LATENT_SVM_OK; 511 | } 512 | -------------------------------------------------------------------------------- /UAV-Detect/KCF/source/kcftracker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Tracker based on Kernelized Correlation Filter (KCF) [1] and Circulant Structure with Kernels (CSK) [2]. 4 | CSK is implemented by using raw gray level features, since it is a single-channel filter. 5 | KCF is implemented by using HOG features (the default), since it extends CSK to multiple channels. 6 | 7 | [1] J. F. Henriques, R. Caseiro, P. Martins, J. Batista, 8 | "High-Speed Tracking with Kernelized Correlation Filters", TPAMI 2015. 9 | 10 | [2] J. F. Henriques, R. Caseiro, P. Martins, J. Batista, 11 | "Exploiting the Circulant Structure of Tracking-by-detection with Kernels", ECCV 2012. 12 | 13 | Authors: Joao Faro, Christian Bailer, Joao F. Henriques 14 | Contacts: joaopfaro@gmail.com, Christian.Bailer@dfki.de, henriques@isr.uc.pt 15 | Institute of Systems and Robotics - University of Coimbra / Department Augmented Vision DFKI 16 | 17 | 18 | Constructor parameters, all boolean: 19 | hog: use HOG features (default), otherwise use raw pixels 20 | fixed_window: fix window size (default), otherwise use ROI size (slower but more accurate) 21 | multiscale: use multi-scale tracking (default; cannot be used with fixed_window = true) 22 | 23 | Default values are set for all properties of the tracker depending on the above choices. 24 | Their values can be customized further before calling init(): 25 | interp_factor: linear interpolation factor for adaptation 26 | sigma: gaussian kernel bandwidth 27 | lambda: regularization 28 | cell_size: HOG cell size 29 | padding: area surrounding the target, relative to its size 30 | output_sigma_factor: bandwidth of gaussian target 31 | template_size: template size in pixels, 0 to use ROI size 32 | scale_step: scale step for multi-scale estimation, 1 to disable it 33 | scale_weight: to downweight detection scores of other scales for added stability 34 | 35 | For speed, the value (template_size/cell_size) should be a power of 2 or a product of small prime numbers. 36 | 37 | Inputs to init(): 38 | image is the initial frame. 39 | roi is a cv::Rect with the target positions in the initial frame 40 | 41 | Inputs to update(): 42 | image is the current frame. 43 | 44 | Outputs of update(): 45 | cv::Rect with target positions for the current frame 46 | 47 | 48 | By downloading, copying, installing or using the software you agree to this license. 49 | If you do not agree to this license, do not download, install, 50 | copy or use the software. 51 | 52 | 53 | License Agreement 54 | For Open Source Computer Vision Library 55 | (3-clause BSD License) 56 | 57 | Redistribution and use in source and binary forms, with or without modification, 58 | are permitted provided that the following conditions are met: 59 | 60 | * Redistributions of source code must retain the above copyright notice, 61 | this list of conditions and the following disclaimer. 62 | 63 | * Redistributions in binary form must reproduce the above copyright notice, 64 | this list of conditions and the following disclaimer in the documentation 65 | and/or other materials provided with the distribution. 66 | 67 | * Neither the names of the copyright holders nor the names of the contributors 68 | may be used to endorse or promote products derived from this software 69 | without specific prior written permission. 70 | 71 | This software is provided by the copyright holders and contributors "as is" and 72 | any express or implied warranties, including, but not limited to, the implied 73 | warranties of merchantability and fitness for a particular purpose are disclaimed. 74 | In no event shall copyright holders or contributors be liable for any direct, 75 | indirect, incidental, special, exemplary, or consequential damages 76 | (including, but not limited to, procurement of substitute goods or services; 77 | loss of use, data, or profits; or business interruption) however caused 78 | and on any theory of liability, whether in contract, strict liability, 79 | or tort (including negligence or otherwise) arising in any way out of 80 | the use of this software, even if advised of the possibility of such damage. 81 | */ 82 | 83 | #ifndef _KCFTRACKER_HEADERS 84 | #include "kcftracker.hpp" 85 | #include "ffttools.hpp" 86 | #include "recttools.hpp" 87 | #include "fhog.hpp" 88 | #include "labdata.hpp" 89 | #endif 90 | 91 | // Constructor 92 | KCFTracker::KCFTracker(bool hog, bool fixed_window, bool multiscale, bool lab) 93 | { 94 | 95 | // Parameters equal in all cases 96 | lambda = 0.0001; 97 | padding = 2.5; 98 | //output_sigma_factor = 0.1; 99 | output_sigma_factor = 0.125; 100 | 101 | 102 | if (hog) { // HOG 103 | // VOT 104 | interp_factor = 0.012; 105 | sigma = 0.6; 106 | // TPAMI 107 | //interp_factor = 0.02; 108 | //sigma = 0.5; 109 | cell_size = 4; 110 | _hogfeatures = true; 111 | 112 | if (lab) { 113 | interp_factor = 0.005; 114 | sigma = 0.4; 115 | //output_sigma_factor = 0.025; 116 | output_sigma_factor = 0.1; 117 | 118 | _labfeatures = true; 119 | _labCentroids = cv::Mat(nClusters, 3, CV_32FC1, &data); 120 | cell_sizeQ = cell_size*cell_size; 121 | } 122 | else{ 123 | _labfeatures = false; 124 | } 125 | } 126 | else { // RAW 127 | interp_factor = 0.075; 128 | sigma = 0.2; 129 | cell_size = 1; 130 | _hogfeatures = false; 131 | 132 | if (lab) { 133 | printf("Lab features are only used with HOG features.\n"); 134 | _labfeatures = false; 135 | } 136 | } 137 | 138 | 139 | if (multiscale) { // multiscale 140 | template_size = 96; 141 | //template_size = 100; 142 | scale_step = 1.05; 143 | scale_weight = 0.95; 144 | if (!fixed_window) { 145 | //printf("Multiscale does not support non-fixed window.\n"); 146 | fixed_window = true; 147 | } 148 | } 149 | else if (fixed_window) { // fit correction without multiscale 150 | template_size = 96; 151 | //template_size = 100; 152 | scale_step = 1; 153 | } 154 | else { 155 | template_size = 1; 156 | scale_step = 1; 157 | } 158 | } 159 | 160 | // Initialize tracker 161 | void KCFTracker::init(const cv::Rect &roi, cv::Mat image) 162 | { 163 | _roi = roi; 164 | assert(roi.width >= 0 && roi.height >= 0); 165 | _tmpl = getFeatures(image, 1); 166 | _prob = createGaussianPeak(size_patch[0], size_patch[1]); 167 | _alphaf = cv::Mat(size_patch[0], size_patch[1], CV_32FC2, float(0)); 168 | //_num = cv::Mat(size_patch[0], size_patch[1], CV_32FC2, float(0)); 169 | //_den = cv::Mat(size_patch[0], size_patch[1], CV_32FC2, float(0)); 170 | train(_tmpl, 1.0); // train with initial frame 171 | } 172 | // Update position based on the new frame 173 | cv::Rect KCFTracker::update(cv::Mat image) 174 | { 175 | if (_roi.x + _roi.width <= 0) _roi.x = -_roi.width + 1; 176 | if (_roi.y + _roi.height <= 0) _roi.y = -_roi.height + 1; 177 | if (_roi.x >= image.cols - 1) _roi.x = image.cols - 2; 178 | if (_roi.y >= image.rows - 1) _roi.y = image.rows - 2; 179 | 180 | float cx = _roi.x + _roi.width / 2.0f; 181 | float cy = _roi.y + _roi.height / 2.0f; 182 | 183 | 184 | float peak_value; 185 | cv::Point2f res = detect(_tmpl, getFeatures(image, 0, 1.0f), peak_value); 186 | 187 | if (scale_step != 1) { 188 | // Test at a smaller _scale 189 | float new_peak_value; 190 | cv::Point2f new_res = detect(_tmpl, getFeatures(image, 0, 1.0f / scale_step), new_peak_value); 191 | 192 | if (scale_weight * new_peak_value > peak_value) { 193 | res = new_res; 194 | peak_value = new_peak_value; 195 | _scale /= scale_step; 196 | _roi.width /= scale_step; 197 | _roi.height /= scale_step; 198 | } 199 | 200 | // Test at a bigger _scale 201 | new_res = detect(_tmpl, getFeatures(image, 0, scale_step), new_peak_value); 202 | 203 | if (scale_weight * new_peak_value > peak_value) { 204 | res = new_res; 205 | peak_value = new_peak_value; 206 | _scale *= scale_step; 207 | _roi.width *= scale_step; 208 | _roi.height *= scale_step; 209 | } 210 | } 211 | 212 | // Adjust by cell size and _scale 213 | _roi.x = cx - _roi.width / 2.0f + ((float) res.x * cell_size * _scale); 214 | _roi.y = cy - _roi.height / 2.0f + ((float) res.y * cell_size * _scale); 215 | 216 | if (_roi.x >= image.cols - 1) _roi.x = image.cols - 1; 217 | if (_roi.y >= image.rows - 1) _roi.y = image.rows - 1; 218 | if (_roi.x + _roi.width <= 0) _roi.x = -_roi.width + 2; 219 | if (_roi.y + _roi.height <= 0) _roi.y = -_roi.height + 2; 220 | 221 | assert(_roi.width >= 0 && _roi.height >= 0); 222 | cv::Mat x = getFeatures(image, 0); 223 | train(x, interp_factor); 224 | 225 | return _roi; 226 | } 227 | 228 | 229 | // Detect object in the current frame. 230 | cv::Point2f KCFTracker::detect(cv::Mat z, cv::Mat x, float &peak_value) 231 | { 232 | using namespace FFTTools; 233 | 234 | cv::Mat k = gaussianCorrelation(x, z); 235 | cv::Mat res = (real(fftd(complexMultiplication(_alphaf, fftd(k)), true))); 236 | 237 | //minMaxLoc only accepts doubles for the peak, and integer points for the coordinates 238 | cv::Point2i pi; 239 | double pv; 240 | cv::minMaxLoc(res, NULL, &pv, NULL, &pi); 241 | peak_value = (float) pv; 242 | 243 | //subpixel peak estimation, coordinates will be non-integer 244 | cv::Point2f p((float)pi.x, (float)pi.y); 245 | 246 | if (pi.x > 0 && pi.x < res.cols-1) { 247 | p.x += subPixelPeak(res.at(pi.y, pi.x-1), peak_value, res.at(pi.y, pi.x+1)); 248 | } 249 | 250 | if (pi.y > 0 && pi.y < res.rows-1) { 251 | p.y += subPixelPeak(res.at(pi.y-1, pi.x), peak_value, res.at(pi.y+1, pi.x)); 252 | } 253 | 254 | p.x -= (res.cols) / 2; 255 | p.y -= (res.rows) / 2; 256 | 257 | return p; 258 | } 259 | 260 | // train tracker with a single image 261 | void KCFTracker::train(cv::Mat x, float train_interp_factor) 262 | { 263 | using namespace FFTTools; 264 | 265 | cv::Mat k = gaussianCorrelation(x, x); 266 | cv::Mat alphaf = complexDivision(_prob, (fftd(k) + lambda)); 267 | 268 | _tmpl = (1 - train_interp_factor) * _tmpl + (train_interp_factor) * x; 269 | _alphaf = (1 - train_interp_factor) * _alphaf + (train_interp_factor) * alphaf; 270 | 271 | 272 | /*cv::Mat kf = fftd(gaussianCorrelation(x, x)); 273 | cv::Mat num = complexMultiplication(kf, _prob); 274 | cv::Mat den = complexMultiplication(kf, kf + lambda); 275 | 276 | _tmpl = (1 - train_interp_factor) * _tmpl + (train_interp_factor) * x; 277 | _num = (1 - train_interp_factor) * _num + (train_interp_factor) * num; 278 | _den = (1 - train_interp_factor) * _den + (train_interp_factor) * den; 279 | 280 | _alphaf = complexDivision(_num, _den);*/ 281 | 282 | } 283 | 284 | // Evaluates a Gaussian kernel with bandwidth SIGMA for all relative shifts between input images X and Y, which must both be MxN. They must also be periodic (ie., pre-processed with a cosine window). 285 | cv::Mat KCFTracker::gaussianCorrelation(cv::Mat x1, cv::Mat x2) 286 | { 287 | using namespace FFTTools; 288 | cv::Mat c = cv::Mat( cv::Size(size_patch[1], size_patch[0]), CV_32F, cv::Scalar(0) ); 289 | // HOG features 290 | if (_hogfeatures) { 291 | cv::Mat caux; 292 | cv::Mat x1aux; 293 | cv::Mat x2aux; 294 | for (int i = 0; i < size_patch[2]; i++) { 295 | x1aux = x1.row(i); // Procedure do deal with cv::Mat multichannel bug 296 | x1aux = x1aux.reshape(1, size_patch[0]); 297 | x2aux = x2.row(i).reshape(1, size_patch[0]); 298 | cv::mulSpectrums(fftd(x1aux), fftd(x2aux), caux, 0, true); 299 | caux = fftd(caux, true); 300 | rearrange(caux); 301 | caux.convertTo(caux,CV_32F); 302 | c = c + real(caux); 303 | } 304 | } 305 | // Gray features 306 | else { 307 | cv::mulSpectrums(fftd(x1), fftd(x2), c, 0, true); 308 | c = fftd(c, true); 309 | rearrange(c); 310 | c = real(c); 311 | } 312 | cv::Mat d; 313 | cv::max(( (cv::sum(x1.mul(x1))[0] + cv::sum(x2.mul(x2))[0])- 2. * c) / (size_patch[0]*size_patch[1]*size_patch[2]) , 0, d); 314 | 315 | cv::Mat k; 316 | cv::exp((-d / (sigma * sigma)), k); 317 | return k; 318 | } 319 | 320 | // Create Gaussian Peak. Function called only in the first frame. 321 | cv::Mat KCFTracker::createGaussianPeak(int sizey, int sizex) 322 | { 323 | cv::Mat_ res(sizey, sizex); 324 | 325 | int syh = (sizey) / 2; 326 | int sxh = (sizex) / 2; 327 | 328 | float output_sigma = std::sqrt((float) sizex * sizey) / padding * output_sigma_factor; 329 | float mult = -0.5 / (output_sigma * output_sigma); 330 | 331 | for (int i = 0; i < sizey; i++) 332 | for (int j = 0; j < sizex; j++) 333 | { 334 | int ih = i - syh; 335 | int jh = j - sxh; 336 | res(i, j) = std::exp(mult * (float) (ih * ih + jh * jh)); 337 | } 338 | return FFTTools::fftd(res); 339 | } 340 | 341 | // Obtain sub-window from image, with replication-padding and extract features 342 | cv::Mat KCFTracker::getFeatures(const cv::Mat & image, bool inithann, float scale_adjust) 343 | { 344 | cv::Rect extracted_roi; 345 | 346 | float cx = _roi.x + _roi.width / 2; 347 | float cy = _roi.y + _roi.height / 2; 348 | 349 | if (inithann) { 350 | int padded_w = _roi.width * padding; 351 | int padded_h = _roi.height * padding; 352 | 353 | if (template_size > 1) { // Fit largest dimension to the given template size 354 | if (padded_w >= padded_h) //fit to width 355 | _scale = padded_w / (float) template_size; 356 | else 357 | _scale = padded_h / (float) template_size; 358 | 359 | _tmpl_sz.width = padded_w / _scale; 360 | _tmpl_sz.height = padded_h / _scale; 361 | } 362 | else { //No template size given, use ROI size 363 | _tmpl_sz.width = padded_w; 364 | _tmpl_sz.height = padded_h; 365 | _scale = 1; 366 | // original code from paper: 367 | /*if (sqrt(padded_w * padded_h) >= 100) { //Normal size 368 | _tmpl_sz.width = padded_w; 369 | _tmpl_sz.height = padded_h; 370 | _scale = 1; 371 | } 372 | else { //ROI is too big, track at half size 373 | _tmpl_sz.width = padded_w / 2; 374 | _tmpl_sz.height = padded_h / 2; 375 | _scale = 2; 376 | }*/ 377 | } 378 | 379 | if (_hogfeatures) { 380 | // Round to cell size and also make it even 381 | _tmpl_sz.width = ( ( (int)(_tmpl_sz.width / (2 * cell_size)) ) * 2 * cell_size ) + cell_size*2; 382 | _tmpl_sz.height = ( ( (int)(_tmpl_sz.height / (2 * cell_size)) ) * 2 * cell_size ) + cell_size*2; 383 | } 384 | else { //Make number of pixels even (helps with some logic involving half-dimensions) 385 | _tmpl_sz.width = (_tmpl_sz.width / 2) * 2; 386 | _tmpl_sz.height = (_tmpl_sz.height / 2) * 2; 387 | } 388 | } 389 | 390 | extracted_roi.width = scale_adjust * _scale * _tmpl_sz.width; 391 | extracted_roi.height = scale_adjust * _scale * _tmpl_sz.height; 392 | 393 | // center roi with new size 394 | extracted_roi.x = cx - extracted_roi.width / 2; 395 | extracted_roi.y = cy - extracted_roi.height / 2; 396 | 397 | cv::Mat FeaturesMap; 398 | cv::Mat z = RectTools::subwindow(image, extracted_roi, cv::BORDER_REPLICATE); 399 | 400 | if (z.cols != _tmpl_sz.width || z.rows != _tmpl_sz.height) { 401 | resize(z, z, _tmpl_sz); 402 | } 403 | 404 | // HOG features 405 | if (_hogfeatures) { 406 | IplImage z_ipl = z; 407 | CvLSVMFeatureMapCaskade *map; 408 | getFeatureMaps(&z_ipl, cell_size, &map); 409 | normalizeAndTruncate(map,0.2f); 410 | PCAFeatureMaps(map); 411 | size_patch[0] = map->sizeY; 412 | size_patch[1] = map->sizeX; 413 | size_patch[2] = map->numFeatures; 414 | 415 | FeaturesMap = cv::Mat(cv::Size(map->numFeatures,map->sizeX*map->sizeY), CV_32F, map->map); // Procedure do deal with cv::Mat multichannel bug 416 | FeaturesMap = FeaturesMap.t(); 417 | freeFeatureMapObject(&map); 418 | 419 | // Lab features 420 | if (_labfeatures) { 421 | cv::Mat imgLab; 422 | cvtColor(z, imgLab, CV_BGR2Lab); 423 | unsigned char *input = (unsigned char*)(imgLab.data); 424 | 425 | // Sparse output vector 426 | cv::Mat outputLab = cv::Mat(_labCentroids.rows, size_patch[0]*size_patch[1], CV_32F, float(0)); 427 | 428 | int cntCell = 0; 429 | // Iterate through each cell 430 | for (int cY = cell_size; cY < z.rows-cell_size; cY+=cell_size){ 431 | for (int cX = cell_size; cX < z.cols-cell_size; cX+=cell_size){ 432 | // Iterate through each pixel of cell (cX,cY) 433 | for(int y = cY; y < cY+cell_size; ++y){ 434 | for(int x = cX; x < cX+cell_size; ++x){ 435 | // Lab components for each pixel 436 | float l = (float)input[(z.cols * y + x) * 3]; 437 | float a = (float)input[(z.cols * y + x) * 3 + 1]; 438 | float b = (float)input[(z.cols * y + x) * 3 + 2]; 439 | 440 | // Iterate trough each centroid 441 | float minDist = FLT_MAX; 442 | int minIdx = 0; 443 | float *inputCentroid = (float*)(_labCentroids.data); 444 | for(int k = 0; k < _labCentroids.rows; ++k){ 445 | float dist = ( (l - inputCentroid[3*k]) * (l - inputCentroid[3*k]) ) 446 | + ( (a - inputCentroid[3*k+1]) * (a - inputCentroid[3*k+1]) ) 447 | + ( (b - inputCentroid[3*k+2]) * (b - inputCentroid[3*k+2]) ); 448 | if(dist < minDist){ 449 | minDist = dist; 450 | minIdx = k; 451 | } 452 | } 453 | // Store result at output 454 | outputLab.at(minIdx, cntCell) += 1.0 / cell_sizeQ; 455 | //((float*) outputLab.data)[minIdx * (size_patch[0]*size_patch[1]) + cntCell] += 1.0 / cell_sizeQ; 456 | } 457 | } 458 | cntCell++; 459 | } 460 | } 461 | // Update size_patch[2] and add features to FeaturesMap 462 | size_patch[2] += _labCentroids.rows; 463 | FeaturesMap.push_back(outputLab); 464 | } 465 | } 466 | else { 467 | FeaturesMap = RectTools::getGrayImage(z); 468 | FeaturesMap -= (float) 0.5; // In Paper; 469 | size_patch[0] = z.rows; 470 | size_patch[1] = z.cols; 471 | size_patch[2] = 1; 472 | } 473 | 474 | if (inithann) { 475 | createHanningMats(); 476 | } 477 | FeaturesMap = hann.mul(FeaturesMap); 478 | return FeaturesMap; 479 | } 480 | 481 | // Initialize Hanning window. Function called only in the first frame. 482 | bool KCFTracker::createHanningMats() 483 | { 484 | cv::Mat hann1t = cv::Mat(cv::Size(size_patch[1],1), CV_32F, cv::Scalar(0)); 485 | cv::Mat hann2t = cv::Mat(cv::Size(1,size_patch[0]), CV_32F, cv::Scalar(0)); 486 | 487 | for (int i = 0; i < hann1t.cols; i++) 488 | hann1t.at (0, i) = 0.5 * (1 - std::cos(2 * 3.14159265358979323846 * i / (hann1t.cols - 1))); 489 | for (int i = 0; i < hann2t.rows; i++) 490 | hann2t.at (i, 0) = 0.5 * (1 - std::cos(2 * 3.14159265358979323846 * i / (hann2t.rows - 1))); 491 | 492 | cv::Mat hann2d = hann2t * hann1t; 493 | // HOG features 494 | if (_hogfeatures) { 495 | cv::Mat hann1d = hann2d.reshape(1,1); // Procedure do deal with cv::Mat multichannel bug 496 | 497 | hann = cv::Mat(cv::Size(size_patch[0]*size_patch[1], size_patch[2]), CV_32F, cv::Scalar(0)); 498 | for (int i = 0; i < size_patch[2]; i++) { 499 | for (int j = 0; j(i,j) = hann1d.at(0,j); 501 | } 502 | } 503 | } 504 | // Gray features 505 | else { 506 | hann = hann2d; 507 | } 508 | return true; 509 | } 510 | 511 | // Calculate sub-pixel peak for one dimension 512 | float KCFTracker::subPixelPeak(float left, float center, float right) 513 | { 514 | float divisor = 2 * center - right - left; 515 | 516 | if (divisor == 0) 517 | return 0; 518 | 519 | return 0.5 * (right - left) / divisor; 520 | } 521 | -------------------------------------------------------------------------------- /UAV-Detect/Release/FastDPM.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/FastDPM.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.log: -------------------------------------------------------------------------------- 1 | 生成启动时间为 2016/4/4 20:16:10。 2 | 1>项目“G:\VS13\UAV-Detect\UAV-Detect\UAV-Detect.vcxproj”在节点 2 上(Build 个目标)。 3 | 1>ClCompile: 4 | C:\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /Zi /nologo /W3 /WX- /sdl /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _CONSOLE /D _LIB /D _CRT_SECURE_NO_DEPRECATE /D _SCL_SECURE_NO_DEPRECATE /D HAVE_TBB /D _UNICODE /D UNICODE /Gm- /EHsc /MTd /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /openmp /Fo"Release\\" /Fd"Release\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt UAVtest.cpp 5 | UAVtest.cpp 6 | Link: 7 | C:\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"G:\VS13\UAV-Detect\Release\UAV-Detect.exe" /INCREMENTAL:NO /NOLOGO opencv_ts300d.lib opencv_world300d.lib pthreadVC2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"G:\VS13\UAV-Detect\Release\UAV-Detect.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"G:\VS13\UAV-Detect\Release\UAV-Detect.lib" /MACHINE:X86 /SAFESEH Release\cvPrint.obj 8 | Release\getCurrentTime.obj 9 | Release\yuSaveMat.obj 10 | Release\FastDPM.obj 11 | Release\analyze_model.obj 12 | Release\apply_rules.obj 13 | Release\apply_rules2.obj 14 | Release\apply_rules3.obj 15 | Release\bboxpred_get.obj 16 | Release\bboxpred_input.obj 17 | Release\bounded_dt.obj 18 | Release\bounded_dt2.obj 19 | Release\clipboxes.obj 20 | Release\cvPermutate.obj 21 | Release\detections_trees2.obj 22 | Release\draw_img.obj 23 | Release\fconv.obj 24 | Release\featpyramid.obj 25 | Release\featpyramid2.obj 26 | Release\features.obj 27 | Release\features14_2.obj 28 | Release\flipfeat.obj 29 | Release\get_score_size.obj 30 | Release\loadPyramid.obj 31 | Release\load_model.obj 32 | Release\loc_feat.obj 33 | Release\model_get_block.obj 34 | Release\nms.obj 35 | Release\parse_detections.obj 36 | Release\pDollar_nms.obj 37 | Release\reduceboxes.obj 38 | Release\sum_score.obj 39 | Release\yuInd2Sub.obj 40 | Release\yuStdDirFiles.obj 41 | Release\boxextractor.obj 42 | Release\fhog.obj 43 | Release\kcftracker.obj 44 | Release\UAVtest.obj 45 | 正在生成代码 46 | 已完成代码的生成 47 | UAV-Detect.vcxproj -> G:\VS13\UAV-Detect\Release\UAV-Detect.exe 48 | 1>已完成生成项目“G:\VS13\UAV-Detect\UAV-Detect\UAV-Detect.vcxproj”(Build 个目标)的操作。 49 | 50 | 生成成功。 51 | 52 | 已用时间 00:00:10.46 53 | -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAV-Detect.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAV-Detect.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/UAV-Detect.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit 2 | Release|Win32|G:\VS13\UAV-Detect\| 3 | -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAV-Detect.tlog/cl.command.1.tlog -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAV-Detect.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAV-Detect.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /UAV-Detect/Release/UAV-Detect.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAV-Detect.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /UAV-Detect/Release/UAVtest.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/UAVtest.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/analyze_model.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/analyze_model.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/apply_rules.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/apply_rules.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/apply_rules2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/apply_rules2.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/apply_rules3.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/apply_rules3.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/bboxpred_get.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/bboxpred_get.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/bboxpred_input.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/bboxpred_input.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/bounded_dt.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/bounded_dt.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/bounded_dt2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/bounded_dt2.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/boxextractor.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/boxextractor.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/clipboxes.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/clipboxes.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/cvPermutate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/cvPermutate.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/cvPrint.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/cvPrint.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/detections_trees2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/detections_trees2.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/draw_img.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/draw_img.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/fconv.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/fconv.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/featpyramid.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/featpyramid.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/featpyramid2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/featpyramid2.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/features.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/features.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/features14_2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/features14_2.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/fhog.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/fhog.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/flipfeat.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/flipfeat.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/getCurrentTime.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/getCurrentTime.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/get_score_size.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/get_score_size.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/kcftracker.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/kcftracker.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/loadPyramid.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/loadPyramid.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/load_model.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/load_model.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/loc_feat.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/loc_feat.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/model_get_block.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/model_get_block.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/nms.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/nms.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/pDollar_nms.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/pDollar_nms.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/parse_detections.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/parse_detections.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/reduceboxes.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/reduceboxes.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/sum_score.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/sum_score.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/vc120.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/vc120.pdb -------------------------------------------------------------------------------- /UAV-Detect/Release/yuInd2Sub.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/yuInd2Sub.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/yuSaveMat.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/yuSaveMat.obj -------------------------------------------------------------------------------- /UAV-Detect/Release/yuStdDirFiles.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/Release/yuStdDirFiles.obj -------------------------------------------------------------------------------- /UAV-Detect/UAV-Detect.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {06A7628F-EFDD-4BC5-903A-D17047704551} 15 | Win32Proj 16 | UAVDetect 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | G:\VS13\UAV-Detect\UAV-Detect\DPM\auxiliary;G:\VS13\UAV-Detect\UAV-Detect\DPM\source;G:\VS13\UAV-Detect\UAV-Detect\DPM\include;G:\VS13\UAV-Detect\UAV-Detect\DPM\fastDPM;$(IncludePath) 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | Level3 54 | Disabled 55 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 56 | true 57 | 58 | 59 | Console 60 | true 61 | 62 | 63 | 64 | 65 | Level3 66 | 67 | 68 | MaxSpeed 69 | true 70 | true 71 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 72 | true 73 | 74 | 75 | Console 76 | true 77 | true 78 | true 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /UAV-Detect/UAV-Detect.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {8786ce70-e2c4-48bc-b31e-caeaece80f16} 18 | 19 | 20 | {c5fea1a6-509d-457d-949d-acd462b0c90f} 21 | 22 | 23 | {e2300adc-7a03-404e-8120-5b4d6e750766} 24 | 25 | 26 | {602a5e43-32e5-470f-b8aa-dcac3a70cf78} 27 | 28 | 29 | 30 | 31 | DPM\auxiliary 32 | 33 | 34 | DPM\auxiliary 35 | 36 | 37 | DPM\auxiliary 38 | 39 | 40 | DPM\source 41 | 42 | 43 | DPM\source 44 | 45 | 46 | DPM\source 47 | 48 | 49 | DPM\source 50 | 51 | 52 | DPM\source 53 | 54 | 55 | DPM\source 56 | 57 | 58 | DPM\source 59 | 60 | 61 | DPM\source 62 | 63 | 64 | DPM\source 65 | 66 | 67 | DPM\source 68 | 69 | 70 | DPM\source 71 | 72 | 73 | DPM\source 74 | 75 | 76 | DPM\source 77 | 78 | 79 | DPM\source 80 | 81 | 82 | DPM\source 83 | 84 | 85 | DPM\source 86 | 87 | 88 | DPM\source 89 | 90 | 91 | DPM\source 92 | 93 | 94 | DPM\source 95 | 96 | 97 | DPM\source 98 | 99 | 100 | DPM\source 101 | 102 | 103 | DPM\source 104 | 105 | 106 | DPM\source 107 | 108 | 109 | DPM\source 110 | 111 | 112 | DPM\source 113 | 114 | 115 | DPM\source 116 | 117 | 118 | DPM\source 119 | 120 | 121 | DPM\source 122 | 123 | 124 | DPM\source 125 | 126 | 127 | DPM\source 128 | 129 | 130 | DPM\source 131 | 132 | 133 | 源文件 134 | 135 | 136 | KCF 137 | 138 | 139 | KCF 140 | 141 | 142 | KCF 143 | 144 | 145 | 146 | 147 | 头文件 148 | 149 | 150 | 头文件 151 | 152 | 153 | 头文件 154 | 155 | 156 | 头文件 157 | 158 | 159 | 头文件 160 | 161 | 162 | 头文件 163 | 164 | 165 | 头文件 166 | 167 | 168 | 头文件 169 | 170 | 171 | 头文件 172 | 173 | 174 | 头文件 175 | 176 | 177 | 头文件 178 | 179 | 180 | -------------------------------------------------------------------------------- /UAV-Detect/UAV-Detect.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /UAV-Detect/UAVtest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kcftracker.hpp" 5 | #include "dirent.h" 6 | #include "boxextractor.h" 7 | 8 | #include "FastDPM.h" 9 | #include 10 | 11 | using namespace std; 12 | 13 | 14 | int main(int argc, char* argv[]){ 15 | 16 | 17 | bool HOG = true; 18 | bool FIXEDWINDOW = false; 19 | bool MULTISCALE = true; 20 | bool LAB = false; 21 | bool ENTER_LEAVE = true; 22 | bool FRAMES_FIRST = true; 23 | int nFrames = 0;// Frame counter 24 | 25 | string model_path("UAV_2.txt");//DPM model 26 | 27 | cv::Mat frame; 28 | cv::Mat image; 29 | cv::VideoCapture capture("uav_data/6.avi"); 30 | //cv::VideoCapture capture(0); 31 | if (model_path.empty()){ 32 | cout << "Please input model file...." << endl; 33 | return -1; 34 | } 35 | 36 | if (!capture.isOpened()){ 37 | cout << "Fail to open video....." << endl; 38 | return -1; 39 | } 40 | 41 | //init KCF 42 | BoxExtractor extractor; 43 | KCFTracker tracker(HOG, FIXEDWINDOW, MULTISCALE, LAB);// Create KCFTracker object 44 | Rect result;// Tracker results 45 | ofstream resultsFile; 46 | string resultsPath = "output.txt"; // Write Results 47 | resultsFile.open(resultsPath); 48 | 49 | 50 | FastDPM PM(model_path); 51 | 52 | while (true){ 53 | 54 | capture >> frame; 55 | if (frame.empty()){ 56 | cout << "Fail to get video......." << endl; 57 | break; 58 | } 59 | 60 | if (ENTER_LEAVE) 61 | { 62 | //DPM detect UAV 63 | 64 | frame.copyTo(image); 65 | cv::Mat img = PM.prepareImg(image); 66 | PM.detect(img, -1.0f, true, true); 67 | 68 | if (!PM.detections.empty()) 69 | { 70 | ENTER_LEAVE = false; 71 | FRAMES_FIRST = true; 72 | } 73 | } 74 | 75 | 76 | 77 | else{ 78 | 79 | //KCF track UAV 80 | 81 | double t = (double)cvGetTickCount(); 82 | // First frame, give the groundtruth to the tracker 83 | if (FRAMES_FIRST) { 84 | //relate KCF with DPM 85 | cv::Rect box(int(UL_INIT.x), int(UL_INIT.y), int(BR_INIT.x - UL_INIT.x), int(BR_INIT.y - UL_INIT.y));//box(x,y,width,height) 86 | tracker.init(box, frame); 87 | rectangle(frame, Point(box.x, box.y), Point(box.x + box.width, box.y + box.height), Scalar(0, 255, 255), 1, 8); 88 | FRAMES_FIRST = false; 89 | //rectangle(frame, Point(400,400), Point(638,478), Scalar(0, 255, 255), 1, 8); 90 | 91 | } 92 | // Update 93 | else{ 94 | result = tracker.update(frame); 95 | rectangle(frame, Point(result.x, result.y), Point(result.x + result.width, result.y + result.height), Scalar(0, 255, 255), 1, 8); 96 | resultsFile << result.x << "," << result.y << "," << result.width << "," << result.height << endl; 97 | //DPM model detect UAV's leave 98 | if (!(result.x > 0 && result.y > 0 && (640 - result.x - result.width) > 0 && (480 - result.y - result.height) > 0)){ 99 | ENTER_LEAVE = true; 100 | cout << "UAV has left....." << endl; 101 | } 102 | } 103 | 104 | t = (double)cvGetTickCount() - t; 105 | cout << "COST TIME: " << t / ((double)cvGetTickFrequency()*1000.) << endl; 106 | 107 | } 108 | 109 | 110 | imshow("UAV DETECT", frame); 111 | char key = waitKey(1); 112 | if (key == 27) break; 113 | 114 | } 115 | 116 | resultsFile.close(); 117 | cvDestroyWindow("UAV DETET"); 118 | return 0; 119 | 120 | } -------------------------------------------------------------------------------- /UAV-Detect/data/000084.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/data/000084.jpg -------------------------------------------------------------------------------- /UAV-Detect/data/1.flv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/data/1.flv -------------------------------------------------------------------------------- /UAV-Detect/data/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/data/1.png -------------------------------------------------------------------------------- /UAV-Detect/data/2.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/data/2.avi -------------------------------------------------------------------------------- /UAV-Detect/data/dpm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/data/dpm.jpg -------------------------------------------------------------------------------- /UAV-Detect/data/test1.flv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/data/test1.flv -------------------------------------------------------------------------------- /UAV-Detect/output.txt: -------------------------------------------------------------------------------- 1 | 160,104,111,47 2 | 160,104,111,47 3 | 160,104,111,47 4 | 160,104,111,47 5 | 172,109,111,47 6 | 181,114,111,47 7 | 182,115,111,47 8 | 195,117,111,47 9 | 198,117,111,47 10 | 200,114,117,49 11 | 202,112,117,49 12 | 202,110,117,49 13 | 202,110,117,49 14 | 201,107,117,49 15 | 200,102,117,49 16 | 199,101,117,49 17 | 198,100,117,49 18 | 189,93,117,49 19 | 189,92,117,49 20 | 188,91,117,49 21 | 183,89,117,49 22 | 182,88,117,49 23 | 180,88,117,49 24 | 178,87,117,49 25 | 171,87,111,47 26 | 171,86,111,47 27 | 172,86,111,47 28 | 175,87,106,45 29 | 176,88,106,45 30 | 176,88,106,45 31 | 178,87,106,45 32 | 181,82,106,45 33 | 180,80,111,47 34 | 183,78,111,47 35 | 183,76,117,49 36 | 188,76,117,49 37 | 190,78,117,49 38 | 191,78,117,49 39 | 165,93,122,52 40 | 161,98,122,52 41 | 162,98,122,52 42 | 156,101,117,49 43 | 145,104,117,49 44 | 145,105,117,49 45 | 142,112,117,49 46 | 140,114,117,49 47 | 140,114,117,49 48 | 141,115,117,49 49 | 151,116,117,49 50 | 150,116,117,49 51 | 151,116,117,49 52 | 157,114,117,49 53 | 157,113,117,49 54 | 169,109,117,49 55 | 183,101,117,49 56 | 201,94,117,49 57 | 204,93,117,49 58 | 205,93,117,49 59 | 240,82,111,47 60 | 240,80,111,47 61 | 249,78,111,47 62 | 256,79,111,47 63 | 256,78,111,47 64 | 266,84,111,47 65 | 263,83,117,49 66 | 271,88,117,49 67 | 270,90,117,49 68 | 269,90,117,49 69 | 245,115,122,52 70 | 241,117,122,52 71 | 224,128,117,49 72 | 217,139,122,52 73 | 216,141,122,52 74 | 187,158,128,54 75 | 178,162,128,54 76 | 168,162,128,54 77 | 144,158,135,57 78 | 143,156,135,57 79 | 124,167,128,54 80 | 111,169,128,54 81 | 106,170,128,54 82 | 98,169,122,52 83 | 98,168,122,52 84 | 98,167,122,52 85 | 98,167,122,52 86 | 81,156,122,52 87 | 81,154,122,52 88 | 78,149,117,49 89 | 77,148,117,49 90 | 80,148,111,47 91 | 77,133,117,49 92 | 78,129,117,49 93 | 85,113,122,52 94 | 84,108,122,52 95 | 90,95,117,49 96 | 92,75,117,49 97 | 104,61,122,52 98 | 120,53,122,52 99 | 133,50,122,52 100 | 140,49,122,52 101 | 140,48,122,52 102 | 148,47,122,52 103 | 158,47,122,52 104 | 157,47,122,52 105 | 158,49,122,52 106 | 158,50,122,52 107 | 158,57,122,52 108 | 158,57,122,52 109 | 159,59,122,52 110 | 160,58,122,52 111 | 161,58,122,52 112 | 161,61,122,52 113 | 165,65,117,49 114 | 165,65,117,49 115 | 163,68,117,49 116 | 165,71,111,47 117 | 164,72,111,47 118 | 158,75,106,45 119 | 158,76,106,45 120 | 158,76,106,45 121 | 156,77,106,45 122 | 153,77,106,45 123 | 152,78,106,45 124 | 152,80,106,45 125 | 152,80,106,45 126 | 151,80,106,45 127 | 151,82,106,45 128 | 152,82,106,45 129 | 161,91,101,43 130 | 161,91,101,43 131 | 162,94,101,43 132 | 169,98,101,43 133 | 165,98,106,45 134 | 176,105,106,45 135 | 176,106,106,45 136 | 177,106,106,45 137 | 178,107,106,45 138 | 182,108,106,45 139 | 182,109,106,45 140 | 184,110,106,45 141 | 185,110,106,45 142 | 185,109,106,45 143 | 184,110,106,45 144 | 184,110,106,45 145 | 172,109,106,45 146 | 172,108,106,45 147 | 170,108,106,45 148 | 167,108,106,45 149 | 167,108,106,45 150 | 166,108,106,45 151 | 155,110,106,45 152 | 155,111,106,45 153 | 148,113,106,45 154 | 147,114,106,45 155 | 146,115,106,45 156 | 146,115,106,45 157 | 134,123,106,45 158 | 134,123,106,45 159 | 132,125,106,45 160 | 124,126,106,45 161 | 124,126,106,45 162 | 124,126,106,45 163 | 114,126,106,45 164 | 114,126,106,45 165 | 112,126,106,45 166 | 105,126,106,45 167 | 105,126,106,45 168 | 104,125,106,45 169 | 104,125,106,45 170 | 104,124,106,45 171 | 102,125,106,45 172 | 102,125,106,45 173 | 101,125,106,45 174 | 101,125,106,45 175 | 102,126,106,45 176 | 102,126,106,45 177 | 102,128,106,45 178 | 107,133,101,43 179 | 107,133,101,43 180 | 109,135,96,41 181 | 108,136,96,41 182 | 109,139,96,41 183 | 109,140,96,41 184 | 108,141,96,41 185 | 108,144,96,41 186 | 108,144,96,41 187 | 107,147,96,41 188 | 103,150,96,41 189 | 99,152,101,43 190 | 97,154,101,43 191 | 95,156,101,43 192 | 89,159,106,45 193 | 90,161,101,43 194 | 87,162,101,43 195 | 84,166,101,43 196 | 83,167,101,43 197 | 82,167,101,43 198 | 80,169,101,43 199 | 79,170,101,43 200 | 78,170,101,43 201 | 78,170,101,43 202 | 78,170,101,43 203 | 78,171,101,43 204 | 78,171,101,43 205 | 83,170,101,43 206 | 83,169,101,43 207 | 84,169,101,43 208 | 90,168,101,43 209 | 92,167,101,43 210 | 95,165,101,43 211 | 100,165,101,43 212 | 100,163,101,43 213 | 101,163,101,43 214 | 106,162,101,43 215 | 107,162,101,43 216 | 114,160,101,43 217 | 114,159,101,43 218 | 114,158,106,45 219 | 115,158,106,45 220 | 116,158,106,45 221 | 124,156,106,45 222 | 125,155,106,45 223 | 128,155,106,45 224 | 134,154,106,45 225 | 134,154,106,45 226 | 145,152,106,45 227 | 145,152,106,45 228 | 147,153,106,45 229 | 147,153,106,45 230 | 150,153,106,45 231 | 151,152,106,45 232 | 161,153,106,45 233 | 160,153,106,45 234 | 160,153,106,45 235 | 164,155,106,45 236 | 169,156,106,45 237 | 169,155,106,45 238 | 172,158,106,45 239 | 172,158,106,45 240 | 171,158,106,45 241 | 174,160,101,43 242 | 174,160,101,43 243 | 173,160,101,43 244 | 172,162,101,43 245 | 173,163,96,41 246 | 170,164,96,41 247 | 169,165,96,41 248 | 169,166,96,41 249 | 161,173,96,41 250 | 161,172,96,41 251 | 159,173,96,41 252 | 157,177,96,41 253 | 150,178,101,43 254 | 145,180,101,43 255 | 138,187,101,43 256 | 138,188,101,43 257 | 136,189,101,43 258 | 135,189,101,43 259 | 135,189,101,43 260 | 133,192,101,43 261 | 132,193,101,43 262 | 118,202,106,45 263 | 109,211,106,45 264 | 103,215,106,45 265 | 101,216,106,45 266 | 100,218,106,45 267 | 99,220,106,45 268 | 102,221,106,45 269 | 102,220,106,45 270 | 116,218,106,45 271 | 145,206,106,45 272 | 150,205,106,45 273 | 155,200,111,47 274 | 172,199,111,47 275 | 192,199,117,49 276 | 197,199,117,49 277 | 218,196,111,47 278 | 247,186,111,47 279 | 250,186,111,47 280 | 260,183,111,47 281 | 275,175,111,47 282 | 275,175,111,47 283 | 288,166,111,47 284 | 292,164,106,45 285 | 292,164,106,45 286 | 293,162,106,45 287 | 297,160,111,47 288 | 297,159,111,47 289 | 297,158,111,47 290 | 298,158,111,47 291 | 294,157,111,47 292 | 286,156,111,47 293 | 288,155,111,47 294 | 278,155,111,47 295 | 278,153,111,47 296 | 278,153,111,47 297 | 277,152,106,45 298 | 264,151,106,45 299 | 264,150,106,45 300 | 256,151,106,45 301 | 247,153,106,45 302 | 247,153,106,45 303 | 243,153,106,45 304 | 223,159,106,45 305 | 225,159,106,45 306 | 222,159,106,45 307 | 214,161,106,45 308 | 206,163,106,45 309 | 204,163,106,45 310 | 204,164,106,45 311 | 195,168,106,45 312 | 193,169,106,45 313 | 193,171,106,45 314 | 192,172,106,45 315 | 192,173,106,45 316 | 194,174,101,43 317 | 196,174,101,43 318 | 215,172,101,43 319 | 221,172,101,43 320 | 231,172,101,43 321 | 260,164,101,43 322 | 270,165,101,43 323 | 288,165,96,41 324 | 306,167,96,41 325 | 310,168,96,41 326 | 310,168,96,41 327 | 318,168,91,39 328 | 324,165,91,39 329 | 326,164,91,39 330 | 326,163,91,39 331 | 332,163,91,39 332 | 334,160,96,41 333 | 336,161,96,41 334 | 340,161,96,41 335 | 345,162,96,41 336 | 345,162,96,41 337 | 346,163,96,41 338 | 346,164,96,41 339 | 346,165,96,41 340 | 347,168,96,41 341 | 347,170,96,41 342 | 345,171,101,43 343 | 345,172,101,43 344 | 341,176,101,43 345 | 333,182,101,43 346 | 333,183,101,43 347 | 334,183,101,43 348 | 316,191,101,43 349 | 309,192,101,43 350 | 302,197,101,43 351 | 301,197,101,43 352 | 285,204,96,41 353 | 271,205,96,41 354 | 270,205,96,41 355 | 257,205,96,41 356 | 240,204,96,41 357 | 240,204,96,41 358 | 231,202,91,39 359 | 230,202,91,39 360 | 228,201,91,39 361 | 218,199,91,39 362 | 209,197,91,39 363 | -------------------------------------------------------------------------------- /UAV-Detect/pthreadVC2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/pthreadVC2.dll -------------------------------------------------------------------------------- /UAV-Detect/uav_data/1.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/1.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/2.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/2.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/3.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/3.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/4.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/4.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/5.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/5.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/6.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/6.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/uav_1.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/uav_1.avi -------------------------------------------------------------------------------- /UAV-Detect/uav_data/uav_2.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiesst/UAV-Detect/62e72c81fdc472b9e4524897611996e5feb39012/UAV-Detect/uav_data/uav_2.avi --------------------------------------------------------------------------------