Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, February 18, 2008 11:19:27 AM(UTC)
beckstev

Groups: Registered
Posts: 5


Hi,
I need a little help with this one. I'm running C# / VS 2008 with version 15 of the toolkit. I'm created non-automated hilite annotations on a TIF image after recognizing text and it associated postion on the image. That works fine and the hilite show up where they are suppose to go. However, when I scroll to view more of the image the hilite annotations do not stay where they were originally added.
I'm using an AnnContainer object and am overriding the OnPostImagePaint event in the viewer control to draw the annotations.
Any thoughts?

Thanks
beckstev

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Monday, February 18, 2008 11:12:46 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

Can you please provide me with a code snippet that shows how exactly are you creating the hilite annotations on the image?

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Tuesday, February 19, 2008 3:34:41 AM(UTC)
beckstev

Groups: Registered
Posts: 5


Maen,
Thanks for the response. I have a user control with a panel control on that. I dynamically create the OcrRasterImageViewer()control and add it to the panel control. The following code in the user control load event is where I set everything up:

private void OCRDemoIndexView_Load(object sender, EventArgs e)
{
try
{
// Set internal variables
mainWorkItem = (MainWorkItem)parentWorkItem;
btConfigHashTable = mainWorkItem.BTConfigHashTable;
btiSeriesDataConn = mainWorkItem.BTISeriesDataConn;
btISeriesApp.BTISeriesDataConn = btiSeriesDataConn;
btISeriesApp.BTDefaultServer = (String)mainWorkItem.BTConfigHashTable["BTSettingsDefaultServer"];

// Initialize Data Entry Fields for fresh start
BTOCRDemoRestart();

Messager.Caption = "BrownTech Optical Character Recognition Demo";
Text = Messager.Caption;
_xRes = 300;
_yRes = 300;
Support.Unlock(false);

RasterCodecs.Startup();
_codecs = new RasterCodecs();

_ocrStarted = false;
_pageAdded = false;
_pageRecognized = false;
_charsUpdated = false;

_viewer = new OcrRasterImageViewer();
_viewer.BackColor = Color.AntiqueWhite;
_viewer.Dock = DockStyle.Fill;
_viewer.AutoScroll = true;
_viewer.DoubleBuffer = true;
panel1.Controls.Add(_viewer);

_viewer.BringToFront();
_viewer.MouseDraw = false;

using ( WaitCursor wait = new WaitCursor())
{
if (RasterSupport.IsLocked(RasterSupportType.Ocr))
{
Messager.ShowError(this, "You need to unlock the OCR engine before you can use this demo!");
return;
}

_rasterEngine = RasterDocumentEngine.Instance;
try
{
_rasterEngine.Startup();
_rasterLanguage[0] = RasterDocumentLanguage.English;
_rasterEngine.SelectLanguages(_rasterLanguage);

}
catch (Exception ex)
{
// check if the OCR engine could be initialized
bool showEngine = false;

if (ex is RasterDocumentException)
{
RasterDocumentException oe = ex as RasterDocumentException;
if (oe.Code == RasterDocumentExceptionCode.InitializeEngine)
showEngine = true;
}

if (showEngine)
new EngineDialog().ShowDialog(this);
else
MessageBox.Show(ex.Message);
return;
}

try
{
RasterDocumentDrawZoneOptions drawOpts = _rasterEngine.DrawZoneOptions;

// Set Zone Drawing Options and Colors
_zonePen = new Pen(Color.Blue, 2);
_zonePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
drawOpts.Pen = _zonePen;

_selzonePen = new Pen(Color.Blue, 2);
_selzonePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
drawOpts.SelectedPen = _selzonePen;
_rasterEngine.DrawZoneOptions = drawOpts;
_viewer.RasterEngine = _rasterEngine;

_ocrStarted = true;
}
catch (Exception ex)
{
Messager.ShowError(this, ex.Message);
}

_imagesKeyValue = DemosGlobal.ImagesFolder;
}

}
catch (Exception ex)
{

bool rethrow = ExceptionPolicy.HandleException(ex, "Global Policy");

if (rethrow)
{
throw;
}
}
}

The user will open an image using a command button and I setup up basic OCR capability as follows:

loader.LoadOnlyOnePage = true;
if (loader.Load(this, _codecs, true))
{
_viewer.OcrMode = false;
_viewer.DrawPage = false;

if (_viewer.Image != null)
_viewer.Image.Dispose();

ResetActivePage();
_viewer.Image = loader.Image;

if (_viewer.Image != null)
// Check to see if OCR was successfully started
if (_ocrStarted)
{

// Add Page to OCR Engine for Processing
_viewer.RasterEngine.AddPage(_viewer.Image, -1);
_pageAdded = true;
UpdateView();
//RefreshPictureBox();


// Prep Annotations
_viewer.AnnContainerObject = new AnnContainer();
_viewer.AnnContainerObject.Bounds = new AnnRectangle(0, 0, _viewer.ImageSize.Width, _viewer.ImageSize.Height, AnnUnit.Pixel);
_viewer.AnnContainerObject.Name = "Container";
_viewer.AnnContainerObject.Visible = true;
_viewer.AnnContainerObject.UnitConverter = new AnnUnitConverter(96, 96);

// Enable recongnize button
ultraButtonRecognize.Enabled = true;

return true;
}
else
{
return false;
}
else
{
return false;
}

}

Finally, I have a command button that I use to recognize a user enterable string and then hilite all the hits on the iamge. Its here that I add the annotations to the container.

private void ultraButtonRecognize_Click(object sender, EventArgs e)
{
// Declare local variables
Int32 iRecogWordCount = 0;
String sRDFFileName = "";
List alAnnotations = new List();

// Prompt for a file name and path to store the RDF File
// sRDFFileName = DemosGlobal.GetOcrOutputFileName(this, "RDF files (*.rdf)|*.rdf");
sRDFFileName = "c:\\dude.rdf";
if (sRDFFileName == "")
{
return;
}

// Initialize OCR Settings
_viewer.RasterEngine.EnableZoneForceSingleColumn = true;
_viewer.RasterEngine.ShowZoneGridlines = true;
_viewer.RasterEngine.FindZones(0, Rectangle.Empty);

_viewer.RasterEngine.SpellLanguageId = RasterDocumentLanguage.English;
_viewer.RasterEngine.EnableSubsystem = true;
_viewer.RasterEngine.EnableCorrection = true;

_viewer.RasterEngine.RecognitionDataFileName = sRDFFileName;

// Delete recognition file if it exists so we can reuse it.
if (File.Exists(sRDFFileName))
{
File.Delete(sRDFFileName);
}

// Recognize the first page in the document
_viewer.RasterEngine.Recognize(0, 1, null);

// Get list of recongized words for the first page
IList liRasterOcrRecognizedWords = _viewer.RasterEngine.GetRecognizedWords(0);

for (int i = 0; i 0)
{

// Load up an array of AnnHiliteObjects
for (int k = 0; k < iRecogWordCount; k++)
{
alAnnotations.Add(new AnnHiliteObject());
}

iRecogWordCount = 0;

// Highlight each recognized word
for (int j = 0; j < liRasterOcrRecognizedWords.Count - 1; j++)
{
if (liRasterOcrRecognizedWords[j].Word == ultraTextEditorOCRSearchString.Text)
{
alAnnotations[iRecogWordCount].Bounds = new AnnRectangle(liRasterOcrRecognizedWords[j].WordArea.Left, liRasterOcrRecognizedWords[j].WordArea.Top, liRasterOcrRecognizedWords[j].WordArea.Width, liRasterOcrRecognizedWords[j].WordArea.Height, AnnUnit.Pixel);
alAnnotations[iRecogWordCount].HiliteColor = Color.Yellow;
_viewer.AnnContainerObject.Objects.Add((AnnHiliteObject)alAnnotations[iRecogWordCount]);
_viewer.Refresh();
iRecogWordCount++;
}
}

// Test Annotation
// create Annotation Note Object and add it to the container
// annContainerObj.Objects.Add(CreateAnnNoteObject(new AnnRectangle(annContainerObj.Bounds.Right / 2, annContainerObj.Bounds.Bottom / 2, (annContainerObj.Bounds.Right / 4) - 1, (annContainerObj.Bounds.Bottom / 4) - 1)));
}
else
{
BTUtilities.BTMessageBox("The entered OCR Search String was not found on this page of the document.", MessageBoxButtons.OK);
ultraTextEditorOCRSearchString.Focus();
}


}

I have overridden the OnPostImagePaint and OnTransformChanged events in the OCRRasterImageViewer control as follows:

protected override void OnPostImagePaint(PaintEventArgs e)
{
if (annContainerObj != null)
annContainerObj.Draw(e.Graphics);

}

protected override void OnTransformChanged(EventArgs e)
{
if (annContainerObj != null)
annContainerObj.Transform.Clone();

}


Thanks

Beckstev

protected override void OnPostImagePaint(PaintEventArgs e)
{
if (annContainerObj != null)
annContainerObj.Draw(e.Graphics);

}

protected override void OnTransformChanged(EventArgs e)
{
if (annContainerObj != null)
annContainerObj.Transform.Clone();

}

 
#4 Posted : Tuesday, February 19, 2008 10:43:07 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

It seems you are trying to add highlight objects and use them in the same project with our OCR engine. I couldn't figure out from the code where the problem might be, but there is a demo that uses LEADTOOLS .NET 15 highlight annotations and OCR together. Please take a look at this forum post and see if it helps you:
http://support.leadtools.com/SupportPortal/cs/forums/16032/ShowPost.aspx#16032

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#5 Posted : Wednesday, February 20, 2008 6:07:20 AM(UTC)
beckstev

Groups: Registered
Posts: 5


Maen,
I used this project as a base already. Any suggestions?

Thanks

beckstev
 
#6 Posted : Wednesday, February 20, 2008 10:17:34 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

Can you please enclose your code in a small working project and send it to me, so that I can check this issue on my side?

When you want to attach any files, please put them all in ZIP or RAR file. Also, don't use preview when you have attachment.
If you have any problem in attaching files to the forum, you can send the files in a ZIP of RAR file to support@leadtools.com. Don't forget to mention this forum post in your email to support.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.150 seconds.