-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdo_one_img.m
69 lines (61 loc) · 2.04 KB
/
do_one_img.m
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
%
% Copyright (c) 2018 James Pritts
% Licensed under the MIT License (see LICENSE for details)
%
% Written by James Pritts
%
function [model_list,lo_res_list,stats_list,meas,img] = ...
do_one_img(img_url,solver,varargin)
repeats_init();
warning('off', 'MATLAB:nearlySingularMatrix');
rng('shuffle')
dbpath = fileparts(mfilename('fullpath'));
KeyValDb.getObj('dbfile', [dbpath '/features.db']);
img = Img('url', img_url);
cache_params = { 'read_cache', true, ...
'write_cache', true };
cid_cache = CidCache(img.cid,cache_params{:});
pp = [(img.width)/2 (img.height)/2];
sc = sum(2*pp);
K = [1/sc 0 -pp(1)/sc; ...
0 1/sc -pp(2)/sc; ...
0 0 1];
dr = DR.get(img,cid_cache, ...
{'type','mser', ...
'reflection', true});
x = [dr(:).u];
G = DR.group_desc(dr,varargin{:});
clear dr;
G = filter_features(x,G,img);
G = limit_group_size(x,G,50);
[x,G] = limit_drs(x,G,1000);
x = x(:,~isnan(G));
G = findgroups(G(~isnan(G)));
[model_list,lo_res_list,stats_list] = ...
rectify_planes(x,G,solver,pp,varargin{:});
meas = struct('x',x,'G',G);
function G = filter_features(x,G,img)
areaT = 0.000035*img.area;
G(find(abs(PT.calc_scale(x)) < areaT)) = nan;
angles = LAF.calc_angle(x);
G(find((angles < 1/10*pi) | (angles > 9/10*pi))) = nan;
G = DR.rm_singletons(findgroups(G));
function G = limit_group_size(x,G,T)
freq = hist(G,1:max(G));
breakit = find(freq > T);
for k = breakit
ind = find(G == k);
m = ceil(freq(k)/T);
Gp = repmat([1:m],T,1)+max(G);
Gp = Gp(1:end-(numel(Gp)-numel(ind)));
G(ind) = Gp;
end
G = DR.rm_singletons(findgroups(G));
function [x,G] = limit_drs(x,G,T)
freq = hist(G,1:max(G));
[sfreq,ind0] = sort(freq,'descend');
csum = cumsum(sfreq);
ind1 = find(csum > T);
rmind = ind0(ind1);
[Lia,Lib] = ismember(G',rmind' ,'rows');
G(Lia) = nan;