Visual identification method for go robot
By combining polygon fitting and Hough circle detection algorithm, combined with adaptive Gaussian fuzzy processing and Gaussian weighted average adaptive threshold binarization, the accuracy of Go robots in chess boards and chess pieces recognition in complex lighting environments is solved, and the accuracy of Go boards and pieces recognition is achieved. High accuracy and robust recognition in complex environments have improved the intelligence level of Go robots.
Patent Information
- Application Number
- CN202411314425.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2024-12-20
AI Technical Summary
Go robots have low accuracy and robustness in complex lighting environments, and it is difficult to accurately identify chessboards and chess pieces under complex lighting conditions such as different brightness, light directions, reflections and occlusions.
Using polygon fitting algorithm and Hoff circle detection algorithm, combined with adaptive Gaussian fuzzy processing and Gaussian weighted average adaptive threshold binarization, through boundary follow-up algorithm and perspective transformation, an adaptive error-removing mechanism is established to improve the recognition of chessboards and chess pieces. Accuracy and robustness.
In complex lighting environments, the accuracy and stability of Go robot visual recognition is significantly improved, ensuring the rapid identification of chessboards and chess pieces, and improving the intelligence level and practicality of Go robots.
Smart Images

Figure CN119169600A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a Go robot visual recognition method in a complex lighting environment such as uneven light, strong reflection or dark shadow. Background Art
[0002] With the development of artificial intelligence and robotics, Go robots have gradually become an important research direction. In practical applications, Go robots need to be able to identify black and white pieces on the board and respond in real time, which poses a severe challenge to visual recognition technology.
[0003] Most current Go robots rely on traditional visual recognition technologies, which usually perform well in environments with relatively stable lighting conditions. However, in practical applications, lighting conditions often change, such as changes in natural light, shadows, reflections, etc., which greatly reduce the accuracy and robustness of visual recognition. Complex lighting environments place higher demands on the visual recognition of Go robots, including different brightness, light direction, reflection and occlusion, making it difficult to accurately identify the board and pieces. Summary of the invention
[0004] In view of the above, the present invention provides a visual recognition algorithm for a Go robot. Particular attention is paid to the applicability in complex lighting environments. The algorithm can stably and accurately identify the chessboard and chess pieces under different lighting conditions by introducing a polygon fitting algorithm and a Hough circle detection algorithm.
[0005] The method of the invention not only performs well under stable lighting conditions, but also shows extremely high robustness and adaptability under complex lighting environments. Its introduction has brought new breakthroughs in the visual recognition of Go robots, enabling them to accurately and quickly identify chessboards and chess pieces in various complex environments, improving the intelligence level and practicality of Go robots.
[0006] The visual recognition method for a Go robot of the present invention comprises the following steps:
[0007] S1 uses a camera to capture an empty Go chessboard image, and performs adaptive Gaussian blur processing on the empty chessboard image by calculating the grayscale histogram of the empty chessboard image, the local variance of different areas, and identifying the edge areas in the image.
[0008] S2 uses Gaussian weighted average adaptive threshold binarization to process the image after adaptive Gaussian blur processing to obtain a binarized image, and extracts contours from the binarized image through a boundary following algorithm.
[0009] S3 performs polygon fitting based on the Douglas-Pucker algorithm on the extracted contour, finds a polygon that meets the constraints, and saves the polygon as a two-dimensional array containing four vertex coordinates.
[0010] S4 sorts the coordinates of the four vertices of the obtained two-dimensional array, applies the sorted two-dimensional array to obtain a standardized chessboard image through perspective transformation, and establishes an all-zero matrix to represent the initial state where all chess pieces on the chessboard are empty.
[0011] S5 performs chess piece recognition. For the chessboard image, the chessboard grid points are obtained by uniform segmentation. Improved Hough circle detection is performed on each grid point area to determine the center position of the chess piece circle. The Hough circle area is segmented into three values with the located center position as the center to obtain the image after the three-value segmentation of the Hough circle area. An adaptive error correction mechanism is established based on the number of three elements in the three-valued area: the color of the black and white chess pieces is determined, and the misidentified grid point area is determined as empty.
[0012] S6 saves the recognition result according to the result of the error correction mechanism, receives the information change of the chess pieces on the chessboard through the all-zero matrix, changes the matrix value of the black chess point position to 1, and changes the matrix value of the white chess point position to 2, and completes the recognition.
[0013] Furthermore, step S1 further includes:
[0014] S11 converts the empty chessboard image from the RGB space to the grayscale space to obtain an empty chessboard grayscale image, wherein the grayscale value calculation formula in the grayscale space is Y=0.299·R+0.587·G+0.114·Β. R, G, B represent the pixel values of the red, green, and blue channels respectively, and Y is the converted grayscale value, and the chessboard grayscale image is obtained by the formula.
[0015] S12 calculates the grayscale histogram of the empty chessboard grayscale image to analyze the brightness and contrast of the image. The calculation formula of the grayscale histogram is: Where I(x,y) is the value of the pixel (x,y), g is the Dirac function, which is used to output 1 at a certain value and 0 in other cases, and W and H are the width and height of the grayscale image of the empty chessboard. The result of the grayscale histogram is used for adaptive processing of different areas in subsequent steps.
[0016] S13 performs Canny edge detection on the chessboard grayscale image based on the grayscale histogram. First, the grayscale histogram is smoothed using a Gaussian filter. The standard deviation of the Gaussian filter is adjusted according to the brightness distribution of the grayscale histogram to enhance the contrast or retain details. Then the Sobel operator is used to calculate the gradient amplitude G(x,y) and gradient direction θ(x,y) of the smoothed grayscale histogram to obtain the gradient amplitude image: Among them G x and G y They represent the gradient of the gradient magnitude image in the horizontal and vertical directions respectively. Finally, based on the gradient magnitude, the non-maximum values are suppressed along the gradient direction, and two thresholds are used to perform double threshold edge connection processing on the gradient magnitude image to obtain the edge region.
[0017] S14 calculates the local variance of different regions in the empty chessboard grayscale image based on the detected edge regions.
[0018] The calculation formula of local variance is as follows Among them, u i,j is the average value of the area around pixel (i,j), is the local variance of the area around pixel (i, j), n = 2k + 1 is the window size, u is the horizontal offset relative to pixel (i, j), and v is the vertical offset relative to pixel (i, j).
[0019] S15 dynamically adjusts the Gaussian filter parameter δ according to the edge area and local area i,j . Define three standard deviation values: basic standard deviation δ0, edge area standard deviation δ edge , standard deviation of high variance region δ high-variance ; For each pixel (i,j): Where E(i,j) is the edge detection result, mean(r 2 ) is the mean of the local variances.
[0020] S16 For each pixel (i, j), use the dynamically adjusted δ in S15 i,j Apply a Gaussian filter: In the window size l i,j *l i,j In the window area, Gaussian blur is performed: Finally, the grayscale image after adaptive Gaussian blur processing is obtained.
[0021] Furthermore, step S2 further includes:
[0022] S21 performs binarization on the grayscale image after adaptive Gaussian blur processing, and uses the Gaussian weighted average adaptive threshold binarization method to automatically adjust the threshold according to the lighting conditions of each local area of the grayscale image after binarization processing; assuming that the given input image is I(x, y), the binarized image is obtained by adaptive threshold binarization where T(h,f) is the local threshold at point (h,f), Among them, N(h,f) is the neighborhood area centered on point (h,f), ω(i,j) is the weight calculated according to Gaussian distribution, and the calculation of the weight depends on the distance of the pixel (i,j) in the neighborhood relative to the center (h,f). Specifically, the weight can be expressed as a Gaussian function: Here, σ is the standard deviation of the Gaussian function.
[0023] S22 regards the binary image obtained in step S21 as an object and zero pixels as a background; identifies contours in the binary image through a boundary following algorithm, the algorithm scans along the boundary of the background pixels, finds all continuous boundary points, connects the boundary points to form contour lines, and represents the edge of the object; finally returns a set P containing all contours.
[0024] Furthermore, step S3 further includes:
[0025] S31 For the contour set P obtained in step S2, use a polygon fitting method based on the Douglas-Pucker algorithm to simplify each element in the contour set P into a polygon; assume a tolerance threshold ε, which is used to control the accuracy of polygon simplification. A larger ε will produce a more simplified polygon, while a smaller ε will retain more original details. For each curve in the contour set P, starting from the starting point and end point of the curve, calculate the distance from all other points to the straight line connecting the starting point and the end point. Assume that the starting point of the curve is p j , the end point is p k , some middle point is p m , then calculate the point p m To Segment The vertical distance d k , the calculation formula is: Among them, (x j ,y j ) and (x k ,y k ) are the coordinates of the starting point and the end point, (x m ,y m ) is the coordinate of the middle point. By recursive segmentation: find the distance between the curve and the line segment The farthest point p max , calculate the distance d max If d max ≥ε, then the curve is at p max Split into two segments at , and recursively apply the same algorithm to each segment until the distance from all points to the corresponding line segment is less than ε; if d max<ε, the current starting point and end point are directly connected, ignoring the intermediate points. All elements in set P are recursively split to form a new polygon set P1. Each element is a simplified version of the original outline, retaining the main geometric features.
[0026] S32 traverses the polygon set P1 in sequence, determines the number of sides of each element, retains those that are quadrilaterals, and discards those that are not quadrilaterals, and finally obtains a set of quadrilaterals P2.
[0027] S33 calculates the actual area of the chessboard. The Go robot camera used in the present invention is installed on a bracket of fixed height, and the height of the camera is ensured not to change during the entire operation process through a non-adjustable rigid structure. This design ensures that the chessboard image captured by the camera maintains a consistent pixel area and avoids image deviation caused by height changes. Use OpenCV's mouse event to select the coordinates of the four vertices of the chessboard, and assume that the coordinates of the four vertices in the clockwise direction are: (x1, y1), (x2, y2), (x3, y3), (x4, y4). Use the vector method formula to calculate the area of the quadrilateral: The Area obtained is the actual area of the chessboard.
[0028] S34 traverses the quadrilateral set P2 in sequence, calculates the area of each quadrilateral, subtracts the area of each quadrilateral from the actual area of the chessboard Area in sequence, returns the quadrilateral with the smallest absolute value of the difference, and saves the result in the form of a two-dimensional array containing four vertex coordinates.
[0029] Further, in step S4, the four elements of the obtained two-dimensional array are sorted, the vertices are divided into two groups of left and right according to the x coordinate, the upper and lower points are sorted according to the y coordinate, and the vertices are output in clockwise order. The sorted two-dimensional array is applied to obtain a standardized 800×800 empty chessboard image through perspective transformation. A 19×19 all-zero matrix is established to represent the initial state where all chess pieces on the chessboard are empty.
[0030] Furthermore, step S5 further includes:
[0031] S51 Start placing pieces on the chessboard and identify the pieces. The chessboard is composed of 19 horizontal lines and 19 vertical lines. A square is formed between every two adjacent lines, so the length (horizontal direction) and width (vertical direction) of the chessboard image are evenly divided into 20 parts. At this time, there are 19 dividing lines in the horizontal and vertical directions, which intersect each other, and finally 19×19 grid points are obtained. For the grid point at position (i1, j1) (1≤i1≤19, 1≤j1≤19), its horizontal position is Pixels, whose vertical position is Pixels, where i is the horizontal index of the grid point and j is the vertical index of the grid point.
[0032] S52 divides the 19×19 grid point positions obtained in step S51 into 19×19 pixel regions, and performs Hough circle detection on each pixel region in turn.
[0033] S53 Due to the influence of image noise and chess piece smear, as well as the inaccurate setting of the minimum and maximum radius of the Hough circle and the accumulator threshold parameter, misidentified Hough circles may appear in the blank point pixel area, and multiple Hough circles may be detected in each pixel area. The area set of Hough circles detected in a pixel area is defined as S1 = {T1, T2, ... T n}.
[0034] S54 calculates the actual area of the chess piece. Since the camera height is fixed and the size of the chess piece is fixed, the area of the chess piece is relatively fixed. A white chess piece is placed at a grid point in an empty chessboard image under uniform lighting conditions. A rectangular area containing the white chess piece with the grid point as the center is taken. The rectangular area is converted to the HSV space. The HSV threshold range of white is defined as [0, 0, 200] to [180, 50, 255]. A mask containing only the white area is generated based on the HSV threshold range. The number of non-zero pixels in the mask is calculated, which is the pixel area S of the white chess piece. The pixel area of the black piece is the same as that of the white piece, both of which are S.
[0035] S55 takes the element T with the smallest absolute difference with S in the set S1 and the element Y with the second smallest absolute difference.
[0036] S56 defines that the distance between the centers of the two circles T and Y in each Hough circle area is m, and the distance between the centers of the two circles (x 11 ,y 11 ) and (x 21 ,y 21 ) coordinates to find the distance between the center of the circle The threshold of the distance between the centers of the circles is defined as th, the number of grid regions with Hough circles is n, and the calculation formula of the threshold of the distance between the centers of the circles is defined as: For the Hough circle area whose center distance is less than or equal to the threshold th, the T Hough circle is returned; for the area whose center distance is greater than the threshold th, the shadow direction is determined according to the distribution of grayscale values around the identified T Hough circle, and the Hough circle that deviates from the actual center position close to the shadow side is eliminated to obtain the center position of the chess piece in each pixel area.
[0037] S57 obtains the minimum value th1 and the maximum value th2 of the grayscale value of each center area in the corresponding center area in the grayscale space of the empty chessboard according to the accurate center position of the chess piece obtained in the chess piece image; performs three-value segmentation in the grayscale space of the chess piece image according to the minimum value th1 and the maximum value th2 of the corresponding center area. After the center area is grayscaled, each grayscale point F becomes Among them, a, b, and c are the three values of the chess piece area in the grayscale image after ternary conversion, and the chess piece ternary image is obtained.
[0038] S58: Based on the three-valued chess piece image obtained in step S57, assuming that the sum function is sum(x), x represents a gray value in a certain three-valued image, sum(a), sum(b), sum(c) in each three-valued area are counted by the sum function, and an adaptive error correction mechanism is established to determine the chess piece:
[0039] (1) If sum(a)≥sum(c) and sum(a)≥sum(b), the chess piece is judged to be black.
[0040] (2) If sum(a)<sum(c) and sum(c)≥sum(b), it is determined to be white.
[0041] (3) All other cases are judged as empty.
[0042] Through the adaptive error correction mechanism, clauses (1) and (2), the black and white color of the chess piece is determined. At the same time, clause (3) determines that the Hough circle that may appear at the empty point position, that is, the misidentified Hough circle, is empty, thereby ensuring the accuracy of chess piece recognition.
[0043] Furthermore, in step S6, the recognition result is saved. The sorted two-dimensional array in S4 is saved as the chessboard positioning result; the result determined by the error correction mechanism is used as the chess piece recognition result, and the information change of the chess piece on the chessboard is received through the 19×19 all-zero matrix, and the matrix value of the position of the black chess piece is changed to 1, and the matrix value of the position of the white chess piece is changed to 2.
[0044] Compared with the prior art, the present invention has the following beneficial effects:
[0045] An adaptive Gaussian blur processing and Gaussian weighted average adaptive threshold binarization method are introduced to automatically adjust the standard deviation and adaptive threshold of the Gaussian filter according to the lighting conditions of each local area of the image, effectively overcoming the interference caused by complex lighting environments such as uneven light, strong reflection or dark shadows; and the Gaussian weighted average adaptive threshold binarization is combined with the polygon fitting method based on the Douglas-Pucker algorithm to post-process the non-closed geometric figures after contour detection into closed geometric figures, effectively improving the accuracy of chessboard positioning under the interference of strong light and strong shadows.
[0046] The improved Hough circle detection algorithm is used to locate chess pieces on the chessboard, effectively overcoming the problems of missed recognition and inaccurate positioning of chess pieces in complex lighting environments; and through the ternary algorithm, the center area of the Hough circle is ternary segmented according to the empty chessboard image located in each game, and an adaptive error correction mechanism is established based on the ternary result, effectively overcoming the problem of misrecognition of chess pieces in complex lighting environments.
[0047] The proposed algorithm is applied to the Go robot vision system, which effectively improves the stability of the Go robot in playing Go in complex lighting environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a flow chart of the visual recognition algorithm used for Go robots;
[0049] Figure 2 It is a schematic diagram of the Go robot equipment;
[0050] Figure 3 It is a diagram of the chessboard positioning process;
[0051] Figure 4 It is a diagram of the chess piece recognition process;
[0052] Figure 5 This is a schematic diagram of the chessboard positioning effect in a complex lighting environment;
[0053] Figure 6 This is a schematic diagram of chess piece recognition effect in a complex lighting environment;
[0054] Figure 7 This is a comparison chart of experimental results. DETAILED DESCRIPTION
[0055] The specific implementation of the present invention will be described below with reference to the accompanying drawings.
[0056] The present invention is based on a visual recognition algorithm for a Go robot, the process is as follows: Figure 1 As shown, the specific steps include:
[0057] The Go robot hardware device captures the chessboard image video stream, samples the video stream into a periodic frame sequence, and extracts image frames at a rate of 10 frames per second. Figure 2 As shown in the figure, the Go robot is mainly composed of a robotic arm, a camera, a Raspberry Pi, a piece-feeding mechanism and a stepper motor; the empty chessboard picture obtained is as follows Figure 3 As shown, from left to right are the empty chessboard image, the adaptive Gaussian blur processing result image, the Gaussian weighted average adaptive threshold binarization result image, and the chessboard positioning result.
[0058] Adaptive Gaussian blur processing. Due to the influence of image noise and uneven lighting, it is necessary to perform adaptive Gaussian blur processing on the image based on the grayscale histogram of the image, the local variance of different areas, and the edge area of the image. First, Figure 3 The empty chessboard image is converted from RGB space to grayscale space, where the grayscale value calculation formula in the grayscale space is Y=0.299·R+0.587·G+0.114·Β; where R, G, and B represent the pixel values of the red, green, and blue channels respectively, and Y is the converted grayscale value; then the histogram of the grayscale image is calculated to analyze the brightness and contrast of the image. The calculation formula of the histogram is: Where I(x,y) is the value of the pixel (x,y), g is the Dirac function, which is used to output 1 at a certain value and 0 in other cases, and W and H are the width and height of the empty chessboard grayscale image respectively; based on the analysis results of the grayscale histogram, the Canny edge detection algorithm is used to calculate the edges in the grayscale image: first, the image is smoothed using a Gaussian filter, and then the Sobel operator is used to calculate the gradient amplitude G(x,y) and gradient direction θ(x,y) of the image to obtain the gradient amplitude image: Among them G x and G y Respectively represent the gradient of the gradient magnitude image in the horizontal direction and the vertical direction, and suppress the non-maximum value along the gradient direction, and use two thresholds to perform double threshold edge connection processing on the gradient magnitude image to obtain the edge area; then, according to the detected edge area, calculate the local variance of different areas in the grayscale image, and the calculation formula of the local variance is as follows: Among them, u i,j is the average value of the area around pixel (i,j), is the local variance of the area around pixel (i, j), n = 2k + 1 is the window size, u is the horizontal offset relative to pixel (i, j), and v is the vertical offset relative to pixel (i, j); finally, according to the edge detection result and the local variance, the standard deviation of the Gaussian filter is dynamically adjusted to define three standard deviation values: basic standard deviation: δ0 = 1.0, edge area standard deviation: δ edge =0.5, standard deviation in high variance area: δ high-variance =2.0; for each pixel (i,j): Where E(i,j) is the edge area, mean(r 2 ) is the average of the local variance. Finally, for each pixel (i, j), a dynamically adjusted δ is used i,j and kernel size k i,j Apply a Gaussian filter: In the window size l i,j *l i,j In the window area, Gaussian blur is performed: The image is processed by adaptive Gaussian blur. From the image, we can see that the grayscale image after adaptive Gaussian blur processing is smoother, the image details are intact, and the noise is significantly eliminated.
[0059] Binarize the grayscale image after adaptive Gaussian blur processing to obtain a binary image. Binarize the grayscale image using the Gaussian weighted average adaptive threshold binarization method to automatically adjust the threshold according to the lighting conditions of each local area of the image; assuming that the given input image is I(x,y), the threshold binarization obtains the binary image Where T(h,f) is the local threshold calculated at point (h,f), usually calculated by the formula: Among them, N(h,f) is the neighborhood area centered on the point (h,f), ω(i,j) is the weight calculated according to the Gaussian distribution, and the calculation of the weight depends on the distance of the pixel (i,j) in the neighborhood relative to the center (x,y). Specifically, the weight can be expressed as a Gaussian function: Where σ is the standard deviation of the Gaussian function. Gaussian weighted average adaptive threshold binarization is as follows Figure 3 As shown in the figure, it can be seen that the Gaussian weighted average adaptive threshold binarization result has better overcome the influence of uneven image illumination on binarization.
[0060] Contour detection. For the input image, non-zero pixels are regarded as objects and zero pixels are regarded as background. Contours in the binary image are identified by the boundary following algorithm. The algorithm scans along the boundary of the background pixels, finds all continuous boundary points, connects the boundary points to form contour lines, and finally returns a set P containing all contours.
[0061] Polygon fitting. A simplified approximate polygon is fitted from the detected contour set P by polygon fitting based on the Douglas-Pucker algorithm; a tolerance threshold ε is assumed, which is used to control the accuracy of polygon simplification. A larger ε will produce a more simplified polygon, while a smaller ε will retain more original details. For each curve in the contour set P, starting from the start and end points of the curve, calculate the distance from all other points to the straight line connecting the start and end points. Assume that the starting point of the curve is p j , the end point is p k , some middle point is p m , then calculate the point p m To Segment The vertical distance d k , the calculation formula is: Among them, (x j ,y j ) and (x k ,yk ) are the coordinates of the starting point and the end point, (x m ,y m ) is the coordinate of the middle point. By recursive segmentation: find the distance from the straight line segment on the curve The farthest point p max , calculate the distance d max If d max ≥ε, then the curve is at p max Split into two segments at , and recursively apply the same algorithm to each segment until the distance from all points to the corresponding line segment is less than ε; if d max <ε, the current starting point and end point are directly connected, ignoring the intermediate points. All approximate polygons are recursively split and returned to form a new polygon set P1. Each approximate polygon is a simplified version of the original outline, retaining the main geometric features.
[0062] Get the chessboard positioning result. Traverse the approximate polygon set P1 in sequence, determine the number of sides of each element, retain if it is a quadrilateral, discard if it is not a quadrilateral, and finally get a set of quadrilaterals P2. Traverse the quadrilateral set P2 in sequence, calculate the area of each quadrilateral, because the camera height is fixed and the actual area of the chessboard is unchanged, so the area of each quadrilateral is subtracted from the actual area of the chessboard in turn, and return the quadrilateral with the smallest absolute value of the difference. The result is saved in the form of a set of two-dimensional matrices containing four vertex coordinates. The chessboard positioning result is as follows Figure 3 As shown in the figure, the four vertices of the chessboard are accurately located.
[0063] Sort the four elements of the obtained two-dimensional array, divide the vertices into two groups according to the x coordinate, sort them according to the y coordinate to get the upper and lower points, output the vertices in clockwise order, and apply the sorted two-dimensional array to obtain the standardized chessboard image area through perspective transformation. The result is as follows Figure 4 As shown in the chessboard picture, from left to right are the chessboard picture, chess piece picture, chess piece positioning result, ternary result, and chess piece recognition result. A 19×19 all-zero matrix is established to represent the initial state where all chess pieces on the chessboard are empty.
[0064] Get the grid point location. Figure 4 It can be seen that the chessboard is composed of 19 horizontal lines and 19 vertical lines. A square is formed between every two adjacent lines, so the length (horizontal direction) and width (vertical direction) of the chessboard image are evenly divided into 20 parts. At this time, there are 19 dividing lines in the horizontal and vertical directions, and they intersect each other, and finally 19×19 grid points are obtained. For the grid point at position (i1, j1) (1≤i1≤19, 1≤j1≤19), its horizontal position is Pixels, whose vertical position is Pixels, where i is the horizontal index of the grid point and j is the vertical index of the grid point.
[0065] Improved Hough circle detection of chess pieces on the chessboard. For chess piece images, first, for the obtained grid point positions, the chessboard is divided into 19×19 pixel areas with 19×19 grid points as the center, and Hough circle detection is performed on each pixel area in turn. Then, for a number of Hough circles detected in an area, their area set is defined as S1={T1,T2,…T n}; Since the camera height is fixed and the chess piece size is fixed, the chess piece area is relatively fixed, which is S; subtract the set from and take the two elements with the smallest absolute difference T = min{abs{T1-S,T2-S,…T n -S}},Y=min{abs{T1-S,T2-S,…T n -S}-{T}}. Define the distance between the centers of the two circles T and Y in each Hough circle area as m. According to the centers of the two circles (x 11 ,y 11 ) and (x 21 ,y 21 ) coordinates to find the distance between the center of the circle The threshold of the distance between the centers of the circles is defined as th, the number of grid regions with Hough circles is n, and the calculation formula of the threshold of the distance between the centers of the circles is defined as: For the Hough circle area whose center distance is less than or equal to the threshold th, the T Hough circle is returned; for the area whose center distance is greater than the threshold th, the shadow direction is determined according to the distribution of grayscale values around the identified T Hough circle, and the Hough circle that deviates from the actual center position close to the shadow side is eliminated, and finally the Hough circle that best fits the actual position in each pixel area is obtained. The final positioning result is as follows Figure 4 As shown in the figure, the located Hough circle is marked with a green circle frame in the figure. From the positioning results, it can be seen that each chess piece is located in a Hough circle, and the center of the located Hough circle is relatively fitted with the center of the chess piece. At the same time, a misidentified Hough circle appears in the 18th row and 15th column.
[0066] Perform three-value segmentation on the Hough circle area. Figure 4 The chess piece center area obtained in the chess piece positioning image obtains the minimum value th1 and the maximum value th2 of the grayscale value of each center area in the corresponding center area in the grayscale space of the empty chessboard; in the chess piece image grayscale space, three-value segmentation is performed according to the minimum value th1 and the maximum value th2 of the corresponding center area. After the center area is grayscaled, each grayscale point F becomes Among them, a, b, and c are the three values of the chess piece area in the grayscale image after ternary conversion. They can be set to any value between 0 and 255. Referring to the binary grayscale value, a is set to 0, c is set to 255, and b is set to the middle value 127. The result of the chess piece ternary conversion is as follows: Figure 4 As shown in the picture, it can be seen that the pixels in the white three-valued area c account for the vast majority of the proportion, the pixels in the black three-valued area a account for the vast majority of the proportion, and the pixels in the misidentified three-valued area b account for the vast majority of the proportion.
[0067] Establish an adaptive error correction mechanism. According to the obtained three-valued image of the chess piece, count the sum(a), sum(b), sum(c) in each three-valued area, and establish an adaptive error correction mechanism:
[0068] (1) If sum(a)≥sum(c) and sum(a)≥sum(b), the chess piece is judged to be black.
[0069] (2) If sum(a)<sum(c) and sum(c)≥sum(b), it is determined to be white.
[0070] (3) All other cases are judged as empty.
[0071] Through the adaptive error correction mechanism, the black and white colors of the chess pieces are determined. At the same time, in item (3), the Hough circles that may appear at the blank point position, that is, the misidentified Hough circles, are determined to be empty, ensuring the accuracy of chess piece recognition. The final error correction mechanism judgment result is as follows Figure 4 As shown in the figure, it can be seen that the black pieces are all identified as red circles, and the white pieces are all identified as blue circles. The misidentified Hough circles in the 18th row and 15th column are excluded in the adaptive error correction mechanism, ensuring the accuracy of recognition. The final recognition accuracy is 100%.
[0072] Save the recognition result. Save the sorted two-dimensional array as the chessboard positioning result; at the same time, as the chess piece recognition result, receive the information change of the chess piece on the chessboard through the 19×19 all-zero matrix, and change the matrix value of the black chess piece position to 1, and change the matrix value of the white chess piece position to 2.
[0073] The chessboard positioning results of the present invention under a typical strong light interference environment are as follows: Figure 5 As shown in the figure above; the chessboard positioning results of the present invention are applied in a typical shadow environment. Figure 5 The following figure shows the positioning results. The positioning results are marked by the green quadrilateral outer frame and four yellow vertices in the figure. Under these eight typical lighting environments, the chessboard positioning rate is 100%.
[0074] The chess piece recognition results of the present invention under a typical strong light interference environment are as follows: Figure 6 As shown in the figure above; the chess piece recognition result of the present invention is applied in a typical shadow environment. Figure 6 As shown in the figure below, the black pieces are identified by a blue circular frame, and the white pieces are identified by a red circular frame. Under these eight typical lighting conditions, the chess piece recognition rate is 100%.
[0075] Comparison of experimental results. We collected 213 chess piece images in normal lighting environments, 78 chess piece images in strong light interference environments, and 98 chess piece images in shadow interference environments. We compared the recognition accuracy with that of Tencent Go. The accuracy indicators include false recognition rate and missed recognition rate. False recognition means recognizing chess pieces where there are no chess pieces, and missed recognition means not recognizing chess pieces where there are chess pieces. The specific results are as follows: Figure 7 As shown, from Figure 7 It is found that the false recognition rate and missed recognition rate of the present invention under all test conditions are significantly lower than those of Tencent Go, especially under strong light and shadow interference. The present invention shows stronger robustness and accuracy when the lighting conditions vary greatly.
Claims
1. A visual recognition method for a Go robot, It is characterized in that The following steps are involved: S1, using a camera to collect an empty chessboard image of a Go chessboard, and performing adaptive Gaussian blur processing on the empty chessboard image; S2, using Gaussian weighted average adaptive threshold binarization to process the image after adaptive Gaussian blur processing to obtain a binarized image, and extracting contours from the binarized image through a boundary following algorithm; S3, performing polygon fitting based on the Douglas-Peucker algorithm on the extracted contour, finding a polygon that meets the constraint conditions, and saving the polygon as a set of two-dimensional arrays containing four vertex coordinates; S4, sorting the coordinates of the four vertices of the two-dimensional array, applying the sorted two-dimensional array to obtain a standardized chessboard image through perspective transformation, and establishing an all-zero matrix to represent an initial state where all chess pieces on the chessboard are empty; S5, obtaining chessboard grid points by uniformly segmenting the chessboard image, and determining the center position of the chess piece circle, performing three-value segmentation on the Hough circle region with the center position as the center, and establishing an adaptive error correction mechanism based on the number of three elements in the three-value region to determine the chess piece; S6. According to the result determined by the error correction mechanism, the recognition result is saved, and the information change of the chess pieces on the chessboard is received through the all-zero matrix, and the matrix value of the black position is changed to 1, and the matrix value of the white position is changed to 2, thereby completing the recognition.
2. A visual recognition method for a Go robot according to claim 1, It is characterized in that The specific implementation process of the adaptive Gaussian blur processing on the empty chessboard image is as follows: S11, converting the empty chessboard image from the RGB space to the grayscale space to obtain an empty chessboard grayscale image, wherein the grayscale value calculation formula in the grayscale space is Y=0.299·R+0.587·G+0.114·Β, where R, G, and B represent the pixel values of the red, green, and blue channels, respectively; S12, calculating the grayscale histogram of the empty chessboard grayscale image, the calculation formula of the grayscale histogram is: Where I(x,y) is the value of the pixel (x,y), g is the Dirac function, and W and H are the width and height of the empty chessboard grayscale image respectively; S13. Perform Canny edge detection on the chessboard grayscale image based on the grayscale histogram. First, use a Gaussian filter to smooth the grayscale histogram, and then use the Sobel operator to calculate the gradient amplitude G(x, y) and gradient direction θ(x, y) of the smoothed grayscale histogram to obtain a gradient amplitude image: Among them G x and G y Respectively represent the gradients of the gradient magnitude image in the horizontal direction and the vertical direction; based on the gradient magnitude, suppress the non-maximum value along the gradient direction, and use two thresholds to perform double threshold edge connection processing on the gradient magnitude image to obtain the edge area; S14. Based on the edge region, calculate the local variance of different regions in the empty chessboard grayscale image: Among them, u i,j is the average value of the area around pixel (i,j), is the local variance of the area around pixel (i, j), n = 2k + 1 is the window size, u is the horizontal offset relative to pixel (i, j), and v is the vertical offset relative to pixel (i, j); S15, dynamically adjust the Gaussian filter parameter δ according to the edge area and local variance i,j ; Define the basic standard deviation δ 0 , the standard deviation of the edge area δ edge , standard deviation of high variance region δ high-variance ; For each pixel (i,j): Where E(i,j) is the edge area, mean(r 2 ) is the mean of the local variances; S16. For each pixel (i, j), use δ i,j Apply a Gaussian filter: In the window size l i,j *l i,j In the window area, Gaussian blur is performed: Get the grayscale image after adaptive Gaussian blur processing.
3. A visual recognition method for a Go robot according to claim 2, It is characterized in that The specific implementation process of step S2 is as follows: S21, using Gaussian weighted average adaptive threshold binarization method, automatically adjust the threshold according to the lighting conditions of each local area of the grayscale image after binarization; assuming that the input I(h,f) is given, the binarized image is obtained by adaptive threshold binarization where T(h,f) is the local threshold at point (h,f), Among them, N(h,f) is the neighborhood area centered on the point (h,f), and ω(i,j) is the weight calculated according to the Gaussian distribution; S22. For the binary image obtained in step S21, non-zero pixels are regarded as objects and zero pixels are regarded as background; contours in the binary image are identified by a boundary following algorithm, the algorithm scans along the boundary of the background pixels, finds all continuous boundary points, connects the boundary points to form contour lines, and represents the edge of the object; finally, a set P containing all contours is returned.
4. A visual recognition method for a Go robot according to claim 3, It is characterized in that The weight ω(i,j) calculation depends on the distance of the pixel (i,j) in the neighborhood relative to the center (h,f), σ is the standard deviation of the Gaussian function.
5. A visual recognition method for a Go robot according to claim 3, It is characterized in that The specific implementation process of step S3 is as follows: S31. For the obtained contour set P, use the polygon fitting method based on the Douglas-Peucker algorithm to simplify each element in the contour set P into a polygon; assume a tolerance threshold ε to control the accuracy of polygon simplification; for each curve in the contour set P, starting from the starting point and end point of the curve, calculate the distance from all other points to the straight line connecting the starting point and the end point; assume that the starting point of the curve is p j , the end point is p k , some middle point is p m , then calculate the point p m To Segment The vertical distance d k : Among them, (x j ,y j ) and (x k ,y k ) are the coordinates of the starting point and the end point, (x m ,y m ) is the coordinate of the middle point; by recursive segmentation: find the distance between the curve and the line segment The farthest point p max , calculate the distance d max ; if d max ≥ε, then the curve is at p max Split into two segments at , and recursively apply the same algorithm to each segment until the distance from all points to the corresponding line segment is less than ε; if d max <ε, then directly connect the current starting point and end point, ignoring the intermediate points; all elements in set P are recursively split to form a new polygon set P 1 ; S32, traverse the polygon set P in sequence 1 , determine the number of sides of each element, keep it if it is a quadrilateral, and discard it if it is not a quadrilateral, and finally get a set of quadrilaterals P 2 ; S33. The Go robot camera used is installed on a bracket with a fixed height. The non-adjustable rigid structure ensures that the height of the camera does not change during the entire operation process. Select the coordinates of the four vertices of the chessboard, and set the coordinates of the four vertices in the clockwise direction as: (x 1 ,y 1 ), (x 2 ,y 2 ), (x 3 ,y 3 ), (x 4 ,y 4 ); Calculate the area of the quadrilateral: Get Area as the actual area of the chessboard; S34, traverse the quadrilateral set P in sequence 2 , calculate the area of each quadrilateral, subtract the area of each quadrilateral from the actual area of the chessboard Area, return the quadrilateral with the smallest absolute value of the difference, and save the result in the form of a two-dimensional array containing the coordinates of the four vertices.
6. A visual recognition method for a Go robot according to claim 5, It is characterized in that The specific implementation process of step S4 is: sorting the four elements of the obtained two-dimensional array, dividing the vertices into two groups of left and right according to the x coordinate, sorting the vertices according to the y coordinate to obtain two upper and lower points, outputting the vertices in clockwise order, applying the sorted two-dimensional array to obtain a standardized 800×800 empty chessboard image through perspective transformation, and establishing a 19×19 all-zero matrix to represent the initial state where all chess pieces on the chessboard are empty.
7. A visual recognition method for a Go robot according to claim 6, It is characterized in that The specific implementation process of step S5 is as follows: S51, start to place the chess pieces on the chessboard. The chessboard is composed of 19 horizontal lines and 19 vertical lines. A square is formed between every two adjacent lines. The length and width of the chessboard image are evenly divided into 20 parts. At this time, there are 19 dividing lines in the horizontal and vertical directions, and they intersect each other, finally obtaining 19×19 grid points; for (i 1 ,j 1 )(1≤i 1 ≤19, 1≤j 1 ≤19) position grid point, its horizontal position is Pixels, whose vertical position is Pixels, where i 1 is the horizontal sequence number of the grid point, j 1 is the vertical sequence number of the grid point; S52, dividing the obtained 19×19 grid point positions into 19×19 pixel regions, and performing Hough circle detection on each pixel region in turn; S53, a pixel area is detected and the Hough circle area set is defined as S 1 ={T 1 ,T 2 ,…T n }; S54, place a white chess piece at a grid point in an empty chessboard image under uniform illumination, take a rectangular area centered on the grid point and containing the white chess piece, convert the rectangular area to HSV space, define the HSV threshold range of white as [0, 0, 200] to [180, 50, 255], generate a mask containing only the white area according to the HSV threshold range, calculate the number of non-zero pixels in the mask, which is the pixel area S of the white chess piece, and the pixel area of the black piece is the same as that of the white piece, both of which are S; S55, take set S 1 The element T with the smallest absolute difference with S and the element Y with the second smallest absolute difference; S56, define the distance between the centers of the two circles T and Y in each Hough circle area as m, and calculate the distance between the centers of the two circles (x 11 ,y 11 ) and (x 21 ,y 21 ) coordinates to find the distance between the center of the circle The threshold of the distance between the centers of the circles is defined as th, the number of grid regions with Hough circles is n, and the calculation formula of the threshold of the distance between the centers of the circles is defined as: For the Hough circle area whose center distance is less than or equal to the threshold th, return the T Hough circle; for the area whose center distance is greater than the threshold th, determine the shadow direction according to the distribution of grayscale values around the identified T Hough circle, remove the Hough circle close to the shadow side that deviates from the actual center position, and obtain the center position of the chess piece in each pixel area; S57, according to the accurate center position of the chess piece obtained in the chess piece image, obtain the minimum value th1 and the maximum value th2 of the grayscale value of each center area in the corresponding center area in the grayscale space of the empty chessboard; perform three-value segmentation in the grayscale space of the chess piece image according to the minimum value th1 and the maximum value th2 of the corresponding center area, and each grayscale point F becomes Among them, a, b, and c are the three values of the chess piece area in the grayscale image after ternary conversion, and the chess piece ternary image is obtained; S58 is based on the ternary image of the chess piece, assuming that the sum function is sum(x), x represents a gray value in a ternary image, and uses the sum function to count sum(a), sum(b), sum(c) in each ternary area to establish an adaptive error correction mechanism to determine the chess piece.
8. A visual recognition method for a Go robot according to claim 7, It is characterized in that The adaptive error correction mechanism is specifically: If sum(a)≥sum(c) and sum(a)≥sum(b), it is determined to be a black piece; if sum(a)<sum(c) and sum(c)≥sum(b), it is determined to be a white piece; in all other cases, it is determined to be empty.
Citation Information
Cited By
Chessboard identification and calibration method for complex scene and device used by method
CN121305043A
