forked from BurhanUlTayyab/GSOC2018_RedHen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Burhan Two
committed
Jun 17, 2018
1 parent
ea281de
commit dc8143f
Showing
2 changed files
with
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include <leptonica/allheaders.h> | ||
#include <tesseract/capi.h> | ||
|
||
void die(const char *errstr) { | ||
fputs(errstr, stderr); | ||
exit(1); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
TessBaseAPI *handle; | ||
PIX *img; | ||
char *text; | ||
|
||
if((img = pixRead("russian-text.png")) == NULL) | ||
die("Error reading image\n"); | ||
|
||
handle = TessBaseAPICreate(); | ||
if(TessBaseAPIInit3(handle, NULL, "rus") != 0) | ||
die("Error initialising tesseract\n"); | ||
|
||
TessBaseAPISetImage2(handle, img); | ||
if(TessBaseAPIRecognize(handle, NULL) != 0) | ||
die("Error in Tesseract recognition\n"); | ||
|
||
if((text = TessBaseAPIGetUTF8Text(handle)) == NULL) | ||
die("Error getting text\n"); | ||
|
||
fputs(text, stdout); | ||
|
||
TessDeleteText(text); | ||
TessBaseAPIEnd(handle); | ||
TessBaseAPIDelete(handle); | ||
pixDestroy(&img); | ||
|
||
return 0; | ||
} |
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,28 @@ | ||
#include <tesseract/baseapi.h> | ||
#include <leptonica/allheaders.h> | ||
|
||
int main() | ||
{ | ||
char *outText; | ||
|
||
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); | ||
// Initialize tesseract-ocr with English, without specifying tessdata path | ||
if (api->Init(NULL, "rus")) { | ||
fprintf(stderr, "Could not initialize tesseract.\n"); | ||
exit(1); | ||
} | ||
|
||
// Open input image with leptonica library | ||
Pix *image = pixRead("a.jpg"); | ||
api->SetImage(image); | ||
// Get OCR result | ||
outText = api->GetUTF8Text(); | ||
printf("OCR output:\n%s", outText); | ||
|
||
// Destroy used object and release memory | ||
api->End(); | ||
delete [] outText; | ||
pixDestroy(&image); | ||
|
||
return 0; | ||
} |