物体检测的特征组合

时间:2017-07-20 05:46:45

标签: feature-extraction object-detection vlfeat

我正在尝试将LBP-HOG结合起来进行物体检测。这实际上是模型自由对象跟踪器的一部分。我已经提取了这两个特征并将它们输入到线性SVM中。这是代码。

svm  = trainSVM( pos{j},neg{j} );  // for LBP features where pos{j} and neg{j} are mxn matrix.

svmHog=trainSVM( posHog{j},negHog{j} ); // for HOG features. i used VLFEAT for both LBP and HOG

SVM灯库用于培训。

我首先使用LBP功能进行窗口分类,使用滑动窗口方法,步幅为4。

然后将前100个预测标签喂入HOG分类器。但我得到的结果总是像44x1,87x1,202x1一样。我错过了什么吗?我的检测代码如下:

function detect(im,model,modelHog,wSize)
%{
this function will take three parameters
    1.  im      --> Test Image
    2.  model   --> trained model
    3.  wStize  --> Size of the window, i.e. [24,32]
and draw rectangle on best estimated window
%}
topLeftRow = 1;
topLeftCol = 1;
[bottomRightCol bottomRightRow d] = size(im);
fcount = 1;
% this for loop scan the entire image and extract features for each sliding window
for y = topLeftCol:3:bottomRightCol-wSize(2)    
    for x = topLeftRow:3:bottomRightRow-wSize(1)
        p1 = [x,y];
        p2 = [x+(wSize(1)-1), y+(wSize(2)-1)];
        po = [p1; p2];
        img = imcut(po,im); 
        hog= vl_hog(single(img),8);
        hog = hog(:,:,1:9) ; % + hog(:,:,10:18);

        lbp= vl_lbp(single(img),16);
        %lbp = lbp(:,:,1:9)+ lbp(:,:,10:18);

        featureVector{fcount} =  lbp; %cat(3,lbp,hog); %HOG(double(img));
        featureVector{fcount}=featureVector{fcount}(:)';
        featureVector{fcount}=transpose(featureVector{fcount});


        featureVectorHOG{fcount} =  hog; %cat(3,lbp,hog); %HOG(double(img));
        featureVectorHOG{fcount}=featureVectorHOG{fcount}(:)';
        featureVectorHOG{fcount}=transpose(featureVectorHOG{fcount});

        boxPoint{fcount} = [x,y];
        fcount = fcount+1;
        x = x+1;
    end
end
lebel = ones(length(featureVector),1);
P = double(cell2mat(featureVector));
% each row of P' correspond to a window
[~, predictions] = svmclassify(P',lebel,model); % classifying each window
[sortedValues,sortIndex] = sort(predictions(:),'descend');
for j=1:100%length(sortedValues)
    bBox{j} = cell2mat(boxPoint(sortIndex(j)));
    fVectorHOG{j}=featureVectorHOG{sortIndex(j)};
end
lebel = ones(length(fVectorHOG),1);
P = double(cell2mat(fVectorHOG));
[~, predictions] = svmclassify(P',lebel,modelHog); % classifying each window
[a, indx]= max(predictions);
bBox = cell2mat(boxPoint(indx));
rectangle('Position',[bBox(1),bBox(2),24,32],'LineWidth',1, 'EdgeColor','r');
end

0 个答案:

没有答案