【问题标题】:Get the size of HOG feature vector - MATLAB获取 HOG 特征向量的大小 - MATLAB
【发布时间】:2016-04-02 01:18:24
【问题描述】:

我是图像处理的初学者,我正在使用 MATLAB 从图像中提取 HOG 特征来训练 SVM 分类器。训练图像的大小为 480*640 像素,使用内置 MATLAB extractHOGFeatures 函数的默认设置,我得到了 167796 个特征。然而,当我测试模型时,它给我的特征更少(只有 216 个特征!),因为我知道测试图像与训练图像具有相同的大小。我在 MATLAB 中收到此错误“TEST 和训练数据中的列数必须相等”。

你知道如何解决这个问题并为训练集和测试集获得相同大小的特征向量吗?

这里是代码,

    [fpos,fneg] = featuress(pathPos, pathNeg);  
    %train SVM
    HOG_featV = loadingV(fpos,fneg);   % loading and labeling each training example


    %% Detection 
    tSize = [24 32];
    testImPath = '.\face_detection\dataset\bikes_and_persons2\';
    imlist = dir([testImPath '*.bmp']);
    for j = 1:length(imlist)
    disp ('inside for loop');
    img = imread([testImPath imlist(j).name]);
    axis equal; axis tight; axis off;
    imshow(img); hold on;
    detect(img,model,tSize);



    %% training
    function [fpos, fneg] = featuress(pathPos,pathNeg)
    % extract features for positive examples
    imlist = dir([pathPos '*.bmp']);
    for i = 1:length(imlist)
      im = imread([pathPos imlist(i).name]);
      fpos{i} = extractHOGFeatures(double(im));
    end
    % extract features for negative examples
    imlist = dir([pathNeg '*.bmp']);
    for i = 1:length(imlist)
      im = imread([pathNeg imlist(i).name]);
      fneg{i} = extractHOGFeatures(double(im));
    end
   end


     %% testing function
     function detect(im,model,wSize)
     topLeftRow = 1;
     topLeftCol = 1;
    [bottomRightCol bottomRightRow d] = size(im);

    fcount = 1;
    for y = topLeftCol:bottomRightCol-wSize(2)    
       for x = topLeftRow:bottomRightRow-wSize(1)
         p1 = [x,y];
         p2 = [x+(wSize(1)-1), y+(wSize(2)-1)];
         po = [p1; p2];
         img = imcut(po,im);      
    featureVector{fcount} = extractHOGFeatures(double(img));
    boxPoint{fcount} = [x,y];
    fcount = fcount+1;
    x = x+1;
        end
    end

  lebel = ones(length(featureVector),1);
  P = cell2mat(featureVector');
  % each row of P' correspond to a window

   [ predictions] = svmclassify(model, P); % classifying each window

   [a, indx]= max(predictions);
    bBox = cell2mat(boxPoint(indx));
    rectangle('Position',[bBox(1),bBox(2),24,32],'LineWidth',1, 'EdgeColor','r');
      end

提前致谢。

【问题讨论】:

  • 除非你显示你的代码,否则没有人可以帮助你。

标签: matlab computer-vision svm feature-extraction matlab-cvst


【解决方案1】:

P 的大小是多少?是 167796 x 216 吗?如果是这样,那么在调用cell2mat 时不应转置featureVector。或者你应该在使用之前转置P。您还可以将featureVector 设为矩阵而不是元胞数组。既然你知道 HOG 向量的长度是 167796 并且你知道你有多少张图片,你可以预先分配它,然后填写行。

【讨论】:

  • 不,我没有得到这个 P 值!
  • 好的,那么img的大小是多少?
猜你喜欢
  • 2016-07-19
  • 1970-01-01
  • 2016-05-07
  • 1970-01-01
  • 1970-01-01
  • 2014-01-01
  • 2014-07-14
  • 2014-08-11
  • 1970-01-01
相关资源
最近更新 更多