-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannotation_widerface_keras.pl
executable file
·94 lines (81 loc) · 1.79 KB
/
annotation_widerface_keras.pl
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
#Generate annotation for keras
use warnings;
use strict;
use Image::Size;
my $dataset_path="dataset/widerface/";
mkdir "$dataset_path"."WIDER_train/annotations_keras";
my $file_no=0;
my $line_no=0;
open(IN,"<$dataset_path"."wider_face_split/wider_face_train_bbx_gt.txt") or die ("wider face dataset not found");
while(my $line=<IN>){
#print $line;
if($line =~ /--/){
if($line_no ne 0){
print OUT <<"EOF";
</annotation>
EOF
close(OUT);
$line_no=0;
}
$line_no=1;
$file_no=$file_no+1;
my $file_path=$line;
chomp $file_path;
my $imagew;
my $imageh;
($imagew, $imageh) = imgsize("./$dataset_path"."WIDER_train/images/$file_path");
open(OUT,">$dataset_path"."WIDER_train/annotations_keras/wider_face-$file_no".".xml");
print OUT <<"EOF";
<annotation verified="yes">
<folder>images</folder>
<filename>$file_path</filename>
<path>$file_path</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>$imagew</width>
<height>$imageh</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
EOF
next;
}
if($line_no eq 1){
$line_no=$line_no+1;
next;
}
if($line_no eq 2){
my $xmin;
my $ymin;
my $w;
my $h;
($xmin,$ymin,$w,$h)=split(" ",$line);
my $xmax;
my $ymax;
$xmax=$xmin+$w;
$ymax=$ymin+$h;
print OUT <<"EOF";
<object>
<name>face</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>$xmin</xmin>
<ymin>$ymin</ymin>
<xmax>$xmax</xmax>
<ymax>$ymax</ymax>
</bndbox>
</object>
EOF
}
}
if($line_no ne 0){
print OUT <<"EOF";
</annotation>
EOF
close(OUT);
}
close(IN);