function [done] = trackRobby2(sequence, trackUntil, rep, firstPoint) szSt = 28; epsilon=2.1; similar=.9; maxCount = 10; frameCount =10; %Initialize target model with a representative Robby [frame,sizeim] = getRobby(sequence,1+((rep-1)*szSt),szSt); targetModel = learnDistribution(frame,1,0); currentH = targetModel.h currentCenter = targetModel.center if(firstPoint ~= 0) currentCenter = firstPoint; end staleTarget=0; shifting = 1; haveEstimate=0; for frm=65:trackUntil [frame,sizeim] = getRobby(sequence,1+((frm-1)*szSt),szSt); shifting = 1; haveEstimate = 0; while(shifting==1) if(haveEstimate==0) candidateModel = learnDistribution(frame,[currentCenter currentH],0); correlation = bhattachar(targetModel.modelDist,candidateModel.modelDist) newCenter = MeanShift(candidateModel,targetModel.modelDist); haveEstimate=1; end newCandidate = learnDistribution(frame,[newCenter,candidateModel.h],0); newHL = round(candidateModel.h + candidateModel.h*.1); newCandidateL = learnDistribution(frame,[newCenter,newHL],0); newHS = round(candidateModel.h - candidateModel.h*.1); newCandidateS = learnDistribution(frame,[newCenter,newHS],0); newCorrelation = bhattachar(targetModel.modelDist,newCandidate.modelDist) newCorrelationL = bhattachar(targetModel.modelDist,newCandidateL.modelDist); newCorrelationS = bhattachar(targetModel.modelDist,newCandidateS.modelDist); if(newCorrelationS > newCorrelation) newCandidate = newCandidateS; newCorrelation = newCorrelationS; 'Reducing H' end if(newCorrelationL > newCorrelation) newCandidate = newCandidateL; newCorrelation = newCorrelationL; 'Inflating H' end currentH = newCandidate.h; if(newCorrelation < similar) staleTarget=1; end %We jumped too far, so back track in half steps while(abs(newCorrelation - correlation) > eps) 'Shift Too Extreme' halfCenter = floor(.5*(newCenter + currentCenter)) newCandidate = learnDistribution(frame,[halfCenter newCandidate.h],0); newCorrelation = bhattachar(targetModel.modelDist,newCandidate.modelDist) newCenter = halfCenter; newCandidate.center = halfCenter; end correlation = newCorrelation; newCenter = MeanShift(newCandidate,targetModel.modelDist); drawBox(frame,newCenter,newCandidate.h,'b'); diff = (newCenter-newCandidate.center) if( sqrt(diff*diff') < epsilon) shifting=0; 'Close enough for Robby' currentCenter = newCenter; frameCount=frameCount+1; if(staleTarget==1) 'Stale Target, Learn Fresh Target' targetModel = learnDistribution(frame,[currentCenter currentH],0); currentCenter = targetModel.center; staleTarget=0; end drawBox(frame,newCenter,newCandidate.h,'b'); end if(frameCount >= maxCount) frameCount = 0; pause end end end done = 1;