Method and device for detecting irregular-edge PCB based on AVI
By calculating the tilt angle of irregular PCB edges and comparing it with a rotated standard image, combined with edge detection and feature point matching, the problem of efficiency and accuracy in detecting irregular PCB edges is solved, achieving efficient and accurate detection results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN QILI ELECTRON CO LTD
- Filing Date
- 2023-10-30
- Publication Date
- 2026-04-24
AI Technical Summary
When using automated vision inspection equipment, PCBs with irregular edges are prone to reduced inspection efficiency and accuracy due to the tilt of the edges, a problem that is difficult to solve effectively with existing technologies.
By acquiring grayscale images of irregularly edged PCBs, calculating their tilt angles, and rotating standard images to the same angle for comparison, edge detection and Hough line transform are used to extract line segment data. The rotation matrix is then calculated to rotate and resize the images. Finally, the SIFT algorithm is used to match feature points to generate comparative similarity results.
It improves the inspection efficiency and accuracy of PCBs with irregular edges, can detect hidden defects, reduce human error, and achieve efficient and precise quality control.
Smart Images

Figure CN121921234A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Automated Visual Inspection (AVI), and more particularly to an AVI-based method and apparatus for inspecting irregularly edged PCBs. Background Technology
[0002] PCB stands for Printed Circuit Board. It is a basic component used to support and connect electronic components and is widely used in various electronic devices. Traditional PCBs are usually rectangular or square with straight edges, but due to certain special requirements, it is sometimes necessary to design and manufacture PCBs with irregular edges.
[0003] For the visual inspection of PCBs produced in large quantities, automated inspection equipment and automated vision inspection technology are typically required to achieve fast and accurate inspection. The inspection targets most hidden defects on PCBs, including missing circuit components, solder joint problems, component misalignment, and other electrical and visual defects. This allows for comprehensive and detailed electrical and visual inspection, and provides efficient data analysis and recording. When using AVI inspection equipment to inspect PCBs with straight edges, problematic PCBs can be accurately detected. However, when using AVI inspection equipment to inspect PCBs with irregular edges, the irregular edges are touched by the baffles in the AVI inspection equipment, causing the PCB under test to tilt at a certain angle. This results in the failure of comparison with the comparison image, significantly reducing the efficiency and accuracy of inspecting PCBs with irregular edges. Summary of the Invention
[0004] The purpose of this invention is to provide an AVI-based method for detecting irregularly edged PCBs, which is characterized by more efficient and accurate detection of irregularly edged PCBs.
[0005] The above-mentioned objective of this invention is achieved through the following technical solution: A method for detecting irregularly edged PCBs based on AVI, comprising: A first comparison image is obtained, which is a grayscale image of a standard PCB image with irregular edges; Obtain a grayscale image of the irregularly edged PCB to be tested; Calculate the tilt angle of the grayscale image of the irregular edge PCB to be tested; The first comparison image is rotated to the same tilt angle as the grayscale image of the irregular edge PCB to be tested, to obtain the second comparison image; The grayscale image of the irregular edge PCB to be tested is compared with the second comparison image, and a comparison similarity result is generated.
[0006] By employing the above technical solution, the first comparison image is rotated to the same tilt angle as the grayscale image of the irregularly edged PCB under test, ensuring that the first comparison image maintains the same angle as the image under test, thereby improving the accuracy of subsequent comparisons. Extracting the grayscale image of the irregularly edged PCB under test allows for edge detection, which helps in further extracting edge contour data. Comparing the grayscale image of the irregularly edged PCB under test with the rotated second comparison image allows for the evaluation of their matching degree by calculating their similarity results. This quantitatively reflects the differences between the irregularly edged PCB under test and the standard irregularly edged PCB, helping to determine whether there are hidden defects, including missing circuit components, solder joint problems, component misalignment, and other electrical and appearance defects.
[0007] In a preferred embodiment, the present invention may be further configured such that calculating the tilt angle of the grayscale image of the irregular edge PCB under test includes: An edge detection algorithm is applied to extract the edge data of the grayscale image of the irregular PCB under test; The Hough linear transform is used to detect straight line segments in the edge data; Based on the line segment data, the angle of the line segment is extracted, and the tilt angle of the grayscale image of the irregular edge PCB under test is determined based on the angle of the line segment.
[0008] By employing the above technical solution and applying edge detection algorithms, edge data of the grayscale image of the irregularly edged PCB under test can be accurately extracted, providing accurate input data for subsequent tilt angle calculation. Using the Hough line transform, information about line segments can be detected from the edge data. Since line segments typically represent the main direction of the PCB edge, by filtering and extracting line segment data, the overall tilt trend of the grayscale image of the irregularly edged PCB can be better captured, thus enabling the determination of the tilt angle of the grayscale image of the irregularly edged PCB under test through the angle of the line segments.
[0009] In a preferred embodiment, the present invention can be further configured to rotate the first comparison image to the same tilt angle as the grayscale image of the irregular edge PCB to be tested, to obtain a second comparison image, including: Measure the length and width of the first comparison image; Calculate the coordinates of the rotation center of the first comparison image based on its length and width. The rotation matrix is calculated based on the coordinates of the rotation center and the tilt angle of the grayscale image of the irregular edge PCB to be tested. The first comparison image is rotated using a rotation matrix to obtain the second comparison image.
[0010] By employing the above technical solution, the length and width of the first comparison image can be measured, allowing for accurate acquisition of its size information. This is crucial for subsequent rotation and transformation operations, as the calculation of the rotation center and the generation of the rotation matrix both require information based on the image's dimensions. The coordinates of the rotation center can be calculated based on the length and width of the first comparison image. Accurate positioning of the rotation center contributes to the precision of subsequent rotation operations and ensures the balance and stability of the image rotation.
[0011] In a preferred embodiment, the invention may further be configured such that the method includes: Adjust the grayscale image of the irregular PCB edge to be tested and the second comparison image to the same size.
[0012] By adopting the above technical solution, the image of the irregular PCB edge under test and the second comparison image are adjusted to the same size. During feature point extraction and descriptor calculation, the two images can be compared pixel-by-pixel, ensuring accuracy and completeness, without missing important feature points, thus improving the accuracy of the comparison results. Based on the coordinates of the rotation center and the tilt angle of the grayscale image of the irregular PCB edge under test, a rotation matrix can be calculated. This rotation matrix describes the rotation transformation relationship of the first comparison image, and its application allows for the rotation operation of the first comparison image. By applying the rotation matrix to rotate the first comparison image, the second comparison image can be obtained. After rotation, the second comparison image can be compared and analyzed with the grayscale image of the irregular PCB edge under test to evaluate the similarity.
[0013] In a preferred embodiment, the present invention may be further configured such that comparing the grayscale image of the irregular edge PCB to be tested with the second comparison image and generating a comparison similarity result includes: Feature points are extracted from the grayscale image of the irregular edge PCB under test and the second comparison image, and their descriptors are calculated; The grayscale image of the irregular edge PCB under test is compared with the feature points and descriptors of the second comparison image. Generate a grayscale image of the irregular edge PCB to be tested and compare it with the second comparison image to obtain a similarity result.
[0014] By employing the above technical solution, feature points are extracted from the grayscale image of the irregularly edged PCB under test and the second comparison image, and their descriptors are calculated, allowing for image similarity comparison. This quantitatively assesses the similarity between the irregularly edged PCB under test and the second comparison image. Accurate similarity results can be obtained through comparative analysis of the grayscale image of the irregularly edged PCB under test and the second comparison image. Based on this result, the degree of matching between the image under test and the second comparison image can be determined, thereby identifying the quality status of the irregularly edged PCB. This helps improve the accuracy and precision of inspection, achieving more reliable production quality control. By calculating feature points and descriptors, and generating the similarity comparison, automated processing of the image of the irregularly edged PCB under test and the second comparison image can be achieved. This saves manpower, improves efficiency, and avoids the influence of subjective factors on the results.
[0015] In a preferred embodiment, the invention may further be configured such that the method includes: The display shows the first comparison image, the grayscale image of the irregular edge PCB to be tested, and the comparison similarity result.
[0016] By employing the above technical solution, displaying the first comparison image, the grayscale image of the irregularly shaped PCB under test, and the comparison similarity results, the images and results can be presented intuitively to the user. This allows users to directly observe and compare the images, and understand the comparison similarity results, thereby better understanding and judging the quality status of the irregularly shaped PCB under test. Furthermore, by displaying the comparison images and results in real time, users can promptly understand the comparison between the irregularly shaped PCB under test and the second comparison image. This enables the rapid detection of defects and anomalies in the irregularly shaped PCB under test, allowing for timely implementation of corresponding measures for processing and adjustment, ensuring the stability of the production process and the accuracy of quality control.
[0017] In a preferred embodiment, the invention may further be configured such that the method includes: Based on whether the comparison similarity result is greater than or equal to a preset threshold, it is determined whether the irregular edge PCB is qualified, and then the qualification rate of the irregular edge PCB is calculated.
[0018] By adopting the above technical solution, the pass / fail status of PCBs with irregular edges can be determined based on whether the comparison similarity result is greater than or equal to a preset threshold, thus achieving automated inspection. This reduces manual intervention, improves inspection speed and accuracy, and avoids the influence of subjective factors on the results. Calculating the pass rate of PCBs with irregular edges provides a direct understanding of the quality control situation during the production process and allows for real-time statistics. This enables the timely detection of problems and anomalies, allowing for prompt adjustments and handling, ensuring the stability of the production process and the effectiveness of quality control.
[0019] The second objective of this invention is to provide an AVI-based detection device for irregularly edged PCBs, which features more efficient and accurate detection of irregularly edged PCBs.
[0020] The second objective of this invention is achieved through the following technical solution: An AVI-based inspection device for irregularly edged PCBs includes: The first comparison image acquisition module is used to acquire the first comparison image; The image acquisition module is used to acquire grayscale images of the irregular edge PCB under test. The tilt angle calculation module calculates the tilt angle of the grayscale image of the irregular edge PCB to be tested. An image rotation module is used to rotate the first comparison image to the same tilt angle as the grayscale image of the irregular edge PCB to be tested, so as to obtain a second comparison image; The comparison module is used to compare the grayscale image of the irregular PCB edge to be tested with the second comparison image and generate a comparison similarity result.
[0021] In a preferred embodiment, the present invention can be further configured such that the tilt angle calculation module includes: The edge extraction unit is used to apply an edge detection algorithm to extract the edge data of the grayscale image of the irregular PCB edge to be tested; A line segment detection unit is used to detect line segment data in the edge data using the Hough line transform. A line segment acquisition unit is used to acquire the line segment data; The straight line segment angle extraction unit is used to extract the straight line segment angle based on the straight line segment data, and to determine the tilt angle of the grayscale image of the irregular edge PCB to be tested based on the straight line segment angle.
[0022] In a preferred embodiment, the present invention can be further configured such that the image rotation module includes: The image length and width measurement unit is used to measure the length and width of the grayscale image of the irregular edge PCB under test based on the edge data. The rotation center coordinate calculation unit is used to calculate the coordinates of the rotation center of the first comparison image based on the length and width of the grayscale image of the irregular edge PCB to be tested. The rotation matrix calculation unit is used to calculate the rotation matrix based on the coordinates of the rotation center and the tilt angle of the grayscale image of the irregular edge PCB to be tested. A rotation unit is used to rotate the first comparison image using a rotation matrix to obtain a second comparison image.
[0023] In a preferred embodiment, the invention may be further configured such that the apparatus includes: The size adjustment module is used to adjust the grayscale image of the irregular edge PCB under test and the second comparison image to the same size.
[0024] In a preferred embodiment, the present invention may be further configured such that the comparison module includes: The feature point extraction unit is used to extract feature points from the grayscale image of the irregular edge PCB under test and the second comparison image, and calculate their descriptors; The comparison unit is used to compare the feature points and their descriptors of the grayscale image of the irregular edge PCB to be tested with the second comparison image; The comparison similarity result generation unit is used to generate a comparison similarity result between the grayscale image of the irregular edge PCB to be tested and the second comparison image.
[0025] In a preferred embodiment, the invention may be further configured such that the apparatus includes: The result display module is used to display the first comparison image, the grayscale image of the irregular edge PCB to be tested, and the comparison similarity comparison result.
[0026] In a preferred embodiment, the invention may be further configured such that the apparatus includes: The pass rate calculation module is used to determine whether the irregular edge PCB is qualified based on the comparison similarity results, thereby calculating the pass rate of the irregular edge PCB.
[0027] The third objective of this invention is to provide an AVI-based detection device for irregularly edged PCBs, which features more efficient and accurate detection of irregularly edged PCBs.
[0028] The above-mentioned objective three of this invention is achieved through the following technical solution: An AVI-based detection device for irregular edge PCBs includes a memory and a processor. The memory stores a computer program that can be loaded and executed by the processor to detect the aforementioned AVI-based irregular edge PCB.
[0029] The fourth objective of this invention is to provide a computer storage medium capable of storing corresponding programs, which facilitates more efficient and accurate detection of irregular PCB edges.
[0030] The fourth objective of this invention is achieved through the following technical solution: A computer-readable storage medium storing a computer program that can be loaded by a processor and executed any of the above-described AVI-based methods for detecting irregularly edged PCBs.
[0031] In summary, the present invention has at least one of the following beneficial technical effects: 1. AVI inspection equipment can inspect PCBs with irregular edges at a very high speed, far exceeding the speed of manual inspection. This can greatly improve production efficiency and reduce production time and costs; 2. The AVI inspection equipment employs a high-resolution camera and scientific image processing algorithms. By indirectly comparing a standard image of the irregularly edged PCB with an image of the PCB under test, it calculates feature points and descriptors, and obtains the comparison similarity between them. This allows it to detect most hidden defects in irregularly edged PCBs during the production process, including missing circuit components, solder joint problems, and component misalignment. For example, if the distance between matching feature points is greater than a preset threshold, resulting in a low comparison similarity, the irregularly edged PCB can be considered to have certain defects. Using AVI inspection equipment to inspect irregularly edged PCBs can significantly improve production efficiency and inspection accuracy, reduce human error, and thus improve the overall production efficiency and reliability of the product. 3. AVI inspection equipment performs inspections based on pre-set inspection standard images and image processing algorithms, resulting in high consistency. In contrast, manual inspection may be affected by user subjectivity, leading to inconsistent results. 4. AVI inspection equipment can record detailed data and images of each irregularly shaped PCB edge being inspected, facilitating subsequent analysis and traceability. This is of great value for product quality control and production process improvement; 5. By adjusting the image of the irregular PCB edge to be tested and the second comparison image to the same size, the two images can be compared pixel by pixel during feature point extraction and descriptor calculation, ensuring their accuracy and completeness, without missing some important feature points, thus improving the accuracy of the comparison results. Attached Figure Description
[0032] Figure 1 This is a flowchart illustrating an AVI-based method for detecting irregular PCB edges, according to one embodiment of the present invention. Figure 2 This is another flowchart illustrating an AVI-based method for detecting irregularly edged PCBs, according to one embodiment of the present invention. Detailed Implementation
[0033] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0034] The following is in conjunction with the appendix Figure 1 , Figure 2 The present invention will be described in further detail below.
[0035] See Figure 1 This is an embodiment of an AVI-based method for detecting irregular PCB edges, which includes steps S101-S105.
[0036] S101. Obtain the first comparison image, which is a grayscale image of the standard PCB image with irregular edge. A standard image of an irregularly shaped PCB is read using an image reading function and converted into a grayscale image, which serves as the first comparison image. Specifically: The image read function is used to read images and perform color channel conversion, converting color images to grayscale images before further image processing algorithms can be used. The image read function has two parameters: file path and grayscale value. The file path is the file path used to receive the image; the grayscale value indicates whether to convert the standard image of the irregularly edged PCB to grayscale. When the value is True, the standard image of the irregularly edged PCB is converted to grayscale; otherwise, no conversion is performed.
[0037] The first comparison image is a grayscale image of the standard image of the irregularly edged PCB. First, the user needs to input the standard image of the irregularly edged PCB into the AVI inspection device. The standard image is stored in image_src.jpg. When obtaining the first comparison image, the image reading function can be used to retrieve it and convert it to a grayscale image.
[0038] In this embodiment, image_src.jpg can be stored locally or in the cloud; no specific limitation is made here.
[0039] S102. Obtain the grayscale image of the irregular edge PCB to be tested; An image of the irregularly shaped PCB edge under test is read using an image reading function and converted into a grayscale image. Specifically: The image read function is used to read images and perform color channel conversion. The image read function has two parameters: file path and grayscale. The file path is the file path used to receive the image of the irregularly edged PCB under test; the grayscale value indicates whether to convert the image of the irregularly edged PCB under test to a grayscale image. When the value is True, the image of the irregularly edged PCB under test is converted to a grayscale image; otherwise, it is not converted.
[0040] The irregular PCB under test is conveyed to the AVI inspection equipment via a conveyor belt. The high-resolution camera of the AVI inspection equipment captures an image of the irregular PCB under test and transmits the image to the AVI inspection equipment. The image of the irregular PCB under test is stored as test.jpg. When obtaining the grayscale image of the irregular PCB under test, the image reading function can be called directly to obtain it and then the image can be passed to img_test.
[0041] In this embodiment, test.jpg can be stored locally or in the cloud; no specific limitation is made here.
[0042] S103. Calculate the tilt angle of the grayscale image of the irregular edge PCB to be tested; Specifically, the tilt angle of the grayscale image of the irregular edge PCB under test is obtained by extracting the angle of the straight line segment data set from the grayscale image of the irregular edge PCB under test.
[0043] The polar coordinate storage format of the line segments in the set of line segments is (rho, theta), representing the perpendicular distance rho from the line segment to the origin of polar coordinates and the angle theta. A loop is used to traverse the set of line segments. In each iteration, the perpendicular distance rho and the angle theta from the current line segment to the origin in polar coordinates are obtained, and the angle is converted to degrees.
[0044] Finally, the print function is used to print the tilt angle of the grayscale image of the irregular PCB edge under test, so that the results can be viewed in the console.
[0045] S104. Rotate the first comparison image to the same tilt angle as the grayscale image of the irregular edge PCB to be tested, and obtain the second comparison image; First, calculate the coordinates of the rotation center of the first comparison image. Second, obtain the rotation matrix and use the rotation matrix acquisition function to rotate the matrix. Pass three parameters to the rotation matrix acquisition function: the coordinates of the rotation center of the first comparison image, the tilt angle of the grayscale image of the irregular PCB edge to be tested, and the scaling factor.
[0046] Finally, a rotation transformation is performed using an affine transformation function. Four parameters are passed to the affine transformation function: the first comparison image, the rotation matrix, the size of the second comparison image, and the interpolation method (such as cv2.INTER_LINEAR).
[0047] By calling the two functions above, the coordinates of the rotation center of the first comparison image are calculated, the rotation matrix is obtained, and the first comparison image is rotated using an affine transformation function to obtain the transformed image as the second comparison image.
[0048] S105. Compare the grayscale image of the irregular edge PCB to be tested with the second comparison image and generate the comparison similarity result.
[0049] The SIFT (Scale Invariant Feature Transform) algorithm is used to detect feature points in a grayscale image of the irregularly edged PCB under test and a second comparison image. A descriptor is generated for each feature point, which can be used to calculate the similarity between the two images. The feature points are determined based on the color and texture features of the irregularly edged PCB, including solder joints, circuit components, etc.
[0050] Feature matching is performed using OpenCV's BFMatcher matcher. The descriptor of the grayscale image of the irregular PCB edge to be tested is matched with the descriptor of the second comparison image to obtain the matching items. The one with the smallest distance is the best matching item.
[0051] Define a constant n, which represents the selection of the top n best matches to calculate the contrast similarity between two images: sort the matches in ascending order of distance, select the top n best matches, and store the information of these best matches.
[0052] Sum the distances of the first n best matches. Calculate the contrast similarity between the two images based on the sum of distances and the number of best matches. Divide the sum of distances by the number of best matches n, and multiply the result by a coefficient to obtain the contrast similarity.
[0053] See Figure 2 Another embodiment of the AVI-based method for detecting irregular PCB edges provided in this embodiment includes steps S201-S215: S201. Obtain the first comparison image, which is a grayscale image of a standard PCB image with irregular edge. S202. Obtain the grayscale image of the irregular edge PCB to be tested; In this embodiment, steps S201-S202 are similar to steps S101-S102 in the above embodiment, and will not be repeated here to avoid repetition.
[0054] S203. Apply an edge detection algorithm to extract edge data from the grayscale image of the irregular PCB edge to be tested; The Canny edge detection algorithm is applied to extract grayscale image edge data of the irregular PCB edge under test. Specifically: The edge detection function is called, taking in a grayscale image of the irregular PCB edge to be tested and specified threshold parameters 50 and 150. First, the function smooths the input image using a 5x5 Gaussian smoothing filter to reduce noise. Then, it calculates the gradient intensity and direction of each pixel in the grayscale image of the irregular PCB edge. Next, based on the set threshold parameters 50 and 150, pixels with strong gradients are categorized into three types: strong edges, weak edges, and non-edges. If a pixel's gradient intensity is greater than 150, it is considered a strong edge; if it is less than 50, it is excluded; and if it is between 50 and 150, it is considered a weak edge. Finally, by removing the portions of weak edges that are not connected to strong edges, the final edge data is obtained.
[0055] S204. Detecting line segments in edge data using Hough linear transform; This paper utilizes the Hough line transform function to detect line segments in edge data. Specifically: By calling the Hough line transformation function, passing in the edge data and the specified parameters rho=1, theta=np.pi / 180, a set of line segment data is obtained. rho refers to the resolution of the radius in Hough space, that is, the length value of each pixel after transforming from polar coordinates to Cartesian coordinates. Setting rho=1 means that all pixels along the line will be calculated in Hough space. theta refers to the resolution of the angle in Hough space, that is, the size of each angle after transforming from polar coordinates to Cartesian coordinates. Setting theta=np.pi / 180 means that a calculation is performed every 1 degree, where np.pi is the constant pi defined in the NumPy library.
[0056] S205. Based on the set of line segment data, extract the angles of the line segments, and determine the tilt angle of the grayscale image of the irregular edge PCB to be tested based on the angles of the line segments.
[0057] Once the set of line segment data is detected, the tilt angle of the grayscale image of the irregular edge PCB under test can be directly obtained from the set of line segment data. Specifically: The set of line segments is stored in polar coordinates, with the storage format (rho, theta), representing the distance as rho and the angle as theta. A loop is used to iterate through the set of line segments. In each iteration, the distance and angle in polar coordinates are retrieved from the current line segment, and the angle is converted to degrees, where degrees = theta * (180 / np.pi), where np.pi is the constant pi defined in the NumPy library.
[0058] Finally, the print function is used to print the tilt angle of the grayscale image of the irregular PCB edge under test, so that the results can be viewed in the console.
[0059] S206. Measure the length and width of the first comparison image; Use the OpenCV library to obtain the length and width of the first comparison image, and use the .shape attribute to obtain the shape information of the first comparison image. The first two elements of the returned tuple represent the length and width of the first comparison image, respectively.
[0060] S207. Calculate the coordinates of the rotation center of the first comparison image based on its length and width. Calculating the coordinates of the rotation center of the first comparison image involves obtaining its length and width, and then dividing both by 2 to obtain the horizontal and vertical coordinates of the center point. Since the origin of the first comparison image is located at the bottom left corner, and the rotation center is located at the center of the image, dividing the width by 2 gives the x-coordinate of the rotation center, and dividing the length by 2 gives the y-coordinate. This provides the coordinates of the rotation center relative to the origin.
[0061] S208. Calculate the rotation matrix based on the coordinates of the rotation center and the tilt angle of the grayscale image of the irregular edge PCB to be tested. Use the get rotation matrix function to obtain the rotation matrix. Pass three parameters to the get rotation matrix function: the coordinates of the rotation center of the first comparison image, the tilt angle of the grayscale image of the irregular PCB edge to be tested, and the scaling factor.
[0062] The rotation matrix is obtained by calling the function to obtain the rotation matrix, taking into account the coordinates of the rotation center of the first comparison image, the tilt angle of the grayscale image of the irregular PCB edge to be tested, and a scaling factor of 1. The scaling factor is set to 1, meaning no scaling is performed.
[0063] S209. Rotate the first comparison image using a rotation matrix to obtain the second comparison image.
[0064] The first comparison image is rotated and transformed, specifically: To apply a rotation transformation using an affine transformation function, pass four parameters to the affine transformation function: the first comparison image, the rotation matrix, the size of the second comparison image, and the interpolation method (such as cv2.INTER_LINEAR), to obtain the second comparison image after rotation transformation.
[0065] S210. Adjust the grayscale image of the irregular edge PCB to be tested and the second comparison image to the same size; Specifically, the resizing function is used to resize two images. It is a tuple containing two elements: width and height. The resizing function takes an input image and a target size (width, height) and returns the resized image.
[0066] Taking a target size of 1944 pixels * 2592 pixels as an example, by calling the resizing function, inputting the second comparison image and the target size (1944, 2592), the resized second comparison image is obtained. Similarly, by inputting the grayscale image of the irregular edge PCB to be tested and the target size (1944, 2592), the resized grayscale image of the irregular edge PCB to be tested is obtained.
[0067] S211. Extract feature points from the grayscale image of the irregular edge PCB to be tested and the second comparison image, and calculate their descriptors; Feature point detection and matching are performed using the SIFT (Scale Invariant Feature Transform) algorithm from the OpenCV library. Specifically: First, initialize the SIFT (Scale Invariant Feature Transform) object, and then use the cv2.detectAndCompute() function from the OpenCV library to detect feature points and calculate their descriptors.
[0068] S212. The grayscale image of the irregular edge PCB under test is compared with the feature points and descriptors of the second comparison image. First, a SIFT object is used to detect feature points and calculate descriptors in the grayscale image of the irregular PCB edge to be tested and the second comparison image. Then, a matcher object based on brute-force matching is created to perform feature point matching, passing in the descriptor, and finally obtaining the matching items.
[0069] S213. Generate the comparison similarity results between the grayscale image of the irregular edge PCB to be tested and the second comparison image; The comparison is performed by comparing the feature points and descriptors of the grayscale image of the irregular edge PCB under test with a second comparison image. First, the feature points and descriptors of the two images are obtained. Then, a descriptor matching function is used to match the descriptors of the two images and calculate the distance to obtain the matching items. The one with the smallest distance is the best matching item.
[0070] Define a constant n, which represents the selection of the top n best matches to calculate the contrast similarity between two images: sort the matches in ascending order of distance, select the top n best matches, and store the information of these best matches.
[0071] Sum the distances of the first n best matches. Calculate the contrast similarity between the two images based on the sum of distances and the number of best matches. Divide the sum of distances by the number of best matches n, and multiply the result by a coefficient to obtain the contrast similarity.
[0072] S214. Display the first comparison image, the grayscale image of the irregular edge PCB to be tested, and the comparison similarity results; A function is used to display two images in a window, showing both images and the comparison similarity results. Finally, a function is used to add text information to the grayscale image of the irregularly edged PCB under test, and then the grayscale image of the irregularly edged PCB with the added text information is displayed.
[0073] S215. Based on whether the comparison similarity result is greater than or equal to the preset threshold, determine whether the irregular edge PCB is qualified, and then calculate the qualification rate of the irregular edge PCB.
[0074] First, the similarity results are used to determine whether the PCB with irregular edge to be tested is qualified. If the similarity between the grayscale image of the PCB with irregular edge to be tested and the second comparison image is greater than or equal to the preset threshold, the PCB with irregular edge to be tested is qualified. If the similarity between the grayscale image of the PCB with irregular edge to be tested and the second comparison image is less than the preset threshold, the PCB with irregular edge to be tested is unqualified.
[0075] Taking 100 irregularly edged PCBs to be tested, with a preset threshold of 99.95%, as an example, the initial number of qualified irregularly edged PCBs is 0. By iterating through each PCB to be tested, the number of qualified PCBs is recorded. When the similarity is greater than or equal to 99.95%, the number of qualified PCBs is incremented by one. The pass rate of the irregularly edged PCBs is calculated by dividing the number of qualified PCBs by the total number of irregularly edged PCBs tested, and then multiplying by 100.
[0076] The beneficial effects that can be achieved by the embodiments of this application include: 1. AVI inspection equipment can inspect PCBs with irregular edges at a very high speed, far exceeding the speed of manual inspection. This can greatly improve production efficiency and reduce production time and costs; 2. AVI inspection equipment uses high-resolution cameras and scientific image processing algorithms to detect most hidden defects in PCBs with irregular edges during production, including missing circuit components, solder joint problems, and component misalignment. Using AVI inspection equipment to inspect PCBs with irregular edges can significantly improve production efficiency and inspection accuracy, reduce human error, and thus improve the overall production efficiency and reliability of the product. 3. AVI inspection equipment performs inspections based on pre-set inspection standard images and image processing algorithms, resulting in high consistency. In contrast, manual inspection may be affected by user subjectivity, leading to inconsistent results. 4. AVI inspection equipment can record detailed data and images of each irregularly shaped PCB edge being inspected, facilitating subsequent analysis and traceability. This is of great value for product quality control and production process improvement; 5. By using edge detection algorithms, Hough linear transform algorithms, and two-dimensional rotation matrices from the OpenCV library, the first comparison image is precisely rotated to an angle consistent with the tilt angle of the grayscale image of the irregular edge PCB to be tested. The second comparison image and the image of the irregular edge PCB to be tested are first adjusted to the same size. Then, the feature points of the second comparison image and the image of the irregular edge PCB to be tested are extracted using the SIFT algorithm. The two images are compared by feature point matching, which achieves a more accurate detection effect for irregular edge PCBs.
[0077] This application also provides an AVI-based detection device for irregular edge PCBs, including a first comparison image acquisition module, a test image acquisition module, a tilt angle calculation module, an image rotation module, and a comparison module.
[0078] The first comparison image acquisition module is used to acquire a first comparison image; the test image acquisition module is used to acquire a grayscale image of the irregular edge PCB to be tested; the tilt angle calculation module is used to calculate the tilt angle of the grayscale image of the irregular edge PCB to be tested; the image rotation module is used to rotate the first comparison image to obtain a second comparison image; the comparison module is used to compare the grayscale image of the irregular edge PCB to be tested with the second comparison image and generate a comparison similarity result.
[0079] In this embodiment, a first comparison image acquisition module acquires a first comparison image and transmits it to an image rotation module. A test image acquisition module acquires a grayscale image of the irregularly shaped PCB edge to be tested and transmits it to a tilt angle calculation module. The tilt angle calculation module calculates the tilt angle of the grayscale image of the irregularly shaped PCB edge to be tested and transmits the tilt angle to the image rotation module. The image rotation module rotates the first comparison image to the same tilt angle as the grayscale image of the irregularly shaped PCB edge to be tested, obtaining a second comparison image, and transmits the second comparison image to a comparison module. The comparison module compares the grayscale image of the irregularly shaped PCB edge to be tested with the second comparison image and generates a comparison similarity result.
[0080] The tilt angle calculation module includes: an edge extraction unit, a line segment detection unit, and a line segment angle extraction unit; the image rotation module includes: an image length and width measurement unit, a rotation center coordinate calculation unit, a rotation matrix calculation unit, and a rotation unit; the comparison module includes: a feature point extraction unit, a comparison unit, and a comparison similarity result generation unit.
[0081] In one possible implementation, the AVI-based inspection device for irregular edge PCBs further includes: a size adjustment module, a display module, and a pass rate calculation module.
[0082] In this embodiment, the module may also include a size adjustment module for adjusting the grayscale image of the irregular edge PCB to be tested and the second comparison image to the same size; a display module for displaying the comparison similarity result image in a window; and a pass rate calculation module for calculating the pass rate of the irregular edge PCB to be tested based on the detection results of the irregular edge PCB.
[0083] It should be noted that the above embodiments of the apparatus are only illustrated by the division of the above functional modules. In practical 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. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0084] This application provides an AVI-based inspection device for irregularly edged PCBs. The AVI-based inspection device for irregularly edged PCBs may include: at least one processor, at least one network interface, a user interface, a memory, and at least one communication bus.
[0085] The processor is used to invoke a method for detecting irregular edge PCBs based on AVI stored in memory. When executed by one or more processors, this causes the AVI-based irregular edge PCB detection device to perform one or more of the methods described in the above embodiments.
[0086] This application also provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the method for irregular edge PCB based on AVI described in the above embodiments. To avoid repetition, it will not be described again here.
[0087] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0088] This specific embodiment is merely an explanation of the present invention and is not intended to limit the invention. After reading this specification, those skilled in the art can make modifications to this embodiment without contributing any inventive step, but such modifications are protected by patent law as long as they are within the scope of the claims of the present invention.
Claims
1. A method for detecting irregularly edged PCBs based on AVI, characterized in that, include: A first comparison image is obtained, which is a grayscale image of a standard PCB image with irregular edges; Obtain a grayscale image of the irregularly edged PCB to be tested; Calculate the tilt angle of the grayscale image of the irregular edge PCB to be tested; The first comparison image is rotated to the same tilt angle as the grayscale image of the irregular edge PCB to be tested, to obtain the second comparison image; The grayscale image of the irregular edge PCB to be tested is compared with the second comparison image, and a comparison similarity result is generated.
2. The method according to claim 1, characterized in that, The calculation of the tilt angle of the grayscale image of the irregular edge PCB under test includes: An edge detection algorithm is applied to extract the edge data of the grayscale image of the irregular PCB under test; The Hough linear transform is used to detect straight line segments in the edge data; Based on the line segment data, the angle of the line segment is extracted, and the tilt angle of the grayscale image of the irregular edge PCB under test is determined based on the angle of the line segment.
3. The method according to claim 2, characterized in that, The step of rotating the first comparison image to the same tilt angle as the grayscale image of the irregular edge PCB under test to obtain the second comparison image includes: Measure the length and width of the first comparison image; Calculate the coordinates of the rotation center of the first comparison image based on its length and width. The rotation matrix is calculated based on the coordinates of the rotation center and the tilt angle of the grayscale image of the irregular edge PCB to be tested. The first comparison image is rotated using a rotation matrix to obtain the second comparison image.
4. The method according to claim 1, characterized in that, The method further includes: Adjust the grayscale image of the irregular PCB edge to be tested and the second comparison image to the same size.
5. The method according to claim 4, characterized in that, The step of comparing the grayscale image of the irregular PCB edge to be tested with the second comparison image and generating a comparison similarity result includes: Feature points are extracted from the grayscale image of the irregular edge PCB under test and the second comparison image, and their descriptors are calculated; The grayscale image of the irregular edge PCB under test is compared with the feature points and descriptors of the second comparison image. Generate a grayscale image of the irregular edge PCB to be tested and compare it with the second comparison image to obtain a similarity result.
6. The method according to claims 1-5, characterized in that, The method further includes: The display shows the first comparison image, the grayscale image of the irregular edge PCB to be tested, and the comparison similarity result.
7. The method according to claim 6, characterized in that, The method further includes: Based on whether the comparison similarity result is greater than or equal to a preset threshold, it is determined whether the irregular edge PCB is qualified, and then the qualification rate of the irregular edge PCB is calculated.
8. A detection device for irregularly shaped PCBs based on AVI, characterized in that, include: The first comparison image acquisition module is used to acquire the first comparison image; The image acquisition module is used to acquire grayscale images of the irregular edge PCB under test. The tilt angle calculation module is used to calculate the tilt angle of the grayscale image of the irregular edge PCB under test. An image rotation module is used to rotate the first comparison image to the same tilt angle as the grayscale image of the irregular edge PCB to be tested, so as to obtain a second comparison image; The comparison module is used to compare the grayscale image of the irregular PCB edge to be tested with the second comparison image and generate a comparison similarity result.
9. The apparatus according to claim 8, characterized in that, The device further includes: The size adjustment module is used to adjust the grayscale image of the irregular edge PCB under test and the second comparison image to the same size.
10. The apparatus according to claim 8, characterized in that, The device further includes: The display module is used to display the comparison similarity result image in a window; The pass rate calculation module is used to determine whether the irregular edge PCB is qualified based on the comparison similarity results, thereby calculating the pass rate of the irregular edge PCB.