forked from tesseract-ocr/tesseract
-
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.
added example code from tesseract-ocr#4070 : GetGradient()
- Loading branch information
1 parent
c1d030a
commit 593aa26
Showing
1 changed file
with
58 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,58 @@ | ||
// example as part of https://github.com/tesseract-ocr/tesseract/pull/4070 | ||
|
||
#include <allheaders.h> | ||
#include <tesseract/baseapi.h> | ||
|
||
|
||
#if defined(BUILD_MONOLITHIC) | ||
# define main tesseract_get_page_gradient_main | ||
|
||
# ifdef __cplusplus | ||
extern "C" { | ||
# endif | ||
|
||
int main(int argc, const char **argv); | ||
|
||
# ifdef __cplusplus | ||
} | ||
# endif | ||
|
||
#endif | ||
|
||
int main(int argc, const char **argv) { | ||
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); | ||
// Initialize tesseract-ocr with English, without specifying tessdata path | ||
if (api->InitSimple(NULL, "eng")) { | ||
fprintf(stderr, "Could not initialize tesseract.\n"); | ||
return 1; | ||
} | ||
|
||
// Open input image with leptonica library | ||
std::string filepath; | ||
if (argc > 1 && argv[1] != nullptr) { | ||
filepath = argv[1]; | ||
} | ||
if (filepath.empty()) { | ||
filepath = "rotate_image.png"; | ||
} | ||
Pix *image = pixRead(filepath.c_str()); | ||
if (!image) { | ||
fprintf(stderr, "Could not open image file: %s\n", filepath.c_str()); | ||
return 1; | ||
} | ||
|
||
api->SetImage(image); | ||
|
||
// Find lines, get average gradient | ||
api->AnalyseLayout(); | ||
float gradient = api->GetGradient(); | ||
|
||
printf("Average Gradient: %f\n", gradient); | ||
|
||
// Destroy used object and release memory | ||
api->End(); | ||
delete api; | ||
pixDestroy(&image); | ||
|
||
return 0; | ||
} |