Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@ include(CheckCXXCompilerFlag)
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 -DINVERT_IMAGES")

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})
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -DDEBUG")
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
# TODO RelWithDebInfo MinSizeRel? maybe move -march=native -ffast-math etc. to a different build type

find_package(Threads)
Expand Down
25 changes: 25 additions & 0 deletions src/vobsub2srt.c++
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ using namespace tesseract;
#define TESSERACT_DATA_PATH TESSERACT_DEFAULT_PATH
#endif

struct ImageInverter {
ImageInverter(const unsigned char* image, size_t image_size)
: inverted_image(new unsigned char[image_size])
{
for (size_t i = 0; i < image_size; ++i) {
inverted_image[i] = 255 - image[i];
}
}
~ImageInverter() { delete[] inverted_image; }

unsigned char* inverted_image;
};

int main(int argc, char **argv) {
bool dump_images = false;
bool verb = false;
Expand Down Expand Up @@ -265,6 +278,18 @@ 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

#ifdef INVERT_IMAGES

ImageInverter inverter(image, width*height);
image = inverter.inverted_image;

#endif // INVERT_IMAGES

if(dump_images) {
dump_pgm(subname, sub_counter, width, height, stride, image, image_size);
}
Expand Down