Skip to content

Commit

Permalink
Build leptonica with PNG and TIFF. Fix a crash in tesseract LSTM mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
emgucv committed Feb 25, 2017
1 parent fc72cf7 commit fe51346
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Emgu.CV.Example/OCR/OCRForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class OCRForm : Form
public OCRForm()
{
InitializeComponent();
InitOcr("", "eng", OcrEngineMode.TesseractOnly);
InitOcr("", "eng", OcrEngineMode.TesseractLstmCombined);
ocrOptionsComboBox.SelectedIndex = 0;

Mat img = new Mat(200, 400, DepthType.Cv8U, 3); //Create a 3 channel image of 400x200
Expand Down
15 changes: 15 additions & 0 deletions Emgu.CV.Extern/tesseract/libtesseract/leptonica/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ ELSEIF(IOS OR APPLE)
add_definitions(-DOS_IOS)
ENDIF()

MESSAGE(STATUS "leptonica HAVE_LIBPNG: ${BUILD_PNG}")
if(BUILD_PNG)
add_definitions(-DHAVE_LIBPNG)
#add_definitions(${PNG_DEFINITIONS})
include_directories(${OPENCV_SUBFOLDER}/3rdparty/libpng)
endif()

MESSAGE(STATUS "leptonica HAVE_LIBTIFF: ${BUILD_TIFF}")
if(BUILD_TIFF)
add_definitions(-DHAVE_LIBTIFF)
#add_definitions(${PNG_DEFINITIONS})
include_directories(${OPENCV_SUBFOLDER}/3rdparty/libtiff)
endif()


add_library(${the_target} STATIC ${lepton_srcs} ${lepton_hdrs})

IF(DEFINED EMGUCV_PLATFORM_TOOLSET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ typedef uintptr_t l_uintptr_t;
*/
#if !defined(HAVE_CONFIG_H) && !defined(ANDROID_BUILD) && !defined(OS_IOS)
#define HAVE_LIBJPEG 0
#define HAVE_LIBTIFF 0
#define HAVE_LIBPNG 0
//#define HAVE_LIBTIFF 0
//#define HAVE_LIBPNG 0
#define HAVE_LIBZ 0
#define HAVE_LIBGIF 0
#define HAVE_LIBUNGIF 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ l_int32 ret;
remove(realpath);
LEPT_FREE(realpath);
}
#elif (defined WINAPI_FAMILY) && (defined WINAPI_PARTITION_APP)
#elif (defined WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) /* windows but not desktop environment */
ret = -1;
#else
srcpath = genPathname(dir, srctail);
Expand Down Expand Up @@ -2938,7 +2938,7 @@ char dirname[240];
close(fd);
return pattern;
}
#elif (defined WINAPI_FAMILY) && (defined WINAPI_PARTITION_APP)
#elif (defined WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) /* windows but not desktop environment */
return (char *)ERROR_PTR("makeTempFilename failed", procName, NULL);
#else
{
Expand Down
13 changes: 13 additions & 0 deletions Emgu.CV.OCR/TessResultRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@

namespace Emgu.CV.OCR
{
/// <summary>
/// Interface to the TesseractResultRender
/// </summary>
public interface ITessResultRenderer
{
/// <summary>
/// Pointer to the unmanaged TessResultRendered
/// </summary>
IntPtr TessResultRendererPtr { get; }
}

Expand All @@ -35,12 +41,19 @@ public PDFRenderer(String outputBase, String dataDir, bool textOnly)
}
}

/// <summary>
/// Release the unmanaged memory associated with this Renderer
/// </summary>
protected override void DisposeObject()
{
if (IntPtr.Zero != _ptr)
OcrInvoke.TessPDFRendererRelease(ref _ptr);
_tessResultRendererPtr = IntPtr.Zero;
}

/// <summary>
/// Pointer to the unmanaged TessResultRendered
/// </summary>
public IntPtr TessResultRendererPtr
{
get
Expand Down
3 changes: 2 additions & 1 deletion Emgu.CV.Test/AutoTestOcr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void TestOCREngGrayText()
using (PDFRenderer pdfRenderer = new PDFRenderer("abc.pdf", "./", false))
using (Pix imgPix = new Pix(img.Mat))
{
ocr.ProcessPage(imgPix, 1, "img", null, 100000, pdfRenderer);
bool success =ocr.ProcessPage(imgPix, 1, "img", null, 100000, pdfRenderer);
EmguAssert.IsTrue(success, "failed to export pdf");
}


Expand Down
1 change: 1 addition & 0 deletions Emgu.CV.Test/AutoTestVarious.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3264,6 +3264,7 @@ public void TestDnnBvlcGoogleNet()

}


[Test]
public void TestDnnTensorFlow()
{
Expand Down

0 comments on commit fe51346

Please sign in to comment.