-
Notifications
You must be signed in to change notification settings - Fork 60
/
rename_inverse.m
98 lines (86 loc) · 2.63 KB
/
rename_inverse.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File Name: transform.m
% Description:
% Inverse rename ICPR018 dataset result txt file name.
% This is according to the rename list generated by <rename.m>.
%
% Origin img name: <img_1.txt>
% New img name: <T1._WBXtXdXXXXXXXX_!!0-item_pic.jpg.txt>
%
% Author: Haozheng Li
% EMail: [email protected]
% Created Time: 2018.5.15
% Last Revised: 2018.5.15
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
clc;
clear;
close all;
fclose('all');
%Parameter
rename_list_name = 'rename_list.txt';
icpr_img_folder = 'image_10000\';
icpr_txt_folder = 'results\';
icdar_gt_folder = 'txt_10000\';
%%
%Clean
fprintf('cleaning gt folder...\n');
gt_dir = dir(icdar_gt_folder);
for i = 3 : size(gt_dir, 1)
delete(strcat(icdar_gt_folder, '*.*'));
end
icpr_count = 0;
rename_list = fopen(rename_list_name, 'r');
while ~feof(rename_list)
tline = fgetl(rename_list);
if tline == -1
break;
end
icpr_count = icpr_count + 1;
str = regexp(tline, ' ', 'split');
rename = str{1};
rename_inv = str{2};
icpr_img_path = strcat(icpr_img_folder, rename_inv, '.jpg');
img = imread(icpr_img_path);
if size(size(img), 2) > 3
img = img(:, :, 1);
end
imshow(img);
icpr_txt_name = strcat(rename, '.txt');
icpr_txt_path = strcat(icpr_txt_folder, icpr_txt_name);
icdar_gt_name = strcat(rename_inv, '.txt');
icdar_gt_path = strcat(icdar_gt_folder, icdar_gt_name);
if ~exist(icpr_txt_path, 'file')
gt_file = fopen(icdar_gt_path, 'w');
fclose(gt_file);
else
copyfile(icpr_txt_path, icdar_gt_folder);
oldname = strcat(icdar_gt_folder, icpr_txt_name);
newname = icdar_gt_name;
dos(['rename' 32 oldname 32 newname]);
end
gt = fopen(icdar_gt_path, 'r');
while ~feof(gt)
tline = fgetl(gt);
if tline == -1
break;
end
str = regexp(tline, ',', 'split');
x1 = str2double(str{1});
y1 = str2double(str{2});
x2 = str2double(str{3});
y2 = str2double(str{4});
x3 = str2double(str{5});
y3 = str2double(str{6});
x4 = str2double(str{7});
y4 = str2double(str{8});
line([x1, x2, x3, x4], [y1, y2, y3, y4], 'Color', 'g');
end
fclose(gt);
if rem(icpr_count, 100) == 0
fprintf('transform %d...\n', icpr_count);
end
pause(0.01);
end
fclose(rename_list);
fprintf('%d files have renamed inverse.\n', icpr_count);