Visual identification method and device for installation eccentricity of grating encoder, medium and product
By performing edge detection and line filtering on the binarized image of the grating encoder, the eccentricity of the grating code disk is located, which solves the problems of time-consuming eccentricity adjustment and insufficient universal adaptability of the grating code disk in photoelectric encoders, and realizes efficient and accurate eccentricity calculation.
Patent Information
- Application Number
- CN202511251479.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-03
- Publication Date
- 2025-11-14
AI Technical Summary
Existing technologies in photoelectric encoders involve time-consuming eccentric adjustment of the grating code disk, making it difficult to eliminate eccentric errors. They also lack versatility and have complex calculation processes, which affect measurement efficiency and accuracy.
By performing edge detection on the binarized image of the grating encoder, extracting the single-pixel skeleton structure, selecting the straight line with the gradient closest to the horizontal, locating the tangent point of the incomplete circular feature line on the code disk, and calculating the eccentricity, the method avoids relying on special features of the code disk and complex fitting of the arc curve.
It improves the universality and flexibility of grating encoder installation eccentricity identification, ensures accuracy and efficiency, simplifies the calculation process, and reduces the impact of noise interference on identification.
Smart Images

Figure CN120947532A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of motor encoder eccentricity recognition technology, and more specifically, to a visual recognition method, device, medium, and product for grating encoder installation eccentricity. Background Technology
[0002] Circular grating code disks are commonly used in photoelectric encoders. They are usually mounted on the shaft of a servo motor and rotate synchronously with the motor. The light and dark code tracks on the grating are used to achieve precise control and detection of displacement. They are widely used in industrial production.
[0003] The installation precision requirements between the encoder disk and the motor spindle are extremely high. Currently used manual installation methods are not only time-consuming but also difficult to eliminate eccentricity errors through manual adjustment. Some existing machine vision adjustment methods combine push rods and high-definition cameras, controlling a servo motor to rotate the encoder disk and capturing multiple sets of images at a fixed position, calculating the eccentricity based on the base circle features. However, these methods typically rely heavily on specific preset features on the encoder disk, using circular fitting for calculation. While effective in specific scenarios, their recognition accuracy drops significantly when the encoder disk type is changed, resulting in insufficient general adaptability. Furthermore, the complex calculation process also significantly impacts measurement efficiency.
[0004] Therefore, it is necessary to propose a universal method for measuring the eccentricity of a circular code disk, which can improve the universality and flexibility of the technology while ensuring accuracy and efficiency. Summary of the Invention
[0005] In view of this, this application provides a visual recognition method, device, medium, and product for grating encoder mounting eccentricity.
[0006] The first aspect of this application provides a visual recognition method for eccentric mounting of a grating encoder, comprising: performing edge detection on a binarized image of a circular grating code disk of the grating encoder to obtain an initial edge pixel map, wherein the binarized image is a local image of an approximately horizontal region of the grating in the circular grating code disk, including the end region of the grating; performing pixel-by-pixel row scanning to detect continuous horizontal edge segments in the initial edge pixel map and extracting the single-pixel skeleton structure of the grating; performing connected component labeling on the single-pixel skeleton structure to obtain position information of multiple straight lines within the connected region of the single-pixel skeleton structure; filtering the target straight line among the multiple straight lines based on the position information; generating a target rectangular region with the endpoint of the target straight line as the center point, and extracting target corner points within the target rectangular region; obtaining the maximum difference between the corner coordinates of the target corner points and the shaft angle of the servo motor controlling the rotation of the circular grating code disk, and determining the eccentricity of the circular grating code disk based on the maximum difference.
[0007] According to an embodiment of this application, the step of scanning row by row to detect continuous horizontal edge segments in the initial edge pixel map and extracting the single-pixel skeleton structure of the grating includes: scanning row by row in the initial pixel map to obtain the start and end pixel column numbers of the continuous horizontal edge segments; if the start and end pixel column numbers of the left and right adjacent regions of the current continuous horizontal edge segment and the previous continuous horizontal edge segment are the same, then the current continuous horizontal edge segment and the previous continuous horizontal edge segment are both valid edge segments; when the current continuous horizontal edge segment and the previous continuous horizontal edge segment are both valid edge segments, based on the lateral connectivity and neighborhood relationship, it is determined whether to retain the current continuous horizontal edge segment and the previous continuous horizontal edge segment; the retained continuous horizontal edge segments are refined into the single-pixel skeleton structure.
[0008] According to an embodiment of this application, when both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments, determining whether to retain the current continuous horizontal edge segment and the previous continuous horizontal edge segment based on lateral connectivity and neighborhood relationships includes: if the current continuous horizontal edge segment and the previous continuous horizontal edge segment have a lateral connection, then retain the current continuous horizontal edge segment and the previous continuous horizontal edge segment; if the current continuous horizontal edge segment is located at an edge position, then determine whether to retain the current continuous horizontal edge segment based on neighborhood relationships, and retain the previous continuous horizontal edge segment; in other cases besides the above two, retain the previous continuous horizontal edge segment.
[0009] According to an embodiment of this application, in the process of labeling connected components of the single-pixel skeleton structure, the method includes: determining vertical connectivity of the single-pixel skeleton structure; if the similarity of pixel columns in the vertical direction between the current detection region and a detection region in the previous row is greater than a first threshold, then the current detection region and the detection region in the previous row are vertically connected, and the current detection region and the detection region in the previous row are assigned the same line label; determining horizontal connectivity of the single-pixel skeleton structure; if the horizontal boundary distance between the current detection region and a detection region in the previous row is less than a second threshold, when it is confirmed that the current detection region and the detection region in the previous row have the same line label are vertically connected, the current detection region is assigned the same line label, wherein the second threshold is a dynamic threshold determined based on the resolution of the binarized image and the code track size of the raster encoder; and determining the connected components of the single-pixel skeleton structure based on the connected regions with the same line label.
[0010] According to an embodiment of this application, the step of selecting the target line with the closest gradient to the horizontal among the multiple lines based on the position information includes: when the gradient direction of the multiple lines is continuously positive, selecting the line at the end of the sequence among the multiple lines as the target line; when the gradient direction of the multiple lines is continuously negative, selecting the line at the beginning of the sequence among the multiple lines; if there is a gradient direction jump among the multiple lines, selecting the line with a horizontal span greater than a third threshold and a vertical span less than a fourth threshold as the target line.
[0011] According to an embodiment of this application, generating a target rectangular region by using the endpoint of the target line as the center point includes: when the left half of the target line is not truncated, using the coordinates of the left endpoint of the target line as the coordinates of the center point; when the left half of the target line is truncated, calculating the coordinates of the center point based on the coordinates of the right endpoint of the target line and a preset deviation value; and generating a target rectangular region based on the coordinates of the center point and a preset size.
[0012] According to an embodiment of this application, the eccentricity is one-half of the maximum difference in the corner coordinates.
[0013] A second aspect of this application provides an electronic device comprising: one or more processors; and a memory for storing one or more programs, wherein, when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to perform the method as described in any of the first aspects.
[0014] A third aspect of this application provides a computer-readable storage medium storing computer-executable instructions that, when executed, are used to implement the method as described in any of the first aspects.
[0015] A fourth aspect of this application provides a computer program product comprising computer-executable instructions which, when executed, are used to implement the method as described in any of the first aspects.
[0016] According to the embodiments of this application, by using the straight line features on the code disk, the tangent point of the incomplete circular feature line on the code disk is located for subsequent eccentricity calculation. This solves the problem of the previous reliance on special stripes on the code disk and the addition of complex calculations due to fitting arc curves. It improves the universality and flexibility of the technology while ensuring accuracy and efficiency. Attached Figure Description
[0017] The above and other objects, features and advantages of this application will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0018] Figure 1A schematic diagram and partial view of a code disk for testing according to an embodiment of this application are shown;
[0019] Figure 2 A flowchart illustrating a visual recognition method for eccentric mounting of a grating encoder according to an embodiment of this application is shown schematically.
[0020] Figure 3 The flowchart illustrating the gradient direction transition point processing during gradient filtering according to an embodiment of this application is shown in the schematic diagram.
[0021] Figure 4 This illustration schematically shows the corner point recognition effect in a partial original image of a single encoder disk according to an embodiment of this application;
[0022] Figure 5 A block diagram of an electronic device 500 adapted to implement a visual recognition method for grating encoder mounting eccentricity according to an embodiment of this application is shown schematically. Detailed Implementation
[0023] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of this application for ease of explanation. However, it will be apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application.
[0024] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0025] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0026] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).
[0027] Figure 1 A schematic diagram and partial view of a code disk used for testing according to an embodiment of this application are shown.
[0028] like Figure 1 As shown in the embodiment of this application, a partial view of the right side of the circular grating code disk is captured. In this partial view, the grating is nearly horizontal. Here, L1 is the grating width, and L2 is the spacing between two columns of gratings.
[0029] Figure 2 A flowchart illustrating a visual recognition method for eccentric mounting of a grating encoder according to an embodiment of this application is shown schematically.
[0030] like Figure 2 As shown, the method includes operations S210~S260.
[0031] In operation S210, edge detection is performed on the binarized image of the circular grating code disk of the grating encoder to obtain an initial edge pixel map. The binarized image is a local image of the approximate horizontal region of the grating in the circular grating code disk, including the end region of the grating.
[0032] In this embodiment of the application, data is collected based on an industrial camera, such as... Figure 1 The image near the middle column of the raster shown in the partial image is used as the original image. The original image undergoes preprocessing, including mean filtering to smooth image details, convolving the original grayscale image with a 5×5 kernel to eliminate noise and obtain a denoised image, morphological closing operations for dilation and erosion (including dilation and erosion steps) to eliminate potential contamination in the acquired image, and global thresholding using the maximum inter-class difference method to finally generate a binary image with global grayscale values of 0 and 1.
[0033] Directional edge detection is performed on the binarized image to obtain an initial edge pixel map. Based on the obtained gradient magnitude and gradient direction θ, an approximate horizontal edge is extracted using gradient direction constraints (|θ|≤45°).
[0034] Specifically, the 3×3 Sobel operator is used to detect the horizontal gradient in the binary image. Vertical gradient Through formula Calculate the direction of the gradient.
[0035] In operation S220, continuous horizontal edge segments in the initial edge pixel point map are detected by pixel-by-pixel row scanning to extract the single-pixel skeleton structure of the raster.
[0036] In this embodiment of the disclosure, for the detected near-horizontal straight edge, since the edge generated by the edge detection operation usually has a width of multiple pixels, it is necessary to perform single-pixel edge thinning processing. This operation includes the following steps: creating a skeleton storage matrix S of the same size as the input image, with the initial value set to a white (255) non-skeleton state, and scanning the initial edge pixel map row by row in the order from top to bottom and from left to right.
[0037] S220 includes S221 to S240.
[0038] In operation S221, the continuous horizontal edge segments in the initial pixel point map are scanned pixel by pixel to obtain the start and end pixel column numbers of the continuous horizontal edge segments.
[0039] In operation S222, if the start and end pixel column numbers of the left and right adjacent regions of the current continuous horizontal edge segment and the previous continuous horizontal edge segment are the same, then both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments.
[0040] In operation S223, when both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments, it is determined whether to retain the current continuous horizontal edge segment and the previous continuous horizontal edge segment based on the lateral connection relationship and the neighborhood relationship.
[0041] In operation S224, the retained continuous horizontal edge segments are refined into single-pixel skeleton structures.
[0042] In this embodiment, the pixel interval of the continuous horizontal edge segment of the current row is identified, and its starting column number and ending column number are recorded, denoted as... .
[0043] Set up a 3×2 neighborhood location coding system:
[0044]
[0045] Where P2 represents the edge segment of the previous row, P5 represents the edge segment of the current row, and P1, P3 and P4, P6 are the left and right adjacent regions of the edge segments of the previous and current rows, respectively. If an edge segment of the current row overlaps with an edge segment of the previous row that has already been marked as a skeleton, that is, if both regions P2 and P5 are detected as valid edge segments, then the edge segment is determined according to its location. Regions are preserved in different cases to achieve the effects of maintaining continuity and topological inheritance.
[0046] Optionally, the neighborhood matching range can be extended to a 3×n window (n≥2), where n is the width of the edge pixels generated after edge detection.
[0047] When both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments, based on lateral connectivity and neighborhood relationships, if there is a lateral connection between the current continuous horizontal edge segment and the previous continuous horizontal edge segment, then both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are retained; if the current continuous horizontal edge segment is located at the edge of the grating, then the topological connectivity is inherited or reconstructed based on the neighborhood relationship to determine whether to retain the current continuous horizontal edge segment, and the previous continuous horizontal edge segment is retained; in other cases besides the above two cases, the previous continuous horizontal edge segment is retained.
[0048] In operation S230, connected component labeling is performed on the single-pixel skeleton structure to obtain the position information of multiple straight lines within the connected region of the single-pixel skeleton structure. S230 includes S231~S233.
[0049] In operation S231, vertical connectivity is determined for the single-pixel skeleton structure. If the similarity of the pixel columns in the vertical direction between the current detection region and the detection region in the previous row is greater than the first threshold, then the current detection region and the detection region in the previous row are vertically connected, and the same straight line label is assigned to the current detection region and the detection region in the previous row.
[0050] In this embodiment, if the current detection area and a certain area in the previous row are connected in the vertical direction, and the pixel column similarity is greater than the first threshold, it can be expressed as the column interval overlap rate ≥70% or the column coordinate difference ≤1 pixel. This meets the requirement of vertical connectivity, and the two are considered to belong to the same straight line. The current detection area inherits the straight line label of a certain area in the previous row.
[0051] In operation S232, horizontal connectivity is determined for the single-pixel skeleton structure. If the horizontal boundary distance between the current detection area and a detection area in the previous row is less than the second threshold, and it is confirmed that the current detection area is vertically connected to the detection area with the same line label as the detection area in the previous row, the current detection area is assigned the same line label. The second threshold is a dynamic threshold, determined based on the resolution of the binarized image and the code track size of the raster encoder.
[0052] In this embodiment, the dynamic threshold δ = L2 / pixel resolution, such as Figure 1 As shown, L2 represents the horizontal spacing between the code tracks of the photoelectric encoding. If the horizontal boundary distance between the current detection area and the previous row's label area is less than the dynamic threshold δ, it meets the requirement of horizontal proximity. Even if it is not vertically connected, it is still regarded as a broken part of the same straight line, inherits its label and is marked as pending, waiting for the subsequent row to verify its vertical connectivity. If it is confirmed to be valid, it is restored to a straight line segment; otherwise, it is removed. If the above conditions are not met, a new label is assigned.
[0053] In operation S233, the connected regions of the single-pixel skeleton structure are determined based on the connected regions with the same straight line labels.
[0054] In this embodiment of the disclosure, after determining the connected components, the position information of multiple straight lines within the connected region of the single-pixel skeleton structure is obtained. The position information of each straight line is output in the form of a row index sequence as follows: Where k is the line ID and a is the row number. This indicates the column range covered by the straight line within the row.
[0055] In operation S240, the target line with the closest gradient to the horizontal is selected from multiple straight lines based on the location information.
[0056] For the position information of each straight line, its corresponding straight line feature matrix T is established, as shown in Table 1:
[0057] Table 1
[0058] in, , These are the starting row areas of the target straight line ( The coordinates of the first and last columns of ) , These are the target line termination line regions ( The coordinates of the first and last columns of (). For forms such as The linear characteristic matrix, where the horizontal span of the line is... The longitudinal span of the straight line .
[0059] Based on the radial distribution of the code stripes of the photoelectric encoder, a classification rule for gradient direction change patterns is set: if the gradient direction of multiple straight lines is continuously positive, then the line at the end of the sequence among the multiple straight lines is selected as the target line; if the gradient direction of multiple straight lines is continuously negative, then the line at the beginning of the sequence among the multiple straight lines is selected; if there is a gradient direction jump among multiple straight lines, then the line with a horizontal span greater than the third threshold and a vertical span less than the fourth threshold is selected as the target line. Figure 3 This illustration demonstrates a rule for processing gradient direction transition points provided in an embodiment of this application. For example... Figure 3 As shown, this process gradually selects the straight line with the largest horizontal span and the smallest vertical span.
[0060] Optionally, spatial constraints can be added when performing horizontal line filtering: This effectively eliminates straight lines that are too slanted. To ensure the effective length of the straight line and avoid the problems that occur when a steeply sloping line is truncated. The smaller value could lead to misjudgment, such as Figure 1 L1, as shown, represents the horizontal length of a single code track in photoelectric encoding.
[0061] In operation S250, the endpoints of the target line are used as the center points to generate a target rectangular area, and the target corner points within the target rectangular area are extracted.
[0062] In the embodiments of this application, based on the line position information, the starting column coordinates and ending column coordinates of the first and last rows of the row index are obtained, and a line feature matrix is constructed by comparing the starting column coordinates of the first and last rows. ,in, .if This indicates that the line has a horizontal gradient. Otherwise, if... It represents the starting column coordinates of the first row, indicating that the line has a positive gradient; if These are the starting column coordinates of the tail row, indicating that the line has a positive gradient. Based on the line's characteristic matrix, we can obtain the line's lateral span. For an m×n image, if This means that the right half of the line is cut off. If the above condition is not met, it means that the left half of the line has been truncated; otherwise, it means that the line has been extracted completely.
[0063] For example, for an image with a resolution of 1920×1080, if This means that the right half of the line is cut off. If the condition is met, it means the left half of the line has been truncated; otherwise, the line has been completely extracted. The coordinates of the edge endpoints of the identified lines are extracted as the final output. result.
[0064] Specifically, when the left half of the target line is not truncated, the coordinates of the left endpoint of the target line are used as the center point coordinates. When the left half of the target line is truncated, the center point coordinates are calculated based on the coordinates of the right endpoint of the target line and a preset deviation value ε. The center point coordinates are the sum of the right endpoint coordinates and the preset deviation value ε. A target rectangular area is generated based on the center point coordinates and a preset size. The deviation value ε depends on the spacing width of the code tracks and the pixel resolution in the code disk.
[0065] In the embodiments of this application, based on the center point coordinates When generating a rectangular ROI region, set the row offset. , and column offset , The offset value is determined based on the scene, which can minimize the computation of the corner response function, avoid background interference, and improve the accuracy of corner positioning. In practical applications, it can be adjusted through the user configuration interface.
[0066] In the embodiments of this application, the Harris corner response function calculation window is set to 5×5 pixels, 16% of the maximum response value is dynamically taken as the corner discrimination threshold, the non-maximum suppression radius is 5 pixels, and the x-coordinates of all corners that pass the filtering are recorded. Ideally, only one corner is output; if two or more corners appear, the average value of the corner coordinates is output.
[0067] Optionally, without departing from the core idea of this solution, alternatives to the corner detection method include, but are not limited to, improved Harris algorithm, FAST, SURF or deep learning corner detection.
[0068] Figure 4 The illustration shows the corner recognition effect in a partial original image of a single encoder disk according to an embodiment of this application.
[0069] In operation S260, the maximum difference between the corner coordinates of the target corner point and the rotation angle of the servo motor controlling the rotation of the circular grating code disk is obtained, and the eccentricity of the circular grating code disk is determined based on the maximum difference.
[0070] The obtained corner coordinates are processed using the following formula:
[0071]
[0072] Collect information from each image Using quadratic interpolation, find The corresponding maximum value and minimum value and the corresponding and Ideally, and 180° difference This refers to the rotation angle of the servo motor's shaft. The eccentricity is half of the maximum difference between the corner coordinates, as given by the formula... Calculate the eccentricity of the target code disk.
[0073] This application proposes a visual recognition method for eccentric installation of a grating encoder. By utilizing the straight line features on the code disk, the tangent point of the incomplete circular feature line on the code disk is located for subsequent calculation of the eccentricity. This solves the problem of relying on special stripes on the code disk and the complex calculations required by fitting arc curves, thus improving the universality and flexibility of the technology while ensuring accuracy and efficiency.
[0074] This method proposes an "edge refinement, line aggregation, gradient detection, and corner output" mode. Through the row scanning mode, each step is output in the form of pixels, which is easy to port to integrated circuit chips such as FPGA and SoC. Through pipeline design, its efficiency advantage can be further utilized.
[0075] This method addresses the issue of misjudging broken line segments due to noise interference in traditional skeleton connected component labeling methods by employing a dynamic threshold-driven pending state mechanism. It improves the robustness of broken region repair while maintaining single-pixel accuracy. Furthermore, the addition of a line feature matrix and gradient direction change classification mechanism avoids extensive gradient division calculations in the process.
[0076] Figure 5 A block diagram of an electronic device suitable for implementing the methods described above, according to an embodiment of this application, is illustrated schematically. Figure 5 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0077] like Figure 5 As shown, an electronic device 500 according to an embodiment of this application includes a processor 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage portion 508 into a random access memory (RAM) 503. The processor 501 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 501 may also include onboard memory for caching purposes. The processor 501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of this application.
[0078] RAM 503 stores various programs and data required for the operation of electronic device 500. Processor 501, ROM 502, and RAM 503 are interconnected via bus 504. Processor 501 executes various operations of the method flow according to embodiments of this application by executing programs in ROM 502 and / or RAM 503. It should be noted that the programs may also be stored in one or more memories other than ROM 502 and RAM 503. Processor 501 may also execute various operations of the method flow according to embodiments of this application by executing programs stored in said one or more memories.
[0079] According to embodiments of this application, the electronic device 500 may further include an input / output (I / O) interface 505, which is also connected to a bus 504. The electronic device 500 may also include one or more of the following components connected to the input / output (I / O) interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the input / output (I / O) interface 505 as needed. A removable medium 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 510 as needed so that computer programs read from it can be installed into the storage section 508 as needed.
[0080] According to embodiments of this application, the method flow according to embodiments of this application can be implemented as a computer software program. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the methods shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is executed by processor 501, it performs the functions defined in the system of embodiments of this application. According to embodiments of this application, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0081] This application also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of this application.
[0082] According to embodiments of this application, the computer-readable storage medium can be a non-volatile computer-readable storage medium. Examples include, but are not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0083] For example, according to embodiments of this application, a computer-readable storage medium may include the ROM 502 and / or RAM 503 described above and / or one or more memories other than ROM 502 and RAM 503.
[0084] Embodiments of this application also include a computer program product comprising a computer program containing program code for performing the methods provided in the embodiments of this application. When the computer program product is run on an electronic device, the program code is used to enable the electronic device to implement the visual recognition method for eccentric grating encoder installation provided in the embodiments of this application.
[0085] When the computer program is executed by the processor 501, it performs the functions defined in the system / apparatus of this application embodiment. According to the embodiments of this application, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0086] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 509, and / or installed from a removable medium 511. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0087] According to embodiments of this application, program code for executing the computer programs provided in the embodiments of this application can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0088] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions. Those skilled in the art will understand that the features described in the various embodiments of this application can be combined and / or combined in various ways, even if such combinations are not explicitly described in this application. In particular, without departing from the spirit and teachings of this application, the features described in the various embodiments of this application can be combined and / or combined in various ways. All such combinations and / or combinations fall within the scope of this application.
[0089] The embodiments of this application have been described above. However, these embodiments are merely illustrative and not intended to limit the scope of this application. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Without departing from the scope of this application, those skilled in the art can make various substitutions and modifications, all of which should fall within the scope of this application.
Claims
1. A visual recognition method for misaligned grating encoder mounting, comprising: Edge detection is performed on the binarized image of the circular grating code disk of the grating encoder to obtain an initial edge pixel map. The binarized image is a local image of the approximate horizontal region of the grating in the circular grating code disk, including the end region of the grating. The continuous horizontal edge segments in the initial edge pixel point map are detected by pixel-by-pixel row scanning, and the single-pixel skeleton structure of the grating is extracted. The single-pixel skeleton structure is labeled with connected components to obtain the position information of multiple straight lines within the connected region of the single-pixel skeleton structure. Based on the location information, select the target straight line among the multiple straight lines whose gradient is closest to horizontal; The target rectangular region is generated by taking the endpoints of the target line as the center point, and the target corner points within the target rectangular region are extracted. The maximum difference between the corner coordinates of the target corner point and the rotation angle of the servo motor controlling the rotation of the circular grating code disk is obtained, and the eccentricity of the circular grating code disk is determined based on the maximum difference.
2. The method according to claim 1, wherein the step of scanning row by row to detect continuous horizontal edge segments in the initial edge pixel map and extracting the single-pixel skeleton structure of the grating comprises: Scan the continuous horizontal edge segments in the initial pixel point map pixel by pixel to obtain the start and end pixel point column numbers of the continuous horizontal edge segments; If the start and end pixel column numbers of the left and right adjacent regions of the current continuous horizontal edge segment and the previous continuous horizontal edge segment are the same, then both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments. When both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments, it is determined whether to retain the current continuous horizontal edge segment and the previous continuous horizontal edge segment based on the lateral connectivity and neighborhood relationship. The retained continuous horizontal edge segments are refined into the single-pixel skeleton structure.
3. The method according to claim 1, wherein when both the current continuous horizontal edge segment and the previous continuous horizontal edge segment are valid edge segments, determining whether to retain the current continuous horizontal edge segment and the previous continuous horizontal edge segment based on lateral connectivity and neighborhood relationships includes: If the current continuous horizontal edge segment and the previous continuous horizontal edge segment are laterally connected, then the current continuous horizontal edge segment and the previous continuous horizontal edge segment are retained. If the current continuous horizontal edge segment is located at an edge position, then based on the neighborhood relationship, it is determined whether to retain the current continuous horizontal edge segment and retain the previous continuous horizontal edge segment; In all other cases except the two mentioned above, the previous continuous horizontal edge segment is retained.
4. The method according to claim 1, wherein during the process of performing connected component labeling on the single-pixel skeleton structure, the method includes: Vertical connectivity is determined for the single-pixel skeleton structure. If the similarity of the pixel columns in the vertical direction between the current detection area and the detection area in the previous row is greater than a first threshold, then the current detection area and the detection area in the previous row are vertically connected, and the same straight line label is assigned to the current detection area and the detection area in the previous row. The single-pixel skeleton structure is horizontally connected. If the horizontal boundary distance between the current detection area and a detection area in the previous row is less than a second threshold, and the current detection area is vertically connected to a detection area with the same line label as the previous row, the current detection area is assigned the same line label. The second threshold is a dynamic threshold, determined based on the resolution of the binarized image and the code track size of the raster encoder. The connected regions of the single-pixel skeleton structure are determined based on the connected regions with the same straight line labels.
5. The method according to claim 1, wherein filtering the target line whose gradient is closest to horizontal among the plurality of straight lines based on the location information comprises: If the gradient direction of the multiple lines is continuously positive, then the line at the end of the sequence of the multiple lines is selected as the target line. If the gradient direction of the multiple lines is continuously negative, then the first line of the sequence among the multiple lines is selected; If there is a gradient direction jump among the multiple straight lines, the straight line with a horizontal span greater than the third threshold and a vertical span less than the fourth threshold is selected as the target straight line.
6. The method according to claim 1, wherein generating the target rectangular region by using the endpoints of the target straight line as center points comprises: When the left half of the target line is not truncated, the coordinates of the left endpoint of the target line are taken as the coordinates of the center point. When the left half of the target line is truncated, the coordinates of the center point are calculated based on the coordinates of the right endpoint of the target line and a preset deviation value. A target rectangular region is generated based on the center point coordinates and the preset size.
7. The method according to claim 1, wherein the eccentricity is one-half of the maximum difference in the coordinates of the corner points.
8. An electronic device, comprising: One or more processors; Memory, used to store one or more programs. Wherein, when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the method as described in any one of claims 1 to 7.
9. A computer-readable storage medium storing computer-executable instructions, which, when executed, are used to implement the method as claimed in any one of claims 1 to 7.
10. A computer program product comprising computer-executable instructions, which, when executed, are used to perform the method as described in any one of claims 1 to 7.