I came across my first stumbling block and overcame it.
The first stage is getting the cards. As mentioned, to do this I simple picked a row of a card and did a CheckWhite(x,y) across it to get the pattern of whites/non-white pixels.
So I put checks in that checked this row of the card, compared it to the table.. and it worked.. sometimes.
What I didn't vouch for is that depending on the suit, some of the anti-aliasing or whatever it is on the cards meant some of these were slightly coloured, and so different suit to suit. So then I had the painful task of taking note of this row for every card in the deck (1 being white, 0 being another colour):
From here I deleted the similar ones (Jack for example is the same for every suit), filled arrays, and we were on to a winner:Code:2h - 00000000000000011111110000000000 2d - 00000000000000011111110000000000 2s - 00000000000000111111110000000000 2c - 00000000000000111111110000000000 3h - 00000000001111111111111100000000 3s - 00000000001111111111111100000000 3c - 00000000001111111111111100000000 3d - 00000000001111111111111100000000 4d - 00111111100000000111111000000000 4h - 01111111000000000111110000000000 4s - 00111111000000001111110000000000 4c - 00011111100000000011111000000000 5c - 00000001111100011111111110000000 5s - 00000001111100001111111110000000 5h - 00000000111100011111111100000000 5d - 00000000111100011111111110000000 6h - 00001111111100000001111111100000 6s - 00111111111000000011111111000000 6c - 00011111111100000001111111100000 6d - 00011111111100000001111111100000 7d - 00000000000000111110000000000000 7h - 00000000000000111110000000000000 7c - 00000000000000111110000000000000 7s - 00000000000001111110000000000000 8h - 00000000111111111111111100000000 8d - 00000000111111111111111100000000 8c - 00000001111111111111111100000000 8s - 00000001111111111111111110000000 9d - 00000111111111111111111111100000 9s - 00000111111111111111111111100000 9c - 00000001111111111111111111111000 9h - 00000001111111111111111111111000 Tc - 00001111000011111000000000011111 Ts - 00001111000011111000000000011111 Td - 00001111000011111000000000011111 Th - 00000001110001111100000000001111 Jh - 00000000000000111111100000000000 Js - 00000000000000111111100000000000 Jd - 00000000000000111111100000000000 Jc - 00000000000000111111100000000000 Qc - 11111100000000000000000011111100 Qh - 11111100000000000000000011111100 Qd - 11111100000000000010000011111100 Qs - 11111100000000000000000011111100 Kd - 00111111111111111100000000000000 Ks - 00111111111111111000000000000000 Kc - 00011111111111111000000000000000 Kh - 00111111111111111000000000000000 Ac - 00001111100000000111110000000000 Ad - 00000111100000000111110000000000 Ah - 00000111100000000011110000000000 As - 00001111100000000111110000000000
On completion, I added a suit check using a corner of the card for colour, and voila, now I can detect any card on the table as long as I know it's top left corner. Excuse the code, it's sloppy (as it's just for my own use), and still has some debugging code in.Code:int c2abuf[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int c2bbuf[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int c3abuf[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; int c4abuf[32] = { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int c4bbuf[32] = { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int c4cbuf[32] = { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int c4dbuf[32] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int c5abuf[32] = { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int ckbbuf[32] = { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int ckcbuf[32] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int caabuf[32] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int cabbuf[32] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int cacbuf[32] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
On completion, I have a value returned (cardv) between 0 and 51. These equate to the following array:Code:int GetCard(int x, int y) { x = x + 22; y = y + 56; int cardv = 15; char xbuf[2]; ZeroMemory(CardBuffer, 33); ZeroMemory(xbuf2, 50); for (int i = 0; i <= 31; i++) { if (CheckWhite(x, y)) { CardBuffer[i] = 1; } else { CardBuffer[i] = 0; } x++; sprintf_s(xbuf, "%d", CardBuffer[i]); lstrcat(xbuf2, xbuf); } if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c2abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c2bbuf))) { cardv = 1; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c3abuf))){ cardv = 2; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c4abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c4bbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c4cbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c4dbuf))){ cardv = 3; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c5abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c5bbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c5cbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c5dbuf))){ cardv = 4; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c6abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c6bbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c6cbuf))){ cardv = 5; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c7abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c7bbuf))){ cardv = 6; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c8abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c8bbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c8cbuf))){ cardv = 7; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c9abuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(c9bbuf))){ cardv = 8; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(ctabuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(ctbbuf))){ cardv = 9; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(cjabuf))){ cardv = 10; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(cqabuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(cqbbuf))){ cardv = 11; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(ckabuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(ckbbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(ckcbuf))){ cardv = 12; } else if (std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(caabuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(cabbuf)) || std::equal(std::begin(CardBuffer), std::end(CardBuffer), std::begin(cacbuf))){ cardv = 0; } if (cardv == 15) { return 100; } else { x = x + 2; y = y - 52; COLORREF pixel; HDC hdcScreen = GetDC(0); pixel = GetPixel(hdcScreen, x, y); if (pixel != CLR_INVALID){ int red = GetRValue(pixel); int green = GetGValue(pixel); int blue = GetBValue(pixel); if (red == green == blue) { cardv = cardv + 39; } else if (green > red && green > blue){ cardv = cardv + 26; } else if (blue > red && blue > green){ cardv = cardv + 13; } } ReleaseDC(0, hdcScreen); } return(cardv); }
- - - Updated - - -Code:const char *cardNames[52] = { "Ah", "2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "Th", "Jh", "Qh", "Kh", "Ad", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "Td", "Jd", "Qd", "Kd", "Ac", "2c", "3c", "4c", "5c", "6c", "7c", "8c", "9c", "Tc", "Jc", "Qc", "Kc", "As", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "Ts", "Js", "Qs", "Ks" };
The next logical step would be to capture bet sizes/pot size, however I'm getting bored of pixel grabbing at the minute so I'm going to look at sorting our preflop ranges for now.