Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/doc/read_file_score32.pl
16354 views
1
#!/usr/bin/perl
2
use strict;
3
use warnings;
4
use autodie; # die if problem reading or writing a file
5
6
my $filein = "./agast_score.txt";
7
my $fileout = "./agast_new.txt";
8
my $i1=1;
9
my $i2=1;
10
my $i3=1;
11
my $tmp;
12
my $ifcount0=0;
13
my $ifcount1=0;
14
my $ifcount2=0;
15
my $ifcount3=0;
16
my $ifcount4=0;
17
my $elsecount;
18
my $myfirstline = $ARGV[0];
19
my $mylastline = $ARGV[1];
20
my $tablename = $ARGV[2];
21
my @array0 = ();
22
my @array1 = ();
23
my @array2 = ();
24
my @array3 = ();
25
my $is_not_a_corner;
26
my $is_a_corner;
27
28
open(my $in1, "<", $filein) or die "Can't open $filein: $!";
29
open(my $out, ">", $fileout) or die "Can't open $fileout: $!";
30
31
32
$array0[0] = 0;
33
$i1=1;
34
while (my $line1 = <$in1>)
35
{
36
chomp $line1;
37
$array0[$i1] = 0;
38
if (($i1>=$myfirstline)&&($i1<=$mylastline))
39
{
40
if($line1=~/if\(ptr\[offset(\d+)/)
41
{
42
if($line1=~/if\(ptr\[offset(\d+).*\>.*cb/)
43
{
44
$tmp=$1;
45
}
46
else
47
{
48
if($line1=~/if\(ptr\[offset(\d+).*\<.*c\_b/)
49
{
50
$tmp=$1+128;
51
}
52
else
53
{
54
die "invalid array index!"
55
}
56
}
57
$array1[$ifcount1] = $tmp;
58
$array0[$ifcount1] = $i1;
59
$ifcount1++;
60
}
61
else
62
{
63
}
64
}
65
$i1++;
66
}
67
$is_not_a_corner=$ifcount1;
68
$is_a_corner=$ifcount1+1;
69
70
close $in1 or die "Can't close $filein: $!";
71
72
open($in1, "<", $filein) or die "Can't open $filein: $!";
73
74
75
$i1=1;
76
while (my $line1 = <$in1>)
77
{
78
chomp $line1;
79
if (($i1>=$myfirstline)&&($i1<=$mylastline))
80
{
81
if ($array0[$ifcount2] == $i1)
82
{
83
$array2[$ifcount2]=0;
84
$array3[$ifcount2]=0;
85
if ($array0[$ifcount2+1] == ($i1+1))
86
{
87
$array2[$ifcount2]=($ifcount2+1);
88
}
89
else
90
{
91
open(my $in2, "<", $filein) or die "Can't open $filein: $!";
92
$i2=1;
93
while (my $line2 = <$in2>)
94
{
95
chomp $line2;
96
if ($i2 == $i1)
97
{
98
last;
99
}
100
$i2++;
101
}
102
my $line2 = <$in2>;
103
chomp $line2;
104
if ($line2=~/goto (\w+)/)
105
{
106
$tmp=$1;
107
if ($tmp eq "is_not_a_corner")
108
{
109
$array2[$ifcount2]=$is_not_a_corner;
110
}
111
if ($tmp eq "is_a_corner")
112
{
113
$array2[$ifcount2]=$is_a_corner;
114
}
115
}
116
else
117
{
118
die "goto expected: $!";
119
}
120
close $in2 or die "Can't close $filein: $!";
121
}
122
#find next else and interpret it
123
open(my $in3, "<", $filein) or die "Can't open $filein: $!";
124
$i3=1;
125
$ifcount3=0;
126
$elsecount=0;
127
while (my $line3 = <$in3>)
128
{
129
chomp $line3;
130
$i3++;
131
if ($i3 == $i1)
132
{
133
last;
134
}
135
}
136
while (my $line3 = <$in3>)
137
{
138
chomp $line3;
139
$ifcount3++;
140
if (($elsecount==0)&&($i3>$i1))
141
{
142
if ($line3=~/goto (\w+)/)
143
{
144
$tmp=$1;
145
if ($tmp eq "is_not_a_corner")
146
{
147
$array3[$ifcount2]=$is_not_a_corner;
148
}
149
if ($tmp eq "is_a_corner")
150
{
151
$array3[$ifcount2]=$is_a_corner;
152
}
153
}
154
else
155
{
156
if ($line3=~/if\(ptr\[offset/)
157
{
158
$ifcount4=0;
159
while ($array0[$ifcount4]!=$i3)
160
{
161
$ifcount4++;
162
if ($ifcount4==$ifcount1)
163
{
164
die "if else match expected: $!";
165
}
166
$array3[$ifcount2]=$ifcount4;
167
}
168
}
169
else
170
{
171
die "elseif or elsegoto match expected: $!";
172
}
173
}
174
last;
175
}
176
else
177
{
178
if ($line3=~/if\(ptr\[offset/)
179
{
180
$elsecount++;
181
}
182
else
183
{
184
if ($line3=~/else/)
185
{
186
$elsecount--;
187
}
188
}
189
}
190
$i3++;
191
}
192
printf("%3d [%3d][0x%08x]\n", $array0[$ifcount2], $ifcount2, (($array1[$ifcount2]&15)<<28)|($array2[$ifcount2]<<16)|(($array1[$ifcount2]&128)<<5)|($array3[$ifcount2]));
193
close $in3 or die "Can't close $filein: $!";
194
$ifcount2++;
195
}
196
else
197
{
198
}
199
}
200
$i1++;
201
}
202
203
printf(" [%3d][0x%08x]\n", $is_not_a_corner, 254);
204
printf(" [%3d][0x%08x]\n", $is_a_corner, 255);
205
206
close $in1 or die "Can't close $filein: $!";
207
208
$ifcount0=0;
209
$ifcount2=0;
210
printf $out " static const unsigned long %s[] = {\n ", $tablename;
211
while ($ifcount0 < $ifcount1)
212
{
213
printf $out "0x%08x, ", (($array1[$ifcount0]&15)<<28)|($array2[$ifcount0]<<16)|(($array1[$ifcount0]&128)<<5)|($array3[$ifcount0]);
214
215
$ifcount0++;
216
$ifcount2++;
217
if ($ifcount2==8)
218
{
219
$ifcount2=0;
220
printf $out "\n";
221
printf $out " ";
222
}
223
224
}
225
printf $out "0x%08x, ", 254;
226
$ifcount0++;
227
$ifcount2++;
228
if ($ifcount2==8)
229
{
230
$ifcount2=0;
231
printf $out "\n";
232
printf $out " ";
233
}
234
printf $out "0x%08x\n", 255;
235
$ifcount0++;
236
$ifcount2++;
237
printf $out " };\n\n";
238
239
$#array0 = -1;
240
$#array1 = -1;
241
$#array2 = -1;
242
$#array3 = -1;
243
244
close $out or die "Can't close $fileout: $!";
245
246