- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
private ChessField Recognize()
{
var output = new ChessField();
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
var xs = x*50;
var ys = y*50;
if (IsNeutral(bitmap.GetPixel(xs + 25, ys + 33)) && IsNeutral(bitmap.GetPixel(xs + 8, ys + 40)))
{
output.figures[y,x].kindOfFigure = Figure.KindOfFigure.Empty;
}
else
{
if ((IsWhite(bitmap.GetPixel(xs + 25, ys + 34)) ||
IsWhite(bitmap.GetPixel(xs + 30, ys + 25))) && !IsBlack(bitmap.GetPixel(xs + 9, ys + 42)))
{
output.figures[y, x].color = Figure.Color.White;
//white rec
if (IsBlack(bitmap.GetPixel(xs + 25, ys + 7)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.King;
continue;
}
if (!IsWhite(bitmap.GetPixel(xs + 25, ys + 32)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Queen;
continue;
}
if (IsBlack(bitmap.GetPixel(xs + 25, ys + 22)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Bishop;
continue;
}
if (IsBlack(bitmap.GetPixel(xs + 25, ys + 27)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Knight;
continue;
}
if (IsWhite(bitmap.GetPixel(xs + 15, ys + 15)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Rook;
continue;
}
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Pawn;
}
else
{
output.figures[y, x].color = Figure.Color.Black;
//black rec
if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 25)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Bishop;
continue;
}
if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 28))||
!IsBlack(bitmap.GetPixel(xs + 25, ys + 29)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Knight;
continue;
}
if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 36)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Rook;
continue;
}
if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 31)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.King;
continue;
}
if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 33)))
{
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Queen;
continue;
}
output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Pawn;
}
}
}
}
return output;
}
4 часа ночи, вино, кофе, чужой курсач, распознание шахматных фигур со скриншота типа этого
http://download.hdd.tomsk.ru/preview/xjntlwtz.jpg
естесно поле уже вырезано и поджато под 400 на 400 пикселей