-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from x4base/master
使用tesseract做初步的OCR
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
if (!isset($argv[1])) { | ||
echo 'please supply image file name'; | ||
exit(1); | ||
} | ||
|
||
$imgFn = $argv[1]; | ||
$tmpFileBase = '/tmp/amisOcrGuess'; | ||
$tmpFile = $tmpFileBase . ".txt"; | ||
|
||
function getOcr($lang) | ||
{ | ||
global $imgFn, $tmpFileBase, $tmpFile; | ||
|
||
$cmd = 'tesseract "' . $imgFn . '" "' . $tmpFileBase . '" -l ' . $lang . ' 2>&1 > /dev/null'; | ||
exec($cmd); | ||
$ocr = file_get_contents($tmpFile); | ||
$ocr = trim($ocr); | ||
|
||
return $ocr; | ||
} | ||
|
||
preg_match('/([0-9]{3})_([0-9]{3}).jpg/', $imgFn, $matches); | ||
if (!$matches) { | ||
die('wrong format of the image file name '); | ||
} | ||
$p = $matches[1]; | ||
$line = $matches[2]; | ||
|
||
$ocrEng = getOcr('eng'); | ||
$ocrCht = getOcr('chi_tra'); | ||
|
||
$pdo = new PDO("sqlite:toufu.sq3"); | ||
$st = $pdo->prepare("UPDATE toufu SET ocr_eng=:eng, ocr_cht=:cht WHERE p=:p AND line=:line "); | ||
$st->execute(array( | ||
'eng' => $ocrEng, | ||
'cht' => $ocrCht, | ||
'p' => $p, | ||
'line' => $line | ||
)); | ||
|
||
echo "$p $line \n"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
body { | ||
padding-top: 20px; | ||
} | ||
|
||
.ocr_block{ | ||
float: left; | ||
margin: 10px | ||
} | ||
|
||
.ocr_block textarea{ | ||
width: 400px; | ||
height: 130px; | ||
} |