Skip to content

Commit

Permalink
Add support for Tesseract 4: invert images and compile as C++11
Browse files Browse the repository at this point in the history
This contains the following PRs:
- ruediger#72 by bit: Fix compile with gcc7 and tesseract 4
- ruediger#75 by oltodosel: inverting images for tesseract 4
  • Loading branch information
Geoffrey-A committed Jun 21, 2020
1 parent 0ba6e25 commit 3a10420
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ include(CheckCXXSourceCompiles)
include(CheckCXXSourceRuns)

set(CMAKE_C_FLAGS "-std=gnu99")
set(CMAKE_CXX_FLAGS "-ansi -pedantic -Wall -Wextra -Wno-long-long")
set(CMAKE_CXX_FLAGS "-ansi -pedantic -Wall -Wextra -Wno-long-long -std=gnu++11")

set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mtune=native -march=native -DNDEBUG -fomit-frame-pointer -ffast-math") # TODO -Ofast GCC 4.6
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
Expand Down
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;
unsigned char* image_rev = new unsigned char[size_r];
for (int i = 0; i < size_r; i++)
{
int val = static_cast<int>(image[i]);
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

0 comments on commit 3a10420

Please sign in to comment.