Circle center positioning method and device based on circular object, equipment and medium
By performing circular sampling and downsampling on a circular grayscale image, counting the difference pixels, and determining the position of the largest pixel in the circle center counting matrix, the problems of large computational load and low accuracy in existing technologies are solved, and the circle center position is quickly and accurately located.
Patent Information
- Application Number
- CN202211031429.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-26
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-08-26
AI Technical Summary
Existing circular object positioning schemes involve large computational loads and low accuracy, while the Hough transform technique makes it difficult to calculate multiple center points and radii.
By acquiring a circular grayscale image, circular sampling is performed to obtain a sampling offset matrix. Downsampling and difference pixel statistics are then stored in a center counting matrix. The sampling center is moved to traverse the region, and the position with the maximum number of pixels is determined as the center of the circle.
It achieves rapid and accurate positioning of the center position, reduces the amount of computation, and improves positioning accuracy.
Smart Images

Figure CN115482267B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a method, apparatus, device, and medium for locating the center of a circular object. Background Technology
[0002] In the fields of image processing and object detection, the detection and localization of circular objects are frequently encountered. Currently, the Hough transform technique is commonly used for the detection and localization of circular objects. Specifically, the edges of the circular object are first detected in the image, and then the circle is detected using the Hough transform technique.
[0003] However, in practice, it has been found that the Hough transform technique used in existing circular object localization schemes requires location calculations for all pixels in the image and cumulative voting for each pixel to determine the center and radius of the circular object. This involves a large amount of computation, and the cumulative voting result is prone to producing multiple centers and radii, leading to low localization accuracy. Therefore, there is an urgent need to propose a better circular object center localization scheme. Summary of the Invention
[0004] This application provides a method, apparatus, device, and medium for locating the center of a circular object, which solves the technical problems of large computational load and low accuracy in existing circular object positioning schemes.
[0005] On the one hand, this application provides a method for locating the center of a circular object through one embodiment of the application, the method comprising the following steps:
[0006] S1. Obtain a circular grayscale image of the circular object;
[0007] S2. Perform circular sampling on the circular grayscale image to obtain the sampling offset matrix;
[0008] S3. Downsample and count the difference pixels in the sampling offset matrix and the center calculation area of the circular grayscale image, and store the number of pixels obtained by the statistics in the pre-built center counting matrix.
[0009] S4. Move the sampling center of the circular sample in the center calculation region according to the set step size, and repeat the above step S3 until the center calculation region is traversed to obtain the center counting matrix.
[0010] S5. The storage location corresponding to the maximum number of pixels in the center counting matrix is determined as the reference center position of the circular object.
[0011] Optionally, the method further includes:
[0012] Increase the size of the sampling offset matrix, update the center calculation region according to the reference center position, and repeat steps S2-S5 to obtain the final center position of the circular object.
[0013] Optionally, step S2 includes:
[0014] Based on a preset sampling radius, the circular grayscale image is sampled in a planar manner along the radial direction and the circumferential direction to obtain multiple planar sampling points;
[0015] The sampling offset matrix is obtained by performing polar coordinate transformation on the multiple planar sampling points, wherein the sampling offset matrix includes the coordinates of the multiple sampling points.
[0016] Optionally, the downsampling and difference pixel statistics of the sampling offset matrix and the center calculation region of the circular grayscale image include:
[0017] The center calculation area of the circular grayscale image is determined according to the preset sampling radius;
[0018] Based on the calculated center region and the sampling offset matrix, the circular grayscale image is downsampled to obtain a downsampled image;
[0019] Based on the pixel value of each pixel in the downsampled image, count the number of pixels in the downsampled image where the absolute value of the difference between adjacent rows is greater than the absolute value of the difference between adjacent columns.
[0020] Optionally, the step of downsampling the circular grayscale image based on the calculated center region and the sampling offset matrix to obtain a downsampled image includes:
[0021] Based on the selected point in the center calculation region, the coordinates of each sampling point in the sampling offset matrix are corrected to obtain the sampling correction matrix;
[0022] The circular grayscale image is downsampled according to the sampling correction matrix to obtain the downsampled image.
[0023] Optionally, storing the statistically obtained pixel count into a pre-built circle center counting matrix includes:
[0024] A center-counting matrix is pre-created, and the center-counting matrix has the same size as the circular grayscale image;
[0025] The counted number of pixels is stored in the center counting matrix at the coordinate position corresponding to the selected point.
[0026] Optionally, step S4 includes:
[0027] Starting from the reference starting point of the circle center calculation region, the sampling center of the circular sampling is moved row by row according to the first step length;
[0028] If the movement exceeds the boundary point of the calculation area of the center, then move down to the target row according to the second step length, and continue to move row by row in the target row according to the first step length;
[0029] After each move, repeat step S3 until the circle center calculation area has been moved and traversed to obtain the circle center counting matrix.
[0030] On the other hand, this application provides a center positioning device based on a circular object through one embodiment of the application. The device includes an acquisition module, a sampling module, a processing module, and a determination module, wherein:
[0031] The acquisition module is used to acquire a circular grayscale image of the circular object;
[0032] The sampling module is used to perform circular sampling on the circular grayscale image to obtain a sampling offset matrix;
[0033] The processing module is used to downsample and count the difference pixels in the sampling offset matrix and the center calculation area of the circular grayscale image, and store the number of pixels obtained by the statistics into a pre-built center counting matrix.
[0034] The processing module is further configured to move the sampling center of the circular sample in the center calculation region according to a set step size, and repeatedly execute the steps performed by the processing module until the center calculation region is traversed to obtain the center counting matrix.
[0035] The determining module is used to determine the storage location corresponding to the maximum number of pixels in the center counting matrix as the reference center position of the circular object.
[0036] For any content not introduced or described in the embodiments of the present invention, please refer to the relevant descriptions in the foregoing method embodiments; they will not be repeated here.
[0037] On the other hand, this application provides a terminal device through one embodiment of the present application. The terminal device includes: a processor, a memory, a communication interface, and a bus; the processor, the memory, and the communication interface are connected through the bus and complete communication with each other; the memory stores executable program code; the processor reads the executable program code stored in the memory to run a program corresponding to the executable program code, so as to execute the circle center positioning method based on a circular object as described above.
[0038] On the other hand, this application provides a computer-readable storage medium through one embodiment of the application, the computer-readable storage medium storing a program that, when the program is run on a terminal device, executes the circle center positioning method based on a circular object as described above.
[0039] One or more technical solutions provided in this application embodiment have at least the following technical effects or advantages: This application acquires a circular grayscale image of the circular object; performs circular sampling on the circular grayscale image to obtain a sampling offset matrix; performs downsampling and difference pixel statistics on the sampling offset matrix and the center calculation region of the circular grayscale image, and stores the number of pixels obtained by the statistics in a pre-built center counting matrix; moves the sampling center of the circular sampling in the center calculation region according to a set step size, and repeats the above downsampling and difference pixel statistics steps until the center calculation region is traversed to obtain the center counting matrix; the storage position corresponding to the maximum number of pixels in the center counting matrix is determined as the reference center position of the circular object. In the above solution, this application considers the pixel changes of the circular object, performs difference pixel statistics on the circular grayscale image, and then quickly and accurately detects the center position of the circular object in the image. This not only achieves the convenience and accuracy of center position positioning, but also simultaneously solves the technical problems of large computational load and low accuracy in existing circular object positioning schemes. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a flowchart illustrating a method for locating the center of a circular object based on an embodiment of this application.
[0042] Figure 2 This is a schematic diagram of a circular grayscale image provided in an embodiment of this application.
[0043] Figure 3 This is a schematic diagram of a circular sampling scenario provided in an embodiment of this application.
[0044] Figure 4 This is a schematic diagram of the distribution of a sampling offset matrix provided in an embodiment of this application.
[0045] Figure 5 This is a schematic diagram of the calculation region of the center of a circular grayscale image provided in an embodiment of this application.
[0046] Figure 6 and Figure 7 This is a schematic diagram of two possible downsampled images provided in the embodiments of this application.
[0047] Figure 8 This is a schematic diagram of a counting matrix image corresponding to a circle center counting matrix provided in an embodiment of this application.
[0048] Figure 9 This is a schematic diagram of a center positioning device based on a circular object provided in an embodiment of this application.
[0049] Figure 10 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Detailed Implementation
[0050] This application provides a method, apparatus, device, and medium for locating the center of a circular object, which solves the technical problems of large computational load and low accuracy in existing circular object positioning schemes.
[0051] The technical solution of this application embodiment is to solve the above-mentioned technical problems, and the general idea is as follows:
[0052] This application provides a method for locating the center of a circular object, the method comprising the following steps:
[0053] S1. Obtain a circular grayscale image of the circular object;
[0054] S2. Perform circular sampling on the circular grayscale image to obtain the sampling offset matrix;
[0055] S3. Downsample and count the difference pixels in the sampling offset matrix and the center calculation area of the circular grayscale image, and store the number of pixels obtained by the statistics in the pre-built center counting matrix.
[0056] S4. Move the sampling center of the circular sample in the center calculation region according to the set step size, and repeat the above step S3 until the center calculation region is traversed to obtain the center counting matrix.
[0057] S5. The storage location corresponding to the maximum number of pixels in the center counting matrix is determined as the reference center position of the circular object.
[0058] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.
[0059] First, it should be clarified that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0060] Please see Figure 1 This is a flowchart illustrating a method for locating the center of a circular object based on an embodiment of this application. Figure 1 The method shown includes the following implementation steps:
[0061] S1. Obtain a circular grayscale image of the circular object.
[0062] The circular grayscale image described in this application can be a filtered grayscale image. Specifically, this application can first obtain an initial image of the circular object, wherein the initial image includes the imaging area of the circular object. In this application, the initial image can be a binarized black and white image, a multi-channel color image, or a multi-channel grayscale image. Therefore, in order to simplify subsequent positioning calculations and improve processing speed, this application can perform grayscale processing on the initial image to convert it into a single-channel grayscale processed image. Finally, in order to suppress noise interference in the image, this application can perform filtering processing on the grayscale processed image to obtain the circular grayscale image. The specific implementation of the filtering processing is not limited in this application; for example, Gaussian filtering, median filtering, etc., are possible methods.
[0063] Therefore, in this application, the initial image including the imaging region of the circular object can generate the circular grayscale image after grayscale processing and filtering. Thus, the circular grayscale image also includes the imaging region of the circular object.
[0064] This application does not limit the size of the circular grayscale image, because the circular grayscale image only needs to include the imaging area of the circular object. That is, the size of the circular grayscale image only needs to be larger than the imaging area of the circular object, and the imaging area of the circular object needs to be placed within the circular grayscale image. For example, the size of the circular grayscale image is H×W, where H is the length of the circular grayscale image and W is the width of the circular grayscale image.
[0065] For example, please see Figure 2 This is a schematic diagram of a circular grayscale image of a possible circular object provided in an embodiment of this application. For example... Figure 2 Taking the circular object as an example of a circular mechanical workpiece, the circular mechanical workpiece is composed of multiple concentric circular workpieces, then as follows: Figure 2 The circular grayscale image shown also contains multiple concentric circles.
[0066] S2. Perform circular sampling on the circular grayscale image to obtain the sampling offset matrix.
[0067] This application takes into account that in a circular grayscale image, the pixel values (also known as grayscale values) of pixels along the radius of the circle change significantly, while the pixel values of pixels along the circumference remain basically unchanged. Therefore, this application can use a circular distribution method to perform circular sampling on the circular grayscale image to obtain the corresponding sampling offset matrix.
[0068] In one specific embodiment, this application can perform planar sampling on the circular grayscale image along the radial and circumferential directions according to a preset sampling radius, obtaining multiple planar sampling points in a planar coordinate system. The number of these multiple planar sampling points is not limited in this application, and the coordinates of these multiple planar sampling points are circularly distributed relative to the center of the circular sampling circle. The sampling radius is a system-defined setting; for example, this application can set the sampling radius of the sampling circle to R. The number of sampling points corresponding to the radial and circumferential directions is also not limited in this application.
[0069] Specifically, for example, this application can perform planar sampling on the circular grayscale image according to the sampling radius R of the sampling circle, the number of sampling points along the radius direction being N, and the number of sampling points along the circumference direction being M. In this case, the sampling precision along the radius direction is R / N, and the sampling precision along the circumference direction is 360 / M. Here, M and N are both positive integers that are user-defined by the system. Generally, the larger the values of M and N, the lower the computational efficiency of this application's solution, but the higher the computational precision.
[0070] Please see Figure 3 This diagram illustrates a scenario involving circular sampling. Figure 3 In this application, planar sampling is performed along the radial direction OW and the circumferential direction WH, respectively, to obtain multiple planar sampling points in the planar coordinate system.
[0071] After obtaining multiple planar sampling points, this application can transform the multiple planar sampling points in the planar coordinate system to the polar coordinate system to obtain the corresponding sampling offset matrix. Please also refer to... Figure 4 A schematic diagram illustrating a possible distribution of the sampling offset matrix is shown. For example... Figure 4 The sampling offset matrix shown has a size of M×N, where M is the number of columns and N is the number of rows. The coordinates of the element in the nth row and mth column of the sampling offset matrix (also called the coordinates of the sampling point or pixel) can be represented as P(X... m Y n The specific formula is shown in formula (1):
[0072]
[0073]
[0074] S3. Perform downsampling and differential pixel statistics on the sampling offset matrix and the center calculation region of the circular grayscale image, and store the number of pixels obtained from the statistics into a pre-built center counting matrix.
[0075] In one specific embodiment, this application can first determine the center calculation region of the circular grayscale image based on the preset sampling radius. Specifically, this application can determine the range of the center position of the circular sampling, i.e., the center calculation region, based on the sampling radius R and the size H×W of the circular grayscale image. The reference starting point of the center calculation region is (R, R), and the shape and size of the center calculation region are not limited; for example, the center calculation region can be a rectangular region of (H-2R)×(W-2R).
[0076] For example, please see Figure 5 A schematic diagram of a possible region for calculating the center of a circle is shown. For example... Figure 5 The reference starting point of the circle center calculation region shown is the upper left corner D(R, R) of the circle center calculation region. The circle center calculation region is located in the center area of the circular grayscale image, represented as a rectangular area bounded by a width of W-2R and a length of H-2R, illustrated as region B. Other areas in the circular grayscale image besides the circle center calculation region can be represented as region A.
[0077] Next, this application can downsample the circular grayscale image based on the calculated center region and the sampling offset matrix to obtain a downsampled image. Specifically, this application can correct the coordinates of each sampling point in the sampling offset matrix based on a selected point in the calculated center region to obtain a sampling correction matrix. Then, based on the sampling correction matrix, the circular grayscale image is downsampled to obtain the downsampled image.
[0078] In specific implementation, this application can select any pixel point from the circular calculation area as the selected point of the circular calculation area, and the coordinates of the selected point can be represented as Q(x, y). Furthermore, this application can use the selected point to modify the coordinates of each sampling point in the sampling offset matrix. Specifically, the coordinates of the selected point and the coordinates of each sampling point in the sampling offset matrix can be superimposed to obtain the corresponding sampling correction matrix. The following example demonstrates the correction method for the sampling point coordinates in the nth row and mth column of the sampling offset matrix, as shown in formula (2):
[0079] P' = P + Q
[0080] X'm =X m +x
[0081] Y' n =Y n +y formula (2)
[0082] Where P' represents the sampling point in the nth row and mth column of the sampling correction matrix, P'(X' m Y' n ) represents the coordinates of P'. P represents the sampling point in the nth row and mth column of the sampling offset matrix, P(X m Y n (x, y) represents the coordinates of P. (x, y) represents the coordinates of the selected point.
[0083] After obtaining the sampling correction matrix, this application can obtain the pixel value corresponding to the coordinate position of each sampling point in the sampling correction matrix from the circular grayscale image, and then combine these pixel values together in the same arrangement order as each sampling point in the sampling correction matrix to obtain the downsampled image.
[0084] For example, please see Figure 6 and Figure 7 This is a schematic diagram of two possible downsampled images provided in the embodiments of this application. The downsampled image is derived from the coordinates (positions) of each sampling point in the sampling correction matrix and the pixel values of each sampling point. Therefore, the downsampled image can be regarded as the expansion of the circular grayscale image in polar coordinates. After the circular shape is expanded in polar coordinates, it will be transformed into a shape similar to a rectangle, and each sampling point can correspond to the sampling correction matrix.
[0085] like Figure 6 Specifically, the downsampled image is shown when the sampling center does not coincide with the true center of the circular object. As shown in the figure, each circular outline of the circular object in the downsampled image is curved in the polar coordinate system.
[0086] like Figure 7 Specifically, the downsampled image is shown when the sampling center coincides with the true center of the circular object. As shown in the figure, each circular outline of the circular object in the downsampled image is approximately a straight line in the polar coordinate system.
[0087] Next, based on the pixel value of each pixel in the downsampled image, this application can use a counting tool such as a counter to count the number of pixels in the downsampled image where the absolute value of the difference between adjacent rows is greater than the absolute value of the difference between adjacent columns. Specifically, this application can start from the 2nd row and 2nd column of the downsampled image, sequentially traversing each pixel in the downsampled image, calculating the absolute value of the difference between the pixel value of that pixel and its left-side adjacent pixel, i.e., calculating the absolute value of the difference between adjacent rows, which can be represented as Diff_H. Similarly, it is also necessary to calculate the absolute value of the difference between the pixel value of that pixel and its adjacent above pixel, i.e., calculating the absolute value of the difference between adjacent columns, which can be represented as Diff_V. Then, the size of Diff_H and Diff_V is compared. If Diff_H is greater than Diff_V, the counter count is incremented by 1; otherwise, the counter count remains unchanged. In other words, this application needs to count the number of pixels in the downsampled image where the absolute value of the difference between adjacent rows is greater than the absolute value of the difference between adjacent columns.
[0088] For example, Table 1 below shows the pixel values of some pixels in a downsampled image.
[0089] Table 1
[0090] 60 65 68 70 73 79 74 74 74
[0091] Taking the pixel with a value of 73 in Table 1 as an example, the absolute value of the column difference Diff_V between it and the pixel with a value of 65 above it is 8; the absolute value of the row difference Diff_H between it and the pixel with a value of 70 to the left is 3. Since 8 is greater than 3, the counter can be incremented by 1.
[0092] Finally, after obtaining the number of pixels, this application can store the number of pixels in a pre-built circle center counting matrix, specifically at the coordinate position (x, y) corresponding to the selected point in the circle center counting matrix. The circle center counting matrix is a pre-created counting storage matrix, and the values of each element in the matrix are set to 0 by default. The circle center counting matrix has the same size as the circular grayscale image; for example, the size of the circle center counting matrix is also H×W.
[0093] S4. Move the sampling center of the circular sample in the center calculation area according to the set step size, and repeat the above step S3 until the center calculation area is traversed to obtain the center counting matrix.
[0094] This application can start from the reference starting point of the circle center calculation region and move the sampling center of the circular sample within the circle center calculation region row by row according to the first step length. When the movement exceeds the boundary point of the circle center calculation region, this application can move down to the target row according to the second step length, and continue to move row by row according to the first step length in the target row. After each movement, the above step S3 is repeated until the entire circle center calculation region is traversed to obtain the circle center counting matrix. Here, the first step length and the second step length can both be set step lengths by the system, and they can be the same or different, which is not limited in this application.
[0095] Specifically, for example, this application can sequentially move the sampling center of the sampling circle from the reference starting point of the center calculation area, i.e., the upper left corner (R, R), to the lower right corner in a "Z" pattern, row by row and column by column. During the row-by-row movement, S pixels are moved each time. When the movement exceeds the right boundary of the center calculation area, it can also jump down by S pixels (i.e., S rows), and continue moving from left to right from the target row reached by the jump. During each movement, this application can execute the above step S3. After all movements are completed, the center counting matrix H×W can be obtained.
[0096] S5. The storage location corresponding to the maximum number of pixels in the center counting matrix is determined as the reference center position of the circular object.
[0097] This application can find the coordinate position of the maximum number of pixels in the circle center counting matrix and determine it as the reference center position of the circular object, which can be represented as C1(X1, Y1).
[0098] For example, please see Figure 8 A schematic diagram of a possible counting matrix image corresponding to a circle center counting matrix is shown. For example... Figure 8 The coordinates of the brightest pixel in the counting matrix image shown are the coordinates of the maximum number of pixels in the circle counting matrix, which is the reference center position of the circular object.
[0099] In an optional embodiment, this application may further increase the size of the sampling offset matrix, using the reference center position as the reference center of the center calculation region, and update the center calculation region. The shape and size of the center calculation region are not limited in this application; for example, it may be a rectangular region with a width and height of 2S. Then, steps S2-S5 are repeated to obtain the final center position of the circular object.
[0100] In specific implementation, this application can simultaneously increase the size of the sampling offset matrix, specifically by increasing the values of M and N, where N is typically less than or equal to R. Simultaneously, taking the reference center position C1 as the center, a new center calculation area is formed with (X1-S, Y1-S) as the reference starting point (upper left corner) of the center calculation area, and a width and height of 2S. Steps S2-S5 are repeated to obtain a new center counting matrix. In step S4, the number of pixels moved each time (i.e., the step size) can be changed according to actual needs; for example, S can be modified to 1. After obtaining the new center counting matrix, this application also determines the coordinate position of the maximum number of pixels in the center counting matrix as the final center position with an accuracy of S, which can be represented as C0(X0, Y0).
[0101] In a specific implementation, this application can also directly expand the circular grayscale image in polar coordinates, directly traverse the pixel values of all pixels, calculate the gradient pixels between each row of pixels, and thus determine the final center position of the circular object.
[0102] In a specific implementation, this application can also directly expand the circular grayscale image in polar coordinates, and then traverse the pixel values of the pixels in the predetermined area according to a predetermined area or a set step size, calculate the gradient pixels between the pixels in the predetermined area, determine the range of the center of the circular pattern, and then continuously adjust the size of the predetermined area or the traversal step size to approach the position of the center of the circular pattern, thereby determining the final center position of the circular object.
[0103] In specific implementation, this application does not directly unfold the circular grayscale image in polar coordinates. Instead, it calculates the offset between the two coordinate systems according to the coordinate transformation relationship between polar and planar coordinates to determine the coordinates of each sampling point. This determines the position of each sampling point in the sampling offset matrix. Then, it iterates through the points in the sampling offset matrix and their corresponding pixel values, determining the final center position of the circular object based on the pixel value distribution. By implementing this embodiment, this application obtains a circular grayscale image of the circular object; performs circular sampling on the circular grayscale image to obtain a sampling offset matrix; performs downsampling and difference pixel statistics on the sampling offset matrix and the center calculation region of the circular grayscale image, storing the statistically obtained pixel count in a pre-built center counting matrix; moves the sampling center of the circular sampling within the center calculation region according to a set step size, repeating the downsampling and difference pixel statistics steps until the center calculation region is traversed, obtaining the center counting matrix; and determines the storage location corresponding to the maximum number of pixels in the center counting matrix as the reference center position of the circular object. In the above solution, this application considers the pixel changes of the circular object, performs differential pixel statistics on the circular grayscale image, and then quickly and accurately detects the center position of the circular object in the image. This not only achieves the convenience and accuracy of center position positioning, but also solves the technical problems of large computational load and low accuracy in existing circular object positioning solutions.
[0104] Based on the same inventive concept, another embodiment of this application provides an apparatus and terminal device for implementing the circle center positioning method based on a circular object described in the embodiments of this application.
[0105] Please see Figure 9 This is a schematic diagram of a center positioning device based on a circular object, provided in an embodiment of this application. Figure 9 The device 90 shown includes an acquisition module 901, a sampling module 902, a processing module 903, and a determination module 904, wherein:
[0106] The acquisition module 901 is used to acquire a circular grayscale image of the circular object;
[0107] The sampling module 902 is used to perform circular sampling on the circular grayscale image to obtain a sampling offset matrix;
[0108] The processing module 903 is used to downsample and count the difference pixels in the sampling offset matrix and the center calculation area of the circular grayscale image, and store the number of pixels obtained by the statistics into a pre-built center counting matrix.
[0109] The processing module 903 is further configured to move the sampling center of the circular sample in the center calculation region according to a set step size, and repeatedly execute the steps performed by the above processing module until the center calculation region is traversed to obtain the center counting matrix.
[0110] The determining module 904 is used to determine the storage location corresponding to the maximum number of pixels in the center counting matrix as the reference center position of the circular object.
[0111] Optionally, the processing module 903 is further configured to:
[0112] Increase the size of the sampling offset matrix, update the center calculation region according to the reference center position, and repeat steps S2-S5 to obtain the final center position of the circular object.
[0113] Optionally, the sampling module 902 is specifically used for:
[0114] Based on a preset sampling radius, the circular grayscale image is sampled in a planar manner along the radial direction and the circumferential direction to obtain multiple planar sampling points;
[0115] The sampling offset matrix is obtained by performing polar coordinate transformation on the multiple planar sampling points, wherein the sampling offset matrix includes the coordinates of the multiple sampling points.
[0116] Optionally, the processing module 903 is specifically used for:
[0117] The center calculation area of the circular grayscale image is determined according to the preset sampling radius;
[0118] Based on the calculated center region and the sampling offset matrix, the circular grayscale image is downsampled to obtain a downsampled image;
[0119] Based on the pixel value of each pixel in the downsampled image, count the number of pixels in the downsampled image where the absolute value of the difference between adjacent rows is greater than the absolute value of the difference between adjacent columns.
[0120] Optionally, the processing module 903 is specifically used for:
[0121] Based on the selected point in the center calculation region, the coordinates of each sampling point in the sampling offset matrix are corrected to obtain the sampling correction matrix;
[0122] The circular grayscale image is downsampled according to the sampling correction matrix to obtain the downsampled image.
[0123] Optionally, the processing module 903 is specifically used for:
[0124] A center-counting matrix is pre-created, and the center-counting matrix has the same size as the circular grayscale image;
[0125] The counted number of pixels is stored in the center counting matrix at the coordinate position corresponding to the selected point.
[0126] Optionally, the determining module 904 is specifically used for:
[0127] Starting from the reference starting point of the circle center calculation region, the sampling center of the circular sampling is moved row by row according to the first step length;
[0128] If the movement exceeds the boundary point of the calculation area of the center, then move down to the target row according to the second step length, and continue to move row by row in the target row according to the first step length;
[0129] After each move, repeat step S3 until the center calculation region is traversed to obtain the center counting matrix.
[0130] For any content not introduced or described in the embodiments of this application, please refer to the relevant descriptions in the foregoing method embodiments; they will not be repeated here.
[0131] Please also refer to 10, which is a structural schematic diagram of a terminal device provided in an embodiment of this application. Figure 10 The terminal device 10 shown includes at least one processor 101, a communication interface 102, a user interface 103, and a memory 104. The processor 101, communication interface 102, user interface 103, and memory 104 can be connected via a bus or other means; this embodiment of the invention takes connection via bus 105 as an example.
[0132] Processor 101 can be a general-purpose processor, such as a central processing unit (CPU).
[0133] The communication interface 102 can be a wired interface (e.g., an Ethernet interface) or a wireless interface (e.g., a cellular network interface or a wireless LAN interface) for communicating with other terminals or websites. In this embodiment of the invention, the communication interface 102 is specifically used to acquire information such as images.
[0134] User interface 103 may specifically be a touch panel, including a touch screen and a touch screen, used to detect operation commands on the touch panel. User interface 103 may also be a physical button or a mouse. User interface 103 may also be a display screen, used to output and display images or data.
[0135] Memory 104 may include volatile memory, such as random access memory (RAM); memory may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); memory 104 may also include combinations of the above types of memory. Memory 104 is used to store a set of program code, and processor 101 is used to call the program code stored in memory 104 to perform the following operation steps:
[0136] S1. Obtain a circular grayscale image of the circular object;
[0137] S2. Perform circular sampling on the circular grayscale image to obtain the sampling offset matrix;
[0138] S3. Downsample and count the difference pixels in the sampling offset matrix and the center calculation area of the circular grayscale image, and store the number of pixels obtained by the statistics in the pre-built center counting matrix.
[0139] S4. Move the sampling center of the circular sample in the center calculation region according to the set step size, and repeat the above step S3 until the center calculation region is traversed to obtain the center counting matrix.
[0140] S5. The storage location corresponding to the maximum number of pixels in the center counting matrix is determined as the reference center position of the circular object.
[0141] Optionally, the processor 101 is further configured to:
[0142] Increase the size of the sampling offset matrix, update the center calculation region according to the reference center position, and repeat steps S2-S5 to obtain the final center position of the circular object.
[0143] Optionally, step S2 includes:
[0144] Based on a preset sampling radius, the circular grayscale image is sampled in a planar manner along the radial direction and the circumferential direction to obtain multiple planar sampling points;
[0145] The sampling offset matrix is obtained by performing polar coordinate transformation on the multiple planar sampling points, wherein the sampling offset matrix includes the coordinates of the multiple sampling points.
[0146] Optionally, the downsampling and difference pixel statistics of the sampling offset matrix and the center calculation region of the circular grayscale image include:
[0147] The center calculation area of the circular grayscale image is determined according to the preset sampling radius;
[0148] Based on the calculated center region and the sampling offset matrix, the circular grayscale image is downsampled to obtain a downsampled image;
[0149] Based on the pixel value of each pixel in the downsampled image, count the number of pixels in the downsampled image where the absolute value of the difference between adjacent rows is greater than the absolute value of the difference between adjacent columns.
[0150] Optionally, the step of downsampling the circular grayscale image based on the calculated center region and the sampling offset matrix to obtain a downsampled image includes:
[0151] Based on the selected point in the center calculation region, the coordinates of each sampling point in the sampling offset matrix are corrected to obtain the sampling correction matrix;
[0152] The circular grayscale image is downsampled according to the sampling correction matrix to obtain the downsampled image.
[0153] Optionally, storing the statistically obtained pixel count into a pre-built circle center counting matrix includes:
[0154] A center-counting matrix is pre-created, and the center-counting matrix has the same size as the circular grayscale image;
[0155] The counted number of pixels is stored in the center counting matrix at the coordinate position corresponding to the selected point.
[0156] Optionally, step S4 includes:
[0157] Starting from the reference starting point of the circle center calculation region, the sampling center of the circular sampling is moved row by row according to the first step length;
[0158] If the movement exceeds the boundary point of the calculation area of the center, then move down to the target row according to the second step length, and continue to move row by row in the target row according to the first step length;
[0159] After each move, repeat step S3 until the circle center calculation area has been moved and traversed to obtain the circle center counting matrix.
[0160] Since the terminal device described in this embodiment is the terminal device used to implement the method in the embodiments of this application, those skilled in the art can understand the specific implementation method and its various variations based on the method described in the embodiments of this application. Therefore, how the terminal device implements the method in the embodiments of this application will not be described in detail here. Any terminal device used by those skilled in the art to implement the method in the embodiments of this application falls within the scope of protection of this application.
[0161] One or more technical solutions provided in this application embodiment have at least the following technical effects or advantages: This application acquires a circular grayscale image of the circular object; performs circular sampling on the circular grayscale image to obtain a sampling offset matrix; performs downsampling and difference pixel statistics on the sampling offset matrix and the center calculation region of the circular grayscale image, and stores the number of pixels obtained by the statistics in a pre-built center counting matrix; moves the sampling center of the circular sampling in the center calculation region according to a set step size, and repeats the above downsampling and difference pixel statistics steps until the center calculation region is traversed to obtain the center counting matrix; the storage position corresponding to the maximum number of pixels in the center counting matrix is determined as the reference center position of the circular object. In the above solution, this application considers the pixel changes of the circular object, performs difference pixel statistics on the circular grayscale image, and then quickly and accurately detects the center position of the circular object in the image. This not only achieves the convenience and accuracy of center position positioning, but also simultaneously solves the technical problems of large computational load and low accuracy in existing circular object positioning schemes.
[0162] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0163] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0164] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0165] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0166] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0167] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for locating the center of a circular object based on the circle, characterized in that, The method comprises the following steps: S1, acquiring a circular gray image of the circular object; S2, circular sampling is performed on the circular gray image to obtain a sampling offset matrix; S3, down-sampling and difference pixel statistics are performed on the sampling offset matrix and a center calculation region of the circular gray image, and the obtained pixel quantity is stored in a pre-built center counting matrix; S4, the sampling center of the circular sampling is moved in the center calculation region according to a set step length, and the step S3 is repeatedly executed until the center calculation region is traversed, so that the center counting matrix is obtained; S5, a storage position corresponding to the maximum pixel quantity in the center counting matrix is determined as a reference center position of the circular object; The down-sampling and difference pixel statistics performed on the sampling offset matrix and the center calculation region of the circular gray image comprise: According to a preset sampling radius, a center calculation region of the circular gray image is determined; According to the center calculation region and the sampling offset matrix, the circular gray image is down-sampled to obtain a down-sampled image; Based on the pixel value of each pixel point in the down-sampled image, the pixel quantity of the down-sampled image in which the absolute value of the difference between adjacent rows is greater than the absolute value of the difference between adjacent columns is counted; According to the center calculation region and the sampling offset matrix, the circular gray image is down-sampled to obtain a down-sampled image, which comprises: According to a selected point in the center calculation region, the coordinates of each sampling point in the sampling offset matrix are corrected to obtain a sampling correction matrix; According to the sampling correction matrix, the circular gray image is down-sampled to obtain the down-sampled image.
2. The method of claim 1, wherein, The method further comprises: The size of the sampling offset matrix is increased, the center calculation region is updated according to the reference center position, and the steps S2-S5 are repeatedly executed to obtain a final center position of the circular object.
3. The method of claim 1, wherein, The step S2 comprises: According to a preset sampling radius, planar sampling is performed on the circular gray image along the radial direction and the circumferential direction to obtain a plurality of planar sampling points; Polar coordinate conversion is performed on the plurality of planar sampling points to obtain the sampling offset matrix, wherein the sampling offset matrix comprises the coordinates of a plurality of sampling points.
4. The method of claim 1, wherein, The pixel quantity obtained by the statistics is stored in a pre-built center counting matrix, which comprises: A center counting matrix is pre-created, and the center counting matrix has the same size as the circular gray image; The counted pixel quantity is stored in the center counting matrix at a coordinate position corresponding to the selected point.
5. The method of claim 1, wherein, The step S4 comprises: From a reference starting point of the center calculation region, the sampling center of the circular sampling is moved row by row according to a first step length; If the movement exceeds a boundary point of the center calculation region, the target row is moved down to a target row according to a second step length, and the movement is continued according to the first step length row by row in the target row; After each movement, the step S3 is repeatedly executed until the center calculation region is traversed, so that the center counting matrix is obtained.
6. A center of a circle positioning device based on a circular object, characterized by, The device comprises an acquisition module, a sampling module, a processing module and a determination module, wherein: The acquisition module is configured to acquire a circular gray image of the circular object. The sampling module is configured to perform circular sampling on the circular gray image to obtain a sampling offset matrix. The processing module is configured to perform down-sampling and difference pixel statistics on the sampling offset matrix and a center calculation region of the circular gray image, and store the counted pixel quantity in a pre-built center counting matrix. The processing module is further configured to move the sampling center of the circular sampling in the center calculation region by a set step length, and repeatedly perform the steps executed by the processing module until the center calculation region is traversed, so as to obtain the center counting matrix. The determination module is configured to determine a storage location corresponding to the maximum pixel quantity in the center counting matrix as a reference center position of the circular object. The down-sampling and difference pixel statistics on the sampling offset matrix and the center calculation region of the circular gray image include: determining a center calculation region of the circular gray image according to a preset sampling radius; performing down-sampling on the circular gray image according to the center calculation region and the sampling offset matrix to obtain a down-sampled image; based on a pixel value of each pixel point in the down-sampled image, counting a pixel quantity of pixels whose absolute value of adjacent row difference is greater than that of adjacent column difference in the down-sampled image. The down-sampling on the circular gray image according to the center calculation region and the sampling offset matrix to obtain a down-sampled image includes: correcting coordinates of each sampling point in the sampling offset matrix according to a selected point in the center calculation region to obtain a sampling correction matrix; performing down-sampling on the circular gray image according to the sampling correction matrix to obtain the down-sampled image.
7. A terminal device, characterized by comprising: The terminal device comprises a processor, a memory, a communication interface and a bus; the processor, the memory and the communication interface are connected through the bus and complete communication among each other; the memory stores executable program codes; the processor runs programs corresponding to the executable program codes by reading the executable program codes stored in the memory, so as to execute the circular center positioning method based on a circular object as claimed in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores programs, and when the programs run in the terminal device, the circular center positioning method based on a circular object as claimed in any one of claims 1-5 is executed.
Citation Information
Patent Citations
Industrial product roundness detection method and device
CN113870189A
Circular calibration plate identification method
CN113963070A