Created
September 23, 2019 13:59
-
-
Save adenkiewicz/a3ca3cb339c5aa3a47cd4eb9a5c47a23 to your computer and use it in GitHub Desktop.
Simple test script for CQExtractor module and OCR quality
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
Import-Module .\CQExtractor.psm1 -Force | |
$score = 0 | |
$arr = New-Object system.collections.hashtable | |
$arr["l"] = ".A" | |
$arr["1"] = ".B" | |
$arr["L"] = ".C" | |
$arr["i"] = ".D" | |
$arr["I"] = ".E" | |
$arr["o"] = ".F" | |
$arr["O"] = ".G" | |
$arr["0"] = ".H" | |
$arr["w"] = ".J" | |
$arr["W"] = ".K" | |
$arr["="] = ".Q" | |
$total = Get-Content .\test.txt | Measure-Object -Line | |
foreach ($line in Get-Content .\test.txt) { | |
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($line) | |
$orig = $tc = [Convert]::ToBase64String($Bytes) | |
foreach ($key in $arr.Keys) { | |
$tc = $tc.Replace($key,$arr["$key"]) | |
} | |
$tc | Export-StringToPng -Path test.png | |
$result = (Export-PngToString -Path test.png).text | |
foreach ($key in $arr.Keys) { | |
$result = $result.Replace($arr["$key"],$key) | |
} | |
$decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result)) | |
if ($line -ne $decoded) { | |
Write-Warning "Mismatch: `n$tc ($orig) vs $result" | |
} | |
else { | |
$score = $score + 1 | |
} | |
} | |
"Scored: {0}/{1}" -f $score, $total.lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment