Last active
October 11, 2015 10:28
-
-
Save windytan/3844771 to your computer and use it in GitHub Desktop.
Perl script to read an image of digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use feature "switch"; | |
open(S,"convert bitit.png gray:-|"); | |
for $y (0..434) { | |
for $x (0..699) { | |
read(S,$a,1); | |
$b[int($x / 27)][int($y / 27)] ++ if (ord($a) < 127); | |
} | |
} | |
close(S); | |
for $y (0..15) { | |
$byte = 0; | |
for $x (0..25) { | |
$byte <<= 1; | |
given ($b[$x][$y] // 0) { | |
when ($_ < 10) { print " "; } | |
when ($_ < 90) { print "1 "; $byte++; } | |
default { print "0 "; } | |
} | |
} | |
printf (" 0x%07x\n",$byte); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment