Chessboard Image Correction Method, Device, Electronic Device and Storage Medium
By detecting the chess pieces in the chessboard image, forming chess strings, calculating the relative coordinates of the chess pieces and reconstructing the image, the problem of inaccurate chess piece positioning caused by distortion in chessboard detection is solved, and the accuracy of chess piece positioning is improved.
Patent Information
- Application Number
- CN202411192800.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2044-08-28
AI Technical Summary
In shooting scenes with high degree of freedom, chess board detection technology is prone to inaccurate positioning of chess pieces due to image distortion, and the existing technology has many restrictions on the shooting position and angle of chess board.
By detecting the chess pieces in the chessboard image, we form a chess string, and use the absolute coordinates of the adjacent chess pieces to calculate the relative coordinates of the chess pieces, and reconstruct the image based on the relative coordinates to correct the chessboard image.
It effectively reduces the problem of inaccurate positioning of chess pieces caused by image distortion and improves the accuracy of chess piece positioning.
Smart Images

Figure CN119067894B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular, to a method, apparatus, electronic device, and storage medium for correcting a chessboard image. Background Art
[0002] In the field of computer vision, object detection is one of the important research topics. Among them, chessboard detection has broad application prospects in fields such as game AI, graphic recognition, and human-computer interaction. With the development of deep learning technology, more and more researchers apply deep learning to chessboard detection and have achieved remarkable results.
[0003] In the deep learning-based chessboard detection method, the accuracy of the chessboard detection result will directly affect the win or loss of the game on the board, and the shooting quality of the chessboard image is an important factor affecting the accuracy of the chessboard detection result. This leads to strict restrictions on the chessboard shooting environment (such as light, etc.) and the chessboard shooting angle in the current chessboard detection technology.
[0004] Specifically, in a shooting scenario with a high degree of freedom, due to reasons such as the shooting angle, it is easy to cause inaccurate positioning results of the chess pieces on the chessboard. When the captured chessboard image is severely tilted, this problem is particularly prominent. Summary of the Invention
[0005] In view of this, the embodiments of the present disclosure provide a method, apparatus, electronic device, and storage medium for correcting a chessboard image to at least partially solve the above problems.
[0006] According to a first aspect of the embodiments of the present disclosure, a method for correcting a chessboard image is provided, including: detecting an initial image of a chessboard to obtain the piece category and absolute coordinates of each piece on the chessboard; grouping each piece according to the absolute coordinates of each piece on the chessboard to obtain a plurality of chess strings of the chessboard, where each piece belonging to the same chess string is located in the same row on the chessboard; obtaining the relative coordinates of each piece on the chessboard based on the two absolute coordinates of any two adjacent pieces in each chess string; and performing image reconstruction based on the relative coordinates and piece categories of each piece on the chessboard to obtain a corrected image of the chessboard.
[0007] According to a second aspect of the embodiments of the present disclosure, a checkerboard image correction device is provided, including: a detection module that detects an initial image of the checkerboard to obtain the piece type and absolute coordinates of each piece on the checkerboard; a grouping module that groups each piece according to the absolute coordinates of each piece on the checkerboard to obtain a plurality of strings of pieces on the checkerboard, where each piece belonging to the same string of pieces is located in the same row on the checkerboard; a conversion module that obtains the relative coordinates of each piece on the checkerboard based on the two absolute coordinates of any two adjacent pieces in each string of pieces; and a reconstruction module that performs image reconstruction based on the relative coordinates and piece types of each piece on the checkerboard to obtain a corrected image of the checkerboard.
[0008] According to a third aspect of the embodiments of the present disclosure, an electronic device is provided, including: a processor; and a memory storing a program, where the program includes instructions that, when executed by the processor, cause the processor to execute the checkerboard image correction method described in the first aspect above.
[0009] According to a fourth aspect of the embodiments of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, where the computer instructions are used to cause the computer to execute the checkerboard image correction method described in the first aspect.
[0010] In summary, the checkerboard image correction solutions provided in various aspects of the present disclosure can accurately correct the positional relationship between pieces by converting the absolute coordinates of the pieces into relative coordinates, and can improve the problem of inaccurate piece positioning caused by image distortion. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In the following description of exemplary embodiments with reference to the accompanying drawings, more details, features, and advantages of the present disclosure are disclosed. In the drawings:
[0012] Figure 1 is a processing flowchart of the checkerboard image correction method according to an exemplary embodiment of the present disclosure.
[0013] Figure 2 is a schematic diagram of a checkerboard according to an exemplary embodiment of the present disclosure.
[0014] Figure 3 is a processing flowchart of the checkerboard image correction method according to another exemplary embodiment of the present disclosure.
[0015] Figure 4 is a structural block diagram of the checkerboard image correction device according to an exemplary embodiment of the present disclosure.
[0016] Figure 5 is a schematic architecture diagram of the electronic device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0017] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Instead, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.
[0018] It should be understood that the various steps recorded in the method embodiments of the present disclosure can be executed in different orders and / or executed in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this regard.
[0019] As used herein, the term "including" and its variations are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description. It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order of the functions executed by these devices, modules or units or their interdependent relationships.
[0020] It should be noted that the modifications of "one" and "plural" mentioned in the present disclosure are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly stated in the context, it should be understood as "one or more". The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only for illustrative purposes and are not used to limit the scope of these messages or information.
[0021] Current chessboard detection technologies have many restrictions on the shooting position and shooting angle of the chessboard. In a shooting scenario with a high degree of freedom, it is easy for the captured image to be distorted, resulting in a poor recognition accuracy of the positions of the chess pieces on the chessboard.
[0022] In view of this, each embodiment of the present disclosure provides a chessboard image correction solution, and the specific implementation of each embodiment of the present disclosure will be described in detail below with reference to the accompanying drawings.
[0023] Figure 1 It is a processing flowchart of the chessboard image correction method according to an exemplary embodiment of the present disclosure. As shown in the figure, this embodiment mainly includes the following steps:
[0024] Step 102, detect the initial image of the chessboard to obtain the piece category and absolute coordinates of each piece on the chessboard.
[0025] In some embodiments, pre - processing of the initial image of the chessboard can be performed, including but not limited to: resizing, cropping, noise reduction, normalization, etc., to ensure that the image data can obtain the best effect in subsequent processing.
[0026] In some embodiments, classification detection can be performed on each target object in the initial image to obtain each chess piece on the chessboard and the chess piece category of each chess piece. The two diagonal points of the chessboard and the two diagonal points of each chess piece are respectively detected to obtain the absolute coordinates of each vertex angle of the chessboard and the absolute coordinates of each chess piece.
[0027] In this embodiment, the absolute coordinates of each chess piece are used to identify the center point position of each chess piece.
[0028] In some embodiments, an image detection model (e.g., a deep learning model) can be used to detect the initial image of the chessboard to obtain the chess piece category and absolute coordinates of each chess piece on the chessboard.
[0029] In this embodiment, the absolute coordinates of each chess piece are composed of a horizontal absolute coordinate and a vertical absolute coordinate.
[0030] In this embodiment, the chessboard can include a Go chessboard, and the chess piece categories can include the white chess category and the black chess category.
[0031] Specifically, an image detection model can be used to perform object detection on the initial image of the chessboard based on given category labels (white chess label and black chess label) to obtain the confidence value of each detected object on the chessboard, and each detected object with a confidence value greater than the confidence threshold (e.g., 0.8) is determined as each target object, where each obtained target object is the black chess and the white chess on the chessboard.
[0032] Preferably, an image detection model can be used to detect the corner coordinates of the lower - left and upper - right corners of the chess piece, that is, the minimum Xmin, Ymin coordinates and the maximum Xmax, Ymax coordinates. The horizontal and vertical sizes of the chess piece can be calculated as w = Xmax - Xmin, h = Ymax - Ymin according to the coordinates of the two diagonal points, so as to calculate the center point position of the chess piece, that is, the absolute coordinates of the chess piece.
[0033] In this embodiment, the image detection model also outputs the absolute coordinates of the 4 vertex angles of the chessboard. Among them, the detection means for the absolute coordinates of each vertex angle of the chessboard can refer to the description of the detection means for each corner point of the chess piece above.
[0034] Step 104: Group each chess piece according to the absolute coordinates of each chess piece on the chessboard to obtain multiple chess strings on the chessboard.
[0035] In this embodiment, each piece belonging to the same string of pieces is located in the same row on the chessboard. For example, in a Go chessboard, each piece belonging to the same string of pieces is located in the same row (horizontal row) or the same column (vertical row) on the Go chessboard.
[0036] For example, in Figure 2 the example shown, White Piece 1, White Piece 2, and White Piece 3 belong to the same string of pieces; White Piece 1, Black Piece 1, White Piece 7, White Piece 10, and Black Piece 9 belong to the same string of pieces.
[0037] In some embodiments, multiple strings of pieces on the chessboard include at least one horizontal string of pieces and at least one vertical string of pieces.
[0038] For example, in Figure 2 the example shown, the chessboard includes 5 horizontal strings of pieces and 7 vertical strings of pieces. Among them, White Piece 1, White Piece 2, and White Piece 3 belong to the same vertical string of pieces; White Piece 1, Black Piece 1, White Piece 7, White Piece 10, and Black Piece 9 belong to the same horizontal string of pieces, and so on.
[0039] In some embodiments, each string of pieces includes at least one piece. For example, in Figure 2 the example shown, the horizontal string of pieces 5 only includes White Piece 5.
[0040] In this embodiment, each piece is respectively grouped into a horizontal string of pieces and a vertical string of pieces on the chessboard.
[0041] For example, in Figure 2 the example shown, White Piece 1 belongs to both the horizontal string of pieces 1 and the vertical string of pieces 1, and White Piece 2 belongs to both the horizontal string of pieces 2 and the vertical string of pieces 1.
[0042] Step 106: Based on the two absolute coordinates of any two adjacent pieces in each string of pieces, obtain the relative coordinates of each piece on the chessboard.
[0043] In some embodiments, any string of pieces can be determined as the current string of pieces. According to the arrangement order of the pieces in the current string of pieces, one piece in the current string of pieces is sequentially determined as the current piece, and the previous piece of the current piece is determined as the previous piece.
[0044] For example, in Figure 2 the example shown, the horizontal string of pieces (hereinafter referred to as the horizontal string of pieces 1) composed of White Piece 1, Black Piece 1, White Piece 7, White Piece 10, and Black Piece 9 can be used as the current string of pieces. The pieces in the horizontal string of pieces 1 can be arranged in order based on their absolute coordinates to obtain the piece sequence of the horizontal string of pieces 1: that is, White Piece 1, Black Piece 1, White Piece 7, White Piece 10, and Black Piece 9. Among them, when Black Piece 1 is used as the current piece, White Piece 1 is the previous piece of Black Piece 1. When White Piece 7 is used as the current piece, the previous piece should be Black Piece 1.
[0045] In this embodiment, the relative coordinates of the previous chess piece can be determined. Based on the absolute coordinates of the current chess piece and the absolute coordinates of the previous chess piece, the interval distance between the current chess piece and the previous chess piece can be obtained. Based on the grid size of the chessboard, the interval distance between the current chess piece and the previous chess piece, and the relative coordinates of the previous chess piece, the relative coordinates of the current chess piece can be obtained.
[0046] Specifically, based on the absolute coordinates of the current chess piece and the absolute coordinates of the previous chess piece, the interval distance between the current chess piece and the previous chess piece can be obtained. By dividing the interval distance by the grid size of the chessboard, the additional coordinate value of the current chess piece can be obtained, and through the addition operation based on the relative coordinates of the previous chess piece and the additional coordinate value of the current chess piece, the relative coordinates of the current chess piece can be obtained.
[0047] In this embodiment, the relative coordinates of each chess piece are composed of a horizontal relative coordinate and a vertical relative coordinate. Therefore, based on the two horizontal absolute coordinates of any two adjacent chess pieces in each horizontal chess string, the horizontal relative coordinates of each chess piece on the chessboard can be identified. Based on the two vertical absolute coordinates of any two adjacent chess pieces in each vertical chess string, the vertical relative coordinates of each chess piece on the chessboard can be identified.
[0048] For example, when the current chess string is horizontal chess string 1 and the current chess piece is black chess 1, the horizontal interval distance between black chess 1 and white chess 1 can be obtained according to the horizontal absolute coordinates of black chess 1 and white chess 1 respectively. Then, by dividing the horizontal interval distance by the grid size of the chessboard, the horizontal additional coordinate value of black chess 1 is obtained as "1". Through the addition operation based on the horizontal relative coordinate "1" of white chess 1 and the horizontal additional coordinate value "1" of black chess 1, the horizontal relative coordinate of black chess 1 is obtained as "2".
[0049] Another example, when the current chess string is horizontal chess string 1 and the current chess piece is white chess 7, the horizontal interval distance between black chess 1 and white chess 7 can be obtained according to the horizontal absolute coordinates of black chess 1 and white chess 7 respectively. Then, by dividing the horizontal interval distance by the grid size of the chessboard, the horizontal additional coordinate value of white chess 7 is obtained as "2". Through the addition operation based on the horizontal relative coordinate "2" of black chess 1 and the horizontal additional coordinate value "2" of white chess 7, the horizontal relative coordinate of white chess 7 is obtained as "4".
[0050] In this embodiment, the horizontal relative coordinates and the vertical relative coordinates of the same chess piece on the chessboard can be combined to obtain the relative coordinates of each chess piece on the chessboard. For example, the relative coordinate of white chess 1 is (1, 1), the relative coordinate of black chess 1 is (1, 2), the relative coordinate of white chess 2 is (2, 1), and so on.
[0051] In some embodiments, when the current chess piece is the first chess piece in the current chess string, the interval distance between the current chess piece and the given reference position on the chessboard is obtained according to the absolute coordinates of the current chess piece and the absolute coordinates of the given reference position on the chessboard, and the relative coordinates of the current chess piece are obtained based on the grid size of the chessboard and the interval distance between the current chess piece and the given reference position.
[0052] Reference Figure 2 , when the current chess string is the horizontal chess string 1 and the current chess piece is the white chess 1, the horizontal interval distance between the white chess 1 and the given reference position can be calculated, and the horizontal interval distance is divided by the grid size of the chessboard to obtain the horizontal additional coordinate value of the white chess 1 as "1". According to the sum result of the horizontal relative coordinate "0" of the given reference position and the horizontal additional coordinate value of "1" to the white chess 1, the horizontal relative coordinate of the white chess 1 is obtained as "1".
[0053] Step 108: Perform image reconstruction based on the relative coordinates and piece types of each chess piece on the chessboard to obtain a corrected image of the chessboard.
[0054] In some embodiments, according to the given reference position in the standard grid of the chessboard, the relative coordinates or absolute coordinates of each chess piece, the chess piece closest to the given reference position among the chess pieces can be determined as the reference chess piece, and each chess piece other than the reference chess piece can be determined as a non-reference chess piece.
[0055] In this example, a vertex position in the standard grid of the chessboard can be determined as the given reference position in the standard grid of the chessboard. For example, in Figure 2 the shown example, the lower left vertex of the chessboard can be determined as the given reference position, and the white chess 1 closest to the lower left vertex can be determined as the reference chess piece, and the white chess 2 to white chess 10 and the black chess 1 to black chess 10 can be determined as non-reference chess pieces.
[0056] In some embodiments, based on the given reference position on the chessboard and the relative coordinates of the reference chess piece, the positioning position of the reference chess piece in the standard grid can be determined. Based on the positioning position of the reference chess piece and the relative coordinates of each non-reference chess piece, the positioning position of each non-reference chess piece in the standard grid of the chessboard can be determined. And based on the positioning positions of the reference chess piece and each non-reference chess piece in the standard grid, and the piece types of the reference chess piece and each non-reference chess piece, the standard grid is rendered to obtain a corrected image of the chessboard.
[0057] Exemplarily, first, based on the coordinate position of the lower-left vertex of the chessboard and the relative coordinates (1, 1) of the white chess piece 1, the positioning position of the white chess piece 1 in the standard chess grid can be determined. Then, based on the positioning position of the white chess piece 1 and the relative coordinates of each non-reference chess piece (i.e., white chess pieces 2 to 10 and black chess pieces 1 to 10), the positioning positions of each non-reference chess piece in the standard chess grid of the chessboard can be deduced, and based on this, image rendering processing is performed on the standard chess grid of the chessboard to obtain a corrected image of the chessboard.
[0058] In summary, the chessboard image correction device of this embodiment groups the chess pieces by detecting the absolute coordinates of each chess piece to obtain multiple chess strings on the chessboard, and then recursively calculates the relative coordinates of each chess piece according to the position arrangement order of the chess pieces in the chess string. Thus, the problem of inaccurate positioning of chess pieces caused by image distortion can be effectively reduced.
[0059] Specifically, the traditional solution usually uses a single reference point to position each chess piece on the chessboard. When there are distortion problems such as image distortion, the positioning deviation of the chess pieces farther from the reference point will be greater. This embodiment uses a recursive calculation solution to calculate the positioning positions of adjacent chess pieces in sequence, so that the relative position error between the corrected chess pieces will not exceed one chess grid, and the position relationship between the chess pieces can be accurately corrected to effectively improve the positioning accuracy of the chess pieces.
[0060] Figure 3 It is a processing flowchart of the chessboard image correction method according to another exemplary embodiment of the present disclosure. As shown in the figure, this embodiment shows the specific implementation solution of the above step 104.
[0061] It should be noted that the chess piece grouping scheme of this embodiment is only executed for one direction on the chessboard. By executing the respective processing steps of this embodiment twice, each horizontal chess string and each vertical chess string on the chessboard can be determined respectively.
[0062] To avoid obscuring the technical key points of this solution and facilitate readers to more clearly understand the technical solution of this embodiment, the following only describes the example of generating each horizontal chess string on the chessboard. The following solution is also applicable to generating each vertical chess string on the chessboard. First, it is stated as follows. As shown in the figure, this embodiment mainly includes the following steps:
[0063] Step 302: Determine each to-be-grouped chess piece that has not formed a chess string from the chess pieces on the chessboard.
[0064] For example, in Figure 2 the shown example, when the horizontal chess string 1 on the chessboard is determined, the white chess pieces 2 to 6, white chess piece 8, white chess piece 9, black chess pieces 2 to 8, and black chess piece 10 can be determined as the to-be-grouped chess pieces. When the horizontal chess string 1 and the horizontal chess string 2 on the chessboard are determined, the white chess pieces 3 to 6, white chess piece 8, black chess pieces 3 to 6, and black chess piece 8 can be determined as the to-be-grouped chess pieces.
[0065] Step 304: Based on the given reference position on the chessboard, determine a reference piece from each piece to be grouped, and determine each piece to be grouped that has not been determined as the reference piece as a candidate piece for the reference piece.
[0066] In this embodiment, based on the given reference position on the chessboard and the absolute coordinate positions of each piece, the piece to be grouped that is closest to the given reference position can be determined as the reference piece.
[0067] In this embodiment, the given reference position on the chessboard is determined based on the absolute coordinates of a vertex of the chessboard. For example, in Figure 2 the example shown, the lower left corner position of the chessboard can be determined as the given reference position.
[0068] Among them, in the case where no horizontal chess string has been determined, the white piece 1 (piece to be grouped) is the reference piece closest to the given reference position, and the white pieces 2 to 10 and the black pieces 1 to 10 are all candidate pieces for the white piece 1; in the case where the horizontal chess string 1 has been determined, the white piece 2 (piece to be grouped) is then the reference piece closest to the given reference position, and the white pieces 3 to 6, white piece 8, white piece 9, black pieces 2 to 8, and black piece 10 are candidate pieces for the white piece 2.
[0069] Step 306: According to the coordinate difference between the absolute coordinates of each candidate piece and the absolute coordinates of the reference piece, determine each target piece of the reference piece from the candidate pieces, and based on the reference piece and each target piece, form a chess string on the chessboard.
[0070] In this embodiment, that is, in the case of generating each horizontal chess string on the chessboard, the absolute vertical coordinates of each candidate piece can be subtracted from the absolute vertical coordinates of the reference piece to obtain the vertical offset value of each candidate piece relative to the reference piece. Each candidate piece with a vertical offset value less than the given vertical offset threshold is determined as the target piece of the reference piece, and based on the reference piece and each target piece, a horizontal chess string on the chessboard is formed.
[0071] In this embodiment, the given vertical offset threshold is determined based on the piece size of each piece.
[0072] Exemplarily, in the case where the reference piece is the white piece 1, the absolute vertical coordinates of each candidate piece can be traversed, and each candidate piece with a vertical deviation value not exceeding the radius of the piece (i.e., the black piece 1, white piece 7, white piece 10, black piece 9) is determined as the target piece of the white piece 1, and based on the white piece 1, i.e., the black piece 1, white piece 7, white piece 10, black piece 9, the horizontal chess string 1 on the chessboard is formed.
[0073] In some other embodiments, when generating each vertical chess string on the chessboard through this embodiment, the absolute horizontal coordinate of each candidate chess piece can be subtracted from the absolute horizontal coordinate of the reference chess piece to obtain the horizontal offset value of each candidate chess piece relative to the reference chess piece. Each candidate chess piece with a horizontal offset value less than the given horizontal offset threshold is determined as the target chess piece of the reference chess piece. Based on the reference chess piece and each target chess piece, a vertical chess string on the chessboard is formed. Among them, the given horizontal offset threshold can also be determined based on the size of each chess piece.
[0074] In some embodiments, when there is no target chess piece of the reference chess piece among the candidate chess pieces, a chess string on the chessboard is directly formed based on the reference chess piece. For example, Figure 2 the horizontal chess string 5 shown.
[0075] Step 308, determine whether there are chess pieces to be grouped on the chessboard. If so, return to step 302; otherwise, proceed to step 310.
[0076] Specifically, when it is determined that there are no chess pieces to be grouped on the chessboard, it means that the grouping operation of all chess pieces on the chessboard has been completed.
[0077] Step 310, obtain each chess string on the chessboard.
[0078] In summary, based on the absolute coordinates of each chess piece, this embodiment recursively traverses each chess piece to group the chess pieces into multiple chess strings for subsequent conversion processing of the relative coordinates of the chess pieces, realizing the automatic correction processing of the relative positions between the chess pieces and improving the positioning accuracy of the chess pieces.
[0079] Figure 4 The structural block diagram of the chessboard image correction device according to an exemplary embodiment of the present disclosure is shown. As shown in the figure, the chessboard image correction device 400 of this embodiment includes:
[0080] A detection module 402 that detects the initial image of the chessboard to obtain the chess piece category and absolute coordinates of each chess piece on the chessboard;
[0081] A grouping module 404 that groups each chess piece according to the absolute coordinates of each chess piece on the chessboard to obtain multiple chess strings on the chessboard, where each chess piece belonging to the same chess string is located in the same row on the chessboard;
[0082] A conversion module 406 that obtains the relative coordinates of each chess piece on the chessboard based on the two absolute coordinates of any two adjacent chess pieces in each chess string;
[0083] A reconstruction module 408 that performs image reconstruction based on the relative coordinates and chess piece categories of each chess piece on the chessboard to obtain the corrected image of the chessboard.
[0084] In some embodiments, the detection module 402 is further configured to: classify and detect each target object in the initial image to obtain each chess piece on the chessboard and the chess piece category of each chess piece; respectively detect two diagonal points of the chessboard and two diagonal points of each chess piece to obtain the absolute coordinates of each vertex angle of the chessboard and the absolute coordinates of each chess piece; wherein, the absolute coordinates of each chess piece are used to identify the center point position of each chess piece.
[0085] In some embodiments, the grouping module 404 is further configured to: determine each ungrouped chess piece that has not formed a chess string from the chess pieces on the chessboard; based on a given reference position of the chessboard, determine a reference chess piece from each ungrouped chess piece, and determine each ungrouped chess piece that has not been determined as the reference chess piece as a candidate chess piece of the reference chess piece; according to the coordinate difference between the absolute coordinates of each candidate chess piece and the absolute coordinates of the reference chess piece, determine each target chess piece of the reference chess piece from each candidate chess piece, and based on the reference chess piece and each target chess piece, form a chess string of the chessboard; return to execute the step of determining each ungrouped chess piece that has not formed a chess string from the chess pieces on the chessboard until there are no ungrouped chess pieces on the chessboard.
[0086] In some embodiments, the grouping module 404 is further configured to: based on the given reference position of the chessboard and the absolute coordinate position of each chess piece, determine an ungrouped chess piece closest to the given reference position as the reference chess piece; wherein, the given reference position is determined based on an absolute coordinate of a vertex angle of the chessboard.
[0087] In some embodiments, each chess string includes at least one chess piece.
[0088] In some embodiments, the grouping module 404 is further configured to: in the case that there is no target chess piece of the reference chess piece among the candidate chess pieces, directly form a chess string of the chessboard based on the reference chess piece.
[0089] In some embodiments, the multiple chess strings include at least one horizontal chess string and at least one vertical chess string, and the absolute coordinates of each chess piece are composed of a horizontal absolute coordinate and a vertical absolute coordinate.
[0090] In some embodiments, the grouping module 404 is further configured to: calculate the difference between the absolute vertical coordinates of each candidate chess piece and the absolute vertical coordinates of the reference chess piece to obtain the vertical offset value of each candidate chess piece relative to the reference chess piece; determine each candidate chess piece with a vertical offset value less than a given vertical offset threshold as the target chess piece of the reference chess piece; based on the reference chess piece and each target chess piece, form a horizontal chess string of the chessboard.
[0091] In some embodiments, the grouping module 404 is further configured to: calculate the difference between the absolute horizontal coordinate of each candidate chess piece and the absolute horizontal coordinate of the reference chess piece to obtain the horizontal offset value of each candidate chess piece relative to the reference chess piece; determine each candidate chess piece with a horizontal offset value less than a given horizontal offset threshold as the target chess piece of the reference chess piece; and form a vertical chess string of the chessboard based on the reference chess piece and each target chess piece.
[0092] In some embodiments, the given vertical offset threshold or the given horizontal offset threshold is determined based on the size of each chess piece.
[0093] In some embodiments, the conversion module 406 is further configured to: determine any one chess string as the current chess string; sequentially determine one chess piece in the current chess string as the current chess piece according to the arrangement order of the chess pieces in the current chess string, determine the previous chess piece of the current chess piece as the previous consecutive chess piece, and determine the relative coordinate of the previous consecutive chess piece; obtain the interval distance between the current chess piece and the previous consecutive chess piece according to the absolute coordinate of the current chess piece and the absolute coordinate of the previous consecutive chess piece; and obtain the relative coordinate of the current chess piece based on the chess grid size of the chessboard, the interval distance between the current chess piece and the previous consecutive chess piece, and the relative coordinate of the previous consecutive chess piece.
[0094] In some embodiments, the conversion module 406 is further configured to: in the case where the current chess piece is the first chess piece in the current chess string, obtain the interval distance between the current chess piece and a given reference position of the chessboard according to the absolute coordinate of the current chess piece and the absolute coordinate of the given reference position of the chessboard; and obtain the relative coordinate of the current chess piece based on the chess grid size of the chessboard and the interval distance between the current chess piece and the given reference position.
[0095] In some embodiments, the multiple chess strings include at least one horizontal chess string and at least one vertical chess string. Each chess piece is respectively grouped into one horizontal chess string and one vertical chess string of the chessboard. The absolute coordinate of each chess piece is composed of a horizontal absolute coordinate and a vertical absolute coordinate, and the relative coordinate of each chess piece is composed of a horizontal relative coordinate and a vertical relative coordinate.
[0096] In some embodiments, the conversion module 406 is further configured to: identify the horizontal relative coordinate of each chess piece on the chessboard based on the two horizontal absolute coordinates of any two adjacent chess pieces in each horizontal chess string, and identify the vertical relative coordinate of each chess piece on the chessboard based on the two vertical absolute coordinates of any two adjacent chess pieces in each vertical chess string; and combine the horizontal relative coordinate and the vertical relative coordinate of the same chess piece on the chessboard to obtain the relative coordinate of each chess piece on the chessboard.
[0097] In some embodiments, the reconstruction module 408 is further configured to: determine, according to a given reference position in the standard chessboard squares of the chessboard, the relative coordinates or absolute coordinates of each chess piece, a chess piece closest to the given reference position among the chess pieces as a reference chess piece, and each chess piece other than the reference chess piece as a non-reference chess piece; determine the positioning position of the reference chess piece in the standard chessboard squares based on the given reference position of the chessboard and the relative coordinates of the reference chess piece; determine the positioning position of each non-reference chess piece in the standard chessboard squares of the chessboard based on the positioning position of the reference chess piece and the relative coordinates of each non-reference chess piece; and render the standard chessboard squares based on the positioning positions of the reference chess piece and each non-reference chess piece in the standard chessboard squares and the chess piece categories of the reference chess piece and each non-reference chess piece to obtain a corrected image of the chessboard.
[0098] Embodiments of the present disclosure further provide a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the chessboard image correction method according to the exemplary embodiments of the present disclosure.
[0099] Exemplary embodiments of the present disclosure further provide an electronic device including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, and when executed by the at least one processor, the computer program is configured to cause the electronic device to execute the chessboard image correction method according to the exemplary embodiments of the present disclosure.
[0100] Please refer to Figure 5 , and now a block diagram of an electronic device 500 that can be used as a server or a client of the present disclosure will be described. It is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0101] As Figure 5As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0102] Multiple components in the electronic device 500 are connected to the I / O interface 505, including: an input unit 506, an output unit 507, a storage unit 508, and a communication unit 509. The input unit 506 can be any type of device capable of inputting information into the electronic device 500. The input unit 506 can receive input digital or character information and generate key signal inputs related to the user settings and / or function controls of the electronic device. The output unit 507 can be any type of device capable of presenting information and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 508 can include, but is not limited to, magnetic disks and optical disks. The communication unit 509 allows the electronic device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks and can include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0103] The computing unit 501 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 501 executes the various methods and processes described above. For example, in some embodiments, the checkerboard image correction method as described above can be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as the storage unit 508. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 500 via the ROM 502 and / or the communication unit 509. In some embodiments, the computing unit 501 can be configured to execute the above-described checkerboard image correction method in any other appropriate way (e.g., by means of firmware).
[0104] The program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, a special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may execute entirely on the machine, partially on the machine, as a stand-alone software package partially on the machine and partially on a remote machine, or entirely on the remote machine or server.
[0105] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0106] As used in the present disclosure, the terms “machine-readable medium” and “computer-readable medium” refer to any computer program product, apparatus, and / or device (e.g., a disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term “machine-readable signal” refers to any signal for providing machine instructions and / or data to a programmable processor.
[0107] In order to provide interaction with a user, the systems and techniques described herein may be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0108] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), and the Internet.
[0109] A computer system can include a client and a server. The client and the server are generally remote from each other and typically interact via a communication network. The client-server relationship is created by computer programs that run on respective computers and have a client-server relationship with each other.
[0110] It should be noted that, according to the needs of implementation, each component / step described in the embodiments of the present disclosure can be split into more components / steps, or two or more components / steps or partial operations of components / steps can be combined into new components / steps to achieve the objectives of the embodiments of the present disclosure.
[0111] The above embodiments are only used to illustrate the embodiments of the present disclosure, rather than to limit the embodiments of the present disclosure. Those of ordinary skill in the relevant art can also make various changes and modifications without departing from the spirit and scope of the embodiments of the present disclosure. Therefore, all equivalent technical solutions also belong to the scope of the embodiments of the present disclosure. The patent protection scope of the embodiments of the present disclosure shall be defined by the claims.
Claims
1. A method for correcting a chessboard image, comprising: Detecting an initial image of the chessboard to obtain the piece category and absolute coordinates of each piece on the chessboard; Grouping each piece according to the absolute coordinates of each piece on the chessboard to obtain multiple strings of pieces on the chessboard, wherein each piece belonging to the same string of pieces is located in the same row on the chessboard; Based on the two absolute coordinates of any two adjacent pieces in each string of pieces, obtaining the relative coordinates of each piece on the chessboard, including: determining any one string of pieces as the current string of pieces, in accordance with the arrangement order of the pieces in the current string of pieces, successively determining one piece in the current string of pieces as the current piece, determining the previous piece of the current piece as the previous piece, and determining the relative coordinates of the previous piece, and based on the absolute coordinates of the current piece and the absolute coordinates of the previous piece, obtaining the distance between the current piece and the previous piece, and based on the chess grid size of the chessboard, the distance between the current piece and the previous piece, and the relative coordinates of the previous piece, obtaining the relative coordinates of the current piece; Performing image reconstruction based on the relative coordinates and piece categories of each piece on the chessboard to obtain a corrected image of the chessboard.
2. The method according to claim 1, wherein The detecting an initial image of the chessboard to obtain the piece category and absolute coordinates of each piece on the chessboard includes: Performing classification detection on each target object in the initial image to obtain each piece on the chessboard and the piece category of each piece; Respectively detecting two diagonal points of the chessboard and two diagonal points of each piece to obtain the absolute coordinates of each vertex angle of the chessboard and the absolute coordinates of each piece; Wherein, the absolute coordinates of each piece are used to identify the center point position of each piece.
3. The method according to claim 1, wherein, The grouping each piece according to the absolute coordinates of each piece on the chessboard to obtain multiple strings of pieces on the chessboard includes: Determining each piece to be grouped that has not formed a string of pieces from the pieces on the chessboard; Based on the given reference position of the chessboard, determining a reference piece from each piece to be grouped, and determining each piece to be grouped that has not been determined as the reference piece as a candidate piece for the reference piece; According to the coordinate difference between the absolute coordinates of each candidate piece and the absolute coordinates of the reference piece, determining each target piece of the reference piece from each candidate piece, and based on the reference piece and each target piece, forming a string of pieces on the chessboard; Returning to execute the step of determining each piece to be grouped that has not formed a string of pieces from the pieces on the chessboard until there are no pieces to be grouped on the chessboard.
4. The method according to claim 3, wherein The determining a reference piece from each piece to be grouped based on the given reference position of the chessboard includes: Based on the given reference position of the chessboard and the absolute coordinate positions of each piece, determining the piece to be grouped that is closest to the given reference position as the reference piece; Wherein, the given reference position is determined based on an absolute coordinate of a vertex angle of the chessboard.
5. The method according to claim 3, wherein Each string of pieces includes at least one piece; The method further includes: In the case that there is no target piece of the reference piece among the candidate pieces, directly form a chess string of the chessboard based on the reference piece.
6. The method according to any one of claims 3 to 5, wherein The multiple chess strings include at least one horizontal chess string and at least one vertical chess string, and the absolute coordinates of each piece are composed of a horizontal absolute coordinate and a vertical absolute coordinate; Among them, any horizontal chess string of the chessboard is formed in the following way: Perform a difference calculation on the absolute vertical coordinates of each candidate piece and the absolute vertical coordinate of the reference piece to obtain the vertical offset value of each candidate piece relative to the reference piece; Determine each candidate piece with a vertical offset value less than a given vertical offset threshold as the target piece of the reference piece; Based on the reference piece and each target piece, form a horizontal chess string of the chessboard; Among them, any vertical chess string of the chessboard is formed in the following way: Perform a difference calculation on the absolute horizontal coordinates of each candidate piece and the absolute horizontal coordinate of the reference piece to obtain the horizontal offset value of each candidate piece relative to the reference piece; Determine each candidate piece with a horizontal offset value less than a given horizontal offset threshold as the target piece of the reference piece; Based on the reference piece and each target piece, form a vertical chess string of the chessboard; Among them, the given vertical offset threshold or the given horizontal offset threshold is determined based on the piece size of each piece.
7. The method according to claim 1, wherein In the case that the current piece is the first piece in the current chess string, the method includes: According to the absolute coordinates of the current piece and the absolute coordinates of a given reference position on the chessboard, obtain the distance between the current piece and the given reference position; Based on the chess grid size of the chessboard and the distance between the current piece and the given reference position, obtain the relative coordinates of the current piece.
8. The method according to claim 1 or 7, wherein The multiple chess strings include at least one horizontal chess string and at least one vertical chess string. Each piece is respectively grouped into a horizontal chess string and a vertical chess string on the chessboard. The absolute coordinates of each piece are composed of a horizontal absolute coordinate and a vertical absolute coordinate, and the relative coordinates of each piece are composed of a horizontal relative coordinate and a vertical relative coordinate; Among them, obtaining the relative coordinates of each piece on the chessboard based on the two absolute coordinates of any two adjacent pieces in each chess string includes: Based on the two horizontal absolute coordinates of any two adjacent pieces in each horizontal chess string, identify the horizontal relative coordinates of each piece on the chessboard. Based on the two vertical absolute coordinates of any two adjacent pieces in each vertical chess string, identify the vertical relative coordinates of each piece on the chessboard; Combine the horizontal relative coordinates and vertical relative coordinates of the same piece on the chessboard to obtain the relative coordinates of each piece on the chessboard.
9. The method according to claim 1, wherein The image reconstruction based on the relative coordinates and piece categories of each piece on the chessboard to obtain the corrected image of the chessboard includes: According to the given reference position in the standard chess grid of the chessboard, the relative coordinates or absolute coordinates of each chess piece, determine the chess piece closest to the given reference position among the chess pieces as the reference chess piece, and determine each chess piece other than the reference chess piece as a non-reference chess piece; Based on the given reference position of the chessboard and the relative coordinates of the reference chess piece, determine the positioning position of the reference chess piece in the standard chess grid; Based on the positioning position of the reference chess piece and the relative coordinates of each non-reference chess piece, determine the positioning position of each non-reference chess piece in the standard chess grid of the chessboard; Based on the positioning positions of the reference chess piece and each non-reference chess piece in the standard chess grid, and the chess piece categories of the reference chess piece and each non-reference chess piece, render the standard chess grid to obtain the corrected image of the chessboard.
10. The method according to claim 1 or 9, wherein, The chessboard includes a Go chessboard; The chess piece categories include the white chess category and the black chess category.
11. A chessboard image correction device, comprising: A detection module that detects an initial image of the chessboard to obtain the chess piece category and absolute coordinates of each chess piece on the chessboard; A grouping module that groups each chess piece according to the absolute coordinates of each chess piece on the chessboard to obtain a plurality of chess strings of the chessboard, wherein each chess piece belonging to the same chess string is located in the same row on the chessboard; A conversion module that, based on the two absolute coordinates of any two adjacent chess pieces in each chess string, obtains the relative coordinates of each chess piece on the chessboard, including determining any one chess string as the current chess string, in the order of arrangement of the chess pieces in the current chess string, successively determining a chess piece in the current chess string as the current chess piece, determining the previous chess piece of the current chess piece as the previous chess piece, and determining the relative coordinates of the previous chess piece, and based on the absolute coordinates of the current chess piece and the absolute coordinates of the previous chess piece, obtaining the distance between the current chess piece and the previous chess piece, and based on the chess grid size of the chessboard, the distance between the current chess piece and the previous chess piece, and the relative coordinates of the previous chess piece, obtaining the relative coordinates of the current chess piece; A reconstruction module that performs image reconstruction based on the relative coordinates and chess piece categories of each chess piece on the chessboard to obtain the corrected image of the chessboard.
12. An electronic device, comprising: A processor; And A memory storing a program, wherein the program includes instructions that, when executed by the processor, cause the processor to execute the chessboard image correction method according to any one of claims 1 to 10.
13. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to execute the chessboard image correction method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Object display method, device, storage medium and electronic device
CN107967447A