Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/vobsub2srt.c++
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

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

unsigned char* image_rev = new unsigned char[size_r];
Copy link
Owner

Choose a reason for hiding this comment

The 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++)
{
Copy link
Owner

Choose a reason for hiding this comment

The 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]);
Copy link
Owner

Choose a reason for hiding this comment

The 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);
}
Expand Down