非极大值抑制(Non-maximum suppression)在物体检测领域的应用
轉(zhuǎn)載自:http://blog.csdn.net/pb09013037/article/details/45477591
一、Nms主要目的
? ? ? ? ??在物體檢測非極大值抑制應(yīng)用十分廣泛,主要目的是為了消除多余的框,找到最佳的物體檢測的位置。
如上圖中:雖然幾個框都檢測到了人臉,但是我不需要這么多的框,我需要找到一個最能表達人臉的框。下圖汽車檢測也是同樣的原理。
?
?二、原理
? 非極大值抑制,顧名思義就是把非極大值過濾掉(抑制)。下面我就R-CNN或者SPP_net中的matlab源碼來進行解釋。
function picks = nms_multiclass(boxes, overlap)
%%boxes為一個m*n的矩陣,其中m為boundingbox的個數(shù),n的前4列為每個boundingbox的坐標,格式為
%%(x1,y1,x2,y2);第5:n列為每一類的置信度。overlap為設(shè)定值,0.3,0.5 .....
x1 = boxes(:,1);%所有boundingbox的x1坐標
y1 = boxes(:,2);%所有boundingbox的y1坐標
x2 = boxes(:,3);%所有boundingbox的x2坐標
y2 = boxes(:,4);%所有boundingbox的y2坐標
area = (x2-x1+1) .* (y2-y1+1); %每個%所有boundingbox的面積
picks = cell(size(boxes, 2)-4, 1);%為每一類預(yù)定義一個將要保留的cell
for iS = 5:size(boxes, 2)%每一類單獨進行
? ? s = boxes(:,iS);
? ? [~, I] = sort(s);%置信度從低到高排序
? ? pick = s*0;
? ? counter = 1;
? ? while ~isempty(I)
? ? ? last = length(I);
? ? ? i = I(last); ?
? ? ? pick(counter) = i;%無條件保留每類得分最高的boundingbox
? ? ? counter = counter + 1;
? ? ? xx1 = max(x1(i), x1(I(1:last-1)));
? ? ? yy1 = max(y1(i), y1(I(1:last-1)));
? ? ? xx2 = min(x2(i), x2(I(1:last-1)));
? ? ? yy2 = min(y2(i), y2(I(1:last-1)));
? ? ? w = max(0.0, xx2-xx1+1);
? ? ? h = max(0.0, yy2-yy1+1);
? ? ? inter = w.*h;
? ? ? o = inter ./ (area(i) + area(I(1:last-1)) - inter);%計算得分最高的那個boundingbox和其余的boundingbox的交集面積
? ? ? I = I(o<=overlap);%保留交集小于一定閾值的boundingbox
? ? end
? ? pick = pick(1:(counter-1));
? ? picks{iS-4} = pick;%保留每一類的boundingbox
end
?
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的非极大值抑制(Non-maximum suppression)在物体检测领域的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 参考文献的注意事项
- 下一篇: 模式识别的评价方法:ROC曲线, DET