Method and device for obtaining offset in circuit board alignment process, and electronic equipment
By performing image segmentation and homography matrix correction on the test diagram and template diagram of the circuit board, combined with template alignment and contour alignment, the problem of inaccurate offset in the prior art is solved, and the alignment accuracy and the accuracy of circuit board quality inspection are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGZHOU SHIYUAN ELECTRONICS CO LTD
- Filing Date
- 2024-12-11
- Publication Date
- 2026-06-12
AI Technical Summary
In existing technologies, the offset between the printed circuit board test pattern and the template pattern is not accurately determined by microscopic observation and measurement, which affects the alignment accuracy.
By acquiring the test image and template image of the circuit board, performing image segmentation, and then using homography matrix correction to capture the image, combined with template alignment and contour alignment, the offset between the test element object and the template element object is determined.
It improves the alignment accuracy between the test diagram and the template diagram, ensures accurate matching of element objects, and enhances the accuracy of circuit board quality inspection.
Smart Images

Figure CN122199363A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electronic equipment technology, and more specifically, to a method, apparatus, and electronic equipment for obtaining offset during circuit board alignment. Background Technology
[0002] Printed circuit boards (PCBs) are essential carriers of electronic components, playing a crucial role in numerous electronic devices. The quality of PCBs not only affects the performance and stability of electronic devices but also significantly impacts their lifespan. PCBs are susceptible to oxidation and scratches during production and transportation; therefore, quality inspection of PCBs is necessary.
[0003] Currently, the relevant technology involves acquiring a test image of the printed circuit board (PCB), aligning the test image with a template image, and then inspecting the test image to achieve the purpose of PCB quality inspection. Specifically, the relevant technology uses microscopic observation and measurement to determine the offset between elements on the test image and elements on the template image. However, the offset determined in this way is inaccurate and will affect the alignment accuracy between the test image and the template image.
[0004] Therefore, there is an urgent need for a method to obtain the offset during the circuit board alignment process, so as to determine the accurate offset between the element objects on the test pattern and the element objects on the template pattern, and improve the alignment accuracy between the test pattern and the template pattern. Summary of the Invention
[0005] This application provides a method, apparatus, and electronic device for obtaining offset during circuit board alignment. The method can accurately determine the offset between the test element object on the test diagram and the template element object on the template diagram, thereby improving the alignment accuracy between the test diagram and the template diagram.
[0006] Firstly, a method for obtaining offset during circuit board alignment is provided. The method includes: acquiring a test image of the circuit board and a corresponding template image, wherein the test image is obtained by correcting a photograph of the circuit board, and the test image and the template image have the same dimensions; dividing the test image and the template image into blocks to obtain multiple test block images in the test image and multiple template block images in the template image, each test block image having a corresponding template block image; for any one of the multiple test block images, taking that test block image as a target test block image, and aligning the target test image with the template image in the template... The corresponding template block diagram in the figure is aligned to determine the first offset of the target test block diagram. The first offset is the offset between the target test block diagram and the corresponding template block diagram during the template alignment process. For one or more test element objects in the target test block diagram, based on the first offset of the target test block diagram, the outline of the test element object is aligned with the template element object corresponding to the test element object in the corresponding template block diagram to determine the second offset of the test element object. The second offset is the offset between the test element object and the corresponding template element object during the outline alignment process.
[0007] In the above technical solution, the photographed image of the circuit board is corrected (including correction of the shape, position, and size of the photographed image) to obtain a test image of the circuit board. Further, the test image and the template image are divided into image blocks to obtain multiple test block images in the test image and multiple template block images in the template image. For any test block image (target test block image) among the multiple test block images and its corresponding template block image in the template image, the method performs template alignment between the target test block image and the corresponding template block image to determine a first offset between the target test block image and the corresponding template block image. This can determine the offset distance between most test elements on the target test block image and their corresponding template elements on the corresponding template block image. Furthermore, for one or more test element objects in the target test block image, the method, based on the first offset of the target test block image, performs contour alignment between the test element object and its corresponding template element object in the corresponding template block image to determine a second offset between the test element object and the corresponding template element object. In other words, for any test element object, this method uses a two-stage alignment process to accurately determine the approximate offset between the test element object and the corresponding template element object (i.e., the first offset between the target test block image and the corresponding template block image), and then determines the precise offset. This improves the alignment accuracy between the test image and the template image.
[0008] In conjunction with the first aspect, in some possible implementations, the target test block image is aligned with the corresponding template block image in the template image to determine the first offset of the target test block image. This includes: during the sliding of the corresponding template block image on the target test block image, based on the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate positions after each sliding, the first offset of the target test block image is determined, and the pixel coordinate positions on the corresponding template block image are aligned with the pixel coordinate positions on the target test image.
[0009] Combining the first aspect and the above implementation methods, in some possible implementation methods, the first offset of the target test block image is determined based on the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate positions after each sliding. This includes: determining the minimum pixel deviation from multiple pixel deviations, and determining the target position of the corresponding template block image at the minimum pixel deviation; determining the horizontal axis offset of the first offset of the target test block image based on the horizontal deviation between the target position and the starting position of the corresponding template block image; and determining the vertical axis offset of the first offset of the target test block image based on the vertical deviation between the target position and the starting position.
[0010] Combining the first aspect and the above implementation methods, in some possible implementation methods, based on the first offset of the target test block map, the test element object and the corresponding template element object in the corresponding template block map are contour aligned to determine the second offset of the test element object. This includes: taking any test element object as the target test element object, moving the target test element object to the corresponding template block map based on the first offset of the target test block map, determining the target template element object corresponding to the target test element object from multiple template element objects in the corresponding template block map; constructing a search tree corresponding to the multiple first contour coordinates of the target template element object based on multiple first contour coordinates of the target template element object, where each node in the search tree has a corresponding first contour coordinate; searching for the nearest neighbor first contour coordinate for each second contour coordinate of the target test element object from the multiple first contour coordinates in the search tree, where the distance between the second contour coordinate and its nearest neighbor first contour coordinate is less than the distance between the second contour coordinate and other first contour coordinates; and determining the second offset of the test element object based on each second contour coordinate and its nearest neighbor first contour coordinate.
[0011] Combining the first aspect and the above implementation methods, in some possible implementation methods, searching for the nearest neighbor first contour coordinates of each second contour coordinate of the target test element object from multiple first contour coordinates in the search tree includes: for any second contour coordinate among the multiple second contour coordinates, taking any second contour coordinate as the target second contour coordinate, determining the distance between the target second contour coordinate and each of the multiple first contour coordinates to obtain multiple first distances, and determining the minimum distance from the multiple first distances; determining the first contour coordinate corresponding to the minimum distance as the nearest neighbor first contour coordinate corresponding to the target second contour coordinate.
[0012] Combining the first aspect and the above implementation methods, in some possible implementation methods, the second offset of the test element object is determined based on the nearest neighbor first contour coordinates corresponding to each of the multiple second contour coordinates, including: determining the distance between the nearest neighbor first contour coordinates corresponding to each of the multiple second contour coordinates to obtain multiple second distances; and determining the average value of the multiple second distances as the second offset of the test element object.
[0013] Combining the first aspect and the above implementation methods, in some possible implementation methods, a search tree corresponding to the multiple first contour coordinates of the target template element object is constructed, including: determining a dividing axis from the horizontal and vertical axes based on the variance of the multiple first contour coordinates on the horizontal and vertical axes; sorting the multiple first contour coordinates according to the dividing axis to obtain multiple marker point coordinates; determining the first contour coordinates corresponding to the root node in the search tree based on a first number of first contour coordinates and the multiple marker point coordinates; determining the first contour coordinates corresponding to at least one left child node of the root node based on the left marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the left marker point coordinates on the horizontal and vertical axes, and a second number of corresponding first contour coordinates; and determining the first contour coordinates corresponding to at least one right child node of the root node based on the right marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the right marker point coordinates on the horizontal and vertical axes, and a third number of corresponding first contour coordinates.
[0014] Combining the first aspect and the above implementation methods, in some possible implementation methods, determining the first contour coordinates corresponding to the root node in the search tree based on the first number of first contour coordinates and the coordinates of the plurality of marker points includes: when the first number is odd, determining the first contour coordinates corresponding to the marker coordinates at the middle position among the plurality of marker coordinates as the first contour coordinates corresponding to the root node; when the first number is even, determining the first marker coordinates and the second marker coordinates at the middle position among the plurality of marker coordinates; determining the first contour coordinates corresponding to the target marker coordinates among the first and second marker coordinates as the first contour coordinates corresponding to the root node, wherein the coordinate value of the target marker coordinates on the segmentation axis is larger.
[0015] In combination with the first aspect and the above implementation methods, in some possible implementation methods, the method for determining the test image includes: determining a homography matrix, which is used to indicate the mapping relationship between the captured image and the template image; and correcting the captured image based on the homography matrix to obtain the test image.
[0016] Combining the first aspect and the above implementation methods, in some possible implementation methods, determining the homography matrix includes: determining a first preset marker point on each of the N target regions in the template image, where N is a positive integer greater than 3; taking the first preset marker point on each target region as the center, determining a second preset marker point matching the first preset marker point in the captured image according to a first preset distance; and determining the homography matrix based on the coordinates of the N first preset marker points and the corresponding coordinates of the N second preset marker points.
[0017] Combining the first aspect and the above implementation methods, in some possible implementation methods, determining the homography matrix based on the coordinates of N first preset marker points and the corresponding coordinates of N second preset marker points includes: constructing a first matrix based on the coordinates of each of the N first preset marker points and the coordinates of the corresponding second preset marker points, and determining the homography matrix based on the preset matrix and the first matrix.
[0018] Secondly, a device for acquiring offset during circuit board alignment is provided. The device includes: an acquisition module for acquiring a test image of the circuit board and a corresponding template image, wherein the test image is obtained by correcting a photograph of the circuit board and the test image has the same size as the template image; a determination module for dividing the test image and the template image into image blocks to obtain multiple test block images in the test image and multiple template block images in the template image, each test block image having a corresponding template block image; and an alignment module for: taking any one of the multiple test block images as a target test block image and aligning the target test image with the template image. The target test block image is aligned with the corresponding template block image in the template image to determine the first offset of the target test block image. The first offset is the offset between the target test block image and the corresponding template block image during the template alignment process. For one or more test element objects in the target test block image, based on the first offset of the target test block image, the outline of the test element object is aligned with the corresponding template element object in the corresponding template block image to determine the second offset of the test element object. The second offset is the offset between the test element object and the corresponding template element object during the outline alignment process.
[0019] In conjunction with the second aspect, in some possible implementations, the alignment module is specifically used to determine the first offset of the target test block image based on the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position during the sliding process of the corresponding template block image on the target test block image, and the pixel coordinate position on the corresponding template block image is aligned with the pixel coordinate position on the target test image.
[0020] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is specifically used to: determine the minimum pixel deviation from multiple pixel deviations, and determine the target position of the corresponding template block image at the minimum pixel deviation; determine the horizontal axis offset of the first offset of the target test block image based on the horizontal deviation between the target position and the starting position of the corresponding template block image; and determine the vertical axis offset of the first offset of the target test block image based on the vertical deviation between the target position and the starting position.
[0021] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is further configured to: take any test element object as the target test element object, move the target test element object to the corresponding template block map based on the first offset of the target test block map, determine the target template element object corresponding to the target test element object from multiple template element objects in the corresponding template block map; construct a search tree corresponding to the multiple first contour coordinates based on the multiple first contour coordinates of the target template element object, where each node in the search tree has a corresponding first contour coordinate; search for the nearest neighbor first contour coordinate for each second contour coordinate of the target test element object from the multiple first contour coordinates in the search tree, where the distance between the second contour coordinate and the nearest neighbor first contour coordinate corresponding to the second contour coordinate is less than the distance between the second contour coordinate and other first contour coordinates; and determine the second offset of the test element object based on each second contour coordinate and the nearest neighbor first contour coordinate corresponding to the second contour coordinate.
[0022] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is further configured to: for any second contour coordinate among the plurality of second contour coordinates, take any second contour coordinate as the target second contour coordinate, determine the distance between the target second contour coordinate and each of the plurality of first contour coordinates to obtain a plurality of first distances, and determine the minimum distance from the plurality of first distances; determine the first contour coordinate corresponding to the minimum distance as the nearest neighbor first contour coordinate corresponding to the target second contour coordinate.
[0023] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is specifically used to: determine the distance between the nearest neighbor first contour coordinates corresponding to each second contour coordinate, and obtain multiple second distances; and determine the average value of the multiple second distances as the second offset of the test element object.
[0024] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is further specifically used for: determining a dividing axis from the horizontal and vertical axes based on the variance of the plurality of first contour coordinates on the horizontal and vertical axes; sorting the plurality of first contour coordinates according to the dividing axis to obtain a plurality of marker point coordinates; determining the first contour coordinates corresponding to the root node in the search tree based on a first number of first contour coordinates and the plurality of marker point coordinates; determining the first contour coordinates corresponding to at least one left child node of the root node based on the left marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the left marker point coordinates on the horizontal and vertical axes, and a second number of corresponding first contour coordinates; and determining the first contour coordinates corresponding to at least one right child node of the root node based on the right marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the right marker point coordinates on the horizontal and vertical axes, and a third number of corresponding first contour coordinates.
[0025] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is further used to: when the first number is odd, determine the first contour coordinate corresponding to the coordinate of the middle position of the multiple marker point coordinates as the first contour coordinate corresponding to the root node; when the first number is even, determine the coordinates of the first marker point and the second marker point in the middle position among the multiple marker point coordinates; determine the first contour coordinate corresponding to the target marker point coordinate among the first marker point coordinates and the second marker point coordinates as the first contour coordinate corresponding to the root node, wherein the coordinate value of the target marker point coordinate on the segmentation axis is larger.
[0026] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is specifically used to: determine a homography matrix, which is used to indicate the mapping relationship between the captured image and the template image; and correct the captured image based on the homography matrix to obtain the test image.
[0027] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is further specifically used for: determining a first preset marker point on each of the N target areas in the template image, where N is a positive integer greater than 3; determining a second preset marker point matching the first preset marker point in the captured image according to a first preset distance, with the first preset marker point on each target area as the center; and determining the homography matrix based on the coordinates of the N first preset marker points and the corresponding coordinates of the N second preset marker points.
[0028] In conjunction with the second aspect and the above implementation methods, in some possible implementation methods, the determining module is specifically used to: construct a first matrix based on the coordinates of each of the N first preset marker points and the coordinates of the corresponding second preset marker points, and determine the homography matrix based on the preset matrix and the first matrix.
[0029] Thirdly, an electronic device is provided, including a memory and a processor. The memory is used to store executable program code, and the processor is used to call and run the executable program code from the memory, causing the electronic device to perform the methods of the first aspect or any possible implementation thereof.
[0030] Fourthly, a computer-readable storage medium is provided that stores executable program code, which, when run on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation thereof. Attached Figure Description
[0031] Figure 1 This is a schematic diagram of a scene using a camera, provided in an embodiment of this application;
[0032] Figure 2 This is a schematic flowchart illustrating a method for obtaining offset during circuit board alignment according to an embodiment of this application;
[0033] Figure 3 This is a schematic diagram of a circuit board provided in an embodiment of this application;
[0034] Figure 4 This is a schematic diagram of a template block diagram sliding on a target test block diagram, provided in an embodiment of this application;
[0035] Figure 5 This is a schematic diagram illustrating the construction of a search tree according to an embodiment of this application;
[0036] Figure 6 This is a schematic diagram illustrating how to determine the nearest neighbor first contour coordinates corresponding to the second contour coordinates of a target, according to an embodiment of this application.
[0037] Figure 7 This is a schematic diagram of the structure of a device for obtaining offset during circuit board alignment provided in an embodiment of this application;
[0038] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0039] The technical solutions in this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. "And / or" in the text 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, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0040] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0041] Figure 1 This is a schematic diagram of a scene using a camera, provided in an embodiment of this application.
[0042] For example, such as Figure 1 As shown, the relevant technology acquires an image of a printed circuit board (PCB) using a target camera (e.g., a line scan camera), and then corrects this image to obtain a test image. Furthermore, the various elements on the test image are aligned with the elements on the PCB template image to determine whether each element on the test image is printed according to its corresponding element on the template image, thus performing quality inspection of the PCB. This can improve the printing quality of the PCB.
[0043] In related technologies, the specific alignment process involves observing and measuring with a microscope to determine the offset between the elements on the test image and the elements on the template image. This method of determining the offset is inaccurate and affects the alignment accuracy between the test image and the template image.
[0044] To address the aforementioned issues, this application provides a method for obtaining offset during circuit board alignment, thereby determining the accurate offset between element objects on the test pattern and element objects on the template pattern, and improving the alignment accuracy between the test pattern and the template pattern. The specific implementation steps are as follows: Figure 2 .
[0045] Figure 2 This is a schematic flowchart illustrating a method for obtaining offset during circuit board alignment provided in an embodiment of this application.
[0046] It should be understood that the method for obtaining offset during circuit board alignment provided in this application embodiment can be applied to electronic devices. Specifically, the method for obtaining offset during circuit board alignment can also be applied to the controller in the electronic device. In some embodiments, the electronic device is a target terminal, including but not limited to: a computing device or a server.
[0047] For example, such as Figure 2 As shown, the method 200 includes:
[0048] Step 201: The electronic device acquires a test image of the circuit board and a corresponding template image. The test image is obtained by correcting a photograph of the circuit board, and the test image and the template image have the same dimensions.
[0049] It should be understood that the "circuit board" in step 201 above is also called a printed circuit board, which refers to a conductive board implemented using electronic printing technology based on a pre-designed target circuit. The circuit board in step 201 can be regarded as the circuit board to be tested. The circuit board to be tested is a bare board without any components. The circuit board to be tested is mainly composed of basic elements such as lines, pads, via rings, silkscreen, substrate, ink substrate, ink metal, through holes, blind holes, plugged holes, cutouts, and exposed copper.
[0050] It should also be understood that the "image captured" in step 201 above refers to an image acquired by a target camera of the circuit board to be tested, which can be a line scan camera. To overcome the effects of target camera distortion, tilted placement of the circuit board, and warping of the circuit board, method 200 corrects the captured image to obtain a test image. This correction refers to adjusting the shape, orientation, position, and size of the captured image. When correcting the size of the captured image, it may be necessary to crop the black borders.
[0051] It should also be understood that the "template drawing" in step 201 above is pre-designed by a professional designer who can design the template drawing using professional PCB design software. From this template drawing, the actual dimensions and shape of the printed circuit board, multiple element objects on the circuit board, and the printing positions of each element object can be obtained.
[0052] Typically, the test diagram can be aligned with the template diagram. Among the multiple element objects on the template diagram (hereinafter referred to as template element objects), the element objects that match the various element objects on the test diagram (hereinafter referred to as test element objects) can be identified. This verifies whether the test element objects on the test diagram match the corresponding template element objects on the template diagram (whether the type and specifications match), that is, whether the element objects on the circuit board to be tested meet the production (pre-designed target circuit) requirements.
[0053] In one possible implementation, the method for determining the test image in step 201 includes: the electronic device determining a homography matrix, which is used to indicate the mapping relationship between the captured image and the template image; the electronic device correcting the captured image based on the homography matrix to obtain the test image.
[0054] It should be understood that in the above scheme, due to factors such as target camera distortion, circuit board tilt, and circuit board warping, the acquired "image" may not be identical to the template image, which is a standard image corresponding to the circuit board to be inspected. The captured image may be distorted due to target camera distortion, circuit board tilt, and circuit board warping, while the template image avoids these problems. Therefore, the captured image can be corrected based on the mapping relationship (homography matrix) between the captured image and the template image.
[0055] It should also be understood that the "homophony matrix" in the above scheme specifically describes the projection mapping relationship from the shooting plane corresponding to the captured image to the plane corresponding to the template image. Furthermore, this homography matrix contains transformation information such as rotation and translation. If the captured image has geometric changes such as rotation angles and translation amounts relative to the template image, the homography matrix can quantify these geometric changes and perform a reverse operation on the captured image during the transformation process, correcting it to the posture of the template image. When the captured image has inconsistent scaling ratios (such as size changes caused by perspective effects) or perspective distortion, the homography matrix can adjust the proportional relationships of various parts in the captured image, eliminating the distortion caused by perspective effects, and making the shape and proportion of objects in the captured image match the template image.
[0056] It should also be understood that the process of “correcting the captured image through the homography matrix to obtain the test image” in the above scheme can be regarded as an image correction process.
[0057] In the above technical solution, the homography matrix can determine how all pixels in the captured image are transformed from the capturing plane to the plane corresponding to the standard image, thereby correcting the shape, orientation, position and size of the captured image, so that the corrected captured image (i.e. the test image) is as consistent as possible with the template image in terms of geometric relationship and size.
[0058] Figure 3 This is a schematic diagram of a circuit board provided in an embodiment of this application.
[0059] For example, such as Figure 3 As shown in (a), a circuit board placed on a horizontal surface warps, with its edges bending. Figure 3 As shown in (b), the circuit board on the horizontal plane tilts due to being placed at an angle.
[0060] In one possible implementation, the electronic device determines the homography matrix by: determining first preset marker points on each of the N target regions in the template image, where N is a positive integer greater than 3; using the first preset marker points on each target region as centers, the electronic device determines second preset marker points in the captured image that match the first preset marker points according to a first preset distance; and determining the homography matrix based on the coordinates of the N first preset marker points and the corresponding coordinates of the N second preset marker points.
[0061] It should be understood that the difference between the "first preset marker point" and the "second preset marker point" in the above scheme is that the former is a preset marker point on the template image, while the latter is a preset marker point on the test image. The "first preset marker point" refers to the location of the preset marker on the template image, which can indicate a target element object, pattern, number, or symbol. In some embodiments, the preset marker is unique in the corresponding target area.
[0062] It should also be understood that the "second preset marker point matching the first preset marker point" in the above scheme refers to the preset marker on the test image being the same as the preset marker on the template image. Specifically, when the preset marker indicates a target element object, the position of the element object that is the same as the target element object is determined in the captured image according to the first preset distance, with the target element object in the target area of the test image as the center. "Same" here refers to the same type and specifications. The process of "determining the second preset marker point corresponding to each of the N first preset marker points" in the above scheme can be regarded as the process of initial alignment between the test image and the template image.
[0063] It should also be understood that the "first preset distance" in the above scheme is a practical empirical value. The template image obtained through scanning is embedded in the line scan camera (located at the center of the imaging area). The circuit board is picked up by a robotic arm and placed on a conveyor belt, and the line scan camera acquires an image of the circuit board. Issues such as the shooting angle, the tilted placement of the circuit board, and distortion of the line scan camera may cause the acquired image to not be strictly centered, resulting in a deviation from the center position of the template image. However, the impact of shooting angle deviation, circuit board tilt, and line scan camera distortion on the acquired image is generally within a certain range. This method uses the first preset distance to overcome the positional deviation relative to the template image during the image acquisition process.
[0064] In some embodiments, the electronic device determines a first preset marker point on each of the N target regions in the template image, including: the electronic device extracts layers from the template image to obtain multiple layered template images, wherein the element objects on the same layer of the multiple layered template images are the same, and the element objects on different layers of the template images are different; the electronic device selects a target layered template image from the multiple layered template images, and determines a first preset marker point on each of the N target regions in the target layered template image.
[0065] In some embodiments, the multiple layered template diagrams include a template diagram of the layer containing the pads and via rings, a template diagram of the layer containing the pads, a template diagram of the layer containing the vias, and a template diagram of the layer containing the via rings.
[0066] In some embodiments, the target area is a boundary area.
[0067] In some embodiments, N is 4.
[0068] In the above technical solution, the projection mapping relationship between two planes (the shooting plane corresponding to the captured image and the plane corresponding to the template image) can be accurately described by using multiple first preset marker points in the template image and multiple corresponding second preset marker points in the test image. Furthermore, when N is 4, the homography matrix can be determined relatively quickly using the coordinates of the four first preset marker points and the corresponding four second preset marker points. This method can correct the captured image to the same viewpoint as the template image using the homography matrix, achieving correction of the captured image's shape, orientation, position, and size.
[0069] In one possible implementation, the electronic device determines the homography matrix based on the coordinates of N first preset marker points and the corresponding coordinates of N second preset marker points, including: the electronic device constructs a first matrix based on the coordinates of each of the N first preset marker points and the coordinates of the corresponding second preset marker points, and determines the homography matrix based on the preset matrix and the first matrix.
[0070] In some embodiments, the electronic device constructs a first matrix based on the coordinates of each of the N first preset marker points and the coordinates of the corresponding second preset marker points, and determines the homography matrix based on the preset matrix and the first matrix, including: the electronic device determines the homography matrix based on the following formula (1).
[0071]
[0072] in, Let [0 0] be the first matrix. T The transpose of this preset matrix, element h 11 h12 h 13 h 21 h 22 h 23 h 31 h 32 and h 33 For the 9 elements in the homography matrix H, (x i y i (x′) represents the coordinates of the i-th first preset marker point. i y′ i ) represents the coordinates of the i-th second preset marker point.
[0073] It should be understood that substituting the coordinates of any first preset marker point and the corresponding second preset marker point into formula (1) yields two equations. Thus, when N is 4, eight equations can be derived using the coordinates of four first preset marker points and the corresponding four second preset marker points. In the case where the homography matrix has nine unknowns but a total of eight degrees of freedom, these eight equations can be used to determine the eight unknowns in the homography matrix, where h... 33 The value is 1.
[0074] It should also be understood that the homography matrix can be expressed as the following formula (2), and the homography matrix can be transformed by the following formula (3);
[0075]
[0076] Where R represents the rotation information of the captured image during the process of correcting it into the test image (transforming all pixels in the captured image from the shooting plane to the plane corresponding to the template image), t represents the translation information of the captured image during the correction process, K1 and K2 are the intrinsic parameter matrices of the target camera (line scan camera), n represents the normal vector relationship between the shooting plane and the plane corresponding to the template image, and d represents the distance between the origin of the camera coordinate system and the plane corresponding to the template image. Therefore, by correcting the captured image using this homography matrix, the tilt, warping, and dimensional differences in the captured image can be corrected.
[0077] In the above technical solution, through in-depth analysis of the homography matrix, it is possible to clearly identify the horizontal rotation and translation information during the correction of the captured image when mapping it to the same viewpoint as the template image, as well as the information for correcting warping and tilting of the captured image caused by the warping of the circuit board. This method maps the captured image to the same viewpoint (coordinate system) as the template image using the homography transformation matrix, ensuring that the test image and the template image are completely identical, thus providing a strong foundation for the subsequent alignment process.
[0078] Step 202: The electronic device performs image segmentation on the test image and the template image respectively to obtain multiple test segment images in the test image and multiple template segment images in the template image. Each test segment image has a corresponding template segment image.
[0079] It should be understood that "segmenting the test image and template image into blocks" in step 202 above refers to the process of dividing the test image and template image into image blocks of fixed size. Each image block is continuous on the image (test image and template image) and does not overlap. Furthermore, "each test block image has a corresponding template block image" in step 202 above means that each test block image has a template block image that is consistent in position and size. Consistent position means that the test block image is located in the same position on the test image as the template block image is located on the template image.
[0080] For example, the size of both the test image and the template image is 10000*10000. The test image and the template image are divided into blocks to obtain 100 test block images in the test image and 100 template block images in the template image. The size of both the test block images and the template block images is 1000*1000.
[0081] Step 203: For any test block diagram among the multiple test block diagrams, the electronic device takes any test block diagram as the target test block diagram, and performs template alignment between the target test block diagram and the template block diagram corresponding to the target test block diagram in the template diagram, and determines the first offset of the target test block diagram. The first offset is the offset between the target test block diagram and the corresponding template block diagram during the template alignment process.
[0082] It should be understood that the "template alignment" operation in step 203 above involves sliding the template block image across the target test block image, traversing all pixels on the target test block image. Furthermore, the "first offset" in step 203 refers to the offset distance between the target test block image and the corresponding template block image when most test element objects on the target test block image match most template element objects on the template block image during the template alignment process (the distance the target test block image moves towards the corresponding template block image, which can also be called the approximate offset between the test element object and the corresponding template element object).
[0083] In one possible implementation, the electronic device performs template alignment between the target test block image and the corresponding template block image in the template image to determine the first offset of the target test block image. This includes: during the sliding of the corresponding template block image on the target test block image, the electronic device determines the first offset of the target test block image based on the pixel deviation between the target test block image and the corresponding template block image at corresponding pixel coordinate positions after each slide, wherein the pixel coordinate positions on the corresponding template block image are aligned with the pixel coordinate positions on the target test image.
[0084] It should be understood that "the corresponding template block image slides on the target test block image" in the above scheme means that the template block image slides above the layer of the target test block image according to preset rules, that is, the sliding process of the template block image is carried out on the background of the target test block image. In addition, both the template block image and the target test block image are grayscale images.
[0085] Figure 4 This is a schematic diagram of a template block diagram sliding on a target test block diagram, provided in an embodiment of this application.
[0086] For example, taking a template block image with a size of 3×3 and a target test block image with a size of 3×3 as an example, the process of the template block image sliding on the target test block image is described. It should be understood that during the sliding process of the template block image on the target test block image, the target test block image does not move. Therefore, in Figure 4 In this embodiment, the center point of the target test block image is used as the origin of the pixel coordinate system, and the current sliding position of the template block image is characterized by the pixel coordinates of the center point of the template block image in the pixel coordinate system. Specifically, as shown... Figure 4 As shown in (a), after the template block image slides on the target test block image, it is at the current first sliding position. (It should be understood that originally the template block image should be on the layer of the target test block image. However, in order to facilitate a clear and intuitive view of the pixel values at the corresponding pixel coordinate positions of the target test block image and the template block image, this application...) Figure 4 To describe the process of the template block image sliding on the target test block image. At the current first sliding position, the pixel coordinate position P on the template block image. 15 The pixel coordinates P on the target test block image 21 The pixel coordinates P on the template block image correspond to the pixel points; 16 The pixel coordinates P on the target test block image 22 The pixel coordinates P on the template block image correspond to the pixel points; 18The pixel coordinates P on the target test block image 24 The pixel correspondence, and the pixel coordinate position P on the template block image. 19 The pixel coordinates P on the target test block image 25 The corresponding pixels. Furthermore, the template block image continues to slide over the target test block image, as... Figure 4 As shown in (b), after sliding, the template block image is at the current second sliding position. At this current second sliding position, the pixel coordinate position P on the template block image is... 14 The pixel coordinates P on the target test block image 22 The pixel coordinates P on the template block image correspond to the pixel points; 15 The pixel coordinates P on the target test block image 23 The pixel coordinates P on the template block image correspond to the pixel points; 17 The pixel coordinates P on the target test block image 25 The pixel correspondence, and the pixel coordinate position P on the template block image. 18 The pixel coordinates P on the target test block image 26 The corresponding pixels. Furthermore, the template block image continues to slide over the target test block image, as... Figure 4 As shown in (c), after sliding, the template block map is at the current third sliding position. Finally, the template block map continues to slide on the target test block map, as shown... Figure 4 As shown in (d) in the figure, after sliding, the template block diagram is in the current fourth sliding position.
[0087] It should be understood that when the template block image is at the current third or fourth sliding position, the specific pixel coordinates of each pixel on the template block image correspond to the pixel coordinates of the target test block image. This can be referenced from the examples where the template block image is at the current first or second sliding position, and will not be elaborated here.
[0088] In some embodiments, the method for determining the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position after each slide includes: the electronic device determining the difference between the pixel value of each pixel in the target test block image and the pixel value of the pixel at the corresponding pixel coordinate position in the corresponding template block image, and determining the square value of each difference; the electronic device determining the sum of the square values of multiple differences as the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position after each slide.
[0089] In some embodiments, the electronic device determines the difference between the pixel value of each pixel in the target test block image and the pixel value of the corresponding pixel coordinate position in the corresponding template block image, and determines the square value of each difference; and determines the sum of the square values of multiple differences as the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position after each slide, including: the electronic device determines the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position after each slide based on the following formula (4);
[0090] PD=∑(T i (x′,y′)-P j (x, y)) 2 (4)
[0091] Where PD represents the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position after each slide, and T represents the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position. i (x′, y′) is the pixel value of the i-th pixel (x′, y′) in the target test block image, P j (x, y) is the pixel value of the j-th pixel (x, y) corresponding to the i-th pixel (x′, y′) in the corresponding template block image.
[0092] In one possible implementation, the electronic device determines a first offset of the target test block image based on the pixel deviation between the target test block image and the corresponding template block image at corresponding pixel coordinate positions after each slide. This includes: the electronic device determining the minimum pixel deviation from multiple pixel deviations and determining the target position of the corresponding template block image at the minimum pixel deviation; the electronic device determining the horizontal axis offset of the first offset of the target test block image based on the horizontal deviation between the target position and the starting position of the corresponding template block image; and the electronic device determining the vertical axis offset of the first offset of the target test block image based on the vertical deviation between the target position and the starting position.
[0093] It should be understood that in the above scheme, the "target position of the corresponding template block diagram" can be characterized by target coordinates, and the "starting position of the corresponding template block diagram" can be characterized by starting coordinates. In the above scheme, the corresponding template block diagram is in a sliding process; therefore, a coordinate system can be established based on the target point on the target test block diagram as the origin, that is, both the target coordinates and the starting coordinates have the target point as the origin. In some embodiments, the target point is the vertex of the upper left or lower left corner of the target test block diagram.
[0094] In the above technical solution, the minimum pixel deviation is determined from multiple pixel deviations, and a first offset is determined based on the horizontal and vertical deviations between the target position of the template block image corresponding to the minimum pixel deviation and the starting position of the corresponding template block image. This is because if the template block image and the target test block image are perfectly aligned, the pixel deviation is 0. Typically, a pixel deviation of 0 will not occur. Therefore, a target position with a pixel deviation close to 0 is usually found, along with the starting position, to determine the first offset. In other words, a template alignment method is used to determine a coarse offset when the test block image and the template block image are aligned.
[0095] In some embodiments, the electronic device determines the horizontal axis offset in the first offset of the target test block based on the horizontal deviation between the target position and the starting position of the corresponding template block diagram, and determines the vertical axis offset in the first offset of the target test block based on the vertical deviation between the target position and the starting position, including: the electronic device determines the horizontal axis offset and the vertical axis offset in the first offset of the target test block based on the following formula (5);
[0096] (X, Y) = ((X) t -X s ), (Y t -Y s (5)
[0097] Where (X, Y) is the first offset, X is the horizontal axis offset of the first offset, and Y is the vertical axis offset of the first offset. t Y t (X) represents the coordinates of the target. x Y x () represents the starting coordinates.
[0098] Step 204: For one or more test element objects in the target test block diagram, the electronic device performs contour alignment between the test element object and the corresponding template element object in the corresponding template block diagram based on the first offset of the target test block diagram, and determines the second offset of the test element object. The second offset is the offset between the test element object and the corresponding template element object during the contour alignment process.
[0099] It should be understood that the "second offset" in step 204 above refers to the offset distance between the test element object and the corresponding template element object after the test element object in the target test block diagram is determined by contour alignment of the test element object and the corresponding template element object (also known as the precise offset between the test element object and the corresponding template element object).
[0100] In some embodiments, one or more test element objects are at least one of pads, via rings, and through holes.
[0101] In one possible implementation, the electronic device, based on a first offset of the target test block map, performs contour alignment between the test element object and its corresponding template element object in the corresponding template block map to determine a second offset of the test element object. This includes: the electronic device taking any test element object as the target test element object, moving the target test element object onto the corresponding template block map based on the first offset of the target test block map, and determining a target template element object corresponding to the target test element object from multiple template element objects in the corresponding template block map; the electronic device constructing a search tree corresponding to the multiple first contour coordinates of the target template element object, where each node in the search tree has a corresponding first contour coordinate; the electronic device searching for the nearest neighbor first contour coordinate for each second contour coordinate of the target test element object from the multiple first contour coordinates in the search tree, where the distance between the second contour coordinate and its nearest neighbor first contour coordinate is less than the distance between the second contour coordinate and other first contour coordinates; and the electronic device determining the second offset of the test element object based on each second contour coordinate and its nearest neighbor first contour coordinate.
[0102] It should be understood that the first contour coordinates corresponding to each node in the "search tree corresponding to multiple first contour coordinates" in the above scheme are described by two-dimensional coordinates. Therefore, the search tree is a binary space partitioning tree, which can be regarded as a KD-tree.
[0103] In the above technical solution, the constructed search tree can reasonably distribute multiple first contour coordinates, and can arrange the disordered first contour coordinates into an ordered sequence. Furthermore, the method searches for the nearest neighbor first contour coordinates for each second contour coordinate of the target test element object from the first contour coordinates corresponding to each node in the search tree. Thus, this method can quickly and efficiently search for matching nearest neighbor first contour coordinates for each second contour coordinate using the search tree, thereby accurately determining the second offset of the test element object.
[0104] In some embodiments, the electronic device moves the target test element object to the corresponding template block map based on a first offset of the target test block map, performs an erosion operation on the moved target test element object to obtain a processed target test element object, and determines a target template element object corresponding to the processed target test element object from a plurality of template element objects in the corresponding template block map.
[0105] It should be understood that the "erosion operation" in the above scheme is used to eliminate pixels in the outline region of the moved target test element object in order to shrink the target test element object and ensure that a corresponding target template element object is found for the moved target test element object.
[0106] In some embodiments, the electronic device determines the target template element object corresponding to the target test element object from a plurality of template element objects in the corresponding template block diagram, including any one of the following: the electronic device determines the template element object that intersects with the outline of the target test element object from the plurality of template element objects as the target template element object; the electronic device determines the template element object that contains the target test element object and is closest to it from the plurality of template element objects as the target template element object.
[0107] In some embodiments, the electronic device moves the target test element object onto the corresponding template block map based on a first offset of the target test block map, including: the electronic device moves the target test element object onto the corresponding template block map based on the following formula (6);
[0108] (X f Y f )=((X i +X), (Y i +Y)) (6)
[0109] Among them, (X) i Y i (X) represents the pixel coordinates of the target test element object before it moved. f Y f ) represents the pixel coordinates of the target test element object after it has been moved.
[0110] The process of "constructing a search tree corresponding to multiple first contour coordinates" will be discussed below.
[0111] In one possible implementation, the electronic device constructs a search tree corresponding to multiple first contour coordinates of the target template element object, including: the electronic device determining a dividing axis from the horizontal and vertical axes based on the variance of the multiple first contour coordinates on the horizontal and vertical axes; the electronic device sorting the multiple first contour coordinates according to the dividing axis to obtain multiple marker point coordinates; the electronic device determining the first contour coordinates corresponding to the root node in the search tree based on a first number of first contour coordinates and the multiple marker point coordinates; determining the first contour coordinates corresponding to at least one left child node of the root node based on the left marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the left marker point coordinates on the horizontal and vertical axes, and a second number of corresponding first contour coordinates; and determining the first contour coordinates corresponding to at least one right child node of the root node based on the right marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the right marker point coordinates on the horizontal and vertical axes, and a third number of corresponding first contour coordinates.
[0112] It should be understood that "the electronic device sorts multiple first contour coordinates according to the segmentation axis to obtain multiple marker point coordinates" in the above scheme means sorting the multiple first contour coordinates in ascending order of the coordinate values on the segmentation axis.
[0113] It should also be understood that the processes described in the above scheme, namely, "determining the first contour coordinates corresponding to at least one left child node of the root node based on the coordinates of the left marker points other than the first contour coordinates corresponding to the root node, the variance of the left marker point coordinates on the horizontal and vertical axes, and the second number of the corresponding first contour coordinates," and "determining the first contour coordinates corresponding to at least one right child node of the root node based on the coordinates of the right marker points other than the first contour coordinates corresponding to the root node, the variance of the right marker point coordinates on the horizontal and vertical axes, and the third number of the corresponding first contour coordinates," are similar to the process of "determining the first contour coordinates corresponding to the root node based on the multiple first contour coordinates, the variance of the multiple first contour coordinates on the horizontal and vertical axes, and the first number of the corresponding first contour coordinates." The specific steps of "determining the dividing axis from the horizontal and vertical axes based on the variance of the multiple first contour coordinates on the horizontal and vertical axes; sorting the multiple first contour coordinates according to the dividing axis to obtain multiple marker point coordinates; determining the first contour coordinates corresponding to the root node in the search tree based on the first number of the first contour coordinates and the multiple marker point coordinates" will not be elaborated further here.
[0114] In the above technical solution, by constructing a search tree corresponding to the multiple first contour coordinates, the disordered multiple first contour coordinates can be arranged in an orderly manner, ensuring that when performing marker point matching (determining the first contour coordinates of the target marker point), the nearest neighbor first contour coordinates can be quickly found using the target marker point, thus accelerating the execution speed of marker point matching and facilitating fast and efficient retrieval and searching.
[0115] In some embodiments, the electronic device determines a segmentation axis from the horizontal and vertical axes based on the variances of the plurality of first contour coordinates on the horizontal and vertical axes, including: when the first variance of the plurality of first contour coordinates on the horizontal axis is greater than or equal to the second variance of the plurality of first contour coordinates on the vertical axis, the electronic device determines the segmentation axis as the horizontal axis; when the first variance is less than the second variance, the electronic device determines the segmentation axis as the vertical axis.
[0116] In the above technical solution, when determining the segmentation axis based on the variance of multiple first contour coordinates on the horizontal and vertical axes, the larger the variance, the more dispersed the distribution of the multiple first contour coordinates on a certain coordinate axis. When the variance on a certain coordinate axis (horizontal and vertical axes) is large, selecting that coordinate axis as the segmentation axis can better distinguish the multiple first contour coordinates, thereby facilitating sorting to determine the root node in the search tree.
[0117] In some embodiments, the method for determining the first variance includes: the electronic device determining the first variance based on the following formula (7);
[0118]
[0119] in, This is the first variance. x is the average of the horizontal axis coordinates among the multiple first contour coordinates. i Let be the x-axis coordinate value of the i-th first contour coordinate among the multiple first contour coordinates, and n be the number of first contour coordinates, i.e., the first quantity.
[0120] In some embodiments, the method for determining the second variance includes: the electronic device determining the second variance based on the following formula (8);
[0121]
[0122] in, This is the second variance. The y-axis coordinate is the average of the multiple first contour coordinates. i It is the ordinate value of the i-th first contour coordinate among the multiple first contour coordinates.
[0123] In one possible implementation, the electronic device determines the first contour coordinates corresponding to the root node in the search tree based on a first number of first contour coordinates and the coordinates of the plurality of marker points, including: when the first number is odd, the electronic device determines the first contour coordinates corresponding to the marker coordinates at the middle position among the plurality of marker coordinates as the first contour coordinates corresponding to the root node; when the first number is even, the electronic device determines the first marker coordinates and the second marker coordinates at the middle position among the plurality of marker coordinates; the electronic device determines the first contour coordinates corresponding to the target marker coordinates among the first and second marker coordinates as the first contour coordinates corresponding to the root node, wherein the coordinate value of the target marker coordinates on the segmentation axis is larger.
[0124] It should be understood that the "first quantity" in the above scheme has two cases: Case 1: the first quantity is odd; Case 2: the first quantity is even. In Case 1, there is only one marker coordinate in the middle among the multiple marker coordinates. Therefore, the first contour coordinate corresponding to this single marker coordinate can be directly determined as the first contour coordinate corresponding to the root node. In Case 2, there are two marker coordinates in the middle among the multiple marker coordinates. This scheme determines the first contour coordinate corresponding to the marker coordinate with the larger coordinate value on the dividing axis among these two marker coordinates as the first contour coordinate corresponding to the root node.
[0125] In the above technical solution, the method discusses the first contour coordinates corresponding to the root node in the search tree in two cases. The first contour coordinate corresponding to the middle marker coordinate among multiple marker coordinates is determined as the first contour coordinate of the root node. This determination method helps maintain the balance of the search tree, reduces the number of backtracking steps during traversal, and thus improves search efficiency. For the second case, where there are two middle marker coordinates among multiple marker coordinates, the method determines the first contour coordinate corresponding to the marker coordinate with the larger coordinate value on the dividing axis as the first contour coordinate of the root node. This is because the coordinate value of the first contour coordinate corresponding to the child node on the dividing axis is smaller than the coordinate value of the first contour coordinate corresponding to the parent node on the dividing axis. This also helps the electronic device quickly and efficiently determine the matching first contour coordinates of each target marker point based on the search tree constructed using this strategy.
[0126] Figure 5 This is a schematic diagram of constructing a search tree according to an embodiment of this application.
[0127] For example, such as Figure 5As shown, taking six first contour coordinates as first contour coordinate 1, first contour coordinate 2, first contour coordinate 3, first contour coordinate 4, first contour coordinate 5, and first contour coordinate 6, specifically (2,3), (5,4), (10,7), (4,7), (8,1), and (7,2) respectively, the process of constructing a search tree corresponding to multiple first contour coordinates is described. Specifically, the electronic device determines the first variance of these six first contour coordinates on the horizontal axis to be 5.83 based on formula (7), and determines the second variance of these six first contour coordinates on the vertical axis to be 4.5 based on formula (8). The electronic device determines that the first variance is greater than the second variance and determines the horizontal axis as the dividing axis. The electronic device sorts these six first contour coordinates according to the horizontal axis to obtain six marker point coordinates, specifically (2,3), (4,7), (5,4), (7,2), (8,1), and (10,7). The electronic device determines the first number of first contour coordinates to be 6. Among these 6 marker coordinates, the coordinates of the first marker point and the second marker point, which are located in the middle position, are (5,4) and (7,2), respectively. Since 7 on the horizontal axis is greater than 5 on the horizontal axis, the electronic device determines the first contour coordinate 6 corresponding to (7,2) as the first contour coordinate corresponding to the root node in the search tree.
[0128] Further, the electronic device determines the coordinates of the first left-side marker point, excluding the first contour coordinates corresponding to the root node, specifically (2,3), (4,7), and (5,4). Based on formula (7), the electronic device determines the third variance of the first left-side marker point coordinates on the horizontal axis to be 1.56, and based on formula (8), determines the fourth variance of the first left-side marker point coordinates on the vertical axis to be 2.89. The electronic device determines that the third variance is less than the fourth variance and determines the vertical axis as the dividing axis. The electronic device sorts the coordinates of the first left-side marker point according to the vertical axis, obtaining three marker point coordinates, specifically (2,3), (5,4), and (4,7). The electronic device determines the second number of the first left-side marker point coordinates to be 3, and the marker point coordinate in the middle position among these three is (5,4). The electronic device determines the first contour coordinate 2 corresponding to (5,4) as the first contour coordinate corresponding to the first left child node (the left child node of the root node) in the search tree. The electronic device determines the coordinates of the first right-side marker point, excluding the first contour coordinates corresponding to the root node, specifically (8,1) and (10,7). The electronic device determines the fifth variance of the first right-side marker coordinates on the horizontal axis to be 1 based on formula (7), and the sixth variance of the first right-side marker coordinates on the vertical axis to be 9 based on formula (8). The electronic device determines that the fifth variance is less than the sixth variance and determines the vertical axis as the dividing axis. The electronic device sorts the coordinates of the first right-side markers according to the vertical axis, obtaining two marker coordinates, specifically (8,1) and (10,7). The electronic device determines that the third number of the first right-side marker coordinates is 2, and the coordinates of the third and fourth markers in the middle position of these two marker coordinates are (8,1) and (10,7) respectively. Since 7 on the vertical axis is greater than 1 on the vertical axis, the electronic device determines the first contour coordinate 3 corresponding to (10,7) as the first contour coordinate corresponding to the first right child node (the right child node of the root node) in the search tree.
[0129] Further, the electronic device determines the coordinates of the second left-side marker point, excluding the first contour coordinates corresponding to the first left-side child node, specifically (2,3) and (4,7). The electronic device continues to determine, based on formula (7), the seventh variance of the second left-side marker point coordinates on the horizontal axis is 1, and based on formula (8), the eighth variance of the second left-side marker point coordinates on the vertical axis is 4. The electronic device determines that the seventh variance is less than the eighth variance and determines the vertical axis as the dividing axis. The electronic device sorts the second left-side marker point coordinates according to the vertical axis, obtaining two marker point coordinates, specifically (2,3) and (4,7). The electronic device determines that the fourth number of the second left-side marker point coordinates is 2, and the fifth and sixth marker point coordinates, which are in the middle of these two coordinates, are (2,3) and (4,7) respectively. The electronic device determines the first contour coordinate 4 corresponding to (4,7) as the first contour coordinate corresponding to the second left-side child node (the left child node of the first left-side child node) in the search tree. Continuing, based on the same strategy, the first contour coordinates corresponding to other nodes in the search tree are constructed. The final search tree can be seen in Figure 5 As shown.
[0130] Specifically, such as Figure 5 As shown, the first contour coordinates corresponding to the root node in the search tree are 6, with coordinates (7,2), the first left child node is 2, with coordinates (5,4), the first right child node is 3, with coordinates (10,7), the second left child node is 4, with coordinates (4,7), the second right child node is 1, with coordinates (2,3), and the third left child node is 5, with coordinates (8,1).
[0131] The process of “searching for the nearest neighbor first contour coordinates for each of the second contour coordinates of the target test element object from multiple first contour coordinates in the search tree” is discussed below.
[0132] In one possible implementation, the electronic device searches for the nearest neighbor first contour coordinates of each second contour coordinate of the target test element object from a plurality of first contour coordinates in the search tree, including: for any second contour coordinate among the plurality of second contour coordinates, the electronic device takes any second contour coordinate as the target second contour coordinate, determines the distance between the target second contour coordinate and each of the plurality of first contour coordinates, obtains a plurality of first distances, and determines the minimum distance from the plurality of first distances; the electronic device determines the first contour coordinate corresponding to the minimum distance as the nearest neighbor first contour coordinate corresponding to the target second contour coordinate.
[0133] It should be understood that in the above scheme, different second contour coordinates may search for the same nearest neighbor first contour coordinate among multiple first contour coordinates. Furthermore, after searching for the nearest neighbor first contour coordinates for each second contour coordinate of the target test element object, these multiple first contour coordinates may not be fully utilized; that is, some first contour coordinates may not have a corresponding second contour coordinate.
[0134] In some embodiments, determining the distance between the second contour coordinates of the target and each of the plurality of first contour coordinates to obtain a plurality of first distances, and determining the minimum distance from the plurality of first distances includes: the electronic device starting from the root node among the plurality of nodes in the search tree, determining the first distance between the first contour coordinates corresponding to the root node and the second contour coordinates of the target; the electronic device determining the first left child node of the root node, and determining the second distance between the first contour coordinates corresponding to the first left child node and the second contour coordinates of the target; if the second distance is greater than the first distance, the electronic device determining the first distance as the minimum distance.
[0135] It should be understood that when "the second distance is greater than the first distance" in the above scheme, it indicates that the distance between the second contour coordinate of the target and the first contour coordinate corresponding to the first left child node is relatively large, the distance between the second contour coordinate of the target and the first contour coordinates corresponding to all child nodes of the first left child node is even larger, and the distance between the second contour coordinate of the target and the first contour coordinate corresponding to the root node is relatively small. Since the circuit board to be inspected is printed by relatively professional personnel based on a template drawing, the printing quality of the circuit board to be inspected will not be too poor. Therefore, this method determines the first contour coordinate that is closer to the second contour coordinate of the target (i.e., the first contour coordinate corresponding to the root node in the above scheme) as the nearest neighbor first contour coordinate corresponding to the second contour coordinate of the target.
[0136] In the above technical solution, the method traverses multiple first contour coordinates starting from the root node among multiple nodes in the search tree. It compares the distance between the target second contour coordinate and the first contour coordinates corresponding to other nodes with a first distance (the distance between the target second contour coordinate and the first contour coordinate corresponding to the root node). The first contour coordinate corresponding to the node closest to the target second contour coordinate is then taken as the nearest neighbor first contour coordinate. This can accurately and quickly determine the nearest neighbor first contour coordinate for the target second contour coordinate. Specifically, when the second distance is greater than the first distance, meaning the target second contour coordinate is closer to the first contour coordinate corresponding to the root node, while the first contour coordinates corresponding to other nodes (the first left child node of the root node and all its child nodes) are farther from the target second contour coordinate, the electronic device determines the first contour coordinate corresponding to the root node as the nearest neighbor first contour coordinate for the target second contour coordinate.
[0137] In some embodiments, the electronic device determines the first left child node of the root node and determines the second distance between the first contour coordinates corresponding to the first left child node and the target second contour coordinates, including: the electronic device determines whether the first horizontal axis coordinate value in the target second contour coordinates is less than the second horizontal axis coordinate value in the first contour coordinates corresponding to the root node; if the first horizontal axis coordinate value is less than the second horizontal axis coordinate value, the electronic device determines the first left child node of the root node and determines the second distance between the first contour coordinates corresponding to the first left child node and the target second contour coordinates.
[0138] In some embodiments, when the second distance is greater than the first distance, the electronic device determines the first distance as the minimum distance, including: when the second distance is greater than the first distance, the electronic device determines the first right child node of the root node, and determines the third distance between the first contour coordinates corresponding to the first right child node and the second contour coordinates of the target; when the third distance is greater than the first distance, the electronic device determines the first distance as the minimum distance.
[0139] It should be understood that in the above scheme, the root node's child nodes include a first left child node and a first right child node. The first contour coordinates corresponding to each node in the search tree are two-dimensional coordinates. Each node in the search tree is determined by sorting multiple first contour coordinates based on the dividing axes (horizontal and vertical axes, i.e., any coordinate axis). The distance between the first contour coordinate and the target's second contour coordinate is affected by both the horizontal and vertical axes. Therefore, the third distance between the first contour coordinate corresponding to the first right child node and the target's second contour coordinate may be smaller than the first distance. Therefore, this method discusses the relationship between the magnitude of the third distance and the first distance.
[0140] It should also be understood that traversing the search tree from the root node to the first left child node is called a top-down traversal. Traversing the search tree from the first right child node to the root node is called a bottom-up traversal. This is to prevent situations where the determined first contour coordinates, when traversing the search tree solely using a top-down traversal, are not truly matching the target's second contour coordinates, potentially overlooking those that actually match. Specifically, if the determined second distance is less than the first distance, and the third distance is even less than the first distance, then the distance between the first contour coordinates corresponding to the first right child node and the target's second contour coordinates is closer, meaning the first contour coordinates corresponding to the first right child node are more likely to match the target's second contour coordinates. Therefore, this method uses a bottom-up traversal to backtrack through multiple nodes.
[0141] In the above technical solution, when the second distance is greater than the first distance, the method further determines a third distance between the first contour coordinates corresponding to the first right child node of the root node and the target second contour coordinates; and compares the third distance with the first distance. This is to prevent the erroneous operation of determining the first contour coordinates corresponding to the root node as the first contour coordinates matching the target second contour coordinates when the third distance is less than the first distance, which would result in the first contour coordinates corresponding to the first right child node being closer to the target second contour coordinates. Therefore, when the third distance is greater than the first distance, this method can determine the first distance as the minimum distance.
[0142] In some embodiments, the method 200 further includes: when the second distance is less than the first distance, the electronic device determines the second left child node of the first left child node and determines the fourth distance between the first contour coordinates corresponding to the second left child node and the target second contour coordinates; when the fourth distance is less than the second distance and the second left child node is a leaf node, the electronic device determines the fourth distance as the minimum distance.
[0143] It should be understood that when "the second distance is less than the first distance" in the above scheme, it indicates that the distance between the target's second contour coordinate and the first contour coordinate corresponding to the first left child node is relatively close, the distance between the target's second contour coordinate and the first contour coordinate corresponding to a child node of the first left child node is even closer, and the distance between the target's second contour coordinate and the first contour coordinate corresponding to the root node is relatively far. Therefore, this method continues to traverse the nodes in the search tree by selecting the left branch of the first left child node. Specifically, this method determines the fourth distance between the first contour coordinate corresponding to the second left child node and the target's second contour coordinate, and compares the fourth distance with the second distance to measure which node's first contour coordinate is closer to the target's second contour coordinate.
[0144] In the above technical solution, when the second distance is less than the first distance, i.e., when the distance between the first contour coordinate corresponding to a child node of the first left child node and the target second contour coordinate is closer, the method further determines a fourth distance between the first contour coordinate corresponding to the second left child node and the target second contour coordinate. When the fourth distance is less than the second distance, the method can continue to determine the distance between the first contour coordinate corresponding to a child node of the second left child node and the target second contour coordinate, but the second left child node has no child nodes. Therefore, the method determines the first contour coordinate corresponding to the second left child node as the first contour coordinate matching the target second contour coordinate. This can accurately determine the first contour coordinate matching the target second contour coordinate.
[0145] In some embodiments, when the fourth distance is less than the second distance and the second left child node is a leaf node, the electronic device determines the fourth distance as the minimum distance, including: the electronic device determines the second right child node of the first left child node, and determines the fifth distance between the first contour coordinates corresponding to the second right child node and the target second contour coordinates; when the fifth distance is greater than the fourth distance and the third distance is greater than the fourth distance, the electronic device determines the fourth distance as the minimum distance.
[0146] It should be understood that traversing the search tree from the root node to the first left child node, and then to the second left child node is called a top-down traversal. Conversely, traversing the search tree from the second left child node to the second right child node, and then to the first right child node, is called a bottom-up traversal. This is to prevent the determination of the first contour coordinates when traversing the search tree solely using a top-down traversal from not actually matching the target's second contour coordinates, potentially overlooking the first contour coordinates that truly match the target's second contour coordinates. Therefore, this method employs a top-down traversal to backtrack through multiple nodes.
[0147] Figure 6 This is a schematic diagram illustrating how to determine the nearest neighbor first contour coordinates corresponding to the second contour coordinates of a target, according to an embodiment of this application.
[0148] For example, such as Figure 6 As shown, taking the second contour coordinate of the target as (4,9) as an example, the process of determining the nearest neighbor first contour coordinate corresponding to the second contour coordinate of the target is described. Specifically, based on (4,9) and (7,2), the electronic device determines that the first distance between the first contour coordinate 6 corresponding to the root node and the second contour coordinate of the target is 7.62, and based on (4,9) and (5,4), determines that the second distance between the first contour coordinate 2 corresponding to the first left child node and the second contour coordinate of the target is 5.1. The second distance is less than the first distance. The electronic device continues to determine that based on (4,9) and (4,7), the fourth distance between the first contour coordinate 4 corresponding to the second left child node and the second contour coordinate of the target is 2. The fourth distance is less than the second distance, and the second left child node is a leaf node. The electronic device determines the first contour coordinate 4 corresponding to the second left child node as the nearest neighbor first contour coordinate corresponding to the second contour coordinate of the target.
[0149] Furthermore, based on (4,9) and (10,7), the electronic device determines that the third distance between the first contour coordinate 3 corresponding to the first right child node and the second contour coordinate of the target is 6.32, which is greater than the fourth distance. Based on (4,9) and (2,3), the electronic device determines that the fifth distance between the first contour coordinate 1 corresponding to the second right child node and the second contour coordinate of the target is 6.32, which is greater than the fourth distance. Therefore, after a backtracking operation, the electronic device ultimately determines the first contour coordinate 4 corresponding to the second left child node as the nearest neighbor first contour coordinate corresponding to the second contour coordinate of the target.
[0150] The process of "determining the second offset of the test element object based on the nearest neighbor first contour coordinates corresponding to each of the multiple second contour coordinates" is discussed below.
[0151] In one possible implementation, the electronic device determines the second offset of the test element object based on the nearest neighbor first contour coordinates corresponding to each of the multiple second contour coordinates, including: the electronic device determines the distance between the nearest neighbor first contour coordinates corresponding to each of the multiple second contour coordinates to obtain multiple second distances; the electronic device determines the average of the multiple second distances as the second offset of the test element object.
[0152] It should be understood that for any test element object, there is a corresponding second offset.
[0153] Figure 7 This is a schematic diagram of the structure of a device for obtaining offset during circuit board alignment provided in an embodiment of this application.
[0154] For example, such as Figure 7 As shown, the device 700 includes:
[0155] The acquisition module 701 is used to acquire a test image of the circuit board and a corresponding template image. The test image is obtained by correcting a photograph of the circuit board, and the test image and the template image have the same size.
[0156] The determination module 702 is used to perform image segmentation on the test image and the template image respectively, to obtain multiple test segment images in the test image and multiple template segment images in the template image, with each test segment image having a corresponding template segment image;
[0157] Alignment module 703 is used for:
[0158] For any test block diagram among the multiple test block diagrams, take any test block diagram as the target test block diagram, and perform template alignment between the target test block diagram and the template block diagram corresponding to the target test block diagram in the template diagram to determine the first offset of the target test block diagram. The first offset is the offset between the target test block diagram and the corresponding template block diagram during the template alignment process.
[0159] For one or more test element objects in the target test block diagram, based on the first offset of the target test block diagram, the contour of the test element object is aligned with the corresponding template element object in the corresponding template block diagram, and the second offset of the test element object is determined. The second offset is the offset between the test element object and the corresponding template element object during the contour alignment process.
[0160] Optionally, the alignment module 703 is specifically used to determine the first offset of the target test block image based on the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position during the sliding process of the corresponding template block image on the target test block image, so that the pixel coordinate position on the corresponding template block image is aligned with the pixel coordinate position on the target test image.
[0161] Optionally, the determining module 702 is specifically configured to: determine the minimum pixel deviation from multiple pixel deviations, and determine the target position of the corresponding template block image at the minimum pixel deviation; determine the horizontal axis offset of the first offset of the target test block image based on the horizontal deviation between the target position and the starting position of the corresponding template block image; and determine the vertical axis offset of the first offset of the target test block image based on the vertical deviation between the target position and the starting position.
[0162] Optionally, the determining module 702 is further configured to: take any test element object as the target test element object, move the target test element object to the corresponding template block map based on the first offset of the target test block map, determine the target template element object corresponding to the target test element object from multiple template element objects in the corresponding template block map; construct a search tree corresponding to the multiple first contour coordinates based on the multiple first contour coordinates of the target template element object, where each node in the search tree has a corresponding first contour coordinate; search for the nearest neighbor first contour coordinate for each second contour coordinate of the target test element object from the multiple first contour coordinates in the search tree, where the distance between the second contour coordinate and the nearest neighbor first contour coordinate corresponding to the second contour coordinate is less than the distance between the second contour coordinate and other first contour coordinates; and determine the second offset of the test element object based on each second contour coordinate and the nearest neighbor first contour coordinate corresponding to the second contour coordinate.
[0163] Optionally, the determining module 702 is further configured to: for any second contour coordinate among the plurality of second contour coordinates, take any second contour coordinate as the target second contour coordinate, determine the distance between the target second contour coordinate and each of the plurality of first contour coordinates to obtain a plurality of first distances, and determine the minimum distance from the plurality of first distances; and determine the first contour coordinate corresponding to the minimum distance as the nearest neighbor first contour coordinate corresponding to the target second contour coordinate.
[0164] Optionally, the determining module 702 is further configured to: determine the distance between the nearest neighbor first contour coordinates corresponding to each second contour coordinate, thereby obtaining multiple second distances; and determine the average value of the multiple second distances as the second offset of the test element object.
[0165] Optionally, the determining module 702 is further configured to: determine a dividing axis from the horizontal and vertical axes based on the variance of the plurality of first contour coordinates on the horizontal and vertical axes; sort the plurality of first contour coordinates according to the dividing axis to obtain a plurality of marker point coordinates; determine the first contour coordinates corresponding to the root node in the search tree based on a first number of first contour coordinates and the plurality of marker point coordinates; determine the first contour coordinates corresponding to at least one left child node of the root node based on the left marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the left marker point coordinates on the horizontal and vertical axes, and a second number of corresponding first contour coordinates; and determine the first contour coordinates corresponding to at least one right child node of the root node based on the right marker point coordinates other than the first contour coordinates corresponding to the root node, the variance of the right marker point coordinates on the horizontal and vertical axes, and a third number of corresponding first contour coordinates.
[0166] Optionally, the determining module 702 is further configured to: when the first number is odd, determine the first contour coordinate corresponding to the coordinate of the middle position of the multiple marker point coordinates as the first contour coordinate corresponding to the root node; when the first number is even, determine the coordinates of the first marker point and the second marker point in the middle position among the multiple marker point coordinates; determine the first contour coordinate corresponding to the target marker point coordinate among the first marker point coordinates and the second marker point coordinates as the first contour coordinate corresponding to the root node, wherein the coordinate value of the target marker point coordinate on the segmentation axis is larger.
[0167] Optionally, the determining module 702 is further configured to: determine a homography matrix, which indicates the mapping relationship between the captured image and the template image; and correct the captured image based on the homography matrix to obtain the test image.
[0168] Optionally, the determining module 702 is further configured to: determine a first preset marker point on each of the N target areas in the template image, where N is a positive integer greater than 3; determine a second preset marker point in the captured image that matches the first preset marker point, centered on the first preset marker point and at a first preset distance; and determine the homography matrix based on the coordinates of the N first preset marker points and the corresponding coordinates of the N second preset marker points.
[0169] Optionally, the determining module 702 is further configured to: construct a first matrix based on the coordinates of each of the N first preset marker points and the coordinates of the corresponding second preset marker points, and determine the homography matrix based on the preset matrix and the first matrix.
[0170] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0171] For example, such as Figure 8 As shown, the electronic device 800 includes a memory 801 and a processor 802. The memory 801 stores executable program code 803, and the processor 802 is used to call and execute the executable program code 803 to perform a method for obtaining offset during circuit board alignment.
[0172] Furthermore, embodiments of this application also protect an apparatus that may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to perform a method for obtaining offset during circuit board alignment provided in embodiments of this application.
[0173] This embodiment can divide the device into functional modules based on the above method example. For example, each module can correspond to a separate function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0174] When the functional modules are divided according to their respective functions, the device may also include an acquisition module and a determination module. It should be noted that all relevant content in the above method embodiments can be referenced in the functional descriptions of the corresponding functional modules, and will not be repeated here.
[0175] It should be understood that the device provided in this embodiment is used to perform the above-described method for obtaining offset during circuit board alignment, and therefore can achieve the same effect as the above-described implementation method.
[0176] When using integrated units, the device may include a processing module and a storage module. When applied to an electronic device, the processing module can be used to control and manage the operation of the electronic device. The storage module can be used to support the execution of relevant executable program code by the electronic device.
[0177] The processing module may be a processor or a controller, which can implement or execute various exemplary logic blocks, modules, and circuits shown in conjunction with the disclosure of this application. The processor may also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc., and the storage module may be a memory.
[0178] In addition, the device provided in the embodiments of this application may specifically be a chip, component or module. The chip may include a connected processor and a memory. The memory is used to store instructions. When the processor calls and executes the instructions, the chip can execute the method for obtaining the offset during the alignment process of a circuit board provided in the above embodiments.
[0179] This embodiment also provides a computer-readable storage medium storing executable program code. When the executable program code is run on a computer, the computer performs the above-described related method steps to implement the method for obtaining offset during circuit board alignment provided in the above embodiment.
[0180] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the method for obtaining offset during circuit board alignment provided in the above embodiment.
[0181] In this embodiment, the device, computer-readable storage medium, computer program product, or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0182] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0183] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0184] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for obtaining offset during circuit board alignment, characterized in that, The method includes: Obtain a test image and a corresponding template image of the circuit board. The test image is obtained by correcting a photograph of the circuit board. The test image and the template image have the same dimensions. The test image and the template image are divided into image blocks respectively to obtain multiple test block images in the test image and multiple template block images in the template image. Each test block image has a corresponding template block image. For any test block diagram among the plurality of test block diagrams, any test block diagram is taken as the target test block diagram, and the target test block diagram is aligned with the template block diagram corresponding to the target test block diagram in the template diagram to determine the first offset of the target test block diagram. The first offset is the offset between the target test block diagram and the corresponding template block diagram during the template alignment process. For one or more test element objects in the target test block diagram, based on the first offset of the target test block diagram, the test element object and the corresponding template element object in the corresponding template block diagram are contour aligned to determine the second offset of the test element object. The second offset is the offset between the test element object and the corresponding template element object during the contour alignment process.
2. The method according to claim 1, characterized in that, The step of aligning the target test block image with the corresponding template block image in the template image to determine the first offset of the target test block image includes: During the sliding process of the corresponding template block image on the target test block image, based on the pixel deviation between the target test block image and the corresponding template block image at the corresponding pixel coordinate position after each sliding, the first offset of the target test block image is determined, and the pixel coordinate position on the corresponding template block image is aligned with the pixel coordinate position on the target test image.
3. The method according to claim 2, characterized in that, The step of determining the first offset of the target test block image based on the pixel deviation between the target test block image and the corresponding template block image at corresponding pixel coordinate positions after each slide includes: Determine the minimum pixel deviation from multiple pixel deviations, and determine the target position of the corresponding template block image at the minimum pixel deviation; Based on the horizontal deviation between the target position and the starting position of the corresponding template block diagram, the horizontal axis offset in the first offset of the target test block diagram is determined; Based on the vertical deviation between the target position and the starting position, the vertical axis offset in the first offset of the target test block map is determined.
4. The method according to claim 1 or 3, characterized in that, The step of aligning the test element object with the corresponding template element object in the corresponding template block image based on the first offset of the target test block image, and determining the second offset of the test element object, includes: Take any test element object as the target test element object, move the target test element object to the corresponding template block diagram based on the first offset of the target test block diagram, and determine the target template element object corresponding to the target test element object from multiple template element objects in the corresponding template block diagram; Based on the multiple first contour coordinates of the target template element object, a search tree corresponding to the multiple first contour coordinates is constructed, and each node in the search tree has a corresponding first contour coordinate; From the multiple first contour coordinates in the search tree, the nearest neighbor first contour coordinate is searched for each second contour coordinate of the target test element object, and the distance between the second contour coordinate and the nearest neighbor first contour coordinate corresponding to the second contour coordinate is less than the distance between the second contour coordinate and each other first contour coordinate. The second offset of the test element object is determined based on the nearest neighbor first contour coordinate corresponding to each of the multiple second contour coordinates.
5. The method according to claim 4, characterized in that, The step of searching for the nearest neighbor first contour coordinates for each second contour coordinate of the target test element object from a plurality of first contour coordinates in the search tree includes: For any second contour coordinate among the plurality of second contour coordinates, take any second contour coordinate as the target second contour coordinate, determine the distance between the target second contour coordinate and each of the plurality of first contour coordinates to obtain a plurality of first distances, and determine the minimum distance from the plurality of first distances; The first contour coordinates corresponding to the minimum distance are determined as the nearest neighbor first contour coordinates corresponding to the second contour coordinates of the target.
6. The method according to claim 4, characterized in that, The step of determining the second offset of the test element object based on each of the multiple second contour coordinates and the nearest neighbor first contour coordinate corresponding to the second contour coordinate includes: Determine the distance between the nearest neighbor first contour coordinates corresponding to each second contour coordinate to obtain multiple second distances; The average of the plurality of second distances is determined as the second offset of the test element object.
7. The method according to claim 4, characterized in that, The step of constructing a search tree corresponding to the multiple first contour coordinates based on the target template element object includes: Based on the variance of the plurality of first contour coordinates on the horizontal and vertical axes, the segmentation axis is determined from the horizontal and vertical axes; The coordinates of the plurality of first contours are sorted according to the dividing axis to obtain the coordinates of the plurality of marker points; Based on the first number of first contour coordinates and the coordinates of the plurality of marker points, the first contour coordinates corresponding to the root node in the search tree are determined. Based on the left contour coordinates other than the first contour coordinates corresponding to the root node among the multiple marker point coordinates, the variance of the left contour coordinates on the horizontal and vertical axes, and the second quantity of the corresponding first contour coordinates, the first contour coordinates corresponding to at least one left child node of the root node are determined. Based on the right contour coordinates other than the first contour coordinates corresponding to the root node among the multiple marker point coordinates, the variance of the right contour coordinates on the horizontal and vertical axes, and the third quantity of the corresponding first contour coordinates, the first contour coordinates corresponding to at least one right child node of the root node are determined.
8. The method according to claim 7, characterized in that, The determination of the first contour coordinates corresponding to the root node in the search tree based on the first number of first contour coordinates and the coordinates of the plurality of marker points includes: When the first number is odd, the first contour coordinate corresponding to the coordinate of the middle position of the multiple marker point coordinates is determined as the first contour coordinate corresponding to the root node; If the first number is even, determine the coordinates of the first and second marker points that are in the middle position among the multiple marker point coordinates; The first contour coordinates corresponding to the target marker coordinates in the first and second marker coordinates are determined as the first contour coordinates corresponding to the root node, and the target marker coordinates have a larger coordinate value on the segmentation axis.
9. The method according to claim 1, characterized in that, The method for determining the test pattern includes: A homography matrix is determined, which is used to indicate the mapping relationship between the captured image and the template image; The captured image is corrected based on the homography matrix to obtain the test image.
10. The method according to claim 9, characterized in that, The determination of the homography matrix includes: A first preset marker point is determined on each of the N target regions in the template image, where N is a positive integer greater than 3; Using a first preset marker point on each of the target areas as the center, a second preset marker point matching the first preset marker point is determined in the captured image according to a first preset distance; The homography matrix is determined based on the coordinates of N first preset marker points and the corresponding coordinates of N second preset marker points.
11. The method according to claim 10, characterized in that, The process of determining the homography matrix based on the coordinates of N first preset marker points and the corresponding coordinates of N second preset marker points includes: A first matrix is constructed based on the coordinates of each of the N first preset marker points and the coordinates of the corresponding second preset marker points, and the homography matrix is determined based on the preset matrix and the first matrix.
12. A device for obtaining offset during circuit board alignment, characterized in that, The device includes: The acquisition module is used to acquire a test image of the circuit board and a corresponding template image. The test image is obtained by correcting a photograph of the circuit board, and the test image and the template image have the same size. The determining module is used to perform image segmentation on the test image and the template image respectively, to obtain multiple test segment images in the test image and multiple template segment images in the template image, wherein each test segment image has a corresponding template segment image; Alignment module, used for: For any test block diagram among the plurality of test block diagrams, any test block diagram is taken as the target test block diagram, and the target test block diagram is aligned with the template block diagram corresponding to the target test block diagram in the template diagram to determine the first offset of the target test block diagram. The first offset is the offset between the target test block diagram and the corresponding template block diagram during the template alignment process. For one or more test element objects in the target test block diagram, based on the first offset of the target test block diagram, the test element object and the corresponding template element object in the corresponding template block diagram are contour aligned to determine the second offset of the test element object. The second offset is the offset between the test element object and the corresponding template element object during the contour alignment process.
13. An electronic device, characterized in that, The electronic device includes: Memory, used to store executable program code; A processor for calling and running the executable program code from the memory, causing the electronic device to perform the method as described in any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores executable program code that, when executed, implements the method as described in any one of claims 1 to 11.