Skip to content

Commit

Permalink
Merge branch 'hotfix/2.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesw committed Oct 25, 2015
2 parents 20d6120 + e009aa3 commit 17a6cc2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
### Version 2.4.0
### Version 2.4.1

* Fixed memory leak in Pix.BinarizeOtsuAdaptiveThreshold, Pix.BinarizeSauvola, and Pix.BinarizeSauvolaTiled - [Issue 218](https://github.com/charlesw/tesseract/issues/218)

### Version 2.4.0

* Support for scaling images - [Issue 183](https://github.com/charlesw/tesseract/issues/183)
* Provide meaningful defaults for Pix.ConvertToGrayscale - [Issue 184](https://github.com/charlesw/tesseract/issues/184)
Expand Down
2 changes: 1 addition & 1 deletion build.proj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Version>2.4.0.0</Version>
<Version>2.4.1.0</Version>
<SourceDir>$(MSBuildProjectDirectory)\src</SourceDir>
<BuildDir>$(MSBuildProjectDirectory)\bin</BuildDir>
<ReleaseDir>$(MSBuildProjectDirectory)\release</ReleaseDir>
Expand Down
51 changes: 36 additions & 15 deletions src/Tesseract.Tests.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tesseract.Tests.Console
{
class Program
internal class Program
{
static void Main(string[] args)
private const int DefaultIterations = 10000;

public static void Main(string[] args)
{
System.Console.WriteLine("Is 64bit process: {0}", Environment.Is64BitProcess);

try {
var testFixture = new Tesseract.Tests.EngineTests();
testFixture.Initialise_CanLoadConfigFile();
} catch (Exception e) {
System.Console.WriteLine("Unhandled exception occured: \r\n{0}", e);
}
System.Console.WriteLine("Is 64bit process: {0}", Environment.Is64BitProcess);

try {
var program = new Program();

using (var pix = Pix.LoadFromFile("./phototest2.png")) {
// Convert RGB to grayscale (required for binarize operations).
using (Pix grayPix = pix.Depth == 32 ? pix.ConvertRGBToGray() : pix.Clone()) {
//program.MemoryLeakDetector(grayPix, tempPix => tempPix.BinarizeSauvolaTiled(50, 0.35f, 8, 8));
//program.MemoryLeakDetector(grayPix, tempPix => tempPix.BinarizeSauvola(50, 0.35f, true));
//program.MemoryLeakDetector(grayPix, tempPix => tempPix.BinarizeOtsuAdaptiveThreshold(50, 50, 5, 5, 0.1f));

// Test clone
program.MemoryLeakDetector(grayPix, tempPix => tempPix.Clone());
}
}
} catch (Exception e) {
System.Console.WriteLine("Unhandled exception occured: \r\n{0}", e);
}
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}

public void MemoryLeakDetector(Pix pix, Func<Pix, Pix> op, int iterations = DefaultIterations)
{
for (int i = 0; i < iterations; i++) {
using (Pix result = op(pix)) {
//using (Pix binaryPix = grayPix.BinarizeOtsuAdaptiveThreshold(50, 50, 5, 5, 0.1f)) {
System.Console.WriteLine("Memory: {0} MB", System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024));
}

GC.Collect();
}
}
}
}
}
10 changes: 10 additions & 0 deletions src/Tesseract.Tests.Console/Tesseract.Tests.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -79,6 +80,15 @@
<Project>{abf7dbf7-2358-47c5-9e42-6f1c04e658a5}</Project>
<Name>Tesseract.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Tesseract\Tesseract.csproj">
<Project>{da780ca0-2606-4259-91c4-3f38c5c90592}</Project>
<Name>Tesseract</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="phototest2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Binary file added src/Tesseract.Tests.Console/phototest2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/Tesseract/Pix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public Pix BinarizeOtsuAdaptiveThreshold(int sx, int sy, int smoothx, int smooth

if (ppixth != IntPtr.Zero) {
// free memory held by ppixth, an array of threshold values found for each tile
Interop.LeptonicaApi.Native.pixaDestroy(ref ppixth);
Interop.LeptonicaApi.Native.pixDestroy(ref ppixth);
}

if (result == 1) throw new TesseractException("Failed to binarize image.");
Expand Down Expand Up @@ -366,15 +366,15 @@ public Pix BinarizeSauvola(int whsize, float factor, bool addborder)
// Free memory held by other unused pix's

if (ppixm != IntPtr.Zero) {
Interop.LeptonicaApi.Native.pixaDestroy(ref ppixm);
Interop.LeptonicaApi.Native.pixDestroy(ref ppixm);
}

if (ppixsd != IntPtr.Zero) {
Interop.LeptonicaApi.Native.pixaDestroy(ref ppixsd);
Interop.LeptonicaApi.Native.pixDestroy(ref ppixsd);
}

if (ppixth != IntPtr.Zero) {
Interop.LeptonicaApi.Native.pixaDestroy(ref ppixth);
Interop.LeptonicaApi.Native.pixDestroy(ref ppixth);
}

if (result == 1) throw new TesseractException("Failed to binarize image.");
Expand Down Expand Up @@ -415,7 +415,7 @@ public Pix BinarizeSauvolaTiled(int whsize, float factor, int nx, int ny)

// Free memory held by other unused pix's
if (ppixth != IntPtr.Zero) {
Interop.LeptonicaApi.Native.pixaDestroy(ref ppixth);
Interop.LeptonicaApi.Native.pixDestroy(ref ppixth);
}

if (result == 1) throw new TesseractException("Failed to binarize image.");
Expand Down

0 comments on commit 17a6cc2

Please sign in to comment.