BB_OVERLAP.m calculates Bounding box overlap BB_OVERLAP is a function to calculate Bounding box overlap. Please note that this function was part of the RGBD tracker code presented in [1] and available under under Open Source MIT License at http://tracking.cs.princeton.edu/code.html INPUT:
0001 function overlap = bb_overlap(bb1,bb2) 0002 % BB_OVERLAP.m calculates Bounding box overlap 0003 % 0004 % BB_OVERLAP is a function to calculate Bounding box overlap. Please 0005 % note that this function was part of the RGBD tracker code presented in 0006 % [1] and available under under Open Source MIT License at 0007 % http://tracking.cs.princeton.edu/code.html 0008 % 0009 % INPUT: 0010 0011 % - bb1 and bb2 bounding boxes in the format [topLeftX, topLeftY, 0012 % bottomRightX, bottomRightY] read as [columnIndexTopLeft, rowIndexTopLeft, 0013 % columnIndexBottomRight, rowIndexBottomRight] 0014 % 0015 % -overlap estimated overlap 0016 % 0017 % See also OCCLUDINGOBJECTSEGDSKCF 0018 % 0019 % [1] Shuran Song and Jianxiong Xiao. Tracking Revisited using RGBD 0020 % Camera: Baseline and Benchmark. 2013. 0021 % 0022 overlap = zeros(1,size(bb2,2)); 0023 0024 if isempty(bb1), return; end; 0025 0026 for i=1:size(bb2,2), 0027 overlap(i) = overlapSingle(bb1,bb2(:,i)); 0028 end 0029 end 0030 0031 function out= overlapSingle(bb1,bb2) 0032 if bb1(1) > bb2(3),out =0 ;return ;end 0033 if (bb1(2) > bb2(4)),out =0 ; return ; end 0034 if (bb1(3) < bb2(1)),out =0 ;return ; end 0035 if (bb1(4) < bb2(2)),out =0 ;return ; end 0036 0037 b=min(bb1(3:4),bb2(3:4))-max(bb1(1:2),bb2(1:2)); 0038 b(b<0)=0; 0039 intersection =b(1).*b(2); 0040 area1=(bb1(3)-bb1(1))*(bb1(4)-bb1(2)); 0041 area2=(bb2(3)-bb2(1))*(bb2(4)-bb2(2)); 0042 out = intersection/(area1 + area2 - intersection); 0043 end