detectWithGivenFeatures.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. function boxes = detectWithGivenFeatures(pyraFeats,model,thresh)
  2. %function boxes = detectWithGivenFeatures(pyraFeats,model,thresh)
  3. %
  4. % BRIEF:
  5. % Detect object in images by searching for large model responses in
  6. % terms of convolution scores
  7. %
  8. % Pretty much the same as the original code of who, only differs in
  9. % handing over precomputed features.
  10. % Additionally, no hallucinated levels are deleted.
  11. %
  12. % author: Alexander Freytag
  13. % date: 26-02-2014 (dd-mm-yyyy)
  14. levels = 1:length(pyraFeats.feat);
  15. %pre-allocate some memory (assume not more then 10k boxes in advance)
  16. boxes = zeros(10000,5);
  17. myDetectorFilter = {model.w};
  18. % padding of image borders
  19. padx = pyraFeats.padx;
  20. pady = pyraFeats.pady;
  21. sizx = size(model.w,2);
  22. sizy = size(model.w,1);
  23. cnt = 0;
  24. for l = levels,
  25. % get features of current scale
  26. scale = pyraFeats.scale(l);
  27. % do the actual convolution
  28. if ( ndims ( myDetectorFilter{1} ) > 2 )
  29. resp = fconv3D( pyraFeats.feat{l}, myDetectorFilter, 1,1);
  30. else
  31. resp = fconv2D( pyraFeats.feat{l}, myDetectorFilter, 1,1);
  32. end
  33. % correction of data structure
  34. resp = resp{1};
  35. % only accept scores over thresh
  36. [y,x] = find(resp >= thresh);
  37. if ( ~isempty(x) )
  38. I = (x-1)*size(resp,1)+y;
  39. % convert responses to original image coordinates
  40. x1 = (x-1-padx)*scale + 1;
  41. y1 = (y-1-pady)*scale + 1;
  42. x2 = x1 + sizx*scale - 1;
  43. y2 = y1 + sizy*scale - 1;
  44. i = cnt+1:cnt+length(I);
  45. % store corners of box + score
  46. boxes(i,:) = [x1 y1 x2 y2 resp(I)];
  47. % increase number of responses found so far
  48. cnt = cnt+length(I);
  49. end
  50. end
  51. %that's it, return the found boxes with corresponding scores
  52. boxes = boxes(1:cnt,:);
  53. end