WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 8th, 2011 at 10:14:20 AM permalink
Guys

I am dabbling with some programming and have created a function that outputs a BIT value.
Basically the function interrogates an image for different types of pixels and outputs the BIT value based on the image.
So if I was looking for X in the line below

O
X
O
X
X
O

It would output the value 26, as the first line is worth 1, second is worth 2, third line is worth 4, fourth is worth 8 etc... So the values picked up are 2, 8 and 16.

with me so far?

Now does anybody have any idea how I use 26 to determine the location of the X's?

This is a very basic example, and in reality the lines are 100's deep.

for what its worth, 26 is totally unique for this combination.

Another example

O
O
O
X
X
X
O
O
O
X
O
X

would be 2616
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
Dween
Dween
  • Threads: 66
  • Posts: 339
Joined: Jan 24, 2010
May 8th, 2011 at 12:43:25 PM permalink
If you're dealing with a line of X's and O's that are hundreds of lines deep, you're going to get into values that are enormous, and chances are your variables won't be able to hold values that high with the accuracy you need.

You could take the value (i.e. 26) and divide it by 2; if there is a remainder of 1, line 1 is an X. Remainder 0, line 1 is an O.
Continue dividing the value by 2, checking for a remainder.

26 / 2 = 13 r 0 = O
13 / 2 = 6 r 1 = X
6 / 2 = 3 r 0 = O
3 / 2 = 1 r 1 = X
1 / 2 = 0 r 1 = X
(all rows after are O's)

There is probably also a bit-shift operand you could use in your code to do the same faster.

When dealing with such a large amount of data, you may need to try another route.
-Dween!
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 8th, 2011 at 12:52:36 PM permalink
Thank you very much, that is very helpful.

My limitation is ;

Number range (floating point): 1.7E–308 to 1.7E+308 with 15-digit precision

I am hoping that will be enough for now. I am currently working with 18 lines, so max value of 131072. I think I could possibly be dealing with 30-40 lines, but will try and avoid it as scanning that many pixels would take a long time
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
PapaChubby
PapaChubby
  • Threads: 11
  • Posts: 495
Joined: Mar 29, 2010
May 8th, 2011 at 4:01:24 PM permalink
Maybe this will help:

log(26)/log(2) = 4.700
Int(4.7) = 4

The first x is in the 4th location (starting from zero, so actually the fifth location)

26 - 2^4 = 10

repeat.
Dween
Dween
  • Threads: 66
  • Posts: 339
Joined: Jan 24, 2010
May 9th, 2011 at 5:10:54 AM permalink
That 15-digit precision is what's going to kill you. Once you hit a 16-digit number, any math you do on the order of the 1's place is going to be woefully inaccurate.

Maybe you should use an array of booleans. They're nothing more than bits anyway. Plus, you have the array's index number to show where your X's (true) and O's (false) go instantly. Problem being you won't be able to show the value (i.e. 26) of the string once you get beyond that 15-digit threshold, which is around 50 bits.
-Dween!
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 9th, 2011 at 8:10:05 AM permalink
Quote: Dween

That 15-digit precision is what's going to kill you. Once you hit a 16-digit number, any math you do on the order of the 1's place is going to be woefully inaccurate.

Maybe you should use an array of booleans. They're nothing more than bits anyway. Plus, you have the array's index number to show where your X's (true) and O's (false) go instantly. Problem being you won't be able to show the value (i.e. 26) of the string once you get beyond that 15-digit threshold, which is around 50 bits.



Dween, thanks for your help, I read all of what you said at least 4 times, but all I took in was 'Blah Blah Blah'
Can you tell me in laymans terms what 15 digit precision means? at 18 lines I am using 131072, how many lines with that limit allow?

To give you more of an insight into what I am doing; I am working on an OCR engine, so most of the text at present is no more than 18 pixels 'high' if the colour of the pixel is 50 shades adrift of the background colour (not color) it registers a 'hit', a $ sign is 7x18 pixels and is worth 12528,127792,8600,131070,13064,16152,7704 (each of those values is the vertical bit value of each of the 7 width pixels.) Should I just add them all together for a hard value of $ ? Or should I further formulate it (or complicate it) to make it smaller? Such as adding them up and only using the 6 right most digits? makes numbers easier to use, but there is a 1 in mill chance of having a collision. (could be far less than 1inMill given the types of numbers I am using).
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
Dween
Dween
  • Threads: 66
  • Posts: 339
Joined: Jan 24, 2010
May 9th, 2011 at 10:37:39 AM permalink
15 digit precision simply means that the most accurate number you can have is a 15 digit number. If you go to 16, 17, 18... digits, the rest will be padded with zeroes, for example:

123,456,789,012,345 x 111 = 13,703,703,580,370,295
But with 15 digit accuracy, the number would be stored as 13,703,703,580,370,200.
Losing that "95" at the end would be a killer for you.

You can have up to 49 lines, as 2 to the 49th power is a 15-digit number.

You would NOT want to add each vertical bit value together, as you would get a number that could have a "collision" with others.
For example, take super simple quotation marks that look like this:
.......
..#.#..
..#.#..
..#.#..
.......
.......
.......
.......
.......
The values of each column, left to right, would be 0,0,14,0,14,0,0.
If you were to add those together, you would get 28.
Which, it just so happens, is the total for a simple apostrophe that looks like this:
.......
.......
...#...
...#...
..#....
.......
.......
.......
.......

Vertical bit values of 0,0,16,12,0,0,0... sums to 28.

Each column would have to be calculated separately and kept separate.

You also may not be able to rely on a single set of values for a character. In your example, a dollar sign ($) is worth:
12528,127792,8600,131070,13064,16152,7704
What if a pixel doesn't get picked up at the top or bottom of the $? What if there is a smudge and an extra pixel is calculated? Unless this is an exercise for a class with error-free data being fed to you, you'll need to take a lot of consideration into the introduction of errors.

I applaud your effort in trying to create an OCR program. That is beyond my experience, but I'm glad some of my lower-level programming insight has been able to assist you.
-Dween!
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 9th, 2011 at 11:01:54 AM permalink
WOW! Thanks!

There are no errors, as there are never any extra pixels. It can read one value from a screen that changes dynamically, flawlessly.
The scan area is about 100x18 pixels, typically 8 characters, and it updates in about 18 milliseconds, which I hope you agree is pretty damn fast.

I think I need to scan 35 areas of a similar size, I dont need them all in real time as such, but if I could collect all the data in less than 4-5 seconds I would be happy.

The downside is if the font changes, colours are not that much of an issue, but I can collect most fonts in less than 10 minutes of activity.

The OCR relies on an empty vertical line to separate the characters, so I have had some glued "24" and "27" where the bottom of the two protrudes into the area of the adjacent number, but I just teach it that the particular 'pattern' is 24 or 27 and it has no issues with the logic or value of the number.
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 9th, 2011 at 11:13:16 AM permalink
Numerically do you think I am doing it the right way?
I will try and get the code to workable demo and send you a copy, including the source.
I only started it yesterday, and was surprised to get it working (or sorts) so quickly.

Previously I have used external programs via dll's but the presence of the program and the dll caused problems.
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 9th, 2011 at 11:23:08 AM permalink

In the photo you can see the OCR asking for a definition of an unknown pattern.
Its scanning the chip count in seat one
The reason it only identifies 4 characters, is because the , and 4 are 'glued' and appear as ",4" in one pattern
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 9th, 2011 at 11:27:15 AM permalink
Oh and for you guys in the US, just in case you forgot. This is on-line poker ;-)
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
Dween
Dween
  • Threads: 66
  • Posts: 339
Joined: Jan 24, 2010
May 9th, 2011 at 12:33:30 PM permalink
Interesting... I didn't realize you were viewing a graphic screen. When you said OCR, my mind went to scanning a piece of paper, which is messy to say the least.

If the font is not going to change, and you know where the characters are going to fall, you may not need to scan the entire area.
Take, for example, a 7-segment LED displaying the digits 0-9.
#####   ....#   #####   #####   #...#   #####   #####   #####   #####   #####
#...# ....# ....# ....# #...# #.... #.... ....# #...# #...#
#...# ....# ##### ##### ##### ##### ##### ....# ##### #####
#...# ....# #.... ....# ....# ....# #...# ....# #...# ....#
##### ....# ##### ##### ....# ##### ##### ....# ##### #####

You have 15 pixels per digit in my example, however, I can determine a digit by polling just 6 pixels, and may even be able to improve. The idea is, you can take the alphanumeric characters --- you KNOW what they will look like --- and pick a dozen pixel-polling sites that could narrow down the possibilities to just one character.

Given 26 alpha and 10 numeric, or 36 characters, a perfect algorithm could give you an answer in 6 pixels. Not all fonts are going to be able to split things into halves with each pixel, so the actual number will increase.

However... since all of your characters are going to be known, it might be just as easy to scan an entire area, get its "value", and determine what character you have. I also imagine that your previous idea of "totaling" all vertical bit-sums would work for you. Like you said, there's a 1 in a million chance of a collision... though maybe it's more like ((1000000-1)/1000000)^36, which is still 99.99% chance of NOT colliding.

You may even want to look at a specific vertical column, to see if it has a unique value across all characters. That way, you only need to determine WHERE the character is, then scan its X'th column.

The specific pixel-polling I was talking about may however work for determining playing cards. If I remember correctly, I once used an online poker software that allowed me to change the look of the cards and chips. If that is possible, it would be super easy to change the cards (and chips if you need to) to have "barcodes" on them, for easy reading.
-Dween!
Ayecarumba
Ayecarumba
  • Threads: 236
  • Posts: 6763
Joined: Nov 17, 2009
May 9th, 2011 at 12:34:31 PM permalink
Quote: WizardofEngland

Oh and for you guys in the US, just in case you forgot. This is on-line poker ;-)




Ha! No one ever wins online.... WPT you say..., Oh... never mind....





Congrats on your WPT tournament run WoE, we all enjoyed your updates, and look forward to the next one.
Simplicity is the ultimate sophistication - Leonardo da Vinci
WizardofEngland
WizardofEngland
  • Threads: 61
  • Posts: 638
Joined: Nov 2, 2010
May 9th, 2011 at 1:04:27 PM permalink
@Dween

I tried that to begin with, but I had issues, some of the text is thinner than others, so if the value starts with a 1, the next digit will be nearer, or an 8 and it will further away. Also the text seems to center adjusted, so if the player had $1.40 instead of $144.74 the pixels will fall in very different places. Also the area is wider than the text, to be sure to grab everything within it. I actually spent best part of a week on just looking for unique pixels, but the combination of different sized digits made it nigh on impossible. Where as the OCR was almost up and running within a few hours. Its also very easy to teach it a new font, and I am pretty sure that if I stay with the method I have, that collisions are practically impossible without the character being the same anyway.

@Ayecarumba

Thanks, it was an amazing experience, had a good run, was one hour short of day three (money day) and outlasted all but one of the tv show pros in the event. I am hoping to repeat the experience again this year. But have recently been laid off from work, so funds are tight.
http://wizardofvegas.com/forum/off-topic/general/10042-woes-black-sheep-game-ii/#post151727
  • Jump to: