Method for automatically measuring sub-pixel parameters of patch component, computer equipment and medium

By extracting and optimizing straight line features in the image, the problem of low component parameter measurement accuracy in the existing technology is solved, automatic measurement at the sub-pixel level is achieved, and detection accuracy and efficiency are improved.

CN118674699APending Publication Date: 2024-09-20YONGJIANG LAB
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202410761016.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

Existing component parameter measurement methods have low measurement accuracy and cannot meet high-precision requirements, especially when measuring pixel-level dimensions, the degree of automation is low.

Method used

An automatic measurement method for sub-pixel parameters of patch components is adopted. By acquiring grayscale images, segmenting the foreground and background, extracting the pin area, calculating the minimum enclosing rectangle and straight line segments, combining straight line segments, optimizing edge straight line segments, and calculating sub-pixel level The distance between pairs of edge straight segments to obtain the length and width of the component.

Benefits of technology

It improves the detection accuracy to the sub-pixel level, significantly improves the automation and efficiency of measurement, and can more accurately locate and measure the pin parameters of components.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118674699A
    Figure CN118674699A
Patent Text Reader

Abstract

The invention provides an automatic measurement method for sub-pixel parameters of a patch component, computer equipment and a medium, and solves the problem of low measurement precision of an existing component parameter measurement method. The measurement method comprises the following steps: acquiring a grey-scale map of a to-be-detected image; segmenting the to-be-detected image to obtain a foreground and a background; extracting all connected regions in the foreground, and screening out interference to obtain an image which only retains a pin region; calculating a minimum surrounding rectangle of all pin areas; extracting all straight line segments of the minimum surrounding rectangle of the pin area; searching and combining all the obtained straight line segments, and combining the straight line segments in the same direction into a pin long straight line segment; extracting edge straight line segment pairs of the long straight line segments of the pins; optimizing the obtained edge straight line segment pair to a sub-pixel level; and calculating the distance between the sub-pixel-level edge straight line segment pairs of the two groups of elements to obtain the distances of the two straight line segment pairs, which are respectively the length and the width of the elements. According to the invention, the detection precision is improved to a sub-pixel level, and the detection precision is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method for automatically measuring sub-pixel parameters of a patch element, computer equipment and a medium thereof, and belongs to the technical field of surface mounting. Background Art

[0002] Surface mount technology is an electronic manufacturing technology that solders patch components onto printed circuit boards. Parameter measurement of patch components is an important means of obtaining component parameters, measuring positions, and detecting defects. Existing component measurement methods include manual measurement and visual measurement. Manual measurement requires distinguishing component types, and different measurement methods are required for different types of components, which results in a low degree of automation. Visual measurement has the advantages of automation, efficiency, and high precision, but existing visual measurement methods are based on pixel-level image features. Under high-precision measurement requirements, pixel-level size measurement cannot meet high-precision measurement requirements. Summary of the invention

[0003] In view of the problem of low measurement accuracy of existing component parameter measurement methods, the present invention provides a method for automatically measuring sub-pixel parameters of patch components with improved measurement accuracy to sub-pixel level, and a computer device and medium thereof.

[0004] A method for automatically measuring sub-pixel parameters of a patch component of the present invention comprises:

[0005] Obtain a grayscale image of the image to be detected;

[0006] Segment the image to be detected to obtain the foreground and background;

[0007] Extract all connected areas in the foreground and filter out interference to obtain an image that only retains the pin area;

[0008] Calculate the minimum enclosing rectangle of all pin areas;

[0009] Extract all straight line segments of the minimum enclosing rectangle of the pin area;

[0010] Search and combine all the straight line segments obtained, and combine the straight line segments in the same direction into the pin long straight line segment;

[0011] Extract edge straight line segment pairs of the long straight line segment of the pin;

[0012] Optimize the obtained edge straight line segment pairs to sub-pixel level;

[0013] The distances between pairs of sub-pixel edge straight line segments of two groups of components are calculated to obtain the distances between the two pairs of straight line segments, which are the length and width of the components, respectively.

[0014] Preferably, the method for segmenting an image based on a threshold value T comprises:

[0015] Determine the threshold T:

[0016]

[0017] Among them, A is the maximum value of the image grayscale, and B is the minimum value of the image grayscale;

[0018] The pixels whose grayscale values ​​in the image to be detected exceed the threshold T are set as the foreground, and the pixels whose grayscale values ​​in the image to be detected are set as the background.

[0019] Preferably, the method of extracting all connected areas in the foreground and filtering out interference to obtain an image retaining only the pin area includes:

[0020] The connected regions in the foreground are extracted. The connected regions are pixel clusters that satisfy eight-connectivity between pixels. The connected regions are labeled, the minimum bounding rectangle of each connected region is calculated, and the characteristic parameters of the connected regions are determined, including the area N, the length W and width H of the minimum bounding rectangle, and the rectangularity.

[0021] The connected area that meets the constraint conditions is regarded as the pin area, and the connected area outside the pin area is filtered out as anomalies. The constraint conditions are:

[0022] S=(T NH >N>T NL )∧(R>T R )∧(T WH >W>T WL )^(H HH >T HL )

[0023] Where S is the constraint logic value of the pin area, T NH and T NL is the area threshold range of the pin area, T R is the rectangularity threshold, T WH and T WL is the width threshold range of the pin area, T HH and T HL is the length threshold range of the pin area; S is 0, indicating that the corresponding connected area does not satisfy the constraint and is interference, and S is 1, indicating that the corresponding connected area is a pin area;

[0024] Calculate the S values ​​of all connected areas, and extract the area with an S value of 1 as the pin area.

[0025] Preferably, a rotating caliper algorithm is used to calculate the minimum circumscribed rectangle of the connected area or the pin area.

[0026] Preferably, the method for extracting the straight line segment of the minimum enclosing rectangle of the pin area includes:

[0027] Determine the four vertices of the minimum circumscribed rectangle. The coordinates of the four vertices are (x 1 ,y 1 ),(x 2 ,y 2 ),(x 3 ,y 3 ),(x 4 ,y 4 );

[0028] The equations of the four straight line segments of the minimum circumscribed rectangle are:

[0029]

[0030] Where x represents the abscissa of the coordinate system where the minimum circumscribed rectangle is located, and y represents the ordinate;

[0031] Convert the four straight line segment equations into general equations and obtain the coefficients of all straight line segment equations:

[0032]

[0033] Among them, A 1 , B 1 , C 1 ,A 2 , B 2 , C 2 ,A 3 , B 3 , C 3 ,A 4 , B 4 , C 4 , are the straight line segment equation coefficients of the four straight line segments of the minimum circumscribed rectangle.

[0034] Preferably, the method of searching and combining all the obtained straight line segments and combining the straight line segments in the same direction into the pin long straight line segment includes:

[0035] Construct the straight line segment adjacency relationship matrix L of the straight line segment pairwise relationship, where the elements are L i,j , the dimension of matrix L is n*n, where n represents the total number of straight line segments;

[0036] Initialize the length of the mark vector F to n, and the initial value to -1, where -1 indicates that the corresponding straight line segment has not been searched, and 0 indicates that the corresponding straight line segment has been searched; initialize the stack C to an empty vector, and the stack C is used to store collinear line segments;

[0037] Traverse all elements of the line segment adjacency matrix L and search for combinations of line segments. The search process is:

[0038] The current processing line segment number is i. When F(i)<0 and C(i) is not empty, push the j position into C(i) and set the F(j) position value to F(i); when F(i)>0 and F(j)<0, push the j position value into the stack C(F(i)) and set the F(j) position value to F(i); i and j are elements L i,j The subscript of ;

[0039] After the search is completed, the straight line segments in the stack C are taken out one by one to form a long straight line segment.

[0040] Preferably, the element L in the line segment adjacency matrix L i,j for:

[0041] L i,j =(θ i,j <T θ )∧(D i,j <T dis )

[0042] Among them, θ i,j is the angle between the straight line segments, T θ is the straight line segment angle threshold, D i,j is the distance between straight line segments, T dis is the distance threshold between straight line segments.

[0043]

[0044] a and b represent the number of pixels on the two straight line segments i and j.

[0045] Preferably, the method for extracting edge straight line segment pairs of the long straight line segments of the pins comprises:

[0046] Project the vertical direction of all the long straight line segments of the pins, and select the edge straight line segment pairs of the two groups of components based on the distance on the projection.

[0047] Preferably, the method of optimizing the obtained edge straight line segment pair to the sub-pixel level includes:

[0048] The pixels on the edge straight line segment (x 0 ,y 0 ) as the center, and take out 4 pixels along the X direction and Y direction as the candidate area. The pixels taken out along the X direction are x 1 ,x 2 ,x 3 ,x 4 ,x 5 , the corresponding grayscale values ​​are Q(x 1 ),Q(x 2 ),Q(x 3 ),Q(x 4 ),Q(x5 );

[0049] Calculate V 1 ,V 2 ,V 3 ,V 4 :

[0050] V i =ln(|Q(x i+1 )-Q(x i )|), i=1,2,3,4;

[0051]

[0052] Then take out pixel y along the Y direction 1 ,y 2 ,y 3 ,y 4 ,y 5 , and the corresponding grayscale values ​​are

[0053] Q(y 1 ),Q(y 2 ),Q(y 3 ),Q(y 4 ),Q(y 5 ), calculate N 1 ,N 2 ,N 3 ,N 4 :

[0054] N i =ln(|Q(y i+1 )-Q(y i )|),i=1,2,3,4;

[0055] Calculate μ y :

[0056]

[0057] The optimized sub-pixel point (x, y) is:

[0058]

[0059] Preferably, the distance between the sub-pixel edge straight line segment pairs of the two groups of elements is calculated to obtain the distance between the two straight line segment pairs, comprising:

[0060] Using two pairs of straight line segments, determine the length and width of the component, where the length d of the component is calculated as:

[0061]

[0062] Among them, A j , Bj , C j and A i , B i , C i is the parameter of the straight line segment equation corresponding to the two straight line segments in the length calculation, (x k ,y k ) and (x l ,y l ) are the coordinates of the points on the two straight line segments respectively;

[0063] Component width w is calculated as follows:

[0064]

[0065] Among them, A w , B w , C w and A z , B z , C z It is the straight line segment equation parameter corresponding to the two straight line segments in the width calculation.

[0066] The present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods when executing the computer program.

[0067] The present invention also provides a medium, wherein the medium stores computer executable instructions, and the computer executable instructions are used to enable a computer to execute any one of the methods.

[0068] The beneficial effects of the present invention are as follows: the present invention uses the common characteristics of components: straight line characteristics. The pins are rectangular, and the straight line is a prominent feature of the component pins, which can reflect the shape of the pins. The straight line size represents the size of the pins, and the positional relationship between the straight lines better reflects the relationship between the pins. The straight line characteristics are used to quickly combine and screen the pins of the components that can be located, obtain the straight line to be measured, and use a new sub-pixel calculation method to improve the detection accuracy to the sub-pixel level, greatly improving the detection accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0069] Figure 1 is a flow chart of the present invention;

[0070] Figure 2 is a flowchart of the search algorithm;

[0071] Figure 3 Schematic diagram for screening of straight line pairs. DETAILED DESCRIPTION

[0072] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0073] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0074] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments, but they are not intended to limit the present invention.

[0075] A flow chart of a method for automatically measuring sub-pixel parameters of a patch component in this embodiment. Figure 1 As shown, the present invention includes:

[0076] Step 1: Set a suitable threshold and perform threshold segmentation on the image. The grayscale value greater than the threshold is set as the foreground, and the grayscale value less than the threshold is set as the background. Image segmentation uses a segmentation method based on threshold T, and the threshold T is determined by the following formula:

[0077]

[0078] A is the maximum grayscale value of the image, and B is the minimum grayscale value of the image. Image segmentation sets pixels whose grayscale values ​​exceed the threshold as foreground, and sets pixels whose grayscale values ​​in the image to be detected are within the threshold T as background.

[0079] Step 2: The method of extracting all connected areas in the foreground and filtering out interference to obtain an image that only retains the pin area includes:

[0080] The connected region refers to the pixel clustering region in the foreground image after threshold segmentation that satisfies eight connectivity between pixels. In this implementation, the two-step method is first used to extract the connected region, and the connected region is labeled to obtain the labeled connected region. Then the rotating caliper algorithm is used to calculate the minimum bounding rectangle of each connected region, and the area, vertex position, length and width parameters of the minimum bounding rectangle are output.

[0081] The connected domain analysis method is used to calculate the characteristics of all connected regions. All interference is filtered out based on indicators such as region area, rectangularity, region length and width, and the retained connected regions are recorded as pin regions.

[0082] Connected region features include region area, region length and width, and rectangularity parameters. Region area refers to the number of foreground pixels in the region, denoted by N. Region area is obtained by calculating the number of foreground pixels in the region. Region length and width refer to the length W and width H of the minimum circumscribed rectangle of the region. Rectangularity refers to the ratio of the region area to the product of the length and width of the minimum circumscribed rectangle, denoted by R. The calculation formula for rectangularity R is as follows:

[0083]

[0084] The screening process is as follows: the constraint logic value S of all pin regions is calculated, and the connected regions that meet the constraint conditions are regarded as pin regions, and the connected regions outside the pin regions are screened out as exceptions:

[0085] S=(T NH >N>T NL )∧(R>T R )∧(T WH >W>T WL )∧(H HH >T HL )

[0086] Among them, T NH and T NL is the area threshold range of the pin area, T R is the rectangularity threshold, T WH and T WL is the width threshold range of the pin area, T HH and T HL is the length threshold range of the pin area. S is the logical result of the area according to the constraint condition. 0 means that the area does not meet the constraint and is interference, and 1 means that the area is a pin area. Calculate the S value of all connected areas, and extract all areas with a value of 1 as pin areas.

[0087] Step 3: Extract the enclosing straight line of all pin areas. The enclosing straight line refers to the straight line corresponding to the minimum circumscribed rectangle of the pin area obtained in step 2. The straight line is determined based on the four vertices of the minimum circumscribed rectangle. Let the four endpoints of the rectangle be (x 1 ,y 1 ),(x 2 2,y 2 ),(x 3 ,y 3 ),(x 4 ,y 4 )The equations of the four straight line segments of the minimum circumscribed rectangle are:

[0088]

[0089] Where x represents the abscissa of the coordinate system where the minimum circumscribed rectangle is located, and y represents the ordinate;

[0090] Convert the four straight line segment equations into general equations and obtain the coefficients of all straight line segment equations:

[0091]

[0092] Among them, A 1 , B 1 , C 1 ,A 2 , B 2 , C 2 ,A 3 , B 3 , C 3 ,A 4 , B 4 , C 4 , are the straight line segment equation coefficients of the four straight line segments of the minimum circumscribed rectangle.

[0093] The method in step 3 can quickly separate the component pins and the background area in the image, and screen out the component pins according to the size and area. The calculation amount is small and the screening conditions are easy to control.

[0094] Step 4: Search and combine all the straight line segments obtained in step 3, and combine the straight line segments in the same direction into long straight line segments. Long straight line segments are obtained by searching and combining straight lines. The process is as follows: First, construct a straight line adjacency matrix L for the relationship between two straight line segments. The total number of straight line segments obtained in step 3 is n, so the dimension of the matrix L is n*n. The value of the adjacency matrix is ​​calculated by the distance and angle between the straight lines. The element L in the straight line segment adjacency matrix L is n*n. i,j The following conditions are met.

[0095] L i,j =(θ i,j <T θ )∧(D i,j <T dis )

[0096] where θ i,j is the angle between the straight line segments, T θ is the straight line segment angle threshold, D i,j is the distance between straight line segments, T dis is the distance threshold between straight line segments.

[0097]

[0098] a and b represent the number of pixels on the two straight line segments i and j.

[0099] After obtaining the line adjacency matrix L, perform line search and combine to form a long line. First, initialize the variables: initialize the length of the mark vector F to n, and the initial value to -1, where -1 means that the corresponding position line has not been searched, and 0 means that the corresponding line has been searched; initialize the stack C to an empty vector, and the stack C is used to store collinear line segments;

[0100] Traverse all elements of the line segment adjacency matrix L and search for combinations of line segments. The search process is:

[0101] The current processing line segment number is i. When F(i)<0 and C(i) is not empty, push the j position into C(i) and set the F(j) position value to F(i); when F(i)>0 and F(j)<0, push the j position value into the stack C(F(i)) and set the F(j) position value to F(i); i and j are elements L i,j The subscript of ;

[0102] After the search is completed, the straight line segments in the stack C are taken out one by one to form a long straight line segment, as shown in 2. The specific process includes:

[0103] S1. Construct the straight line segment adjacency relationship matrix L of the straight line segment pairwise relationship, where the elements are L i,j , the dimension of matrix L is n*n, where n represents the total number of straight line segments;

[0104] S2. Initialize the length of the mark vector F to n, and the initial value to -1, where -1 indicates that the corresponding straight line segment has not been searched, and 0 indicates that the corresponding straight line segment has been searched; initialize the stack C to an empty vector, and the stack C is used to store collinear line segments, i = 0, j = 0;

[0105] S3, j = i;

[0106] S4, L i,j Is it equal to 1? If yes, go to S5; if not, go to S7;

[0107] S5, the current processing line segment number is i, when F(i)<0 and C(i) is empty, push i into the stack C(i), set the value of F(i) position to i, push j into C(i), set the value of F(j) position to F(i), and go to S6;

[0108] When F(i)<0 and C(i) is not empty, push position j into C(i), set the value of position F(j) to F(i), and go to S6;

[0109] When F(i)>0 and F(j)<0, push the value at position j into the stack C(F(i)), set the value at position F(j) to F(i), and go to S6;

[0110] When F(i)>0 and F(j)>0, go to S6;

[0111] S6, j = j + 1;

[0112] S7, determine whether j is less than or equal to n, if so, go to S4, if not, go to S8;

[0113] S8, i=i+1;

[0114] S9. Determine whether i is less than or equal to n. If so, go to S3. If not, take out the straight line segments in the stack C in sequence to form a long straight line segment.

[0115] This implementation adopts the idea of ​​combination to combine straight line segments into long straight line segments, realizing a conversion from pins to components as a whole, and transforming individual component pins into a pair of overall straight line segments for component measurement. This has three advantages: first, it automatically locates the component measurement straight line segment pairs; second, it automatically groups the pin straight line segments; and third, it extracts the corresponding straight line segments as long straight line segments to reduce measurement errors.

[0116] Step 5: Project all pairs of long straight line segments of the pins, and filter out the edge straight line segments of the component based on the projection distance. The necessary step for the combined long straight line segments is to extract the boundary straight line segments. The boundary straight line segments are the enclosing straight line segments used for component measurement. The straight line segment measurement pair is based on the projection along the center of the component, and the straight line segments at the boundary of the position projection are the measured straight line segments. Project in the vertical direction along the measured straight line segment, and extract the straight line segments based on the distance on the projection. Use the distance of the intersection of the straight line segments along the X and Y axes to filter the boundary straight line segments. Figure 3 As shown, the intersection point of all the long straight lines of the SOP element along the Y direction is y 1 <y 2 <y 3 <y 4 , the distance along the X axis is x 1 <x 2 <... <x 7 <x 8 , then x 1 , x 8 ,y 1 ,y 4 The corresponding long straight line segments are extracted as boundary long straight line segments.

[0117] The component pin sizes tend to cluster in a certain direction. This step uses a projection method to screen out the pin groups at the edge. The use of straight line projection avoids the influence of the component pin area on the pin group screening and improves the stability of the screening.

[0118] Step 6: Use the new sub-pixel interpolation algorithm to calculate the sub-pixel straight line pixel, and use the model parameters to optimize the pixel-level straight line result to the sub-pixel level. 0 ,y 0) as the center, and take out 4 pixels along the X direction and Y direction as the candidate area. The pixels taken out along the X direction are x 1 ,x 2 ,x 3 ,x 4 ,x 5 , the corresponding grayscale values ​​are Q(x 1 ),Q(x 2 ),Q(x 3 ),Q(x 4 ),Q(x 5 );

[0119] Substitute into the formula to calculate V 1 ,V 2 ,V 3 ,V 4 :

[0120] V i =ln(|Q(x i+1 )-Q(x i )|), i=1,2,3,4;

[0121] Then use the formula to calculate the position μ x :

[0122] where i, j, k, l∈{1,2,3,4}, i≠j≠k≠l

[0123] Then take out pixel y along the Y direction 1 ,y 2 ,y 3 ,y 4 ,y 5 , the corresponding grayscale values ​​are Q(y 1 ),Q(y 2 ),Q(y 3 ),Q(y 4 ),Q(y 5 ), substitute into the formula to calculate N 1 ,N 2 ,N 3 ,N 4 :

[0124] N i =ln(|Q(y i+1 )-Q(y i )|),i=1,2,3,4;

[0125] Substitute into the formula to calculate μ y :

[0126] where i, j, k, l∈{1,2,3,4}, i≠j≠k≠l

[0127] The optimized sub-pixel point (x, y) is:

[0128]

[0129] Step 7: Based on the straight line pairs processed in step 6, calculate the distance between the straight line pairs. The distances between the two straight line pairs calculated are the length and width of the component. The straight line pairs obtained are x 1 , x 8 ,y 1 ,y 4 . Where x 1 , x 8 The distance between the straight lines is the length of the element, y 1 and 4 The distance between the straight lines is the width of the element. The distance between the straight lines is calculated by fitting the straight line and the distance from the point to the straight line, expressed as x. 1 and x 8 For example, the formula used for the straight-line distance is as follows:

[0130]

[0131] Where d is the distance between the straight line segments, that is, the length of the element, A j , B j , C j and A i , B i , C i is the parameter of the straight line segment equation corresponding to the two straight line segments in the length calculation, (x k ,y k ) and (x l ,y l ) are the coordinates of the points on the two straight line segments; 1 and 4 The distance calculation can be obtained in the same way. The formula based on is the calculation method of the component width w:

[0132]

[0133] Among them, A w , B w , C w and A z , B z , C z It is the straight line segment equation parameter corresponding to the two straight line segments in the width calculation.

[0134] Exemplary computing devices of the present invention:

[0135] The device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of any method in the specific implementation manner are implemented.

[0136] Exemplary media of the present invention:

[0137] The medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute any method described in any specific implementation manner.

[0138] Although the present invention is described herein with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the present invention. It should therefore be understood that many modifications may be made to the exemplary embodiments and that other arrangements may be devised without departing from the spirit and scope of the present invention as defined by the appended claims. It should be understood that the various dependent claims and features described herein may be combined in a manner different from that described in the original claims. It should also be understood that features described in conjunction with individual embodiments may be used in other described embodiments.

Claims

1. Automatic measurement method of sub-pixel parameters of patch components, characterized in that: The method comprises: Obtain a grayscale image of the image to be detected; Segment the image to be detected to obtain the foreground and background; Extract all connected areas in the foreground and filter out interference to obtain an image that only retains the pin area; Calculate the minimum enclosing rectangle of all pin areas; Extract all straight line segments of the minimum enclosing rectangle of the pin area; Search and combine all the straight line segments obtained, and combine the straight line segments in the same direction into the pin long straight line segment; Extract the edge straight line segment pairs of the long straight line segment of the pin; Optimize the obtained edge straight line segment pairs to sub-pixel level; The distances between pairs of sub-pixel edge straight line segments of two groups of components are calculated to obtain the distances between the two pairs of straight line segments, which are the length and width of the components, respectively.

2. The automatic measurement method of sub-pixel parameters of patch components according to claim 1, characterized in that: Methods for segmenting an image based on threshold T include: Determine the threshold T: Among them, A is the maximum value of the image grayscale, and B is the minimum value of the image grayscale; The pixels whose grayscale values ​​in the image to be detected exceed the threshold T are set as the foreground, and the pixels whose grayscale values ​​in the image to be detected are set as the background.

3. The automatic measurement method of sub-pixel parameters of patch components according to claim 1, characterized in that: The method of extracting all connected areas in the foreground and filtering out interference to obtain an image retaining only the pin area includes: Extract the connected area in the foreground, the connected area is the pixel cluster area that satisfies eight connectivity between pixels, label the connected area, calculate the minimum bounding rectangle of each connected area, and determine the characteristic parameters of the connected area, including the area N, the length W and width H of the minimum bounding rectangle, and the rectangularity The connected area that meets the constraint conditions is regarded as the pin area, and the connected area outside the pin area is filtered out as anomalies. The constraint conditions are: S=(T NH >N>T NL )^(R>T R )^(T WH >W>T WL )∧(H HH >T HL ) Where S is the constraint logic value of the pin area, T NH and T NL is the area threshold range of the pin area, T R is the rectangularity threshold, T WH and T WL is the width threshold range of the pin area, T HH and T HL is the length threshold range of the pin area; S is 0, indicating that the corresponding connected area does not satisfy the constraint and is interference, and S is 1, indicating that the corresponding connected area is a pin area; Calculate the S values ​​of all connected areas, and extract the area with an S value of 1 as the pin area.

4. The automatic measurement method of sub-pixel parameters of patch components according to claim 3, characterized in that: The minimum enclosing rectangle of the connected area or the pin area is calculated using the rotating caliper algorithm.

5. The automatic measurement method of sub-pixel parameters of patch components according to claim 1, characterized in that: The method of extracting the straight line segment of the minimum enclosing rectangle of the pin area includes: Determine the four vertices of the minimum circumscribed rectangle. The coordinates of the four vertices are (x1, y1), (x2, y2), (x3, y3), and (x4, y4). The equations of the four straight line segments of the minimum circumscribed rectangle are: Where x represents the abscissa of the coordinate system where the minimum circumscribed rectangle is located, and y represents the ordinate; Convert the four straight line segment equations into general equations and obtain the coefficients of all straight line segment equations: Among them, A1, B1, C1, A2, B2, C2, A3, B3, C3, A4, B4, C4 are the coefficients of the straight line segment equations of the four straight line segments of the minimum circumscribed rectangle.

6. The automatic measurement method of sub-pixel parameters of patch components according to claim 5, characterized in that: The method of searching and combining all the obtained straight line segments and combining the straight line segments in the same direction into the pin long straight line segment includes: Construct the straight line segment adjacency relationship matrix L of the straight line segment pairwise relationship, where the elements are L i,j , the dimension of matrix L is n*n, where n represents the total number of straight line segments; Initialize the length of the mark vector F to n, and the initial value to -1, where -1 indicates that the corresponding straight line segment has not been searched, and 0 indicates that the corresponding straight line segment has been searched; initialize the stack C to an empty vector, and the stack C is used to store collinear line segments; Traverse all elements of the line segment adjacency matrix L and search for combinations of line segments. The search process is: The current processing line segment number is i. When F(i)<0 and C(i) is not empty, push the j position into C(i) and set the F(j) position value to F(i); when F(i)>0 and F(j)<0, push the j position value into the stack C(F(i)) and set the F(j) position value to F(i); i and j are elements L i,j The subscript of ; After the search is completed, the straight line segments in the stack C are taken out one by one to form a long straight line segment.

7. The automatic measurement method of sub-pixel parameters of patch components according to claim 6, characterized in that: The element L in the line segment adjacency matrix L i,j for: L i,j =(θ i,j <T θ )^(D i,j <T dis ) Among them, θ i,j is the angle between the straight line segments, T θ is the straight line segment angle threshold, D i,j is the distance between straight line segments, T dis is the distance threshold between straight line segments. a and b represent the number of pixels on the two straight line segments i and j.

8. The automatic measurement method of sub-pixel parameters of patch components according to claim 1, characterized in that: The method for extracting edge straight line segment pairs of the long straight line segment of the pin includes: Project the vertical direction of all the long straight line segments of the pins, and select the edge straight line segment pairs of the two groups of components based on the distance on the projection.

9. The automatic measurement method of sub-pixel parameters of patch components according to claim 1, characterized in that: Methods for optimizing the obtained edge straight line segment pairs to sub-pixel level include: Taking the pixel (x0, y0) on the edge straight line segment as the center, take out 4 pixels along the X direction and Y direction as the candidate area. The pixels taken out along the X direction are x1, x2, x3, x4, x5, and the corresponding grayscale values ​​are Q(x1), Q(x2), Q(x3), Q(x4), Q(x5); Calculate V1, V2, V3, V4: V i =ln(Q(x i+1 )-Q(x i )),i=1,2,3,4; i、j、k、l∈{1,2,3,4},i≠j≠k≠l Then take out pixels y1, y2, y3, y4, y5 along the Y direction, the corresponding grayscale values ​​are Q(y1), Q(y2), Q(y3), Q(y4), Q(y5), calculate N1, N2, N3, N4: N i =ln(Q(y i+1 )-Q(y i )),i=1,2,3,4; Calculate μ y : The optimized sub-pixel point (x, y) is:

10. The automatic measurement method of sub-pixel parameters of patch components according to claim 5, characterized in that: The method of calculating the distance between the sub-pixel edge straight line segment pairs of two groups of components and obtaining the distance between the two straight line segment pairs includes: Using two pairs of straight line segments, determine the length and width of the component, where the length d of the component is calculated as: Among them, A j , B j , C j and A i , B i , C i is the parameter of the straight line segment equation corresponding to the two straight line segments in the length calculation, (x k ,y k ) and (x l ,y l ) are the coordinates of the points on the two straight line segments respectively; Component width w is calculated as follows: Among them, A w , B w , C w and A z , B z , C z It is the straight line segment equation parameter corresponding to the two straight line segments in the width calculation.

11. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.

12. A medium, characterized in that The medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Detection method for rectangular pin component visual positioning

    CN104359402A

  • SOP element positioning and defect detecting method based on vision

    CN104933720A

  • Detecting and error-correcting method capable of rapidly and accurately obtaining element center and deflection angle

    CN104981105A

  • TR element locating and defect detecting method based on vision

    CN104990926A

  • Patch element positioning identification method based on minimum enclosing rectangle

    CN105809705A