Poker-AI.org

Poker AI and Botting Discussion Forum
It is currently Mon Nov 13, 2023 2:54 pm

All times are UTC




Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: OCR for asian network
PostPosted: Sat Mar 25, 2017 5:53 pm 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
Hi,

I am trying to do ocr for asian network, it seems very complicated so far because letters, digits, cards are displayed in many different ways. I can separate digits / letters automatically and save them as templates, but the problem is that I don't know if there are limited number of templates for e.g. digit 0.
in the attachment you can find 3 different stacks, so you can see that the same digits look different. There are occasions when the same digit (e.g. 0) looks the same way, but most of the time it is different. I convert the image to binary in order to remove rgb but still there are a lot of differences. You can also see 7 different digits 0
that are convert to binary image, how it all looks very different.

I haven't tried tesseract on this, but i think that it would perform very bad because letters and digits are very often connected, no clear border.
I hope that you will recognize that there are two images in the attachment, the second one displaying 3 different stacks is very small.
Any idea how to solve this?
Thanks in advance.


Attachments:
tables.png
tables.png [ 975.93 KiB | Viewed 25255 times ]
image.png
image.png [ 22.9 KiB | Viewed 25258 times ]
stacks.png
stacks.png [ 1.55 KiB | Viewed 25258 times ]
Top
 Profile  
 
PostPosted: Sat Mar 25, 2017 10:42 pm 
Offline
Veteran Member

Joined: Wed Mar 20, 2013 1:43 am
Posts: 267
What is the name of the site? Maybe you can change the fonts or so, to make it more readable?

Everytime I did OCR, I was never happy with software like Tess, I always wrote my own code. I also never use anything like NNs in my code, I usually write a ton of custom rules to detect the borders and the characters. It's usually a ton of work, but after a while the accuracy is pretty good.


Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 1:01 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
Today I founded some new filters for this situation.
c++ code (opencv)
Code:
cv::Mat Img = cv::imread("c:/orign.png");
   
   //filter1
   for (int row = 0; row < Img.rows; row++){
      for (int col = 0; col < Img.cols-1; col++){
         uint8_t b1 = Img.at<cv::Vec3b>(row, col)[0];
         uint8_t g1 = Img.at<cv::Vec3b>(row, col)[1];
         uint8_t r1 = Img.at<cv::Vec3b>(row, col)[2];
         uint8_t h1, s1, v1;
         RGB2HSV(r1, g1, b1, &h1, &s1, &v1);
         uint8_t b2 = Img.at<cv::Vec3b>(row, col+1)[0];
         uint8_t g2 = Img.at<cv::Vec3b>(row, col+1)[1];
         uint8_t r2 = Img.at<cv::Vec3b>(row, col+1)[2];
         uint8_t h2, s2, v2;
         RGB2HSV(r2, g2, b2, &h2, &s2, &v2);
         if ((h1 > h2)&&(h1-h2 > 15)&&(h1>100)&&(h1<125)) Img.at<cv::Vec3b>(row, col+1) = cv::Vec3b(0, 0, 0);
      }
   }
   cv::imwrite("c:/filter1.png", Img);
   //filter2
   for (int row = 0; row < Img.rows; row++){
      for (int col = 0; col < Img.cols - 1; col++){
         uint8_t b1 = Img.at<cv::Vec3b>(row, col)[0];
         uint8_t g1 = Img.at<cv::Vec3b>(row, col)[1];
         uint8_t r1 = Img.at<cv::Vec3b>(row, col)[2];
         uint8_t h1, s1, v1;
         RGB2HSV(r1, g1, b1, &h1, &s1, &v1);
         uint8_t b2 = Img.at<cv::Vec3b>(row, col + 1)[0];
         uint8_t g2 = Img.at<cv::Vec3b>(row, col + 1)[1];
         uint8_t r2 = Img.at<cv::Vec3b>(row, col + 1)[2];
         uint8_t h2, s2, v2;
         RGB2HSV(r2, g2, b2, &h2, &s2, &v2);
         if ((h1 > h2) && (h1 - h2 > 15) && (h2>100) && (h2<125)) Img.at<cv::Vec3b>(row, col) = cv::Vec3b(0, 0, 0);
      }
   }
   cv::imwrite("c:/filter2.png", Img);
   //cv::Mat Img2 = Img.clone();
   //filter3
   for (int row = 0; row < Img.rows; row++){
      for (int col = 0; col < Img.cols; col++){
         uint8_t b = Img.at<cv::Vec3b>(row, col)[0];
         uint8_t g = Img.at<cv::Vec3b>(row, col)[1];
         uint8_t r = Img.at<cv::Vec3b>(row, col)[2];
         uint8_t h, s, v;
         RGB2HSV(r, g, b, &h, &s, &v);
         bool is_good_point = false;
         if ((h>100) && (h < 125) && (s>60) && (s<120) && (v > 200)) is_good_point = true;
         
         if (!is_good_point) Img.at<cv::Vec3b>(row, col) = cv::Vec3b(0, 0, 0);
         
      }
   }
   cv::imwrite("c:/filter3.png", Img);


Attachments:
filter2.png
filter2.png [ 25.53 KiB | Viewed 25245 times ]
filter1.png
filter1.png [ 26.28 KiB | Viewed 25245 times ]
orign.png
orign.png [ 14.96 KiB | Viewed 25245 times ]
Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 1:02 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
Cant attach more 3 files. And here is result.
(you can do all 3 filters in one sycle)

With good filters, it will be much easier to recognize ;)


Attachments:
result.png
result.png [ 12.33 KiB | Viewed 25245 times ]


Last edited by nefton on Sun Mar 26, 2017 1:23 am, edited 1 time in total.
Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 1:19 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
And with close letters.
If letter you cut from stack is too width (9+ pixels)
You can try to compare all leters you have with the begin of your superwidth twice letter,
and if sucsess try the same thing on begin+sucsess_letter.width position


Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 12:04 pm 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
Can you give me the biggest size stack you can do?
Have some idea.


Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 4:21 pm 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
Hi thank you for your answer. I don't understand what kind of filters do you apply on the image? Could you describe it in words? I am using c#, for my bot, I understand c++ code but I don't understand what you are doing exactly? I see that you change image from RGB to HSV but that is all I understand.
Also by looking at your output images I see that the digits are still quite different, so how can I recognize e.g. digit 0 if it is displayed in so many different ways?
In the attachment you can find the biggest stack size I have found.


Attachments:
table_0.png
table_0.png [ 401.06 KiB | Viewed 25228 times ]
Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 4:23 pm 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
nefton wrote:
Cant attach more 3 files. And here is result.
(you can do all 3 filters in one sycle)

With good filters, it will be much easier to recognize ;)


Ok I can see from the result image that it should be easier to recognize digits after the proposed filters are applied. Still I don't understand how could I do it in c# because I don't understand your code?


Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 4:24 pm 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
HontoNiBaka wrote:
What is the name of the site? Maybe you can change the fonts or so, to make it more readable?

Everytime I did OCR, I was never happy with software like Tess, I always wrote my own code. I also never use anything like NNs in my code, I usually write a ton of custom rules to detect the borders and the characters. It's usually a ton of work, but after a while the accuracy is pretty good.


The name is natural 8, asian online casino.


Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 5:32 pm 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
mlatinjo wrote:
In the attachment you can find the biggest stack size I have found.

I mean width and height of stack digits. (Screenshoot max table size you can do)

Filters... I thought the above pictures will be enough for understanding.
1st filter. I delete right edge of all digits. I see that on edge there is big hue gradient (h1-h2)
2nd filter. The same only on right edge
3rd. remain only desired hue and saturation diapason.

Without 1st and 2nd filters - there was bad results from 3rd filter.

But I have another idea how to recognize it. May be this red and blue edges are not noise, and we should not remove it.
They appear from worst algoritm of resizing they template digits to size that are displayed to you.
And if we can understand this algoritm of resizing - we can use this bad pixels to restore the original digits.

And even if this idea will not work - you can just store many variants of your digits (10variants x 10digits = 100 templates only (it is not terrible value))


Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 6:19 pm 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
Hi in the attachment you can find the biggest size table I could make for my 22 inch monitor, and standard table size. I guess that the resize is made on standard table size, which is what you want to see?
You can see that even in the standard table size, the digits look quite different. From that I can conclude that the digits and letters don't look different because of resize because on standard table size it also looks all different?


Attachments:
standardSizeTable.png
standardSizeTable.png [ 512.74 KiB | Viewed 25222 times ]
bigtable.png
bigtable.png [ 1.19 MiB | Viewed 25222 times ]
Top
 Profile  
 
PostPosted: Sun Mar 26, 2017 8:27 pm 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
I do it :) !!!!
1. This color artifacts calls clear type!
2. Here is macro photo of orign.png on my monitor. It all explain.
Attachment:
clear_type.jpg
clear_type.jpg [ 592.89 KiB | Viewed 25218 times ]

red lines - is border of monitor pixels.
So now I think it easy to raise qualyty of recognizing X10 times :idea: :geek:


Top
 Profile  
 
PostPosted: Mon Mar 27, 2017 2:41 am 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
How did you produce image1? It is interesting how you can see rgb channels of each pixel in the monitor.

How does scaling to huge image size is going to help recognize digits?


Top
 Profile  
 
PostPosted: Mon Mar 27, 2017 3:19 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
[quote="mlatinjo"]How did you produce image1? It is interesting how you can see rgb channels of each pixel in the monitor.
Attachment:
macro.jpg
macro.jpg [ 92.32 KiB | Viewed 25210 times ]

small hole on the cap is to make minimum apperture I can do. (for big depht of field)
+ several macro rings M42
With this tehniques I can do 5x times more closer picture then in photo below. And more quality :roll:
This photo makes in hurry.


Last edited by nefton on Tue Mar 28, 2017 4:58 am, edited 2 times in total.

Top
 Profile  
 
PostPosted: Mon Mar 27, 2017 3:27 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
mlatinjo wrote:
How does scaling to huge image size is going to help recognize digits?


No, understanding of what happens will help mutch.
You can imagine several algoritms, based on subpixel places, and all of them will be mutch better then now.
Simplest - is to make width*3, height*3 1 chanel picture and fill it by values of r, g, b subpixels.
I tryed it - it good.
But it is not best algoritm for you. More understanding cleartype algoritm will produce mutch better algoritms.(but some more hard)


Top
 Profile  
 
PostPosted: Mon Mar 27, 2017 6:42 pm 
Offline
Senior Member

Joined: Fri Nov 25, 2016 10:42 pm
Posts: 122
Quote:
Simplest - is to make width*3, height*3 1 chanel picture and fill it by values of r, g, b subpixels.
I tryed it - it good.


Just to mention, it is also important to recognize table information fast, it would be good less that 0.5 sec. I think that if the solution would be to increase image then it would increase the time to recognize information.


Top
 Profile  
 
PostPosted: Mon Mar 27, 2017 8:44 pm 
Offline
Senior Member
User avatar

Joined: Sun Mar 10, 2013 10:31 am
Posts: 139
No, we talk about cutted stack image (about 50x10) and no whole image ofcource.
It is nothing. You can not even measure this time without many itterations.
Anyway, all algoritms I thinking includes 1st step triple at least width.
And for debug sences you should triple height too. (after you had compleet working algoritm you can reduce height trippling)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group