Results 1 to 7 of 7

Thread: Tesseract_GetUTF8Text access violation

  1. #1
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default Tesseract_GetUTF8Text access violation

    The text detection worked when i used the Tesseract Tool:


    When i executed it in script, it returned an empty string:
    Code:
    procedure getText;
    const
      myTesseractFilter: TTesseractFilter = [1, 1, [False, 0, TM_Mean]];
    const
      area: TBox = [396, 643, 428, 665];
    var
      bmp: integer;
    begin
      bmp:= BitmapFromClient(area.x1, area.y1, area.x2, area.y2);
      DisplayDebugImgWindow(100, 100);
      ClearDebugImg;
      DrawBitmapDebugImg(bmp);
      writeln(Tesseract_GetText(area.x1, area.y1, area.x2, area.y2, myTesseractFilter));
    end;
    result:


    In the Tesseract_GetText function, Tesseract_GetUTF8Text is throwing an access violation which caused the except block to be executed. Any idea what's causing this?
    Code:
        try
          textPtr := Tesseract_GetUTF8Text(__tesseractPtr, textLen);
        except
          TextPtr := nil;
        end;
    Last edited by riwu; 07-01-2017 at 06:53 AM.

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    ...
    You might need to apply the Tesseract filter before getting the text.
    Simba Code:
    Tesseract_ApplyFilter(bmp, myTesseractFilter);

  3. #3
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    You might need to apply the Tesseract filter before getting the text.
    Simba Code:
    Tesseract_ApplyFilter(bmp, myTesseractFilter);
    That's already called here
    Code:
    function Tesseract_GetText(const xs, ys, xe, ye: integer; filter: TTesseractFilter; Whitelist: String = TESS_WHITELIST_NONE): string; overload;
    var
      bmp: Integer;
      t, tt: LongWord;
    begin
      if((xe - xs) < 10) or ((ye - ys) < 10) then
        Exit('');
    
      bmp := bitmapFromClient(xs, ys, xe, ye);
    
      try
        t := getSystemTime();
        Tesseract_ApplyFilter(bmp, filter);
    
        t := (getSystemTime() - t);
        tt := getSystemTime();
    
        result := Tesseract_GetText(bmp, Whitelist);
        {$IFDEF TESSERACT_DEBUG}
        printf('Tesseract_GetText(): Filtering took: %d ms, Tesseract Took: %d ms, Total Time: %d ms.', [t, (getSystemTime() - tt), (getSystemTime() - tt) + t]);
        printf('Tesseract_GetText(): Text found: %s', [result]);
        {$ENDIF}
      finally
        {$IFDEF TESSERACT_DEBUG}
        clearDebugImg();
        displayDebugImgWindow(getMufasaBitmap(bmp).getWidth(), getMufasaBitmap(bmp).getHeight());
        drawBitmapDebugImg(bmp);
        {$ENDIF}
      end;
    
      freeBitmap(bmp);
    end;

  4. #4
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    That's already called here
    Code:
    function Tesseract_GetText(const xs, ys, xe, ye: integer; filter: TTesseractFilter; Whitelist: String = TESS_WHITELIST_NONE): string; overload;
    var
      bmp: Integer;
      t, tt: LongWord;
    begin
      if((xe - xs) < 10) or ((ye - ys) < 10) then
        Exit('');
    
      bmp := bitmapFromClient(xs, ys, xe, ye);
    
      try
        t := getSystemTime();
        Tesseract_ApplyFilter(bmp, filter);
    
        t := (getSystemTime() - t);
        tt := getSystemTime();
    
        result := Tesseract_GetText(bmp, Whitelist);
        {$IFDEF TESSERACT_DEBUG}
        printf('Tesseract_GetText(): Filtering took: %d ms, Tesseract Took: %d ms, Total Time: %d ms.', [t, (getSystemTime() - tt), (getSystemTime() - tt) + t]);
        printf('Tesseract_GetText(): Text found: %s', [result]);
        {$ENDIF}
      finally
        {$IFDEF TESSERACT_DEBUG}
        clearDebugImg();
        displayDebugImgWindow(getMufasaBitmap(bmp).getWidth(), getMufasaBitmap(bmp).getHeight());
        drawBitmapDebugImg(bmp);
        {$ENDIF}
      end;
    
      freeBitmap(bmp);
    end;
    ?? That's not the function you're using in your first post.
    Last edited by Citrus; 07-01-2017 at 06:48 AM.

  5. #5
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    ?? That's not the function you're using in your first post.
    Oh was actually using this: writeln(Tesseract_GetText(area.x1, area.y1, area.x2, area.y2, myTesseractFilter));
    copied the wrong code

  6. #6
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Seems like there's something wrong with my code or my setup, i couldn't get tesseract to work on anything.
    Does the code below works for anyone? (save the attached image as img.jpg in the same folder as script/app)
    @Olly @slacky
    Code:
    {$i tesseract.simba}
    
    procedure getText;
    const
      myTesseractFilter: TTesseractFilter = [1, 1, [False, 0, TM_Mean]];
    var
      bmp: integer;
    begin
      bmp:= LoadBitmap('img.jpg');
      DisplayDebugImgWindow(100, 100);
      ClearDebugImg;
      DrawBitmapDebugImg(bmp);
    
      writeln(Tesseract_GetText(bmp));
      Tesseract_ApplyFilter(bmp, myTesseractFilter);
      writeln(Tesseract_GetText(bmp));
    end;
    
    begin
      getText;
    end.
    Attached Images Attached Images

  7. #7
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Tested with SRL-6 in both Simba 1.1 and 1.2, both works. No such public include as Tessearct.simba, so I went with SRL-6, which I assume you've based it of.

    Edit: My test is using Simba 32bit, as usual that is what I recommend others to use as well.
    Last edited by slacky; 07-08-2017 at 04:21 PM.
    !No priv. messages please

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •