Chess game recognition method, device, equipment, storage medium and program product

By using contour recognition and line calibration algorithms, vertices and pieces in the chessboard image are identified, improving the accuracy of piece positioning and solving the problem of accurate chessboard recognition under complex and variable lighting conditions. This enables precise piece positioning and recognition even under unclear image conditions.

CN121788957BActive Publication Date: 2026-07-10CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610263483.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-03-05
Publication Date
2026-07-10
Estimated Expiration
2046-03-05

AI Technical Summary

Technical Problem

Existing chess game recognition methods suffer from low image clarity under complex and variable lighting conditions, leading to inaccurate piece positioning and affecting the accuracy of chess game recognition.

Method used

A contour recognition algorithm is used to identify the outermost vertex of the chessboard and the chess piece image in the chessboard image. Straight line detection is performed to obtain the reference intercept difference between the first and second types of straight lines. The straight lines are calibrated, the intersection points are calculated, the chess piece detection region is constructed, and the category of the chess piece is identified using an object detection model.

Benefits of technology

It improves the accuracy of piece positioning and game board recognition, especially in the case of unclear images, it can still accurately locate pieces and identify their categories.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121788957B_ABST
    Figure CN121788957B_ABST
Patent Text Reader

Abstract

A chess game recognition method, device, equipment, storage medium and program product are disclosed. The method comprises: recognizing a vertex and a chess piece image in a chessboard image; performing straight line detection on the chessboard image to obtain a first type of straight line and a second type of straight line contained in the chessboard image; obtaining a first reference intercept difference and a second reference intercept difference; calibrating the first type of straight line by using the first reference intercept difference and calibrating the second type of straight line by using the second reference intercept difference to obtain a first type of calibrated straight line and a second type of calibrated straight line; calculating the intersection of the first type of calibrated straight line and the second type of calibrated straight line to obtain a chessboard corner point; taking the chessboard corner point and the vertex as the center, a chess piece detection area corresponding to each chessboard corner point is constructed; and in the case that the area overlap ratio of the chess piece image and the chess piece detection area is greater than a preset threshold, the category of the chess piece in the chess piece image is recognized to obtain the position of the chess piece of different categories in the chessboard, thereby improving the accuracy of the chess piece positioning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer vision technology, and in particular relates to a method, apparatus, device, storage medium and program product for chess game recognition. Background Technology

[0002] In the process of chess games between humans and artificial intelligence, game recognition is an important foundation for realizing automated chess games.

[0003] Currently, the method typically relies on visual algorithms to identify the four outermost corners of the chessboard and the corners of the chessboard squares. Then, contour recognition algorithms are used to identify the outlines of the pieces. By using the position of the piece's outline and the position of the corners of the chessboard squares, the position of the piece in the game can be determined.

[0004] However, contour recognition and vision algorithms are limited by image sharpness; low image sharpness can lead to inaccurate recognition results. The complex and variable lighting in chess scenarios can result in blurry images, reducing the accuracy of corner point localization and piece recognition, and further decreasing the accuracy of piece positioning on the board. Summary of the Invention

[0005] This application provides a method, apparatus, device, storage medium, and program product for chess game recognition, which can improve the accuracy of chess piece positioning.

[0006] In a first aspect, embodiments of this application provide a method for chess game recognition, including:

[0007] The outermost vertices and chess pieces in the chessboard image are identified using a contour recognition algorithm.

[0008] Line detection is performed on the chessboard image to obtain a first type of line and a second type of line contained in the chessboard image, wherein the first type of line and the second type of line intersect perpendicularly.

[0009] Obtain the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines. The first reference intercept difference is used to represent the distance between two adjacent first type straight lines in the chessboard image, and the second reference intercept difference is used to represent the distance between two adjacent second type straight lines in the chessboard image.

[0010] The first type of straight line is calibrated using the first reference intercept difference, and the second type of straight line is calibrated using the second reference intercept difference to obtain the first type of calibration straight line and the second type of calibration straight line;

[0011] Calculate the intersection of the first type of calibration line and the second type of calibration line to obtain the corner points of the chessboard;

[0012] With the corner points and vertices of the chessboard as the centers, construct a chess piece detection area with a preset side length corresponding to each corner point of the chessboard.

[0013] If the overlap ratio between the area of ​​the chess piece image and the area of ​​the chess piece detection region is greater than a preset threshold, the target detection model is used to identify the category of the chess piece in the chess piece image, and the positions of different categories of chess pieces on the chessboard are obtained.

[0014] In one possible implementation, identifying the outermost vertices and chess piece images of the chessboard image using a contour recognition algorithm includes:

[0015] The chessboard image is binarized to obtain a binary image of the chessboard image;

[0016] An edge detection algorithm is used to identify the chessboard outline information and chess piece outline information in the binary image;

[0017] The vertices are determined based on the chessboard outline information;

[0018] The chess piece image is determined based on the chess piece outline information.

[0019] In one possible implementation, the step of using an edge detection algorithm to identify the chessboard outline information and chess piece outline information in the binary image includes:

[0020] The edge detection algorithm described above is used to obtain multiple contour information in the chessboard image;

[0021] A first contour set is obtained by fitting convex quadrilaterals to the multiple contour information;

[0022] The contour information other than the contour information in the first contour set is taken as the chess piece contour information;

[0023] The contour information of the largest contour in the first contour set is used as the chessboard contour information.

[0024] In one possible implementation, obtaining the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines includes:

[0025] Calculate the difference of the first intercepts of any pair of adjacent lines of the first type and the difference of the second intercepts of any pair of adjacent lines of the second type;

[0026] Perform a clustering operation on the first intercept difference to obtain the first cluster corresponding to the first type of straight line;

[0027] Perform a clustering operation on the second intercept difference to obtain the second cluster corresponding to the second type of straight line;

[0028] The cluster containing the most elements in the first cluster is taken as the first target cluster;

[0029] The cluster containing the most elements in the second cluster is taken as the second target cluster;

[0030] Calculate the mean of the first target cluster to obtain the first reference intercept difference;

[0031] Calculate the mean of the second target cluster to obtain the second reference intercept difference.

[0032] In one possible implementation, calibrating the first type of straight line using the first reference intercept difference and calibrating the second straight line using the second reference intercept difference to obtain the first type of calibration straight line and the second type of calibration straight line includes:

[0033] Based on the first intercept difference of each first type of straight line, determine the first target straight line with the smallest difference from the first reference intercept difference among the first type of straight lines;

[0034] Determine the first correct line adjacent to the first target line among the first type of lines according to the first reference intercept difference;

[0035] The first correct line is used as the first target line. The step of determining the first target line with the smallest difference from the first reference intercept difference among the first type of lines is executed repeatedly based on the first intercept difference corresponding to each first type of line until a first preset number of first correct lines are determined to obtain the first type of calibration line.

[0036] Based on the second intercept difference of each second type of line, determine the second target line among the second type of lines with the smallest difference from the second reference intercept difference;

[0037] Determine the second correct line adjacent to the second target line in the second type of straight lines according to the second reference intercept difference;

[0038] Using the second correct line as the second target line, the step of determining the second target line with the smallest difference between the second type of lines and the second reference intercept difference based on the intercept difference corresponding to each second type of line is repeated until a second preset number of second correct lines are determined to obtain the second type of calibration line.

[0039] In one possible implementation, before constructing a chess piece detection region of a preset side length corresponding to each chessboard corner point, centered on the chessboard corner point and the vertex, the method further includes:

[0040] Obtain the side length of the bounding box corresponding to each chess piece image, wherein the chess piece image is tangent to the inner wall of the bounding box;

[0041] Calculate the mean side length of the bounding box corresponding to each chess piece image to obtain the mean side length;

[0042] The preset side length is obtained by calculating a preset multiple of the mean side length.

[0043] In one possible implementation, after identifying the category of chess pieces in the chess piece image using an object detection model and obtaining the positions of different categories of chess pieces on the chessboard, the method further includes:

[0044] In the event of abnormal position information of different categories of chess pieces on the chessboard, the contour recognition algorithm is used to identify the updated vertices of the chessboard image;

[0045] Calculate the coordinate transformation matrix based on the updated vertex coordinates and the vertex coordinates of the vertex;

[0046] The coordinates of the chessboard corner points are transformed using the coordinate transformation matrix to obtain the updated chessboard corner point coordinates.

[0047] Secondly, embodiments of this application provide a chess game recognition device, comprising:

[0048] The contour recognition module is used to identify the outermost vertices and chess piece images in a chessboard image based on the contour recognition algorithm.

[0049] A line detection module is used to perform line detection on the chessboard image to obtain a first type of line and a second type of line contained in the chessboard image, wherein the first type of line and the second type of line intersect perpendicularly.

[0050] The acquisition module is used to acquire the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines. The first reference intercept difference is used to represent the distance between two adjacent first type straight lines in the chessboard image, and the second reference intercept difference is used to represent the distance between two adjacent second type straight lines in the chessboard image.

[0051] The calibration module is used to calibrate the first type of straight line using the first reference intercept difference and to calibrate the second straight line using the second reference intercept difference, so as to obtain the first type of calibration straight line and the second type of calibration straight line.

[0052] The calculation module is used to calculate the intersection of the first type of calibration line and the second type of calibration line to obtain the corner points of the chessboard;

[0053] The construction module is used to construct a chess piece detection area with a preset side length corresponding to each chessboard corner point, centered on the chessboard corner point and the vertex point;

[0054] The identification module is used to identify the category of chess pieces in the chess piece image using a target detection model when the ratio of the overlapping area of ​​the area of ​​the chess piece image and the area of ​​the chess piece detection region is greater than a preset threshold, thereby obtaining the position of different categories of chess pieces on the chessboard.

[0055] Thirdly, embodiments of this application provide an electronic device, the device including: a processor and a memory storing computer program instructions;

[0056] The method for chess position recognition, as described in the first aspect, is implemented when the processor executes computer program instructions.

[0057] Fourthly, embodiments of this application provide a computer storage medium storing computer program instructions, which, when executed by a processor, implement the chess game recognition method as described in the first aspect.

[0058] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform a chess game recognition method as described in the first aspect.

[0059] This application discloses a method, apparatus, device, storage medium, and program product for chessboard recognition. It employs a contour recognition algorithm to identify vertices and chess piece images in a chessboard image. Then, it performs line detection on the chessboard image to identify straight lines contained within it. These lines include a first type and a second type, which intersect perpendicularly. In the chessboard, these first and second types of lines represent the horizontal and vertical lines. For different types of lines, a first reference intercept difference for the first type and a second reference intercept difference for the second type are obtained. The first reference intercept difference is used to calibrate the first type of lines, and the second reference intercept difference is used to calibrate the second type of lines. Thus, even when the chessboard image is unclear, the intercept differences allow for accurate calculation of the horizontal and vertical lines, improving the accuracy of line detection and consequently, the accuracy of chessboard corner point location. Given the calculated corner points of the chessboard, a chess piece detection region with a preset side length is constructed, centered on the corner points and vertices. If the overlap between the chess piece image and the chess piece detection region is greater than a preset threshold, it indicates that the chess piece has landed on the corresponding corner point of the chessboard in that chess piece detection region, thus achieving accurate chess piece positioning. Then, the category of the chess piece is identified using an object detection model, thereby obtaining the placement of different chess pieces in the game and improving the accuracy of game recognition. Attached Figure Description

[0060] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0061] Figure 1 This is a flowchart illustrating a method for chess game recognition provided in an embodiment of this application;

[0062] Figure 2 This is a schematic flowchart of a contour recognition method provided in an embodiment of this application;

[0063] Figure 3(a) is a schematic diagram of a chess piece image provided in an embodiment of this application;

[0064] Figure 3(b) is an exemplary schematic diagram of a binary image of a chess piece provided in an embodiment of this application;

[0065] Figure 4 This is a schematic flowchart of a method for determining a reference intercept difference provided in an embodiment of this application;

[0066] Figure 5 This is a schematic flowchart of a method for determining a reference intercept difference provided in an embodiment of this application;

[0067] Figure 6 This is an exemplary schematic diagram of a chessboard corner point provided in an embodiment of this application;

[0068] Figure 7(a) is a schematic diagram of another chessboard image provided in an embodiment of this application;

[0069] Figure 7(b) and an exemplary schematic diagram of a type of chess piece provided in an embodiment of this application;

[0070] Figure 8 This is an exemplary schematic diagram of the chessboard position after a change in position, provided in an embodiment of this application.

[0071] Figure 9 This is a schematic diagram of the structure of a chess game recognition device provided in an embodiment of this application;

[0072] Figure 10 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0073] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.

[0074] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0075] Currently, in chess games between humans and artificial intelligence, accurate game identification is needed to enable automated gameplay by AI. Existing game identification methods fall into two categories:

[0076] The first type of chessboard recognition method involves a magnetic sensor embedded inside the chessboard, with a small magnet at the bottom of each piece. When a piece is placed on the board, the magnetic sensor can detect its type and position. However, this method requires additional hardware, resulting in higher costs.

[0077] The second type of chessboard recognition method involves an electronic device analyzing a captured chessboard image using a camera and image processing algorithms to identify the chessboard's boundaries and grid positions. However, this method has lower accuracy.

[0078] To address the problems existing in the prior art, embodiments of this application provide a method, apparatus, device, storage medium, and program product for chess game recognition. The following first describes the method for chess game recognition provided by embodiments of this application. Figure 1 As shown, the method includes:

[0079] S101. Identify the outermost vertices and chess piece images of the chessboard in the chessboard image using the contour recognition algorithm.

[0080] The chessboard image is an image containing the chessboard captured by an electronic device through a camera. The outermost vertices of the chessboard are the four vertices on the outer perimeter of the chessboard in the chess piece image of Figure 3(a).

[0081] Specifically, electronic devices can extract the contours of different objects in a chessboard image using a contour recognition algorithm. These contours include the chessboard outline (i.e., the outer contour of the chessboard), the chessboard grid outlines, and the chess piece outlines. By performing shape fitting on different contours, such as quadrilateral fitting, the chess piece outlines can be selected. Then, by calculating the area of ​​the contours, the chessboard outline and the chessboard grid outlines are distinguished. The chessboard comprises multiple chessboard grids. This application does not impose specific limitations on the contour recognition algorithm.

[0082] S102. Perform line detection on the chessboard image to obtain the first type of lines and the second type of lines contained in the chessboard image.

[0083] In this system, the first type of line intersects the second type of line perpendicularly. In one example, the first type of line can be a horizontal line on a chessboard, and the second type of line can be a vertical line on a chessboard.

[0084] Specifically, due to the different camera placement positions, the captured chessboard image may not be a front view of the chessboard. Therefore, to improve the accuracy of line detection, the electronic device can perform perspective transformation on the captured chessboard image, converting it into a front view. Then, line detection is performed on the front view to obtain the lines within it. Finally, the slope of the lines is used to distinguish between the first type of line and the second type of line.

[0085] In one example, the Hough transform can be used to detect straight lines in a front view.

[0086] S103. Obtain the first reference intercept difference of the first type of straight line and the second reference intercept difference of the second type of straight line.

[0087] The first reference intercept difference represents the distance between two adjacent lines of the first type in the chessboard image, and the second reference intercept difference represents the distance between two adjacent lines of the second type in the chessboard image. The first and second reference intercept differences can be preset based on experience.

[0088] S104. The first type of straight line is calibrated using the first reference intercept difference, and the second type of straight line is calibrated using the second reference intercept difference, to obtain the first type of calibration straight line and the second type of calibration straight line.

[0089] Specifically, for each physical straight line on the chessboard, multiple detection lines corresponding to each physical straight line can be obtained through the above-mentioned straight line detection. Therefore, the reference intercept difference is used to filter the multiple detection lines corresponding to each physical straight line.

[0090] Understandably, the lines obtained through line detection can all be represented by a mathematical expression, such as Ax + By + C = 0. Therefore, the electronic device can determine the intercept of each line based on the mathematical expression corresponding to each line. By calculating the difference in intercepts between adjacent lines, the intercept difference between adjacent lines can be obtained. The first reference intercept difference is the correct intercept difference between adjacent lines in the first category, and the second reference intercept difference is the correct intercept difference between adjacent lines in the second category. Therefore, by calibrating the identified first and second category lines according to the first and second reference intercept differences, the first and second category calibrated lines can be obtained, which are the accurately positioned lines.

[0091] Specifically, after determining the first and second reference intercept differences, for the first type of straight lines, based on the intercept differences between adjacent straight lines, a target straight line closest to the first reference intercept difference is determined. Then, using the target straight line as a reference, and with the first reference intercept difference as a step size, straight lines in the first type of straight lines with an intercept difference of one, two, three times the first reference intercept difference, and so on, are determined until the number of first-type calibration straight lines found meets a preset threshold. Similarly, the method for determining the second type of calibration straight lines is the same and will not be repeated here.

[0092] S105. Calculate the intersection of the first type of calibration line and the second type of calibration line to obtain the corner points of the chessboard.

[0093] Understandably, after determining the first type of calibration line and the second type of calibration line as described above, we can further determine the mathematical expressions for the first type of calibration line and the second type of calibration line, and then calculate the intersection point of the first type of calibration line and the second type of calibration line through the mathematical expressions.

[0094] S106. Construct a chess piece detection area with a preset side length for each chessboard corner point, centered on both the corner point and the vertex point.

[0095] Construct a piece detection area with a preset side length, centered on each corner point and each vertex of the chessboard.

[0096] The preset side length can be set in advance based on experience.

[0097] S107. When the overlap ratio between the area of ​​the chess piece image and the area of ​​the chess piece detection region is greater than a preset threshold, the target detection model is used to identify the category of the chess piece in the chess piece image and obtain the position of different categories of chess pieces on the chessboard.

[0098] The overlap ratio refers to the ratio of the area of ​​the overlapping region between the chess piece detection region and the chess piece image to the area of ​​the chess piece detection region. A preset threshold can be set empirically. In one example, the preset threshold could be 10%.

[0099] Specifically, the overlap ratio can be calculated by counting the number of pixels belonging to the chess piece image that fall into the chess piece detection area. For example, if the chess piece detection area includes 100 pixels, and the number of pixels belonging to the chess piece image that fall into the chess piece detection area is 25, then the overlap ratio is 25 / 100 = 25%.

[0100] In one example, assuming the chessboard is a Chinese chess board, the object detection model identifies 15 categories: 7 categories of black pieces, 7 categories of red pieces, and a chessboard without pieces. The training algorithm can employ the MobileNetV3 convolutional neural network architecture for mobile and embedded devices.

[0101] Using the above method, a contour recognition algorithm is employed to identify vertices and chess pieces in a chessboard image. Then, line detection is performed on the chessboard image to detect the lines contained within it. These lines are categorized into two types: first-type lines and second-type lines. The first and second types of lines intersect perpendicularly, forming the horizontal and vertical lines on the chessboard. For each type of line, the first reference intercept difference for the first type and the second reference intercept difference for the second type are obtained. The first reference intercept difference is used to calibrate the first-type lines, and the second reference intercept difference is used to calibrate the second-type lines. Thus, even when the chessboard image is unclear, the intercept differences allow for accurate calculation of the horizontal and vertical lines, improving the accuracy of line detection and consequently, the accuracy of chessboard corner location. Given the calculated corner points of the chessboard, a chess piece detection region with a preset side length is constructed, centered on the corner points and vertices. If the overlap between the chess piece image and the chess piece detection region is greater than a preset threshold, it indicates that the chess piece has landed on the corresponding corner point of the chessboard in that chess piece detection region, thus achieving accurate chess piece positioning. Then, the category of the chess piece is identified using an object detection model, thereby obtaining the placement of different chess pieces in the game and improving the accuracy of game recognition.

[0102] The preset side length can be determined based on the size of the chess piece in the chess piece image. Specifically, before constructing the chess piece detection region with the preset side length, the preset side length is determined as follows:

[0103] Obtain the side length of the bounding box corresponding to each chess piece image, with the chess piece image and the inner wall of the bounding box being tangent; calculate the mean side length of the bounding box corresponding to each chess piece image; calculate a preset multiple of the mean side length to obtain the preset side length.

[0104] In this process, the electronic device identifies each chess piece image, which is circular, and constructs a square bounding box using the outline of the chess piece image as the inscribed circle.

[0105] Understandably, because electronic devices using contour recognition algorithms may lose some image information during the contour recognition process, the sizes of the recognized chess piece images will vary, resulting in different side lengths of the constructed bounding boxes. To ensure the accuracy of the calculation results, the average side length of the bounding box corresponding to each chess piece image can be calculated to improve the accuracy of the calculation results.

[0106] Thus, the preset side length is determined based on the bounding box side length, and the electronic device can dynamically adjust it according to the size of the pieces in different chessboard images, thereby ensuring accuracy.

[0107] Regarding S101 above, the outermost vertices and chess piece images of the chessboard in the chessboard image are identified according to the contour recognition algorithm, which can be specifically implemented as S1011-S1014, such as... Figure 2 As shown:

[0108] S1011. Perform binarization processing on the chessboard image to obtain a binary image of the chessboard.

[0109] Binarization refers to processing a chessboard image into a black-and-white image. In one example, binarization can be achieved using the opening operation.

[0110] S1012. Use an edge detection algorithm to identify the chessboard outline information and chess piece outline information in the binary image.

[0111] Regarding S1012 above, the edge detection algorithm is used to identify the chessboard outline information and chess piece outline information in the binary image. Specifically, this can be implemented as follows:

[0112] Step 1: Use an edge detection algorithm to obtain multiple contour information in the chessboard image.

[0113] Step 2: Fit convex quadrilaterals to multiple contour information to obtain the first contour set.

[0114] The first set of contours includes chessboard contour information, which includes chessboard grid contour information.

[0115] Specifically, electronic devices can perform convex quadrilateral fitting on the contour information to distinguish between the chessboard contour information and the chess piece contour information.

[0116] In one example, for a chessboard image, the electronic device preprocesses the image, including opening, edge detection, and dilation. Then, a contour recognition algorithm is used to extract contours, and convex quadrilaterals are fitted to all contours. Finally, the largest convex quadrilateral is selected based on its area, and its four vertices are determined. For a chess piece image, the electronic device performs Hue-Saturation-Value (HSV) segmentation on the perspective-transformed front view to remove the background, retaining only the chess piece image. The background-removed chess piece image is then preprocessed, including opening, edge detection, and dilation, and converted into a binary image.

[0117] Step 3: Take the contour information other than the contour information in the first contour set from the multiple contour information as the chess piece contour information.

[0118] Step 4: Use the contour information of the largest contour in the first contour set as the chessboard contour information.

[0119] The electronic device can determine the chessboard outline and the chessboard grid outline by using edge detection algorithms and convex quadrilateral fitting. The areas of the chessboard grid outlines are basically the same, while the area of ​​the chessboard outline is much larger than the area of ​​the chessboard grid outline. Therefore, the chessboard outline can be determined by calculating the area of ​​the outline.

[0120] Using the method provided in this application, after detecting multiple contour information in a chessboard image using an edge detection algorithm, where the contour information includes the contour information of the chessboard squares and the contour information of the chess pieces, to distinguish between the chessboard squares and the chess pieces, convex quadrilateral fitting can be performed on each contour information. The contour that meets the fitting conditions is taken as the first contour information corresponding to the chessboard square. Then, the contour with the largest area is selected from it, and this contour is the contour of the chessboard, thus obtaining the chessboard contour information. The other contour information besides the contour information in the first contour set is the chess piece contour information included in the chessboard image. In this way, through convex quadrilateral fitting, chess pieces and chessboard squares can be quickly distinguished from a chessboard image.

[0121] S1013. Determine the vertices based on the chessboard outline information.

[0122] The vertices are the four outermost corners of the chessboard.

[0123] To further improve the accuracy of vertex positioning, the electronic device can continuously acquire multiple chessboard images. Then, for each chessboard image, it identifies the chessboard outline and the vertices within each image, thus obtaining the vertex coordinates from multiple chessboard images. For a vertex at the same corner of the chessboard, the variance and mean coordinates of that vertex are calculated for each chessboard image. If the variance is less than a preset variance threshold, the mean coordinates are used as the vertex coordinates, thereby determining the vertex position within the chessboard image.

[0124] S1014. Determine the chess piece image based on the chess piece outline information.

[0125] Using the method provided in the embodiments of this application, the chessboard image is binarized into a black and white binary image. The edges in the binary image can be accurately extracted, thereby obtaining chessboard outline information and chess piece outline information.

[0126] In one example, Figure 3(a) and Figure 3(b) are used to illustrate the chess piece image and the binary image. Figure 3(a) is a chess piece image cropped according to the chess piece outline information, and Figure 3(b) is a binary image of the chess piece image. The pixels in the chess piece image area are white, and the image outside the chess piece image area is black.

[0127] In some embodiments of this application, the above-described S103, obtaining the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines, can be implemented as S1031-S1037, such as... Figure 4 As shown:

[0128] S1031. Calculate the difference of the first intercepts of any two adjacent first-type lines and the difference of the second intercepts of any two adjacent second-type lines.

[0129] The method for calculating the intercept difference is described in the above embodiments and will not be repeated here.

[0130] S1032. Perform clustering operation on the first intercept difference to obtain the first cluster corresponding to the first type of straight line.

[0131] S1033. Perform clustering operation on the second intercept difference to obtain the second cluster corresponding to the second type of straight line.

[0132] Specifically, the K-means clustering algorithm can be used for clustering. In one example, the K-means clustering algorithm is initialized with two center vectors to achieve binary classification based on the first intercept difference. This application does not impose specific limitations on the clustering algorithm used.

[0133] S1034. The cluster with the most elements in the first cluster is taken as the first target cluster.

[0134] S1035. The cluster containing the most elements in the second cluster is taken as the second target cluster.

[0135] S1036. Calculate the mean of the first target cluster to obtain the first reference intercept difference.

[0136] S1037. Calculate the mean of the second target cluster to obtain the second reference intercept difference.

[0137] Using the method provided in the embodiments of this application, for lines of the same category, the first intercept difference of the first category of lines and the second intercept difference of the second category of lines are obtained by calculating the intercept difference between adjacent lines. Then, clustering operations are performed on the first intercept difference and the second intercept difference respectively. Through the clustering operation, intercept differences with small differences can be assigned to the same cluster. Therefore, the first reference intercept difference and the second reference intercept difference are calculated using the cluster containing the most elements, thereby ensuring the accuracy of the calculated first reference intercept difference and the second reference intercept difference.

[0138] Based on the above determination of the first reference intercept difference and the second reference intercept difference, the lines on the chessboard are calibrated using the first reference intercept difference and the second reference intercept difference, such as... Figure 5 As shown, for S104 above, the first type of straight line is calibrated using the first reference intercept difference, and the second type of straight line is calibrated using the second reference intercept difference, resulting in the first type of calibration straight line and the second type of calibration straight line. The specific calibration process is as follows:

[0139] S1041. Based on the first intercept difference of each first type of straight line, determine the first target straight line with the smallest difference from the first reference intercept difference among the first type of straight lines.

[0140] Specifically, for each physical line on the chessboard, the aforementioned line detection algorithm may detect multiple corresponding lines. Therefore, the electronic device needs to determine the correct target line from these multiple detected lines for each line. Based on this, the intercept difference for each detected line is calculated, and the detected line with the smallest difference from the first reference intercept difference is selected as the first target line.

[0141] S1042. Determine the first correct line adjacent to the first target line among the first type of straight lines according to the first reference intercept difference.

[0142] Specifically, after determining the first target line, the system searches for the entity line adjacent to the entity line corresponding to the first target line in the chessboard image, and then determines the first correct line adjacent to the first target line in the detection lines corresponding to the adjacent entity lines according to the first reference intercept difference.

[0143] Specifically, if among the detection lines corresponding to adjacent entity lines there exists an intercept difference between the first target line and the first reference intercept difference, the electronic device can directly determine the first correct line. If among the detection lines corresponding to adjacent entity lines there does not exist an intercept difference between the first target line and the first reference intercept difference, the electronic device calculates the intercept differences between the first target line and multiple detection lines corresponding to adjacent entity lines, and selects the detection line with the smallest difference between its intercept difference and the first reference intercept difference as the first correct line.

[0144] S1043. Using the first correct line as the first target line, repeatedly execute the step of determining the first target line with the smallest difference from the first reference intercept difference among the first type of lines based on the first intercept difference corresponding to each first type of line, until a first preset number of first correct lines are determined to obtain the first type of calibration line.

[0145] The first preset quantity is determined based on the chessboard type and the type of the first type of straight line.

[0146] S1044. Based on the second intercept difference of each second type of line, determine the second target line with the smallest difference from the second reference intercept difference among the second type of lines.

[0147] S1045. Determine the second correct line adjacent to the second target line among the second type of lines according to the second reference intercept difference.

[0148] Specifically, the method for determining the second correct line is the same as the method for determining the first correct line, and will not be repeated here.

[0149] S1046. Using the second correct line as the second target line, repeatedly execute the step of determining the second target line with the smallest difference between the second type of lines and the second reference intercept difference based on the intercept difference corresponding to each second type of line, until a second preset number of second correct lines are determined to obtain the second type of calibration line.

[0150] The second preset quantity is determined based on the chessboard type and the type of the first type of straight line.

[0151] Using the method provided in this application, based on determining the first intercept difference and the second intercept difference, firstly, a first target line with the smallest difference in intercept difference with adjacent lines is determined among the first type of lines. The first target line is the first type of line with the most accurate positioning in the chessboard image. Then, adjacent lines of the first target line are searched according to the first intercept difference, thereby determining the first correct line adjacent to the first target line. In this way, based on the first intercept difference and the initially determined first target line, the correct lines in the first type of lines can be iteratively searched, ensuring the positioning accuracy of the first type of lines. Similarly, for the second type of lines, the correct lines in the second type of lines are iteratively searched in the same way, thereby ensuring the positioning accuracy of the chessboard lines in the chessboard image.

[0152] After calibrating and positioning the lines as described above, the intersection points of the first and second types of lines are calculated using the linear expression for each line, thereby determining the corner points on the chessboard. For example... Figure 6 As shown, Figure 6 An example is shown of the corners and vertices of a chessboard.

[0153] Furthermore, according to S106 above, after constructing a chess piece detection region with a preset side length corresponding to each chessboard corner point centered on the chessboard corner point and vertex, the electronic device calculates the overlap ratio between the chess piece image and the chess piece detection region, determines the corner point position of each chess piece image, and uses the target detection model to determine the category of the chess piece corresponding to each chess piece image, as shown in Figure 7(a), where 7(a) is the chessboard image and Figure 7(b) is the probability of each chess piece belonging to the category output by the target detection model.

[0154] In some embodiments of this application, since the position of the chessboard may change due to external factors after the chessboard is located, such as changes caused by a player's move, the electronic device can recalibrate the chessboard's positioning. Specifically, in S107 above, when the overlap ratio between the area of ​​the chess piece image and the area of ​​the chess piece detection region is greater than a preset threshold, after identifying the category of the chess pieces in the chess piece image using a target detection model and obtaining the positions of different categories of chess pieces on the chessboard, the method further includes:

[0155] Step A: When the position information of different types of pieces on the chessboard is abnormal, a contour recognition algorithm is used to identify the updated vertices of the chessboard image.

[0156] In this process, after the electronic device identifies the coordinates of the corner points of the chessboard, it caches the identified corner point coordinates and constructs a chess piece detection area according to the cached corner point coordinates. If the identified chess piece image and any chess piece detection area do not overlap, it is determined that there is an abnormal position information.

[0157] Specifically, the method for electronic devices to identify and update vertices refers to the method for identifying vertices in the above embodiments, and will not be repeated here.

[0158] Step B: Calculate the coordinate transformation matrix based on the updated vertex coordinates and the vertex coordinates of the vertex.

[0159] Step C: Use the coordinate transformation matrix to transform the coordinates of the chessboard corner points to obtain the updated chessboard corner point coordinates.

[0160] like Figure 8 As shown, after the electronic device completes the positioning of the chessboard, the position of the chessboard changes in the subsequent captured images. Therefore, based on the latest captured image, the electronic device identifies the vertices of the chessboard, calculates the coordinate transformation matrix by calculating the vertices of the latest captured image, and then uses the coordinate transformation matrix to transform the coordinates of the corner points of the chessboard to obtain the updated coordinates of the chessboard corner points.

[0161] Using the method provided in this application, when abnormal position information is detected on the chessboard, the electronic device re-identifies the chessboard image to obtain updated vertices. A coordinate transformation matrix can be calculated using the updated vertices and their coordinates. Since the relationship between the positions of the corner points and the vertices on the chessboard is fixed, the coordinate transformation matrix can be used to transform the coordinates of the chessboard corner points, thereby obtaining updated corner point coordinates. This enables rapid positioning of the chessboard corner points, improving positioning efficiency and accuracy.

[0162] Based on the same concept, embodiments of this application provide a device for chess game recognition, such as... Figure 9 As shown, the device includes:

[0163] The contour recognition module 901 is used to identify the outermost vertex and chess piece images of the chessboard in the chessboard image according to the contour recognition algorithm;

[0164] The line detection module 902 is used to perform line detection on the chessboard image to obtain a first type of line and a second type of line contained in the chessboard image, wherein the first type of line and the second type of line intersect perpendicularly.

[0165] The acquisition module 903 is used to acquire the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines. The first reference intercept difference is used to represent the distance between two adjacent first type straight lines in the chessboard image, and the second reference intercept difference is used to represent the distance between two adjacent second type straight lines in the chessboard image.

[0166] The calibration module 904 is used to calibrate the first type of straight line using the first reference intercept difference and to calibrate the second straight line using the second reference intercept difference, so as to obtain the first type of calibration straight line and the second type of calibration straight line.

[0167] The calculation module 905 is used to calculate the intersection of the first type of calibration line and the second type of calibration line to obtain the corner points of the chessboard;

[0168] Construction module 906 is used to construct a chess piece detection area with a preset side length corresponding to each chessboard corner point, centered on the chessboard corner point and the vertex point;

[0169] The recognition module 907 is used to identify the category of chess pieces in the chess piece image by using a target detection model when the ratio of the overlapping area of ​​the area of ​​the chess piece image and the area of ​​the chess piece detection area is greater than a preset threshold, thereby obtaining the position of different categories of chess pieces on the chessboard.

[0170] In one possible implementation, the contour recognition module 901 is specifically used for:

[0171] The chessboard image is binarized to obtain a binary image of the chessboard image;

[0172] An edge detection algorithm is used to identify the chessboard outline information and chess piece outline information in the binary image;

[0173] The vertices are determined based on the chessboard outline information;

[0174] The chess piece image is determined based on the chess piece outline information.

[0175] In one possible implementation, the contour recognition module 901 is specifically used for:

[0176] The edge detection algorithm described above is used to obtain multiple contour information in the chessboard image;

[0177] A first contour set is obtained by fitting convex quadrilaterals to the multiple contour information;

[0178] The contour information other than the contour information in the first contour set is taken as the chess piece contour information;

[0179] The contour information of the largest contour in the first contour set is used as the chessboard contour information.

[0180] In one possible implementation, module 903 is used specifically for:

[0181] Calculate the difference of the first intercepts of any pair of adjacent lines of the first type and the difference of the second intercepts of any pair of adjacent lines of the second type;

[0182] Perform a clustering operation on the first intercept difference to obtain the first cluster corresponding to the first type of straight line;

[0183] Perform a clustering operation on the second intercept difference to obtain the second cluster corresponding to the second type of straight line;

[0184] The cluster containing the most elements in the first cluster is taken as the first target cluster;

[0185] The cluster containing the most elements in the second cluster is taken as the second target cluster;

[0186] Calculate the mean of the first target cluster to obtain the first reference intercept difference;

[0187] Calculate the mean of the second target cluster to obtain the second reference intercept difference.

[0188] In one possible implementation, calibration module 904 is used for:

[0189] Based on the first intercept difference of each first type of straight line, determine the first target straight line with the smallest difference from the first reference intercept difference among the first type of straight lines;

[0190] Determine the first correct line adjacent to the first target line among the first type of lines according to the first reference intercept difference;

[0191] The first correct line is used as the first target line. The step of determining the first target line with the smallest difference from the first reference intercept difference among the first type of lines is executed repeatedly based on the first intercept difference corresponding to each first type of line until a first preset number of first correct lines are determined to obtain the first type of calibration line.

[0192] Based on the second intercept difference of each second type of line, determine the second target line among the second type of lines with the smallest difference from the second reference intercept difference;

[0193] Determine the second correct line adjacent to the second target line in the second type of straight lines according to the second reference intercept difference;

[0194] Using the second correct line as the second target line, the process of repeatedly executing the step of determining the second target line with the smallest difference between the second type of lines and the second reference intercept difference based on the intercept difference corresponding to each second type of line is repeated until a second preset number of second correct lines are determined to obtain the second type of calibration line.

[0195] In one possible implementation, the acquisition module 903 is further configured to acquire the side length of the bounding box corresponding to each chess piece image, wherein the chess piece image and the inner wall of the bounding box are tangent.

[0196] The calculation module 905 is also used to calculate the mean side length of the bounding box corresponding to each chess piece image to obtain the mean side length;

[0197] The calculation module 905 is also used to calculate a preset multiple of the mean side length to obtain the preset side length.

[0198] In one possible implementation, the device further includes:

[0199] The identification module is used to identify the updated vertices of the chessboard image using the contour recognition algorithm when the position information of the different categories of chess pieces on the chessboard is abnormal.

[0200] The calculation module 905 is also used to calculate a coordinate transformation matrix based on the vertex coordinates of the updated vertex and the vertex coordinates of the vertex;

[0201] The coordinate transformation module is used to perform coordinate transformation on the coordinates of the chessboard corner points using the coordinate transformation matrix to obtain updated chessboard corner point coordinates.

[0202] It should be noted that the chess game recognition device is the same as the chess game recognition method described above. All implementation methods in the above method embodiments are applicable to the embodiments of this device and can achieve the same technical effect.

[0203] Figure 10 A schematic diagram of the hardware structure of the electronic device provided in an embodiment of this application is shown.

[0204] The electronic device may include a processor 1001 and a memory 1002 storing computer program instructions.

[0205] Specifically, the processor 1001 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0206] Memory 1002 may include mass storage for data or instructions. For example, and not limitingly, memory 1002 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 1002 may include removable or non-removable (or fixed) media. Where appropriate, memory 1002 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 1002 is non-volatile solid-state memory.

[0207] In a particular embodiment, memory 1002 may include read-only memory (ROM), random access memory (RAM), disk storage media device, optical storage media device, flash memory device, electrical, optical, or other physical / tangible memory storage device. Thus, generally, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the methods according to one aspect of this disclosure.

[0208] The processor 1001 reads and executes computer program instructions stored in the memory 1002 to implement any of the chess game recognition methods in the above embodiments.

[0209] In one example, the electronic device may also include a communication interface 1003 and a bus 1004. For example, Figure 10 As shown, the processor 1001, memory 1002, and communication interface 1003 are connected through bus 1004 and complete communication with each other.

[0210] The communication interface 1003 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.

[0211] Bus 1004 includes hardware, software, or both, that couples components of an electronic device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Super Transmission (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 1004 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.

[0212] Furthermore, in conjunction with the chess game recognition method in the above embodiments, this application embodiment can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the chess game recognition methods in the above embodiments.

[0213] This application also provides a computer program product, including a computer program that, when executed, implements any of the chess game recognition methods described in the above embodiments.

[0214] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.

[0215] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on machine-readable media or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable media" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable read-only memory (EROM), floppy disks, compact disc read-only memory (CD-ROM), optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.

[0216] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.

[0217] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.

[0218] The above are merely specific embodiments of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.

Claims

1. A method for chess game recognition, characterized in that, include: The outermost vertices and chess pieces in the chessboard image are identified using a contour recognition algorithm. Line detection is performed on the chessboard image to obtain a first type of line and a second type of line contained in the chessboard image, wherein the first type of line and the second type of line intersect perpendicularly. A first reference intercept difference of the first type of straight lines and a second reference intercept difference of the second type of straight lines are obtained. The first reference intercept difference is used to represent the distance between two adjacent first type straight lines in the chessboard image, and the second reference intercept difference is used to represent the distance between two adjacent second type straight lines in the chessboard image. The first reference intercept difference is used to cluster the intercept differences of adjacent first type straight lines to obtain a first type of cluster, and the average of the first type of cluster with the largest sample size is obtained. The second reference intercept difference is used to cluster the intercept differences of adjacent second type straight lines to obtain a second type of cluster, and the average of the second type of cluster with the largest sample size is obtained. The first type of straight line is calibrated using the first reference intercept difference, and the second type of straight line is calibrated using the second reference intercept difference to obtain the first type of calibration straight line and the second type of calibration straight line; Calculate the intersection of the first type of calibration line and the second type of calibration line to obtain the chessboard corner points; With the corner point and the vertex of the chessboard as the center, a chess piece detection area of ​​a preset side length is constructed for each chessboard corner point; If the ratio of the overlapping area between the area of ​​the chess piece image and the area of ​​the chess piece detection region is greater than a preset threshold, the target detection model is used to identify the category of the chess piece in the chess piece image and obtain the position of different categories of chess pieces on the chessboard. The step of calibrating the first type of straight line using the first reference intercept difference and calibrating the second type of straight line using the second reference intercept difference to obtain the first type of calibrated straight line and the second type of calibrated straight line includes: Based on the first intercept difference of each first type of straight line, determine the first target straight line with the smallest difference from the first reference intercept difference among the first type of straight lines; Determine the first correct line adjacent to the first target line among the first type of lines according to the first reference intercept difference; The first correct line is used as the first target line. The step of determining the first target line with the smallest difference from the first reference intercept difference among the first type of lines is executed repeatedly based on the first intercept difference corresponding to each first type of line until a first preset number of first correct lines are determined to obtain the first type of calibration line. Based on the second intercept difference of each second type of line, determine the second target line among the second type of lines with the smallest difference from the second reference intercept difference; Determine the second correct line adjacent to the second target line in the second type of straight lines according to the second reference intercept difference; Using the second correct line as the second target line, the process of repeatedly executing the step of determining the second target line with the smallest difference between the second type of lines and the second reference intercept difference based on the intercept difference corresponding to each second type of line is repeated until a second preset number of second correct lines are determined to obtain the second type of calibration line.

2. The method according to claim 1, characterized in that, The step of identifying the outermost vertices and chess piece images of a chessboard image using a contour recognition algorithm includes: The chessboard image is binarized to obtain a binary image of the chessboard image; An edge detection algorithm is used to identify the chessboard outline information and chess piece outline information in the binary image; The vertices are determined based on the chessboard outline information; The chess piece image is determined based on the chess piece outline information.

3. The method according to claim 2, characterized in that, The step of using an edge detection algorithm to identify the chessboard outline information and chess piece outline information in the binary image includes: The edge detection algorithm described above is used to obtain multiple contour information in the chessboard image; A first contour set is obtained by fitting convex quadrilaterals to the multiple contour information; The contour information other than the contour information in the first contour set is taken as the chess piece contour information; The contour information of the largest contour in the first contour set is used as the chessboard contour information.

4. The method according to claim 1, characterized in that, The step of obtaining the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines includes: Calculate the difference of the first intercepts of any pair of adjacent lines of the first type and the difference of the second intercepts of any pair of adjacent lines of the second type; Perform a clustering operation on the first intercept difference to obtain the first cluster corresponding to the first type of straight line; Perform a clustering operation on the second intercept difference to obtain the second cluster corresponding to the second type of straight line; The cluster containing the most elements in the first cluster is taken as the first target cluster; The cluster containing the most elements in the second cluster is taken as the second target cluster; Calculate the mean of the first target cluster to obtain the first reference intercept difference; Calculate the mean of the second target cluster to obtain the second reference intercept difference.

5. The method according to claim 1, characterized in that, Before constructing a chess piece detection region of a preset side length corresponding to each chessboard corner point, centered on the chessboard corner point and the vertex point, the method further includes: Obtain the side length of the bounding box corresponding to each chess piece image, wherein the chess piece image is tangent to the inner wall of the bounding box; Calculate the mean side length of the bounding box corresponding to each chess piece image to obtain the mean side length; The preset side length is obtained by calculating a preset multiple of the mean side length.

6. The method according to claim 1, characterized in that, After identifying the categories of chess pieces in the chess piece image using an object detection model and obtaining the positions of different categories of chess pieces on the chessboard, the method further includes: In the event of abnormal position information of different categories of chess pieces on the chessboard, the contour recognition algorithm is used to identify the updated vertices of the chessboard image; Calculate the coordinate transformation matrix based on the updated vertex coordinates and the vertex coordinates of the vertex; The coordinates of the chessboard corner points are transformed using the coordinate transformation matrix to obtain the updated chessboard corner point coordinates.

7. A device for chess game recognition, characterized in that, include: The contour recognition module is used to identify the outermost vertices and chess piece images in a chessboard image based on the contour recognition algorithm. A line detection module is used to perform line detection on the chessboard image to obtain a first type of line and a second type of line contained in the chessboard image, wherein the first type of line and the second type of line intersect perpendicularly. The acquisition module is used to acquire the first reference intercept difference of the first type of straight lines and the second reference intercept difference of the second type of straight lines. The first reference intercept difference is used to represent the distance between two adjacent first type straight lines in the chessboard image, and the second reference intercept difference is used to represent the distance between two adjacent second type straight lines in the chessboard image. The first reference intercept difference is used to cluster the intercept differences of adjacent first type straight lines to obtain a first type of cluster, and the average value of the first type of cluster with the largest sample size is obtained. The second reference intercept difference is used to cluster the intercept differences of adjacent second type straight lines to obtain a second type of cluster, and the average value of the second type of cluster with the largest sample size is obtained. The calibration module is used to calibrate the first type of straight line using the first reference intercept difference and to calibrate the second type of straight line using the second reference intercept difference, so as to obtain the first type of calibration straight line and the second type of calibration straight line. The calculation module is used to calculate the intersection of the first type of calibration line and the second type of calibration line to obtain the corner points of the chessboard; The construction module is used to construct a chess piece detection area with a preset side length corresponding to each chessboard corner point, centered on the chessboard corner point and the vertex point; The identification module is used to identify the category of chess pieces in the chess piece image using a target detection model when the ratio of the overlapping area of ​​the area of ​​the chess piece image and the area of ​​the chess piece detection region is greater than a preset threshold, and to obtain the position of different categories of chess pieces on the chessboard. The calibration module is specifically used for: Based on the first intercept difference of each first type of straight line, determine the first target straight line with the smallest difference from the first reference intercept difference among the first type of straight lines; Determine the first correct line adjacent to the first target line among the first type of lines according to the first reference intercept difference; The first correct line is used as the first target line. The step of determining the first target line with the smallest difference from the first reference intercept difference among the first type of lines is executed repeatedly based on the first intercept difference corresponding to each first type of line until a first preset number of first correct lines are determined to obtain the first type of calibration line. Based on the second intercept difference of each second type of line, determine the second target line among the second type of lines with the smallest difference from the second reference intercept difference; Determine the second correct line adjacent to the second target line in the second type of straight lines according to the second reference intercept difference; Using the second correct line as the second target line, the process of repeatedly executing the step of determining the second target line with the smallest difference between the second type of lines and the second reference intercept difference based on the intercept difference corresponding to each second type of line is repeated until a second preset number of second correct lines are determined to obtain the second type of calibration line.

8. An electronic device, characterized in that, The electronic device includes: a processor and a memory storing computer program instructions; The processor executes computer program instructions to implement the chess game recognition method as described in any one of claims 1-6.

9. A computer storage medium, characterized in that, The computer storage medium stores computer program instructions, which, when executed by a processor, implement the chess game recognition method as described in any one of claims 1-6.

10. A computer program product, characterized in that, When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device performs the chess game recognition method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Chessboard positioning method and device, equipment and storage medium

    CN113838032A

  • Chess piece identifying and positioning method based on chess robot visual system

    CN118537621A