-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdetect_object.m
More file actions
105 lines (82 loc) · 2.53 KB
/
detect_object.m
File metadata and controls
105 lines (82 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function [ ds ] = detect_object( impath, cls, DISPLAY )
%DETECT_OBJECT Detecting Object using Active Deformable Part Models
% impath: input image file
% cls: object class of interest
% DISPLAY: boolean flag for displaying top detection
% ds: detection bounding boxes
% AUTORIGHTS
% -------------------------------------------------------
% Copyright (C) 2013-2014 Menglong Zhu, Nikolay Atanasov
% Samarth Brahmbhatt
%
% This file is part of the Active Deformable Part Models
% code (http://cis.upenn.edu/~menglong/adpm.html)
% and is available under the terms of an MIT-like license
% provided in COPYING. Please retain this notice and
% COPYING if you use this file (or a portion of it) in
% your project.
% -------------------------------------------------------
if nargin < 1
disp('Please specify input image file');
ds = [];
return;
end
if nargin < 2
disp('Please specify object class');
ds = [];
return;
end
if nargin < 3
DISPLAY = 1;
end
% load original DPM model
load(sprintf('models/VOC2010/%s_final.mat', cls));
% load pca policy
pca_pol = load(sprintf('models/%s_2010_pca_policy_%d_%d',cls, 20, 5));
pca_policy = pca_pol.policy;
%load full policy
pol = load(sprintf('models/%s_2010_policy_%d_%d',cls, 50, 5));
policy = pol.policy;
im = imread(impath);
% Display image
if DISPLAY
clf;
imagesc(im);
axis image;
axis off;
end
% Perform object detection
ds = detect(im, model, policy, pca_policy);
% Display detection
if DISPLAY
showboxes(im, ds(1,1:4));
title('ADPM top detection');
end
end
% main detection function
function [ds] = detect(im, model, policy, pca_policy)
pca = 5;
load('external/pca.mat');
policy_model = grammar2simple(project_model(model, coeff, pca));
fprintf('Building the feature pyramid...');
th = tic();
pyra = featpyramid(double(im), model);
tF = toc(th);
fprintf('done\n');
fprintf(' --> Feature pyramid generation took %f seconds\n', tF);
fprintf('Computing detections with ADPM...');
[dP, bP, tP, nP] = pca_policy_detect(pyra, policy_model, policy, pca_policy);
fprintf('done\n');
fprintf(' --> ADPM detection took %f seconds\n', tP);
ds = getboxes(im, dP, bP);
end
function b = getboxes(image, det, all)
b = [];
if ~isempty(det)
[det, all] = clipboxes(image, det, all);
I = nms(det, 0.5);
det = det(I,:);
all = all(I,:);
b = [det(:,1:4) all];
end
end