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