Summary of the invention
The present invention be in order to solve current arithmetic accuracy and robustness poor, need to rely on prior imformation and could realize the detection of pinout information, accuracy that segmentation obtains pin field and obtain pin field center is corrected to image rotation and can have a strong impact on the positioning precision of element and a kind of detection & localization method for PLCC element of proposing.
For a detection & localization method for PLCC element, realize according to the following steps:
Step one: adopt optical lighting system to obtain PLCC part drawing picture;
Step 2: select fixed threshold to carry out Threshold segmentation to the PLCC part drawing picture that step one obtains, obtains the pretreated image of binaryzation and the number of non-zero pixels point in image after calculating binaryzation pre-service;
Step 3: whether the number of the non-zero pixels point that determining step two obtains reaches 0.1 ~ 0.9 times of PLCC element total number of image pixels, if so, continues to perform step 4, otherwise terminates this element testing process, return corresponding error code;
Step 4: adopt maximum variance between clusters to obtain self-adaption binaryzation image to the PLCC part drawing picture of step one, adopt again size be 5 × 5 rectangle in check self-adaption binaryzation image and carry out morphology and open operation, noise spot set less in filtering self-adaption binaryzation image, the morphology obtained opens application drawing picture; Wherein, it is first carry out etching operation to self-adaption binaryzation image with the rectangle kernel that size is 5 × 5 that described morphology opens operation, then by size be 5 × 5 rectangle in check the image after corrosion and carry out expansive working;
Step 5: the morphology obtained step 4 is opened application drawing picture and adopted connected component labeling algorithm to extract all profiles, obtains the minimum enclosed rectangle that each profile is corresponding, calculates the area of each profile and minimum enclosed rectangle thereof;
Step 6: the interference profile in filtering non-pinned region;
Step 7: the least square ellipse obtaining pin profile; Wherein, the anglec of rotation of described least square ellipse is the angle of transverse and Y-axis, and wherein coordinate system presses image procossing convention, with the image upper left corner for initial point, is to the right X-axis positive dirction, is Y-axis positive dirction downwards; There is following relational expression in the anglec of rotation of pin and the anglec of rotation of least square ellipse:
θ=90°-ψ
Wherein θ is the anglec of rotation of pin profile, and ψ is the anglec of rotation of least square ellipse, obtains the anglec of rotation of pin profile according to upper formula;
Step 8: the square calculating pin profile, the profile center-of-mass coordinate obtained according to first moment is as the centre coordinate of pin profile; For two-dimensional digital image, f (x, y) is pixel corresponding to (x, y) some place, wherein (p+q) rank square m
p,qbe defined as:
This two-dimensional digital image barycenter (x
0, y
0) computing formula be:
Wherein m
p,qrepresent (p+q) rank square of image, (x
0, y
0) be the centre coordinate of pin profile;
Step 9: adopt clustering algorithm PLCC component pin to be divided into four class pin profiles, correspond to four, upper and lower, left and right pin set respectively, and check that whether cluster result is correct, if, continue to perform step 10, otherwise terminate this element testing process, return corresponding error code;
Step 10: four class pin profiles step 9 obtained correspond in actual pin set respectively, first the pin set defined on the right side of PLCC element is the first pin set, counterclockwise definition the second pin set, the 3rd pin set and the 4th pin set; Angle according to the opposite side two class pin profile line of centres and X-axis judges, with X-axis angle little be the first pin set and the 3rd pin set, judge according to the centre coordinate X value size of this two classes pin profile again, X value the greater is the first pin set, X value smaller is the 3rd pin set, in like manner judges the second pin set and the 4th pin set;
Step 11: calculate the mean value of four pin set centre coordinates as rough element central coordinate, in each pin set, according to the line angular dimension of pin profile center and rough element central, pin profile in each pin set is sorted, obtain call number index [i] [j] of each pin profile in element, represent a jth pin profile of i-th group;
Step 12: judge that whether the number of pin profile in opposite side pin set is identical, if so, continues to perform next step, otherwise terminates this element testing process, return corresponding error code;
Step 13: obtain the minimum enclosed rectangle that the rear each pin profile of sequence is corresponding, its length and width correspond to length and the width of component pin respectively, calculate its mean value as examination criteria value,
be i-th spacing between pin and (i+1) individual pin, wherein (x
i+1, y
i+1) be the centre coordinate of the i-th+1 pin minimum enclosed rectangle, (x
i, y
i) be the centre coordinate of i-th pin minimum enclosed rectangle, calculate its mean value as examination criteria value, judge the length of each pin, width and spacing whether in standard value range of allowable error, if, continue to perform step 14, otherwise terminate this element testing process, return corresponding error code;
Step 14: according to barycenter matching rectangle of each pin profile after sequence, realize the accurate location of PLCC element, export center and the anglec of rotation of this rectangle, correspond to center and the anglec of rotation of element respectively, detection & localization process terminates.
Invention effect
The present invention does not rely on the detection & localization that prior imformation can realize PLCC element; The pin profile obtained connected component labeling carries out multistep screening can guarantee filtering interfering profile, improves the accuracy of cluster, guarantees the reliability of cluster result; The anglec of rotation of least square ellipse is adopted to obtain the anglec of rotation of pin profile and adopt pin profile barycenter as cluster standard, the pin set of twice cluster to four limits is classified, again the pin in each pin set is sorted, and define the first pin set, accurately can detect that mistake appears in which pin, adds the accuracy of detection.Adopt the least square method improved according to the pin profile barycenter fitting a straight line in each pin set, more accurately simulate the rectangle representing position of components according to the relation between four straight lines, realize the accurate location to element, make the precision of algorithm bring up to 90%.
Embodiment
Embodiment one: a kind of detection & localization method for PLCC element of present embodiment, realizes: step one according to the following steps: adopt optical lighting system to obtain PLCC part drawing picture;
Step 2: select fixed threshold to carry out Threshold segmentation to the PLCC part drawing picture that step one obtains, obtains the pretreated image of binaryzation and the number of non-zero pixels point in image after calculating binaryzation pre-service;
Step 3: whether the number of the non-zero pixels point that determining step two obtains reaches 0.1 ~ 0.9 times of PLCC element total number of image pixels, if so, continues to perform step 4, otherwise terminates this element testing process, return corresponding error code;
Step 4: adopt maximum variance between clusters to obtain self-adaption binaryzation image to the PLCC part drawing picture of step one, adopt again size be 5 × 5 rectangle in check self-adaption binaryzation image and carry out morphology and open operation, noise spot set less in filtering self-adaption binaryzation image, the morphology obtained opens application drawing picture; Wherein, it is first carry out etching operation to self-adaption binaryzation image with the rectangle kernel that size is 5 × 5 that described morphology opens operation, then by size be 5 × 5 rectangle in check the image after corrosion and carry out expansive working;
Step 5: the morphology obtained step 4 is opened application drawing picture and adopted connected component labeling algorithm to extract all profiles, obtains the minimum enclosed rectangle that each profile is corresponding, calculates the area of each profile and minimum enclosed rectangle thereof;
Step 6: adopt the method for cluster to distinguish component pin group, the interference profile in filtering non-pinned region before cluster operation must be guaranteed;
Step 7: the least square ellipse obtaining pin profile; Wherein, the anglec of rotation of described least square ellipse is the angle of transverse and Y-axis, and wherein coordinate system presses image procossing convention, with the image upper left corner for initial point, is to the right X-axis positive dirction, is Y-axis positive dirction downwards; There is following relational expression in the anglec of rotation of pin and the anglec of rotation of least square ellipse:
θ=90°-ψ
Wherein θ is the anglec of rotation of pin profile, and ψ is the anglec of rotation of least square ellipse, obtains the anglec of rotation of pin profile according to upper formula;
Step 8: the square calculating pin profile, the profile center-of-mass coordinate obtained according to first moment is as the centre coordinate of pin profile; For two-dimensional digital image, f (x, y) is pixel corresponding to (x, y) some place, wherein (p+q) rank square m
p,qbe defined as:
This two-dimensional digital image barycenter (x
0, y
0) computing formula be:
Wherein m
p,qrepresent (p+q) rank square of image, (x
0, y
0) be the centre coordinate of pin profile;
Step 9: adopt clustering algorithm PLCC component pin to be divided into four class pin profiles, correspond to four, upper and lower, left and right pin set respectively, and check that whether cluster result is correct, if, continue to perform step 10, otherwise terminate this element testing process, return corresponding error code;
Step 10: four class pin profiles step 9 obtained correspond in actual pin set respectively, first the pin set defined on the right side of PLCC element is the first pin set, counterclockwise definition the second pin set, the 3rd pin set and the 4th pin set; Angle according to the opposite side two class pin profile line of centres and X-axis judges, with X-axis angle little be the first pin set and the 3rd pin set, judge according to the centre coordinate X value size of this two classes pin profile again, X value the greater is the first pin set, X value smaller is the 3rd pin set, in like manner judges the second pin set and the 4th pin set;
Step 11: calculate the mean value of four pin set centre coordinates as rough element central coordinate, in each pin set, according to the line angular dimension of pin profile center and rough element central, pin profile in each pin set is sorted, obtain call number index [i] [j] of each pin profile in element, represent a jth pin profile of i-th group;
Step 12: judge that whether the number of pin profile in opposite side pin set is identical, if so, continues to perform next step, otherwise terminates this element testing process, return corresponding error code;
Step 13: obtain the minimum enclosed rectangle that the rear each pin profile of sequence is corresponding, its length and width correspond to length and the width of component pin respectively, calculate its mean value as examination criteria value,
be i-th spacing between pin and (i+1) individual pin, wherein (x
i+1, y
i+1) be the centre coordinate of the i-th+1 pin minimum enclosed rectangle, (x
i, y
i) be the centre coordinate of i-th pin minimum enclosed rectangle, calculate its mean value as examination criteria value, judge the length of each pin, width and spacing whether in standard value range of allowable error, if, continue to perform step 14, otherwise terminate this element testing process, return corresponding error code;
Step 14: according to barycenter matching rectangle of each pin profile after sequence, realize the accurate location of PLCC element, export center and the anglec of rotation of this rectangle, correspond to center and the anglec of rotation of element respectively, detection & localization process terminates.Embodiment two: present embodiment and embodiment one are unlike the interference profile in step 6 filtering non-pinned region, and detailed process is as follows:
(1) carry out first time screening according to the rectangular degree of profile: judge whether the ratio of contour area and its minimum enclosed rectangle area is greater than 0.5, if so, then retain this profile and corresponding minimum enclosed rectangle, otherwise delete;
(2) programmed screening is carried out according to the Aspect Ratio of minimum enclosed rectangle: the mean value calculating the minimum enclosed rectangle Aspect Ratio that previous step retains, judge that whether the Aspect Ratio of the minimum enclosed rectangle that first time screening rear profile is corresponding is at [0.6 of mean value, 1.4] times, if, then retain the profile that this minimum enclosed rectangle is corresponding, otherwise delete;
(3) third time screening is carried out according to the area of profile: the area average calculating the profile that previous step retains, after judging programmed screening, whether the area of each profile is at [0.8 of mean profile area, 1.2] times, if, then delete this profile, otherwise retain as pin profile.
Other step and parameter identical with embodiment one.
Embodiment three: present embodiment and embodiment one or two unlike: step 9 concrete steps are as follows:
(1) rotation angle range of pin profile is [-90 °, 90 °], wherein-90 ° represent identical sense of rotation with 90 °, the anglec of rotation of pin profile and the difference of the first pin profile anglec of rotation is adopted to input as first time cluster sample, similar according to the anglec of rotation of opposite side pin set, nearly 90 ° of the anglec of rotation difference of adjacent leads group, pin profile is divided into two classes, obtain the average anglec of rotation of each class and average centre coordinate, judge that whether the absolute value of the average anglec of rotation difference of classification one and classification two is at [85 °, 95 °] in, if, then judge whether the mean center coordinate of classification one and classification two differs and be less than ten small pixel, , if, continue to perform next step, otherwise terminate this element testing process, return corresponding error code,
(2) according to the position at pin profile center, two subclasses are further subdivided into each class profile that previous step cluster obtains: the profile first dividing classification one correspondence, a unique straight line is determined by the average anglec of rotation of classification two and average centre coordinate, the centre coordinate of profile in classification one is substituted into this straight-line equation, and computing method are as follows:
Wherein (x
0, i, y
0, i) be the centre coordinate of i-th profile in classification one, θ
0for the average anglec of rotation of profile in classification one, (x
1, y
1) be the mean center coordinate of profile in classification two, θ
1for the average anglec of rotation of profile in classification two, profile in classification one is divided into two subclasses by the positive negativity obtaining △ according to above computing method, correspond to call number index0, index2 or index1, index3 respectively, the algorithm principle dividing classification two is identical with upper, pin profile is divided into four class index0, index2 and index1, index3 the most at last, as four pin set of element;
(3) calculate the centre coordinate that previous step obtains four class pin profiles respectively, calculate σ according to following formula:
Wherein (x
0, y
0) be the centre coordinate of the i-th ndex0 class pin profile, (x
1, y
1) be the centre coordinate of the i-th ndex1 class pin profile, (x
2, y
2) be the centre coordinate of the i-th ndex2 class pin profile, (x
3, y
3) be the centre coordinate of the i-th ndex3 class pin profile, uniquely straight line is determined by the i-th ndex0 class pin profile center, the i-th ndex2 class pin profile center, another straight line is uniquely determined by the i-th ndex1 class pin profile center, the i-th ndex3 class pin profile center, judge that whether the absolute value σ of two included angle of straight line is at [85 °, 95 °] in scope, if so, continue to perform next step, otherwise terminate this element testing process, return corresponding error code.
Other step and parameter identical with embodiment one or two.
Embodiment four: one of present embodiment and embodiment one to three unlike: the detailed process of step 14 rectangle fitting is as follows:
(1) traditional least squares line fitting method is improved, simulates straight line equation according to the barycenter of pin profile in each pin set:
Wherein (n
1, n
2) be unit orthogonal vector, c is any one constant;
Match point coordinate is substituted into this straight-line equation:
r=c+n
1x
ij+n
2y
ij
Wherein (x
ij, y
ij) be the center-of-mass coordinate of a jth pin profile in rear i-th pin set of sequence;
Then | r| represents the distance of pin profile barycenter to this fitting a straight line, calculates satisfied
straight line parameter is as best straight line matching;
(2) be a rectangle due to what finally need matching, according to the characteristic that the parallel adjacent side of the opposite side of rectangle is orthogonal, simulate four following straight-line equations:
c
1+n
1x+n
2y=0
c
2+n
2x+n1y=0
c
3+n
1x+n
2y=0
c
4-n
2x+n
1y=0
Calculate satisfied after the pin profile barycenter of each pin set is substituted into above formula
straight line parameter, a closed rectangle can be surrounded by these four straight lines, realize the accurate location to element; Wherein, described c
1c
2c
3c
4represent four constants, (n
1, n
2) be unit orthogonal vector.
Other step and parameter identical with one of embodiment one to three.