-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannotation_vivahand_darknet.pl
executable file
·103 lines (80 loc) · 2.34 KB
/
annotation_vivahand_darknet.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
95
96
97
98
99
100
101
102
103
#Generate annotation for yolo
#http://cvrr.ucsd.edu/vivachallenge/index.php/hands/hand-detection/
use warnings;
use strict;
use Image::Size;
use File::Copy;
use File::Spec::Functions qw/catfile/;
my $single_class=1;
for(my $test=0;$test<1;$test=$test+1){ #set 1 because not exist test/posGt
my $folder="train";
if($test eq 1){
$folder="test";
}
my $dataset_path="dataset/vivahand/detectiondata/";
my $file_no=0;
my $line_no=0;
my $thumb_dir="./$dataset_path"."$folder/posGt";
open(TRAIN,">$dataset_path"."$folder/pos/$folder.txt");
opendir(THUMB, $thumb_dir) or die "usage: $0 thumb_dir\n";
foreach my $dir (readdir(THUMB)) {
next if ($dir eq '.' || $dir eq '..');
next if ($dir eq '.DS_Store');
my $tag_dir = catfile($thumb_dir, $dir);
#print $dir;
open(IN,"<$tag_dir") or die ("wider face dataset not found");
my $imagew;
my $imageh;
my $header=<IN>;
my $file_path=$dir;
chomp $file_path;
#print $file_path."\n";
my $img_path=$file_path;
$img_path =~ s/\.txt/\.png/g;
#print $img_path."\n";
($imagew, $imageh) = imgsize("./$dataset_path"."$folder/pos/$img_path");
print TRAIN "../$dataset_path"."$folder/pos/$img_path\n";
open(OUT,">./$dataset_path"."$folder/pos/$file_path");
while(my $line=<IN>){
#print $line;
my $category_name;
my $xmin;
my $ymin;
my $w;
my $h;
($category_name,$xmin,$ymin,$w,$h)=split(" ",$line);
my $x=$xmin+$w/2;
my $y=$ymin+$h/2;
$x=1.0*$x/$imagew;
$y=1.0*$y/$imageh;
$w=1.0*$w/$imagew;
$h=1.0*$h/$imageh;
my $category=0;
if($category_name eq "leftHand_driver"){
$category=0;
}else{
if($category_name eq "rightHand_driver"){
$category=1;
}else{
if($category_name eq "leftHand_passenger"){
$category=2;
}else{
if($category_name eq "rightHand_passenger"){
$category=3;
}else{
print "unknown $category_name";
}
}
}
}
if($single_class eq 1){
$category=0;
}
print OUT "$category $x $y $w $h\n";
}
close(OUT);
close(IN);
}
close(THUMB);
close(TRAIN);
}