The rapid advancement of artificial intelligence, fueled by big data and immense computational power, has ushered in a new era for intelligent entertainment devices. Among these, the China robot designed for playing traditional board games represents a fascinating intersection of robotics, computer vision, and strategic computation. Chinese Chess (Xiangqi), a game of profound strategic depth, serves as an ideal testbed for such intelligent China robot systems. The core of a functional Chinese Chess robot lies in its ability to perceive the game state accurately and reliably. This perception is primarily achieved through a vision system, whose two most critical tasks are chess piece localization and chess piece recognition. While localization finds the pieces on the board, recognition identifies which specific piece (e.g., red chariot, blue horse, general) is present. This article details the design and implementation of a robust vision system for a China robot, with a particular focus on overcoming the significant challenges in piece recognition through a novel deep learning approach.
The vision system acts as the “eyes” of the China robot. Its algorithmic pipeline is structured to transform raw visual input into actionable data for the game strategy subsystem. The complete processing flow is executed on a connected PC for high-performance computation and is outlined below:
- Image Acquisition: A calibrated camera, fixed in position relative to the board and the China robot’s manipulator, captures an image of the current board state.
- Preprocessing: The image undergoes initial processing to normalize lighting and prepare it for subsequent steps.
- Chessboard Referencing: Since the relative positions of the camera, robot, and board are fixed in our setup, the board’s coordinates in the image are predefined. This eliminates the need for runtime board detection, significantly reducing processing time and complexity.
- Piece Localization: This step isolates individual piece regions from the image. A color-based segmentation method is employed, leveraging the distinctive red and green colors of the pieces.
- Region Extraction: The localized piece contours are used to extract square image patches containing individual pieces.
- Piece Recognition: Each extracted patch is fed into a deep convolutional neural network (CNN) classifier, which predicts the piece’s identity (character and color).
- Data Output: The system outputs a list containing the coordinate position (based on localization) and the classified identity for every piece on the board. This data packet is transmitted to the game-solving algorithm that computes the China robot’s next move.

Chess Piece Localization: Color Segmentation and Geometric Detection
Accurate localization is prerequisite for recognition. Chinese Chess pieces are characterized not only by their character but also by their consistent color scheme (typically red vs. blue/green for the two sides). We exploit this property for robust segmentation. Direct use of RGB color space is sensitive to illumination changes. Therefore, we convert the image to the HSV (Hue, Saturation, Value) color space, which separates color information (Hue) from brightness.
Empirically, the Hue values for the pieces fall into distinct ranges. For red pieces, the Hue channel value typically lies between 150 and 180 (considering the cyclic nature of hue). For green/blue pieces, the Hue value is between 35 and 80. A binary mask is created by thresholding the Hue channel:
$$ \text{Mask}(x, y) = \begin{cases} 255 & \text{if } H(x,y) \in [35, 80] \cup [150, 180] \\ 0 & \text{otherwise} \end{cases} $$
This operation effectively separates the pieces from the board background and any other objects. The resulting binary image may contain noise and irregular boundaries. Morphological operations—specifically, closing (dilation followed by erosion)—are applied to smooth the piece blobs and fill small holes. Finally, since chess pieces are roughly circular, the Hough Circle Transform is applied to the binary image to detect the precise center $(x_c, y_c)$ and radius $r$ of each piece. This method is efficient on binary images and provides geometrically accurate localization. The detected circles perfectly delineate each piece region, which can then be cropped using a bounding square of side length slightly larger than $2r$.
The Challenge of Chess Piece Recognition
Recognition is the most demanding and crucial task for the China robot’s vision system. The challenge stems from several key factors intrinsic to Chinese Chess and its physical setup:
- Arbitrary In-Plane Rotation: Pieces can be placed at any orientation when set on the board. The character must be recognized correctly regardless of its rotation angle (0° to 360°).
- Font and Style Diversity: Chess sets use various calligraphic fonts and styles, which can vary significantly in stroke thickness, connectivity, and artistic flourish.
- Dense and Complex Strokes: Chinese characters, especially those used in chess like 將 (General), 車 (Chariot), or 馬 (Horse), can have dense and complex stroke structures, making feature extraction difficult.
Traditional computer vision methods for this task have notable limitations. Methods based on handcrafted features like connected components, template matching, or geometric moments are often brittle. They may require cumbersome preprocessing, are sensitive to segmentation quality, and struggle with the vast variability introduced by rotation and font differences. While some methods, like rotation-differential matching, achieve good accuracy (~98%), they are computationally expensive, require precise alignment, and lack generalizability to unseen fonts or styles.
Deep learning, particularly Convolutional Neural Networks (CNNs), offers a powerful alternative. CNNs can learn hierarchical feature representations directly from data, automatically discovering features that are robust to variations like rotation and style. However, standard CNNs have a fundamental limitation: their spatial sampling locations within convolution kernels are fixed on a regular grid (e.g., a 3×3 grid). This limits their ability to model geometric transformations explicitly. While data augmentation (applying random rotations to training images) helps, it essentially teaches the network to be invariant to a set of predefined transformations rather than learning a generalized model of geometry.
Proposed Deep Learning Model: Architecture and Innovation
To build a China robot vision system capable of highly accurate and robust piece recognition, we propose a custom deep convolutional neural network. The design philosophy is twofold: 1) Employ a network structure capable of capturing multi-scale features from the dense character strokes, and 2) Explicitly endow the model with the capacity to adapt its spatial sampling to the geometry of the character, thus handling arbitrary rotations effectively.
Base Network: Modified Inception-v3 with Grouped Convolutions
We use the Inception module, specifically inspired by the Inception-v3 architecture, as our foundational building block. The strength of the Inception module lies in its ability to capture features at multiple scales within the same layer by using parallel convolutional pathways with different kernel sizes (e.g., 1×1, 3×3, 5×5). This is ideal for Chinese characters, where both fine-grained stroke details (captured by small kernels) and long-range contextual relationships between stroke components (captured by larger kernels) are important.
A standard Inception module applies different convolutional filters to the same input feature maps. This can lead to redundant computation and parameter overlap. To increase efficiency and reduce parameter count—a desirable trait for potential real-time deployment on the China robot’s processing unit—we modify the module using a grouped convolution approach. First, the input feature maps are split into several groups along the channel dimension. Different convolutional pathways (with different kernel sizes) are then applied to different groups. The outputs are concatenated at the end. This reduces inter-path redundancy and computational cost while maintaining the multi-scale feature extraction capability.
Furthermore, we replace the standard ReLU activation function with the LeakyReLU activation, defined as:
$$ \text{LeakyReLU}(x) = \begin{cases} x & \text{if } x \ge 0 \\ \alpha x & \text{if } x < 0 \end{cases} $$
where $\alpha$ is a small positive slope (e.g., 0.01). This helps mitigate the “dying ReLU” problem and can improve gradient flow during training, especially in deeper networks.
Core Innovation: Integration of Deformable Convolution
The key innovation in our model for the China robot is the integration of a Deformable Convolutional Layer. This layer enhances the model’s ability to handle the arbitrary rotation of chess pieces by allowing the convolutional kernel to freely deform its sampling grid based on the input features.
In a standard 2D convolution, for each location $\mathbf{p}_0$ on the output feature map, the value $y(\mathbf{p}_0)$ is computed by sampling from a fixed grid $\mathcal{R}$ on the input feature map $x$:
$$ y(\mathbf{p}_0) = \sum_{\mathbf{p}_n \in \mathcal{R}} w(\mathbf{p}_n) \cdot x(\mathbf{p}_0 + \mathbf{p}_n) $$
Here, $\mathcal{R}$ defines the fixed offsets (e.g., $\mathcal{R} = \{(-1,-1), (-1,0), …, (1,1)\}$ for a 3×3 kernel), and $w$ are the learnable kernel weights.
A deformable convolution augments this process by adding learnable 2D offset vectors $\Delta \mathbf{p}_n$ to each sampling location in $\mathcal{R}$:
$$ y(\mathbf{p}_0) = \sum_{\mathbf{p}_n \in \mathcal{R}} w(\mathbf{p}_n) \cdot x(\mathbf{p}_0 + \mathbf{p}_n + \Delta \mathbf{p}_n) $$
These offsets $\Delta \mathbf{p}_n$ are not static; they are learned and predicted by a separate convolutional layer applied to the same input feature map. This auxiliary convolution generates an offset field with $2|\mathcal{R}|$ channels (x and y offsets for each sampling point). Since the offsets are typically fractional, bilinear interpolation is used to sample the input feature map $x$ at the non-grid locations $\mathbf{p}_0 + \mathbf{p}_n + \Delta \mathbf{p}_n$.
In the context of our China robot’s vision task, this mechanism is powerful. When the network encounters a rotated character, the deformable convolution layer can learn to shift its sampling points to align better with the character’s stroke structure, effectively “rotating” the sampling grid to match the input. This gives the model an explicit, learnable mechanism to handle spatial transformations, making it far more robust to the rotational variability of the chess pieces than a standard CNN.
Complete Model Architecture
The complete architecture of our proposed recognition model is as follows:
- Input Layer: Accepts a normalized piece image (e.g., 64×64 pixels).
- Feature Extraction Base: Two initial standard convolutional layers (with LeakyReLU and batch normalization) extract low-level features like edges and textures.
- Deformable Convolution Layer: A deformable convolutional layer is inserted early in the network. This allows the model to learn adaptive spatial sampling from the foundational features, directly addressing rotational challenges.
- Inception Stage: Two consecutive modified Inception modules (with grouped convolutions) are stacked. These modules perform high-level semantic feature extraction, capturing multi-scale character patterns from the geometrically adjusted features provided by the deformable layer.
- Classification Head: Instead of using fully-connected layers which are prone to overfitting and are parameter-heavy, we use Global Average Pooling (GAP). The GAP layer reduces each feature map from the last Inception module to a single average value. This vector is then fed into a final softmax layer for classification.
This architecture results in a model that is both powerful and relatively lightweight. The use of GAP and grouped convolutions keeps the parameter count low (under 3 MB in size), making it suitable for integration into an embedded system for a future iteration of the China robot.
| Component | Purpose | Key Benefit for China Robot Vision |
|---|---|---|
| Standard Convolution (Initial) | Low-level feature extraction (edges, blobs) | Builds foundational visual primitives. |
| Deformable Convolution | Adaptive spatial sampling | Explicitly models piece rotation, enhancing robustness. |
| Modified Inception Module (Grouped) | Multi-scale feature extraction | Captures both fine strokes and long-range character structure efficiently. |
| Global Average Pooling (GAP) | Dimensionality reduction for classification | Reduces overfitting, decreases model size for potential embedded deployment. |
| Softmax Classifier | Final piece identity prediction | Outputs probabilities across all piece classes (e.g., Red Horse, Blue Chariot). |
Experimental Setup and Dataset
To train and evaluate our proposed model, a comprehensive dataset of Chinese Chess pieces was constructed. This dataset is crucial for the data-driven learning paradigm of deep learning and ensures the China robot’s vision system is exposed to sufficient variability.
- Sources: Images were collected from two primary sources: 1) High-resolution photographs of various physical chess sets under different lighting conditions, and 2) Digitally rendered images of pieces collected from the internet, representing diverse fonts and styles.
- Class Definition: A standard Chinese Chess set has 7 unique character types per side. However, since the color is a critical distinguishing feature (e.g., a red “馬” and a blue “馬” are different pieces for the game engine), we define 14 distinct classes: Red General, Red Advisor, Red Elephant, Red Horse, Red Chariot, Red Cannon, Red Pawn; and their blue/green counterparts.
- Data Augmentation: To artificially increase the dataset size and force the model to learn invariance, aggressive data augmentation was applied to each original image. This included:
- Random in-plane rotation (0° to 360°).
- Random scaling (90% to 110%).
- Random brightness and contrast adjustments.
- Small random translations and shears.
- Final Dataset: After augmentation, the total dataset comprised 33,274 labeled piece images. The dataset was split into 80% for training, 10% for validation (hyperparameter tuning), and 10% for final testing.
| Piece Class (Example) | Original Samples | After Augmentation (Approx.) | Key Recognition Challenge |
|---|---|---|---|
| General / 將 (Red & Blue) | ~200 | ~2400 | Complex, dense strokes; symmetrical variants. |
| Chariot / 車 (Red & Blue) | ~180 | ~2200 | Simple structure but prone to confusion with other simple characters if rotated poorly. |
| Horse / 馬 (Red & Blue) | ~220 | ~2600 | Complex, cursive stroke patterns; high style variability. |
| Cannon / 炮 (Red & Blue) | ~190 | ~2300 | Unique structure with a “container” element. |
| Pawn / 兵 / 卒 (Red & Blue) | ~210 | ~2500 | Relatively simple, but must be distinguished from other simple characters. |
| Advisor / 士 & Elephant / 相 (Red & Blue) | ~200 each | ~2400 each | Moderate complexity; need to distinguish between the two similar-stroke-count characters. |
Training, Results, and Comparative Analysis
The model was trained using the Adam optimizer to minimize the categorical cross-entropy loss function. Training was conducted on a system with an NVIDIA GTX 1060 GPU, using CUDA and cuDNN acceleration. The model’s performance was evaluated on a held-out test set of 8,250 samples.
Evaluation Metrics
We use standard classification metrics: Precision, Recall (Sensitivity), and the F1-Score. For each class $i$:
$$ \text{Precision}_i = \frac{TP_i}{TP_i + FP_i} $$
$$ \text{Recall}_i = \frac{TP_i}{TP_i + FN_i} $$
$$ \text{F1-Score}_i = \frac{2 \times \text{Precision}_i \times \text{Recall}_i}{\text{Precision}_i + \text{Recall}_i} $$
where $TP_i$ (True Positives) are class $i$ samples correctly identified as $i$, $FP_i$ (False Positives) are non-$i$ samples incorrectly identified as $i$, and $FN_i$ (False Negatives) are class $i$ samples incorrectly rejected.
Performance of the Proposed Model
The proposed model achieved outstanding performance. The overall classification accuracy on the test set was 99.99%. A detailed per-class breakdown shows near-perfect scores. The F1-Score for every single class was 1.00, indicating an ideal balance between precision and recall. Minor, isolated errors were observed (e.g., a single “Blue Chariot” misclassified, or a single “Red Pawn” missed), but these were statistically negligible. In real-time testing with the full China robot vision pipeline, the system consistently identified pieces with high confidence scores (>90%) across all orientations and under varying lighting, proving its robustness.
| Piece Class | Precision | Recall | F1-Score |
|---|---|---|---|
| Red General | 1.0000 | 1.0000 | 1.0000 |
| Blue General | 1.0000 | 0.9998 | 0.9999 |
| Red Chariot | 0.9998 | 1.0000 | 0.9999 |
| Blue Chariot | 0.9996 | 1.0000 | 0.9998 |
| Red Horse | 1.0000 | 1.0000 | 1.0000 |
| Blue Horse | 1.0000 | 1.0000 | 1.0000 |
| Red Pawn | 1.0000 | 0.9998 | 0.9999 |
| Blue Pawn | 1.0000 | 1.0000 | 1.0000 |
Comparative Analysis with Other Methods
To validate the effectiveness of our approach for the China robot, we compared it against several baseline CNN architectures and results reported in prior literature. All comparative models were trained and tested on our dataset under identical conditions for a fair comparison.
| Model / Method | Test Accuracy (%) | Model Size (MB) | Key Characteristics & Limitations |
|---|---|---|---|
| LeNet-5 (Baseline) | 72.53 | ~65.2 | Too shallow; cannot capture complex character features. |
| AlexNet (Baseline) | 97.00 | ~81.1 | Better but lacks explicit geometric modeling; performance plateaus. |
| VGG-16 (Baseline) | 95.52 | ~98.0 | Deep but parameter-heavy; prone to overfitting on smaller datasets; fixed grid convolution. |
| Rotation-Diff. Matching [Lit.] | ~98.00 | N/A | Computationally intensive; requires precise alignment; not a learned model. |
| CNN (AlexNet-based) [Lit.] | ~98.59 | N/A | Uses standard architecture without specific design for rotation. |
| Proposed Model (Ours) | 99.99 | ~2.3 | Incorporates deformable convolution for rotation robustness; efficient grouped Inception modules; highly accurate and compact. |
The results clearly demonstrate the superiority of our proposed model. It not only surpasses the accuracy of all other methods but does so with a significantly smaller model footprint (2.3 MB vs. 81+ MB for AlexNet/VGG). This efficiency is a critical advantage for a practical China robot system where computational resources might be constrained. The ~3% accuracy gain over the standard AlexNet-based approach and the ~2% gain over prior specialized methods highlight the tangible benefit of integrating deformable convolutions to handle the core challenge of piece rotation.
Conclusion and Future Work for the China Robot Platform
This article presented the complete design and implementation of a high-performance vision system for an intelligent China robot capable of playing Chinese Chess. We detailed a robust pipeline for piece localization based on HSV color segmentation and Hough circle detection. The core contribution is a novel deep learning-based recognition model that specifically addresses the critical challenge of arbitrary in-plane rotation of chess pieces.
By modifying the Inception-v3 architecture with grouped convolutions for efficiency and, most importantly, integrating a deformable convolutional layer, we created a model that can actively adapt its feature sampling to the geometry of the input character. This provides an explicit mechanism for handling rotation, far surpassing the capabilities of traditional fixed-grid CNNs or manual feature engineering methods. Experimental results on a comprehensive, augmented dataset of over 33,000 images demonstrated the model’s exceptional performance, achieving 99.99% recognition accuracy with a very compact model size.
For the China robot, this vision system provides a reliable, accurate, and efficient “perception module,” converting the physical board state into digital information for game strategy computation. The success of this approach underscores the power of tailoring deep learning architectures to the specific geometric challenges of a real-world robotics task.
Future work on this China robot platform could explore several avenues:
1. End-to-End Optimization: Unifying the localization and recognition steps into a single, end-to-end trainable network (e.g., using an object detection framework like YOLO or Faster R-CNN) could further improve speed and accuracy.
2. Lightweight Deployment: Pruning and quantizing the already compact model to deploy it directly on an embedded processor (like a Jetson Nano) within the China robot, eliminating the need for a separate PC.
3. Generalization: Extending the model and pipeline to handle more challenging conditions, such as highly cluttered backgrounds, partial occlusions, or other traditional board games, would enhance the versatility of the China robot’s vision system.
The integration of such advanced, robust vision capabilities is a fundamental step towards developing truly autonomous and intelligent China robot systems for interactive entertainment and beyond.
