Skip to content

Commit

Permalink
Merge branch 'release/1.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesw committed Jun 22, 2014
2 parents eace964 + 999b2cd commit 3aec396
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,4 @@ pip-log.txt
/src/AssemblyVersionInfo.cs

/*.Log
*.sdsettings
2 changes: 1 addition & 1 deletion Samples/Tesseract.ConsoleDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void Main(string[] args)

private class ResultPrinter
{
private FormattedConsoleLogger logger;
readonly FormattedConsoleLogger logger;

public ResultPrinter(FormattedConsoleLogger logger)
{
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tesseract.WebDemo/Default.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void OnSubmitFileClicked(object sender, EventArgs args)
{
// for now just fail hard if there's any error however in a propper app I would expect a full demo.

using (var engine = new TesseractEngine(Server.MapPath(@"./tessdata"), "eng", EngineMode.Default))
using (var engine = new TesseractEngine(Server.MapPath(@"~/tessdata"), "eng", EngineMode.Default))
{
// have to load Pix via a bitmap since Pix doesn't support loading a stream.
using (var image = new System.Drawing.Bitmap(imageFile.PostedFile.InputStream))
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>1.0.10</Version>
<Version>1.0.11</Version>
<SourceDir>$(MSBuildProjectDirectory)\src</SourceDir>
<BuildDir>$(MSBuildProjectDirectory)\bin</BuildDir>
<ReleaseDir>$(MSBuildProjectDirectory)\release</ReleaseDir>
Expand Down
25 changes: 25 additions & 0 deletions src/Tesseract.Tests/EngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ public void CanParseText()
}
}
}

[Test]
public void CanParseDifferentRegionsInSameImage()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using(var img = Pix.LoadFromFile("./phototest.tif")) {
using(var page = engine.Process(img, Rect.FromCoords(0, 0, img.Width, 188))) {
var region1Text = page.GetText();

const string expectedTextRegion1 =
"This is a lot of 12 point text to test the\nocr code and see if it works on all types\nof file format.\n\n";

Assert.That(region1Text, Is.EqualTo(expectedTextRegion1));

page.RegionOfInterest = Rect.FromCoords(0, 188, img.Width, img.Height);

var region2Text = page.GetText();
const string expectedTextRegion2 =
"The quick brown dog jumped over the\nlazy fox. The quick brown dog jumped\nover the lazy fox. The quick brown dog\njumped over the lazy fox. The quick\nbrown dog jumped over the lazy fox.\n\n";

Assert.That(region2Text, Is.EqualTo(expectedTextRegion2));
}
}
}
}

[Test]
public void CanParseUznFile()
Expand Down
7 changes: 6 additions & 1 deletion src/Tesseract/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Version 1.10

* Added support for uzn files - [Issue 66](https://github.com/charlesw/tesseract/issues/66)
* Added support for uzn files - [Issue 66](https://github.com/charlesw/tesseract/issues/66)

### Version 1.11

* Allow changing the current region of interest without having to reload the entire image (Page.RegionOfInterest)
* Fixed loader for ASP.NET [Issue 97](https://github.com/charlesw/tesseract/issues/97)
2 changes: 1 addition & 1 deletion src/Tesseract/Interop/WindowsLibraryLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void LoadLibrary(string dllName)
#if !ClientProfile
if(HttpContext.Current != null) {
var server = HttpContext.Current.Server;
baseDirectory = Path.GetFullPath(server.MapPath("bin"));
baseDirectory = Path.GetFullPath(server.MapPath("~/bin"));
dllHandle = LoadLibraryInternal(dllName, baseDirectory, processArch);
if (dllHandle != IntPtr.Zero) return;
}
Expand Down
33 changes: 30 additions & 3 deletions src/Tesseract/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@ namespace Tesseract
public sealed class Page : DisposableBase
{
private bool runRecognitionPhase;

private Rect regionOfInterest;


public TesseractEngine Engine { get; private set; }
public Pix Image { get; private set; }

internal Page(TesseractEngine engine)
internal Page(TesseractEngine engine, Pix image, Rect regionOfInterest)
{
Engine = engine;
Image = image;
RegionOfInterest = regionOfInterest;
}


/// <summary>
/// The current region of interest being parsed.
/// </summary>
public Rect RegionOfInterest {
get {
return regionOfInterest;
}
set {
if (value.X1 < 0 || value.Y1 < 0 || value.X2 > Image.Width || value.Y2 > Image.Height)
throw new ArgumentException("The region of interest to be processed must be within the image bounds.", "value");

if(regionOfInterest != value) {
regionOfInterest = value;

// update region of interest in image
Interop.TessApi.BaseApiSetRectangle(Engine.Handle, regionOfInterest.X1, regionOfInterest.Y1, regionOfInterest.Width, regionOfInterest.Height);

// request rerun of recognition on the next call that requires recognition
runRecognitionPhase = true;
}
}
}

public PageIterator AnalyseLayout()
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tesseract/TesseractEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,10 @@ public Page Process(Pix image, string inputName, Rect region, PageSegMode? pageS

Interop.TessApi.BaseAPISetPageSegMode(handle, pageSegMode.HasValue ? pageSegMode.Value : DefaultPageSegMode);
Interop.TessApi.BaseApiSetImage(handle, image.Handle);
Interop.TessApi.BaseApiSetRectangle(handle, region.X1, region.Y1, region.Width, region.Height);
if(!String.IsNullOrEmpty(inputName)) {
Interop.TessApi.BaseApiSetInputName(handle, inputName);
}
var page = new Page(this);
var page = new Page(this, image, region);
page.Disposed += OnIteratorDisposed;
return page;
}
Expand Down

0 comments on commit 3aec396

Please sign in to comment.