Advertisement
Janilabo

asd

Nov 12th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.58 KB | None | 0 0
  1. {$I SCARExt\SCARExt.scar}
  2. {$L project1.dll}
  3.  
  4. function GetBitmapColorTPA(bmp: TSCARBitmap; color: Integer;Tol:Integer): TPointArray;
  5. var
  6.   client: TSCARClient;
  7. begin
  8.   Client := SetClient(TSCARBitmapClient.Create(bmp));
  9.   FindColorTolEx(Result, color, 0, 0, (bmp.Width - 1), (bmp.Height - 1), Tol);
  10.   SetClient(client).Free;
  11. end;
  12.  
  13. procedure Test;
  14. var
  15.   t:Integer;
  16.   TPA,Skel: TPointArray;
  17.   Img:T2DIntArray;
  18.   bmp: TSCARBitmap;
  19.   png: TPNGFile;
  20. begin
  21.  
  22.   bmp := TSCARBitmap.Create('');      
  23.   png := TPNGFile.Create;            
  24.  
  25.   png.LoadFromFile(ScriptPath + 'small_ints2.png');
  26.   bmp := png.ToBitmap;
  27.   png.Free;
  28.   begin
  29.     //bmp.ResizeEx(bmp.width*5, bmp.height*5, brBilinear);
  30.     t := GetTimeRunning;
  31.     Img := XT_Bmp2Matrix(bmp,False);  
  32.     XT_ImResize(Img,bmp.width*5, bmp.height*6, rm_bilinear);
  33.     Img := XT_ImThresholdAdaptive(Img, 0, 255, TM_Mean, 65);
  34.     Img := XT_ImBlurFilter(Img,5);
  35.     Img := XT_ImBlurFilter(Img,3);
  36.     Img := XT_ImThresholdAdaptive(Img, 0, 255, TM_MinMax, 0);
  37.  
  38.     XT_BmpSetData(bmp, Img, True);  
  39.     TPA := GetBitmapColorTPA(bmp, 255, 0);
  40.     Skel := XT_TPASkeleton(TPA, 2, 6);  //Skeletonize for smooth chars
  41.     Skel := XT_TPAExpand(Skel, 1); //More stable.
  42.     Bmp.Clear(0);
  43.     bmp.SetPixels(Skel,255);
  44.    
  45.     WriteLn(GetTimeRunning - t);
  46.     DebugBitmap(bmp);
  47.     bmp.SaveToPng(ScriptPath + 'small_ints.png');
  48.     bmp.Free;
  49.  
  50.     SetTesserPath(ScriptPath + 'Tesseract-OCR\Tesseract.exe');
  51.     WriteLn(Tesseract(ScriptPath + 'small_ints.png', ScriptPath + 'temp.txt'));
  52.   end;
  53. end;
  54.  
  55. begin
  56.   Test;
  57. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement