-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualization.cpp
103 lines (96 loc) · 2.39 KB
/
visualization.cpp
1
2
3
4
5
6
7
8
9
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "stdafx.h"
#include "visualization.h"
#include "config.h"
using namespace cv;
std::string getPieceFilePath(Piece piece)
{
switch (piece) {
case Piece::BlackBishop:
return path_piece_black_bishop;
case Piece::WhiteBishop:
return path_piece_white_bishop;
case Piece::BlackKing:
return path_piece_black_king;
case Piece::WhiteKing:
return path_piece_white_king;
case Piece::BlackKnight:
return path_piece_black_knight;
case Piece::WhiteKnight:
return path_piece_white_knight;
case Piece::BlackPawn:
return path_piece_black_pawn;
case Piece::WhitePawn:
return path_piece_white_pawn;
case Piece::BlackRook:
return path_piece_black_rook;
case Piece::WhiteRook:
return path_piece_white_rook;
case Piece::BlackQueen:
return path_piece_black_queen;
case Piece::WhiteQueen:
return path_piece_white_queen;
}
return "";
}
std::string pieceToString(Piece piece)
{
switch (piece) {
case Piece::BlackBishop:
return "black bishop";
case Piece::WhiteBishop:
return "white bishop";
case Piece::BlackKing:
return "black king";
case Piece::WhiteKing:
return "white king";
case Piece::BlackKnight:
return "black knight";
case Piece::WhiteKnight:
return "white knight";
case Piece::BlackPawn:
return "black pawn";
case Piece::WhitePawn:
return "white pawn";
case Piece::BlackRook:
return "black rook";
case Piece::WhiteRook:
return "white rook";
case Piece::BlackQueen:
return "black queen";
case Piece::WhiteQueen:
return "white queen";
}
return "";
}
Mat getDigitalChessboard(std::vector<std::pair<Piece, Point2i>> pieces)
{
const int blockSize = 64;
const int imageSize = blockSize * 8;
Mat board = imread(path_board, IMREAD_COLOR);
int row = 0;
for (int i = 0; i < imageSize; i = i + blockSize) {
int col = 0;
for (int j = 0; j < imageSize; j = j + blockSize) {
Mat ROI = board(Rect(i, j, blockSize, blockSize));
for (int k = 0; k < pieces.size(); k++)
{
if (pieces.at(k).second.x == row && pieces.at(k).second.y == col)
{
std::string path = getPieceFilePath(pieces.at(k).first);
Mat piece = imread(path, IMREAD_UNCHANGED);
for (int i = 0; i < piece.rows; i++) {
for (int j = 0; j < piece.cols; j++) {
Vec4b pixel = piece.at<Vec4b>(i, j);
if (pixel[3] != 0) {
ROI.at<Vec3b>(i + 10, j + 10) = Vec3b(pixel[0], pixel[1], pixel[2]);
}
}
}
}
}
col++;
}
row++;
}
return board;
}