Precision PCB Fabrication, High-Frequency PCB, High-Speed PCB, Standard PCB, Multilayer PCB and PCB Assembly.
The most reliable PCB & PCBA custom service factory.
PCB News

PCB News - Application of chain code table and line segment table in PCB

PCB News

PCB News - Application of chain code table and line segment table in PCB

Application of chain code table and line segment table in PCB

2021-11-03
View:410
Author:Kavie

Application of Chain Code Table and Line Segment Table in PCB Hole Position Detection
Abstract: This article studies the positioning of printed circuit boards (Printed-Circuit Board) holes in the industry, and achieves the purpose of benchmarking the PCB board punching machine. Effective pre-processing of the image acquired by the CCD, using the combination of the chain code table and the line segment table to accurately and quickly determine the centroid of the PCB hole position. The method in this paper can detect the centroid accurately to 0.001 pixel level. And find out the area, perimeter, shape, and centroid of the hole. This method runs successfully on the VC++6.0 platform, and its programming speed is fast, and it can achieve real-time, accurate, intelligent, and batch inspection, which greatly improves the quality and speed of PCB board inspection.

pcb


Introduction

Automated Optical Inspection (AOI, Automated Optical Inspection) is a visual inspection method that has emerged in recent years. It acquires images through CCD, and judges defects and malfunctions through computer processing and analysis. The application of AOI on the PCB production line has the advantages of fast detection speed, short programming time, and intelligent detection and control of images in large quantities. With the development of industrial technology, the requirements for the aperture size of the PCB board are becoming more and more precise, and the requirements for the mass production of machines are also getting higher and higher. This article is derived from a project of a company producing hole counting machine. The technical requirement is that the minimum radius of the PCB hole position is 0.2mm, and there are as many as 2000 round holes on each PCB. The total processing time is not more than 10s. The result is obtained after processing. The center of the circle is accurate to 0.01 pixel level, and the deviation of each circle center from the center of the template must not exceed 25um. If 80% of the center deviation exceeds this index, it is regarded as unqualified, and the equipment benchmark needs to be adjusted.


"Edge" refers to the collection of pixels in the image that have a step change or a roof-like change in the pixel gray level. It exists between target and background, target and target, region and region, primitive and primitive. He is very useful for image recognition and analysis. The edge can outline the outline of the target object, so that the observer can see it at a glance, and contains abundant information [1]. Therefore, to obtain the hole position information, you must first perform edge detection and contour tracking. Use the freeman chain code to trace the contour of the edge, and use the chain code table and the line segment table to store and process the data.


1 Image acquisition and preprocessing


(1) This article uses backlighting and high-resolution cameras to obtain high-contrast and high-quality images. The image resolution is 409*096. The quality of the image source is very important, and it will directly affect the subsequent image processing.


(2) Use median filtering to smooth the image, the purpose of which is to minimize or eliminate the influence of noise and improve the image quality. Median filtering can overcome the blurring of image details caused by linear filters such as least mean square filtering and mean filtering under certain conditions, and is the most effective for filtering pulse interference and image scanning noise. For the images involved in this article, the PCB board Hole details are flawed, so median filtering is more appropriate. Its advantage is that it can eliminate noise without destroying the edges of the image.


(3) Use OSTU (Maximum Between-Class Variance Method) for threshold segmentation. This method is simple, stable and effective. It is a binarization method that automatically selects the threshold on the basis of judging the minimum function and the principle of the square method. The idea is to divide the image The histogram is divided into two groups with a certain gray level. When the variance of the divided two groups is the largest, the gray level is set to the best threshold [2].


2 Use chain code table and line segment table [3] to describe the data results of the image


(1) Use Freeman chain code contour tracking Freeman chain code [4] is divided into eight-connected and four-connected chain codes. The eight-connected chain code is defined by the direction in which the central pixel points to its 8 neighbors, and the four-connected chain uses the central pixel. Point to the direction of its 4 neighbors, with a value of 0~3. This article uses an eight-connected chain code, as shown in Figure 2 below, the 8-connected chain code rotates in a clockwise direction, and the value of the chain code decreases by 1 when it rotates 45 degrees clockwise; if the value of the chain code increases by 4, the direction is reversed, and 8 is added. Then back to the original direction. When the chain code value exceeds 8 or is less than 0, use modulo 8 operation to remove or add 8.


(2) Application of chain code table


For the tracking of a single hole in the PCB board, this article uses the Freeman chain code method to obtain the boundary chain code of the target object. When a certain point is searched for the gray level of the target body, this point is the boundary point of the target body. If this point has not been coded, then this point is the starting point of a certain hole position. From this point, the contour tracking is carried out by Freeman chain code, and the chain code value of each point on the boundary can be traced, and according to The deviation value of the coordinates of the center point and the neighboring points is shown in Table 1. The coordinates of each boundary point can be obtained from the coordinates of the starting point, which can be expressed as a two-dimensional array inc[8][2].


The specific coding process is: set the gray level of the target object as G1 and the background gray level as G2. Search the image of the entire PCB board. When a certain point A meets the gray level of G1, it is regarded as a boundary point. Starting from A, the boundary of the hole position is searched clockwise, and the initial value is defined as the chain code value equal to 4 Search for the next point in the direction. If the gray value of the next point is equal to G1, it is the next boundary point. Otherwise, the search direction is rotated 45 degrees clockwise, and the chain code value is 3 to continue to search for the point, so that the first point is always found A point B that satisfies the gray value equal to G1. Then set B as the new boundary point, and set the tracking end flag to 0. If no boundary point is found in the neighboring points, set the tracking end flag to 1, indicating that it is an isolated point.


Point B is taken as the new boundary point. Take its chain code value as the direction of the starting chain code. Repeat the above tracking clockwise until the last boundary point is point A. The single hole bitmap is tracked, and Mark this area with color filling, which means it has been searched, and the tracked chain code value is stored in the chain code table. In this paper, the chain code table is stored in a one-dimensional integer array code[ ], the storage contents with subscripts 0 and 1 are the coordinates X and Y of the starting boundary point respectively, and the total chain code number is stored in the unit with subscript 2 The number N, starting from the unit with the subscript 3, store the chain code value of the first boundary point, the chain code value of the second boundary point... until the chain code value of the last Nth boundary point.


3 Line segment table


(1) Definition of line segment table


Since the chain code table can only represent the boundary of the target body, but not the inside and outside of the boundary, the chain code table cannot represent the internal pixels of the target body, but in fact, in addition to obtaining the boundary points and perimeter of an image, it also obtains For other parameters, such as the hole center data and area obtained in this article, in order to realize the processing and calculation of the internal pixels, another structure-the line segment table is needed.


The area can also be seen as composed of horizontal line segments. Each line segment can be represented by its two end points. The endpoint table that smoothly arranges all the horizontal line segments in the area according to the scan is called the line segment table. Each point of the line segment table is composed of two parts. The even-numbered point represents the coordinates of the left end point, and the odd-numbered point represents the coordinates of the right end point. If a structure DOT is defined to represent the line segment table, use a one-dimensional array dot[ ], let i represent the line segment The left end of this line segment can be expressed as dot[2*i], and the right end point is dot[2*i+1].


(2) Application of line segment table


The line segment table obtains each line segment and the endpoint value of the line segment, so the internal pixels of the area can be easily obtained through calculations, and other important parameters of the image can be obtained, such as the parameters required in this article: the area of the calculation area, the center of gravity; Quickly fill a certain area (to avoid repeated searches and improve efficiency); the shape parameter of the area, the formula is expressed as: F = L*L/4 πS


The purpose of this project is to detect the center of the circular hole, so it is particularly important for the shape detection of the area. In the above formula, L is the circumference and S is the area. The shape parameter F obtained by this ratio is the shape parameter of the circle. 1. The greater the difference from 1, the greater the difference from the shape of the circle. In order to count the number of holes in the PCB hole and the center of the circle, this shape parameter can be used for judgment. If it is near 1, it can be approximated as The round hole is processed, otherwise it is directly filled with a non-round hole color mark and will not be recorded in the result.


(3) Conversion of chain code table to line segment table [5]


Use the line segment table to indicate that other important parameters of the image can be obtained, and the conversion from the chain code table to the line segment table can be in accordance with Table 2.


Specific steps are as follows:


After the conversion of the table, the chain code obtains three types [6]: middle point, type number 0; left end point, type number 1; right end point, type number 2; singular point, type number 3. According to the data in the chain code table, the incoming chain code value and the outgoing chain code value can be known, and the type of this point can be determined for the direction of the two. In the program design, the point type can be judged according to Table 3. If it is the left and right end points, the coordinates are stored in a temporary array. The singular point can be regarded as a coincidence of the same left and right points, that is, it should be stored twice, in the middle Do not deposit points. The endpoints in the line segment table are sorted by the size of the Y coordinate, and in the same row are sorted by the size of the X coordinate.


4 Experimental results


This experiment takes a screenshot of the PCB image of this project to process, screenshot and process the filled image.


Use the algorithm and program in this article to process the screenshots, and use the chain code table and line segment table to store the data, and you can get some parameter information of the PCB hole position.


5 Conclusion


In this paper, the backlight source is used to obtain high-quality PCB images, and OSTU threshold segmentation method is used to obtain the binary image of the source image stably and simply, scan and perform contour tracking, and use the principle of tracking the next point to the right. It is more prepared and time-saving. The chain code table and the line segment table store data and data processing, and it is very convenient and accurate to obtain the perimeter, area and hole centroid of the PCB board, and successfully solve the positioning problem when the PCB board is punched. This experiment has been run and verified on the Visual C++ software platform. It can detect and process 216 circular holes within 31 us, and obtain the speed and accuracy required by this project. The results prove that this method is feasible.