forked from pxnguyen/videotext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chardetexp.m
77 lines (69 loc) · 2.25 KB
/
chardetexp.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
70
71
72
73
74
75
76
77
% Given that you have mixtures of models, this script is to run and output
% the performance on the ICDAR dataset
configs=configsgen;
dataset_path = fullfile(configs.icdar,'test');
imagesPath = fullfile(dataset_path,'images');
modelPath = 'mixture_models';
gtDir = fullfile(configs.icdar,'test','charAnn');
dtDir = fullfile(configs.icdar,'test','det_results_synth');
dtDirMix = fullfile(configs.icdar,'test','det_results_mix');
dtDirReal = fullfile(configs.icdar,'test','det_results_real');
%% load the models
models = loadMixtureModels(modelPath);
%% get the image list
imgLst = dir(fullfile(imagesPath,'*.jpg'));
nImg = length(imgLst);
hmsPath = fullfile('hms');
if ~exist(hmsPath,'dir'); mkdir(hmsPath); end
%% Get the heatmap
savehms = @(sf,hms,scales) save(sf,'hms','scales');
parfor i=1:nImg
i
savePath = fullfile(hmsPath,sprintf('%s.mat',imgLst(i).name))
if exist(savePath,'file'); continue; end;
imgPath = fullfile(imagesPath,imgLst(i).name);
I = imread(imgPath);
tic; [hms,scales] = charDetMixtures('gethm',I,models); toc;
savehms(savePath,hms,scales);
end
%% Get the bbs
savebbs = @(sf,bbs) save(sf,'bbs');
parfor i=1:nImg
i
imgPath = fullfile(imagesPath,imgLst(i).name);
I = imread(imgPath);
currentHmsPath = fullfile(hmsPath,sprintf('%s.mat',imgLst(i).name));
bbs = charDetMixtures('getbbs',I,models,currentHmsPath);
bbs = bbNms(bbs,'type','max','overlap',.5,'separate',1);
savePath = fullfile(dtDirMix,sprintf('%s.mat',imgLst(i).name));
savebbs(savePath,bbs);
end
%% Get the f-score
fscores = zeros(length(configs.alphabets),2);
%%
beta = 2;
for iChar = 1:length(configs.alphabets)
try
iChar
currentChar = configs.alphabets(iChar);
[gt0,~] = bbGt('loadAll',gtDir,[],{'lbls',currentChar});
fprintf('Load synth\n');
dtsynth = loadBB(dtDir,iChar);
fprintf('Load real\n');
dtreal = loadBB(dtDirReal,iChar);
% Computing score for synth
[gts,dts] = bbGt( 'evalRes', gt0, dtsynth);
[xss,yss,~]=bbGt('compRoc', gts, dts, 0);
fs = fscore2(xss,yss,beta);
fscores(iChar,1) = fs;
% Computing score for real
[gtr,dtr] = bbGt( 'evalRes', gt0, dtreal);
[xsr,ysr,~]=bbGt('compRoc', gtr, dtr, 0);
fs = fscore2(xsr,ysr,beta);
fscores(iChar,2) = fs;
fscores
catch e
e
continue
end
end