void CleanUp() { if (_ocrPage != null) { _ocrPage.Dispose(); _ocrPage = null; } if (_ocrEngine != null && _ocrEngine.IsStarted) { _ocrEngine.Shutdown(); _ocrEngine.Dispose(); } if (_codecs != null) { _codecs.Dispose(); } }
private void LoadUniqueFieldValueInstanceImages() { string zoneFile, sql, imageFile = "", imagePath; int page = 0, zoneID = 1; if (ocrPageZones != null) { ocrPageZones.Dispose(); ocrPageZones = null; } if (uniqueFieldValueRowNumber >= dataTableUniqueFieldValues.Rows.Count) { return; } OcrZone zone; LeadRect zoneRect; RasterImage pageImage = null, zoneImage; textBoxValue.Text = dataTableUniqueFieldValues.Rows[uniqueFieldValueRowNumber][0].ToString(); sql = "select Page, ZoneID from Field where Batch = '" + BatchName + "' and FieldID = " + fieldIndex.ToString() + " and (ValueAdvantage = '" + textBoxValue.Text.Replace("'", "''") + "') order by Page, Line"; oleDbCommand = new OleDbCommand(sql, oleDbConnection); oleDbDataAdapter = new OleDbDataAdapter(oleDbCommand); dataTableUniqueFieldValueInstances = new DataTable(); oleDbDataAdapter.Fill(dataTableUniqueFieldValueInstances); images = new List <RasterImage>(); foreach (DataRow instanceRow in dataTableUniqueFieldValueInstances.Rows) { zoneID = int.Parse(instanceRow["ZoneID"].ToString()); if (page != int.Parse(instanceRow[0].ToString())) { page = int.Parse(instanceRow[0].ToString()); sql = "select top 1 Srcfile from " + BatchTableName + " where Batch = '" + BatchName + "' and Page = " + page.ToString(); oleDbCommand = new OleDbCommand(sql, oleDbConnection); oleDbDataAdapter = new OleDbDataAdapter(oleDbCommand); DataTable dataTableSrcfile = new System.Data.DataTable(); oleDbDataAdapter.Fill(dataTableSrcfile); if (dataTableSrcfile.Rows.Count > 0) { imageFile = dataTableSrcfile.Rows[0][0].ToString(); imagePath = @"I:\" + BatchName.Split(' ')[0] + @"\" + imageFile; if (imageFile.Split('\\').Length == 3) { imageFile = imageFile.Split('\\')[2]; } else { imageFile = imageFile.Split('\\')[1]; } zoneFile = imagePath.Substring(0, imagePath.LastIndexOf(".")) + ".ozf"; if (File.Exists(zoneFile)) { try { pageImage = codecs.Load(imagePath); if (pageImage.XResolution < 150) { pageImage.XResolution = 150; } if (pageImage.YResolution < 150) { pageImage.YResolution = 150; } ocrPageZones = OcrEngine.CreatePage(pageImage, OcrImageSharingMode.AutoDispose); ocrPageZones.LoadZones(zoneFile); } catch (Exception ex) { if (showedMemoryMessage == false) { Messager.ShowInformation(this, "Could not open " + imagePath + ". " + ex.Message); showedMemoryMessage = true; } pageImage = null; } } } } if (pageImage != null) { zone = GetPageZone(ocrPageZones, zoneID); zoneRect = zone.Bounds.ToRectangle(150, 150); zoneImage = pageImage.Clone(zoneRect); zoneImage.CustomData.Add("Page", page.ToString()); zoneImage.CustomData.Add("ZoneID", instanceRow["ZoneID"].ToString()); zoneImage.CustomData.Add("FieldID", fieldIndex.ToString()); images.Add(zoneImage); } if (images.Count > 59) { break; } } DisplayUniqueFieldValueInstanceImagePage(); }
private void LoadImage(bool loadDefaultImage) { ImageFileLoader loader = new ImageFileLoader(); bool bLoaded; loader.OpenDialogInitialPath = _openInitialPath; try { loader.LoadOnlyOnePage = true; if (loadDefaultImage) { if (_ocrEngineType == OcrEngineType.OmniPageArabic) { bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ArabicSample.tif", _codecs, 1, -1); } else { bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ocr1.tif", _codecs, 1, -1); } } else { bLoaded = loader.Load(this, _codecs, true) > 0; } if (bLoaded) { _openInitialPath = Path.GetDirectoryName(loader.FileName); RasterImage image = loader.Image; if (image.XResolution < 150) { image.XResolution = 150; } if (image.YResolution < 150) { image.YResolution = 150; } if (_ocrPage != null) { _ocrPage.Dispose(); _ocrPage = null; } _viewer.Image = image; if (_ocrEngine.IsStarted) { _ocrPage = _ocrEngine.CreatePage(image, OcrImageSharingMode.None); } _currentHighlightRect = LeadRect.Empty; _recognitionResults.Text = ""; _tsMainZoomComboBox_SelectedIndexChanged(_tsMainZoomComboBox, new EventArgs()); } } catch (Exception ex) { Messager.ShowFileOpenError(this, loader.FileName, ex); } finally { _viewer.Invalidate(); } }