一天的成果

主线程函数有:

load('INRIA/inriaperson_final');
addpath star-cascade
im1 = imread('test3.png');
im2 = imread('test2.png');

thresh = -0.5;
pca = 5;
% orig_model = model;
csc_model = cascade_model(model, '2007', pca, thresh);

pyra1 = featpyramid(double(im1), csc_model);
pyra2 = featpyramid(double(im2), csc_model);


[dCSC1, bCSC1] = cascade_detect(pyra1, csc_model, csc_model.thresh);
[dCSC2, bCSC2] = cascade_detect(pyra2, csc_model, csc_model.thresh);
boxes1 = getboxes(csc_model, im1, dCSC1, bCSC1);
boxes2 = getboxes(csc_model, im2, dCSC1, bCSC1);

featureim1 = cell(1,8);
featureim2 = cell(1,8);
numfilters = 10;
n = 1;
for i = numfilters:-1:1
%     n = 1;
    x1 = boxes1(:,1+(i-1)*4);
    y1 = boxes1(:,2+(i-1)*4);
    x2 = boxes1(:,3+(i-1)*4);
    y2 = boxes1(:,4+(i-1)*4);
    % remove unused filters
    del = find(((x1 == 0) .* (x2 == 0) .* (y1 == 0) .* (y2 == 0)) == 1);
    x1(del) = [];
    x2(del) = [];
    y1(del) = [];
    y2(del) = [];
    if i == 2
        continue;
    end
    if i == 1
        continue;
    end
    temp = imcrop(im1,[x1 y1 x2-x1 y2-y1]); 
    temp = rgb2gray(temp);
    TextFeature=statxture(temp);
%     featureim1 = cell(8)
    featureim1{1,n} = TextFeature;
    n = n+1;
end

n = 1;
for i = numfilters:-1:1
%     n = 1;
    x1 = boxes2(:,1+(i-1)*4);
    y1 = boxes2(:,2+(i-1)*4);
    x2 = boxes2(:,3+(i-1)*4);
    y2 = boxes2(:,4+(i-1)*4);
    % remove unused filters
    del = find(((x1 == 0) .* (x2 == 0) .* (y1 == 0) .* (y2 == 0)) == 1);
    x1(del) = [];
    x2(del) = [];
    y1(del) = [];
    y2(del) = [];
    if i == 2
        continue;
    end
    if i == 1
        continue;
    end
    temp = imcrop(im2,[x1 y1 x2-x1 y2-y1]); 
    temp = rgb2gray(temp);
    TextFeature=statxture(temp);
%     featureim2 = cell(8);
    featureim2{1,n} = TextFeature;
    n = n+1;
end

for k = 1:1:8
    feature1 = featureim1{1,k};
    feature2 = featureim2{1,k};
    distance = (feature1-feature2)*(feature1-feature2)';
    DisResult(k) = distance;
end
figure;
showboxes2(im2, boxes2);
figure;
showboxes2(im1, boxes1);
k = 1;
for i = numfilters:-1:1
%     n = 1;
    x1 = boxes2(:,1+(i-1)*4);
    y1 = boxes2(:,2+(i-1)*4);
    x2 = boxes2(:,3+(i-1)*4);
    y2 = boxes2(:,4+(i-1)*4);
%     % remove unused filters
%     del = find(((x1 == 0) .* (x2 == 0) .* (y1 == 0) .* (y2 == 0)) == 1);
%     x1(del) = [];
%     x2(del) = [];
%     y1(del) = [];
%     y2(del) = [];
    if i == 2
        continue;
    end
    if i == 1
        continue;
    end
    string = int2str(DisResult(k));
    k = k+1;
    x = round(x1+(x2-x1)/2);
    y = round(y1+(y2-y1)/2);
%     text(x,y,string);
    text('Position',[x,y],'string',string,'color','r')
end

用到的函数有:

function b = getboxes(model, image, det, all)
b = [];
if ~isempty(det)
  try
    % attempt to use bounding box prediction, if available
    bboxpred = model.bboxpred;
    [det all] = clipboxes(image, det, all);
    [det all] = bboxpred_get(bboxpred, det, all);
  catch
    warning('no bounding box predictor found');
  end
  [det all] = clipboxes(image, det, all);
  I = nms(det, 0.5);
  det = det(I,:);
  all = all(I,:);
  b = [det(:,1:4) all];
end
end
还有:

function showboxes2(im, boxes, out)

% showboxes(im, boxes, out)
% Draw bounding boxes on top of image.
% If out is given, a pdf of the image is generated (requires export_fig).

if nargin > 2
  % different settings for producing pdfs
  print = true;
  wwidth = 2.25;
  cwidth = 1.25;
  imsz = size(im);
  % resize so that the image is 300 pixels per inch
  % and 1.2 inches tall
  scale = 1.2 / (imsz(1)/300);
  im = imresize(im, scale, 'method', 'cubic');
  %f = fspecial('gaussian', [3 3], 0.5);
  %im = imfilter(im, f);
  boxes = (boxes-1)*scale+1;
else
  print = false;
  cwidth = 2;
end

% image(im); 
imshow(im);
if print
  truesize(gcf);
end
axis image;
axis off;
set(gcf, 'Color', 'white');

if ~isempty(boxes)
  numfilters = floor(size(boxes, 2)/4);
  if print
    % if printing, increase the contrast around the boxes
    % by printing a white box under each color box
    for i = 1:numfilters
      x1 = boxes(:,1+(i-1)*4);
      y1 = boxes(:,2+(i-1)*4);
      x2 = boxes(:,3+(i-1)*4);
      y2 = boxes(:,4+(i-1)*4);
      % remove unused filters
      del = find(((x1 == 0) .* (x2 == 0) .* (y1 == 0) .* (y2 == 0)) == 1);
      x1(del) = [];
      x2(del) = [];
      y1(del) = [];
      y2(del) = [];
      if i == 1
        w = wwidth;
      else
        w = wwidth;
      end
      line([x1 x1 x2 x2 x1]', [y1 y2 y2 y1 y1]', 'color', 'w', 'linewidth', w);
    end
  end
  % draw the boxes with the detection window on top (reverse order)
  for i = numfilters:-1:1
    x1 = boxes(:,1+(i-1)*4);
    y1 = boxes(:,2+(i-1)*4);
    x2 = boxes(:,3+(i-1)*4);
    y2 = boxes(:,4+(i-1)*4);
    % remove unused filters
    del = find(((x1 == 0) .* (x2 == 0) .* (y1 == 0) .* (y2 == 0)) == 1);
    x1(del) = [];
    x2(del) = [];
    y1(del) = [];
    y2(del) = [];
    if i == 2
        continue;
    end
    if i == 1
      c = [160/255 0 0];
      s = '-';
    else
      c = 'b';
      s = '-';
    end
    line([x1 x1 x2 x2 x1]', [y1 y2 y2 y1 y1]', 'color', c, 'linewidth', cwidth, 'linestyle', s);
  end
end

% save to pdf
if print
  % requires export_fig from http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
  export_fig([out]);
end
end

还有就是上一篇的纹理特征了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值