SRL Archive - RS3 Help

How does tesseractGetText work?


mastah

2014-06-07 12:18:41

I dont't understand what i need to put in every parameter and what it means. Sometimes I get the right values from it and sometimes I don't. I need to parse an integer value from a line of text.
Kind regards

Olly

2014-06-07 14:26:15

Show me a image of the text and il walk you though it.

mastah

2014-06-07 14:56:03

Great thanks!
For example this image, I already found out how to get an integer value from it. Only the text messages aren't always correct.
Especially resizeMultipler,threshinvert etc. I don't understand. And x1,y1 etc. can be any box right as long as text is in it?

tesseractGetText(const x1, y1, x2, y2, resizeMultipler: integer; threshInvert: boolean; threshAmount: integer; config: string = ''): string; overload;

[ATTACH=CONFIG]23370[/ATTACH]

Does this function always get the right text?

Olly

2014-06-07 16:01:14

{$i srl-6/srl.simba}

var
canvas, bmp, w, h, i: integer;

begin
canvas := createBitmap(300, 500);

Bmp := BitmapFromString(59, 16, 'meJxllf9r1WUUx5VW5JaheaXcKjLbcLpMnUa3zS8z98V2XavrnIvrmEu2xZyazQx0RcHCCqEIKYIC0Sj2QwhDE4KI8te+UNJv3nu36fqtu80/YL0+94UPl7sPh8M55znPed7nPOc8n3jt2oa6Z2rXl1eteRRa/VhMIVC8du3B5A548/OPb1j/FM6JXRugzsQWBSxFxFKhGtyCnYBho0ajwQOh4ub2sBEBqFD1mhVAlZBVK1atBOfLiZ1wyKTggl+IdqGlCHk8Xxy5sBfaiYDARngIGGQIDACTBBkE3BobtulvtV2y7FQbMhdPCWEVihIpcgiwC+WghhQWkhjm5+f3NO8ORYZM03pScN1C/VGFXUSAIQs4V4B65FArkUVodtqRFbxuBVtOIWwJNQlbYsvLyleWEbYzmUCAVleUxQsaO6CV2y0a6zY+jAM8BCcmloDqzHAfkV3y6EJudoVGI4hcfmdu9lAqGZbYAjwwEzbZnkCAROsAQmaEm5hNCsCxFQ+hbl4Xs7FFTkyHgvjwY/0dAmbJvCydmWIPo+1e83UJC5ztfYe7VbUXVRhUYLCALo2+PzKRTePw7/TU2feGTQr8Lbvrr//y03z+u/H3Xz376oXdsr3qx2vjGOdmc999ewkhPEEff/TBraksFvjRIwMBLZb+g01eDYSa6mjR7jd9Kwvghq2PEIrTlz1YKmAEqxfVtqLsgbIln35yLptJU3yMgwO9szO5s6PviBnArNZuqqmurLh29fI/N/4kR2L+cHX8+q8/dySe7e1qvJ2HZ3G+/OL85ORET3cX8qkTfXfmZkZOn2IJDPhwF8qquJkm8vDgfiNgIZ3lS0uscFtr09LSeyBgg8fuxd7e1gpyCOPQ0GA2m476IZ8mRvYKHk8A73wuusS9L77AEbidOXkY1TlF6O1+xc6nIO+efoN0dHOJmw0q+L1oZeoQxgfAJtLe1gxaVEjMNA92VOyxZSVQZ7IZC6vRWG2puTL+fTbfLX5cyoH9yUi4+5jYw6iprqSlDv2mpxgQUJFtddS3j72KinPUHl3J8JvwseUBzw9dsxUWHhwA+psFdPzoAAjZxexMTmYuXvhqW91Wiszt4ImwsSaq8L6Xdm2uKg2onAuE13taoynOT+tbJ9/MZjKoIuQU8XgptAGyFfa9pcj+I3yfsTMRnEud4ZuerhT5h6MjU1OTdBRou1Odudx/tB9o7SLmER8a4I/ff4umIP8/ZRKhHfGapu3VUxNpK7/uifsJRbKpAwkQ9r2WmsnlentSzi/y5+fPIQz2p6ZvTzhQqKTJeF76+jOOowKQj5VDV/iNjY0tXrTIqp44PgRmjOn0TdD6dGNvbWnMZm5iJwvAILAU3XhlBa2CCowrl78RMGdxCqF8JTKZNJgdXnJhqE2NjGiGaAr21Ns/HXvjTi6eWHC2ReEg95EMliX3LbY9ymMl4YdLstjDKgKj5++JaJBjKHeONPqYI+PvjCiHdxIH7PiLjRxxcIu1NYhlBBJEzwgMJOChyNYZVYeQiGglm8ojfD2UETglADYdHxzV8PjoSXaoAmO7PGSnnV0WUNicTlf7TwSqqERuUuzSYpHZ64+eONjhT666FzexkT4yFtMED3KY3wjSXU8TF4aCodwLJ2uWosRjJf8DESz4tA==');
FastDrawTransparent(0, 0, bmp, canvas);
getBitmapSize(bmp, w, h);
i := h;

// first we resize the image - Tesseract needs bigger text to read accurately
ResizeBitmapEx(bmp, RM_Bilinear, w * 3, h * 3); // in this case we triple the size - this is the resize amount
FastDrawTransparent(0, i, bmp, canvas);
i := i + (h * 3);

// next the threshold filter is applied
// - alpha = 0, beta = 255.
// - invert should be false if text is brighter then the background else true.
// - method = tm_mean or tm_minmax just mess around to find the best one for you, both have uses.
// - c = the amount to threshold, can be negative or postive, mess around with this.
ThresholdAdaptiveBitmap(bmp, 0, 255, false, TM_Mean, 50);
FastDrawTransparent(0, i, bmp, canvas);

displayDebugImgWindow(300, 500);
drawBitmapDebugImg(canvas);
freeBitmap(bmp);
freeBitmap(canvas);

// as you can see the end image we have a decent red on black text, tesseract should like this.

// what i just did is the same as this tesseractGetText(100, 100, 100, 100, FILTER_SMALL_CHARS); - Make the area as small as you can around the text.

// FILTER_SMALL_CHARS being a constant that holds this infomation -
// {resize multipler w, resize multipler h, invert, threshold amount}
// FILTER_SMALL_CHARS: array [0..3] of variant = [3, 3, false, 50];
end;

Give that a run and you will see what tesseract does, and even mess around with the params to see what they do..

To sum it up there is a preset filter you can use that should work for you

tesseractGetText(100, 100, 100, 100, FILTER_SMALL_CHARS);

mastah

2014-06-08 13:18:32

Thanks alot, I totally get it now!