singleFrameDSKCF

PURPOSE ^

SINGLEFRAMEDSKCF.m is the core function of DS-KCF tracker

SYNOPSIS ^

function [pos,trackerDSKCF_struct,trackerDSKCF_structOccluder,scaleDSKCF_struct,DSKCFparameters_Occluder,segmentedMASK,shapeDSKCF_struct,timeMatrixRow]=singleFrameDSKCF(firstFrame,pos,frameCurr,trackerDSKCF_struct,DSKCFparameters,scaleDSKCF_struct,trackerDSKCF_structOccluder,DSKCFparameters_Occluder,shapeDSKCF_struct)

DESCRIPTION ^

 SINGLEFRAMEDSKCF.m is the core function of DS-KCF tracker


   SINGLEFRAMEDSKCF is the core function of DS-KCF tracker (for more
   details see [1]). It applies the DS-KCF tracker to a single frame of
   the sequence. This function is based on several data structures where
   input and output data is stored.Please note that data structures are
   supposed to be initialized as in wrapperDSKCF and runDSKCF.m test
   script.

   INPUT:
   - firstFrame   boolean flag that marks the first frame of the
   sequence
   - frameCurr    first frame data structure (see WRAPPERDSKCF)
   - trackerDSKCF_struct  DS-KCF tracker data structure (see WRAPPERDSKCF,
   INITDSKCFTRACKER)
   - DSKCFparameters, DSKCFparameters_Occluder    parameters structures
   (see WRAPPERDSKCF)
   - scaleDSKCF_struct    scale data structure (see
   wrapperDSKCF,INITDSKCFPARAM)
   -trackerDSKCF_structOccluder DS-KCF tracker data structure for the
   occluder
   -pos previous position of the DS-KCF tracker pos=[y x] where x is the
   column and y is the row index
   -shapeDSKCF_struct data structure containing shape information and
   segmentation masks

   OUTPUT
   -pos updated position of the DS-KCF tracker pos=[y x] where x is the
   column and y is the row index
   -trackerDSKCF_struct,trackerDSKCF_structOccluder updated data
   structures for the trackers
   -scaleDSKCF_struct updated scale data structure
   -DSKCFparameters_Occluder updated parameter structure for the occluder
   -timeMatrixRow Vecotr containing the processing rate for all the main
   modules of the ds-kcf (see [1] for more details)

  See also wrapperDSKCF, CHECKOCCLUSIONSDSKCF_NOISEMODEL,
  CHECKOCCLUSIONSDSKCF_SECONDPLANE, ENLARGEBB, OCCLUDINGOBJECTSEGDSKCF,
  TARGETSEARCHDSKCF, GETSCALEFACTORSTRUCT, FROMBBTOCENTRALPOINT,
  FROMCENTRALPOINTTOBB, GAUSSIAN_SHAPED_LABELS, GET_SUBWINDOW,
  MAXRESPONSEDEPTHWEIGHTDSKCF, MODELUPDATEDSKCF, RESETDSKCFTRACKERINFO,
  ROIFROMBB,SINGLEFRAMEDSKCF_OCCLUDER,INITDSKCFSHAPE,EXTRACTSEGMENTEDPATCHV3,
  REGIONMODIFICATIONCHECK,GETSHAPEFACTORSTRUCTDIRECTIONSV2

  [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T.
  Burghardt, A. Paiement, L. Tao, DS-KCF: A real-time tracker for RGB-D
  data, Journal of Real-Time Image Processing


  University of Bristol
  Massimo Camplani and Sion Hannuna

  massimo.camplani@bristol.ac.uk
  hannuna@compsci.bristol.ac.uk

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [pos,trackerDSKCF_struct,trackerDSKCF_structOccluder,scaleDSKCF_struct,...
0002     DSKCFparameters_Occluder,segmentedMASK,shapeDSKCF_struct,timeMatrixRow]=singleFrameDSKCF(firstFrame,pos,frameCurr,...
0003     trackerDSKCF_struct,DSKCFparameters,scaleDSKCF_struct,...
0004     trackerDSKCF_structOccluder,DSKCFparameters_Occluder,shapeDSKCF_struct)
0005 % SINGLEFRAMEDSKCF.m is the core function of DS-KCF tracker
0006 %
0007 %
0008 %   SINGLEFRAMEDSKCF is the core function of DS-KCF tracker (for more
0009 %   details see [1]). It applies the DS-KCF tracker to a single frame of
0010 %   the sequence. This function is based on several data structures where
0011 %   input and output data is stored.Please note that data structures are
0012 %   supposed to be initialized as in wrapperDSKCF and runDSKCF.m test
0013 %   script.
0014 %
0015 %   INPUT:
0016 %   - firstFrame   boolean flag that marks the first frame of the
0017 %   sequence
0018 %   - frameCurr    first frame data structure (see WRAPPERDSKCF)
0019 %   - trackerDSKCF_struct  DS-KCF tracker data structure (see WRAPPERDSKCF,
0020 %   INITDSKCFTRACKER)
0021 %   - DSKCFparameters, DSKCFparameters_Occluder    parameters structures
0022 %   (see WRAPPERDSKCF)
0023 %   - scaleDSKCF_struct    scale data structure (see
0024 %   wrapperDSKCF,INITDSKCFPARAM)
0025 %   -trackerDSKCF_structOccluder DS-KCF tracker data structure for the
0026 %   occluder
0027 %   -pos previous position of the DS-KCF tracker pos=[y x] where x is the
0028 %   column and y is the row index
0029 %   -shapeDSKCF_struct data structure containing shape information and
0030 %   segmentation masks
0031 %
0032 %   OUTPUT
0033 %   -pos updated position of the DS-KCF tracker pos=[y x] where x is the
0034 %   column and y is the row index
0035 %   -trackerDSKCF_struct,trackerDSKCF_structOccluder updated data
0036 %   structures for the trackers
0037 %   -scaleDSKCF_struct updated scale data structure
0038 %   -DSKCFparameters_Occluder updated parameter structure for the occluder
0039 %   -timeMatrixRow Vecotr containing the processing rate for all the main
0040 %   modules of the ds-kcf (see [1] for more details)
0041 %
0042 %  See also wrapperDSKCF, CHECKOCCLUSIONSDSKCF_NOISEMODEL,
0043 %  CHECKOCCLUSIONSDSKCF_SECONDPLANE, ENLARGEBB, OCCLUDINGOBJECTSEGDSKCF,
0044 %  TARGETSEARCHDSKCF, GETSCALEFACTORSTRUCT, FROMBBTOCENTRALPOINT,
0045 %  FROMCENTRALPOINTTOBB, GAUSSIAN_SHAPED_LABELS, GET_SUBWINDOW,
0046 %  MAXRESPONSEDEPTHWEIGHTDSKCF, MODELUPDATEDSKCF, RESETDSKCFTRACKERINFO,
0047 %  ROIFROMBB,SINGLEFRAMEDSKCF_OCCLUDER,INITDSKCFSHAPE,EXTRACTSEGMENTEDPATCHV3,
0048 %  REGIONMODIFICATIONCHECK,GETSHAPEFACTORSTRUCTDIRECTIONSV2
0049 %
0050 %  [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T.
0051 %  Burghardt, A. Paiement, L. Tao, DS-KCF: A real-time tracker for RGB-D
0052 %  data, Journal of Real-Time Image Processing
0053 %
0054 %
0055 %  University of Bristol
0056 %  Massimo Camplani and Sion Hannuna
0057 %
0058 %  massimo.camplani@bristol.ac.uk
0059 %  hannuna@compsci.bristol.ac.uk
0060 
0061 im=frameCurr.gray;
0062 imRGB=frameCurr.rgb;
0063 depth=frameCurr.depth;
0064 noData=frameCurr.depthNoData;
0065 depth16Bit=frameCurr.depth16Bit;
0066 
0067 %hard coded threshold for DS-KCF algorithm see [1] for more details
0068 confInterval1=0.4;
0069 confInterval2=0.15;
0070 confValue3=0.14;
0071 
0072 currentScale=scaleDSKCF_struct.i;
0073 
0074 %clean target struct.....
0075 trackerDSKCF_struct=resetDSKCFtrackerInfo(trackerDSKCF_struct);
0076 changeOfShapeFlag=false;
0077 segmentedMASK=repmat(0,size(depth));
0078 numberTimeIntervals=7;
0079 timeMatrixRow=repmat(-1,1,numberTimeIntervals);
0080 
0081 %This is not the first frame we can start tracking!!!!!!!!!!
0082 if(firstFrame==false)
0083     
0084     %no occlusion case
0085     if ~trackerDSKCF_struct.previousTarget.underOcclusion,
0086         
0087         timeMaxResponse=tic();
0088         ticINDEX=1;
0089         
0090         %track the object and then check for occlusions
0091         patch = get_subwindow(im, pos, scaleDSKCF_struct.windows_sizes(currentScale).window_sz);
0092         patch_depth = get_subwindow(depth, pos, scaleDSKCF_struct.windows_sizes(currentScale).window_sz);
0093         
0094         %calculate response of the DS-KCF tracker
0095         [response, maxResponse,pos]=maxResponseDepthWeightDSKCF(...
0096             patch,patch_depth,depth16Bit, DSKCFparameters.features,DSKCFparameters.kernel,...
0097             pos,DSKCFparameters.cell_size, scaleDSKCF_struct.cos_windows(currentScale).cos_window,...
0098             trackerDSKCF_struct.model_xf,trackerDSKCF_struct.model_alphaf,...
0099             trackerDSKCF_struct.model_xDf,trackerDSKCF_struct.model_alphaDf,...
0100             trackerDSKCF_struct.previousTarget.meanDepthObj,...
0101             trackerDSKCF_struct.previousTarget.stdDepthObj);
0102         
0103         %update tracker struct, new position etc
0104         trackerDSKCF_struct.currentTarget.posX=pos(2);
0105         trackerDSKCF_struct.currentTarget.posY=pos(1);
0106         
0107         trackerDSKCF_struct.currentTarget.bb=fromCentralPointToBB...
0108             (trackerDSKCF_struct.currentTarget.posX,trackerDSKCF_struct.currentTarget.posY,...
0109             trackerDSKCF_struct.currentTarget.w,trackerDSKCF_struct.currentTarget.h,...
0110             size(im,2),size(im,1));
0111         
0112         trackerDSKCF_struct.currentTarget.conf=max(response(:));%use this one, discard the weight...
0113         timeMatrixRow(ticINDEX)=toc(timeMaxResponse);
0114         
0115         timeSegmentAndCheck=tic();
0116         ticINDEX=2;
0117         
0118         %segment the depth data inside the tracked region
0119         [p, trackerDSKCF_struct.currentTarget.meanDepthObj,...
0120             trackerDSKCF_struct.currentTarget.stdDepthObj,estimatedDepth,...
0121             estimatedSTD,minIndexReduced,trackerDSKCF_struct.currentTarget.LabelRegions,...
0122             trackerDSKCF_struct.currentTarget.Centers,trackerDSKCF_struct.currentTarget.regionIndex,...
0123             trackerDSKCF_struct.currentTarget.LUT,regionIndexOBJ] = checkOcclusionsDSKCF_noiseModel(...
0124             depth16Bit,noData,trackerDSKCF_struct, trackerDSKCF_struct.currentTarget.bb);
0125         
0126         %if the segmented target is in the front plane use current bounding
0127         %box....or use the one provided by the depth based segmentation as
0128         %in [1]
0129         if(regionIndexOBJ==0 )
0130             trackerDSKCF_struct.currentTarget.segmentedBB=...
0131                 trackerDSKCF_struct.currentTarget.bb';
0132         else
0133             tmpProp=regionprops(trackerDSKCF_struct.currentTarget.LabelRegions...
0134                 ==regionIndexOBJ,'BoundingBox');
0135             tmpBB=tmpProp.BoundingBox;
0136             %tmpCentroid=tmpProp.Centroid;
0137             trackerDSKCF_struct.currentTarget.segmentedBB=ceil([tmpBB(1), ....
0138                 tmpBB(2),tmpBB(1)+tmpBB(3),tmpBB(2)+tmpBB(4)]);
0139             tmpOffset=enlargeBB(trackerDSKCF_struct.currentTarget.bb ,0.05,size(depth16Bit));
0140             trackerDSKCF_struct.currentTarget.segmentedBB([1,3])=...
0141                 +trackerDSKCF_struct.currentTarget.segmentedBB([1,3])...
0142                 +tmpOffset(1);
0143             trackerDSKCF_struct.currentTarget.segmentedBB([2,4])=...
0144                 +trackerDSKCF_struct.currentTarget.segmentedBB([2,4])...
0145                 +tmpOffset(2);
0146             tmpBBforSeg=enlargeBB(trackerDSKCF_struct.currentTarget.bb ,0.05,size(depth16Bit));
0147             %generate a out of bound rect is necessary
0148             outOfBoundBB=enlargeBB(trackerDSKCF_struct.currentTarget.bb ,0.05,5*size(depth16Bit));
0149             outOfBoundSize=[outOfBoundBB(4)-outOfBoundBB(2)+1,outOfBoundBB(3)-outOfBoundBB(1)+1];
0150             
0151             [tmpMask,insidePatchIndexes,finalMask]=extractSegmentedPatchV3(trackerDSKCF_struct.currentTarget.LabelRegions==regionIndexOBJ,...
0152                 outOfBoundSize,[trackerDSKCF_struct.currentTarget.posX,trackerDSKCF_struct.currentTarget.posY],...
0153                 shapeDSKCF_struct,[size(depth16Bit,2),size(depth16Bit,1)]);
0154             
0155             if(shapeDSKCF_struct.growingStatus==false)
0156                 shapeDSKCF_struct=addSegmentationResults(shapeDSKCF_struct,tmpMask,tmpBBforSeg,tmpOffset,size(depth16Bit));
0157             else
0158                 %in case region is growing....then resegment....
0159                 %segment the depth data inside the tracked region
0160                 %take the new bb
0161                 newSegmentBB=fromCentralPointToBB(trackerDSKCF_struct.currentTarget.posX,...
0162                     trackerDSKCF_struct.currentTarget.posY,shapeDSKCF_struct.segmentW,...
0163                     shapeDSKCF_struct.segmentH,size(im,2),size(im,1));
0164                 
0165                 [pNEW, newMean,newSTD,newEstimatedDepth,newEstimatedSTD,newMinIndexReduced,...
0166                     newLabelRegions,newCenters,newRegionIndex,newLUT,newRegionIndexOBJ] = ...
0167                     checkOcclusionsDSKCF_noiseModel(...
0168                     depth16Bit,noData,trackerDSKCF_struct, newSegmentBB);
0169                 
0170                 [depthDistance,depthIndex]=min(abs(newCenters-trackerDSKCF_struct.currentTarget.meanDepthObj));
0171                 
0172                 newLabelData=newLabelRegions==depthIndex;
0173                 
0174                 tmpProp=regionprops(newLabelData,'BoundingBox');
0175                 if(isempty(tmpProp)==true)
0176                     tmpBB=trackerDSKCF_struct.currentTarget.segmentedBB;
0177                     newLabelData=zeros(size(shapeDSKCF_struct.cumulativeMask));
0178                 else
0179                     tmpBB=tmpProp.BoundingBox;
0180                     %end
0181                     
0182                     %tmpCentroid=tmpProp.Centroid;
0183                     trackerDSKCF_struct.currentTarget.segmentedBB=ceil([tmpBB(1), ....
0184                         tmpBB(2),tmpBB(1)+tmpBB(3),tmpBB(2)+tmpBB(4)]);
0185                     
0186                     tmpOffset=enlargeBB(newSegmentBB ,0.05,size(depth16Bit));
0187                     
0188                     trackerDSKCF_struct.currentTarget.segmentedBB([1,3])=...
0189                         +trackerDSKCF_struct.currentTarget.segmentedBB([1,3])...
0190                         +tmpOffset(1);
0191                     
0192                     trackerDSKCF_struct.currentTarget.segmentedBB([2,4])=...
0193                         +trackerDSKCF_struct.currentTarget.segmentedBB([2,4])...
0194                         +tmpOffset(2);
0195                 end
0196                 
0197                 tmpBBforSeg=enlargeBB(newSegmentBB ,0.05,size(depth16Bit));
0198                 outOfBoundBB=enlargeBB(newSegmentBB,0.05,5*size(depth16Bit));%generate a out of bound rect is necessary
0199                 outOfBoundSize=[outOfBoundBB(4)-outOfBoundBB(2)+1,outOfBoundBB(3)-outOfBoundBB(1)+1];
0200                 
0201                 [tmpMask,insidePatchIndexes,finalMask]=extractSegmentedPatchV3(newLabelData,...
0202                     outOfBoundSize,[trackerDSKCF_struct.currentTarget.posX,trackerDSKCF_struct.currentTarget.posY],...
0203                     shapeDSKCF_struct,[size(depth16Bit,2),size(depth16Bit,1)]);
0204                 
0205                
0206                 shapeDSKCF_struct=addSegmentationResults(shapeDSKCF_struct,tmpMask,tmpBBforSeg,tmpOffset,size(depth16Bit));
0207             end
0208             
0209             %CUMULATIVE SEGMENTATION...
0210             tmpBBforSegCumulative=shapeDSKCF_struct.cumulativeBB;
0211             
0212             sizeOfSegmenter=(tmpBBforSegCumulative(3)-tmpBBforSegCumulative(1))...
0213                 *(tmpBBforSegCumulative(4)-tmpBBforSegCumulative(2));
0214             
0215             sizeOfTarget=(trackerDSKCF_struct.currentTarget.bb(3)-...
0216                 trackerDSKCF_struct.currentTarget.bb(1))*(trackerDSKCF_struct.currentTarget.bb(4)...
0217                 -trackerDSKCF_struct.currentTarget.bb(2));
0218             %%sizeOfSegmenter=
0219             accumulatedSEGBool=size(shapeDSKCF_struct.maskArray,3)==(shapeDSKCF_struct.slidingWindowSize);
0220             sr = scaleDSKCF_struct.InitialDepth / scaleDSKCF_struct.currDepth;
0221             targ_sz = round(scaleDSKCF_struct.InitialTargetSize * sr);
0222             %invert the coordinate as you need to combine this with positions
0223             srSize= targ_sz([2,1]);
0224             currentScaleBB=[pos(:,[2,1]) - srSize/2, pos(:,[2,1]) + srSize/2];
0225             
0226             trackerDSKCF_struct.currentTarget.segmentedBB=currentScaleBB;
0227             
0228             %No data percentage
0229             depthNoData=roiFromBB(noData,trackerDSKCF_struct.currentTarget.bb);
0230             noDataPercent=sum(sum(depthNoData))<0.4*sizeOfTarget;
0231             
0232             %minimunSize check
0233             minSizeOK=(sizeOfSegmenter>39*39);
0234             if(minSizeOK==0)
0235                 
0236                 minSizeOK= (tmpBBforSegCumulative(3)-tmpBBforSegCumulative(1)>39)...
0237                     ||(tmpBBforSegCumulative(4)-tmpBBforSegCumulative(2)>39);
0238             end
0239             [tmpBBforSegCumulative,shapeDSKCF_struct,changeOfShapeFlag,newOutput]=...
0240                 regionModificationCheck(sizeOfSegmenter,sizeOfTarget,...
0241                 accumulatedSEGBool,noDataPercent,minSizeOK,tmpBBforSegCumulative,...
0242                 shapeDSKCF_struct,size(depth16Bit),trackerDSKCF_struct);
0243             %if it is not changed the target bb is used
0244             if(newOutput)
0245                 trackerDSKCF_struct.currentTarget.segmentedBB=tmpBBforSegCumulative(:)';
0246             end
0247             
0248         end
0249         %occlusion condition
0250         trackerDSKCF_struct.currentTarget.underOcclusion = abs(p)>0.35 && trackerDSKCF_struct.currentTarget.conf<confInterval1;
0251         
0252         if ~trackerDSKCF_struct.currentTarget.underOcclusion
0253             %eventually correct the frameCurr.targetDepthFast
0254             if(trackerDSKCF_struct.currentTarget.meanDepthObj~=estimatedDepth && minIndexReduced==1)
0255                 trackerDSKCF_struct.currentTarget.meanDepthObj=estimatedDepth;
0256                 trackerDSKCF_struct.currentTarget.stdDepthObj=estimatedSTD;
0257             end
0258         end
0259         
0260         timeMatrixRow(ticINDEX)=toc(timeSegmentAndCheck);
0261         
0262         timeStartNewTracker=tic();
0263         ticINDEX=3;
0264         
0265         %IF UNDER OCCLUSION START TO SEGMENT OCCLUDER AND OCCLUDED
0266         %OBJECTS
0267         if trackerDSKCF_struct.currentTarget.underOcclusion,
0268             % initialize occlusion
0269             [tmpOccBB] = occludingObjectSegDSKCF(depth16Bit,trackerDSKCF_struct);
0270             
0271             if (isempty(tmpOccBB) | isnan(tmpOccBB) )
0272                 trackerDSKCF_struct.currentTarget.underOcclusion = 0;
0273             else
0274                 if trackerDSKCF_struct.currentTarget.conf <0.15,
0275                     trackerDSKCF_struct.currentTarget.bb = [];
0276                 end
0277                 trackerDSKCF_struct.currentTarget.occBB = tmpOccBB;
0278             end
0279             
0280             %occlusion detected......is time to fill the struct
0281             %for the occluder we not use any change of scale or other
0282             %occlusion detector!!!! so now you have to re-init it,
0283             %according to the new patch size etc etc
0284             
0285             if (isempty(tmpOccBB)==false)
0286                 
0287                 %delete cumulative Mask
0288                 shapeDSKCF_struct=initDSKCFshape(5,0);
0289                 %assign the occluding bb to the occluder data struct
0290                 trackerDSKCF_structOccluder.previousTarget.bb=...
0291                     tmpOccBB;
0292                 
0293                 [trackerDSKCF_structOccluder.previousTarget.posX,...
0294                     trackerDSKCF_structOccluder.previousTarget.posY...
0295                     trackerDSKCF_structOccluder.previousTarget.w,...
0296                     trackerDSKCF_structOccluder.previousTarget.h]...
0297                     =fromBBtoCentralPoint(tmpOccBB);
0298                 
0299                 trackerDSKCF_structOccluder.target_sz=...
0300                     [trackerDSKCF_structOccluder.previousTarget.h, ...
0301                     trackerDSKCF_structOccluder.previousTarget.w];
0302                 
0303                 trackerDSKCF_structOccluder.window_sz = floor(...
0304                     trackerDSKCF_structOccluder.target_sz *...
0305                     (1 + DSKCFparameters_Occluder.padding));
0306                 
0307                 trackerDSKCF_structOccluder.output_sigma = sqrt(prod(...
0308                     trackerDSKCF_structOccluder.target_sz)) * ...
0309                     DSKCFparameters_Occluder.output_sigma_factor / ...
0310                     DSKCFparameters_Occluder.cell_size;
0311                 
0312                 trackerDSKCF_structOccluder.yf = fft2(gaussian_shaped_labels(...
0313                     trackerDSKCF_structOccluder.output_sigma, floor(...
0314                     trackerDSKCF_structOccluder.window_sz / DSKCFparameters_Occluder.cell_size)));
0315                 
0316                 %store pre-computed cosine window
0317                 trackerDSKCF_structOccluder.cos_window = hann(size(...
0318                     trackerDSKCF_structOccluder.yf,1)) * hann(size(...
0319                     trackerDSKCF_structOccluder.yf,2))';
0320                 
0321                 [trackerDSKCF_structOccluder]=singleFrameDSKCF_occluder(1,im,...
0322                     depth,trackerDSKCF_structOccluder,DSKCFparameters_Occluder);
0323                 
0324                 %update target size in the current object tracker
0325                 trackerDSKCF_structOccluder.currentTarget=...
0326                     trackerDSKCF_structOccluder.previousTarget;
0327             end
0328         end
0329         
0330         timeMatrixRow(ticINDEX)=toc(timeStartNewTracker);
0331         
0332     else
0333         %PREVIOUS FRAME UNDER OCCLUSION....
0334         
0335         timeTrackOccluder=tic();
0336         ticINDEX=4;
0337         
0338         %track the occluded object!!!
0339         [trackerDSKCF_structOccluder,occludedPos]=singleFrameDSKCF_occluder(0,im,...
0340             depth,trackerDSKCF_structOccluder,DSKCFparameters_Occluder);
0341         
0342         %update occluder previous position for tracking...
0343         trackerDSKCF_structOccluder.previousTarget.posX=...
0344             trackerDSKCF_structOccluder.currentTarget.posX;
0345         trackerDSKCF_structOccluder.previousTarget.posY=...
0346             trackerDSKCF_structOccluder.currentTarget.posY;
0347         
0348         
0349         if isempty(trackerDSKCF_structOccluder.currentTarget.bb),
0350             trackerDSKCF_structOccluder.currentTarget.bb = ...
0351                 trackerDSKCF_structOccluder.previousTarget.bb;
0352         end
0353         %then update the previous
0354         trackerDSKCF_structOccluder.previousTarget.bb=...
0355             trackerDSKCF_structOccluder.currentTarget.bb;
0356         
0357         %update occluder bb in the main target
0358         trackerDSKCF_struct.currentTarget.occBB=trackerDSKCF_structOccluder.currentTarget.bb;
0359         
0360         timeMatrixRow(ticINDEX)=toc(timeTrackOccluder);
0361         
0362         timeSolveOcclusion=tic();
0363         ticINDEX=5;
0364         
0365         %enlarge searching reagion...
0366         if(isempty(trackerDSKCF_struct.previousTarget.bb)==false)
0367             extremaBB=[min([trackerDSKCF_struct.currentTarget.occBB(1),...
0368                 trackerDSKCF_struct.previousTarget.occBB(1),...
0369                 trackerDSKCF_struct.previousTarget.bb(1)]),...
0370                 min([trackerDSKCF_struct.currentTarget.occBB(2),...
0371                 trackerDSKCF_struct.previousTarget.occBB(2),...
0372                 trackerDSKCF_struct.previousTarget.bb(2)]),...
0373                 max([trackerDSKCF_struct.currentTarget.occBB(3),...
0374                 trackerDSKCF_struct.previousTarget.occBB(3),...
0375                 trackerDSKCF_struct.previousTarget.bb(3)]),...
0376                 max([trackerDSKCF_struct.currentTarget.occBB(4),...
0377                 trackerDSKCF_struct.previousTarget.occBB(4),...
0378                 trackerDSKCF_struct.previousTarget.bb(4)])];
0379             
0380             extremaBB=[max(extremaBB(1),1),max(extremaBB(2),1),...
0381                 min(extremaBB(3),size(im,2)),min(extremaBB(4),size(im,1))];
0382         else
0383             extremaBB=[min(trackerDSKCF_struct.currentTarget.occBB(1),...
0384                 trackerDSKCF_struct.previousTarget.occBB(1)),...
0385                 min(trackerDSKCF_struct.currentTarget.occBB(2),...
0386                 trackerDSKCF_struct.previousTarget.occBB(2)),...
0387                 max(trackerDSKCF_struct.currentTarget.occBB(3),...
0388                 trackerDSKCF_struct.previousTarget.occBB(3)),...
0389                 max(trackerDSKCF_struct.currentTarget.occBB(4),...
0390                 trackerDSKCF_struct.previousTarget.occBB(4))];
0391             extremaBB=[max(extremaBB(1),1),max(extremaBB(2),1),...
0392                 min(extremaBB(3),size(im,2)),min(extremaBB(4),size(im,1))];
0393             
0394         end
0395         
0396         %bbIn=framePrev.occBB;
0397         bbIn=extremaBB;
0398         bbIn=enlargeBB(bbIn ,0.05,size(noData));
0399         
0400         %extract the target roi, from the depth and the nodata mask
0401         front_depth=roiFromBB(depth16Bit,bbIn);
0402         depthNoData=roiFromBB(noData,bbIn);
0403         
0404         %in case of bounding box with no depth data....
0405         if(sum(sum(depthNoData)')==size(front_depth,1)*size(front_depth,2))
0406             trackerDSKCF_struct.currentTarget.LabelRegions=depthNoData>10000000;
0407             trackerDSKCF_struct.currentTarget.Centers=1000000;
0408             trackerDSKCF_struct.currentTarget.LUT=[];
0409             %eventually segment the current occluding area
0410         else
0411             %note, we are saving the segmentation of the occluding region,
0412             %in the target struct rather thant the other one!!!!!
0413             [trackerDSKCF_struct.currentTarget.LabelRegions,...
0414                 trackerDSKCF_struct.currentTarget.Centers,...
0415                 trackerDSKCF_struct.currentTarget.LUT,~,~,~]=...
0416                 fastDepthSegmentationDSKCF_noiseModel(front_depth,3,depthNoData,...
0417                 1,[-1 -1 -1],1,trackerDSKCF_struct.currentTarget.meanDepthObj,...
0418                 trackerDSKCF_struct.currentTarget.stdDepthObj,[2.3,0.00055,0.00000235]);
0419             
0420         end
0421         
0422         %filter out very small regions
0423         tmpProp=regionprops(trackerDSKCF_struct.currentTarget.LabelRegions,'Area');
0424         areaList= cat(1, tmpProp.Area);
0425         minArea=scaleDSKCF_struct.target_sz(currentScale).target_sz(2)*...
0426             scaleDSKCF_struct.target_sz(currentScale).target_sz(1)*0.05;
0427         
0428         areaSmallIndex=areaList<minArea;
0429         
0430         %exclude the small area index setting a super high depth!!!!!!!!
0431         %it will never be used
0432         trackerDSKCF_struct.currentTarget.Centers(:,areaSmallIndex)= 1000000;
0433         
0434         [dummyVal,trackerDSKCF_struct.currentTarget.regionIndex]=...
0435             min(trackerDSKCF_struct.currentTarget.Centers);
0436         
0437         %very bad segmentation, full of small regions. Set up a flag....
0438         if(dummyVal==1000000)
0439             trackerDSKCF_struct.currentTarget.regionIndex=6666666;
0440         end
0441         
0442         %search for target's candidates in the search region.....
0443         [tarBB, segmentedOccBB, targetList, targetIndex,occmask] =  ...
0444             targetSearchDSKCF(bbIn, trackerDSKCF_struct, DSKCFparameters,...
0445             im,depth,depth16Bit,scaleDSKCF_struct,confValue3);
0446         tarBBSegmented=[];
0447         if(isempty(segmentedOccBB)==false)
0448             extremaBB=[min([trackerDSKCF_struct.currentTarget.occBB(1),...
0449                 segmentedOccBB(1)]),min([trackerDSKCF_struct.currentTarget.occBB(2),...
0450                 segmentedOccBB(2)]),max([trackerDSKCF_struct.currentTarget.occBB(3),...
0451                 segmentedOccBB(3)]),max([trackerDSKCF_struct.currentTarget.occBB(4),...
0452                 segmentedOccBB(4)])];
0453             
0454             trackerDSKCF_struct.currentTarget.occBB=[max(extremaBB(1),1),...
0455                 max(extremaBB(2),1),min(extremaBB(3),size(im,2)),...
0456                 min(extremaBB(4),size(im,1))]';
0457             
0458         end
0459         
0460         if(isempty(trackerDSKCF_struct.currentTarget.occBB))
0461             trackerDSKCF_struct.currentTarget.occBB=trackerDSKCF_struct.previousTarget.occBB;
0462         end
0463         
0464         %THESE CANDIDATES....CAME FROM THE SEGMENTATIONS....YOU NEED TO
0465         %RESIZE THEM WITH THE REQUIRED WINDOW...
0466         centerNew=[];
0467         if(~isempty(tarBB))
0468             tarBBSegmented=tarBB;
0469             widthtarBB=tarBB(3)-tarBB(1);
0470             heighttarBB=tarBB(4)-tarBB(2);
0471             centerNew=floor([tarBB(1)+widthtarBB/2 tarBB(2)+heighttarBB/2]);
0472             
0473             tarBB(1:2)=centerNew - scaleDSKCF_struct.target_sz(scaleDSKCF_struct.i).target_sz([2 1])/2;
0474             tarBB(3:4)=centerNew + scaleDSKCF_struct.target_sz(scaleDSKCF_struct.i).target_sz([2 1])/2;
0475             
0476         end
0477         
0478         
0479         % calculate detection and segmentation consistency
0480         trackerDSKCF_struct.currentTarget.bb = tarBB;
0481         trackerDSKCF_struct.currentTarget.conf = targetList.Conf_class(targetIndex);
0482         trackerDSKCF_struct.currentTarget.segmentedBB = tarBB';
0483         
0484         
0485         %%Kill some strange respons on the occluding mask
0486         occmask = imfill(occmask,'holes');
0487         tmpMask=repmat(0,size(depth));
0488         tmpMask(bbIn(2):bbIn(4),bbIn(1):bbIn(3))=occmask;
0489         
0490         if(isempty(centerNew)==false)
0491             
0492             %re-assign new position to the target, even if the target is
0493             %not valid, you need this just for visualization or checking
0494             %the algorithm....
0495             [trackerDSKCF_struct.currentTarget.posX,...
0496                 trackerDSKCF_struct.currentTarget.posY...
0497                 trackerDSKCF_struct.currentTarget.w,...
0498                 trackerDSKCF_struct.currentTarget.h]...
0499                 =fromBBtoCentralPoint(trackerDSKCF_struct.currentTarget.bb);
0500             %update tracker struct, new position etc
0501             pos(2)=trackerDSKCF_struct.currentTarget.posX;
0502             pos(1)=trackerDSKCF_struct.currentTarget.posY;
0503             
0504             if(tmpMask(centerNew(2),centerNew(1))==1)
0505                 trackerDSKCF_struct.currentTarget.conf=0;
0506             end
0507         end
0508         
0509         % check recovery
0510         trackerDSKCF_struct.currentTarget.underOcclusion =1;
0511         if ~isempty(trackerDSKCF_struct.currentTarget.bb)
0512             [p, TMPtargetDepth,TMPtargetStd,TMPLabelRegions,TMPCenters,...
0513                 TMPregionIndex,TMPLUT,secondPlaneDepth,secondPlaneDepthStd] ...
0514                 = checkOcclusionsDSKCF_secondPlane(depth16Bit,...
0515                 noData,trackerDSKCF_struct, trackerDSKCF_struct.currentTarget.bb);
0516             
0517             if trackerDSKCF_struct.currentTarget.conf > confInterval1/2 && p<0.35,
0518                 trackerDSKCF_struct.currentTarget.underOcclusion =0;
0519                 trackerDSKCF_struct.currentTarget.segmentedBB = tarBBSegmented';
0520             end
0521             
0522             if ~trackerDSKCF_struct.currentTarget.underOcclusion,
0523                 tmpWeight = max(0,min(1,trackerDSKCF_struct.currentTarget.conf));
0524                 
0525             else
0526                 tmpWeight = 0;
0527             end
0528             
0529             
0530             if(isempty(secondPlaneDepth)==false)
0531                 TMPtargetDepth=secondPlaneDepth;
0532                 TMPtargetStd=secondPlaneDepthStd;
0533                 tmpWeight=tmpWeight*2.5;
0534                 if(tmpWeight>1)
0535                     tmpWeight=0.95;
0536                 end
0537                 
0538             end
0539             
0540             trackerDSKCF_struct.currentTarget.meanDepthObj = tmpWeight * TMPtargetDepth + (1-tmpWeight) * trackerDSKCF_struct.currentTarget.meanDepthObj;
0541             trackerDSKCF_struct.currentTarget.stdDepthObj = tmpWeight * TMPtargetStd + (1-tmpWeight) * trackerDSKCF_struct.currentTarget.stdDepthObj;
0542             
0543         else
0544             trackerDSKCF_struct.currentTarget.meanDepthObj = trackerDSKCF_struct.previousTarget.meanDepthObj;
0545             trackerDSKCF_struct.currentTarget.stdDepthObj = trackerDSKCF_struct.previousTarget.stdDepthObj;
0546         end
0547         
0548         timeMatrixRow(ticINDEX)=toc(timeSolveOcclusion);
0549     end
0550     
0551     
0552 end
0553 
0554 %IF UNDER OCCLUSION DON'T UPDATE.....
0555 if(trackerDSKCF_struct.previousTarget.underOcclusion==false && trackerDSKCF_struct.currentTarget.underOcclusion==false)
0556     additionalShapeInterpolation=0;
0557     timeEstimateChangeOfScale=tic();
0558     ticINDEX=6;
0559     
0560     %check for scale change
0561     if(firstFrame==false)
0562         scaleDSKCF_struct=getScaleFactorStruct(trackerDSKCF_struct.currentTarget.meanDepthObj,scaleDSKCF_struct);
0563         if(changeOfShapeFlag && scaleDSKCF_struct.updated==false)
0564                [scaleDSKCF_struct,newPosShape,additionalShapeInterpolation,shapeDSKCF_struct]=...
0565                    getShapeFactorStructDirectionsV2(trackerDSKCF_struct.currentTarget.segmentedBB,pos,...
0566                 trackerDSKCF_struct.currentTarget.meanDepthObj,scaleDSKCF_struct,shapeDSKCF_struct);
0567         end
0568     end
0569     
0570     timeMatrixRow(ticINDEX)=toc(timeEstimateChangeOfScale);
0571     
0572     timeModelUpdate=tic();
0573     ticINDEX=7;
0574     
0575     %obtain a subwindow for training at newly estimated target position
0576     patch = get_subwindow(im, pos, scaleDSKCF_struct.windows_sizes(scaleDSKCF_struct.i).window_sz);
0577     patch_depth = get_subwindow(depth, pos, scaleDSKCF_struct.windows_sizes(scaleDSKCF_struct.i).window_sz);
0578     
0579     %check for detections....and generate the new weights
0580     %detWf=fft2(detW);
0581     detWf=scaleDSKCF_struct.yfs(scaleDSKCF_struct.i).yf;%fft2(detW);
0582     %update the model
0583     [trackerDSKCF_struct.model_alphaf, trackerDSKCF_struct.model_alphaDf, ...
0584         trackerDSKCF_struct.model_xf, trackerDSKCF_struct.model_xDf]=...
0585         modelUpdateDSKCF(firstFrame,patch,patch_depth,DSKCFparameters.features,...
0586         DSKCFparameters.cell_size,scaleDSKCF_struct.cos_windows(scaleDSKCF_struct.i).cos_window,...
0587         DSKCFparameters.kernel,detWf,...
0588         DSKCFparameters.lambda,trackerDSKCF_struct.model_alphaf, ...
0589         trackerDSKCF_struct.model_alphaDf,trackerDSKCF_struct.model_xf,...
0590         trackerDSKCF_struct.model_xDf,scaleDSKCF_struct.updated,DSKCFparameters.interp_factor+additionalShapeInterpolation);
0591     
0592     %if scale changed you must change tracker size information
0593     if(scaleDSKCF_struct.updated)
0594         %[newH,newW]= ;
0595         trackerDSKCF_struct.currentTarget.h=scaleDSKCF_struct.target_sz(scaleDSKCF_struct.i).target_sz(1);
0596         trackerDSKCF_struct.currentTarget.w=scaleDSKCF_struct.target_sz(scaleDSKCF_struct.i).target_sz(2);
0597         
0598         %reinit tracker shape
0599         relativeShapeScaleFactor=0;
0600         if(shapeDSKCF_struct.growingStatus==true)
0601             relativeShapeScaleFactor=1+(scaleDSKCF_struct.i-scaleDSKCF_struct.iPrev)*scaleDSKCF_struct.step;
0602             %shapeScaleFactor=scaleDSKCF_struct
0603         end
0604         shapeDSKCF_struct=initDSKCFshape(5,relativeShapeScaleFactor,shapeDSKCF_struct);
0605         
0606     end
0607     
0608     timeMatrixRow(ticINDEX)=toc(timeModelUpdate);
0609     
0610 else
0611     %%THERE IS AN OCCLUSION.....NOW WHAT TO DO.....? DON'T UPDATE MODEL....
0612     %UPDATE ONLY POSITION!!!!!
0613     
0614     % TO BE CHECKEDD!!!!!
0615     if(isempty(trackerDSKCF_struct.currentTarget.bb))
0616         pos=[];
0617     else
0618         pos=[trackerDSKCF_struct.currentTarget.posY,trackerDSKCF_struct.currentTarget.posX];
0619     end
0620 end
0621 
0622 end

Generated on Thu 24-Nov-2016 18:03:21 by m2html © 2005