-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inverting images for tesseract 4 #75
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,6 +265,25 @@ int main(int argc, char **argv) { | |
<< start_pts << ")\n"; | ||
} | ||
|
||
|
||
// While tesseract version 3.05 (and older) handle inverted image (dark background and light text) without problem, for 4.x version use dark text on light background. | ||
// https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality#inverting-images | ||
|
||
bool inverting_images = true; | ||
|
||
if (inverting_images) { | ||
int size_r = width * height; | ||
unsigned char* image_rev = new unsigned char[size_r]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You never free that pointer. |
||
for (int i = 0; i < size_r; i++) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the bracket placement is inconsistent with the rest of the file |
||
int val = static_cast<int>(image[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the cast? |
||
unsigned char cz = (255 - val); | ||
image_rev[i] = cz; | ||
} | ||
|
||
image = image_rev; | ||
} | ||
|
||
if(dump_images) { | ||
dump_pgm(subname, sub_counter, width, height, stride, image, image_size); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be size_t. Probably size_t const