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