Skip to content

Instantly share code, notes, and snippets.

@wincentbalin
Last active March 20, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wincentbalin/446c5523ec229c8331cef2c907dcd69e to your computer and use it in GitHub Desktop.
Save wincentbalin/446c5523ec229c8331cef2c907dcd69e to your computer and use it in GitHub Desktop.
Attempt to compile static binaries for qt-box-editor using MXE
#!/bin/sh
#
# Compile qt-box-editor for win32
# Set amount of MXE parallel compiling jobs
if [ "$JOBS" = "" ]
then
JOBS=1
export JOBS
fi
# Set MXE path
if [ "$MXE" = "" ]
then
MXE=/opt/mxe
export MXE
fi
# Check MXE path
if [ ! -d "$MXE" ]
then
echo MXE not found in $MXE
echo Please set the variable $MXE to the path of MXE!
exit 1
fi
# Set up MXE win32 compilation
PATH=$MXE/usr/bin:$PATH
export PATH
CROSS_ARCH=i686-w64-mingw32.static
export CROSS_ARCH
# Go to MXE directory and compile the dependencies
(
echo Compiling or updating dependencies... && \
cd "$MXE" && \
make MXE_TARGETS=$CROSS_ARCH JOBS=$JOBS cc pthreads zlib giflib jpeg libpng openjpeg tiff libwebp icu4c cairo pango qt
)
# Set versions of packages to be compiled
LEPTONICA_VERSION=1.75.3
TESSERACT_VERSION=3.05.01
QT_BOX_EDITOR_VERSION=1.11
# Compile Leptonica
if [ ! -d "leptonica-$LEPTONICA_VERSION" ]
then
echo Downloading Leptonica...
wget -q -O - https://github.com/DanBloomberg/leptonica/archive/$LEPTONICA_VERSION.tar.gz | tar zxvf -
fi
(
echo Compiling Leptonica... && \
cd leptonica-$LEPTONICA_VERSION && \
./autobuild && \
./configure --host=$CROSS_ARCH --prefix=$MXE/usr/$CROSS_ARCH --enable-static --disable-shared && \
make -j$JOBS && \
make install
)
# Compile Tesseract
if [ ! -d "tesseract-$TESSERACT_VERSION" ]
then
echo Downloading Tesseract...
wget -q -O - https://github.com/tesseract-ocr/tesseract/archive/$TESSERACT_VERSION.tar.gz | tar zxvf -
fi
(
echo Compiling Tesseract... && \
cd tesseract-$TESSERACT_VERSION && \
./autogen.sh && \
CPPFLAGS="-std=c++98 -O2 -DNDEBUG" ./configure --host=$CROSS_ARCH --prefix=$MXE/usr/$CROSS_ARCH --enable-static --disable-shared --disable-tessdata-prefix && \
make -j$JOBS && \
./configure --host=$CROSS_ARCH --prefix=$MXE/usr/$CROSS_ARCH --enable-static --disable-shared --disable-tessdata-prefix && \
make -j$JOBS training && \
make install && \
make training-install
)
# Compile qt-box-editor
if [ ! -d "qt-box-editor-$QT_BOX_EDITOR_VERSION" ]
then
echo Downloading qt-box-editor...
wget -q -O - https://github.com/zdenop/qt-box-editor/archive/v$QT_BOX_EDITOR_VERSION.tar.gz | tar zxvf -
fi
(
echo Compiling qt-box-editor... && \
cd qt-box-editor-$QT_BOX_EDITOR_VERSION && \
patch -p1 < ../qt-box-editor-mxe.patch && \
$MXE/usr/$CROSS_ARCH/qt/bin/qmake && \
make -j$JOBS && \
cp win32/qt-box-editor-$QT_BOX_EDITOR_VERSION.exe ..
)
--- qt-box-editor-1.11/qt-box-editor.pro.orig 2013-07-31 21:51:25.000000000 +0200
+++ qt-box-editor-1.11/qt-box-editor.pro 2018-03-19 01:27:13.923329731 +0100
@@ -58,7 +58,13 @@
resources/QBE-Oxygen.qrc \
resources/QBE-Tango.qrc
-LIBS += -llept -ltesseract
+LIBS += -ltesseract -llept -lwebp -lopenjp2 -lgif
+
+CONFIG(static) {
+ DEFINES += USE_STATIC
+ CONFIG += static_qt_plugins
+ QMAKE_LFLAGS *= -static -static-libstdc++ -static-libgcc
+}
win32: {
DESTDIR = ./win32
--- qt-box-editor-1.11/src/TessTools.cpp.orig 2013-07-31 21:51:25.000000000 +0200
+++ qt-box-editor-1.11/src/TessTools.cpp 2018-03-19 01:21:36.311329731 +0100
@@ -21,6 +21,8 @@
**********************************************************************/
#include <tesseract/strngs.h>
+#include "leptonica/allheaders.h"
+#include "tesseract/renderer.h"
#include <locale.h>
#include "TessTools.h"
#include "Settings.h"
@@ -98,19 +100,27 @@
}
api->SetVariable("tessedit_create_boxfile", "1");
- STRING text_out;
+ tesseract::TessResultRenderer *text_renderer = new tesseract::TessBoxTextRenderer(NULL);
QApplication::setOverrideCursor(Qt::WaitCursor);
- if (!api->ProcessPage(pixs, page, NULL, NULL, 0, &text_out)) {
+ if (!api->ProcessPage(pixs, page, NULL, NULL, 0, text_renderer)) {
msg("Error during processing.\n");
}
QApplication::restoreOverrideCursor();
+ char *data;
+ QString text_out;
+ if (data = api->GetBoxText(page)) {
+ text_out = QString::fromUtf8(data);
+ delete data;
+ }
+ delete text_renderer;
+
pixDestroy(&pixs);
api->End();
delete api;
- return QString::fromUtf8(text_out.string());
+ return text_out;
}
/*!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment