forked from liuwei16/CSP
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dt_txt2json.m
31 lines (31 loc) · 889 Bytes
/
dt_txt2json.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
clear
addpath('./cocoapi/MatlabAPI')
main_path = '../output/valresults/city/h/off';
subdir = dir(main_path);
for j = 3 : length(subdir)
ndt=0;
dt_coco = struct();
dt_path = fullfile(main_path, subdir(j).name);
% res = load([dt_path,'/val_500_det.txt'],'%f');
res = load([dt_path,'/val_det.txt'],'%f');
num_imgs = max(res(:,1));
out = [dt_path,'/val_dt.json'];
if exist(out,'file')
continue
end
for i = 1:num_imgs
bbs = res(res(:,1)==i,:);
for ibb=1:size(bbs,1)
ndt=ndt+1;
bb=bbs(ibb,2:6);
dt_coco(ndt).image_id=i;
dt_coco(ndt).category_id=1;
dt_coco(ndt).bbox=bb(1:4);
dt_coco(ndt).score=bb(5);
end
end
dt_string = gason(dt_coco);
fp = fopen(out,'w');
fprintf(fp,'%s',dt_string);
fclose(fp);
end