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

Make it compile on Debian 11, invert image for better recognition #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ project(vobsub2srt)

cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)

if(NOT CMAKE_BUILD_TYPE)
Expand Down
14 changes: 2 additions & 12 deletions CMakeModules/FindTesseract.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,8 @@ if(TESSERACT_DATA_PATH)
add_definitions(-DTESSERACT_DATA_PATH="${TESSERACT_DATA_PATH}")
endif()

set(CMAKE_REQUIRED_INCLUDES ${Tesseract_INCLUDE_DIR})
check_cxx_source_compiles(
"#include \"tesseract/baseapi.h\"
using namespace tesseract;
int main() {
}"
TESSERACT_NAMESPACE)
if(TESSERACT_NAMESPACE)
add_definitions("-DCONFIG_TESSERACT_NAMESPACE")
else()
message(WARNING "You are using an old Tesseract version. Support for Tesseract 2 is deprecated and will be removed in the future!")
endif()
add_definitions("-DCONFIG_TESSERACT_NAMESPACE")

list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${Tesseract_INCLUDE_DIR})

if(BUILD_STATIC)
Expand Down
16 changes: 16 additions & 0 deletions src/vobsub2srt.c++
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,22 @@ int main(int argc, char **argv) {
dump_pgm(subname, sub_counter, width, height, stride, image, image_size);
}

// for 4.x version use dark text on light background.
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;
}

#ifdef CONFIG_TESSERACT_NAMESPACE
char *text = tess_base_api.TesseractRect(image, 1, stride, 0, 0, width, height);
#else
Expand Down