ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Problem using traineddata (Fast and Best)
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

restkrat

USA
2 Posts

Posted - Feb 02 2022 :  14:12:40  Show Profile  Reply
Hello,

The only eng.traineddata I can get to work is the one from the English LTSM+Legacy download. When I try to the other two English LTSM Only (Fast) or English LTSM Only (Best), I get an access error when using either of them. I have just been replacing the eng.traineddata. Any idea what I can do to make those two work?


Thanks



procedure TForm1.Button1Click(Sender: TObject);
begin
od1.Execute(Form1.Handle);
if od1.FileName <> '' then
begin
im1.IO.LoadFromFile(od1.FileName);
im1.Fit();
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ocrrect: TIERectangle;
  langPath : string;
  langCode: string;
  langis : String;
begin
m1.Clear;
memo1.Clear;
Screen.Cursor := crHourglass;

langCode := string(IEVisionLanguageNameToCode('English'));
if cmbengine.Text = 'LTSMLegacy' then langPath := IncludeTrailingBackSlash(ExtractFilePath(Application.ExeName) + 'LTSMLegacy');
if cmbengine.Text = 'LTSMFast' then langPath := IncludeTrailingBackSlash(ExtractFilePath(Application.ExeName) + 'LTSMFast');
if cmbengine.Text = 'LTSMBest' then langPath := IncludeTrailingBackSlash(ExtractFilePath(Application.ExeName) + 'LTSMBest');

if not IEVisionAvailable(False) then
begin
  ShowMessage('This application requires ievision.dll plugin. Please download it from www.imageen.com/download/');
  Application.Terminate;
  exit;
end;

//langis := langcode +  '.traineddata';

//memo1.Lines.Add(langis);
//memo1.Lines.Add(langpath + langcode + '.traineddata');
Try

OCR := IEVisionLib.createOCR(PAnsiChar(AnsiString(langPath)), PAnsiChar(AnsiString(langCode)), TIEVisionOCREngine(cmbEngine.ItemIndex));
//OCR := IEVisionLib.createOCR(PAnsiChar(AnsiString(langPath)), PAnsiChar(AnsiString(langis)), TIEVisionOCREngine(cmbEngine.ItemIndex));

OCR.setSegmentationMode(TIEVisionOCRPageSegmentationMode(cmbLayout.ItemIndex));

ocrrect := Im1.SelectedRect;

m1.Lines.Text := OCR.recognize(Im1.IEBitmap.GetIEVisionImage(), IEVisionRect(ocrrect.x, ocrrect.y, ocrrect.width, ocrrect.height)).c_str();

except
    on E: Exception do
    begin
      if E is EAccessViolation then
        MessageDlg('An error was encountered processing this image. Ensure you are using the latest version of the IEVision plug-in.', mtError, [mbOK], 0)
      else
        MessageDlg('An error was encountered processing this image: ' + e.message, mtError, [mbOK], 0);
    end;
  end;
Screen.Cursor := crDefault;
end;

xequte

38608 Posts

Posted - Feb 02 2022 :  16:08:30  Show Profile  Reply
Hi

Can you forward us some of your test files? Are you using the latest version of ImageEn and IEVision?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

restkrat

USA
2 Posts

Posted - Feb 03 2022 :  20:26:33  Show Profile  Reply
Hello,

I am using ImageEn 10.3.0 and IEVision 6.0.1

The attachment has the image I have been testing with.

Thanks



Go to Top of Page

xequte

38608 Posts

Posted - Mar 16 2022 :  17:01:14  Show Profile  Reply
Hi

ievOCRLTSMAndLegacy ievOCRLegacy cannot be used with the Best or Fast engines, as they include no legacy support.

The corrected code is as follows:

procedure TForm1.Button2Click(Sender: TObject);
var
  ocrrect: TIERectangle;
  langPath : string;
  langCode: string;
  eng: TIEVisionOCREngine;
begin
  m1.Clear;
  Screen.Cursor := crHourglass;

  langCode := string(IEVisionLanguageNameToCode('English'));
  if cmbengine.Text = 'LTSMLegacy' then                                  
  begin
    langPath := IncludeTrailingBackSlash(ExtractFilePath(Application.ExeName) + 'LTSMLegacy');
    eng := ievOCRLTSMAndLegacy; // or ievOCRDefault or ievOCRLegacy
  end
  else
  if cmbengine.Text = 'LTSMFast' then
  begin
    langPath := IncludeTrailingBackSlash(ExtractFilePath(Application.ExeName) + 'LTSMFast');
    eng := ievOCRLTSM; // Or ievOCRDefault
  end
  else
  if cmbengine.Text = 'LTSMBest' then
  begin
    langPath := IncludeTrailingBackSlash(ExtractFilePath(Application.ExeName) + 'LTSMBest');
    eng := ievOCRLTSM; // Or ievOCRDefault
  end
  else
    raise Exception.create( 'Invalid selection' );

  if not IEVisionAvailable(False) then
  begin
    ShowMessage('This application requires ievision.dll plugin. Please download it from www.imageen.com/download/');
    Application.Terminate;
    exit;
  end;

  OCR := IEVisionLib.createOCR(PAnsiChar(AnsiString(langPath)), PAnsiChar(AnsiString(langCode)), eng );
  OCR.setSegmentationMode(TIEVisionOCRPageSegmentationMode(cmbLayout.ItemIndex));

  ocrrect := Im1.SelectedRect;
  m1.Lines.Text := OCR.recognize(Im1.IEBitmap.GetIEVisionImage(), IEVisionRect(ocrrect.x, ocrrect.y, ocrrect.width, ocrrect.height)).c_str();

  Screen.Cursor := crDefault;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: