├── EdgeBox ├── edgeBoxes.m ├── edgesChns.m ├── edgesDetect.m ├── init_EdgeBox.m ├── private │ ├── correspondPixels.mexa64 │ ├── correspondPixels.mexmaci64 │ ├── correspondPixels.mexw64 │ ├── edgeBoxesMex.cpp │ ├── edgeBoxesMex.mexa64 │ ├── edgeBoxesMex.mexmaci64 │ ├── edgeBoxesMex.mexw64 │ ├── edgesDetectMex.cpp │ ├── edgesDetectMex.mexa64 │ ├── edgesDetectMex.mexmaci64 │ ├── edgesDetectMex.mexw64 │ ├── edgesNmsMex.cpp │ ├── edgesNmsMex.mexa64 │ ├── edgesNmsMex.mexmaci64 │ ├── edgesNmsMex.mexw64 │ ├── spDetectMex.cpp │ ├── spDetectMex.mexa64 │ ├── spDetectMex.mexmaci64 │ ├── spDetectMex.mexw64 │ ├── ucm_mean_pb.mexa64 │ ├── ucm_mean_pb.mexmaci64 │ └── ucm_mean_pb.mexw64 └── run_EdgeBox.m ├── JSAR_Re_lib ├── feature │ ├── average_feature_region.m │ ├── fcn.m │ ├── fhog.m │ ├── get_cnn_layers.m │ ├── get_colorspace.m │ ├── get_features.m │ ├── get_fhog.m │ ├── get_pixels.m │ ├── get_table_feature.m │ ├── gradient2.m │ ├── gradientHist.m │ ├── gradientMag.m │ ├── gradientMex.cpp │ ├── gradientMex.mexa64 │ ├── gradientMex.mexmaci64 │ ├── gradientMex.mexw64 │ ├── im2c.m │ ├── lookup_tables │ │ └── CNnorm.mat │ └── w2crs.mat ├── implementation │ ├── average_feature_region.m │ ├── cosine_calculate.m │ ├── crop_scale_sample.m │ ├── extract_template.m │ ├── get_size_sample.m │ ├── init_features.m │ ├── init_gauss_win.m │ ├── init_gaussian.asv │ ├── init_regwindow.m │ ├── init_size.m │ ├── load_image.m │ ├── re_detection.m │ ├── run_detection.m │ ├── run_training.m │ ├── search_size.m │ ├── shift_sample_scale.m │ ├── size_factor.m │ └── tracking_JSAR_Re.m └── utils │ ├── integralVecImage.m │ ├── mexResize.cpp │ ├── mexResize.mexa64 │ ├── mexResize.mexmaci64 │ ├── mexResize.mexw64 │ ├── mtimesx.c │ ├── mtimesx.m │ ├── mtimesx.mexa64 │ └── mtimesx.mexmaci64 ├── JSAR_lib ├── average_feature_region.m ├── computeArea.m ├── computeIntersectionArea.m ├── computePascalScore.m ├── fcn.m ├── fhog.m ├── get_colorspace.m ├── get_features.m ├── get_fhog.m ├── get_pixels.m ├── get_size_sample.m ├── get_subwindow_no_window.m ├── get_table_feature.m ├── gradient2.m ├── gradientHist.m ├── gradientMag.m ├── gradientMex.cpp ├── gradientMex.mexa64 ├── gradientMex.mexmaci64 ├── gradientMex.mexw64 ├── im2c.m ├── init_regwindow.m ├── integralVecImage.m ├── load_video_info.m ├── lookup_tables │ └── CNnorm.mat ├── mexResize.cpp ├── mexResize.mexa64 ├── mexResize.mexmaci64 ├── mexResize.mexw64 ├── mtimesx.c ├── mtimesx.m ├── mtimesx.mexa64 ├── mtimesx.mexmaci64 ├── mtimesx.mexw64 ├── mtimesx_RealTimesReal.c ├── mtimesx_build.m ├── mtimesx_sparse.m ├── opencv_core242.dll ├── opencv_imgproc242.dll ├── resizeDFT2.m ├── resp_newton.m ├── shift_sample.m ├── table_lookup.m └── tracking_JSAR.m ├── README.md ├── channels ├── Contents.m ├── chnsCompute.m ├── chnsPyramid.m ├── chnsScaling.m ├── convBox.m ├── convMax.m ├── convTri.m ├── fhog.m ├── gradient2.m ├── gradientHist.m ├── gradientMag.m ├── hog.m ├── hogDraw.m ├── imPad.m ├── imResample.m ├── private │ ├── chnsTestCpp.cpp │ ├── convConst.cpp │ ├── convConst.mexa64 │ ├── convConst.mexmaci64 │ ├── convConst.mexw64 │ ├── gradientMex.cpp │ ├── gradientMex.mexa64 │ ├── gradientMex.mexmaci64 │ ├── gradientMex.mexw64 │ ├── gradientMexNew.mexmaci64 │ ├── imPadMex.cpp │ ├── imPadMex.mexa64 │ ├── imPadMex.mexmaci64 │ ├── imPadMex.mexw64 │ ├── imResampleMex.cpp │ ├── imResampleMex.mexa64 │ ├── imResampleMex.mexmaci64 │ ├── imResampleMex.mexw64 │ ├── rgbConvertMex.cpp │ ├── rgbConvertMex.mexa64 │ ├── rgbConvertMex.mexmaci64 │ ├── rgbConvertMex.mexw64 │ ├── sse.hpp │ └── wrappers.hpp └── rgbConvert.m ├── detector ├── Contents.m ├── acfDemoCal.m ├── acfDemoInria.m ├── acfDetect.m ├── acfModify.m ├── acfReadme.m ├── acfSweeps.m ├── acfTest.m ├── acfTrain.m ├── bbApply.m ├── bbGt.m ├── bbLabeler.m ├── bbNms.m ├── models │ ├── AcfCaltech+Detector.mat │ ├── AcfCaltech+Log.txt │ ├── AcfCaltech+Roc.png │ ├── AcfInriaDetector.mat │ ├── AcfInriaLog.txt │ ├── AcfInriaRoc.png │ ├── LdcfCaltechDetector.mat │ ├── LdcfCaltechLog.txt │ ├── LdcfCaltechRoc.png │ ├── LdcfInriaDetector.mat │ ├── LdcfInriaLog.txt │ └── LdcfInriaRoc.png └── private │ ├── acfDetect1.cpp │ ├── acfDetect1.mexa64 │ ├── acfDetect1.mexmaci64 │ └── acfDetect1.mexw64 ├── images ├── Contents.m ├── assignToBins.m ├── clusterMontage.m ├── convnFast.m ├── filmStrip.m ├── gaussSmooth.m ├── histMontage.m ├── histc2.m ├── histcImLoc.m ├── histcImWin.m ├── im.m ├── imMlGauss.m └── images.mat ├── matlab ├── Contents.m ├── arrayCrop.m ├── arrayToDims.m ├── c.m ├── cc.m ├── ccc.m ├── cell2array.m ├── char2img.m ├── checkNumArgs.m ├── dijkstra.m ├── dirSynch.m ├── diskFill.m ├── dispMatrixIm.m ├── fevalArrays.m ├── fevalDistr.m ├── fevalDistrDisk.m ├── fevalImages.m ├── fevalMats.m ├── figureResized.m ├── gauss2ellipse.m ├── getPrmDflt.m ├── imLabel.m ├── ind2sub2.m ├── int2str2.m ├── isfield2.m ├── mat2cell2.m ├── medianw.m ├── multiDiv.m ├── multiTimes.m ├── normpdf2.m ├── num2strs.m ├── plotEllipse.m ├── plotGaussEllipses.m └── plotRoc.m ├── models └── forest │ └── modelBsds.mat ├── results_OPE ├── DTB70 │ ├── error.png │ └── overlap.png ├── UAV123_10fps │ ├── error.png │ └── overlap.png ├── UAV20L │ └── error.png └── UAVDT │ ├── error.png │ └── overlap.png ├── run_JSAR.m ├── run_JSAR_Re.m └── videos ├── Contents.m ├── behaviorAnnotator.m ├── behaviorData.m ├── imagesAlign.m ├── imagesAlignSeq.m ├── kernelTracker.m ├── opticalFlow.m ├── opticalFlowTest.mat ├── peds30-seek.mat ├── peds30.seq ├── private ├── ktComputeW_c.c ├── ktComputeW_c.mexa64 ├── ktComputeW_c.mexmaci64 ├── ktComputeW_c.mexw64 ├── ktHistcRgb_c.c ├── ktHistcRgb_c.mexa64 ├── ktHistcRgb_c.mexmaci64 ├── ktHistcRgb_c.mexw64 ├── opticalFlowHsMex.cpp ├── opticalFlowHsMex.mexa64 ├── opticalFlowHsMex.mexmaci64 └── opticalFlowHsMex.mexw64 ├── seqIo.m ├── seqPlayer.m ├── seqReaderPlugin.m └── seqWriterPlugin.m /EdgeBox/edgeBoxes.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/edgeBoxes.m -------------------------------------------------------------------------------- /EdgeBox/edgesChns.m: -------------------------------------------------------------------------------- 1 | function [chnsReg,chnsSim] = edgesChns( I, opts ) 2 | % Compute features for structured edge detection. 3 | % 4 | % For an introductory tutorial please see edgesDemo.m. 5 | % 6 | % USAGE 7 | % [chnsReg,chnsSim] = edgesChns( I, opts ) 8 | % 9 | % INPUTS 10 | % I - [h x w x 3] color input image 11 | % opts - structured edge model options 12 | % 13 | % OUTPUTS 14 | % chnsReg - [h x w x nChannel] regular output channels 15 | % chnsSim - [h x w x nChannel] self-similarity output channels 16 | % 17 | % EXAMPLE 18 | % 19 | % See also edgesDemo, edgesTrain, edgesDetect, gradientMag 20 | % 21 | % Structured Edge Detection Toolbox Version 3.01 22 | % Code written by Piotr Dollar, 2014. 23 | % Licensed under the MSR-LA Full Rights License [see license.txt] 24 | 25 | shrink=opts.shrink; nTypes=1; chns=cell(1,opts.nChns); k=0; 26 | if(size(I,3)>3), nTypes=2; Is={I(:,:,1:3),I(:,:,4:end)}; end 27 | for t=1:nTypes 28 | if(nTypes>1), I=Is{t}; end 29 | if(size(I,3)==1), cs='gray'; else cs='luv'; end; I=rgbConvert(I,cs); 30 | Ishrink=imResample(I,1/shrink); k=k+1; chns{k}=Ishrink; 31 | for i = 1:2, s=2^(i-1); 32 | if(s==shrink), I1=Ishrink; else I1=imResample(I,1/s); end 33 | I1 = convTri( I1, opts.grdSmooth ); 34 | [M,O] = gradientMag( I1, 0, opts.normRad, .01 ); 35 | H = gradientHist( M, O, max(1,shrink/s), opts.nOrients, 0 ); 36 | k=k+1; chns{k}=imResample(M,s/shrink); 37 | k=k+1; chns{k}=imResample(H,max(1,s/shrink)); 38 | end 39 | end 40 | chns=cat(3,chns{1:k}); assert(size(chns,3)==opts.nChns); 41 | chnSm=opts.chnSmooth/shrink; if(chnSm>1), chnSm=round(chnSm); end 42 | simSm=opts.simSmooth/shrink; if(simSm>1), simSm=round(simSm); end 43 | chnsReg=convTri(chns,chnSm); chnsSim=convTri(chns,simSm); 44 | 45 | end 46 | -------------------------------------------------------------------------------- /EdgeBox/edgesDetect.m: -------------------------------------------------------------------------------- 1 | function [E,O,inds,segs] = edgesDetect( I, model ) 2 | % Detect edges in image. 3 | % 4 | % For an introductory tutorial please see edgesDemo.m. 5 | % 6 | % The following model params may be altered prior to detecting edges: 7 | % prm = stride, sharpen, multiscale, nTreesEval, nThreads, nms 8 | % Simply alter model.opts.prm. For example, set model.opts.nms=1 to enable 9 | % non-maximum suppression. See edgesTrain for parameter details. 10 | % 11 | % USAGE 12 | % [E,O,inds,segs] = edgesDetect( I, model ) 13 | % 14 | % INPUTS 15 | % I - [h x w x 3] color input image 16 | % model - structured edge model trained with edgesTrain 17 | % 18 | % OUTPUTS 19 | % E - [h x w] edge probability map 20 | % O - [h x w] coarse edge normal orientation (0=left, pi/2=up) 21 | % inds - [h/s x w/s x nTreesEval] leaf node indices 22 | % segs - [g x g x h/s x w/s x nTreesEval] local segmentations 23 | % 24 | % EXAMPLE 25 | % 26 | % See also edgesDemo, edgesTrain, edgesChns 27 | % 28 | % Structured Edge Detection Toolbox Version 3.01 29 | % Code written by Piotr Dollar, 2014. 30 | % Licensed under the MSR-LA Full Rights License [see license.txt] 31 | 32 | % get parameters 33 | opts=model.opts; opts.nTreesEval=min(opts.nTreesEval,opts.nTrees); 34 | if(~isfield(opts,'sharpen')), opts.sharpen=0; end 35 | if(~isfield(model,'segs')), model.segs=[]; model.nSegs=[]; end 36 | opts.stride=max(opts.stride,opts.shrink); model.opts=opts; 37 | 38 | if( opts.multiscale ) 39 | % if multiscale run edgesDetect multiple times 40 | ss=2.^(-1:1); k=length(ss); inds=cell(1,k); segs=inds; 41 | siz=size(I); model.opts.multiscale=0; model.opts.nms=0; E=0; 42 | for i=1:k, s=ss(i); I1=imResample(I,s); 43 | if(nargout<4), [E1,~,inds{i}]=edgesDetect(I1,model); 44 | else [E1,~,inds{i},segs{i}]=edgesDetect(I1,model); end 45 | E=E+imResample(E1,siz(1:2)); 46 | end; E=E/k; model.opts=opts; 47 | 48 | else 49 | % pad image, making divisible by 4 50 | siz=size(I); r=opts.imWidth/2; p=[r r r r]; 51 | p([2 4])=p([2 4])+mod(4-mod(siz(1:2)+2*r,4),4); 52 | I = imPad(I,p,'symmetric'); 53 | 54 | % compute features and apply forest to image 55 | [chnsReg,chnsSim] = edgesChns( I, opts ); 56 | s=opts.sharpen; if(s), I=convTri(rgbConvert(I,'rgb'),1); end 57 | if(nargout<4), [E,inds] = edgesDetectMex(model,I,chnsReg,chnsSim); 58 | else [E,inds,segs] = edgesDetectMex(model,I,chnsReg,chnsSim); end 59 | 60 | % normalize and finalize edge maps 61 | t=opts.stride^2/opts.gtWidth^2/opts.nTreesEval; r=opts.gtWidth/2; 62 | if(s==0), t=t*2; elseif(s==1), t=t*1.8; else t=t*1.66; end 63 | E=E(1+r:siz(1)+r,1+r:siz(2)+r,:)*t; E=convTri(E,1); 64 | end 65 | 66 | % compute approximate orientation O from edges E 67 | if( opts.nms==-1 ), O=[]; elseif( nargout>1 || opts.nms ) 68 | [Ox,Oy]=gradient2(convTri(E,4)); 69 | [Oxx,~]=gradient2(Ox); [Oxy,Oyy]=gradient2(Oy); 70 | O=mod(atan(Oyy.*sign(-Oxy)./(Oxx+1e-5)),pi); 71 | end 72 | 73 | % perform nms 74 | if( opts.nms>0 ), E=edgesNmsMex(E,O,1,5,1.01,opts.nThreads); end 75 | 76 | end 77 | -------------------------------------------------------------------------------- /EdgeBox/init_EdgeBox.m: -------------------------------------------------------------------------------- 1 | function [model,opts] = init_EdgeBox() 2 | %% load pre-trained edge detection model and set opts 3 | model=load('models/forest/modelBsds'); 4 | model=model.model; 5 | model.opts.multiscale=0; 6 | model.opts.sharpen=2; 7 | model.opts.nThreads=4; 8 | %% set up opts for edgeBoxes 9 | opts = edgeBoxes; 10 | opts.alpha =0.625; % step size of sliding window search 11 | opts.beta =0.85; % nms threshold for object proposals 12 | opts.minScore = 0.01; % min score of boxes to detect 13 | opts.maxBoxes = 30; % max number of boxes to detect 14 | end -------------------------------------------------------------------------------- /EdgeBox/private/correspondPixels.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/correspondPixels.mexa64 -------------------------------------------------------------------------------- /EdgeBox/private/correspondPixels.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/correspondPixels.mexmaci64 -------------------------------------------------------------------------------- /EdgeBox/private/correspondPixels.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/correspondPixels.mexw64 -------------------------------------------------------------------------------- /EdgeBox/private/edgeBoxesMex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/edgeBoxesMex.mexa64 -------------------------------------------------------------------------------- /EdgeBox/private/edgeBoxesMex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/edgeBoxesMex.mexmaci64 -------------------------------------------------------------------------------- /EdgeBox/private/edgeBoxesMex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/edgeBoxesMex.mexw64 -------------------------------------------------------------------------------- /EdgeBox/private/edgesDetectMex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/edgesDetectMex.mexa64 -------------------------------------------------------------------------------- /EdgeBox/private/edgesDetectMex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/edgesDetectMex.mexmaci64 -------------------------------------------------------------------------------- /EdgeBox/private/edgesDetectMex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/EdgeBox/private/edgesDetectMex.mexw64 -------------------------------------------------------------------------------- /EdgeBox/private/edgesNmsMex.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Structured Edge Detection Toolbox Version 3.01 3 | * Code written by Piotr Dollar, 2014. 4 | * Licensed under the MSR-LA Full Rights License [see license.txt] 5 | *******************************************************************************/ 6 | #include 7 | #include 8 | #ifdef USEOMP 9 | #include 10 | #endif 11 | 12 | // return I[x,y] via bilinear interpolation 13 | inline float interp( float *I, int h, int w, float x, float y ) { 14 | x = x<0 ? 0 : (x>w-1.001 ? w-1.001 : x); 15 | y = y<0 ? 0 : (y>h-1.001 ? h-1.001 : y); 16 | int x0=int(x), y0=int(y), x1=x0+1, y1=y0+1; 17 | float dx0=x-x0, dy0=y-y0, dx1=1-dx0, dy1=1-dy0; 18 | return I[x0*h+y0]*dx1*dy1 + I[x1*h+y0]*dx0*dy1 + 19 | I[x0*h+y1]*dx1*dy0 + I[x1*h+y1]*dx0*dy0; 20 | } 21 | 22 | // E = mexFunction(E,O,r,s,m,nThreads) 23 | void mexFunction( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) 24 | { 25 | float *E0 = (float*) mxGetData(pr[0]); // original edge map 26 | float *O = (float*) mxGetData(pr[1]); // orientation map 27 | int r = (int) mxGetScalar(pr[2]); // radius for nms supr 28 | int s = (int) mxGetScalar(pr[3]); // radius for supr boundaries 29 | float m = (float) mxGetScalar(pr[4]); // multiplier for conservative supr 30 | int nThreads = (int) mxGetScalar(pr[5]); // number of threads for evaluation 31 | 32 | int h=(int) mxGetM(pr[0]), w=(int) mxGetN(pr[0]); 33 | pl[0] = mxCreateNumericMatrix(h,w,mxSINGLE_CLASS,mxREAL); 34 | float *E = (float*) mxGetData(pl[0]); 35 | 36 | // suppress edges where edge is stronger in orthogonal direction 37 | #ifdef USEOMP 38 | nThreads = nThreadsw/2?w/2:s; s=s>h/2? h/2:s; 52 | for( int x=0; xsize(im,1)*size(im,2) 7 | ys=1:size(im,1); 8 | xs=1:size(im,2); 9 | else 10 | xs = floor(pos(2)) + (1:round(sqrt(num_pixels))) - floor(1/2*round(sqrt(num_pixels))); 11 | ys = floor(pos(1)) + (1:round(sqrt(num_pixels))) - floor(1/2*round(sqrt(num_pixels))); 12 | % check for out-of-bounds coordinates, and set them to the values at 13 | % the borders 14 | xs(xs < 1) = 1; 15 | ys(ys < 1) = 1; 16 | xs(xs > size(im,2)) = size(im,2); 17 | ys(ys > size(im,1)) = size(im,1); 18 | end 19 | I=im(ys,xs,:); 20 | % imshow(I); 21 | % tic, 22 | bbs=edgeBoxes(I,model,opts); 23 | % %toc 24 | % gt=bbs; 25 | % gt(:,5)=0; 26 | % [gtRes,dtRes]=bbGt('evalRes',double(gt),double(bbs),.1); 27 | % figure(1); 28 | % bbGt('showRes',I,gtRes,dtRes(dtRes(:,6)==1,:)); 29 | fclose all; 30 | Bbs=zeros(size(bbs,1),5); 31 | for i=1:size(Bbs,1) 32 | Bbs(i,1:2)=bbs(i,1:2)+[xs(1),ys(1)]; 33 | Bbs(i,3:4)=bbs(i,3:4); 34 | Bbs(i,5)=bbs(i,5); 35 | if Bbs(i,1)<1 36 | Bbs(i,1)=1; 37 | end 38 | if Bbs(i,1)>size(im,2) 39 | Bbs(i,1)=size(im,2); 40 | end 41 | if Bbs(i,2)<1 42 | Bbs(i,2)=1; 43 | end 44 | if Bbs(i,2)>size(im,1) 45 | Bbs(i,2)=size(im,1); 46 | end 47 | end 48 | end -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/average_feature_region.m: -------------------------------------------------------------------------------- 1 | function [ region_image ] = average_feature_region(im, region_size) 2 | % compute cell wise averages, where a cell is a region_size*region_sized 3 | % region in the image. Input can be uint8t, single or double matrices 4 | % of arbitrary dimension 5 | 6 | region_area = region_size.^2; 7 | 8 | if isa(im,'double') || isa(im,'single') || isa(im,'gpuArray') 9 | maxval = 1.0; 10 | elseif isa(im,'unit8') 11 | maxval = 255; 12 | end 13 | 14 | % compute the integral image 15 | iImage = integralVecImage(im); 16 | 17 | % region indices 18 | i1 = (region_size:region_size:size(im,1)) + 1; 19 | i2 = (region_size:region_size:size(im,2)) + 1; 20 | 21 | % sum over region, divided by number of elements, and normalize to [0,1] 22 | % range if integer image 23 | region_image = (iImage(i1,i2,:,:) - iImage(i1,i2-region_size,:,:) - iImage(i1-region_size,i2,:,:) + iImage(i1-region_size,i2-region_size,:,:)) ./ (region_area * maxval); 24 | 25 | end 26 | 27 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/fcn.m: -------------------------------------------------------------------------------- 1 | function out = fcn(im_patch, features, w2c) 2 | 3 | % out = get_feature_map(im_patch, features, w2c) 4 | % 5 | % Extracts the given features from the image patch. w2c is the 6 | % Color Names matrix, if used. 7 | 8 | if nargin < 3 9 | w2c = []; 10 | end 11 | 12 | % the names of the features that can be used 13 | valid_features = {'gray', 'cn'}; 14 | 15 | % the dimension of the valid features 16 | feature_levels = [1 10]'; 17 | 18 | num_valid_features = length(valid_features); 19 | used_features = false(num_valid_features, 1); 20 | 21 | % get the used features 22 | for i = 1:num_valid_features 23 | used_features(i) = any(strcmpi(valid_features{i}, features)); 24 | end 25 | 26 | % total number of used feature levels 27 | num_feature_levels = sum(feature_levels .* used_features); 28 | 29 | level = 0; 30 | 31 | % If grayscale image 32 | if size(im_patch, 3) == 1 33 | % Features that are available for grayscale sequances 34 | 35 | % Grayscale values (image intensity) 36 | out = single(im_patch)/255 - 0.5; 37 | else 38 | % Features that are available for color sequances 39 | 40 | % allocate space (for speed) 41 | out = zeros(size(im_patch, 1), size(im_patch, 2), num_feature_levels, 'single'); 42 | 43 | % Grayscale values (image intensity) 44 | if used_features(1) 45 | out(:,:,level+1) = single(rgb2gray(im_patch))/255 - 0.5; 46 | level = level + feature_levels(1); 47 | end 48 | 49 | % Color Names 50 | if used_features(2) 51 | if isempty(w2c) 52 | % load the RGB to color name matrix if not in input 53 | temp = load('w2crs'); 54 | w2c = temp.w2crs; 55 | end 56 | 57 | % extract color descriptor 58 | out(:,:,level+(1:10)) = im2c(single(im_patch), w2c, -2); 59 | level = level + feature_levels(2); 60 | end 61 | end -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/get_cnn_layers.m: -------------------------------------------------------------------------------- 1 | function feature_map = get_cnn_layers(im, fparams, gparams) 2 | 3 | % Get layers from a cnn. 4 | 5 | if size(im,3) == 1 6 | im = repmat(im, [1 1 3]); 7 | end 8 | 9 | im_sample_size = size(im); 10 | 11 | %preprocess the image 12 | if ~isequal(im_sample_size(1:2), fparams.net.meta.normalization.imageSize(1:2)) 13 | im = imresize(single(im), fparams.net.meta.normalization.imageSize(1:2)); 14 | else 15 | im = single(im); 16 | end 17 | 18 | % Normalize with average image 19 | im = bsxfun(@minus, im, fparams.net.meta.normalization.averageImage); 20 | 21 | if gparams.use_gpu 22 | im = gpuArray(im); 23 | cnn_feat = vl_simplenn(fparams.net, im,[],[],'CuDNN',true, 'Mode', 'test'); 24 | else 25 | cnn_feat = vl_simplenn(fparams.net, im, [], [], 'Mode', 'test'); 26 | end 27 | 28 | feature_map = cell(1,1,length(fparams.output_layer)); 29 | 30 | for k = 1:length(fparams.output_layer) 31 | if fparams.downsample_factor(k) == 1 32 | feature_map{k} = cnn_feat(fparams.output_layer(k) + 1).x(fparams.start_ind(k,1):fparams.end_ind(k,1), fparams.start_ind(k,2):fparams.end_ind(k,2), :, :); 33 | else 34 | feature_map{k} = vl_nnpool(cnn_feat(fparams.output_layer(k) + 1).x(fparams.start_ind(k,1):fparams.end_ind(k,1), fparams.start_ind(k,2):fparams.end_ind(k,2), :, :), fparams.downsample_factor(k), 'stride', fparams.downsample_factor(k), 'method', 'avg'); 35 | end 36 | end 37 | 38 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/get_colorspace.m: -------------------------------------------------------------------------------- 1 | function [ colorspace ] = get_colorspace(im, fparam, gparam ) 2 | 3 | [im_height, im_width, num_im_chan, num_images] = size(im); 4 | 5 | single_im = single(im)/255; 6 | 7 | if fparam.useForGray 8 | if num_im_chan == 3 9 | if num_images == 1 10 | t_colorspace = rgb2gray(single_im) - 0.5; 11 | else 12 | t_colorspace = zeros(im_height, im_width, 1, num_images, 'single'); 13 | for k = 1:num_images 14 | t_colorspace(:,:,:,k) = rgb2gray(single_im(:,:,:,k)) - 0.5; 15 | end 16 | end 17 | elseif num_im_chan == 1 18 | t_colorspace = single_im - 0.5; 19 | else 20 | except = MException('get_colorspace','Invalid input data, must have 1 or 3 dimensions'); 21 | throw(except); 22 | end 23 | elseif fparam.useForColor 24 | if num_im_chan == 3 25 | t_colorspace = single_im - 0.5; 26 | else 27 | except = MException('get_colorspace','Invalid input data, must have 3 dimensions for rgb'); 28 | throw(except); 29 | end 30 | end 31 | if gparam.cell_size > 1 32 | colorspace = average_feature_region(t_colorspace,gparam.cell_size); 33 | else 34 | colorspace = t_colorspace; 35 | end 36 | end 37 | 38 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/get_features.m: -------------------------------------------------------------------------------- 1 | function [feature_pixels, support_sz] = get_features(image, features, gparams, fg_size) 2 | 3 | if ~ iscell(features) 4 | features = {features}; 5 | end 6 | 7 | [im_height, im_width, num_im_chan, num_images] = size(image); 8 | 9 | colorImage = num_im_chan == 3; 10 | 11 | %compute total dimension of all features 12 | tot_feature_dim = 0; 13 | for n = 1:length(features) 14 | 15 | if ~isfield(features{n}.fparams,'useForColor') 16 | features{n}.fparams.useForColor = true; 17 | end 18 | 19 | if ~isfield(features{n}.fparams,'useForGray') 20 | features{n}.fparams.useForGray = true; 21 | end 22 | 23 | if (features{n}.fparams.useForColor && colorImage) || (features{n}.fparams.useForGray && ~colorImage) 24 | tot_feature_dim = tot_feature_dim + features{n}.fparams.nDim; 25 | end 26 | 27 | end 28 | 29 | if nargin < 4 || isempty(fg_size) 30 | if gparams.cell_size == -1 31 | fg_size = size(features{1}.getFeature(image,features{1}.fparams,gparams)); 32 | else 33 | fg_size = [floor(im_height/gparams.cell_size), floor(im_width/gparams.cell_size)]; 34 | end 35 | end 36 | 37 | % temporary hack for fixing deep features 38 | if gparams.cell_size == -1 39 | cf = features{1}; 40 | if (cf.fparams.useForColor && colorImage) || (cf.fparams.useForGray && ~colorImage) 41 | [feature_pixels, support_sz] = cf.getFeature(image,cf.fparams,gparams); 42 | end 43 | else 44 | %compute the feature set 45 | feature_pixels = zeros(fg_size(1),fg_size(2),tot_feature_dim, num_images, 'single'); 46 | 47 | currDim = 1; 48 | for n = 1:length(features) 49 | cf = features{n}; 50 | if (cf.fparams.useForColor && colorImage) || (cf.fparams.useForGray && ~colorImage) 51 | feature_pixels(:,:,currDim:(currDim+cf.fparams.nDim-1),:) = cf.getFeature(image,cf.fparams,gparams); 52 | currDim = currDim + cf.fparams.nDim; 53 | end 54 | end 55 | support_sz = [im_height, im_width]; 56 | end 57 | 58 | end -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/get_fhog.m: -------------------------------------------------------------------------------- 1 | function [ feature_image ] = get_fhog(im, fparam, gparam ) 2 | %extract fhog features using piotrs toolbox. Currently takes no parameters 3 | %except hog-cell-size 4 | if ~isfield(fparam, 'nOrients') 5 | fparam.nOrients = 9; 6 | end 7 | [im_height, im_width,~, num_images] = size(im); 8 | feature_image = zeros(floor(im_height/gparam.cell_size), floor(im_width/gparam.cell_size), fparam.nDim, num_images, 'single'); 9 | for k = 1:num_images 10 | hog_image = fhog(single(im(:,:,:,k)), gparam.cell_size, fparam.nOrients); 11 | %the last dimension is all 0 so we can discard it 12 | feature_image(:,:,:,k) = hog_image(:,:,1:end-1); 13 | end 14 | end -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/get_pixels.m: -------------------------------------------------------------------------------- 1 | function [ resized_patch ] = get_pixels(im, pos, sz, resize_target) 2 | 3 | if isscalar(sz) %square sub-window 4 | sz = [sz, sz]; 5 | end 6 | 7 | %make sure the size is not to small 8 | if sz(1) < 1 9 | sz(1) = 2; 10 | end 11 | if sz(2) < 1 12 | sz(2) = 2; 13 | end 14 | 15 | 16 | xs = floor(pos(2)) + (1:sz(2)) - floor(sz(2)/2); 17 | ys = floor(pos(1)) + (1:sz(1)) - floor(sz(1)/2); 18 | 19 | %check for out-of-bounds coordinates, and set them to the values at 20 | %the borders 21 | xs(xs < 1) = 1; 22 | ys(ys < 1) = 1; 23 | xs(xs > size(im,2)) = size(im,2); 24 | ys(ys > size(im,1)) = size(im,1); 25 | 26 | %extract image 27 | im_patch = im(ys, xs, :); 28 | 29 | if isempty(resize_target) 30 | resized_patch = im_patch; 31 | else 32 | resized_patch = mexResize(im_patch,resize_target,'auto'); 33 | end 34 | end 35 | 36 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/get_table_feature.m: -------------------------------------------------------------------------------- 1 | function [ features ] = get_table_feature(im, fparam, gparam) 2 | %get per-pixel features using a lookup table, if the gparam feature cell 3 | %size is set to something large than one, the resulting data will be 4 | %averaged in cells of the specified size. 5 | %tables are loaded dynamically when needed from the lookup_tables folder, 6 | %and stored in a persistent variable 7 | 8 | persistent tables; 9 | 10 | if isempty(tables) 11 | tables = {}; 12 | end 13 | 14 | tab_ind = 0; 15 | for k = 1:length(tables) 16 | if isfield(tables{k}, fparam.tablename) 17 | tab_ind = k; 18 | break; 19 | end 20 | end 21 | 22 | if tab_ind == 0 23 | tables{end+1} = load(['lookup_tables/' fparam.tablename]); 24 | tab_ind = length(tables); 25 | end 26 | 27 | if strcmp(tables{tab_ind}.inputType,'color') 28 | if size(im,3) ~= 3 29 | except = MException('cannot get colorfeature from non color image'); 30 | raise(except); 31 | end 32 | elseif strcmp(tables{tab_ind}.inputType,'gray') 33 | if size(im,3) == 3 34 | im_gray = zeros(size(im,1),size(im,2),1,size(im,4),'uint8'); 35 | for k = 1:size(im,4) 36 | im_gray(:,:,:,k) = rgb2gray(im(:,:,:,k)); 37 | end 38 | im = im_gray; 39 | end 40 | end 41 | 42 | %else extract the feature and return it 43 | temp_features = table_lookup(im,tables{tab_ind}.(fparam.tablename)); 44 | 45 | if gparam.cell_size > 1 46 | features = average_feature_region(temp_features,gparam.cell_size); 47 | else 48 | features = temp_features; 49 | end 50 | 51 | end 52 | 53 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/gradient2.m: -------------------------------------------------------------------------------- 1 | function [Gx,Gy] = gradient2( I ) 2 | % Compute numerical gradients along x and y directions. 3 | % 4 | % For 2D arrays identical to Matlab's gradient() with a spacing value of 5 | % h=1 but ~10-20x faster (due to mexed implementation). Like gradient(), 6 | % computes centered derivatives in interior of image and uncentered 7 | % derivatives along boundaries. For 3D arrays computes x and y gradient 8 | % separately for each channel and concatenates the results. 9 | % 10 | % This code requires SSE2 to compile and run (most modern Intel and AMD 11 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 12 | % 13 | % USAGE 14 | % [Gx,Gy] = gradient2( I ) 15 | % 16 | % INPUTS 17 | % I - [hxwxk] input k channel single image 18 | % 19 | % OUTPUTS 20 | % Gx - [hxwxk] x-gradient (horizontal) 21 | % Gy - [hxwxk] y-gradient (vertical) 22 | % 23 | % EXAMPLE 24 | % I=single(imread('peppers.png'))/255; 25 | % tic, [Gx1,Gy1]=gradient(I,1); toc 26 | % tic, [Gx2,Gy2]=gradient2(I); toc 27 | % isequal(Gx1,Gx2), isequal(Gy1,Gy2) 28 | % 29 | % See also gradient, gradientMag 30 | % 31 | % Piotr's Computer Vision Matlab Toolbox Version 3.00 32 | % Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com] 33 | % Licensed under the Simplified BSD License [see external/bsd.txt] 34 | 35 | [Gx,Gy]=gradientMex('gradient2',I); 36 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/gradientHist.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/feature/gradientHist.m -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/gradientMag.m: -------------------------------------------------------------------------------- 1 | function [M,O] = gradientMag( I, channel, normRad, normConst, full ) 2 | % Compute gradient magnitude and orientation at each image location. 3 | % 4 | % If input image has k>1 channels and channel=0, keeps gradient with 5 | % maximum magnitude (over all channels) at each location. Otherwise if 6 | % channel is between 1 and k computes gradient for the given channel. 7 | % If full==1 orientation is computed in [0,2*pi) else it is in [0,pi). 8 | % 9 | % If normRad>0, normalization is performed by first computing S, a smoothed 10 | % version of the gradient magnitude, then setting: M = M./(S + normConst). 11 | % S is computed by S = convTri( M, normRad ). 12 | % 13 | % This code requires SSE2 to compile and run (most modern Intel and AMD 14 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 15 | % 16 | % USAGE 17 | % [M,O] = gradientMag( I, [channel], [normRad], [normConst], [full] ) 18 | % 19 | % INPUTS 20 | % I - [hxwxk] input k channel single image 21 | % channel - [0] if>0 color channel to use for gradient computation 22 | % normRad - [0] normalization radius (no normalization if 0) 23 | % normConst - [.005] normalization constant 24 | % full - [0] if true compute angles in [0,2*pi) else in [0,pi) 25 | % 26 | % OUTPUTS 27 | % M - [hxw] gradient magnitude at each location 28 | % O - [hxw] approximate gradient orientation modulo PI 29 | % 30 | % EXAMPLE 31 | % I=rgbConvert(imread('peppers.png'),'gray'); 32 | % [Gx,Gy]=gradient2(I); M=sqrt(Gx.^2+Gy.^2); O=atan2(Gy,Gx); 33 | % full=0; [M1,O1]=gradientMag(I,0,0,0,full); 34 | % D=abs(M-M1); mean2(D), if(full), o=pi*2; else o=pi; end 35 | % D=abs(O-O1); D(~M)=0; D(D>o*.99)=o-D(D>o*.99); mean2(abs(D)) 36 | % 37 | % See also gradient, gradient2, gradientHist, convTri 38 | % 39 | % Piotr's Computer Vision Matlab Toolbox Version 3.23 40 | % Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com] 41 | % Licensed under the Simplified BSD License [see external/bsd.txt] 42 | 43 | if(nargin<1 || isempty(I)), M=single([]); O=M; return; end 44 | if(nargin<2 || isempty(channel)), channel=0; end 45 | if(nargin<3 || isempty(normRad)), normRad=0; end 46 | if(nargin<4 || isempty(normConst)), normConst=.005; end 47 | if(nargin<5 || isempty(full)), full=0; end 48 | 49 | if(nargout<=1), M=gradientMex('gradientMag',I,channel,full); 50 | else [M,O]=gradientMex('gradientMag',I,channel,full); end 51 | 52 | if( normRad==0 ), return; end; S = convTri( M, normRad ); 53 | gradientMex('gradientMagNorm',M,S,normConst); % operates on M 54 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/gradientMex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/feature/gradientMex.mexa64 -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/gradientMex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/feature/gradientMex.mexmaci64 -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/gradientMex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/feature/gradientMex.mexw64 -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/im2c.m: -------------------------------------------------------------------------------- 1 | function out=im2c(im,w2c,color) 2 | % input im should be DOUBLE ! 3 | % color=0 is color names out 4 | % color=-1 is colored image with color names out 5 | % color=1-11 is prob of colorname=color out; 6 | % color=-1 return probabilities 7 | % order of color names: black , blue , brown , grey , green , orange , pink , purple , red , white , yellow 8 | color_values = { [0 0 0] , [0 0 1] , [.5 .4 .25] , [.5 .5 .5] , [0 1 0] , [1 .8 0] , [1 .5 1] , [1 0 1] , [1 0 0] , [1 1 1 ] , [ 1 1 0 ] }; 9 | 10 | if(nargin<3) 11 | color=0; 12 | end 13 | 14 | RR=im(:,:,1);GG=im(:,:,2);BB=im(:,:,3); 15 | 16 | index_im = 1+floor(RR(:)/8)+32*floor(GG(:)/8)+32*32*floor(BB(:)/8); 17 | 18 | if(color==0) 19 | [max1,w2cM]=max(w2c,[],2); 20 | out=reshape(w2cM(index_im(:)),size(im,1),size(im,2)); 21 | end 22 | 23 | if(color>0 && color < 12) 24 | w2cM=w2c(:,color); 25 | out=reshape(w2cM(index_im(:)),size(im,1),size(im,2)); 26 | end 27 | 28 | if(color==-1) 29 | out=im; 30 | [max1,w2cM]=max(w2c,[],2); 31 | out2=reshape(w2cM(index_im(:)),size(im,1),size(im,2)); 32 | 33 | for jj=1:size(im,1) 34 | for ii=1:size(im,2) 35 | out(jj,ii,:)=color_values{out2(jj,ii)}'*255; 36 | end 37 | end 38 | end 39 | 40 | if(color==-2) 41 | out=reshape(w2c(index_im,:),size(im,1),size(im,2),size(w2c,2)); 42 | end 43 | -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/lookup_tables/CNnorm.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/feature/lookup_tables/CNnorm.mat -------------------------------------------------------------------------------- /JSAR_Re_lib/feature/w2crs.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/feature/w2crs.mat -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/average_feature_region.m: -------------------------------------------------------------------------------- 1 | function [ region_image ] = average_feature_region(im, region_size) 2 | % compute cell wise averages, where a cell is a region_size*region_sized 3 | % region in the image. Input can be uint8t, single or double matrices 4 | % of arbitrary dimension 5 | 6 | region_area = region_size.^2; 7 | 8 | if isa(im,'double') || isa(im,'single') || isa(im,'gpuArray') 9 | maxval = 1.0; 10 | elseif isa(im,'unit8') 11 | maxval = 255; 12 | end 13 | 14 | % compute the integral image 15 | iImage = integralVecImage(im); 16 | 17 | % region indices 18 | i1 = (region_size:region_size:size(im,1)) + 1; 19 | i2 = (region_size:region_size:size(im,2)) + 1; 20 | 21 | % sum over region, divided by number of elements, and normalize to [0,1] 22 | % range if integer image 23 | region_image = (iImage(i1,i2,:,:) - iImage(i1,i2-region_size,:,:) - iImage(i1-region_size,i2,:,:) + iImage(i1-region_size,i2-region_size,:,:)) ./ (region_area * maxval); 24 | 25 | end 26 | 27 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/cosine_calculate.m: -------------------------------------------------------------------------------- 1 | function cosine_score = cosine_calculate(im,pos,target_sz,sz,features,global_feat_params,gtt) 2 | target_pixel=get_pixels(im, pos, round(target_sz), sz); 3 | tt=get_features(target_pixel,features,global_feat_params); 4 | var=(gtt-tt).^2; 5 | s1=gtt.^2; 6 | s2=tt.^2; 7 | cosine_score=100*sum(var(:))/(sum(s1(:))*sum(s2(:))); 8 | end 9 | 10 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/crop_scale_sample.m: -------------------------------------------------------------------------------- 1 | function out = crop_scale_sample(im, pos, base_target_sz, scaleFactors, scale_window, scale_model_sz) 2 | 3 | % out = get_scale_sample(im, pos, base_target_sz, scaleFactors, scale_window, scale_model_sz) 4 | % 5 | % Extracts a sample for the scale filter at the current 6 | % location and scale. 7 | 8 | nScales = length(scaleFactors); 9 | 10 | for s = 1:nScales 11 | patch_sz = floor(base_target_sz * scaleFactors(s)); 12 | patch_sz=max(patch_sz,2); 13 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 14 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 15 | 16 | % check for out-of-bounds coordinates, and set them to the values at 17 | % the borders 18 | xs(xs < 1) = 1; 19 | ys(ys < 1) = 1; 20 | xs(xs > size(im,2)) = size(im,2); 21 | ys(ys > size(im,1)) = size(im,1); 22 | 23 | % extract image 24 | im_patch = im(ys, xs, :); 25 | 26 | % resize image to model size 27 | im_patch_resized = mexResize(im_patch, scale_model_sz, 'auto'); 28 | % extract scale features 29 | temp_hog = fhog(single(im_patch_resized), 4); 30 | 31 | temp(:,:,1:31) = temp_hog(:,:,1:31); 32 | 33 | 34 | if s == 1 35 | out = zeros(numel(temp), nScales, 'single'); 36 | end 37 | out(:,s)=temp(:); 38 | % if color image 39 | 40 | % window 41 | out(:,s) = temp(:) * scale_window(s); 42 | end -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/extract_template.m: -------------------------------------------------------------------------------- 1 | function [gtt,rd_update,redetection] = extract_template(im,pos,target_sz,sz,features,global_feat_params,redetection) 2 | gt_pixel=get_pixels(im, pos, target_sz, sz); 3 | gtt=get_features(gt_pixel,features,global_feat_params); 4 | if redetection 5 | redetection=0; 6 | end 7 | rd_update=1; 8 | end 9 | 10 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/get_size_sample.m: -------------------------------------------------------------------------------- 1 | function out = get_size_sample(im, pos, base_target_sz, sv_factors, arc_factors, size_model_sz) 2 | 3 | num_sv= length(sv_factors); 4 | num_arc=length(arc_factors); 5 | 6 | for s = 1:num_sv 7 | for a=1:num_arc 8 | patch_sz = floor(base_target_sz * sv_factors(s)); 9 | patch_sz(1) = floor(patch_sz(1)*sqrt(arc_factors(a))); 10 | patch_sz(2) = floor(patch_sz(2)/sqrt(arc_factors(a))); 11 | %make sure the size is not to small 12 | patch_sz = max(patch_sz, 2); 13 | 14 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 15 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 16 | 17 | %check for out-of-bounds coordinates, and set them to the values at 18 | %the borders 19 | xs(xs < 1) = 1; 20 | ys(ys < 1) = 1; 21 | xs(xs > size(im,2)) = size(im,2); 22 | ys(ys > size(im,1)) = size(im,1); 23 | 24 | %extract image 25 | im_patch = im(ys, xs, :); 26 | 27 | % resize image to model size 28 | % im_patch_resized = mexResize(im_patch, size_model_sz, 'auto'); 29 | % extract scale features 30 | 31 | % im_patch_resized = mexResize(im_patch_resized,size_model_sz/hog_box_cell_size,'auto'); 32 | % temp(:,:,1)=single(rgb2gray(im_patch_resized))/255-0.5; 33 | % temp(:,:,2:11)=fcn(im_patch_resized, 'cn', w2c); 34 | % resize image to model size 35 | im_patch_resized = mexResize(im_patch, size_model_sz, 'auto'); 36 | 37 | % extract scale features 38 | temp_hog = fhog(single(im_patch_resized),4); 39 | temp = temp_hog(:,:,1:31); 40 | 41 | if a==1&&s==1 42 | out= zeros( num_sv, num_arc,numel(temp),'single'); 43 | end 44 | 45 | % out(s,a,:) = temp(:)*window(s,a); 46 | out(s,a,:) = temp(:); 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/init_features.m: -------------------------------------------------------------------------------- 1 | function [features,im,colorImage] = init_features(params) 2 | try 3 | im = imread([params.video_path '/img/' params.s_frames{1}]); 4 | catch 5 | try 6 | im = imread(params.s_frames{1}); 7 | catch 8 | im = imread([params.video_path '/' params.s_frames{1}]); 9 | end 10 | end 11 | if size(im,3) == 3 12 | if all(all(im(:,:,1) == im(:,:,2))) 13 | colorImage = false; 14 | else 15 | colorImage = true; 16 | end 17 | else 18 | colorImage = false; 19 | end 20 | 21 | % compute feature dimensionality 22 | features = params.t_features; 23 | feature_dim = 0; 24 | for n = 1:length(features) 25 | 26 | if ~isfield(features{n}.fparams,'useForColor') 27 | features{n}.fparams.useForColor = true; 28 | end 29 | 30 | if ~isfield(features{n}.fparams,'useForGray') 31 | features{n}.fparams.useForGray = true; 32 | end 33 | 34 | if (features{n}.fparams.useForColor && colorImage) || (features{n}.fparams.useForGray && ~colorImage) 35 | feature_dim = feature_dim + features{n}.fparams.nDim; 36 | end 37 | end 38 | 39 | if size(im,3) > 1 && colorImage == false 40 | im = im(:,:,1); 41 | end 42 | 43 | end 44 | 45 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/init_gauss_win.m: -------------------------------------------------------------------------------- 1 | function [y0,cos_window] = init_gauss_win(params,base_target_sz,featureRatio,use_sz) 2 | % construct the label function- correlation output, 2D gaussian function, 3 | % with a peak located upon the target 4 | 5 | output_sigma = sqrt(prod(floor(base_target_sz/featureRatio))) * params.output_sigma_factor; 6 | rg = circshift(-floor((use_sz(1)-1)/2):ceil((use_sz(1)-1)/2), [0 -floor((use_sz(1)-1)/2)]); 7 | cg = circshift(-floor((use_sz(2)-1)/2):ceil((use_sz(2)-1)/2), [0 -floor((use_sz(2)-1)/2)]); 8 | [rs, cs] = ndgrid(rg,cg); 9 | y0 = exp(-0.5 * (((rs.^2 + cs.^2) / output_sigma^2))); 10 | % construct cosine window 11 | cos_window = single(hann(use_sz(1)+2)*hann(use_sz(2)+2)'); 12 | cos_window = cos_window(2:end-1,2:end-1); 13 | end 14 | 15 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/init_gaussian.asv: -------------------------------------------------------------------------------- 1 | function [outputArg1,outputArg2] = init_gaussian() 2 | % construct the label function- correlation output, 2D gaussian function, 3 | % with a peak located upon the target 4 | 5 | output_sigma = sqrt(prod(floor(base_target_sz/featureRatio))) * output_sigma_factor; 6 | rg = circshift(-floor((use_sz(1)-1)/2):ceil((use_sz(1)-1)/2), [0 -floor((use_sz(1)-1)/2)]); 7 | cg = circshift(-floor((use_sz(2)-1)/2):ceil((use_sz(2)-1)/2), [0 -floor((use_sz(2)-1)/2)]); 8 | [rs, cs] = ndgrid(rg,cg); 9 | y = exp(-0.5 * (((rs.^2 + cs.^2) / output_sigma^2))); 10 | yf = fft2(y); % FFT of y. 11 | 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/init_regwindow.m: -------------------------------------------------------------------------------- 1 | function [range_h,range_w,reg_window]=init_regwindow(sz,target_sz,params) 2 | reg_scale =target_sz; 3 | use_sz = sz; 4 | reg_window = ones(use_sz) * params.reg_window_max; 5 | range = zeros(numel(reg_scale), 2); 6 | 7 | % determine the target center and range in the regularization windows 8 | for j = 1:numel(reg_scale) 9 | range(j,:) = [0, reg_scale(j) - 1] - floor(reg_scale(j) / 2); 10 | end 11 | center = floor((use_sz + 1)/ 2) + mod(use_sz + 1,2); 12 | range_h = (center(1)+ range(1,1)) : (center(1) + range(1,2)); 13 | range_w = (center(2)+ range(2,1)) : (center(2) + range(2,2)); 14 | reg_window(range_h, range_w) = params.reg_window_min; 15 | 16 | 17 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/init_size.m: -------------------------------------------------------------------------------- 1 | function [CurrentSvFactor,CurrentArcFactor,base_target_sz,reg_sz,sz,use_sz] = init_size(params,target_sz,search_area,featureRatio) 2 | if search_area > params.max_image_sample_size 3 | CurrentSvFactor = sqrt(search_area /params.max_image_sample_size); 4 | elseif search_area 1 && colorImage == false 13 | im = im(:,:,1); 14 | end 15 | end 16 | 17 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/re_detection.m: -------------------------------------------------------------------------------- 1 | function [pos,target_sz,success] = re_detection(params,Bbs,pos,target_sz,im,rg_f,features,global_feat_params,use_sz,search_area_scale,thred,featureRatio) 2 | 3 | response_max=zeros(size(Bbs,1),1); 4 | reability=zeros(size(Bbs,1),1); 5 | for i=1:size(Bbs,1) 6 | proposal_pos=[Bbs(i,2)+floor(Bbs(i,4)/2),Bbs(i,1)+floor(Bbs(i,3)/2)]; 7 | proposal_size=[Bbs(i,4),Bbs(i,3)]; 8 | search_area = prod(proposal_size * search_area_scale); 9 | [currentScaleFactor,~,~,~,sz,~] = init_size(params,proposal_size,search_area,featureRatio); 10 | proposal_pixel=get_pixels(im, proposal_pos, round(sz*currentScaleFactor), 4*[size(rg_f,1),size(rg_f,2)]); 11 | pt=get_features(proposal_pixel,features,global_feat_params); 12 | % construct cosine window 13 | cos_window = single(hann(size(pt,1)+2)*hann(size(pt,2)+2)'); 14 | cos_window = cos_window(2:end-1,2:end-1); 15 | ptf=fft2(bsxfun(@times,pt,cos_window)); 16 | presponsef=permute(sum(bsxfun(@times, conj(rg_f), ptf), 3), [1 2 4 3]); 17 | presponsef_padded = resizeDFT2(presponsef, use_sz); 18 | presponse = ifft2(presponsef_padded, 'symmetric'); 19 | response_max(i)=max(presponse(:)); 20 | reability(i)=response_max(i); 21 | if response_max(i)0 26 | pro_index= reability == max(reability); 27 | redet_gt=Bbs(pro_index,1:4); 28 | pos=[redet_gt(2)+floor(redet_gt(4)/2),redet_gt(1)+floor(redet_gt(3)/2)]; 29 | target_sz=[redet_gt(4),redet_gt(3)]; 30 | success=1; 31 | else 32 | success=0; 33 | end 34 | end 35 | 36 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/run_detection.m: -------------------------------------------------------------------------------- 1 | function [xtf,pos,translation_vec,response] = run_detection(im,pos,sz,CurrentSvFactor,features,cos_window,g_f,global_feat_params,use_sz,ky,kx,newton_iterations,featureRatio) 2 | pixel_template = get_pixels(im, pos, round(sz*CurrentSvFactor), sz); 3 | xtf = fft2(bsxfun(@times,get_features(pixel_template,features,global_feat_params),cos_window)); 4 | responsef = sum(bsxfun(@times, conj(g_f), xtf), 3); 5 | % if we undersampled features, we want to interpolate the 6 | % response so it has the same size as the image patch 7 | responsef_padded = resizeDFT2(responsef, use_sz); 8 | % response in the spatial domain 9 | response = ifft2(responsef_padded, 'symmetric'); 10 | responsef_padded=fft2(response); 11 | % find maximum peak 12 | [disp_row, disp_col] = resp_newton(response, responsef_padded, newton_iterations, ky, kx, use_sz); 13 | % calculate translation 14 | translation_vec = round([disp_row, disp_col] * featureRatio * CurrentSvFactor); 15 | % update position 16 | pos = pos + translation_vec; 17 | end 18 | 19 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/run_training.m: -------------------------------------------------------------------------------- 1 | function [g_f,g_pre] = run_training(xf,use_sz,g_pre,params,mu,yf,w) 2 | g_f = single(zeros(size(xf))); 3 | h_f = g_f; 4 | l_f = h_f; 5 | gamma = 1; 6 | betha = 10; 7 | gamma_max = 10000; 8 | % ADMM solution 9 | T = prod(use_sz); 10 | S_xx = sum(conj(xf) .* xf, 3); 11 | Sg_pre= sum(conj(xf) .* g_pre, 3); 12 | Sgx_pre= bsxfun(@times, xf, Sg_pre); 13 | iter = 1; 14 | while (iter <= params.admm_iterations) 15 | % subproblem g 16 | B = S_xx + T * (gamma + mu); 17 | Shx_f = sum(conj(xf) .* h_f, 3); 18 | Slx_f = sum(conj(xf) .* l_f, 3); 19 | g_f = ((1/(T*(gamma + mu)) * bsxfun(@times, yf, xf)) - ((1/(gamma + mu)) * l_f) +(gamma/(gamma + mu)) * h_f) + (mu/(gamma + mu)) * g_pre - ... 20 | bsxfun(@rdivide,(1/(T*(gamma + mu)) * bsxfun(@times, xf, (S_xx .* yf)) + (mu/(gamma + mu)) * Sgx_pre- ... 21 | (1/(gamma + mu))* (bsxfun(@times, xf, Slx_f)) +(gamma/(gamma + mu))* (bsxfun(@times, xf, Shx_f))), B); 22 | % subproblem h 23 | lhd= T ./ (params.admm_lambda*w .^2 + gamma*T); 24 | X=ifft2(gamma*(g_f + l_f)); 25 | h=bsxfun(@times,lhd,X); 26 | h_f = fft2(h); 27 | % update h 28 | l_f = l_f + (gamma * (g_f - h_f)); 29 | % update gamma 30 | gamma = min(betha* gamma, gamma_max); 31 | iter = iter+1; 32 | end 33 | % save the trained filters 34 | g_pre= g_f; 35 | 36 | end 37 | 38 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/search_size.m: -------------------------------------------------------------------------------- 1 | function [xs,CurrentSvFactor,CurrentArcFactor,size_vector] = search_size(sf_num,sf_den,im,pos,base_target_sz,CurrentSvFactor,CurrentArcFactor,svFactors,arcFactors,size_model_sz,min_sv_factor,max_sv_factor,min_arc_factor,max_arc_factor,params) 2 | % update position 3 | 4 | xs = get_size_sample(im, pos, base_target_sz, CurrentSvFactor * svFactors, CurrentArcFactor*arcFactors,size_model_sz); 5 | xsf = fft2(xs); 6 | scale_response = ifft2((sum(sf_num .* xsf, 3) ./ (sf_den + params.size_lambda)),'symmetric'); 7 | 8 | % find the maximum scale response 9 | [recovered_sv,recovered_arc] = find(scale_response == max(scale_response(:)), 1); 10 | size_vector=[recovered_sv-floor(size(scale_response,1)/2)-1,recovered_arc-floor(size(scale_response,2)/2)-1]; 11 | % update the scale 12 | CurrentSvFactor = CurrentSvFactor * svFactors(recovered_sv); 13 | if CurrentSvFactor < min_sv_factor 14 | CurrentSvFactor = min_sv_factor; 15 | elseif CurrentSvFactor > max_sv_factor 16 | CurrentSvFactor = max_sv_factor; 17 | end 18 | CurrentArcFactor=CurrentArcFactor*arcFactors(recovered_arc); 19 | if CurrentArcFactor < min_arc_factor 20 | CurrentArcFactor = min_arc_factor; 21 | elseif CurrentArcFactor > max_arc_factor 22 | CurrentArcFactor = max_arc_factor; 23 | end 24 | 25 | end 26 | 27 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/shift_sample_scale.m: -------------------------------------------------------------------------------- 1 | function out = shift_sample_scale(im, pos, base_target_sz,xs,recovered_scale,scaleFactors,scale_window,scale_model_sz) 2 | nScales = length(scaleFactors); 3 | out = zeros(size(xs,1), nScales, 'single'); 4 | shift_pos=recovered_scale-ceil(nScales/2); 5 | if shift_pos==0 6 | out=xs; 7 | elseif shift_pos>0 8 | for j=1:nScales-shift_pos 9 | out(:,j)=xs(:,j+shift_pos)/(scale_window(j+shift_pos)+1e-5)*scale_window(j); 10 | end 11 | for i=1:shift_pos 12 | patch_sz = floor(base_target_sz * scaleFactors(nScales-shift_pos+i)); 13 | patch_sz = max(patch_sz, 2); 14 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 15 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 16 | % check for out-of-bounds coordinates, and set them to the values at 17 | % the borders 18 | xs(xs < 1) = 1; 19 | ys(ys < 1) = 1; 20 | xs(xs > size(im,2)) = size(im,2); 21 | ys(ys > size(im,1)) = size(im,1); 22 | 23 | % extract image 24 | im_patch = im(ys, xs, :); 25 | 26 | % resize image to model size 27 | im_patch_resized = mexResize(im_patch, scale_model_sz, 'auto'); 28 | 29 | % extract scale features 30 | temp_hog = fhog(single(im_patch_resized), 4); 31 | 32 | 33 | temp(:,:,1:31) = temp_hog(:,:,1:31); 34 | out(:,nScales-shift_pos+i)=temp(:); 35 | % window 36 | out(:,nScales-shift_pos+i) = temp(:) * scale_window(nScales-shift_pos+i); 37 | end 38 | else 39 | for j=1:nScales+shift_pos 40 | out(:,j-shift_pos)=xs(:,j)/(scale_window(j)+1e-5).*scale_window(j-shift_pos); 41 | end 42 | for i=1:-shift_pos 43 | patch_sz = floor(base_target_sz * scaleFactors(i)); 44 | patch_sz = max(patch_sz, 2); 45 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 46 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 47 | % check for out-of-bounds coordinates, and set them to the values at 48 | % the borders 49 | xs(xs < 1) = 1; 50 | ys(ys < 1) = 1; 51 | xs(xs > size(im,2)) = size(im,2); 52 | ys(ys > size(im,1)) = size(im,1); 53 | 54 | % extract image 55 | im_patch = im(ys, xs, :); 56 | 57 | % resize image to model size 58 | im_patch_resized = mexResize(im_patch, scale_model_sz, 'auto'); 59 | 60 | % extract scale features 61 | temp_hog = fhog(single(im_patch_resized), 4); 62 | 63 | 64 | temp(:,:,1:31) = temp_hog(:,:,1:31); 65 | 66 | % window 67 | out(:,i) = temp(:) * scale_window(i); 68 | out(:,i)=temp(:); 69 | end 70 | end 71 | 72 | -------------------------------------------------------------------------------- /JSAR_Re_lib/implementation/size_factor.m: -------------------------------------------------------------------------------- 1 | function [ysf,svFactors,arcFactors,size_model_sz,min_sv_factor,max_sv_factor,min_arc_factor,max_arc_factor] = size_factor(params,target_sz,sz,base_target_sz,im) 2 | %% SCALE ADAPTATION INITIALIZATION 3 | % parameters for sv and arc estimation 4 | sv_sigma = sqrt(params.num_sv) *params.sv_sigma_factor; 5 | arc_sigma=sqrt(params.num_arc)*params.arc_sigma_factor; 6 | svg= (1:params.num_sv) - ceil(params.num_sv/2); 7 | arcg=(1:params.num_arc) - ceil(params.num_arc/2); 8 | [svs, arcs] = ndgrid(svg,arcg); 9 | ys = exp(-0.5 * ((svs.^2 / sv_sigma^2)+(arcs.^2/arc_sigma^2))); 10 | ysf = fft2(ys); 11 | 12 | ss = 1:params.num_sv; 13 | as=1:params.num_arc; 14 | svFactors = params.sv_step.^(ceil(params.num_sv/2) - ss); 15 | arcFactors=params.arc_step.^(ceil(params.num_arc/2) - as); 16 | 17 | if params.size_model_factor^2 * prod(target_sz) > params.size_model_max_area 18 | params.size_model_factor = sqrt(params.size_model_max_area/prod(target_sz)); 19 | end 20 | 21 | if prod(target_sz) > params.size_model_max_area 22 | params.size_model_factor = sqrt(params.size_model_max_area/prod(target_sz)); 23 | end 24 | size_model_sz = floor(target_sz* params.size_model_factor); 25 | 26 | % set maximum and minimum scales 27 | min_sv_factor = params.sv_step ^ ceil(log(max(20./sz)) / log(params.sv_step)); 28 | max_sv_factor = params.sv_step ^ floor(log(min([size(im,1) size(im,2)] ./ base_target_sz)) / (log(params.sv_step))); 29 | min_arc_factor =1.5*1/params.search_area_scale^2*(target_sz(1)/target_sz(2)); 30 | max_arc_factor =params.search_area_scale^2/(1.5*target_sz(1)/target_sz(2)); 31 | 32 | end 33 | 34 | -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/integralVecImage.m: -------------------------------------------------------------------------------- 1 | function intImage = integralVecImage(I) 2 | %integralImage Compute integral image. 3 | % J = integralImage(I) computes integral image of an intensity image I. 4 | % The output integral image, J, is zero padded on top and left, resulting 5 | % in size(J) = size(I) + 1. This facilitates easy computation of pixel 6 | % sums along all image boundaries. Integral image, J, is essentially 7 | % a padded version of CUMSUM(CUMSUM(I),2). 8 | % 9 | % Class Support 10 | % ------------- 11 | % Intensity image I can be any numeric class. The class of output 12 | % integral image, J, is double. 13 | % 14 | % Example 15 | % ------- 16 | % % Compute the integral image and use it to compute sum of pixels 17 | % % over a rectangular region in I. 18 | % I = magic(5) 19 | % 20 | % % define rectangular region as 21 | % % [startingRow, startingColumn, endingRow, endingColumn] 22 | % [sR sC eR eC] = deal(1, 3, 2, 4); 23 | % 24 | % % compute the sum over the region using the integral image 25 | % J = integralImage(I); 26 | % regionSum = J(eR+1,eC+1) - J(eR+1,sC) - J(sR,eC+1) + J(sR,sC) 27 | % 28 | % See also integralFilter, CUMSUM 29 | 30 | % Copyright 2010 The MathWorks, Inc. 31 | 32 | % References: 33 | % P.A. Viola and M.J. Jones. Rapid object detection using boosted 34 | % cascade of simple features. In CVPR (1), pages 511-518, 2001. 35 | % 36 | %#codegen 37 | %#ok<*EMCLS> 38 | %#ok<*EMCA> 39 | 40 | % validateattributes(I, {'numeric','logical'}, {'2d', 'nonsparse', 'real'},... 41 | % 'integralImage', 'I'); 42 | 43 | if ~isempty(I) 44 | intImage = zeros(size(I,1)+1, size(I,2)+1, size(I,3), size(I,4), 'single'); 45 | intImage(2:end, 2:end, :, :) = cumsum(cumsum(I,1),2); 46 | else 47 | intImage = []; 48 | end 49 | 50 | -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mexResize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mex.h" 5 | #include "MxArray.hpp" 6 | #include 7 | 8 | #include 9 | 10 | using namespace std; 11 | using namespace cv; 12 | 13 | /* 14 | * Use opencv function to resample image quickly 15 | */ 16 | 17 | // matlab entry point 18 | // dst = resize(src, scale) 19 | // image should be color with double values 20 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { 21 | if (nrhs < 2){ 22 | mexErrMsgTxt("Wrong number of inputs"); 23 | } 24 | if (nlhs != 1){ 25 | mexErrMsgTxt("Wrong number of outputs"); 26 | } 27 | 28 | vector rhs(prhs,prhs+nrhs); 29 | 30 | //convert input data to opencv matrix 31 | Mat img = rhs[0].toMat(); 32 | Mat imgr; 33 | Size s = rhs[1].toSize(); 34 | Size newSize = Size(s.height,s.width); 35 | Size oldSize = img.size(); 36 | //interpolation method 37 | int interpolation = INTER_LINEAR; 38 | 39 | //if interpolation method provided set it 40 | if(nrhs == 3){ 41 | string interp = rhs[2].toString(); 42 | if(interp.compare("antialias") == 0){ 43 | interpolation = INTER_AREA; 44 | }else if(interp.compare("linear") == 0){ 45 | interpolation = INTER_LINEAR; 46 | }else if(interp.compare("auto") == 0){ //if we are zooming, use linear else use area interpolation 47 | //old array has width and height swapped, newArray does not 48 | if(newSize.width > oldSize.height){ 49 | interpolation = INTER_LINEAR; 50 | }else{ 51 | interpolation = INTER_AREA; 52 | } 53 | }else{ 54 | mexErrMsgTxt("Invalid interpolation provided, valid is linear (default), antialias, auto"); 55 | } 56 | } 57 | 58 | //use opencv resize function 59 | resize(img,imgr,newSize,0,0,interpolation); 60 | //convert back to matlab representation 61 | plhs[0] = MxArray(imgr); 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mexResize.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mexResize.mexa64 -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mexResize.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mexResize.mexmaci64 -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mexResize.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mexResize.mexw64 -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mtimesx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mtimesx.c -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mtimesx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mtimesx.m -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mtimesx.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mtimesx.mexa64 -------------------------------------------------------------------------------- /JSAR_Re_lib/utils/mtimesx.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_Re_lib/utils/mtimesx.mexmaci64 -------------------------------------------------------------------------------- /JSAR_lib/average_feature_region.m: -------------------------------------------------------------------------------- 1 | function [ region_image ] = average_feature_region(im, region_size) 2 | % compute cell wise averages, where a cell is a region_size*region_sized 3 | % region in the image. Input can be uint8t, single or double matrices 4 | % of arbitrary dimension 5 | 6 | region_area = region_size.^2; 7 | 8 | if isa(im,'double') || isa(im,'single') || isa(im,'gpuArray') 9 | maxval = 1.0; 10 | elseif isa(im,'unit8') 11 | maxval = 255; 12 | end 13 | 14 | % compute the integral image 15 | iImage = integralVecImage(im); 16 | 17 | % region indices 18 | i1 = (region_size:region_size:size(im,1)) + 1; 19 | i2 = (region_size:region_size:size(im,2)) + 1; 20 | 21 | % sum over region, divided by number of elements, and normalize to [0,1] 22 | % range if integer image 23 | region_image = (iImage(i1,i2,:,:) - iImage(i1,i2-region_size,:,:) - iImage(i1-region_size,i2,:,:) + iImage(i1-region_size,i2-region_size,:,:)) ./ (region_area * maxval); 24 | 25 | end 26 | 27 | -------------------------------------------------------------------------------- /JSAR_lib/computeArea.m: -------------------------------------------------------------------------------- 1 | 2 | function areaBB = computeArea(bb) 3 | %computes area of the bb=[xmin ymin xmax ymax] 4 | 5 | if ((bb(1) > bb(3)) || (bb(2) > bb(4))) 6 | areaBB = 0; 7 | else 8 | areaBB = (bb(3) - bb(1) + 1) * (bb(4) - bb(2) + 1); 9 | end -------------------------------------------------------------------------------- /JSAR_lib/computeIntersectionArea.m: -------------------------------------------------------------------------------- 1 | function areaIntersection = computeIntersectionArea(bb1,bb2) 2 | %compute intersection anrea of bb1 and bb2 3 | %bb1 and bb2 - bounding boxes 4 | %bbi = [xmin ymin xmax ymax] for i=1,2 5 | 6 | xmin = max(bb1(1),bb2(1)); 7 | xmax = min(bb1(3),bb2(3)); 8 | ymin = max(bb1(2),bb2(2)); 9 | ymax = min(bb1(4),bb2(4)); 10 | 11 | areaIntersection = computeArea([xmin ymin xmax ymax]); 12 | 13 | end -------------------------------------------------------------------------------- /JSAR_lib/computePascalScore.m: -------------------------------------------------------------------------------- 1 | function pascalScore = computePascalScore(bb1,bb2) 2 | %compute the Pascal score of the bb1, bb2 (intersection/union) 3 | 4 | intersectionArea = computeIntersectionArea(bb1,bb2); 5 | pascalScore = intersectionArea/(computeArea(bb1)+computeArea(bb2)-intersectionArea); 6 | return -------------------------------------------------------------------------------- /JSAR_lib/fcn.m: -------------------------------------------------------------------------------- 1 | function out = fcn(im_patch, features, w2c) 2 | 3 | % out = get_feature_map(im_patch, features, w2c) 4 | % 5 | % Extracts the given features from the image patch. w2c is the 6 | % Color Names matrix, if used. 7 | 8 | if nargin < 3 9 | w2c = []; 10 | end 11 | 12 | % the names of the features that can be used 13 | valid_features = {'gray', 'cn'}; 14 | 15 | % the dimension of the valid features 16 | feature_levels = [1 10]'; 17 | 18 | num_valid_features = length(valid_features); 19 | used_features = false(num_valid_features, 1); 20 | 21 | % get the used features 22 | for i = 1:num_valid_features 23 | used_features(i) = any(strcmpi(valid_features{i}, features)); 24 | end 25 | 26 | % total number of used feature levels 27 | num_feature_levels = sum(feature_levels .* used_features); 28 | 29 | level = 0; 30 | 31 | % If grayscale image 32 | if size(im_patch, 3) == 1 33 | % Features that are available for grayscale sequances 34 | 35 | % Grayscale values (image intensity) 36 | out = single(im_patch)/255 - 0.5; 37 | else 38 | % Features that are available for color sequances 39 | 40 | % allocate space (for speed) 41 | out = zeros(size(im_patch, 1), size(im_patch, 2), num_feature_levels, 'single'); 42 | 43 | % Grayscale values (image intensity) 44 | if used_features(1) 45 | out(:,:,level+1) = single(rgb2gray(im_patch))/255 - 0.5; 46 | level = level + feature_levels(1); 47 | end 48 | 49 | % Color Names 50 | if used_features(2) 51 | if isempty(w2c) 52 | % load the RGB to color name matrix if not in input 53 | temp = load('w2crs'); 54 | w2c = temp.w2crs; 55 | end 56 | 57 | % extract color descriptor 58 | out(:,:,level+(1:10)) = im2c(single(im_patch), w2c, -2); 59 | level = level + feature_levels(2); 60 | end 61 | end -------------------------------------------------------------------------------- /JSAR_lib/get_colorspace.m: -------------------------------------------------------------------------------- 1 | function [ colorspace ] = get_colorspace(im, fparam, gparam ) 2 | 3 | [im_height, im_width, num_im_chan, num_images] = size(im); 4 | 5 | single_im = single(im)/255; 6 | 7 | if fparam.useForGray 8 | if num_im_chan == 3 9 | if num_images == 1 10 | t_colorspace = rgb2gray(single_im) - 0.5; 11 | else 12 | t_colorspace = zeros(im_height, im_width, 1, num_images, 'single'); 13 | for k = 1:num_images 14 | t_colorspace(:,:,:,k) = rgb2gray(single_im(:,:,:,k)) - 0.5; 15 | end 16 | end 17 | elseif num_im_chan == 1 18 | t_colorspace = single_im - 0.5; 19 | else 20 | except = MException('get_colorspace','Invalid input data, must have 1 or 3 dimensions'); 21 | throw(except); 22 | end 23 | elseif fparam.useForColor 24 | if num_im_chan == 3 25 | t_colorspace = single_im - 0.5; 26 | else 27 | except = MException('get_colorspace','Invalid input data, must have 3 dimensions for rgb'); 28 | throw(except); 29 | end 30 | end 31 | if gparam.cell_size > 1 32 | colorspace = average_feature_region(t_colorspace,gparam.cell_size); 33 | else 34 | colorspace = t_colorspace; 35 | end 36 | end 37 | 38 | -------------------------------------------------------------------------------- /JSAR_lib/get_features.m: -------------------------------------------------------------------------------- 1 | function [feature_pixels, support_sz] = get_features(image, features, gparams, fg_size ) 2 | 3 | if ~ iscell(features) 4 | features = {features}; 5 | end 6 | 7 | [im_height, im_width, num_im_chan, num_images] = size(image); 8 | 9 | colorImage = num_im_chan == 3; 10 | 11 | 12 | %compute total dimension of all features 13 | tot_feature_dim = 0; 14 | for n = 1:length(features) 15 | 16 | if ~isfield(features{n}.fparams,'useForColor') 17 | features{n}.fparams.useForColor = true; 18 | end 19 | 20 | if ~isfield(features{n}.fparams,'useForGray') 21 | features{n}.fparams.useForGray = true; 22 | end 23 | 24 | if (features{n}.fparams.useForColor && colorImage) || (features{n}.fparams.useForGray && ~colorImage) 25 | tot_feature_dim = tot_feature_dim + features{n}.fparams.nDim; 26 | end 27 | 28 | end 29 | 30 | if nargin < 4 || isempty(fg_size) 31 | if gparams.cell_size == -1 32 | fg_size = size(features{1}.getFeature(image,features{1}.fparams,gparams)); 33 | else 34 | fg_size = [floor(im_height/gparams.cell_size), floor(im_width/gparams.cell_size)]; 35 | end 36 | end 37 | 38 | % temporary hack for fixing deep features 39 | if gparams.cell_size == -1 40 | cf = features{1}; 41 | if (cf.fparams.useForColor && colorImage) || (cf.fparams.useForGray && ~colorImage) 42 | [feature_pixels, support_sz] = cf.getFeature(image,cf.fparams,gparams); 43 | end 44 | else 45 | %compute the feature set 46 | feature_pixels = zeros(fg_size(1),fg_size(2),tot_feature_dim, num_images, 'single'); 47 | 48 | currDim = 1; 49 | for n = 1:length(features) 50 | cf = features{n}; 51 | if (cf.fparams.useForColor && colorImage) || (cf.fparams.useForGray && ~colorImage) 52 | 53 | feature_pixels(:,:,currDim:(currDim+cf.fparams.nDim-1),:) = cf.getFeature(image,cf.fparams,gparams); 54 | 55 | currDim = currDim + cf.fparams.nDim; 56 | end 57 | end 58 | support_sz = [im_height, im_width]; 59 | end 60 | 61 | end -------------------------------------------------------------------------------- /JSAR_lib/get_fhog.m: -------------------------------------------------------------------------------- 1 | function [ feature_image ] = get_fhog(im, fparam, gparam) 2 | %extract fhog features using piotrs toolbox. Currently takes no parameters 3 | %except hog-cell-size 4 | if ~isfield(fparam, 'nOrients') 5 | fparam.nOrients = 9; 6 | end 7 | [im_height, im_width, ~, num_images] = size(im); 8 | feature_image = zeros(floor(im_height/gparam.cell_size), floor(im_width/gparam.cell_size), fparam.nDim, num_images, 'single'); 9 | for k = 1:num_images 10 | hog_image = fhog(single(im(:,:,:,k)), gparam.cell_size, fparam.nOrients); 11 | % for i=1:size(hog_image,3) 12 | % this_feature=hog_image(:,:,i); 13 | % heatmap(this_feature); 14 | % end 15 | %the last dimension is all 0 so we can discard it 16 | feature_image(:,:,:,k) = hog_image(:,:,1:end-1); 17 | end 18 | end -------------------------------------------------------------------------------- /JSAR_lib/get_pixels.m: -------------------------------------------------------------------------------- 1 | function [ resized_patch ] = get_pixels(im, pos, sz, resize_target) 2 | 3 | if isscalar(sz) %square sub-window 4 | sz = [sz, sz]; 5 | end 6 | 7 | %make sure the size is not to small 8 | if sz(1) < 1 9 | sz(1) = 2; 10 | end 11 | if sz(2) < 1 12 | sz(2) = 2; 13 | end 14 | 15 | xs = floor(pos(2)) + (1:sz(2)) - floor(sz(2)/2); 16 | ys = floor(pos(1)) + (1:sz(1)) - floor(sz(1)/2); 17 | 18 | %check for out-of-bounds coordinates, and set them to the values at 19 | %the borders 20 | xs(xs < 1) = 1; 21 | ys(ys < 1) = 1; 22 | xs(xs > size(im,2)) = size(im,2); 23 | ys(ys > size(im,1)) = size(im,1); 24 | 25 | %extract image 26 | im_patch = im(ys, xs, :); 27 | 28 | if isempty(resize_target) 29 | resized_patch = im_patch; 30 | else 31 | resized_patch = mexResize(im_patch,resize_target,'auto'); 32 | end 33 | 34 | end 35 | 36 | -------------------------------------------------------------------------------- /JSAR_lib/get_size_sample.m: -------------------------------------------------------------------------------- 1 | function out = get_size_sample(im, pos, base_target_sz, sv_factors, arc_factors, size_model_sz,window,frame) 2 | 3 | num_sv= length(sv_factors); 4 | num_arc=length(arc_factors); 5 | 6 | for s = 1:num_sv 7 | for a=1:num_arc 8 | patch_sz = floor(base_target_sz * sv_factors(s)); 9 | patch_sz(1) = floor(patch_sz(1)*sqrt(arc_factors(a))); 10 | patch_sz(2) = floor(patch_sz(2)/sqrt(arc_factors(a))); 11 | %make sure the size is not to small 12 | patch_sz = max(patch_sz, 2); 13 | 14 | xs = floor(pos(2)) + (1:patch_sz(2)) - floor(patch_sz(2)/2); 15 | ys = floor(pos(1)) + (1:patch_sz(1)) - floor(patch_sz(1)/2); 16 | 17 | %check for out-of-bounds coordinates, and set them to the values at 18 | %the borders 19 | xs(xs < 1) = 1; 20 | ys(ys < 1) = 1; 21 | xs(xs > size(im,2)) = size(im,2); 22 | ys(ys > size(im,1)) = size(im,1); 23 | 24 | %extract image 25 | im_patch = im(ys, xs, :); 26 | % if frame==5 27 | % savedir='H:\IROS\ORIGIN\'; 28 | % imwrite(im_patch,[savedir, num2str(s),'_',num2str(a),'.png']); 29 | % hold off; 30 | % end 31 | % resize image to model size 32 | % im_patch_resized = mexResize(im_patch, size_model_sz, 'auto'); 33 | % extract scale features 34 | 35 | % im_patch_resized = mexResize(im_patch_resized,size_model_sz/hog_box_cell_size,'auto'); 36 | % temp(:,:,1)=single(rgb2gray(im_patch_resized))/255-0.5; 37 | % temp(:,:,2:11)=fcn(im_patch_resized, 'cn', w2c); 38 | % resize image to model size 39 | im_patch_resized = mexResize(im_patch, size_model_sz, 'auto'); 40 | 41 | % extract scale features 42 | temp_hog = fhog(single(im_patch_resized),4); 43 | temp = temp_hog(:,:,1:31); 44 | 45 | if a==1&&s==1 46 | out= zeros(num_sv, num_arc,numel(temp),'single'); 47 | end 48 | % 49 | % if frame==5 50 | % fig_temp=sum(temp,3); 51 | % savedir='H:\IROS\FEATURE\'; 52 | % colormap(parula); 53 | % han=figure(2); 54 | % set(han,'visible','off'); 55 | % surf(fig_temp); 56 | % shading interp; 57 | % axis ij; 58 | % axis off; 59 | % view([0,90]); 60 | % saveas(gcf,[savedir,num2str(s),'_',num2str(a),'.png']); 61 | % hold off; 62 | % end 63 | % 64 | 65 | 66 | % out(s,a,:) = temp(:)*window(s,a); 67 | out(s,a,:) = temp(:); 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /JSAR_lib/get_subwindow_no_window.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/get_subwindow_no_window.m -------------------------------------------------------------------------------- /JSAR_lib/get_table_feature.m: -------------------------------------------------------------------------------- 1 | function [ feature_map ] = get_table_feature(im, fparam, gparam) 2 | %get per-pixel features using a lookup table, if the gparam feature cell 3 | %size is set to something large than one, the resulting data will be 4 | %averaged in cells of the specified size. 5 | % 6 | %tables are loaded dynamically when needed from the lookup_tables folder, 7 | %and stored in a persistent variable 8 | 9 | persistent tables; 10 | gparam.use_gpu=false; 11 | if isempty(tables) 12 | tables = {}; 13 | end 14 | 15 | if isfield(fparam, 'cell_size') 16 | cell_size = fparam.cell_size; 17 | else 18 | cell_size = gparam.cell_size; 19 | end 20 | 21 | tab_ind = 0; 22 | for k = 1:length(tables) 23 | if isfield(tables{k}, fparam.tablename) 24 | tab_ind = k; 25 | break; 26 | end 27 | end 28 | 29 | if tab_ind == 0 30 | tables{end+1} = load(['lookup_tables/' fparam.tablename]); 31 | tab_ind = length(tables); 32 | end 33 | 34 | if strcmp(tables{tab_ind}.inputType,'color') 35 | if size(im,3) ~= 3 36 | except = MException('cannot get colorfeature from non color image'); 37 | raise(except); 38 | end 39 | elseif strcmp(tables{tab_ind}.inputType,'gray') 40 | if size(im,3) == 3 41 | im_gray = zeros(size(im,1),size(im,2),1,size(im,4),'uint8'); 42 | for k = 1:size(im,4) 43 | im_gray(:,:,:,k) = rgb2gray(im(:,:,:,k)); 44 | end 45 | im = im_gray; 46 | end 47 | end 48 | % sel_channel=1:5; 49 | % tables{1}.(fparam.tablename)=tables{1}.(fparam.tablename)(:,sel_channel); 50 | % Extract features from table 51 | if gparam.use_gpu 52 | feature_map = gpuArray(table_lookup(im,tables{tab_ind}.(fparam.tablename))); 53 | else 54 | feature_map = table_lookup(im,tables{tab_ind}.(fparam.tablename)); 55 | end 56 | 57 | if cell_size > 1 58 | feature_map = average_feature_region(feature_map, cell_size); 59 | end 60 | 61 | end 62 | 63 | -------------------------------------------------------------------------------- /JSAR_lib/gradient2.m: -------------------------------------------------------------------------------- 1 | function [Gx,Gy] = gradient2( I ) 2 | % Compute numerical gradients along x and y directions. 3 | % 4 | % For 2D arrays identical to Matlab's gradient() with a spacing value of 5 | % h=1 but ~10-20x faster (due to mexed implementation). Like gradient(), 6 | % computes centered derivatives in interior of image and uncentered 7 | % derivatives along boundaries. For 3D arrays computes x and y gradient 8 | % separately for each channel and concatenates the results. 9 | % 10 | % This code requires SSE2 to compile and run (most modern Intel and AMD 11 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 12 | % 13 | % USAGE 14 | % [Gx,Gy] = gradient2( I ) 15 | % 16 | % INPUTS 17 | % I - [hxwxk] input k channel single image 18 | % 19 | % OUTPUTS 20 | % Gx - [hxwxk] x-gradient (horizontal) 21 | % Gy - [hxwxk] y-gradient (vertical) 22 | % 23 | % EXAMPLE 24 | % I=single(imread('peppers.png'))/255; 25 | % tic, [Gx1,Gy1]=gradient(I,1); toc 26 | % tic, [Gx2,Gy2]=gradient2(I); toc 27 | % isequal(Gx1,Gx2), isequal(Gy1,Gy2) 28 | % 29 | % See also gradient, gradientMag 30 | % 31 | % Piotr's Computer Vision Matlab Toolbox Version 3.00 32 | % Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com] 33 | % Licensed under the Simplified BSD License [see external/bsd.txt] 34 | 35 | [Gx,Gy]=gradientMex('gradient2',I); 36 | -------------------------------------------------------------------------------- /JSAR_lib/gradientHist.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/gradientHist.m -------------------------------------------------------------------------------- /JSAR_lib/gradientMag.m: -------------------------------------------------------------------------------- 1 | function [M,O] = gradientMag( I, channel, normRad, normConst, full ) 2 | % Compute gradient magnitude and orientation at each image location. 3 | % 4 | % If input image has k>1 channels and channel=0, keeps gradient with 5 | % maximum magnitude (over all channels) at each location. Otherwise if 6 | % channel is between 1 and k computes gradient for the given channel. 7 | % If full==1 orientation is computed in [0,2*pi) else it is in [0,pi). 8 | % 9 | % If normRad>0, normalization is performed by first computing S, a smoothed 10 | % version of the gradient magnitude, then setting: M = M./(S + normConst). 11 | % S is computed by S = convTri( M, normRad ). 12 | % 13 | % This code requires SSE2 to compile and run (most modern Intel and AMD 14 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 15 | % 16 | % USAGE 17 | % [M,O] = gradientMag( I, [channel], [normRad], [normConst], [full] ) 18 | % 19 | % INPUTS 20 | % I - [hxwxk] input k channel single image 21 | % channel - [0] if>0 color channel to use for gradient computation 22 | % normRad - [0] normalization radius (no normalization if 0) 23 | % normConst - [.005] normalization constant 24 | % full - [0] if true compute angles in [0,2*pi) else in [0,pi) 25 | % 26 | % OUTPUTS 27 | % M - [hxw] gradient magnitude at each location 28 | % O - [hxw] approximate gradient orientation modulo PI 29 | % 30 | % EXAMPLE 31 | % I=rgbConvert(imread('peppers.png'),'gray'); 32 | % [Gx,Gy]=gradient2(I); M=sqrt(Gx.^2+Gy.^2); O=atan2(Gy,Gx); 33 | % full=0; [M1,O1]=gradientMag(I,0,0,0,full); 34 | % D=abs(M-M1); mean2(D), if(full), o=pi*2; else o=pi; end 35 | % D=abs(O-O1); D(~M)=0; D(D>o*.99)=o-D(D>o*.99); mean2(abs(D)) 36 | % 37 | % See also gradient, gradient2, gradientHist, convTri 38 | % 39 | % Piotr's Computer Vision Matlab Toolbox Version 3.23 40 | % Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com] 41 | % Licensed under the Simplified BSD License [see external/bsd.txt] 42 | 43 | if(nargin<1 || isempty(I)), M=single([]); O=M; return; end 44 | if(nargin<2 || isempty(channel)), channel=0; end 45 | if(nargin<3 || isempty(normRad)), normRad=0; end 46 | if(nargin<4 || isempty(normConst)), normConst=.005; end 47 | if(nargin<5 || isempty(full)), full=0; end 48 | 49 | if(nargout<=1), M=gradientMex('gradientMag',I,channel,full); 50 | else [M,O]=gradientMex('gradientMag',I,channel,full); end 51 | 52 | if( normRad==0 ), return; end; S = convTri( M, normRad ); 53 | gradientMex('gradientMagNorm',M,S,normConst); % operates on M 54 | -------------------------------------------------------------------------------- /JSAR_lib/gradientMex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/gradientMex.mexa64 -------------------------------------------------------------------------------- /JSAR_lib/gradientMex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/gradientMex.mexmaci64 -------------------------------------------------------------------------------- /JSAR_lib/gradientMex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/gradientMex.mexw64 -------------------------------------------------------------------------------- /JSAR_lib/im2c.m: -------------------------------------------------------------------------------- 1 | function out=im2c(im,w2c,color) 2 | % input im should be DOUBLE ! 3 | % color=0 is color names out 4 | % color=-1 is colored image with color names out 5 | % color=1-11 is prob of colorname=color out; 6 | % color=-1 return probabilities 7 | % order of color names: black , blue , brown , grey , green , orange , pink , purple , red , white , yellow 8 | color_values = { [0 0 0] , [0 0 1] , [.5 .4 .25] , [.5 .5 .5] , [0 1 0] , [1 .8 0] , [1 .5 1] , [1 0 1] , [1 0 0] , [1 1 1 ] , [ 1 1 0 ] }; 9 | 10 | if(nargin<3) 11 | color=0; 12 | end 13 | 14 | RR=im(:,:,1);GG=im(:,:,2);BB=im(:,:,3); 15 | 16 | index_im = 1+floor(RR(:)/8)+32*floor(GG(:)/8)+32*32*floor(BB(:)/8); 17 | 18 | if(color==0) 19 | [max1,w2cM]=max(w2c,[],2); 20 | out=reshape(w2cM(index_im(:)),size(im,1),size(im,2)); 21 | end 22 | 23 | if(color>0 && color < 12) 24 | w2cM=w2c(:,color); 25 | out=reshape(w2cM(index_im(:)),size(im,1),size(im,2)); 26 | end 27 | 28 | if(color==-1) 29 | out=im; 30 | [max1,w2cM]=max(w2c,[],2); 31 | out2=reshape(w2cM(index_im(:)),size(im,1),size(im,2)); 32 | 33 | for jj=1:size(im,1) 34 | for ii=1:size(im,2) 35 | out(jj,ii,:)=color_values{out2(jj,ii)}'*255; 36 | end 37 | end 38 | end 39 | 40 | if(color==-2) 41 | out=reshape(w2c(index_im,:),size(im,1),size(im,2),size(w2c,2)); 42 | end 43 | -------------------------------------------------------------------------------- /JSAR_lib/init_regwindow.m: -------------------------------------------------------------------------------- 1 | function [range_h,range_w,reg_window]=init_regwindow(sz,target_sz,params) 2 | reg_scale =target_sz; 3 | reg_scale=max(reg_scale,2); 4 | use_sz = sz; 5 | reg_window = ones(use_sz) * params.reg_window_max; 6 | range = zeros(numel(reg_scale), 2); 7 | use_sz=max(use_sz,2); 8 | % determine the target center and range in the regularization windows 9 | for j = 1:numel(reg_scale) 10 | range(j,:) = [0, reg_scale(j) - 1] - floor(reg_scale(j) / 2); 11 | end 12 | center = floor((use_sz + 1)/ 2) + mod(use_sz + 1,2); 13 | range_h = (center(1)+ range(1,1)) : (center(1) + range(1,2)); 14 | range_w = (center(2)+ range(2,1)) : (center(2) + range(2,2)); 15 | range_h(range_h<1)=1; 16 | range_w(range_w<1)=1; 17 | range_h(range_h>size(reg_window,1))=size(reg_window,1); 18 | range_w(range_w>size(reg_window,2))=size(reg_window,2); 19 | reg_window(range_h, range_w) = params.reg_window_min; 20 | 21 | 22 | -------------------------------------------------------------------------------- /JSAR_lib/integralVecImage.m: -------------------------------------------------------------------------------- 1 | function intImage = integralVecImage(I) 2 | 3 | % Compute the integral image of I. 4 | 5 | if ~isempty(I) 6 | intImage = zeros(size(I,1)+1, size(I,2)+1, size(I,3), size(I,4), 'like', I); 7 | intImage(2:end, 2:end, :, :) = cumsum(cumsum(I,1),2); 8 | else 9 | intImage = []; 10 | end 11 | 12 | -------------------------------------------------------------------------------- /JSAR_lib/load_video_info.m: -------------------------------------------------------------------------------- 1 | function [seq, ground_truth] = load_video_info(video_path) 2 | 3 | ground_truth = dlmread([video_path '/groundtruth_rect.txt']); 4 | 5 | seq.len = size(ground_truth, 1); 6 | seq.init_rect = ground_truth(1,:); 7 | 8 | img_path = [video_path '/img/']; 9 | 10 | img_files = dir(fullfile(img_path, '*.jpg')); 11 | % img_files = img_files(4:end); 12 | img_files = {img_files.name}; 13 | % img_files = [img_path img_files]; 14 | % if exist([img_path num2str(1, '%04i.png')], 'file'), 15 | % img_files = num2str((1:seq.len)', [img_path '%04i.png']); 16 | % elseif exist([img_path num2str(1, '%04i.jpg')], 'file'), 17 | % img_files = num2str((1:seq.len)', [img_path '%04i.jpg']); 18 | % elseif exist([img_path num2str(1, '%04i.bmp')], 'file'), 19 | % img_files = num2str((1:seq.len)', [img_path '%04i.bmp']); 20 | % else 21 | % error('No image files to load.') 22 | % end 23 | 24 | seq.s_frames = cellstr(img_files); 25 | 26 | end 27 | 28 | -------------------------------------------------------------------------------- /JSAR_lib/lookup_tables/CNnorm.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/lookup_tables/CNnorm.mat -------------------------------------------------------------------------------- /JSAR_lib/mexResize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mex.h" 5 | #include "MxArray.hpp" 6 | #include 7 | 8 | #include 9 | 10 | using namespace std; 11 | using namespace cv; 12 | 13 | /* 14 | * Use opencv function to resample image quickly 15 | */ 16 | 17 | // matlab entry point 18 | // dst = resize(src, scale) 19 | // image should be color with double values 20 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { 21 | if (nrhs < 2){ 22 | mexErrMsgTxt("Wrong number of inputs"); 23 | } 24 | if (nlhs != 1){ 25 | mexErrMsgTxt("Wrong number of outputs"); 26 | } 27 | 28 | vector rhs(prhs,prhs+nrhs); 29 | 30 | //convert input data to opencv matrix 31 | Mat img = rhs[0].toMat(); 32 | Mat imgr; 33 | Size s = rhs[1].toSize(); 34 | Size newSize = Size(s.height,s.width); 35 | Size oldSize = img.size(); 36 | //interpolation method 37 | int interpolation = INTER_LINEAR; 38 | 39 | //if interpolation method provided set it 40 | if(nrhs == 3){ 41 | string interp = rhs[2].toString(); 42 | if(interp.compare("antialias") == 0){ 43 | interpolation = INTER_AREA; 44 | }else if(interp.compare("linear") == 0){ 45 | interpolation = INTER_LINEAR; 46 | }else if(interp.compare("auto") == 0){ //if we are zooming, use linear else use area interpolation 47 | //old array has width and height swapped, newArray does not 48 | if(newSize.width > oldSize.height){ 49 | interpolation = INTER_LINEAR; 50 | }else{ 51 | interpolation = INTER_AREA; 52 | } 53 | }else{ 54 | mexErrMsgTxt("Invalid interpolation provided, valid is linear (default), antialias, auto"); 55 | } 56 | } 57 | 58 | //use opencv resize function 59 | resize(img,imgr,newSize,0,0,interpolation); 60 | //convert back to matlab representation 61 | plhs[0] = MxArray(imgr); 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /JSAR_lib/mexResize.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mexResize.mexa64 -------------------------------------------------------------------------------- /JSAR_lib/mexResize.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mexResize.mexmaci64 -------------------------------------------------------------------------------- /JSAR_lib/mexResize.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mexResize.mexw64 -------------------------------------------------------------------------------- /JSAR_lib/mtimesx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mtimesx.c -------------------------------------------------------------------------------- /JSAR_lib/mtimesx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mtimesx.m -------------------------------------------------------------------------------- /JSAR_lib/mtimesx.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mtimesx.mexa64 -------------------------------------------------------------------------------- /JSAR_lib/mtimesx.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mtimesx.mexmaci64 -------------------------------------------------------------------------------- /JSAR_lib/mtimesx.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/mtimesx.mexw64 -------------------------------------------------------------------------------- /JSAR_lib/opencv_core242.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/opencv_core242.dll -------------------------------------------------------------------------------- /JSAR_lib/opencv_imgproc242.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/JSAR_lib/opencv_imgproc242.dll -------------------------------------------------------------------------------- /JSAR_lib/resizeDFT2.m: -------------------------------------------------------------------------------- 1 | function resizeddft = resizeDFT2(inputdft, desiredSize) 2 | 3 | [imh, imw, n1, n2] = size(inputdft); 4 | imsz = [imh, imw]; 5 | 6 | if any(desiredSize ~= imsz) 7 | minsz = min(imsz, desiredSize); 8 | 9 | scaling = prod(desiredSize)/prod(imsz); 10 | 11 | resizeddft = complex(zeros([desiredSize n1 n2], 'single')); 12 | 13 | mids = ceil(minsz/2); 14 | mide = floor((minsz-1)/2) - 1; 15 | 16 | resizeddft(1:mids(1), 1:mids(2), :, :) = scaling * inputdft(1:mids(1), 1:mids(2), :, :); 17 | resizeddft(1:mids(1), end - mide(2):end, :, :) = scaling * inputdft(1:mids(1), end - mide(2):end, :, :); 18 | resizeddft(end - mide(1):end, 1:mids(2), :, :) = scaling * inputdft(end - mide(1):end, 1:mids(2), :, :); 19 | resizeddft(end - mide(1):end, end - mide(2):end, :, :) = scaling * inputdft(end - mide(1):end, end - mide(2):end, :, :); 20 | else 21 | resizeddft = inputdft; 22 | end 23 | end -------------------------------------------------------------------------------- /JSAR_lib/resp_newton.m: -------------------------------------------------------------------------------- 1 | function [disp_row, disp_col, sind] = resp_newton(response, responsef, iterations, ky, kx, use_sz) 2 | 3 | [max_resp_row, max_row] = max(response, [], 1); 4 | [init_max_response, max_col] = max(max_resp_row, [], 2); 5 | max_row_perm = permute(max_row, [2 3 1]); 6 | col = max_col(:)'; 7 | row = max_row_perm(sub2ind(size(max_row_perm), col, 1:size(response,3))); 8 | 9 | trans_row = mod(row - 1 + floor((use_sz(1)-1)/2), use_sz(1)) - floor((use_sz(1)-1)/2); 10 | trans_col = mod(col - 1 + floor((use_sz(2)-1)/2), use_sz(2)) - floor((use_sz(2)-1)/2); 11 | init_pos_y = permute(2*pi * trans_row / use_sz(1), [1 3 2]); 12 | init_pos_x = permute(2*pi * trans_col / use_sz(2), [1 3 2]); 13 | max_pos_y = init_pos_y; 14 | max_pos_x = init_pos_x; 15 | 16 | % pre-compute complex exponential 17 | exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); 18 | exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); 19 | 20 | % gradient_step_size = gradient_step_size / prod(use_sz); 21 | 22 | ky2 = ky.*ky; 23 | kx2 = kx.*kx; 24 | 25 | iter = 1; 26 | while iter <= iterations 27 | % Compute gradient 28 | ky_exp_ky = bsxfun(@times, ky, exp_iky); 29 | kx_exp_kx = bsxfun(@times, kx, exp_ikx); 30 | y_resp = mtimesx(exp_iky, responsef, 'speed'); 31 | resp_x = mtimesx(responsef, exp_ikx, 'speed'); 32 | grad_y = -imag(mtimesx(ky_exp_ky, resp_x, 'speed')); 33 | grad_x = -imag(mtimesx(y_resp, kx_exp_kx, 'speed')); 34 | ival = 1i * mtimesx(exp_iky, resp_x, 'speed'); 35 | H_yy = real(-mtimesx(bsxfun(@times, ky2, exp_iky), resp_x, 'speed') + ival); 36 | H_xx = real(-mtimesx(y_resp, bsxfun(@times, kx2, exp_ikx), 'speed') + ival); 37 | H_xy = real(-mtimesx(ky_exp_ky, mtimesx(responsef, kx_exp_kx, 'speed'), 'speed')); 38 | det_H = H_yy .* H_xx - H_xy .* H_xy; 39 | 40 | % Compute new position using newtons method 41 | max_pos_y = max_pos_y - (H_xx .* grad_y - H_xy .* grad_x) ./ det_H; 42 | max_pos_x = max_pos_x - (H_yy .* grad_x - H_xy .* grad_y) ./ det_H; 43 | 44 | % Evaluate maximum 45 | exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); 46 | exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); 47 | 48 | iter = iter + 1; 49 | end 50 | max_response = 1 / prod(use_sz) * real(mtimesx(mtimesx(exp_iky, responsef, 'speed'), exp_ikx, 'speed')); 51 | 52 | % check for scales that have not increased in score 53 | ind = max_response < init_max_response; 54 | max_response(ind) = init_max_response(ind); 55 | max_pos_y(ind) = init_pos_y(ind); 56 | max_pos_x(ind) = init_pos_x(ind); 57 | 58 | [max_scale_response, sind] = max(max_response(:)); 59 | disp_row = (mod(max_pos_y(1,1,sind) + pi, 2*pi) - pi) / (2*pi) * use_sz(1); 60 | disp_col = (mod(max_pos_x(1,1,sind) + pi, 2*pi) - pi) / (2*pi) * use_sz(2); 61 | end -------------------------------------------------------------------------------- /JSAR_lib/shift_sample.m: -------------------------------------------------------------------------------- 1 | function xf = shift_sample(xf, shift, kx, ky) 2 | 3 | % Shift a sample in the Fourier domain. The shift should be normalized to 4 | % the range [-pi, pi]. 5 | shift_exp_y =exp((1i * shift(1)) * ky); 6 | shift_exp_x = exp((1i * shift(2)) * kx); 7 | xf =bsxfun(@times, bsxfun(@times, xf, shift_exp_y), shift_exp_x); -------------------------------------------------------------------------------- /JSAR_lib/table_lookup.m: -------------------------------------------------------------------------------- 1 | function out=table_lookup(im,table) 2 | 3 | if isa(im,'uint8') 4 | im = int32(im); 5 | end 6 | 7 | [im_height, im_width, num_im_chan, num_images] = size(im); 8 | 9 | den = int32(8); 10 | fac = int32(32); 11 | offset = int32(1); 12 | 13 | if num_im_chan == 3 14 | RR=im(:,:,1,:);GG=im(:,:,2,:);BB=im(:,:,3,:); 15 | index_im = offset + idivide(RR,den) + fac*idivide(GG,den) + fac*fac*idivide(BB,den); 16 | out = permute(reshape(table(index_im(:),:), im_height, im_width, num_images, size(table,2)), [1 2 4 3]); 17 | else 18 | out = permute(reshape(table(im(:)+1,:), im_height, im_width, num_images, size(table,2)), [1 2 4 3]); 19 | end; 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Automatic Failure Recovery and Re-Initialization for Online UAV Tracking with Joint Scale and Aspect Ratio Optimization 2 | This is the Matlab implementation of our joint scale and aspect ratio optimization tracker (JSAR) and JSAR-Re which adds novel re-detection strategy in JSAR. 3 | 4 | # Abstract 5 | 6 | Current unmanned aerial vehicle (UAV) visual tracking algorithms are primarily limited with respect to: (i) the kind of size variation they can deal with, (ii) the implementation speed which hardly meets the real-time requirement. In this work, a real-time UAV tracking algorithm with powerful size estimation ability is proposed. Specifically, the overall tracking task is allocated to two 2D filters: (i) translation filter forlocation prediction in the space domain, (ii) size filter for scale and aspect ratio optimization in the size domain. Besides, an efficient two-stage re-detection strategy is introduced for long-term UAV tracking tasks. Large-scale experiments on four UAV benchmarks demonstrate the superiority of the presented method which has computation feasibility on a low-cost CPU. 7 | 8 | # Publication 9 | 10 | JSAR and JSAR-Re are proposed in our paper accepted by IROS 2020. Detailed explanation of our method can be found in the paper: 11 | 12 | Fangqiang Ding, Changhong Fu, Yiming Li, Jin Jin and Chen Feng. 13 | 14 | Automatic Failure Recovery and Re-Initialization for Online UAV Tracking with Joint Scale and Aspect Ratio Optimization 15 | 16 | https://arxiv.org/abs/2008.03915 17 | 18 | If you want to refer to this paper, please cite it as follows: 19 | 20 | @article{Ding2020Auto, 21 | 22 | author = {Fangqiang Ding and Changhong Fu and Yiming Li and Jin Jin and Chen Feng}, 23 | 24 | title = {Automatic Failure Recovery and Re-Initialization for Online UAV Tracking with Joint Scale and Aspect Ratio Optimization}, 25 | 26 | Year = {2020}, 27 | 28 | journal = {arXiv:2008.03915} 29 | 30 | } 31 | 32 | 33 | # Contact 34 | 35 | Fangqiang Ding 36 | 37 | Email: dfq.toytiny@gmail.com 38 | 39 | Changhong Fu 40 | 41 | Email: [changhong.fu@tongji.edu.cn](mailto:changhong.fu@tongji.edu.cn) 42 | 43 | # Demonstration running instructions 44 | 45 | This code is compatible with UAV123@10fps, DTB70, UAVDT and UAV20L benchmark. Therefore, if you want to run it in benchmark, just put JSAR folder in trackers, and config sequences and trackers (JSAR or JSAR-Re) according to instructions from aforementioned benchmarks. 46 | 47 | # Results on UAV datasets 48 | 49 | ### UAV123@10fps 50 | 51 | ![](results_OPE/UAV123_10fps/error.png) 52 | 53 | ![](results_OPE/UAV123_10fps/overlap.png) 54 | 55 | 56 | 57 | ### UAVDT 58 | 59 | ![](results_OPE/UAVDT/error.png) 60 | 61 | ![](results_OPE/UAVDT/overlap.png) 62 | 63 | ### DTB70 64 | 65 | ![](results_OPE/DTB70/error.png) 66 | 67 | ![](results_OPE/DTB70/overlap.png) 68 | 69 | ### UAV20L 70 | 71 | ![](results_OPE/UAV20L/error.png) 72 | 73 | # Acknowledgements 74 | 75 | We thank the contribution of Feng Li and Ning Wang for their previous work STRCF and MCCT-H. The feature extraction modules and some of the parameter are borrowed from the MCCT tracker (https://github.com/594422814/MCCT). 76 | -------------------------------------------------------------------------------- /channels/Contents.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/channels/Contents.m -------------------------------------------------------------------------------- /channels/chnsCompute.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/channels/chnsCompute.m -------------------------------------------------------------------------------- /channels/chnsPyramid.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/channels/chnsPyramid.m -------------------------------------------------------------------------------- /channels/chnsScaling.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/channels/chnsScaling.m -------------------------------------------------------------------------------- /channels/convMax.m: -------------------------------------------------------------------------------- 1 | function J = convMax( I, r, nomex ) 2 | % Extremely fast 2D image convolution with a max filter. 3 | % 4 | % For each location computes J(y,x) = max(max(I(y-r:y+r,x-r:x+r))). The 5 | % filtering is constant time per-window, independent of r. First, the 6 | % filtering is separable, which brings the complexity down to O(r) per 7 | % window from O(r*r). To bring the implemention down to constant time 8 | % (independent of r) we use the van Herk/Gil-Werman algorithm. Ignoring 9 | % boundaries, just 3 max operations are need per-window regardless of r. 10 | % http://www.leptonica.com/grayscale-morphology.html#FAST-IMPLEMENTATION 11 | % 12 | % The output is exactly equivalent to the following Matlab operations: 13 | % I=padarray(I,[r r],'replicate','both'); [h,w,d]=size(I); J=I; 14 | % for z=1:d, for x=r+1:w-r, for y=r+1:h-r 15 | % J(y,x,z) = max(max(I(y-r:y+r,x-r:x+r,z))); end; end; end 16 | % J=J(r+1:h-r,r+1:w-r,:); 17 | % The computation, however, is an order of magnitude faster than the above. 18 | % 19 | % USAGE 20 | % J = convMax( I, r, [nomex] ) 21 | % 22 | % INPUTS 23 | % I - [hxwxk] input k channel single image 24 | % r - integer filter radius or radii along y and x 25 | % nomex - [0] if true perform computation in matlab (for testing/timing) 26 | % 27 | % OUTPUTS 28 | % J - [hxwxk] max image 29 | % 30 | % EXAMPLE 31 | % I = single(imResample(imread('cameraman.tif'),[480 640]))/255; 32 | % r = 5; % set parameter as desired 33 | % tic, J1=convMax(I,r); toc % mex version (fast) 34 | % tic, J2=convMax(I,r,1); toc % matlab version (slow) 35 | % figure(1); im(J1); figure(2); im(abs(J2-J1)); 36 | % 37 | % See also conv2, convTri, convBox 38 | % 39 | % Piotr's Computer Vision Matlab Toolbox Version 3.00 40 | % Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com] 41 | % Licensed under the Simplified BSD License [see external/bsd.txt] 42 | 43 | assert( all(r>=0) ); 44 | if( nargin<3 ), nomex=0; end 45 | if( all(r==0) ), J = I; return; end 46 | if( numel(r)==1 ), ry=r; rx=r; else ry=r(1); rx=r(2); end 47 | 48 | if( nomex==0 ) 49 | d=size(I,3); 50 | if(d==1), J=convConst('convMax',convConst('convMax',I,ry,1)',rx,1)'; else 51 | J=I; for z=1:d, J(:,:,z) = ... 52 | convConst('convMax',convConst('convMax',J(:,:,z),ry,1)',rx,1)'; end 53 | end 54 | else 55 | I=padarray(I,[ry rx],'replicate','both'); [h,w,d]=size(I); J=I; 56 | for z=1:d, for x=rx+1:w-rx, for y=ry+1:h-ry 57 | J(y,x,z) = max(max(I(y-ry:y+ry,x-rx:x+rx,z))); end; end; end 58 | J=J(ry+1:h-ry,rx+1:w-rx,:); 59 | end 60 | 61 | end 62 | -------------------------------------------------------------------------------- /channels/fhog.m: -------------------------------------------------------------------------------- 1 | function H = fhog( I, binSize, nOrients, clip, crop ) 2 | % Efficiently compute Felzenszwalb's HOG (FHOG) features. 3 | % 4 | % A fast implementation of the HOG variant used by Felzenszwalb et al. 5 | % in their work on discriminatively trained deformable part models. 6 | % http://www.cs.berkeley.edu/~rbg/latent/index.html 7 | % Gives nearly identical results to features.cc in code release version 5 8 | % but runs 4x faster (over 125 fps on VGA color images). 9 | % 10 | % The computed HOG features are 3*nOrients+5 dimensional. There are 11 | % 2*nOrients contrast sensitive orientation channels, nOrients contrast 12 | % insensitive orientation channels, 4 texture channels and 1 all zeros 13 | % channel (used as a 'truncation' feature). Using the standard value of 14 | % nOrients=9 gives a 32 dimensional feature vector at each cell. This 15 | % variant of HOG, refered to as FHOG, has been shown to achieve superior 16 | % performance to the original HOG features. For details please refer to 17 | % work by Felzenszwalb et al. (see link above). 18 | % 19 | % This function is essentially a wrapper for calls to gradientMag() 20 | % and gradientHist(). Specifically, it is equivalent to the following: 21 | % [M,O] = gradientMag( I,0,0,0,1 ); softBin = -1; useHog = 2; 22 | % H = gradientHist(M,O,binSize,nOrients,softBin,useHog,clip); 23 | % See gradientHist() for more general usage. 24 | % 25 | % This code requires SSE2 to compile and run (most modern Intel and AMD 26 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 27 | % 28 | % USAGE 29 | % H = fhog( I, [binSize], [nOrients], [clip], [crop] ) 30 | % 31 | % INPUTS 32 | % I - [hxw] color or grayscale input image (must have type single) 33 | % binSize - [8] spatial bin size 34 | % nOrients - [9] number of orientation bins 35 | % clip - [.2] value at which to clip histogram bins 36 | % crop - [0] if true crop boundaries 37 | % 38 | % OUTPUTS 39 | % H - [h/binSize w/binSize nOrients*3+5] computed hog features 40 | % 41 | % EXAMPLE 42 | % I=imResample(single(imread('peppers.png'))/255,[480 640]); 43 | % tic, for i=1:100, H=fhog(I,8,9); end; disp(100/toc) % >125 fps 44 | % figure(1); im(I); V=hogDraw(H,25,1); figure(2); im(V) 45 | % 46 | % EXAMPLE 47 | % % comparison to features.cc (requires DPM code release version 5) 48 | % I=imResample(single(imread('peppers.png'))/255,[480 640]); Id=double(I); 49 | % tic, for i=1:100, H1=features(Id,8); end; disp(100/toc) 50 | % tic, for i=1:100, H2=fhog(I,8,9,.2,1); end; disp(100/toc) 51 | % figure(1); montage2(H1); figure(2); montage2(H2); 52 | % D=abs(H1-H2); mean(D(:)) 53 | % 54 | % See also hog, hogDraw, gradientHist 55 | % 56 | % Piotr's Computer Vision Matlab Toolbox Version 3.23 57 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 58 | % Licensed under the Simplified BSD License [see external/bsd.txt] 59 | 60 | if( nargin<2 ), binSize=8; end 61 | if( nargin<3 ), nOrients=9; end 62 | if( nargin<4 ), clip=.2; end 63 | if( nargin<5 ), crop=0; end 64 | 65 | softBin = -1; useHog = 2; b = binSize; 66 | [M,O] = gradientMag( I,0,0,0,1 ); 67 | H = gradientHist(M,O,binSize,nOrients,softBin,useHog,clip); 68 | if( crop ), e=mod(size(I),b)1 channels and channel=0, keeps gradient with 5 | % maximum magnitude (over all channels) at each location. Otherwise if 6 | % channel is between 1 and k computes gradient for the given channel. 7 | % If full==1 orientation is computed in [0,2*pi) else it is in [0,pi). 8 | % 9 | % If normRad>0, normalization is performed by first computing S, a smoothed 10 | % version of the gradient magnitude, then setting: M = M./(S + normConst). 11 | % S is computed by S = convTri( M, normRad ). 12 | % 13 | % This code requires SSE2 to compile and run (most modern Intel and AMD 14 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 15 | % 16 | % USAGE 17 | % [M,O] = gradientMag( I, [channel], [normRad], [normConst], [full] ) 18 | % 19 | % INPUTS 20 | % I - [hxwxk] input k channel single image 21 | % channel - [0] if>0 color channel to use for gradient computation 22 | % normRad - [0] normalization radius (no normalization if 0) 23 | % normConst - [.005] normalization constant 24 | % full - [0] if true compute angles in [0,2*pi) else in [0,pi) 25 | % 26 | % OUTPUTS 27 | % M - [hxw] gradient magnitude at each location 28 | % O - [hxw] approximate gradient orientation modulo PI 29 | % 30 | % EXAMPLE 31 | % I=rgbConvert(imread('peppers.png'),'gray'); 32 | % [Gx,Gy]=gradient2(I); M=sqrt(Gx.^2+Gy.^2); O=atan2(Gy,Gx); 33 | % full=0; [M1,O1]=gradientMag(I,0,0,0,full); 34 | % D=abs(M-M1); mean2(D), if(full), o=pi*2; else o=pi; end 35 | % D=abs(O-O1); D(~M)=0; D(D>o*.99)=o-D(D>o*.99); mean2(abs(D)) 36 | % 37 | % See also gradient, gradient2, gradientHist, convTri 38 | % 39 | % Piotr's Computer Vision Matlab Toolbox Version 3.23 40 | % Copyright 2014 Piotr Dollar & Ron Appel. [pdollar-at-gmail.com] 41 | % Licensed under the Simplified BSD License [see external/bsd.txt] 42 | 43 | if(nargin<1 || isempty(I)), M=single([]); O=M; return; end 44 | if(nargin<2 || isempty(channel)), channel=0; end 45 | if(nargin<3 || isempty(normRad)), normRad=0; end 46 | if(nargin<4 || isempty(normConst)), normConst=.005; end 47 | if(nargin<5 || isempty(full)), full=0; end 48 | 49 | if(nargout<=1), M=gradientMex('gradientMag',I,channel,full); 50 | else [M,O]=gradientMex('gradientMag',I,channel,full); end 51 | 52 | if( normRad==0 ), return; end; S = convTri( M, normRad ); 53 | gradientMex('gradientMagNorm',M,S,normConst); % operates on M 54 | -------------------------------------------------------------------------------- /channels/hogDraw.m: -------------------------------------------------------------------------------- 1 | function V = hogDraw( H, w, fhog ) 2 | % Create visualization of hog descriptor. 3 | % 4 | % USAGE 5 | % V = hogDraw( H, [w], [fhog] ) 6 | % 7 | % INPUTS 8 | % H - [m n oBin*4] computed hog features 9 | % w - [15] width for each glyph 10 | % fhog - [0] if true draw features returned by fhog 11 | % 12 | % OUTPUTS 13 | % V - [m*w n*w] visualization of hog features 14 | % 15 | % EXAMPLE 16 | % 17 | % See also hog, fhog 18 | % 19 | % Piotr's Computer Vision Matlab Toolbox Version 3.23 20 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 21 | % Licensed under the Simplified BSD License [see external/bsd.txt] 22 | 23 | % fold normalizations 24 | if(nargin<3 || isempty(fhog)), fhog=0; end 25 | m=size(H,3); if(fhog), m=(m-5)/3; H=H(:,:,1:m*3); m=3; else m=4; end 26 | s=size(H); s(3)=s(3)/m; w0=H; H=zeros(s); 27 | for o=0:m-1, H=H+w0(:,:,(1:s(3))+o*s(3)); end; 28 | 29 | % construct a "glyph" for each orientaion 30 | if(nargin<2 || isempty(w)), w=15; end 31 | bar=zeros(w,w); bar(:,round(.45*w):round(.55*w))=1; 32 | bars=zeros([size(bar) s(3)]); 33 | for o=1:s(3), bars(:,:,o)=imrotate(bar,-(o-1)*180/s(3),'crop'); end 34 | 35 | % make pictures of positive weights by adding up weighted glyphs 36 | H(H<0)=0; V=zeros(w*s(1:2)); 37 | for r=1:s(1), rs=(1:w)+(r-1)*w; 38 | for c=1:s(2), cs=(1:w)+(c-1)*w; 39 | for o=1:s(3), V(rs,cs)=V(rs,cs)+bars(:,:,o)*H(r,c,o); end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /channels/imPad.m: -------------------------------------------------------------------------------- 1 | function J = imPad( I, pad, type ) 2 | % Pad an image along its four boundaries. 3 | % 4 | % Similar to Matlab's padarray, with the following differences: 5 | % (1) limited to padding along height and width 6 | % (2) input format allows for separate padding along each dimension 7 | % (3) padding values may be negative, in which case performs *cropping* 8 | % (4) optimized (speedup can be significant, esp. for small arrays) 9 | % 10 | % The amount of padding along each of the four boundaries (referred to as 11 | % T/B/L/R) is determined by the parameter "pad" as follows: 12 | % if(numel(pad)==1): T=B=L=R=pad 13 | % if(numel(pad)==2): T=B=pad(1), L=R=pad(2) 14 | % if(numel(pad)==4): T=pad(1), B=pad(2), L=pad(3), R=pad(4) 15 | % 16 | % USAGE 17 | % J = imPad( I, pad, type ) 18 | % 19 | % INPUTS 20 | % I - [hxwxk] input image (single, double or uint8 array) 21 | % pad - pad or crop amount: 1, 2, or 4 element vector (see above) 22 | % type - pad value or 'replicate', 'symmetric', 'circular' 23 | % 24 | % OUTPUTS 25 | % J - [T+h+B x L+w+R x k] padded image 26 | % 27 | % EXAMPLE 28 | % I=imread('peppers.png'); pad=[10 20]; type=50; 29 | % tic, J1=imPad(I,pad,type); toc 30 | % tic, J2=padarray(I,pad,type,'both'); toc 31 | % figure(1); im(J1); isequal(J1,J2) 32 | % 33 | % See also padarray 34 | % 35 | % Piotr's Computer Vision Matlab Toolbox Version 3.00 36 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 37 | % Licensed under the Simplified BSD License [see external/bsd.txt] 38 | 39 | J = imPadMex( I, pad, type ); 40 | 41 | %%% OLD Matlab code - slower (although still faster than padarray) 42 | % [h,w,~]=size(I); p=pad; k=length(p); 43 | % if(k==1), p=[p p p p]; elseif(k==2), p=[p(1) p(1) p(2) p(2)]; end 44 | % if( length(type)==1 ) 45 | % J=imPad(I,p,'replicate'); v=feval(class(I),type); 46 | % J(1:p(1),:,:)=v; J(end-p(2)+1:end,:,:)=v; 47 | % J(:,1:p(3),:)=v; J(:,end-p(4)+1:end,:)=v; 48 | % return; 49 | % elseif( strcmp(type,'replicate') ) 50 | % rs = [uint32(ones(1,p(1))) 1:h h*ones(1,p(2))]; 51 | % cs = [uint32(ones(1,p(3))) 1:w w*ones(1,p(4))]; 52 | % elseif( strcmp(type,'symmetric') ) 53 | % rs = uint32([1:h h:-1:1]); rs=rs(mod(-p(1):h+p(2)-1,2*h)+1); 54 | % cs = uint32([1:w w:-1:1]); cs=cs(mod(-p(3):w+p(4)-1,2*w)+1); 55 | % elseif( strcmp(type,'circular') ) 56 | % rs = uint32(1:h); rs=rs(mod(-p(1):h+p(2)-1,h)+1); 57 | % cs = uint32(1:w); cs=cs(mod(-p(3):w+p(4)-1,w)+1); 58 | % end 59 | % J = I(rs,cs,:); 60 | -------------------------------------------------------------------------------- /channels/imResample.m: -------------------------------------------------------------------------------- 1 | function B = imResample( A, scale, method, norm ) 2 | % Fast bilinear image downsampling/upsampling. 3 | % 4 | % Gives similar results to imresize with the bilinear option and 5 | % antialiasing turned off if scale is near 1, except sometimes the final 6 | % dims are off by 1 pixel. For very small values of the scale imresize is 7 | % faster but only looks at subset of values of original image. 8 | % 9 | % This code requires SSE2 to compile and run (most modern Intel and AMD 10 | % processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2. 11 | % 12 | % USAGE 13 | % B = imResample( A, scale, [method], [norm] ) 14 | % 15 | % INPUT 16 | % A - input image (2D or 3D single, double or uint8 array) 17 | % scale - scalar resize factor [s] of target height and width [h w] 18 | % method - ['bilinear'] either 'bilinear' or 'nearest' 19 | % norm - [1] optionally multiply every output pixel by norm 20 | % 21 | % OUPUT 22 | % B - resampled image 23 | % 24 | % EXAMPLE 25 | % I=single(imread('cameraman.tif')); n=100; s=1/2; method='bilinear'; 26 | % tic, for i=1:n, I1=imresize(I,s,method,'Antialiasing',0); end; toc 27 | % tic, for i=1:n, I2=imResample(I,s,method); end; toc 28 | % figure(1); im(I1); figure(2); im(I2); 29 | % 30 | % See also imresize 31 | % 32 | % Piotr's Computer Vision Matlab Toolbox Version 3.24 33 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 34 | % Licensed under the Simplified BSD License [see external/bsd.txt] 35 | 36 | % figure out method and get target dimensions 37 | if( nargin<3 || isempty(method) ), bilinear=1; else 38 | if(~all(ischar(method))), error('method must be a string'); end 39 | bilinear = ~strcmpi(method,'nearest'); 40 | end 41 | if( nargin<4 || isempty(norm) ), norm=1; end 42 | [m,n,~]=size(A); k=numel(scale); 43 | same = (k==1 && scale==1) | (k==2 && m==scale(1) && n==scale(2)); 44 | if( same && norm==1 ); B=A; return; end 45 | 46 | if( bilinear ) 47 | % use bilinear interpolation 48 | if(k==1), m1=round(scale*m); n1=round(scale*n); 49 | else m1=scale(1); n1=scale(2); end 50 | B=imResampleMex(A,m1,n1,norm); 51 | else 52 | % use nearest neighbor interpolation 53 | if(k==1), sy=scale; sx=sy; m1=ceil(m*sy); n1=ceil(n*sx); 54 | else m1=scale(1); n1=scale(2); sy=m1/m; sx=n1/n; end 55 | y=(1:m1)'; y=floor(y/sy-.5/sy+1); y=min(max(1,y),m); 56 | x=(1:n1)'; x=floor(x/sx-.5/sx+1); x=min(max(1,x),n); 57 | nd=ndims(A); if(nd==2), B=A(y,x); elseif(nd==3), B=A(y,x,:); 58 | else ids={y,x}; ids(3:nd)={':'}; B=A(ids{:}); end 59 | if(norm~=1), B=B*norm; end 60 | end 61 | -------------------------------------------------------------------------------- /channels/private/chnsTestCpp.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Piotr's Computer Vision Matlab Toolbox Version 3.00 3 | * Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 4 | * Licensed under the Simplified BSD License [see external/bsd.txt] 5 | *******************************************************************************/ 6 | #include 7 | #include 8 | #include "rgbConvertMex.cpp" 9 | #include "imPadMex.cpp" 10 | #include "convConst.cpp" 11 | #include "imResampleMex.cpp" 12 | #include "gradientMex.cpp" 13 | 14 | // compile and test standalone channels source code 15 | int main(int argc, const char* argv[]) 16 | { 17 | // initialize test array (misalign controls memory mis-alignment) 18 | const int h=12, w=12, misalign=1; int x, y, d; 19 | float I[h*w*3+misalign], *I0=I+misalign; 20 | for( x=0; xbbLoad for test data (see bbGt>bbLoad) 13 | % .pModify - [] params for acfModify for modifying detector 14 | % .thr - [.5] threshold on overlap area for comparing two bbs 15 | % .mul - [0] if true allow multiple matches to each gt 16 | % .reapply - [0] if true re-apply detector even if bbs already computed 17 | % .ref - [10.^(-2:.25:0)] reference points (see bbGt>compRoc) 18 | % .lims - [3.1e-3 1e1 .05 1] plot axis limits 19 | % .show - [0] optional figure number for display 20 | % 21 | % OUTPUTS 22 | % miss - log-average miss rate computed at reference points 23 | % roc - [nx3] n data points along roc of form [score fp tp] 24 | % gt - [mx5] ground truth results [x y w h match] (see bbGt>evalRes) 25 | % dt - [nx6] detect results [x y w h score match] (see bbGt>evalRes) 26 | % 27 | % EXAMPLE 28 | % 29 | % See also acfTrain, acfDetect, acfModify, acfDemoInria, bbGt 30 | % 31 | % Piotr's Computer Vision Matlab Toolbox Version 3.40 32 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 33 | % Licensed under the Simplified BSD License [see external/bsd.txt] 34 | 35 | % get parameters 36 | dfs={ 'name','REQ', 'imgDir','REQ', 'gtDir','REQ', 'pLoad',[], ... 37 | 'pModify',[], 'thr',.5,'mul',0, 'reapply',0, 'ref',10.^(-2:.25:0), ... 38 | 'lims',[3.1e-3 1e1 .05 1], 'show',0 }; 39 | [name,imgDir,gtDir,pLoad,pModify,thr,mul,reapply,ref,lims,show] = ... 40 | getPrmDflt(varargin,dfs,1); 41 | 42 | % run detector on directory of images 43 | bbsNm=[name 'Dets.txt']; 44 | if(reapply && exist(bbsNm,'file')), delete(bbsNm); end 45 | if(reapply || ~exist(bbsNm,'file')) 46 | detector = load([name 'Detector.mat']); 47 | detector = detector.detector; 48 | if(~isempty(pModify)), detector=acfModify(detector,pModify); end 49 | imgNms = bbGt('getFiles',{imgDir}); 50 | acfDetect( imgNms, detector, bbsNm ); 51 | end 52 | 53 | % run evaluation using bbGt 54 | [gt,dt] = bbGt('loadAll',gtDir,bbsNm,pLoad); 55 | [gt,dt] = bbGt('evalRes',gt,dt,thr,mul); 56 | [fp,tp,score,miss] = bbGt('compRoc',gt,dt,1,ref); 57 | miss=exp(mean(log(max(1e-10,1-miss)))); roc=[score fp tp]; 58 | 59 | % optionally plot roc 60 | if( ~show ), return; end 61 | figure(show); plotRoc([fp tp],'logx',1,'logy',1,'xLbl','fppi',... 62 | 'lims',lims,'color','g','smooth',1,'fpTarget',ref); 63 | title(sprintf('log-average miss rate = %.2f%%',miss*100)); 64 | savefig([name 'Roc'],show,'png'); 65 | 66 | end 67 | -------------------------------------------------------------------------------- /detector/acfTrain.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/acfTrain.m -------------------------------------------------------------------------------- /detector/models/AcfCaltech+Detector.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/AcfCaltech+Detector.mat -------------------------------------------------------------------------------- /detector/models/AcfCaltech+Roc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/AcfCaltech+Roc.png -------------------------------------------------------------------------------- /detector/models/AcfInriaDetector.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/AcfInriaDetector.mat -------------------------------------------------------------------------------- /detector/models/AcfInriaRoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/AcfInriaRoc.png -------------------------------------------------------------------------------- /detector/models/LdcfCaltechDetector.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/LdcfCaltechDetector.mat -------------------------------------------------------------------------------- /detector/models/LdcfCaltechRoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/LdcfCaltechRoc.png -------------------------------------------------------------------------------- /detector/models/LdcfInriaDetector.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/LdcfInriaDetector.mat -------------------------------------------------------------------------------- /detector/models/LdcfInriaRoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/models/LdcfInriaRoc.png -------------------------------------------------------------------------------- /detector/private/acfDetect1.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/private/acfDetect1.mexa64 -------------------------------------------------------------------------------- /detector/private/acfDetect1.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/private/acfDetect1.mexmaci64 -------------------------------------------------------------------------------- /detector/private/acfDetect1.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/detector/private/acfDetect1.mexw64 -------------------------------------------------------------------------------- /images/Contents.m: -------------------------------------------------------------------------------- 1 | % IMAGES 2 | % See also 3 | % 4 | % Display: 5 | % clusterMontage - Used for visualization of clusters of images and videos. 6 | % im - Function for displaying grayscale images. 7 | % filmStrip - Used to display R stacks of T images as a "filmstrip". 8 | % makeGif - Writes a matlab movie to an animated GIF. 9 | % montage2 - Used to display collections of images and videos. 10 | % movieToImages - Creates a stack of images from a matlab movie M. 11 | % playMovie - Shows/makes an/several movie(s) from an image sequence. 12 | % 13 | % Histograms: 14 | % assignToBins - Quantizes A according to values in edges. 15 | % histc2 - Multidimensional histogram count with weighted values. 16 | % histcImWin - Calculates local histograms at every point in an image I. 17 | % histcImLoc - Creates a series of locally position dependent histograms. 18 | % histMontage - Used to display multiple 1D histograms. 19 | % 20 | % Generalized correlation: 21 | % normxcorrn - Normalized n-dimensional cross-correlation. 22 | % xcorrn - n-dimensional cross-correlation. Generalized version of xcorr2. 23 | % xeucn - n-dimensional euclidean distance between each window in A and template T. 24 | % 25 | % Image deformation: 26 | % imNormalize - Various ways to normalize a (multidimensional) image. 27 | % imShrink - Used to shrink a multidimensional array I by integer amount. 28 | % imtransform2 - Applies a linear or nonlinear transformation to an image I. 29 | % jitterImage - Creates multiple, slightly jittered versions of an image. 30 | % textureMap - Maps texture in I according to rsDst and csDst. 31 | % 32 | % Generalized nonmaximal suppression: 33 | % nonMaxSupr - Applies nonmaximal suppression on an image of arbitrary dimension. 34 | % nonMaxSuprList - Applies nonmaximal suppression to a list. 35 | % nonMaxSuprWin - Nonmaximal suppression of values outside of a given window. 36 | % 37 | % Binary mask creation: 38 | % maskCircle - Creates an image of a 'pie slice' of a circle. 39 | % maskEllipse - Creates a binary image of an ellipse. 40 | % maskGaussians - Divides a volume into softly overlapping gaussian windows. 41 | % maskSphere - Creates an 'image' of a n-dimensional hypersphere. 42 | % 43 | % Linear filtering: 44 | % convnFast - Fast convolution, replacement for both conv2 and convn. 45 | % gaussSmooth - Applies Gaussian smoothing to a (multidimensional) image. 46 | % localSum - Fast routine for box, max and min filtering. 47 | % 48 | % Miscellaneous: 49 | % imMlGauss - Calculates max likelihood params of Gaussian that gave rise to image G. 50 | % imRectRot - Create a draggable, resizable, rotatable rectangle or ellipse. 51 | % imwrite2 - Similar to imwrite, except follows a strict naming convention. 52 | -------------------------------------------------------------------------------- /images/assignToBins.m: -------------------------------------------------------------------------------- 1 | function B = assignToBins( A, edges ) 2 | % Quantizes A according to values in edges. 3 | % 4 | % assignToBins replaces each value in A with a value between [0,nBins] where 5 | % nBins=length(edges)-1. edges must be a vector of monotonically 6 | % increasing values. Each element v in A gets converted to a discrete 7 | % value q such that edges(q)<=v< edges(q+1). If v==edges(end) then q=nBins. 8 | % If v does not fall into any bin, then q=0. See histc2 for more details 9 | % about edges. For even spaced edges can get away with rounding A 10 | % appropriately, see example below. 11 | % 12 | % USAGE 13 | % B = assignToBins( A, edges ) 14 | % 15 | % INPUTS 16 | % A - numeric array of arbitrary dimension 17 | % edges - quantization bounds, see histc2 18 | % 19 | % OUTPUTS 20 | % B - size(A) array of quantization levels, ints between [0,nBins] 21 | % 22 | % EXAMPLE 23 | % A = rand(5,5); 24 | % B1 = assignToBins(A,[0:.1:1]); 25 | % B2 = ceil(A*10); B1-B2 26 | % 27 | % See also HISTC2 28 | % 29 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 30 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 31 | % Licensed under the Simplified BSD License [see external/bsd.txt] 32 | 33 | if(~isa(A,'double')); A = double(A); end; 34 | 35 | if( length(edges)==1 ) % if nBins given instead of edges calculate edges 36 | edges = linspace( min(A(:))-eps, max(A(:))+eps, edges+1 ); end; 37 | 38 | B = assignToBins1( A, edges ); % assign bin number 39 | B = B + 1; % convert to 1 indexed 40 | B = reshape( B, size(A) ); % resize B to have correct shape 41 | B( B==(length(edges)) ) = 0; % vals outside or range get bin 0 42 | -------------------------------------------------------------------------------- /images/clusterMontage.m: -------------------------------------------------------------------------------- 1 | function IC = clusterMontage( I, IDX, nElem, pad ) 2 | % Used for visualization of clusters of images and videos. 3 | % 4 | % Organizes the matrix I, which is either MxNxR for images or MxNxTxR for 5 | % videos, into a [M x N x T x nElem x nCluster] array IC, where each 6 | % element IC(:,:,:,:,i) is the set of objects belonging to cluster i. 7 | % If not all clusters have the same size, if pad==1 blank elements are 8 | % added to pad the clusters so they do in fact have the same size, and if 9 | % pad is 0 then IC is a cell vector where IC{i} is the set of objects 10 | % belonging to cluster i. 11 | % 12 | % To display only a subset of clusters, given in a vector cs, use IDXb: 13 | % IDXb = zeros(size(IDX)); for i=1:length(cs) IDXb(IDX==cs(i))=i; end; 14 | % 15 | % USAGE 16 | % IC = clusterMontage( I, IDX, nElem, [pad] ) 17 | % 18 | % INPUTS 19 | % I - MxNxR array of images or MxNxTxR array of videos 20 | % IDX - cluster membership (Rx1 integer vector) [see kmeans2.m] 21 | % nElem - max number of instances to show of each cluster 22 | % pad - [1] pads each cluster w blanks so it has exactly nElem 23 | % 24 | % OUTPUTS 25 | % IC - if pad==1 [M x N x T x nElem x nCluster] array 26 | % - if pad==0 nCluster cell of [M x N x T x nElem_i] arrays 27 | % 28 | % EXAMPLE - images 29 | % load( 'images.mat' ); 30 | % keep=randSample(144,80); IDXi=IDXi(keep); images=images(:,:,keep); 31 | % IC = clusterMontage( images, IDXi, 9, 0 ); 32 | % figure(1); montage2( IC ) 33 | % 34 | % EXAMPLE - videos 35 | % load( 'images.mat' ); 36 | % IC = clusterMontage( videos, IDXv, 9, 0 ); 37 | % figure(1); playMovie( IC ) 38 | % 39 | % See also KMEANS2, MONTAGE2, PLAYMOVIE, CELL2ARRAY 40 | % 41 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 42 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 43 | % Licensed under the Simplified BSD License [see external/bsd.txt] 44 | 45 | if( nargin<4 || isempty(pad) ); pad=1; end 46 | 47 | % error check 48 | siz = size(I); nd = ndims(I); 49 | if(nd~=3 && nd~=4); error('I must be 3 or 4 dimensional array'); end; 50 | inds = {':'}; inds = inds(:,ones(1,nd-1)); 51 | 52 | % discard outliers 53 | keepLocs = find( IDX>0 ); IDX = IDX(keepLocs); I=I(inds{:},keepLocs); 54 | 55 | % sample both I and IDX so have nElem per cluster 56 | uIDX=unique(IDX)'; 57 | for i=uIDX 58 | locs = find(IDX==i); nLocs = length(locs); 59 | if( nLocs>nElem ) 60 | keepLocs = [find(IDX~=i); locs(randSample(nLocs,nElem))]; 61 | IDX = IDX(keepLocs); I=I(inds{:},keepLocs); 62 | elseif( nLocs 65 | I = cat( nd, I, repmat(uint8(0),[siz(1:nd-1) nAdd])); 66 | end; 67 | end; 68 | 69 | % string out I 70 | if( pad ) 71 | IC = repmat( uint8(0), [siz(1:nd-1), nElem, length(uIDX)] ); 72 | for i=uIDX; IC(inds{:},:,i) = I(inds{:},IDX==i); end 73 | else 74 | IC = cell(1,max(IDX)); 75 | for i=uIDX; IC{i} = I(inds{:},IDX==i); end 76 | end 77 | -------------------------------------------------------------------------------- /images/filmStrip.m: -------------------------------------------------------------------------------- 1 | function F = filmStrip( I, overlap, delta, border ) 2 | % Used to display R stacks of T images as a "filmstrip". 3 | % 4 | % See examples below to see what is meant by "filmstrip". 5 | % 6 | % USAGE 7 | % F = filmStrip( I, overlap, delta, border ) 8 | % 9 | % INPUTS 10 | % I - MxNxTxR or MxNx1xTxR or MxNx3xTxR array 11 | % (of bw or color images). R can equal 1. 12 | % overlap - amount of overlap between successive frames 13 | % delta - amount to shift each successive frame upward 14 | % border - width of black border around each frame 15 | % 16 | % OUTPUTS 17 | % F - filmstrip 18 | % 19 | % EXAMPLE - one filmstrip 20 | % load images; 21 | % F1 = filmStrip( video(:,:,1:15), 10, 2, 5 ); figure(1); im(F1); % one 22 | % F2 = filmStrip( videos(:,:,:,1:10), 5, 2, 3 ); figure(2); im(F2); % many 23 | % 24 | % See also MONTAGE2 25 | % 26 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 27 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 28 | % Licensed under the Simplified BSD License [see external/bsd.txt] 29 | 30 | % convert I to be of type double, and have dimensions MxNxCxTxR 31 | I = double(I); I = I/max(I(:)); sizI = size(I); 32 | if(~any(sizI(3)==[1 3])); I=reshape(I,[sizI(1:2),1,sizI(3:end)]); end 33 | I = padarray( I, [border border 0 0 0], 0, 'both' ); 34 | [mRows, nCols, nColor, nFrame, nStrip] = size(I); 35 | 36 | % size of final filmstip object 37 | sizF1 = [mRows+delta*(nFrame-1), nFrame*nCols-overlap*(nFrame-1), nColor]; 38 | sizF=sizF1; sizF(1)=sizF1(1)*nStrip - ((nFrame-1-2)*delta)*(nStrip-1); 39 | mRowsF1 = sizF1(1); 40 | 41 | for i=1:nStrip 42 | 43 | % Create i-th film strip 44 | Fi = -ones( sizF1 ); row = 1; col = sizF1(2); 45 | for f=nFrame:-1:1 46 | Fi( row:(row+mRows-1), (col-nCols+1):col, : ) = I(:,:,:,f,i); 47 | row = row + delta; col = col - nCols + overlap; 48 | end 49 | 50 | % stop if creating single filmstrip 51 | if( nStrip==1 ); F=Fi; break; end 52 | 53 | % merge with the previous film strips 54 | if( i==1 ); F = -ones( sizF ); row2=1; end 55 | Fc = F( row2:(row2+mRowsF1-1), : ); 56 | locs=(Fc<0); Fc(locs) = Fi(locs); 57 | F( row2:(row2+mRowsF1-1), : ) = Fc; 58 | row2 = row2 + mRowsF1 - ((nFrame-1-2)*delta); 59 | end 60 | F(F<0)=1; 61 | -------------------------------------------------------------------------------- /images/gaussSmooth.m: -------------------------------------------------------------------------------- 1 | function [L,filters] = gaussSmooth( I, sigmas, shape, radius ) 2 | % Applies Gaussian smoothing to a (multidimensional) image. 3 | % 4 | % Smooths the n-dimensional array I with a n-dimensional gaussian with 5 | % standard deviations specified by sigmas. This operation in linearly 6 | % seperable and is implemented as such. 7 | % 8 | % USAGE 9 | % [L,filters] = gaussSmooth( I, sigmas, [shape], [radius] ) 10 | % 11 | % INPUTS 12 | % I - input image 13 | % sigmas - either n dimensional or 1 dimensional vector of standard devs 14 | % if sigmas(n)<=.3 then does not smooth along that dimension 15 | % shape - ['full'] shape flag 'valid', 'full', 'same', or 'smooth' 16 | % radius - [2.25] radius in units of standard deviation 17 | % 18 | % OUTPUTS 19 | % L - smoothed image 20 | % filters - actual filters used, cell array of length n 21 | % 22 | % EXAMPLE 23 | % load trees; I=ind2gray(X,map); 24 | % I2 = gaussSmooth( I, 1, 'same' ); 25 | % figure(1); im(I); figure(2); im(I2); 26 | % 27 | % See also FILTERGAUSS 28 | % 29 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 30 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 31 | % Licensed under the Simplified BSD License [see external/bsd.txt] 32 | 33 | nd = ndims(I); if(length(sigmas)==1); sigmas=repmat(sigmas,[1,nd]); end 34 | if( nd > length(sigmas)); error('Incorrect # of simgas specified'); end 35 | sigmas = sigmas(1:nd); 36 | 37 | if( isa( I, 'uint8' ) ); I = double(I); end 38 | if( nargin<3 || isempty(shape) ); shape='full'; end 39 | if( nargin<4 || isempty(radius) ); radius=2.25; end 40 | 41 | % create and apply 1D gaussian masks along each dimension 42 | L = I; filters = cell(1,nd); 43 | for i=1:nd 44 | if (sigmas(i)>.3) 45 | r = ceil( sigmas(i)*radius ); 46 | f = filterGauss( 2*r+1, [], sigmas(i)^2 ); 47 | f = permute( f, circshift(1:nd,[1,i-1]) ); 48 | filters{i} = f; 49 | L = convnFast( L, f, shape ); 50 | else 51 | filters{i} = 1; 52 | end 53 | end 54 | 55 | -------------------------------------------------------------------------------- /images/histMontage.m: -------------------------------------------------------------------------------- 1 | function histMontage( HS, mm, nn ) 2 | % Used to display multiple 1D histograms. 3 | % 4 | % USAGE 5 | % histMontage( HS, mm, nn ) 6 | % 7 | % INPUTS 8 | % HS - HS(i,j) is the jth bin in the ith histogram 9 | % mm - [] #images/row (if [] then calculated based on nn) 10 | % nn - [] #images/col (if [] then calculated based on mm) 11 | % 12 | % OUTPUTS 13 | % 14 | % EXAMPLE 15 | % h = histc2( randn(2000,1), 20 )'; clf; histMontage([h; h]); 16 | % 17 | % See also HISTC, HISTC2 18 | % 19 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 20 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 21 | % Licensed under the Simplified BSD License [see external/bsd.txt] 22 | 23 | [nhist, nbins] = size(HS); 24 | if( nhist>100 || nhist*nbins>10000 ) 25 | error('Too much histogram data to display!'); end; 26 | 27 | % get layout of images (mm=#images/row, nn=#images/col) 28 | if (nargin<3 || isempty(mm) || isempty(nn)) 29 | if (nargin==1 || (nargin==2 && isempty(mm)) || (nargin==3 && ... 30 | isempty(mm) && isempty(nn)) ) 31 | nn = round(sqrt(nhist)); 32 | mm = ceil( nhist / nn ); 33 | elseif (isempty(mm)) 34 | mm = ceil( nhist / nn ); 35 | else 36 | nn = ceil( nhist / mm ); 37 | end; 38 | end; 39 | 40 | % plot each histogram 41 | clf; 42 | for q=1:nhist 43 | if( nhist>1 ); subplot( mm, nn, q ); end; 44 | bar( HS(q,:), 1 ); shading('flat'); 45 | ylim( [0,1] ); set( gca, 'YTick', [] ); 46 | xlim( [.5, nbins+.5] ); set( gca, 'XTick', [] ); 47 | end; 48 | -------------------------------------------------------------------------------- /images/histcImWin.m: -------------------------------------------------------------------------------- 1 | function H = histcImWin( I, edges, wtMask, shape ) 2 | % Calculates local histograms at every point in an image I. 3 | % 4 | % H(i,j,...,k,:) will contain the histogram at location (i,j,...,k), as 5 | % calculated by weighing values in I by placing wtMask at that 6 | % location. For example, if wtMask is ones(windowSize) then the 7 | % histogram at every location will simply be a histogram of the pixels 8 | % within that window. See histc2 for more information about histgorams. 9 | % See convnFast for information on shape flags. 10 | % 11 | % USAGE 12 | % H = histcImWin( I, edges, wtMask, [shape] ) 13 | % 14 | % INPUTS 15 | % I - image (possibly multidimensional) [see above] 16 | % edges - quantization bounds, see histc2 17 | % wtMask - numeric array of weights, or cell array of sep kernels 18 | % shape - ['full'], 'valid', 'same', or 'smooth' 19 | % 20 | % OUTPUTS 21 | % H - [size(I)xnBins] array of size(I) histograms 22 | % 23 | % EXAMPLE 24 | % load trees; L=conv2(X,filterDog2d(10,4,1,0),'valid'); figure(1); im(L); 25 | % f1=filterGauss(25,[],25); f2=ones(1,15); 26 | % H1 = histcImWin(L, 15, {f1,f1'}, 'same'); figure(2); montage2(H1); 27 | % H2 = histcImWin(L, 15, {f2,f2'}, 'same'); figure(3); montage2(H2); 28 | % 29 | % See also ASSIGNTOBINS, HISTC2, CONVNFAST, HISTCIMLOC 30 | % 31 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 32 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 33 | % Licensed under the Simplified BSD License [see external/bsd.txt] 34 | 35 | if( nargin<4 || isempty(shape) ); shape = 'full'; end; 36 | if( ~iscell(wtMask) ); wtMask={wtMask}; end; 37 | 38 | % split I into channels 39 | I = assignToBins( I, edges ); 40 | nBins=length(edges)-1; if(nBins==0); nBins=edges; end; 41 | nd = ndims(I); siz=size(I); maxI = max(I(:)); 42 | if( nd==2 && siz(2)==1); nd=1; siz=siz(1); end; 43 | QI = false( [siz maxI] ); 44 | inds = {':'}; inds = inds(:,ones(1,nd)); 45 | for i=1:nBins; QI(inds{:},i)=(I==i); end; 46 | H = double( QI ); 47 | 48 | % convolve with wtMask to get histograms, scale appropriately 49 | for i=1:length(wtMask) 50 | wtMaski = wtMask{i}; 51 | for d=1:ndims(wtMaski); wtMaski = flipdim(wtMaski,d); end; 52 | wtMaski = wtMaski / sum(wtMaski(:)); 53 | H = convnFast( H, wtMaski, shape ); 54 | end; 55 | -------------------------------------------------------------------------------- /images/im.m: -------------------------------------------------------------------------------- 1 | function varargout = im( I, range, extraInf ) 2 | % Function for displaying grayscale images. 3 | % 4 | % Handy function for showing a grayscale or color image with a colorbar. 5 | % 6 | % USAGE 7 | % h = im( I, [range], [extraInf] ) 8 | % 9 | % INPUTS 10 | % I - image in a valid format for imagesc 11 | % range - [] minval/maxval for imagesc 12 | % extraInf - [1] if 1 then colorbar is shown as well as tick marks 13 | % 14 | % OUTPUTS 15 | % h - handle for image graphics object 16 | % 17 | % EXAMPLE 18 | % load clown; im( X ) 19 | % 20 | % See also imshow, imview, impixelinfo, imtool, imagesc 21 | % 22 | % Piotr's Computer Vision Matlab Toolbox Version 2.41 23 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 24 | % Licensed under the Simplified BSD License [see external/bsd.txt] 25 | if( nargin<1 || isempty(I)); I=0; end; 26 | if( nargin<2 || isempty(range)), range=[]; end 27 | if( nargin<3 || isempty(extraInf)); extraInf=1; end; 28 | % display image using imagesc 29 | if(isempty(range)), h=imagesc(I); else h=imagesc(I,range); end 30 | % set basic and optional properties 31 | colormap(gray); title(inputname(1)); axis('image'); 32 | if( extraInf ), colorbar; else set(gca,'XTick',[],'YTick',[]); end 33 | % output h only if output argument explicitly requested 34 | if(nargout>0), varargout={h}; end 35 | end 36 | 37 | % whitebg('black'); set(gcf,'color', [0 0 0]); %black background 38 | % set(gcf,'menubar','none'); % no menu 39 | -------------------------------------------------------------------------------- /images/images.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/images/images.mat -------------------------------------------------------------------------------- /matlab/arrayCrop.m: -------------------------------------------------------------------------------- 1 | function I = arrayCrop( I, strLocs, endLocs, padEl ) 2 | % Used to crop a rectangular region from an n dimensional array. 3 | % 4 | % Guarantees that the resulting array will have dims as specified by rect 5 | % by filling in locations with padEl if the locations are outside of array. 6 | % 7 | % USAGE 8 | % I = arrayCrop( I, strLocs, endLocs, [padEl] ) 9 | % 10 | % INPUTS 11 | % I - n dimensional array to crop window from 12 | % strLocs - locs at which to start cropping along each dim 13 | % endLocs - locs at which to end cropping along each dim 14 | % padEl - [0] element with which to pad 15 | % 16 | % OUTPUTS 17 | % I - cropped array 18 | % 19 | % EXAMPLE 20 | % I=randn(10); IC=arrayCrop( I, [-1 1], [10 10], 0 ); 21 | % 22 | % See also PADARRAY, ARRAYTODIMS 23 | % 24 | % Piotr's Computer Vision Matlab Toolbox Version 2.02 25 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 26 | % Licensed under the Simplified BSD License [see external/bsd.txt] 27 | 28 | if( nargin<4 || isempty(padEl)); padEl=0; end 29 | nd = ndims(I); siz = size(I); 30 | [strLocs,er] = checkNumArgs(strLocs,size(siz),0,0); error(er); 31 | [endLocs,er] = checkNumArgs(endLocs,size(siz),0,0); error(er); 32 | if( any(strLocs>endLocs)); error('strLocs must be <= endLocs'); end 33 | 34 | % crop a real rect [accelerate implementation if nd==2 or nd==3] 35 | strL1 = max(strLocs,1); endL1 = min(endLocs, siz); 36 | if( nd==2 ) 37 | I = I( strL1(1):endL1(1), strL1(2):endL1(2) ); 38 | elseif( nd==3 ) 39 | I = I( strL1(1):endL1(1), strL1(2):endL1(2), strL1(3):endL1(3) ); 40 | else 41 | extract = cell( nd, 1 ); 42 | for d=1:nd; extract{d} = strL1(d):endL1(d); end 43 | I = I( extract{:} ); 44 | end 45 | 46 | % then pad as appropriate (essentially inlined padarray) 47 | if( any(strLocs<1) || any(endLocs>siz) ) 48 | padEl = feval( class(I), padEl ); 49 | padPre = 1 - min( strLocs, 1 ); 50 | sizPadded = endLocs-strLocs+1; 51 | idx=cell(1,nd); 52 | for d=1:nd; idx{d}=(1:size(I,d))+padPre(d); end 53 | Ib = repmat( padEl, sizPadded ); 54 | Ib(idx{:})=I; I=Ib; 55 | end 56 | -------------------------------------------------------------------------------- /matlab/arrayToDims.m: -------------------------------------------------------------------------------- 1 | function IC = arrayToDims( I, dims, padEl ) 2 | % Pads or crops I appropriately so that size(IC)==dims. 3 | % 4 | % For each dimension d, if size(I,d) is larger then dims(d) then 5 | % symmetrically crops along d (if cropping amount is odd crops one more 6 | % unit from the start of the dimension). If size(I,d) is smaller then 7 | % dims(d) then symmetrically pads along d with padEl (if padding amount is 8 | % even then pads one more unit along the start of the dimension). 9 | % 10 | % USAGE 11 | % IC = arrayToDims( I, dims, [padEl] ) 12 | % 13 | % INPUTS 14 | % I - n dim array to crop window from (for arrays can only crop) 15 | % dims - dimensions to make I 16 | % padEl - [0] element with which to pad 17 | % 18 | % OUTPUTS 19 | % IC - cropped array 20 | % 21 | % EXAMPLE 22 | % I=randn(10); delta=1; IC=arrayToDims(I,size(I)-2*delta); 23 | % 24 | % See also ARRAYCROP, PADARRAY 25 | % 26 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 27 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 28 | % Licensed under the Simplified BSD License [see external/bsd.txt] 29 | 30 | if( nargin<3 || isempty(padEl)); padEl=0; end 31 | nd = ndims(I); siz = size(I); 32 | [dims,er] = checkNumArgs( dims, size(siz), 0, 1 ); error(er); 33 | if(any(dims==0)); IC=[]; return; end 34 | 35 | % get start and end locations for cropping 36 | strLocs = ones( 1, nd ); endLocs = siz; 37 | for d=1:nd 38 | delta = siz(d) - dims(d); 39 | if ( delta~=0 ) 40 | deltaHalf = floor( delta / 2 ); 41 | deltaRem = delta - 2*deltaHalf; 42 | strLocs(d) = 1 + (deltaHalf + deltaRem); 43 | endLocs(d) = siz(d) - deltaHalf; 44 | end 45 | end 46 | 47 | % call arrayCrop 48 | IC = arrayCrop( I, strLocs, endLocs, padEl ); 49 | -------------------------------------------------------------------------------- /matlab/c.m: -------------------------------------------------------------------------------- 1 | % clc - clear command window. 2 | % 3 | % USAGE 4 | % c 5 | % 6 | % INPUTS 7 | % 8 | % OUTPUTS 9 | % 10 | % EXAMPLE 11 | % 12 | % See also CLC, CC, CCC 13 | % 14 | % Piotr's Computer Vision Matlab Toolbox Version 1.5 15 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 16 | % Licensed under the Simplified BSD License [see external/bsd.txt] 17 | 18 | clc 19 | -------------------------------------------------------------------------------- /matlab/cc.m: -------------------------------------------------------------------------------- 1 | % close all, clc 2 | % 3 | % USAGE 4 | % cc 5 | % 6 | % INPUTS 7 | % 8 | % OUTPUTS 9 | % 10 | % EXAMPLE 11 | % 12 | % See also C, CCC 13 | % 14 | % Piotr's Computer Vision Matlab Toolbox Version 1.5 15 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 16 | % Licensed under the Simplified BSD License [see external/bsd.txt] 17 | 18 | close all; clc 19 | -------------------------------------------------------------------------------- /matlab/ccc.m: -------------------------------------------------------------------------------- 1 | % clear, close all, clc, clear global 2 | % 3 | % USAGE 4 | % ccc 5 | % 6 | % INPUTS 7 | % 8 | % OUTPUTS 9 | % 10 | % EXAMPLE 11 | % 12 | % See also C, CC 13 | % 14 | % Piotr's Computer Vision Matlab Toolbox Version 1.5 15 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 16 | % Licensed under the Simplified BSD License [see external/bsd.txt] 17 | 18 | clear; close all; clc; clear all; 19 | -------------------------------------------------------------------------------- /matlab/cell2array.m: -------------------------------------------------------------------------------- 1 | function Y = cell2array( X, padEl ) 2 | % Flattens a cell array of regular arrays into a regular array. 3 | % 4 | % Each element of X must be a regular array, and must have the same number 5 | % of dimensions k. Converts X to an array Y of dimension k+1 where 6 | % Y(:,:...,:,i) is X{i} padded to be as big as the biggest element in X 7 | % (along each dimension). Specifically, let di1..dik be the k dimensions of 8 | % element X{i}. Let dj=max(dij) for each j. Then each element of X{i} is 9 | % padded to have size [d1 ... dk], and then the elements of X are stacked 10 | % into a vector. Treats the cell array X as a vector (so ignores the 11 | % layout of X). 12 | % 13 | % USAGE 14 | % Y = cell2array( X, [padEl] ) 15 | % 16 | % INPUTS 17 | % X - cell array of regular arrays each with dimension k 18 | % padEl - [0] element with which to pad 19 | % 20 | % OUTPUTS 21 | % Y - resulting array of dimension k+1 22 | % 23 | % EXAMPLE 24 | % for i=1:10; X{i}=rand(30); end; Y = cell2array(X); 25 | % 26 | % See also MAT2CELL2, CELL2MAT 27 | % 28 | % Piotr's Computer Vision Matlab Toolbox Version 2.40 29 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 30 | % Licensed under the Simplified BSD License [see external/bsd.txt] 31 | 32 | if(~iscell(X)); error('X must be a cell array'); end 33 | if(iscell(X{1})); error('X must contain regular arrays'); end 34 | n = numel(X); nd = ndims(X{1}); 35 | for i=2:n 36 | if(ndims(X{i})~=nd); error('all elem of X must have same dims'); end 37 | end 38 | if(nargin<2); padEl=0; end 39 | 40 | %%% get maximum and minimum size of any element of X 41 | maxsiz = size(X{1}); minsiz = size(X{1}); 42 | for i=1:n 43 | siz = size(X{i}); 44 | maxsiz = max( maxsiz, siz ); 45 | minsiz = min( minsiz, siz ); 46 | end 47 | 48 | %%% construct Y 49 | inds=cell(1,nd); for d=1:nd; inds{d} = 1:maxsiz(d); end 50 | Y = zeros( [maxsiz n], class(X{1}) ); 51 | if( all(maxsiz==minsiz) ) 52 | for i=1:n; Y( inds{:}, i ) = X{i}; end 53 | else 54 | for i=1:n; Y( inds{:}, i ) = arrayToDims( X{i}, maxsiz, padEl); end 55 | end 56 | -------------------------------------------------------------------------------- /matlab/char2img.m: -------------------------------------------------------------------------------- 1 | function masks = char2img( strings, h, pad ) 2 | % Convert ascii text to a binary image using pre-computed templates. 3 | % 4 | % Input strings can only contain standard characters (ascii character 5 | % 32-126). First time char2img() is ever called with a given height h, 6 | % txt2img() is used to create a template for each ascii character. All 7 | % subsequent calls to to char2img() with the given height are very fast as 8 | % the pre-computed templates are used and no display/screen capture is 9 | % needed. 10 | % 11 | % USAGE 12 | % masks = char2img( strings, h, [pad] ) 13 | % 14 | % INPUTS 15 | % strings - {1xn} text string or cell array of text strings to convert 16 | % h - font height in pixels 17 | % pad - [0] amount of extra padding between chars 18 | % 19 | % OUTPUTS 20 | % masks - {1xn} binary image masks of height h for each string 21 | % 22 | % EXAMPLE 23 | % mask=char2img('hello world',50); im(mask{1}) 24 | % mask=char2img(num2str(pi),35); im(mask{1}) 25 | % 26 | % See also TXT2IMG 27 | % 28 | % Piotr's Computer Vision Matlab Toolbox Version 2.65 29 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 30 | % Licensed under the Simplified BSD License [see external/bsd.txt] 31 | 32 | % load or create character templates (or simply store persistently) 33 | persistent chars h0 34 | if(isempty(h0) || h0~=h) 35 | pth=fileparts(mfilename('fullpath')); 36 | fName=sprintf('%s/private/char2img_h%03i.mat',pth,h); h0=h; 37 | if(exist(fName,'file')), load(fName); else 38 | chars=char(32:126); chars=num2cell(chars); 39 | chars=txt2img(chars,h,{'Interpreter','none'}); 40 | save(fName,'chars'); 41 | end 42 | end 43 | % add padding to chars 44 | if(nargin<3 || isempty(pad)), pad=0; end 45 | charsPad=chars; if(pad), pad=ones(h,pad,'uint8'); 46 | for i=1:length(chars), charsPad{i}=[pad chars{i} pad]; end; end 47 | % create actual string using templates 48 | if(~iscell(strings)), strings={strings}; end 49 | n=length(strings); masks=cell(1,n); 50 | for s=1:n, str=strings{s}; 51 | str(str<32 | str>126)=32; str=uint8(str-31); 52 | M=[charsPad{str}]; masks{s}=M; 53 | end 54 | -------------------------------------------------------------------------------- /matlab/dijkstra.m: -------------------------------------------------------------------------------- 1 | function [D,P] = dijkstra( G, varargin ) 2 | % Runs Dijkstra's shortest path algorithm on a distance matrix. 3 | % 4 | % Runs Dijkstra's on the given SPARSE nxn distance matrix G, where missing 5 | % values mean no edge (infinite distance). Uses a Finonacci heap resulting 6 | % in fast computation. Finds the shortest path distance from every point 7 | % S(i) in the 1xp source vector S to every other point j, resulting in a 8 | % pxn distance matrix D. P(i,j) contains the second to last node on the 9 | % path from S(i) to j. If point j is not reachable from point S(i) then 10 | % D(i,j)=inf and P(i,j)=-1. 11 | % 12 | % USAGE 13 | % [D P] = dijkstra( G, [S] ) 14 | % 15 | % INPUT 16 | % G - sparse nxn distance matrix 17 | % S - 1xp array of source indices i 18 | % 19 | % OUPUT 20 | % D - pxn - shortest path lengths from S(i) to j 21 | % P - pxn - indicies of second to last node on path from S(i) to j 22 | % 23 | % EXAMPLE 24 | % n=11; G=sparse(n,n); for i=1:n-1, G(i,i+1)=1; end; G=G+G'; 25 | % [D,P] = dijkstra(G,5), % D=[4:-1:0 1:6]; P=[2:5 -1 5:10]; 26 | % 27 | % See also 28 | % 29 | % Piotr's Computer Vision Matlab Toolbox Version 3.20 30 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 31 | % Licensed under the Simplified BSD License [see external/bsd.txt] 32 | 33 | [D,P] = dijkstra1( G, varargin{:} ); 34 | -------------------------------------------------------------------------------- /matlab/diskFill.m: -------------------------------------------------------------------------------- 1 | function diskFill( tDir, nGig ) 2 | % Fill a harddisk with garbage files (useful before discarding disk). 3 | % 4 | % USAGE 5 | % diskFill( tDir, nGig ) 6 | % 7 | % INPUTS 8 | % tDir - target directory to fill with garbage 9 | % nGig - maximum number of gigabytes to write to disk 10 | % 11 | % OUTPUTS 12 | % 13 | % EXAMPLE 14 | % diskFill( 'k:', 500 ) 15 | % 16 | % See also 17 | % 18 | % Piotr's Computer Vision Matlab Toolbox Version 2.61 19 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 20 | % Licensed under the Simplified BSD License [see external/bsd.txt] 21 | 22 | nm = sprintf('%s/garbage_%s_%05i_%%05i.mat',tDir,date,round(rand*10^5)); 23 | tid = ticStatus(); 24 | for i=1:nGig 25 | % write up to 1 GB of garbage bytes in chunks of 1 MB 26 | fid=fopen(sprintf(nm,i),'w'); mb=2^20; n=0; o=mb; 27 | while(n<2^30 && o==mb), o=fwrite(fid,rand(mb,1)); n=n+o; end 28 | try fclose(fid); catch, end; tocStatus( tid, i/nGig ); %#ok 29 | % if write failed (k<1), disk is presumably full 30 | if( o1 && all(s(1:2)=='0.')), s=s(2:end); end 49 | s=s(1:min(end,maxLen)); if(M1(i,j)>maxM/2), col='k'; else col='w'; end 50 | text(j,i,s,'col',col,txtAlign{:},pvPairs{:}); 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /matlab/fevalArrays.m: -------------------------------------------------------------------------------- 1 | function B = fevalArrays( A, fHandle, varargin ) 2 | % Used to apply the same operation to a stack of array elements. 3 | % 4 | % The only constraint on the function specified in fHandle is that given 5 | % two differrent input arrays a1 and a2, if a1 and a2 have the same 6 | % dimensions then the outputs b1 and b2 must have the same dimensions. For 7 | % long operations shows progress information. 8 | % 9 | % A can have arbitrary dimension. Suppose A has size d1 x d2 ... x dn. 10 | % Then for the purpose of this function A has dn elements, where 11 | % A(:,:,...,i) is the ith element. This function then applies the 12 | % operation in fHandle, with paramters given in varargin, to each element 13 | % in A. The results are returned in the array B, of size f1 x f2 x ... x fk 14 | % x dn. Each of the n element of B of the form B(:,:,...,i) is the the 15 | % result of applying fHandle to A(:,:,...,i). A may also be a cell array, 16 | % see the last example. 17 | % 18 | % A limitation of fevalArrays is that it does not pass state information 19 | % to fHandle. For example, fHandle may want to know how many times it's 20 | % been called. This can be overcome by saving state information inside 21 | % fHandle using 'persistent' variables. For an example see imwrite2. 22 | % 23 | % USAGE 24 | % B = fevalArrays( A, fHandle, varargin ) 25 | % 26 | % INPUTS 27 | % A - input array 28 | % fHandle - operation to apply to each 'element' of A 29 | % params - [varargin] parameters for each operation specified by fHandle 30 | % 31 | % OUTPUTS 32 | % B - output array 33 | % 34 | % EXAMPLE 35 | % B = fevalArrays( A, @rgb2gray ); % where A is MxNx3xR 36 | % B = fevalArrays( A, @imresize, .5 ); % where A is MxNxR 37 | % B = fevalArrays( A, @imNormalize ); % where A has arbitrary dims 38 | % B = fevalArrays( A, @(x) {imresize(x{1},.5)} ); % A is cell array 39 | % 40 | % See also FEVALIMAGES, FEVALMATS, ARRAYFUN 41 | % IMWRITE2, PERSISTENT, TICSTATUS, 42 | % 43 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 44 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 45 | % Licensed under the Simplified BSD License [see external/bsd.txt] 46 | 47 | nd = ndims(A); siz = size(A); n = siz(end); 48 | indsA = {':'}; indsA = indsA(ones(nd-1,1)); 49 | 50 | ticId = ticStatus('fevalArrays',[],60); 51 | for i=1:n 52 | % apply fHandle to each element of A 53 | b = feval( fHandle, A(indsA{:},i), varargin{:} ); 54 | if( i==1 ) 55 | ndb = ndims(b); 56 | if(ndb==2 && size(b,2)==1); ndb=1; end 57 | onesNdb = ones(1,ndb); 58 | B = repmat( b, [onesNdb,n] ); 59 | indsB = {':'}; indsB = indsB(onesNdb); 60 | else 61 | B(indsB{:},i) = b; 62 | end; 63 | tocStatus( ticId, i/n ); 64 | end 65 | -------------------------------------------------------------------------------- /matlab/fevalDistrDisk.m: -------------------------------------------------------------------------------- 1 | function fevalDistrDisk( funNm, jobDir, jobId ) 2 | % Helper for fevalDistr (do no call directly). 3 | % 4 | % USAGE 5 | % fevalDistrDisk( funNm, jobDir, jobId ) 6 | % 7 | % INPUTS 8 | % 9 | % OUTPUTS 10 | % 11 | % EXAMPLE 12 | % 13 | % See also fevalDistr 14 | % 15 | % Piotr's Computer Vision Matlab Toolbox Version 3.02 16 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 17 | % Licensed under the Simplified BSD License [see external/bsd.txt] 18 | jobId=[jobDir int2str2(str2double(jobId),10)]; 19 | fIn=[jobId '-in.mat']; if(exist(fIn,'file')~=2), return; end 20 | job=load(fIn); job=job.job; 21 | r=feval(funNm,job{:}); save([jobId '-out'],'r'); %#ok 22 | f=fopen([jobId '-done'],'w'); fclose(f); 23 | end 24 | -------------------------------------------------------------------------------- /matlab/figureResized.m: -------------------------------------------------------------------------------- 1 | function varargout = figureResized( screenratio, varargin ) 2 | % Creates a figures that takes up certain area of screen. 3 | % 4 | % Almost same as figure, except get to specify what fraction of available 5 | % screen space figure should take up. Figure appears in center of screen. 6 | % 7 | % USAGE 8 | % varargout = figureResized( screenratio, varargin ) 9 | % 10 | % INPUTS 11 | % screenratio - controls fraction of screen image takes out (<=.8) 12 | % varargin - parameters to figure 13 | % 14 | % OUTPUTS 15 | % varargout - out from figure 16 | % 17 | % EXAMPLE 18 | % figureResized( .75 ) 19 | % 20 | % See also FIGURE 21 | % 22 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 23 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 24 | % Licensed under the Simplified BSD License [see external/bsd.txt] 25 | 26 | if( nargin<1 ); screenratio=.3; end 27 | if( screenratio>1 ); error('screenratio must be <= 1'); end 28 | 29 | % call figure 30 | h = figure( varargin{:} ); 31 | if( nargout ); varargout = {h}; end; 32 | 33 | % get dimensions of screen and what want figure to be 34 | units = get(0,'Units'); 35 | ss = get(0,'ScreenSize'); 36 | st = (1 - screenratio)/2; 37 | pos = [st*ss(3), st*ss(4), screenratio*ss(3), screenratio*ss(4)]; 38 | 39 | % set dimensions of figure 40 | set( h, 'Units', units ); 41 | set( h, 'Position', pos ); 42 | -------------------------------------------------------------------------------- /matlab/gauss2ellipse.m: -------------------------------------------------------------------------------- 1 | function [cRow, cCol, ra, rb, phi] = gauss2ellipse( mu, C, rad ) 2 | % Creates an ellipse representing the 2D Gaussian distribution. 3 | % 4 | % Creates an ellipse representing the 2D Gaussian distribution with mean mu 5 | % and covariance matrix C. Returns 5 parameters that specify the ellipse. 6 | % 7 | % USAGE 8 | % [cRow, cCol, ra, rb, phi] = gauss2ellipse( mu, C, [rad] ) 9 | % 10 | % INPUTS 11 | % mu - 1x2 vector representing the center of the ellipse 12 | % C - 2x2 cov matrix 13 | % rad - [2] Number of std to create the ellipse to 14 | % 15 | % OUTPUTS 16 | % cRow - the row location of the center of the ellipse 17 | % cCol - the column location of the center of the ellipse 18 | % ra - semi-major axis length (in pixels) of the ellipse 19 | % rb - semi-minor axis length (in pixels) of the ellipse 20 | % phi - rotation angle (radians) of semimajor axis from x-axis 21 | % 22 | % EXAMPLE 23 | % [cRow, cCol, ra, rb, phi] = gauss2ellipse( [5 5], [1 0; .5 2] ) 24 | % plotEllipse( cRow, cCol, ra, rb, phi ); 25 | % 26 | % See also PLOTELLIPSE, PLOTGAUSSELLIPSES, MASKELLIPSE 27 | % 28 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 29 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 30 | % Licensed under the Simplified BSD License [see external/bsd.txt] 31 | 32 | if (nargin<3 || isempty(rad) ); rad=2; end; 33 | 34 | % error check 35 | if (~all(size(mu)==[1,2]) || ~all(size(C)==[2,2])) 36 | error('Works only for 2D Gaussians'); end 37 | 38 | % decompose using SVD 39 | [~,D,R] = svd(C); 40 | normstd = sqrt( diag( D ) ); 41 | 42 | % get angle of rotation (in row/column format) 43 | phi = acos(R(1,1)); 44 | if (R(2,1) < 0); phi = 2*pi - phi; end 45 | phi = pi/2 - phi; 46 | 47 | % get ellipse radii 48 | ra = rad*normstd(1); 49 | rb = rad*normstd(2); 50 | 51 | % center of ellipse 52 | cRow = mu(1); 53 | cCol = mu(2); 54 | -------------------------------------------------------------------------------- /matlab/getPrmDflt.m: -------------------------------------------------------------------------------- 1 | function varargout = getPrmDflt( prm, dfs, checkExtra ) 2 | % Helper to set default values (if not already set) of parameter struct. 3 | % 4 | % Takes input parameters and a list of 'name'/default pairs, and for each 5 | % 'name' for which prm has no value (prm.(name) is not a field or 'name' 6 | % does not appear in prm list), getPrmDflt assigns the given default 7 | % value. If default value for variable 'name' is 'REQ', and value for 8 | % 'name' is not given, an error is thrown. See below for usage details. 9 | % 10 | % USAGE (nargout==1) 11 | % prm = getPrmDflt( prm, dfs, [checkExtra] ) 12 | % 13 | % USAGE (nargout>1) 14 | % [ param1 ... paramN ] = getPrmDflt( prm, dfs, [checkExtra] ) 15 | % 16 | % INPUTS 17 | % prm - param struct or cell of form {'name1' v1 'name2' v2 ...} 18 | % dfs - cell of form {'name1' def1 'name2' def2 ...} 19 | % checkExtra - [0] if 1 throw error if prm contains params not in dfs 20 | % if -1 if prm contains params not in dfs adds them 21 | % 22 | % OUTPUTS (nargout==1) 23 | % prm - parameter struct with fields 'name1' through 'nameN' assigned 24 | % 25 | % OUTPUTS (nargout>1) 26 | % param1 - value assigned to parameter with 'name1' 27 | % ... 28 | % paramN - value assigned to parameter with 'nameN' 29 | % 30 | % EXAMPLE 31 | % dfs = { 'x','REQ', 'y',0, 'z',[], 'eps',1e-3 }; 32 | % prm = getPrmDflt( struct('x',1,'y',1), dfs ) 33 | % [ x y z eps ] = getPrmDflt( {'x',2,'y',1}, dfs ) 34 | % 35 | % See also INPUTPARSER 36 | % 37 | % Piotr's Computer Vision Matlab Toolbox Version 2.60 38 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 39 | % Licensed under the Simplified BSD License [see external/bsd.txt] 40 | 41 | if( mod(length(dfs),2) ), error('odd number of default parameters'); end 42 | if nargin<=2, checkExtra = 0; end 43 | 44 | % get the input parameters as two cell arrays: prmVal and prmField 45 | if iscell(prm) && length(prm)==1, prm=prm{1}; end 46 | if iscell(prm) 47 | if(mod(length(prm),2)), error('odd number of parameters in prm'); end 48 | prmField = prm(1:2:end); prmVal = prm(2:2:end); 49 | else 50 | if(~isstruct(prm)), error('prm must be a struct or a cell'); end 51 | prmVal = struct2cell(prm); prmField = fieldnames(prm); 52 | end 53 | 54 | % get and update default values using quick for loop 55 | dfsField = dfs(1:2:end); dfsVal = dfs(2:2:end); 56 | if checkExtra>0 57 | for i=1:length(prmField) 58 | j = find(strcmp(prmField{i},dfsField)); 59 | if isempty(j), error('parameter %s is not valid', prmField{i}); end 60 | dfsVal(j) = prmVal(i); 61 | end 62 | elseif checkExtra<0 63 | for i=1:length(prmField) 64 | j = find(strcmp(prmField{i},dfsField)); 65 | if isempty(j), j=length(dfsVal)+1; dfsField{j}=prmField{i}; end 66 | dfsVal(j) = prmVal(i); 67 | end 68 | else 69 | for i=1:length(prmField) 70 | dfsVal(strcmp(prmField{i},dfsField)) = prmVal(i); 71 | end 72 | end 73 | 74 | % check for missing values 75 | if any(strcmp('REQ',dfsVal)) 76 | cmpArray = find(strcmp('REQ',dfsVal)); 77 | error(['Required field ''' dfsField{cmpArray(1)} ''' not specified.'] ); 78 | end 79 | 80 | % set output 81 | if nargout==1 82 | varargout{1} = cell2struct( dfsVal, dfsField, 2 ); 83 | else 84 | varargout = dfsVal; 85 | end 86 | -------------------------------------------------------------------------------- /matlab/ind2sub2.m: -------------------------------------------------------------------------------- 1 | function sub = ind2sub2( siz, ind ) 2 | % Improved version of ind2sub. 3 | % 4 | % Almost the same as ind2sub, except always returns only a single output 5 | % that contains all the index locations. Also handles multiple linear 6 | % indicies at the same time. See help for ind2sub for more info. 7 | % 8 | % USAGE 9 | % sub = ind2sub2( siz, ind ) 10 | % 11 | % INPUTS 12 | % siz - size of array into which ind is an index 13 | % ind - linear index (or vector of indicies) into given array 14 | % 15 | % OUTPUTS 16 | % sub - sub(i,:) is the ith set of subscripts into the array. 17 | % 18 | % EXAMPLE 19 | % sub = ind2sub2( [10,10], 20 ) % 10 2 20 | % sub = ind2sub2( [10,10], [20 19] ) % 10 2; 9 2 21 | % 22 | % See also IND2SUB, SUB2IND2 23 | % 24 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 25 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 26 | % Licensed under the Simplified BSD License [see external/bsd.txt] 27 | 28 | if( any(ind>prod(siz)) ); error('index out of range'); end 29 | 30 | % taken almost directly from ind2sub.m 31 | ind = ind(:); 32 | nd = length(siz); 33 | k = [1 cumprod(siz(1:end-1))]; 34 | ind = ind - 1; 35 | sub = zeros(length(ind),nd); 36 | for i = nd:-1:1 37 | sub(:,i) = floor(ind/k(i))+1; 38 | ind = rem(ind,k(i)); 39 | end 40 | -------------------------------------------------------------------------------- /matlab/int2str2.m: -------------------------------------------------------------------------------- 1 | function nstr = int2str2( n, nDigits ) 2 | % Convert integer to string of given length; improved version of int2str. 3 | % 4 | % Pads string with zeros on the left. For integers similar to 5 | % sprintf( '%03i', n ); %for nDigits=3 6 | % If input n is an array, output is a cell array of strings of the same 7 | % dimension as n. Works also for non integers (pads to given length). 8 | % 9 | % USAGE 10 | % nstr = int2str2( n, [nDigits] ) 11 | % 12 | % INPUTS 13 | % n - integer to convert to string 14 | % nDigits - [0] minimum number of digits to use 15 | % 16 | % OUTPUTS 17 | % nstr - string repr. of n (or cell array of strings if n is array) 18 | % 19 | % EXAMPLE 20 | % s = int2str2( 3, 3 ) % s='003' 21 | % 22 | % See also INT2STR 23 | % 24 | % Piotr's Computer Vision Matlab Toolbox Version 1.5 25 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 26 | % Licensed under the Simplified BSD License [see external/bsd.txt] 27 | 28 | if( nargin<2 ); nDigits=0; end 29 | 30 | nel = numel( n ); 31 | negvals=(n<0); n=abs(n); 32 | if( nel==1 ) % for a single int 33 | nstr = num2str( n ); 34 | if( nDigits > size(nstr,2) ) 35 | nstr = [repmat( '0', 1, nDigits-size(nstr,2) ), nstr]; 36 | end; 37 | if(negvals); nstr=['-' nstr]; end 38 | 39 | else % for array of ints 40 | nstr = cell(size(n)); 41 | for i=1:nel 42 | nstr{i} = num2str( n(i) ); 43 | if( nDigits > size(nstr{i},2) ) 44 | nstr{i} = [repmat( '0', 1, nDigits-size(nstr{i},2) ), nstr{i}]; 45 | end; 46 | if(negvals(i)); nstr{i}=['-' nstr{i}]; end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /matlab/isfield2.m: -------------------------------------------------------------------------------- 1 | function tf = isfield2( S, fs, isinit ) 2 | % Similar to isfield but also test whether fields are initialized. 3 | % 4 | % A more comprehensive test of what fields are present [and optionally 5 | % initialized] in a stuct S. fs is either a single field name or a cell 6 | % array of field names. The presence of all fields in fs are tested for in 7 | % S, tf is true iif all fs are present. Additionally, if isinit==1, then tf 8 | % is true iff every field fs of every element of S is nonempty (test done 9 | % using isempty). 10 | % 11 | % USAGE 12 | % tf = isfield2( S, fs, [isinit] ) 13 | % 14 | % INPUTS 15 | % S - struct array 16 | % fs - cell of string name or string 17 | % isinit - [0] if true additionally test if all fields are initialized 18 | % 19 | % OUTPUTS 20 | % tf - true or false, depending on results of above tests 21 | % 22 | % EXAMPLE 23 | % isfield2( struct('a',1,'b',2), {'a','b'}, 1 ) 24 | % 25 | % See also ISFIELD 26 | % 27 | % Piotr's Computer Vision Matlab Toolbox Version 2.10 28 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 29 | % Licensed under the Simplified BSD License [see external/bsd.txt] 30 | 31 | tf = all( isfield(S,fs) ); 32 | if( ~tf || nargin<3 || ~isinit ); return; end 33 | 34 | % now optionally check if fields are initialized 35 | if( iscell(fs) ) 36 | for i=1:length(fs) 37 | for j=1:numel(S) 38 | if( isempty(S(j).(fs{i})) ); tf=false; return; end; 39 | end; 40 | end; 41 | else 42 | for j=1:numel(S) 43 | if( isempty(S(j).(fs)) ); tf=false; return; end; 44 | end; 45 | end 46 | -------------------------------------------------------------------------------- /matlab/mat2cell2.m: -------------------------------------------------------------------------------- 1 | function C = mat2cell2( X, parts ) 2 | % Break matrix up into a cell array of same sized matrices. 3 | % 4 | % Useful wrapper for matlab function mat2cell. Instead of specifying 5 | % locations along each dimension at which to split the matrix, this 6 | % function takes the number of parts along each dimension to break X into. 7 | % That is if X is d1xd2x...xdk and parts=[p1 p2 ... pk]; then X is split 8 | % into p1*p2*...*pk matricies of dimension d1/p1 x d2/p2 x ... x dk/pk. If 9 | % di/pi is not an integer, floor(di/pi) is used. Leftover chunks of X are 10 | % discarded. Using a scalar p for parts is equivalent to using [p p ... p]. 11 | % 12 | % So for example if X is 10*16, mat2cell2( X, [2 3] ) breaks X into 2*3 13 | % parts, each of size 5x5, and the last column of X is discarded. 14 | % 15 | % USAGE 16 | % C = mat2cell2( X, parts ) 17 | % 18 | % INPUTS 19 | % X - matrix to split 20 | % parts - see above 21 | % 22 | % OUTPUTS 23 | % C - cell array adjacent submatrices of X 24 | % 25 | % EXAMPLE 26 | % A=rand(6,10); B = mat2cell2(A,[3 3]), 27 | % 28 | % See also MAT2CELL, CELL2ARRAY, CELL2MAT 29 | % 30 | % Piotr's Computer Vision Matlab Toolbox Version 3.02 31 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 32 | % Licensed under the Simplified BSD License [see external/bsd.txt] 33 | 34 | siz = size(X); nd = ndims(X); 35 | if(length(parts)>nd && all(parts(nd+1:end)==1)), parts=parts(1:nd); end 36 | [parts,er] = checkNumArgs( parts, size(siz), 0, 2 ); error(er); 37 | 38 | % crop border areas so as to make dims of X divisible by parts 39 | parts = min(siz,parts); siz = siz - mod( siz, parts ); 40 | if (~all( siz==size(X))); X = arrayCrop( X, ones(1,nd), siz ); end 41 | 42 | % Convert to cell array by calling mat2cell 43 | bounds = cell(1,nd); 44 | for d=1:nd; bounds{d} = repmat( siz(d)/parts(d), [1 parts(d)] ); end 45 | C=mat2cell( X, bounds{:}); 46 | -------------------------------------------------------------------------------- /matlab/medianw.m: -------------------------------------------------------------------------------- 1 | function m = medianw( x, w, dim ) 2 | % Fast weighted median. 3 | % 4 | % Computes the weighted median of a set of samples. 5 | % http://en.wikipedia.org/wiki/Weighted_median 6 | % "A weighted median of a sample is the 50% weighted percentile." 7 | % For matrices computes median along each column (or dimension dim). 8 | % If all weights are equal to 1 gives identical results to median. 9 | % 10 | % USAGE 11 | % m = medianw( x, w, [dim] ) 12 | % 13 | % INPUTS 14 | % x - vector or array of samples 15 | % w - vector or array of weights 16 | % dim - dimension along which to compute median 17 | % 18 | % OUTPUTS 19 | % m - weighted median value of x 20 | % 21 | % EXAMPLE - simple toy example 22 | % x=[1 2 3]; w=[1 1 5]; medianw(x,w) 23 | % 24 | % EXAMPLE - comparison to median 25 | % n=randi(100); m=randi(100); 26 | % x=rand(n,m); w=ones(n,m); 27 | % m1=median(x); m2=medianw(x,w); 28 | % assert(isequal(m1,m2)) 29 | % 30 | % See also median 31 | % 32 | % Piotr's Computer Vision Matlab Toolbox Version 3.24 33 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 34 | % Licensed under the Simplified BSD License [see external/bsd.txt] 35 | 36 | if(nargin<3), dim=find(size(x)~=1,1); end 37 | d=dim; nd=ndims(x); n=numel(x); 38 | 39 | if( n==1 || size(x,d)==1 ) 40 | m=x; 41 | elseif( length(x)==n ) 42 | [x,o]=sort(x); w=w(o); w=cumsum(w); 43 | w=w/w(end); [~,j]=min(w<=.5); 44 | if(j==1 || w(j-1)~=.5), m=x(j); 45 | else m=(x(j-1)+x(j))/2; end 46 | else 47 | if(d>1), p=[d 1:d-1 d+1:nd]; x=permute(x,p); w=permute(w,p); end 48 | [x,o]=sort(x); w=w(o); w=cumsum(w); is={':'}; is=is(ones(1,nd-1)); 49 | w=bsxfun(@rdivide,w,w(end,is{:})); [~,j]=min(w<=.5); 50 | s=size(x); s=reshape(((1:n/s(1))-1)*s(1),size(j)); 51 | j0=max(1,j-1); j0=j0+s; j=j+s; 52 | same=w(j0)~=.5; j0(same)=j(same); m=(x(j0)+x(j))/2; 53 | if(d>1), p=[2:d 1 d+1:nd]; m=permute(m,p); end 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /matlab/multiDiv.m: -------------------------------------------------------------------------------- 1 | function C = multiDiv( A, B, type ) 2 | % Matrix divide each submatrix of two 3D arrays without looping. 3 | % 4 | % type controls the matrix multiplication to perform (for each i): 5 | % 1 - C(:,:,i) = A(:,:,i)\B(:,:) 6 | % 2 - C(:,:,i) = A(:,:,i)\B(:,:,i) 7 | % 3 - C(:,i) = A(:,:,i)\B(:,i) 8 | % Corresponding dimensions of A and B must match appropriately. 9 | % Other cases (see multiTimes.m) are not yet implemented. 10 | % 11 | % USAGE 12 | % C = multiDiv( A, B, type ) 13 | % 14 | % INPUTS 15 | % A - [ma x na x oa] matrix 16 | % B - [mb x nb x ob] matrix 17 | % type - division type (see above) 18 | % 19 | % OUTPUTS 20 | % C - result of the division 21 | % 22 | % 23 | % EXAMPLE [case 1] 24 | % n=10000; A=randn(3,3,n); B=eye(3,3); 25 | % tic, C1=multiDiv(A,B,1); toc 26 | % tic, C2=C1; for i=1:n, C2(:,:,i)=A(:,:,i)\B; end; toc 27 | % tic, C3=C1; for i=1:n, C3(:,:,i)=inv(A(:,:,i)); end; toc 28 | % sum(abs(C1(:)-C2(:))), sum(abs(C1(:)-C3(:))) 29 | % 30 | % EXAMPLE [case 2] 31 | % n=10000; A=randn(3,3,n); B=randn(3,10,n); 32 | % tic, C1=multiDiv(A,B,2); toc 33 | % tic, C2=C1; for i=1:n, C2(:,:,i)=A(:,:,i)\B(:,:,i); end; toc 34 | % sum(abs(C1(:)-C2(:))) 35 | % 36 | % EXAMPLE [case 3] 37 | % n=30000; A=randn(2,2,n); B=randn(2,n); 38 | % tic, C1=multiDiv(A,B,3); toc 39 | % tic, C2=C1; for i=1:n, C2(:,i)=A(:,:,i)\B(:,i); end; toc 40 | % sum(abs(C1(:)-C2(:))) 41 | % 42 | % See also MULTITIMES, SPBLKDIAG 43 | % 44 | % Piotr's Computer Vision Matlab Toolbox Version 2.40 45 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 46 | % Licensed under the Simplified BSD License [see external/bsd.txt] 47 | 48 | ma = size(A,1); na = size(A,2); oa = size(A,3); 49 | mb = size(B,1); nb = size(B,2); ob = size(B,3); %#ok 50 | step=max(ceil(100000/ma/na),1); 51 | 52 | switch type 53 | case {1,2} % C(:,:,i) = A(:,:,i)\B(:,:,i) or A(:,:,i)\B(:,:) 54 | C=zeros(na,nb,oa); inds=[]; s=0; 55 | while( s 39 | ps = zeros(N,1); 40 | 41 | else % get probabilities 42 | xs = (xs-m(:)*ones(1,N))'; 43 | denom = (2*pi)^(d/2)*sqrt(abs(det(C))); 44 | mahal = sum( (xs/C).*xs, 2 ); 45 | numer = exp(-0.5*mahal); 46 | ps = numer/denom; 47 | end 48 | -------------------------------------------------------------------------------- /matlab/num2strs.m: -------------------------------------------------------------------------------- 1 | function Y = num2strs( X, varargin ) 2 | % Applies num2str to each element of an array X. 3 | % 4 | % USAGE 5 | % Y = num2strs( X, [varargin] ) 6 | % 7 | % INPUTS 8 | % X - array of number to convert to strings 9 | % varargin - [] additional input to num2str 10 | % 11 | % OUTPUTS 12 | % Y - cell array of strings 13 | % 14 | % EXAMPLE 15 | % Y = num2strs( [1.3 2.6; 3 11] ) 16 | % 17 | % See also NUM2STR 18 | % 19 | % Piotr's Computer Vision Matlab Toolbox Version 1.5 20 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 21 | % Licensed under the Simplified BSD License [see external/bsd.txt] 22 | 23 | Y = cell(size(X)); 24 | for i=1:numel(X) 25 | Y{i} = num2str( X(i), varargin{:} ); 26 | end 27 | -------------------------------------------------------------------------------- /matlab/plotEllipse.m: -------------------------------------------------------------------------------- 1 | function [h,hc,hl] = plotEllipse(cRow,cCol,ra,rb,phi,color,nPnts,lw,ls) 2 | % Adds an ellipse to the current plot. 3 | % 4 | % USAGE 5 | % [h,hc,hl] = plotEllipse(cRow,cCol,ra,rb,phi,[color],[nPnts],[lw],[ls]) 6 | % 7 | % INPUTS 8 | % cRow - the row location of the center of the ellipse 9 | % cCol - the column location of the center of the ellipse 10 | % ra - semi-major axis radius length (in pixels) of the ellipse 11 | % rb - semi-minor axis radius length (in pixels) of the ellipse 12 | % phi - rotation angle (radians) of semimajor axis from x-axis 13 | % color - ['b'] color for ellipse 14 | % nPnts - [100] number of points used to draw each ellipse 15 | % lw - [1] line width 16 | % ls - ['-'] line style 17 | % 18 | % OUTPUT 19 | % h - handle to ellipse 20 | % hc - handle to ellipse center 21 | % hl - handle to ellipse orient 22 | % 23 | % EXAMPLE 24 | % plotEllipse( 3, 2, 1, 5, pi/6, 'g'); 25 | % 26 | % See also plotGaussEllipses 27 | % 28 | % Piotr's Computer Vision Matlab Toolbox Version 2.42 29 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 30 | % Licensed under the Simplified BSD License [see external/bsd.txt] 31 | 32 | narginchk( 5, 9 ); 33 | if(nargin<6 || isempty(color)); color = 'b'; end 34 | if(nargin<7 || isempty(nPnts)); nPnts = 100; end 35 | if(nargin<8 || isempty(nPnts)); lw = 1; end 36 | if(nargin<9 || isempty(ls)); ls = '-'; end 37 | 38 | % plot ellipse (rotate a scaled circle): 39 | ts = linspace(-pi,pi,nPnts+1); cts = cos(ts); sts = sin(ts); 40 | h = plot( ra*cts*cos(-phi) + rb*sts*sin(-phi) + cCol, ... 41 | rb*sts*cos(-phi) - ra*cts*sin(-phi) + cRow ); 42 | 43 | % plot center point and line indicating orientation 44 | washeld = ishold; if(~washeld); hold('on'); end 45 | hc = plot( cCol, cRow, 'k+' ); 46 | hl = plot( [cCol cCol+cos(-phi)*ra], [cRow cRow-sin(-phi)*ra] ); 47 | set([h hc hl],'Color',color,'LineWidth',lw,'LineStyle',ls); 48 | if(~washeld); hold('off'); end; 49 | 50 | end 51 | -------------------------------------------------------------------------------- /matlab/plotGaussEllipses.m: -------------------------------------------------------------------------------- 1 | function hs = plotGaussEllipses( mus, Cs, rad ) 2 | % Plots 2D ellipses derived from 2D Gaussians specified by mus & Cs. 3 | % 4 | % USAGE 5 | % hs = plotGaussEllipses( mus, Cs, [rad] ) 6 | % 7 | % INPUTS 8 | % mus - k x 2 matrix of means 9 | % Cs - 2 x 2 x k covariance matricies 10 | % rad - [2] Number of std to create the ellipse to 11 | % 12 | % OUTPUTS 13 | % hs - handles to ellipses 14 | % 15 | % EXAMPLE 16 | % plotGaussEllipses( [ 10 10; 10 10 ], cat(3,eye(2),eye(2)*2) ); 17 | % 18 | % See also PLOTELLIPSE, GAUSS2ELLIPSE 19 | % 20 | % Piotr's Computer Vision Matlab Toolbox Version 2.0 21 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 22 | % Licensed under the Simplified BSD License [see external/bsd.txt] 23 | 24 | if (nargin<3 || isempty(rad) ); rad=2; end 25 | colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k']; nc = length(colors); 26 | 27 | washeld = ishold; if (~washeld); hold('on'); end 28 | hs = zeros( size(mus,1),1 ); 29 | for i=1:size( mus,1) 30 | [ cRow, ccol, ra, rb, phi ] = gauss2ellipse( mus(i,:), Cs(:,:,i), rad ); 31 | hs(i)=plotEllipse( cRow, ccol, ra, rb, phi, colors( mod(i-1,nc)+1) ); 32 | end 33 | if (~washeld); hold('off'); end 34 | -------------------------------------------------------------------------------- /models/forest/modelBsds.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/models/forest/modelBsds.mat -------------------------------------------------------------------------------- /results_OPE/DTB70/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/DTB70/error.png -------------------------------------------------------------------------------- /results_OPE/DTB70/overlap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/DTB70/overlap.png -------------------------------------------------------------------------------- /results_OPE/UAV123_10fps/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/UAV123_10fps/error.png -------------------------------------------------------------------------------- /results_OPE/UAV123_10fps/overlap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/UAV123_10fps/overlap.png -------------------------------------------------------------------------------- /results_OPE/UAV20L/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/UAV20L/error.png -------------------------------------------------------------------------------- /results_OPE/UAVDT/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/UAVDT/error.png -------------------------------------------------------------------------------- /results_OPE/UAVDT/overlap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/results_OPE/UAVDT/overlap.png -------------------------------------------------------------------------------- /run_JSAR.m: -------------------------------------------------------------------------------- 1 | function results = run_JSAR(seq) 2 | 3 | addpath(genpath('ArvTrack_lib/')); 4 | % HOG feature parameters 5 | hog_params.nDim = 31; 6 | params.video_path = seq.video_path; 7 | % Grayscale feature parameters 8 | grayscale_params.colorspace='gray'; 9 | grayscale_params.nDim = 1; 10 | 11 | cn_params.tablename = 'CNnorm'; 12 | cn_params.useForGray = false; 13 | cn_params.cell_size = 4; 14 | cn_params.nDim = 10; 15 | 16 | % Global feature parameters 17 | params.t_features = { 18 | struct('getFeature',@get_colorspace, 'fparams',grayscale_params),... 19 | struct('getFeature',@get_fhog,'fparams',hog_params),... 20 | struct('getFeature',@get_table_feature, 'fparams',cn_params),... 21 | }; 22 | params.t_global.cell_size = 4; % Feature cell size 23 | 24 | % Search region + extended background parameters 25 | params.search_area_shape = 'square'; % the shape of the training/detection window: 'proportional', 'square' or 'fix_padding' 26 | params.search_area_scale = 5; % the size of the training/detection area proportional to the target size 27 | params.filter_max_area = 50^2; % the size of the training/detection area in feature grid cells 28 | 29 | % Learning parameters 30 | params.output_sigma_factor =1/20; % standard deviation of the desired correlation output (proportional to target) 31 | % Detection parameters 32 | params.newton_iterations = 5; % number of Newton's iteration to maximize the detection scores 33 | 34 | % Scale parameters 35 | params.num_sv =13; 36 | params.num_arc=13; 37 | params.learning_rate_size=0.014; 38 | params.sv_sigma_factor =1.5; 39 | params.arc_sigma_factor=1.5; 40 | params.size_model_factor = 1; 41 | params.sv_step=1.03; 42 | params.arc_step=1.02^2; 43 | params.size_lambda = 0.01; 44 | params.size_model_max_area = 32*16; 45 | params.hog_box_cell_size = 4; 46 | params.min_image_sample_size = 200^2; % Minimum area of image samples 47 | params.max_image_sample_size = 200^2; % Maximum area of image samples 48 | params.init_mu=16; 49 | % size, position, frames initialization 50 | params.wsize = [seq.init_rect(1,4), seq.init_rect(1,3)]; 51 | params.init_pos = [seq.init_rect(1,2), seq.init_rect(1,1)] + floor(params.wsize/2); 52 | params.s_frames = seq.s_frames; 53 | params.no_fram = seq.en_frame - seq.st_frame + 1; 54 | params.seq_st_frame = seq.st_frame; 55 | params.seq_en_frame = seq.en_frame; 56 | 57 | % ADMM parameters, # of iteration, and lambda- mu and betha are set in 58 | % the main function. 59 | params.admm_iterations = 4; 60 | params.admm_lambda =1e-2; 61 | params.reg_window_max=1e5; 62 | params.reg_window_min=1e-3; 63 | % Debug and visualization 64 | params.visualization = 1; 65 | % Run the main function 66 | results = tracking_JSAR(params); 67 | -------------------------------------------------------------------------------- /run_JSAR_Re.m: -------------------------------------------------------------------------------- 1 | 2 | function results = run_JSAR_Re(seq) 3 | 4 | % Initialize path 5 | addpath(genpath('ArvTrack_Re_lib/')); 6 | addpath(genpath('EdgeBox/')); 7 | addpath(genpath('models/')); 8 | addpath(genpath('channels/')); 9 | addpath(genpath('detector/')); 10 | addpath(genpath('images/')); 11 | addpath(genpath('matlab/')); 12 | addpath(genpath('videos/')); 13 | % HOG feature parameters 14 | hog_params.cell_size = 4; 15 | hog_params.nDim = 31; 16 | % ColorName feature parameters 17 | cn_params.nDim =10; 18 | cn_params.tablename = 'CNnorm'; 19 | cn_params.useForGray = false; 20 | cn_params.cell_size = 4; 21 | % Grayscale feature parameters 22 | grayscale_params.nDim=1; 23 | grayscale_params.colorspace='gray'; 24 | grayscale_params.cell_size = 4; 25 | 26 | % Global feature parameters 27 | params.t_features = { 28 | struct('getFeature',@get_colorspace, 'fparams',grayscale_params),... 29 | struct('getFeature',@get_fhog,'fparams',hog_params),... 30 | struct('getFeature',@get_table_feature, 'fparams',cn_params),... 31 | }; 32 | % Global feature parameters 33 | params.t_global.cell_size = 4; % Feature cell size 34 | 35 | % Search region + extended background parameters 36 | params.search_area_shape = 'square'; % the shape of the training/detection window: 'proportional', 'square' or 'fix_padding' 37 | params.search_area_scale =5; % the size of the training/detection area proportional to the target size 38 | params.min_image_sample_size = 200^2; % Minimum area of image samples 39 | params.max_image_sample_size = 200^2; % Maximum area of image samples 40 | % Gaussian response parameter 41 | params.output_sigma_factor =0.054; % standard deviation of the desired correlation output (proportional to target) 42 | % Detection parameters 43 | params.newton_iterations= 5; % number of Newton's iteration to maximize the detection scores 44 | % Set files and gt 45 | params.name=seq.name; 46 | params.video_path = seq.video_path; 47 | params.img_files = seq.s_frames; 48 | params.wsize = [seq.init_rect(1,4), seq.init_rect(1,3)]; 49 | params.init_pos = [seq.init_rect(1,2), seq.init_rect(1,1)] + floor(params.wsize/2); 50 | params.s_frames = seq.s_frames; 51 | params.no_fram = seq.en_frame - seq.st_frame + 1; 52 | params.seq_st_frame = seq.st_frame; 53 | params.seq_en_frame = seq.en_frame; 54 | params.ground_truth=seq.init_rect; 55 | 56 | % ADMM parameters, # of iteration, and lambda- mu and betha are set in 57 | % the main function. 58 | params.admm_iterations = 4; 59 | params.admm_lambda =1; 60 | 61 | params.init_mu=16; 62 | params.init_rmu=16; 63 | params.reg_window_max=1e5; 64 | params.reg_window_min=1e-3; 65 | 66 | % Scale parameters 67 | params.num_sv =13; 68 | params.num_arc=13; 69 | params.learning_rate_size=0.014; 70 | params.sv_sigma_factor =1.5; 71 | params.arc_sigma_factor=1.7; 72 | params.size_model_factor = 1; 73 | params.sv_step=1.03; 74 | params.arc_step=1.02^2; 75 | params.size_lambda = 0.01; 76 | params.size_model_max_area = 32*16; 77 | params.hog_scale_cell_size = 4; 78 | % Debug and visualization 79 | params.visualization =1; 80 | 81 | % Run the main function 82 | results = tracking_JSAR_Re(params); 83 | -------------------------------------------------------------------------------- /videos/Contents.m: -------------------------------------------------------------------------------- 1 | % VIDEOS 2 | % See also 3 | % 4 | % Behavior annotation for seq files: 5 | % behaviorAnnotator - Caltech Behavior Annotator. 6 | % behaviorData - Retrieve and manipulate behavior annotation of a video. 7 | % 8 | % Seq files [custom codec free video format]: 9 | % seqIo - Utilities for reading and writing seq files. 10 | % seqReaderPlugin - Plugin for seqIo and videoIO to allow reading of seq files. 11 | % seqWriterPlugin - Plugin for seqIo and videoIO to allow writing of seq files. 12 | % seqPlayer - Simple GUI to play seq files. 13 | % 14 | % Image and sequence alignment: 15 | % imagesAlign - Fast and robust estimation of homography relating two images. 16 | % imagesAlignSeq - Stabilize image sequence using coarse optical flow estimation. 17 | % 18 | % Miscellaneous: 19 | % kernelTracker - Kernel Tracker from Comaniciu, Ramesh and Meer PAMI 2003. 20 | % opticalFlow - Coarse-to-fine optical flow using Lucas&Kanade or Horn&Schunck. 21 | -------------------------------------------------------------------------------- /videos/imagesAlignSeq.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/imagesAlignSeq.m -------------------------------------------------------------------------------- /videos/opticalFlowTest.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/opticalFlowTest.mat -------------------------------------------------------------------------------- /videos/peds30-seek.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/peds30-seek.mat -------------------------------------------------------------------------------- /videos/peds30.seq: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/peds30.seq -------------------------------------------------------------------------------- /videos/private/ktComputeW_c.c: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * Piotr's Computer Vision Matlab Toolbox Version 2.2 3 | * Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 4 | * Licensed under the Simplified BSD License [see external/bsd.txt] 5 | **************************************************************************/ 6 | #include "mex.h" 7 | #include "math.h" 8 | typedef unsigned char uchar; 9 | 10 | /* Construct W for kernel tracker. */ 11 | void ktComputeW( double* w, uchar* B, double* q, double *p, int n, int nBits ) { 12 | int i, indFlat, nBits2=nBits+nBits, nBins=1<0 ) ? sqrt(q[i]/p[i]) : 0.0; 17 | for( i=0; i 1) mexErrMsgTxt("Too many output arguments."); 32 | 33 | /* extract inputs */ 34 | n = mxGetM( prhs[0] ); 35 | B = (uchar*) mxGetData(prhs[0]); 36 | q = mxGetPr(prhs[1]); 37 | p = mxGetPr(prhs[2]); 38 | nBits = (int) mxGetScalar(prhs[3]); 39 | 40 | /* create outputs */ 41 | dims[0]=n; dims[1]=1; 42 | plhs[0] = mxCreateNumericArray(1, dims, mxDOUBLE_CLASS, mxREAL); 43 | w = mxGetPr( plhs[0] ); 44 | 45 | /* call main function */ 46 | ktComputeW( w, B, q, p, n, nBits ); 47 | } 48 | -------------------------------------------------------------------------------- /videos/private/ktComputeW_c.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/private/ktComputeW_c.mexa64 -------------------------------------------------------------------------------- /videos/private/ktComputeW_c.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/private/ktComputeW_c.mexmaci64 -------------------------------------------------------------------------------- /videos/private/ktComputeW_c.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vision4robotics/JSAR-Tracker/50d6873f7f60ee192b912d68d01f1350742192a1/videos/private/ktComputeW_c.mexw64 -------------------------------------------------------------------------------- /videos/private/ktHistcRgb_c.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Piotr's Computer Vision Matlab Toolbox Version 2.2 3 | * Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] 4 | * Licensed under the Simplified BSD License [see external/bsd.txt] 5 | *******************************************************************************/ 6 | #include "mex.h" 7 | typedef unsigned char uchar; 8 | 9 | /******************************************************************************* 10 | * Construct 3-D RGB histogram of colors in B [n x 3]. 11 | * Efficient implementation possible for the following reasons: 12 | * 1) We know that histogram is 3 dimensional. 13 | * 2) All values in B are between [0,2^nBits) 14 | * 3) Bins are restricted to powers of 2 (nBins=2^nBits) 15 | * Finding the bin index is simply a matter of dividing/multiplying by 16 | * powers of 2, which can be done efficiently with the left and right shift 17 | * operators. See also histc2c.c in toolbox for more general histogramming 18 | * implementation. This is about 5x faster. Note: nBins = 2^nBits = 1< 1) mexErrMsgTxt("Too many output arguments."); 34 | 35 | /* extract inputs */ 36 | n = mxGetM( prhs[0] ); 37 | B = (uchar*) mxGetData(prhs[0]); 38 | wtMask = mxGetPr(prhs[1]); 39 | nBits = (int) mxGetScalar(prhs[2]); 40 | 41 | /* create outputs-- nBins = 2^nBits */ 42 | dims[0]=dims[1]=dims[2]=1<